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          Ftyp : Node_Id := First (Predefined_Float_Types);
3869          Decl : Node_Id;
3870          Def  : Node_Id;
3871          Nam  : Name_Id;
3872       begin
3873          String_To_Name_Buffer (Strval (Expression (Arg3)));
3874          Nam := Name_Find;
3875
3876          while Present (Ftyp) and then Chars (Ftyp) /= Nam loop
3877             Next (Ftyp);
3878          end loop;
3879
3880          if Present (Ftyp) then
3881             --  Don't build a derived type declaration, because predefined C
3882             --  types have no declaration anywhere, so cannot really be named.
3883             --  Instead build a full type declaration, starting with an
3884             --  appropriate type definition is built
3885
3886             if Is_Floating_Point_Type (Ftyp) then
3887                Def := Make_Floating_Point_Definition (Loc,
3888                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
3889                  Make_Real_Range_Specification (Loc,
3890                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
3891                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
3892
3893             else
3894                --  Should never have a predefined type we cannot handle
3895                raise Program_Error;
3896             end if;
3897
3898             --  Build and insert a Full_Type_Declaration, which will be
3899             --  analyzed as soon as this list entry has been analyzed.
3900
3901             Decl := Make_Full_Type_Declaration (Loc,
3902               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
3903               Type_Definition => Def);
3904
3905             Insert_After (N, Decl);
3906             Mark_Rewrite_Insertion (Decl);
3907
3908          else
3909             Error_Pragma_Arg ("no matching type found for pragma%",
3910             Arg2);
3911          end if;
3912       end Process_Import_Predefined_Type;
3913
3914       ---------------------------------
3915       -- Process_Import_Or_Interface --
3916       ---------------------------------
3917
3918       procedure Process_Import_Or_Interface is
3919          C      : Convention_Id;
3920          Def_Id : Entity_Id;
3921          Hom_Id : Entity_Id;
3922
3923       begin
3924          Process_Convention (C, Def_Id);
3925          Kill_Size_Check_Code (Def_Id);
3926          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
3927
3928          if Ekind_In (Def_Id, E_Variable, E_Constant) then
3929
3930             --  We do not permit Import to apply to a renaming declaration
3931
3932             if Present (Renamed_Object (Def_Id)) then
3933                Error_Pragma_Arg
3934                  ("pragma% not allowed for object renaming", Arg2);
3935
3936             --  User initialization is not allowed for imported object, but
3937             --  the object declaration may contain a default initialization,
3938             --  that will be discarded. Note that an explicit initialization
3939             --  only counts if it comes from source, otherwise it is simply
3940             --  the code generator making an implicit initialization explicit.
3941
3942             elsif Present (Expression (Parent (Def_Id)))
3943               and then Comes_From_Source (Expression (Parent (Def_Id)))
3944             then
3945                Error_Msg_Sloc := Sloc (Def_Id);
3946                Error_Pragma_Arg
3947                  ("no initialization allowed for declaration of& #",
3948                   "\imported entities cannot be initialized (RM B.1(24))",
3949                   Arg2);
3950
3951             else
3952                Set_Imported (Def_Id);
3953                Process_Interface_Name (Def_Id, Arg3, Arg4);
3954
3955                --  Note that we do not set Is_Public here. That's because we
3956                --  only want to set it if there is no address clause, and we
3957                --  don't know that yet, so we delay that processing till
3958                --  freeze time.
3959
3960                --  pragma Import completes deferred constants
3961
3962                if Ekind (Def_Id) = E_Constant then
3963                   Set_Has_Completion (Def_Id);
3964                end if;
3965
3966                --  It is not possible to import a constant of an unconstrained
3967                --  array type (e.g. string) because there is no simple way to
3968                --  write a meaningful subtype for it.
3969
3970                if Is_Array_Type (Etype (Def_Id))
3971                  and then not Is_Constrained (Etype (Def_Id))
3972                then
3973                   Error_Msg_NE
3974                     ("imported constant& must have a constrained subtype",
3975                       N, Def_Id);
3976                end if;
3977             end if;
3978
3979          elsif Is_Subprogram (Def_Id)
3980            or else Is_Generic_Subprogram (Def_Id)
3981          then
3982             --  If the name is overloaded, pragma applies to all of the denoted
3983             --  entities in the same declarative part.
3984
3985             Hom_Id := Def_Id;
3986             while Present (Hom_Id) loop
3987                Def_Id := Get_Base_Subprogram (Hom_Id);
3988
3989                --  Ignore inherited subprograms because the pragma will apply
3990                --  to the parent operation, which is the one called.
3991
3992                if Is_Overloadable (Def_Id)
3993                  and then Present (Alias (Def_Id))
3994                then
3995                   null;
3996
3997                --  If it is not a subprogram, it must be in an outer scope and
3998                --  pragma does not apply.
3999
4000                elsif not Is_Subprogram (Def_Id)
4001                  and then not Is_Generic_Subprogram (Def_Id)
4002                then
4003                   null;
4004
4005                --  The pragma does not apply to primitives of interfaces
4006
4007                elsif Is_Dispatching_Operation (Def_Id)
4008                  and then Present (Find_Dispatching_Type (Def_Id))
4009                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4010                then
4011                   null;
4012
4013                --  Verify that the homonym is in the same declarative part (not
4014                --  just the same scope).
4015
4016                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4017                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4018                then
4019                   exit;
4020
4021                else
4022                   Set_Imported (Def_Id);
4023
4024                   --  Reject an Import applied to an abstract subprogram
4025
4026                   if Is_Subprogram (Def_Id)
4027                     and then Is_Abstract_Subprogram (Def_Id)
4028                   then
4029                      Error_Msg_Sloc := Sloc (Def_Id);
4030                      Error_Msg_NE
4031                        ("cannot import abstract subprogram& declared#",
4032                         Arg2, Def_Id);
4033                   end if;
4034
4035                   --  Special processing for Convention_Intrinsic
4036
4037                   if C = Convention_Intrinsic then
4038
4039                      --  Link_Name argument not allowed for intrinsic
4040
4041                      Check_No_Link_Name;
4042
4043                      Set_Is_Intrinsic_Subprogram (Def_Id);
4044
4045                      --  If no external name is present, then check that this
4046                      --  is a valid intrinsic subprogram. If an external name
4047                      --  is present, then this is handled by the back end.
4048
4049                      if No (Arg3) then
4050                         Check_Intrinsic_Subprogram
4051                           (Def_Id, Get_Pragma_Arg (Arg2));
4052                      end if;
4053                   end if;
4054
4055                   --  All interfaced procedures need an external symbol created
4056                   --  for them since they are always referenced from another
4057                   --  object file.
4058
4059                   Set_Is_Public (Def_Id);
4060
4061                   --  Verify that the subprogram does not have a completion
4062                   --  through a renaming declaration. For other completions the
4063                   --  pragma appears as a too late representation.
4064
4065                   declare
4066                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4067
4068                   begin
4069                      if Present (Decl)
4070                        and then Nkind (Decl) = N_Subprogram_Declaration
4071                        and then Present (Corresponding_Body (Decl))
4072                        and then Nkind (Unit_Declaration_Node
4073                                         (Corresponding_Body (Decl))) =
4074                                              N_Subprogram_Renaming_Declaration
4075                      then
4076                         Error_Msg_Sloc := Sloc (Def_Id);
4077                         Error_Msg_NE
4078                           ("cannot import&, renaming already provided for " &
4079                            "declaration #", N, Def_Id);
4080                      end if;
4081                   end;
4082
4083                   Set_Has_Completion (Def_Id);
4084                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4085                end if;
4086
4087                if Is_Compilation_Unit (Hom_Id) then
4088
4089                   --  Its possible homonyms are not affected by the pragma.
4090                   --  Such homonyms might be present in the context of other
4091                   --  units being compiled.
4092
4093                   exit;
4094
4095                else
4096                   Hom_Id := Homonym (Hom_Id);
4097                end if;
4098             end loop;
4099
4100          --  When the convention is Java or CIL, we also allow Import to be
4101          --  given for packages, generic packages, exceptions, record
4102          --  components, and access to subprograms.
4103
4104          elsif (C = Convention_Java or else C = Convention_CIL)
4105            and then
4106              (Is_Package_Or_Generic_Package (Def_Id)
4107                or else Ekind (Def_Id) = E_Exception
4108                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4109                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4110          then
4111             Set_Imported (Def_Id);
4112             Set_Is_Public (Def_Id);
4113             Process_Interface_Name (Def_Id, Arg3, Arg4);
4114
4115          --  Import a CPP class
4116
4117          elsif Is_Record_Type (Def_Id)
4118            and then C = Convention_CPP
4119          then
4120             --  Types treated as CPP classes are treated as limited, but we
4121             --  don't require them to be declared this way. A warning is issued
4122             --  to encourage the user to declare them as limited. This is not
4123             --  an error, for compatibility reasons, because these types have
4124             --  been supported this way for some time.
4125
4126             if not Is_Limited_Type (Def_Id) then
4127                Error_Msg_N
4128                  ("imported 'C'P'P type should be " &
4129                     "explicitly declared limited?",
4130                   Get_Pragma_Arg (Arg2));
4131                Error_Msg_N
4132                  ("\type will be considered limited",
4133                   Get_Pragma_Arg (Arg2));
4134             end if;
4135
4136             Set_Is_CPP_Class (Def_Id);
4137             Set_Is_Limited_Record (Def_Id);
4138
4139             --  Imported CPP types must not have discriminants (because C++
4140             --  classes do not have discriminants).
4141
4142             if Has_Discriminants (Def_Id) then
4143                Error_Msg_N
4144                  ("imported 'C'P'P type cannot have discriminants",
4145                   First (Discriminant_Specifications
4146                           (Declaration_Node (Def_Id))));
4147             end if;
4148
4149             --  Components of imported CPP types must not have default
4150             --  expressions because the constructor (if any) is on the
4151             --  C++ side.
4152
4153             declare
4154                Tdef  : constant Node_Id :=
4155                          Type_Definition (Declaration_Node (Def_Id));
4156                Clist : Node_Id;
4157                Comp  : Node_Id;
4158
4159             begin
4160                if Nkind (Tdef) = N_Record_Definition then
4161                   Clist := Component_List (Tdef);
4162
4163                else
4164                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4165                   Clist := Component_List (Record_Extension_Part (Tdef));
4166                end if;
4167
4168                if Present (Clist) then
4169                   Comp := First (Component_Items (Clist));
4170                   while Present (Comp) loop
4171                      if Present (Expression (Comp)) then
4172                         Error_Msg_N
4173                           ("component of imported 'C'P'P type cannot have" &
4174                            " default expression", Expression (Comp));
4175                      end if;
4176
4177                      Next (Comp);
4178                   end loop;
4179                end if;
4180             end;
4181
4182          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4183             Check_No_Link_Name;
4184             Check_Arg_Count (3);
4185             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4186
4187             Process_Import_Predefined_Type;
4188
4189          else
4190             Error_Pragma_Arg
4191               ("second argument of pragma% must be object, subprogram" &
4192                " or incomplete type",
4193                Arg2);
4194          end if;
4195
4196          --  If this pragma applies to a compilation unit, then the unit, which
4197          --  is a subprogram, does not require (or allow) a body. We also do
4198          --  not need to elaborate imported procedures.
4199
4200          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4201             declare
4202                Cunit : constant Node_Id := Parent (Parent (N));
4203             begin
4204                Set_Body_Required (Cunit, False);
4205             end;
4206          end if;
4207       end Process_Import_Or_Interface;
4208
4209       --------------------
4210       -- Process_Inline --
4211       --------------------
4212
4213       procedure Process_Inline (Active : Boolean) is
4214          Assoc     : Node_Id;
4215          Decl      : Node_Id;
4216          Subp_Id   : Node_Id;
4217          Subp      : Entity_Id;
4218          Applies   : Boolean;
4219
4220          Effective : Boolean := False;
4221          --  Set True if inline has some effect, i.e. if there is at least one
4222          --  subprogram set as inlined as a result of the use of the pragma.
4223
4224          procedure Make_Inline (Subp : Entity_Id);
4225          --  Subp is the defining unit name of the subprogram declaration. Set
4226          --  the flag, as well as the flag in the corresponding body, if there
4227          --  is one present.
4228
4229          procedure Set_Inline_Flags (Subp : Entity_Id);
4230          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4231          --  Has_Pragma_Inline_Always for the Inline_Always case.
4232
4233          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4234          --  Returns True if it can be determined at this stage that inlining
4235          --  is not possible, for example if the body is available and contains
4236          --  exception handlers, we prevent inlining, since otherwise we can
4237          --  get undefined symbols at link time. This function also emits a
4238          --  warning if front-end inlining is enabled and the pragma appears
4239          --  too late.
4240          --
4241          --  ??? is business with link symbols still valid, or does it relate
4242          --  to front end ZCX which is being phased out ???
4243
4244          ---------------------------
4245          -- Inlining_Not_Possible --
4246          ---------------------------
4247
4248          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4249             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4250             Stats : Node_Id;
4251
4252          begin
4253             if Nkind (Decl) = N_Subprogram_Body then
4254                Stats := Handled_Statement_Sequence (Decl);
4255                return Present (Exception_Handlers (Stats))
4256                  or else Present (At_End_Proc (Stats));
4257
4258             elsif Nkind (Decl) = N_Subprogram_Declaration
4259               and then Present (Corresponding_Body (Decl))
4260             then
4261                if Front_End_Inlining
4262                  and then Analyzed (Corresponding_Body (Decl))
4263                then
4264                   Error_Msg_N ("pragma appears too late, ignored?", N);
4265                   return True;
4266
4267                --  If the subprogram is a renaming as body, the body is just a
4268                --  call to the renamed subprogram, and inlining is trivially
4269                --  possible.
4270
4271                elsif
4272                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4273                                              N_Subprogram_Renaming_Declaration
4274                then
4275                   return False;
4276
4277                else
4278                   Stats :=
4279                     Handled_Statement_Sequence
4280                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4281
4282                   return
4283                     Present (Exception_Handlers (Stats))
4284                       or else Present (At_End_Proc (Stats));
4285                end if;
4286
4287             else
4288                --  If body is not available, assume the best, the check is
4289                --  performed again when compiling enclosing package bodies.
4290
4291                return False;
4292             end if;
4293          end Inlining_Not_Possible;
4294
4295          -----------------
4296          -- Make_Inline --
4297          -----------------
4298
4299          procedure Make_Inline (Subp : Entity_Id) is
4300             Kind       : constant Entity_Kind := Ekind (Subp);
4301             Inner_Subp : Entity_Id   := Subp;
4302
4303          begin
4304             --  Ignore if bad type, avoid cascaded error
4305
4306             if Etype (Subp) = Any_Type then
4307                Applies := True;
4308                return;
4309
4310             --  Ignore if all inlining is suppressed
4311
4312             elsif Suppress_All_Inlining then
4313                Applies := True;
4314                return;
4315
4316             --  If inlining is not possible, for now do not treat as an error
4317
4318             elsif Inlining_Not_Possible (Subp) then
4319                Applies := True;
4320                return;
4321
4322             --  Here we have a candidate for inlining, but we must exclude
4323             --  derived operations. Otherwise we would end up trying to inline
4324             --  a phantom declaration, and the result would be to drag in a
4325             --  body which has no direct inlining associated with it. That
4326             --  would not only be inefficient but would also result in the
4327             --  backend doing cross-unit inlining in cases where it was
4328             --  definitely inappropriate to do so.
4329
4330             --  However, a simple Comes_From_Source test is insufficient, since
4331             --  we do want to allow inlining of generic instances which also do
4332             --  not come from source. We also need to recognize specs generated
4333             --  by the front-end for bodies that carry the pragma. Finally,
4334             --  predefined operators do not come from source but are not
4335             --  inlineable either.
4336
4337             elsif Is_Generic_Instance (Subp)
4338               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4339             then
4340                null;
4341
4342             elsif not Comes_From_Source (Subp)
4343               and then Scope (Subp) /= Standard_Standard
4344             then
4345                Applies := True;
4346                return;
4347             end if;
4348
4349             --  The referenced entity must either be the enclosing entity, or
4350             --  an entity declared within the current open scope.
4351
4352             if Present (Scope (Subp))
4353               and then Scope (Subp) /= Current_Scope
4354               and then Subp /= Current_Scope
4355             then
4356                Error_Pragma_Arg
4357                  ("argument of% must be entity in current scope", Assoc);
4358                return;
4359             end if;
4360
4361             --  Processing for procedure, operator or function. If subprogram
4362             --  is aliased (as for an instance) indicate that the renamed
4363             --  entity (if declared in the same unit) is inlined.
4364
4365             if Is_Subprogram (Subp) then
4366                Inner_Subp := Ultimate_Alias (Inner_Subp);
4367
4368                if In_Same_Source_Unit (Subp, Inner_Subp) then
4369                   Set_Inline_Flags (Inner_Subp);
4370
4371                   Decl := Parent (Parent (Inner_Subp));
4372
4373                   if Nkind (Decl) = N_Subprogram_Declaration
4374                     and then Present (Corresponding_Body (Decl))
4375                   then
4376                      Set_Inline_Flags (Corresponding_Body (Decl));
4377
4378                   elsif Is_Generic_Instance (Subp) then
4379
4380                      --  Indicate that the body needs to be created for
4381                      --  inlining subsequent calls. The instantiation node
4382                      --  follows the declaration of the wrapper package
4383                      --  created for it.
4384
4385                      if Scope (Subp) /= Standard_Standard
4386                        and then
4387                          Need_Subprogram_Instance_Body
4388                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4389                               Subp)
4390                      then
4391                         null;
4392                      end if;
4393                   end if;
4394                end if;
4395
4396                Applies := True;
4397
4398             --  For a generic subprogram set flag as well, for use at the point
4399             --  of instantiation, to determine whether the body should be
4400             --  generated.
4401
4402             elsif Is_Generic_Subprogram (Subp) then
4403                Set_Inline_Flags (Subp);
4404                Applies := True;
4405
4406             --  Literals are by definition inlined
4407
4408             elsif Kind = E_Enumeration_Literal then
4409                null;
4410
4411             --  Anything else is an error
4412
4413             else
4414                Error_Pragma_Arg
4415                  ("expect subprogram name for pragma%", Assoc);
4416             end if;
4417          end Make_Inline;
4418
4419          ----------------------
4420          -- Set_Inline_Flags --
4421          ----------------------
4422
4423          procedure Set_Inline_Flags (Subp : Entity_Id) is
4424          begin
4425             if Active then
4426                Set_Is_Inlined (Subp);
4427             end if;
4428
4429             if not Has_Pragma_Inline (Subp) then
4430                Set_Has_Pragma_Inline (Subp);
4431                Effective := True;
4432             end if;
4433
4434             if Prag_Id = Pragma_Inline_Always then
4435                Set_Has_Pragma_Inline_Always (Subp);
4436             end if;
4437          end Set_Inline_Flags;
4438
4439       --  Start of processing for Process_Inline
4440
4441       begin
4442          Check_No_Identifiers;
4443          Check_At_Least_N_Arguments (1);
4444
4445          if Active then
4446             Inline_Processing_Required := True;
4447          end if;
4448
4449          Assoc := Arg1;
4450          while Present (Assoc) loop
4451             Subp_Id := Get_Pragma_Arg (Assoc);
4452             Analyze (Subp_Id);
4453             Applies := False;
4454
4455             if Is_Entity_Name (Subp_Id) then
4456                Subp := Entity (Subp_Id);
4457
4458                if Subp = Any_Id then
4459
4460                   --  If previous error, avoid cascaded errors
4461
4462                   Applies := True;
4463                   Effective := True;
4464
4465                else
4466                   Make_Inline (Subp);
4467
4468                   --  For the pragma case, climb homonym chain. This is
4469                   --  what implements allowing the pragma in the renaming
4470                   --  case, with the result applying to the ancestors.
4471
4472                   if not From_Aspect_Specification (N) then
4473                      while Present (Homonym (Subp))
4474                        and then Scope (Homonym (Subp)) = Current_Scope
4475                      loop
4476                         Make_Inline (Homonym (Subp));
4477                         Subp := Homonym (Subp);
4478                      end loop;
4479                   end if;
4480                end if;
4481             end if;
4482
4483             if not Applies then
4484                Error_Pragma_Arg
4485                  ("inappropriate argument for pragma%", Assoc);
4486
4487             elsif not Effective
4488               and then Warn_On_Redundant_Constructs
4489               and then not Suppress_All_Inlining
4490             then
4491                if Inlining_Not_Possible (Subp) then
4492                   Error_Msg_NE
4493                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4494                else
4495                   Error_Msg_NE
4496                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4497                end if;
4498             end if;
4499
4500             Next (Assoc);
4501          end loop;
4502       end Process_Inline;
4503
4504       ----------------------------
4505       -- Process_Interface_Name --
4506       ----------------------------
4507
4508       procedure Process_Interface_Name
4509         (Subprogram_Def : Entity_Id;
4510          Ext_Arg        : Node_Id;
4511          Link_Arg       : Node_Id)
4512       is
4513          Ext_Nam    : Node_Id;
4514          Link_Nam   : Node_Id;
4515          String_Val : String_Id;
4516
4517          procedure Check_Form_Of_Interface_Name
4518            (SN            : Node_Id;
4519             Ext_Name_Case : Boolean);
4520          --  SN is a string literal node for an interface name. This routine
4521          --  performs some minimal checks that the name is reasonable. In
4522          --  particular that no spaces or other obviously incorrect characters
4523          --  appear. This is only a warning, since any characters are allowed.
4524          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4525
4526          ----------------------------------
4527          -- Check_Form_Of_Interface_Name --
4528          ----------------------------------
4529
4530          procedure Check_Form_Of_Interface_Name
4531            (SN            : Node_Id;
4532             Ext_Name_Case : Boolean)
4533          is
4534             S  : constant String_Id := Strval (Expr_Value_S (SN));
4535             SL : constant Nat       := String_Length (S);
4536             C  : Char_Code;
4537
4538          begin
4539             if SL = 0 then
4540                Error_Msg_N ("interface name cannot be null string", SN);
4541             end if;
4542
4543             for J in 1 .. SL loop
4544                C := Get_String_Char (S, J);
4545
4546                --  Look for dubious character and issue unconditional warning.
4547                --  Definitely dubious if not in character range.
4548
4549                if not In_Character_Range (C)
4550
4551                   --  For all cases except CLI target,
4552                   --  commas, spaces and slashes are dubious (in CLI, we use
4553                   --  commas and backslashes in external names to specify
4554                   --  assembly version and public key, while slashes and spaces
4555                   --  can be used in names to mark nested classes and
4556                   --  valuetypes).
4557
4558                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4559                              and then (Get_Character (C) = ','
4560                                          or else
4561                                        Get_Character (C) = '\'))
4562                  or else (VM_Target /= CLI_Target
4563                             and then (Get_Character (C) = ' '
4564                                         or else
4565                                       Get_Character (C) = '/'))
4566                then
4567                   Error_Msg
4568                     ("?interface name contains illegal character",
4569                      Sloc (SN) + Source_Ptr (J));
4570                end if;
4571             end loop;
4572          end Check_Form_Of_Interface_Name;
4573
4574       --  Start of processing for Process_Interface_Name
4575
4576       begin
4577          if No (Link_Arg) then
4578             if No (Ext_Arg) then
4579                if VM_Target = CLI_Target
4580                  and then Ekind (Subprogram_Def) = E_Package
4581                  and then Nkind (Parent (Subprogram_Def)) =
4582                                                  N_Package_Specification
4583                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
4584                then
4585                   Set_Interface_Name
4586                      (Subprogram_Def,
4587                       Interface_Name
4588                         (Generic_Parent (Parent (Subprogram_Def))));
4589                end if;
4590
4591                return;
4592
4593             elsif Chars (Ext_Arg) = Name_Link_Name then
4594                Ext_Nam  := Empty;
4595                Link_Nam := Expression (Ext_Arg);
4596
4597             else
4598                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4599                Ext_Nam  := Expression (Ext_Arg);
4600                Link_Nam := Empty;
4601             end if;
4602
4603          else
4604             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
4605             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4606             Ext_Nam  := Expression (Ext_Arg);
4607             Link_Nam := Expression (Link_Arg);
4608          end if;
4609
4610          --  Check expressions for external name and link name are static
4611
4612          if Present (Ext_Nam) then
4613             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4614             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4615
4616             --  Verify that external name is not the name of a local entity,
4617             --  which would hide the imported one and could lead to run-time
4618             --  surprises. The problem can only arise for entities declared in
4619             --  a package body (otherwise the external name is fully qualified
4620             --  and will not conflict).
4621
4622             declare
4623                Nam : Name_Id;
4624                E   : Entity_Id;
4625                Par : Node_Id;
4626
4627             begin
4628                if Prag_Id = Pragma_Import then
4629                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4630                   Nam := Name_Find;
4631                   E   := Entity_Id (Get_Name_Table_Info (Nam));
4632
4633                   if Nam /= Chars (Subprogram_Def)
4634                     and then Present (E)
4635                     and then not Is_Overloadable (E)
4636                     and then Is_Immediately_Visible (E)
4637                     and then not Is_Imported (E)
4638                     and then Ekind (Scope (E)) = E_Package
4639                   then
4640                      Par := Parent (E);
4641                      while Present (Par) loop
4642                         if Nkind (Par) = N_Package_Body then
4643                            Error_Msg_Sloc := Sloc (E);
4644                            Error_Msg_NE
4645                              ("imported entity is hidden by & declared#",
4646                               Ext_Arg, E);
4647                            exit;
4648                         end if;
4649
4650                         Par := Parent (Par);
4651                      end loop;
4652                   end if;
4653                end if;
4654             end;
4655          end if;
4656
4657          if Present (Link_Nam) then
4658             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4659             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4660          end if;
4661
4662          --  If there is no link name, just set the external name
4663
4664          if No (Link_Nam) then
4665             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4666
4667          --  For the Link_Name case, the given literal is preceded by an
4668          --  asterisk, which indicates to GCC that the given name should be
4669          --  taken literally, and in particular that no prepending of
4670          --  underlines should occur, even in systems where this is the
4671          --  normal default.
4672
4673          else
4674             Start_String;
4675
4676             if VM_Target = No_VM then
4677                Store_String_Char (Get_Char_Code ('*'));
4678             end if;
4679
4680             String_Val := Strval (Expr_Value_S (Link_Nam));
4681             Store_String_Chars (String_Val);
4682             Link_Nam :=
4683               Make_String_Literal (Sloc (Link_Nam),
4684                 Strval => End_String);
4685          end if;
4686
4687          Set_Encoded_Interface_Name
4688            (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4689
4690          --  We allow duplicated export names in CIL, as they are always
4691          --  enclosed in a namespace that differentiates them, and overloaded
4692          --  entities are supported by the VM.
4693
4694          if Convention (Subprogram_Def) /= Convention_CIL then
4695             Check_Duplicated_Export_Name (Link_Nam);
4696          end if;
4697       end Process_Interface_Name;
4698
4699       -----------------------------------------
4700       -- Process_Interrupt_Or_Attach_Handler --
4701       -----------------------------------------
4702
4703       procedure Process_Interrupt_Or_Attach_Handler is
4704          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
4705          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4706          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
4707
4708       begin
4709          Set_Is_Interrupt_Handler (Handler_Proc);
4710
4711          --  If the pragma is not associated with a handler procedure within a
4712          --  protected type, then it must be for a nonprotected procedure for
4713          --  the AAMP target, in which case we don't associate a representation
4714          --  item with the procedure's scope.
4715
4716          if Ekind (Proc_Scope) = E_Protected_Type then
4717             if Prag_Id = Pragma_Interrupt_Handler
4718                  or else
4719                Prag_Id = Pragma_Attach_Handler
4720             then
4721                Record_Rep_Item (Proc_Scope, N);
4722             end if;
4723          end if;
4724       end Process_Interrupt_Or_Attach_Handler;
4725
4726       --------------------------------------------------
4727       -- Process_Restrictions_Or_Restriction_Warnings --
4728       --------------------------------------------------
4729
4730       --  Note: some of the simple identifier cases were handled in par-prag,
4731       --  but it is harmless (and more straightforward) to simply handle all
4732       --  cases here, even if it means we repeat a bit of work in some cases.
4733
4734       procedure Process_Restrictions_Or_Restriction_Warnings
4735         (Warn : Boolean)
4736       is
4737          Arg   : Node_Id;
4738          R_Id  : Restriction_Id;
4739          Id    : Name_Id;
4740          Expr  : Node_Id;
4741          Val   : Uint;
4742
4743          procedure Check_Unit_Name (N : Node_Id);
4744          --  Checks unit name parameter for No_Dependence. Returns if it has
4745          --  an appropriate form, otherwise raises pragma argument error.
4746
4747          ---------------------
4748          -- Check_Unit_Name --
4749          ---------------------
4750
4751          procedure Check_Unit_Name (N : Node_Id) is
4752          begin
4753             if Nkind (N) = N_Selected_Component then
4754                Check_Unit_Name (Prefix (N));
4755                Check_Unit_Name (Selector_Name (N));
4756
4757             elsif Nkind (N) = N_Identifier then
4758                return;
4759
4760             else
4761                Error_Pragma_Arg
4762                  ("wrong form for unit name for No_Dependence", N);
4763             end if;
4764          end Check_Unit_Name;
4765
4766       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
4767
4768       begin
4769          --  Ignore all Restrictions pragma in CodePeer mode
4770
4771          if CodePeer_Mode then
4772             return;
4773          end if;
4774
4775          Check_Ada_83_Warning;
4776          Check_At_Least_N_Arguments (1);
4777          Check_Valid_Configuration_Pragma;
4778
4779          Arg := Arg1;
4780          while Present (Arg) loop
4781             Id := Chars (Arg);
4782             Expr := Get_Pragma_Arg (Arg);
4783
4784             --  Case of no restriction identifier present
4785
4786             if Id = No_Name then
4787                if Nkind (Expr) /= N_Identifier then
4788                   Error_Pragma_Arg
4789                     ("invalid form for restriction", Arg);
4790                end if;
4791
4792                R_Id :=
4793                  Get_Restriction_Id
4794                    (Process_Restriction_Synonyms (Expr));
4795
4796                if R_Id not in All_Boolean_Restrictions then
4797                   Error_Msg_Name_1 := Pname;
4798                   Error_Msg_N
4799                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
4800
4801                   --  Check for possible misspelling
4802
4803                   for J in Restriction_Id loop
4804                      declare
4805                         Rnm : constant String := Restriction_Id'Image (J);
4806
4807                      begin
4808                         Name_Buffer (1 .. Rnm'Length) := Rnm;
4809                         Name_Len := Rnm'Length;
4810                         Set_Casing (All_Lower_Case);
4811
4812                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
4813                            Set_Casing
4814                              (Identifier_Casing (Current_Source_File));
4815                            Error_Msg_String (1 .. Rnm'Length) :=
4816                              Name_Buffer (1 .. Name_Len);
4817                            Error_Msg_Strlen := Rnm'Length;
4818                            Error_Msg_N -- CODEFIX
4819                              ("\possible misspelling of ""~""",
4820                               Get_Pragma_Arg (Arg));
4821                            exit;
4822                         end if;
4823                      end;
4824                   end loop;
4825
4826                   raise Pragma_Exit;
4827                end if;
4828
4829                if Implementation_Restriction (R_Id) then
4830                   Check_Restriction (No_Implementation_Restrictions, Arg);
4831                end if;
4832
4833                --  If this is a warning, then set the warning unless we already
4834                --  have a real restriction active (we never want a warning to
4835                --  override a real restriction).
4836
4837                if Warn then
4838                   if not Restriction_Active (R_Id) then
4839                      Set_Restriction (R_Id, N);
4840                      Restriction_Warnings (R_Id) := True;
4841                   end if;
4842
4843                --  If real restriction case, then set it and make sure that the
4844                --  restriction warning flag is off, since a real restriction
4845                --  always overrides a warning.
4846
4847                else
4848                   Set_Restriction (R_Id, N);
4849                   Restriction_Warnings (R_Id) := False;
4850                end if;
4851
4852                --  Check for obsolescent restrictions in Ada 2005 mode
4853
4854                if not Warn
4855                  and then Ada_Version >= Ada_2005
4856                  and then (R_Id = No_Asynchronous_Control
4857                             or else
4858                            R_Id = No_Unchecked_Deallocation
4859                             or else
4860                            R_Id = No_Unchecked_Conversion)
4861                then
4862                   Check_Restriction (No_Obsolescent_Features, N);
4863                end if;
4864
4865                --  A very special case that must be processed here: pragma
4866                --  Restrictions (No_Exceptions) turns off all run-time
4867                --  checking. This is a bit dubious in terms of the formal
4868                --  language definition, but it is what is intended by RM
4869                --  H.4(12). Restriction_Warnings never affects generated code
4870                --  so this is done only in the real restriction case.
4871
4872                if R_Id = No_Exceptions and then not Warn then
4873                   Scope_Suppress := (others => True);
4874                end if;
4875
4876             --  Case of No_Dependence => unit-name. Note that the parser
4877             --  already made the necessary entry in the No_Dependence table.
4878
4879             elsif Id = Name_No_Dependence then
4880                Check_Unit_Name (Expr);
4881
4882             --  All other cases of restriction identifier present
4883
4884             else
4885                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
4886                Analyze_And_Resolve (Expr, Any_Integer);
4887
4888                if R_Id not in All_Parameter_Restrictions then
4889                   Error_Pragma_Arg
4890                     ("invalid restriction parameter identifier", Arg);
4891
4892                elsif not Is_OK_Static_Expression (Expr) then
4893                   Flag_Non_Static_Expr
4894                     ("value must be static expression!", Expr);
4895                   raise Pragma_Exit;
4896
4897                elsif not Is_Integer_Type (Etype (Expr))
4898                  or else Expr_Value (Expr) < 0
4899                then
4900                   Error_Pragma_Arg
4901                     ("value must be non-negative integer", Arg);
4902                end if;
4903
4904                --  Restriction pragma is active
4905
4906                Val := Expr_Value (Expr);
4907
4908                if not UI_Is_In_Int_Range (Val) then
4909                   Error_Pragma_Arg
4910                     ("pragma ignored, value too large?", Arg);
4911                end if;
4912
4913                --  Warning case. If the real restriction is active, then we
4914                --  ignore the request, since warning never overrides a real
4915                --  restriction. Otherwise we set the proper warning. Note that
4916                --  this circuit sets the warning again if it is already set,
4917                --  which is what we want, since the constant may have changed.
4918
4919                if Warn then
4920                   if not Restriction_Active (R_Id) then
4921                      Set_Restriction
4922                        (R_Id, N, Integer (UI_To_Int (Val)));
4923                      Restriction_Warnings (R_Id) := True;
4924                   end if;
4925
4926                --  Real restriction case, set restriction and make sure warning
4927                --  flag is off since real restriction always overrides warning.
4928
4929                else
4930                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
4931                   Restriction_Warnings (R_Id) := False;
4932                end if;
4933             end if;
4934
4935             Next (Arg);
4936          end loop;
4937       end Process_Restrictions_Or_Restriction_Warnings;
4938
4939       ---------------------------------
4940       -- Process_Suppress_Unsuppress --
4941       ---------------------------------
4942
4943       --  Note: this procedure makes entries in the check suppress data
4944       --  structures managed by Sem. See spec of package Sem for full
4945       --  details on how we handle recording of check suppression.
4946
4947       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
4948          C    : Check_Id;
4949          E_Id : Node_Id;
4950          E    : Entity_Id;
4951
4952          In_Package_Spec : constant Boolean :=
4953                              Is_Package_Or_Generic_Package (Current_Scope)
4954                                and then not In_Package_Body (Current_Scope);
4955
4956          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
4957          --  Used to suppress a single check on the given entity
4958
4959          --------------------------------
4960          -- Suppress_Unsuppress_Echeck --
4961          --------------------------------
4962
4963          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
4964          begin
4965             Set_Checks_May_Be_Suppressed (E);
4966
4967             if In_Package_Spec then
4968                Push_Global_Suppress_Stack_Entry
4969                  (Entity   => E,
4970                   Check    => C,
4971                   Suppress => Suppress_Case);
4972
4973             else
4974                Push_Local_Suppress_Stack_Entry
4975                  (Entity   => E,
4976                   Check    => C,
4977                   Suppress => Suppress_Case);
4978             end if;
4979
4980             --  If this is a first subtype, and the base type is distinct,
4981             --  then also set the suppress flags on the base type.
4982
4983             if Is_First_Subtype (E)
4984               and then Etype (E) /= E
4985             then
4986                Suppress_Unsuppress_Echeck (Etype (E), C);
4987             end if;
4988          end Suppress_Unsuppress_Echeck;
4989
4990       --  Start of processing for Process_Suppress_Unsuppress
4991
4992       begin
4993          --  Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
4994          --  we want to generate checks for analysis purposes, as set by -gnatC
4995
4996          if CodePeer_Mode and then Comes_From_Source (N) then
4997             return;
4998          end if;
4999
5000          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5001          --  declarative part or a package spec (RM 11.5(5)).
5002
5003          if not Is_Configuration_Pragma then
5004             Check_Is_In_Decl_Part_Or_Package_Spec;
5005          end if;
5006
5007          Check_At_Least_N_Arguments (1);
5008          Check_At_Most_N_Arguments (2);
5009          Check_No_Identifier (Arg1);
5010          Check_Arg_Is_Identifier (Arg1);
5011
5012          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5013
5014          if C = No_Check_Id then
5015             Error_Pragma_Arg
5016               ("argument of pragma% is not valid check name", Arg1);
5017          end if;
5018
5019          if not Suppress_Case
5020            and then (C = All_Checks or else C = Overflow_Check)
5021          then
5022             Opt.Overflow_Checks_Unsuppressed := True;
5023          end if;
5024
5025          if Arg_Count = 1 then
5026
5027             --  Make an entry in the local scope suppress table. This is the
5028             --  table that directly shows the current value of the scope
5029             --  suppress check for any check id value.
5030
5031             if C = All_Checks then
5032
5033                --  For All_Checks, we set all specific predefined checks with
5034                --  the exception of Elaboration_Check, which is handled
5035                --  specially because of not wanting All_Checks to have the
5036                --  effect of deactivating static elaboration order processing.
5037
5038                for J in Scope_Suppress'Range loop
5039                   if J /= Elaboration_Check then
5040                      Scope_Suppress (J) := Suppress_Case;
5041                   end if;
5042                end loop;
5043
5044             --  If not All_Checks, and predefined check, then set appropriate
5045             --  scope entry. Note that we will set Elaboration_Check if this
5046             --  is explicitly specified.
5047
5048             elsif C in Predefined_Check_Id then
5049                Scope_Suppress (C) := Suppress_Case;
5050             end if;
5051
5052             --  Also make an entry in the Local_Entity_Suppress table
5053
5054             Push_Local_Suppress_Stack_Entry
5055               (Entity   => Empty,
5056                Check    => C,
5057                Suppress => Suppress_Case);
5058
5059          --  Case of two arguments present, where the check is suppressed for
5060          --  a specified entity (given as the second argument of the pragma)
5061
5062          else
5063             --  This is obsolescent in Ada 2005 mode
5064
5065             if Ada_Version >= Ada_2005 then
5066                Check_Restriction (No_Obsolescent_Features, Arg2);
5067             end if;
5068
5069             Check_Optional_Identifier (Arg2, Name_On);
5070             E_Id := Get_Pragma_Arg (Arg2);
5071             Analyze (E_Id);
5072
5073             if not Is_Entity_Name (E_Id) then
5074                Error_Pragma_Arg
5075                  ("second argument of pragma% must be entity name", Arg2);
5076             end if;
5077
5078             E := Entity (E_Id);
5079
5080             if E = Any_Id then
5081                return;
5082             end if;
5083
5084             --  Enforce RM 11.5(7) which requires that for a pragma that
5085             --  appears within a package spec, the named entity must be
5086             --  within the package spec. We allow the package name itself
5087             --  to be mentioned since that makes sense, although it is not
5088             --  strictly allowed by 11.5(7).
5089
5090             if In_Package_Spec
5091               and then E /= Current_Scope
5092               and then Scope (E) /= Current_Scope
5093             then
5094                Error_Pragma_Arg
5095                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5096                   Arg2);
5097             end if;
5098
5099             --  Loop through homonyms. As noted below, in the case of a package
5100             --  spec, only homonyms within the package spec are considered.
5101
5102             loop
5103                Suppress_Unsuppress_Echeck (E, C);
5104
5105                if Is_Generic_Instance (E)
5106                  and then Is_Subprogram (E)
5107                  and then Present (Alias (E))
5108                then
5109                   Suppress_Unsuppress_Echeck (Alias (E), C);
5110                end if;
5111
5112                --  Move to next homonym if not aspect spec case
5113
5114                exit when From_Aspect_Specification (N);
5115                E := Homonym (E);
5116                exit when No (E);
5117
5118                --  If we are within a package specification, the pragma only
5119                --  applies to homonyms in the same scope.
5120
5121                exit when In_Package_Spec
5122                  and then Scope (E) /= Current_Scope;
5123             end loop;
5124          end if;
5125       end Process_Suppress_Unsuppress;
5126
5127       ------------------
5128       -- Set_Exported --
5129       ------------------
5130
5131       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5132       begin
5133          if Is_Imported (E) then
5134             Error_Pragma_Arg
5135               ("cannot export entity& that was previously imported", Arg);
5136
5137          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5138             Error_Pragma_Arg
5139               ("cannot export entity& that has an address clause", Arg);
5140          end if;
5141
5142          Set_Is_Exported (E);
5143
5144          --  Generate a reference for entity explicitly, because the
5145          --  identifier may be overloaded and name resolution will not
5146          --  generate one.
5147
5148          Generate_Reference (E, Arg);
5149
5150          --  Deal with exporting non-library level entity
5151
5152          if not Is_Library_Level_Entity (E) then
5153
5154             --  Not allowed at all for subprograms
5155
5156             if Is_Subprogram (E) then
5157                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5158
5159             --  Otherwise set public and statically allocated
5160
5161             else
5162                Set_Is_Public (E);
5163                Set_Is_Statically_Allocated (E);
5164
5165                --  Warn if the corresponding W flag is set and the pragma comes
5166                --  from source. The latter may not be true e.g. on VMS where we
5167                --  expand export pragmas for exception codes associated with
5168                --  imported or exported exceptions. We do not want to generate
5169                --  a warning for something that the user did not write.
5170
5171                if Warn_On_Export_Import
5172                  and then Comes_From_Source (Arg)
5173                then
5174                   Error_Msg_NE
5175                     ("?& has been made static as a result of Export", Arg, E);
5176                   Error_Msg_N
5177                     ("\this usage is non-standard and non-portable", Arg);
5178                end if;
5179             end if;
5180          end if;
5181
5182          if Warn_On_Export_Import and then Is_Type (E) then
5183             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5184          end if;
5185
5186          if Warn_On_Export_Import and Inside_A_Generic then
5187             Error_Msg_NE
5188               ("all instances of& will have the same external name?", Arg, E);
5189          end if;
5190       end Set_Exported;
5191
5192       ----------------------------------------------
5193       -- Set_Extended_Import_Export_External_Name --
5194       ----------------------------------------------
5195
5196       procedure Set_Extended_Import_Export_External_Name
5197         (Internal_Ent : Entity_Id;
5198          Arg_External : Node_Id)
5199       is
5200          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5201          New_Name : Node_Id;
5202
5203       begin
5204          if No (Arg_External) then
5205             return;
5206          end if;
5207
5208          Check_Arg_Is_External_Name (Arg_External);
5209
5210          if Nkind (Arg_External) = N_String_Literal then
5211             if String_Length (Strval (Arg_External)) = 0 then
5212                return;
5213             else
5214                New_Name := Adjust_External_Name_Case (Arg_External);
5215             end if;
5216
5217          elsif Nkind (Arg_External) = N_Identifier then
5218             New_Name := Get_Default_External_Name (Arg_External);
5219
5220          --  Check_Arg_Is_External_Name should let through only identifiers and
5221          --  string literals or static string expressions (which are folded to
5222          --  string literals).
5223
5224          else
5225             raise Program_Error;
5226          end if;
5227
5228          --  If we already have an external name set (by a prior normal Import
5229          --  or Export pragma), then the external names must match
5230
5231          if Present (Interface_Name (Internal_Ent)) then
5232             Check_Matching_Internal_Names : declare
5233                S1 : constant String_Id := Strval (Old_Name);
5234                S2 : constant String_Id := Strval (New_Name);
5235
5236                procedure Mismatch;
5237                --  Called if names do not match
5238
5239                --------------
5240                -- Mismatch --
5241                --------------
5242
5243                procedure Mismatch is
5244                begin
5245                   Error_Msg_Sloc := Sloc (Old_Name);
5246                   Error_Pragma_Arg
5247                     ("external name does not match that given #",
5248                      Arg_External);
5249                end Mismatch;
5250
5251             --  Start of processing for Check_Matching_Internal_Names
5252
5253             begin
5254                if String_Length (S1) /= String_Length (S2) then
5255                   Mismatch;
5256
5257                else
5258                   for J in 1 .. String_Length (S1) loop
5259                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5260                         Mismatch;
5261                      end if;
5262                   end loop;
5263                end if;
5264             end Check_Matching_Internal_Names;
5265
5266          --  Otherwise set the given name
5267
5268          else
5269             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5270             Check_Duplicated_Export_Name (New_Name);
5271          end if;
5272       end Set_Extended_Import_Export_External_Name;
5273
5274       ------------------
5275       -- Set_Imported --
5276       ------------------
5277
5278       procedure Set_Imported (E : Entity_Id) is
5279       begin
5280          --  Error message if already imported or exported
5281
5282          if Is_Exported (E) or else Is_Imported (E) then
5283
5284             --  Error if being set Exported twice
5285
5286             if Is_Exported (E) then
5287                Error_Msg_NE ("entity& was previously exported", N, E);
5288
5289             --  OK if Import/Interface case
5290
5291             elsif Import_Interface_Present (N) then
5292                goto OK;
5293
5294             --  Error if being set Imported twice
5295
5296             else
5297                Error_Msg_NE ("entity& was previously imported", N, E);
5298             end if;
5299
5300             Error_Msg_Name_1 := Pname;
5301             Error_Msg_N
5302               ("\(pragma% applies to all previous entities)", N);
5303
5304             Error_Msg_Sloc  := Sloc (E);
5305             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5306
5307          --  Here if not previously imported or exported, OK to import
5308
5309          else
5310             Set_Is_Imported (E);
5311
5312             --  If the entity is an object that is not at the library level,
5313             --  then it is statically allocated. We do not worry about objects
5314             --  with address clauses in this context since they are not really
5315             --  imported in the linker sense.
5316
5317             if Is_Object (E)
5318               and then not Is_Library_Level_Entity (E)
5319               and then No (Address_Clause (E))
5320             then
5321                Set_Is_Statically_Allocated (E);
5322             end if;
5323          end if;
5324
5325          <<OK>> null;
5326       end Set_Imported;
5327
5328       -------------------------
5329       -- Set_Mechanism_Value --
5330       -------------------------
5331
5332       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5333       --  analyzed, since it is semantic nonsense), so we get it in the exact
5334       --  form created by the parser.
5335
5336       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5337          Class        : Node_Id;
5338          Param        : Node_Id;
5339          Mech_Name_Id : Name_Id;
5340
5341          procedure Bad_Class;
5342          --  Signal bad descriptor class name
5343
5344          procedure Bad_Mechanism;
5345          --  Signal bad mechanism name
5346
5347          ---------------
5348          -- Bad_Class --
5349          ---------------
5350
5351          procedure Bad_Class is
5352          begin
5353             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5354          end Bad_Class;
5355
5356          -------------------------
5357          -- Bad_Mechanism_Value --
5358          -------------------------
5359
5360          procedure Bad_Mechanism is
5361          begin
5362             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5363          end Bad_Mechanism;
5364
5365       --  Start of processing for Set_Mechanism_Value
5366
5367       begin
5368          if Mechanism (Ent) /= Default_Mechanism then
5369             Error_Msg_NE
5370               ("mechanism for & has already been set", Mech_Name, Ent);
5371          end if;
5372
5373          --  MECHANISM_NAME ::= value | reference | descriptor |
5374          --                     short_descriptor
5375
5376          if Nkind (Mech_Name) = N_Identifier then
5377             if Chars (Mech_Name) = Name_Value then
5378                Set_Mechanism (Ent, By_Copy);
5379                return;
5380
5381             elsif Chars (Mech_Name) = Name_Reference then
5382                Set_Mechanism (Ent, By_Reference);
5383                return;
5384
5385             elsif Chars (Mech_Name) = Name_Descriptor then
5386                Check_VMS (Mech_Name);
5387
5388                --  Descriptor => Short_Descriptor if pragma was given
5389
5390                if Short_Descriptors then
5391                   Set_Mechanism (Ent, By_Short_Descriptor);
5392                else
5393                   Set_Mechanism (Ent, By_Descriptor);
5394                end if;
5395
5396                return;
5397
5398             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5399                Check_VMS (Mech_Name);
5400                Set_Mechanism (Ent, By_Short_Descriptor);
5401                return;
5402
5403             elsif Chars (Mech_Name) = Name_Copy then
5404                Error_Pragma_Arg
5405                  ("bad mechanism name, Value assumed", Mech_Name);
5406
5407             else
5408                Bad_Mechanism;
5409             end if;
5410
5411          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5412          --                     short_descriptor (CLASS_NAME)
5413          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5414
5415          --  Note: this form is parsed as an indexed component
5416
5417          elsif Nkind (Mech_Name) = N_Indexed_Component then
5418             Class := First (Expressions (Mech_Name));
5419
5420             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5421              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5422                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5423              or else Present (Next (Class))
5424             then
5425                Bad_Mechanism;
5426             else
5427                Mech_Name_Id := Chars (Prefix (Mech_Name));
5428
5429                --  Change Descriptor => Short_Descriptor if pragma was given
5430
5431                if Mech_Name_Id = Name_Descriptor
5432                  and then Short_Descriptors
5433                then
5434                   Mech_Name_Id := Name_Short_Descriptor;
5435                end if;
5436             end if;
5437
5438          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5439          --                     short_descriptor (Class => CLASS_NAME)
5440          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5441
5442          --  Note: this form is parsed as a function call
5443
5444          elsif Nkind (Mech_Name) = N_Function_Call then
5445             Param := First (Parameter_Associations (Mech_Name));
5446
5447             if Nkind (Name (Mech_Name)) /= N_Identifier
5448               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5449                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5450               or else Present (Next (Param))
5451               or else No (Selector_Name (Param))
5452               or else Chars (Selector_Name (Param)) /= Name_Class
5453             then
5454                Bad_Mechanism;
5455             else
5456                Class := Explicit_Actual_Parameter (Param);
5457                Mech_Name_Id := Chars (Name (Mech_Name));
5458             end if;
5459
5460          else
5461             Bad_Mechanism;
5462          end if;
5463
5464          --  Fall through here with Class set to descriptor class name
5465
5466          Check_VMS (Mech_Name);
5467
5468          if Nkind (Class) /= N_Identifier then
5469             Bad_Class;
5470
5471          elsif Mech_Name_Id = Name_Descriptor
5472            and then Chars (Class) = Name_UBS
5473          then
5474             Set_Mechanism (Ent, By_Descriptor_UBS);
5475
5476          elsif Mech_Name_Id = Name_Descriptor
5477            and then Chars (Class) = Name_UBSB
5478          then
5479             Set_Mechanism (Ent, By_Descriptor_UBSB);
5480
5481          elsif Mech_Name_Id = Name_Descriptor
5482            and then Chars (Class) = Name_UBA
5483          then
5484             Set_Mechanism (Ent, By_Descriptor_UBA);
5485
5486          elsif Mech_Name_Id = Name_Descriptor
5487            and then Chars (Class) = Name_S
5488          then
5489             Set_Mechanism (Ent, By_Descriptor_S);
5490
5491          elsif Mech_Name_Id = Name_Descriptor
5492            and then Chars (Class) = Name_SB
5493          then
5494             Set_Mechanism (Ent, By_Descriptor_SB);
5495
5496          elsif Mech_Name_Id = Name_Descriptor
5497            and then Chars (Class) = Name_A
5498          then
5499             Set_Mechanism (Ent, By_Descriptor_A);
5500
5501          elsif Mech_Name_Id = Name_Descriptor
5502            and then Chars (Class) = Name_NCA
5503          then
5504             Set_Mechanism (Ent, By_Descriptor_NCA);
5505
5506          elsif Mech_Name_Id = Name_Short_Descriptor
5507            and then Chars (Class) = Name_UBS
5508          then
5509             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5510
5511          elsif Mech_Name_Id = Name_Short_Descriptor
5512            and then Chars (Class) = Name_UBSB
5513          then
5514             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5515
5516          elsif Mech_Name_Id = Name_Short_Descriptor
5517            and then Chars (Class) = Name_UBA
5518          then
5519             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5520
5521          elsif Mech_Name_Id = Name_Short_Descriptor
5522            and then Chars (Class) = Name_S
5523          then
5524             Set_Mechanism (Ent, By_Short_Descriptor_S);
5525
5526          elsif Mech_Name_Id = Name_Short_Descriptor
5527            and then Chars (Class) = Name_SB
5528          then
5529             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5530
5531          elsif Mech_Name_Id = Name_Short_Descriptor
5532            and then Chars (Class) = Name_A
5533          then
5534             Set_Mechanism (Ent, By_Short_Descriptor_A);
5535
5536          elsif Mech_Name_Id = Name_Short_Descriptor
5537            and then Chars (Class) = Name_NCA
5538          then
5539             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5540
5541          else
5542             Bad_Class;
5543          end if;
5544       end Set_Mechanism_Value;
5545
5546       ---------------------------
5547       -- Set_Ravenscar_Profile --
5548       ---------------------------
5549
5550       --  The tasks to be done here are
5551
5552       --    Set required policies
5553
5554       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5555       --      pragma Locking_Policy (Ceiling_Locking)
5556
5557       --    Set Detect_Blocking mode
5558
5559       --    Set required restrictions (see System.Rident for detailed list)
5560
5561       --    Set the No_Dependence rules
5562       --      No_Dependence => Ada.Asynchronous_Task_Control
5563       --      No_Dependence => Ada.Calendar
5564       --      No_Dependence => Ada.Execution_Time.Group_Budget
5565       --      No_Dependence => Ada.Execution_Time.Timers
5566       --      No_Dependence => Ada.Task_Attributes
5567       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
5568
5569       procedure Set_Ravenscar_Profile (N : Node_Id) is
5570          Prefix_Entity   : Entity_Id;
5571          Selector_Entity : Entity_Id;
5572          Prefix_Node     : Node_Id;
5573          Node            : Node_Id;
5574
5575       begin
5576          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5577
5578          if Task_Dispatching_Policy /= ' '
5579            and then Task_Dispatching_Policy /= 'F'
5580          then
5581             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5582             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5583
5584          --  Set the FIFO_Within_Priorities policy, but always preserve
5585          --  System_Location since we like the error message with the run time
5586          --  name.
5587
5588          else
5589             Task_Dispatching_Policy := 'F';
5590
5591             if Task_Dispatching_Policy_Sloc /= System_Location then
5592                Task_Dispatching_Policy_Sloc := Loc;
5593             end if;
5594          end if;
5595
5596          --  pragma Locking_Policy (Ceiling_Locking)
5597
5598          if Locking_Policy /= ' '
5599            and then Locking_Policy /= 'C'
5600          then
5601             Error_Msg_Sloc := Locking_Policy_Sloc;
5602             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5603
5604          --  Set the Ceiling_Locking policy, but preserve System_Location since
5605          --  we like the error message with the run time name.
5606
5607          else
5608             Locking_Policy := 'C';
5609
5610             if Locking_Policy_Sloc /= System_Location then
5611                Locking_Policy_Sloc := Loc;
5612             end if;
5613          end if;
5614
5615          --  pragma Detect_Blocking
5616
5617          Detect_Blocking := True;
5618
5619          --  Set the corresponding restrictions
5620
5621          Set_Profile_Restrictions
5622            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5623
5624          --  Set the No_Dependence restrictions
5625
5626          --  The following No_Dependence restrictions:
5627          --    No_Dependence => Ada.Asynchronous_Task_Control
5628          --    No_Dependence => Ada.Calendar
5629          --    No_Dependence => Ada.Task_Attributes
5630          --  are already set by previous call to Set_Profile_Restrictions.
5631
5632          --  Set the following restrictions which were added to Ada 2005:
5633          --    No_Dependence => Ada.Execution_Time.Group_Budget
5634          --    No_Dependence => Ada.Execution_Time.Timers
5635
5636          if Ada_Version >= Ada_2005 then
5637             Name_Buffer (1 .. 3) := "ada";
5638             Name_Len := 3;
5639
5640             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5641
5642             Name_Buffer (1 .. 14) := "execution_time";
5643             Name_Len := 14;
5644
5645             Selector_Entity := Make_Identifier (Loc, Name_Find);
5646
5647             Prefix_Node :=
5648               Make_Selected_Component
5649                 (Sloc          => Loc,
5650                  Prefix        => Prefix_Entity,
5651                  Selector_Name => Selector_Entity);
5652
5653             Name_Buffer (1 .. 13) := "group_budgets";
5654             Name_Len := 13;
5655
5656             Selector_Entity := Make_Identifier (Loc, Name_Find);
5657
5658             Node :=
5659               Make_Selected_Component
5660                 (Sloc          => Loc,
5661                  Prefix        => Prefix_Node,
5662                  Selector_Name => Selector_Entity);
5663
5664             Set_Restriction_No_Dependence
5665               (Unit    => Node,
5666                Warn    => Treat_Restrictions_As_Warnings,
5667                Profile => Ravenscar);
5668
5669             Name_Buffer (1 .. 6) := "timers";
5670             Name_Len := 6;
5671
5672             Selector_Entity := Make_Identifier (Loc, Name_Find);
5673
5674             Node :=
5675               Make_Selected_Component
5676                 (Sloc          => Loc,
5677                  Prefix        => Prefix_Node,
5678                  Selector_Name => Selector_Entity);
5679
5680             Set_Restriction_No_Dependence
5681               (Unit    => Node,
5682                Warn    => Treat_Restrictions_As_Warnings,
5683                Profile => Ravenscar);
5684          end if;
5685
5686          --  Set the following restrictions which was added to Ada 2012 (see
5687          --  AI-0171):
5688          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
5689
5690          if Ada_Version >= Ada_2012 then
5691             Name_Buffer (1 .. 6) := "system";
5692             Name_Len := 6;
5693
5694             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5695
5696             Name_Buffer (1 .. 15) := "multiprocessors";
5697             Name_Len := 15;
5698
5699             Selector_Entity := Make_Identifier (Loc, Name_Find);
5700
5701             Prefix_Node :=
5702               Make_Selected_Component
5703                 (Sloc          => Loc,
5704                  Prefix        => Prefix_Entity,
5705                  Selector_Name => Selector_Entity);
5706
5707             Name_Buffer (1 .. 19) := "dispatching_domains";
5708             Name_Len := 19;
5709
5710             Selector_Entity := Make_Identifier (Loc, Name_Find);
5711
5712             Node :=
5713               Make_Selected_Component
5714                 (Sloc          => Loc,
5715                  Prefix        => Prefix_Node,
5716                  Selector_Name => Selector_Entity);
5717
5718             Set_Restriction_No_Dependence
5719               (Unit    => Node,
5720                Warn    => Treat_Restrictions_As_Warnings,
5721                Profile => Ravenscar);
5722          end if;
5723       end Set_Ravenscar_Profile;
5724
5725    --  Start of processing for Analyze_Pragma
5726
5727    begin
5728       --  The following code is a defense against recursion. Not clear that
5729       --  this can happen legitimately, but perhaps some error situations
5730       --  can cause it, and we did see this recursion during testing.
5731
5732       if Analyzed (N) then
5733          return;
5734       else
5735          Set_Analyzed (N, True);
5736       end if;
5737
5738       --  Deal with unrecognized pragma
5739
5740       if not Is_Pragma_Name (Pname) then
5741          if Warn_On_Unrecognized_Pragma then
5742             Error_Msg_Name_1 := Pname;
5743             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
5744
5745             for PN in First_Pragma_Name .. Last_Pragma_Name loop
5746                if Is_Bad_Spelling_Of (Pname, PN) then
5747                   Error_Msg_Name_1 := PN;
5748                   Error_Msg_N -- CODEFIX
5749                     ("\?possible misspelling of %!", Pragma_Identifier (N));
5750                   exit;
5751                end if;
5752             end loop;
5753          end if;
5754
5755          return;
5756       end if;
5757
5758       --  Here to start processing for recognized pragma
5759
5760       Prag_Id := Get_Pragma_Id (Pname);
5761
5762       --  Preset arguments
5763
5764       Arg_Count := 0;
5765       Arg1      := Empty;
5766       Arg2      := Empty;
5767       Arg3      := Empty;
5768       Arg4      := Empty;
5769
5770       if Present (Pragma_Argument_Associations (N)) then
5771          Arg_Count := List_Length (Pragma_Argument_Associations (N));
5772          Arg1 := First (Pragma_Argument_Associations (N));
5773
5774          if Present (Arg1) then
5775             Arg2 := Next (Arg1);
5776
5777             if Present (Arg2) then
5778                Arg3 := Next (Arg2);
5779
5780                if Present (Arg3) then
5781                   Arg4 := Next (Arg3);
5782                end if;
5783             end if;
5784          end if;
5785       end if;
5786
5787       --  An enumeration type defines the pragmas that are supported by the
5788       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
5789       --  into the corresponding enumeration value for the following case.
5790
5791       case Prag_Id is
5792
5793          -----------------
5794          -- Abort_Defer --
5795          -----------------
5796
5797          --  pragma Abort_Defer;
5798
5799          when Pragma_Abort_Defer =>
5800             GNAT_Pragma;
5801             Check_Arg_Count (0);
5802
5803             --  The only required semantic processing is to check the
5804             --  placement. This pragma must appear at the start of the
5805             --  statement sequence of a handled sequence of statements.
5806
5807             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
5808               or else N /= First (Statements (Parent (N)))
5809             then
5810                Pragma_Misplaced;
5811             end if;
5812
5813          ------------
5814          -- Ada_83 --
5815          ------------
5816
5817          --  pragma Ada_83;
5818
5819          --  Note: this pragma also has some specific processing in Par.Prag
5820          --  because we want to set the Ada version mode during parsing.
5821
5822          when Pragma_Ada_83 =>
5823             GNAT_Pragma;
5824             Check_Arg_Count (0);
5825
5826             --  We really should check unconditionally for proper configuration
5827             --  pragma placement, since we really don't want mixed Ada modes
5828             --  within a single unit, and the GNAT reference manual has always
5829             --  said this was a configuration pragma, but we did not check and
5830             --  are hesitant to add the check now.
5831
5832             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
5833             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
5834             --  or Ada 2012 mode.
5835
5836             if Ada_Version >= Ada_2005 then
5837                Check_Valid_Configuration_Pragma;
5838             end if;
5839
5840             --  Now set Ada 83 mode
5841
5842             Ada_Version := Ada_83;
5843             Ada_Version_Explicit := Ada_Version;
5844
5845          ------------
5846          -- Ada_95 --
5847          ------------
5848
5849          --  pragma Ada_95;
5850
5851          --  Note: this pragma also has some specific processing in Par.Prag
5852          --  because we want to set the Ada 83 version mode during parsing.
5853
5854          when Pragma_Ada_95 =>
5855             GNAT_Pragma;
5856             Check_Arg_Count (0);
5857
5858             --  We really should check unconditionally for proper configuration
5859             --  pragma placement, since we really don't want mixed Ada modes
5860             --  within a single unit, and the GNAT reference manual has always
5861             --  said this was a configuration pragma, but we did not check and
5862             --  are hesitant to add the check now.
5863
5864             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
5865             --  or Ada 95, so we must check if we are in Ada 2005 mode.
5866
5867             if Ada_Version >= Ada_2005 then
5868                Check_Valid_Configuration_Pragma;
5869             end if;
5870
5871             --  Now set Ada 95 mode
5872
5873             Ada_Version := Ada_95;
5874             Ada_Version_Explicit := Ada_Version;
5875
5876          ---------------------
5877          -- Ada_05/Ada_2005 --
5878          ---------------------
5879
5880          --  pragma Ada_05;
5881          --  pragma Ada_05 (LOCAL_NAME);
5882
5883          --  pragma Ada_2005;
5884          --  pragma Ada_2005 (LOCAL_NAME):
5885
5886          --  Note: these pragmas also have some specific processing in Par.Prag
5887          --  because we want to set the Ada 2005 version mode during parsing.
5888
5889          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
5890             E_Id : Node_Id;
5891
5892          begin
5893             GNAT_Pragma;
5894
5895             if Arg_Count = 1 then
5896                Check_Arg_Is_Local_Name (Arg1);
5897                E_Id := Get_Pragma_Arg (Arg1);
5898
5899                if Etype (E_Id) = Any_Type then
5900                   return;
5901                end if;
5902
5903                Set_Is_Ada_2005_Only (Entity (E_Id));
5904
5905             else
5906                Check_Arg_Count (0);
5907
5908                --  For Ada_2005 we unconditionally enforce the documented
5909                --  configuration pragma placement, since we do not want to
5910                --  tolerate mixed modes in a unit involving Ada 2005. That
5911                --  would cause real difficulties for those cases where there
5912                --  are incompatibilities between Ada 95 and Ada 2005.
5913
5914                Check_Valid_Configuration_Pragma;
5915
5916                --  Now set appropriate Ada mode
5917
5918                Ada_Version          := Ada_2005;
5919                Ada_Version_Explicit := Ada_2005;
5920             end if;
5921          end;
5922
5923          ---------------------
5924          -- Ada_12/Ada_2012 --
5925          ---------------------
5926
5927          --  pragma Ada_12;
5928          --  pragma Ada_12 (LOCAL_NAME);
5929
5930          --  pragma Ada_2012;
5931          --  pragma Ada_2012 (LOCAL_NAME):
5932
5933          --  Note: these pragmas also have some specific processing in Par.Prag
5934          --  because we want to set the Ada 2012 version mode during parsing.
5935
5936          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
5937             E_Id : Node_Id;
5938
5939          begin
5940             GNAT_Pragma;
5941
5942             if Arg_Count = 1 then
5943                Check_Arg_Is_Local_Name (Arg1);
5944                E_Id := Get_Pragma_Arg (Arg1);
5945
5946                if Etype (E_Id) = Any_Type then
5947                   return;
5948                end if;
5949
5950                Set_Is_Ada_2012_Only (Entity (E_Id));
5951
5952             else
5953                Check_Arg_Count (0);
5954
5955                --  For Ada_2012 we unconditionally enforce the documented
5956                --  configuration pragma placement, since we do not want to
5957                --  tolerate mixed modes in a unit involving Ada 2012. That
5958                --  would cause real difficulties for those cases where there
5959                --  are incompatibilities between Ada 95 and Ada 2012. We could
5960                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
5961
5962                Check_Valid_Configuration_Pragma;
5963
5964                --  Now set appropriate Ada mode
5965
5966                Ada_Version          := Ada_2012;
5967                Ada_Version_Explicit := Ada_2012;
5968             end if;
5969          end;
5970
5971          ----------------------
5972          -- All_Calls_Remote --
5973          ----------------------
5974
5975          --  pragma All_Calls_Remote [(library_package_NAME)];
5976
5977          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
5978             Lib_Entity : Entity_Id;
5979
5980          begin
5981             Check_Ada_83_Warning;
5982             Check_Valid_Library_Unit_Pragma;
5983
5984             if Nkind (N) = N_Null_Statement then
5985                return;
5986             end if;
5987
5988             Lib_Entity := Find_Lib_Unit_Name;
5989
5990             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
5991
5992             if Present (Lib_Entity)
5993               and then not Debug_Flag_U
5994             then
5995                if not Is_Remote_Call_Interface (Lib_Entity) then
5996                   Error_Pragma ("pragma% only apply to rci unit");
5997
5998                --  Set flag for entity of the library unit
5999
6000                else
6001                   Set_Has_All_Calls_Remote (Lib_Entity);
6002                end if;
6003
6004             end if;
6005          end All_Calls_Remote;
6006
6007          --------------
6008          -- Annotate --
6009          --------------
6010
6011          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6012          --  ARG ::= NAME | EXPRESSION
6013
6014          --  The first two arguments are by convention intended to refer to an
6015          --  external tool and a tool-specific function. These arguments are
6016          --  not analyzed.
6017
6018          when Pragma_Annotate => Annotate : begin
6019             GNAT_Pragma;
6020             Check_At_Least_N_Arguments (1);
6021             Check_Arg_Is_Identifier (Arg1);
6022             Check_No_Identifiers;
6023             Store_Note (N);
6024
6025             declare
6026                Arg : Node_Id;
6027                Exp : Node_Id;
6028
6029             begin
6030                --  Second unanalyzed parameter is optional
6031
6032                if No (Arg2) then
6033                   null;
6034                else
6035                   Arg := Next (Arg2);
6036                   while Present (Arg) loop
6037                      Exp := Get_Pragma_Arg (Arg);
6038                      Analyze (Exp);
6039
6040                      if Is_Entity_Name (Exp) then
6041                         null;
6042
6043                      --  For string literals, we assume Standard_String as the
6044                      --  type, unless the string contains wide or wide_wide
6045                      --  characters.
6046
6047                      elsif Nkind (Exp) = N_String_Literal then
6048                         if Has_Wide_Wide_Character (Exp) then
6049                            Resolve (Exp, Standard_Wide_Wide_String);
6050                         elsif Has_Wide_Character (Exp) then
6051                            Resolve (Exp, Standard_Wide_String);
6052                         else
6053                            Resolve (Exp, Standard_String);
6054                         end if;
6055
6056                      elsif Is_Overloaded (Exp) then
6057                            Error_Pragma_Arg
6058                              ("ambiguous argument for pragma%", Exp);
6059
6060                      else
6061                         Resolve (Exp);
6062                      end if;
6063
6064                      Next (Arg);
6065                   end loop;
6066                end if;
6067             end;
6068          end Annotate;
6069
6070          ------------
6071          -- Assert --
6072          ------------
6073
6074          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6075          --                 [, [Message =>] Static_String_EXPRESSION]);
6076
6077          when Pragma_Assert => Assert : declare
6078             Expr : Node_Id;
6079             Newa : List_Id;
6080
6081          begin
6082             Ada_2005_Pragma;
6083             Check_At_Least_N_Arguments (1);
6084             Check_At_Most_N_Arguments (2);
6085             Check_Arg_Order ((Name_Check, Name_Message));
6086             Check_Optional_Identifier (Arg1, Name_Check);
6087
6088             --  We treat pragma Assert as equivalent to:
6089
6090             --    pragma Check (Assertion, condition [, msg]);
6091
6092             --  So rewrite pragma in this manner, and analyze the result
6093
6094             Expr := Get_Pragma_Arg (Arg1);
6095             Newa := New_List (
6096               Make_Pragma_Argument_Association (Loc,
6097                 Expression => Make_Identifier (Loc, Name_Assertion)),
6098
6099               Make_Pragma_Argument_Association (Sloc (Expr),
6100                 Expression => Expr));
6101
6102             if Arg_Count > 1 then
6103                Check_Optional_Identifier (Arg2, Name_Message);
6104                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6105                Append_To (Newa, Relocate_Node (Arg2));
6106             end if;
6107
6108             Rewrite (N,
6109               Make_Pragma (Loc,
6110                 Chars => Name_Check,
6111                 Pragma_Argument_Associations => Newa));
6112             Analyze (N);
6113          end Assert;
6114
6115          ----------------------
6116          -- Assertion_Policy --
6117          ----------------------
6118
6119          --  pragma Assertion_Policy (Check | Ignore)
6120
6121          when Pragma_Assertion_Policy => Assertion_Policy : declare
6122             Policy : Node_Id;
6123
6124          begin
6125             Ada_2005_Pragma;
6126             Check_Valid_Configuration_Pragma;
6127             Check_Arg_Count (1);
6128             Check_No_Identifiers;
6129             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6130
6131             --  We treat pragma Assertion_Policy as equivalent to:
6132
6133             --    pragma Check_Policy (Assertion, policy)
6134
6135             --  So rewrite the pragma in that manner and link on to the chain
6136             --  of Check_Policy pragmas, marking the pragma as analyzed.
6137
6138             Policy := Get_Pragma_Arg (Arg1);
6139
6140             Rewrite (N,
6141               Make_Pragma (Loc,
6142                 Chars => Name_Check_Policy,
6143
6144                 Pragma_Argument_Associations => New_List (
6145                   Make_Pragma_Argument_Association (Loc,
6146                     Expression => Make_Identifier (Loc, Name_Assertion)),
6147
6148                   Make_Pragma_Argument_Association (Loc,
6149                     Expression =>
6150                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6151
6152             Set_Analyzed (N);
6153             Set_Next_Pragma (N, Opt.Check_Policy_List);
6154             Opt.Check_Policy_List := N;
6155          end Assertion_Policy;
6156
6157          ------------------------------
6158          -- Assume_No_Invalid_Values --
6159          ------------------------------
6160
6161          --  pragma Assume_No_Invalid_Values (On | Off);
6162
6163          when Pragma_Assume_No_Invalid_Values =>
6164             GNAT_Pragma;
6165             Check_Valid_Configuration_Pragma;
6166             Check_Arg_Count (1);
6167             Check_No_Identifiers;
6168             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6169
6170             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6171                Assume_No_Invalid_Values := True;
6172             else
6173                Assume_No_Invalid_Values := False;
6174             end if;
6175
6176          ---------------
6177          -- AST_Entry --
6178          ---------------
6179
6180          --  pragma AST_Entry (entry_IDENTIFIER);
6181
6182          when Pragma_AST_Entry => AST_Entry : declare
6183             Ent : Node_Id;
6184
6185          begin
6186             GNAT_Pragma;
6187             Check_VMS (N);
6188             Check_Arg_Count (1);
6189             Check_No_Identifiers;
6190             Check_Arg_Is_Local_Name (Arg1);
6191             Ent := Entity (Get_Pragma_Arg (Arg1));
6192
6193             --  Note: the implementation of the AST_Entry pragma could handle
6194             --  the entry family case fine, but for now we are consistent with
6195             --  the DEC rules, and do not allow the pragma, which of course
6196             --  has the effect of also forbidding the attribute.
6197
6198             if Ekind (Ent) /= E_Entry then
6199                Error_Pragma_Arg
6200                  ("pragma% argument must be simple entry name", Arg1);
6201
6202             elsif Is_AST_Entry (Ent) then
6203                Error_Pragma_Arg
6204                  ("duplicate % pragma for entry", Arg1);
6205
6206             elsif Has_Homonym (Ent) then
6207                Error_Pragma_Arg
6208                  ("pragma% argument cannot specify overloaded entry", Arg1);
6209
6210             else
6211                declare
6212                   FF : constant Entity_Id := First_Formal (Ent);
6213
6214                begin
6215                   if Present (FF) then
6216                      if Present (Next_Formal (FF)) then
6217                         Error_Pragma_Arg
6218                           ("entry for pragma% can have only one argument",
6219                            Arg1);
6220
6221                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6222                         Error_Pragma_Arg
6223                           ("entry parameter for pragma% must have mode IN",
6224                            Arg1);
6225                      end if;
6226                   end if;
6227                end;
6228
6229                Set_Is_AST_Entry (Ent);
6230             end if;
6231          end AST_Entry;
6232
6233          ------------------
6234          -- Asynchronous --
6235          ------------------
6236
6237          --  pragma Asynchronous (LOCAL_NAME);
6238
6239          when Pragma_Asynchronous => Asynchronous : declare
6240             Nm     : Entity_Id;
6241             C_Ent  : Entity_Id;
6242             L      : List_Id;
6243             S      : Node_Id;
6244             N      : Node_Id;
6245             Formal : Entity_Id;
6246
6247             procedure Process_Async_Pragma;
6248             --  Common processing for procedure and access-to-procedure case
6249
6250             --------------------------
6251             -- Process_Async_Pragma --
6252             --------------------------
6253
6254             procedure Process_Async_Pragma is
6255             begin
6256                if No (L) then
6257                   Set_Is_Asynchronous (Nm);
6258                   return;
6259                end if;
6260
6261                --  The formals should be of mode IN (RM E.4.1(6))
6262
6263                S := First (L);
6264                while Present (S) loop
6265                   Formal := Defining_Identifier (S);
6266
6267                   if Nkind (Formal) = N_Defining_Identifier
6268                     and then Ekind (Formal) /= E_In_Parameter
6269                   then
6270                      Error_Pragma_Arg
6271                        ("pragma% procedure can only have IN parameter",
6272                         Arg1);
6273                   end if;
6274
6275                   Next (S);
6276                end loop;
6277
6278                Set_Is_Asynchronous (Nm);
6279             end Process_Async_Pragma;
6280
6281          --  Start of processing for pragma Asynchronous
6282
6283          begin
6284             Check_Ada_83_Warning;
6285             Check_No_Identifiers;
6286             Check_Arg_Count (1);
6287             Check_Arg_Is_Local_Name (Arg1);
6288
6289             if Debug_Flag_U then
6290                return;
6291             end if;
6292
6293             C_Ent := Cunit_Entity (Current_Sem_Unit);
6294             Analyze (Get_Pragma_Arg (Arg1));
6295             Nm := Entity (Get_Pragma_Arg (Arg1));
6296
6297             if not Is_Remote_Call_Interface (C_Ent)
6298               and then not Is_Remote_Types (C_Ent)
6299             then
6300                --  This pragma should only appear in an RCI or Remote Types
6301                --  unit (RM E.4.1(4)).
6302
6303                Error_Pragma
6304                  ("pragma% not in Remote_Call_Interface or " &
6305                   "Remote_Types unit");
6306             end if;
6307
6308             if Ekind (Nm) = E_Procedure
6309               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6310             then
6311                if not Is_Remote_Call_Interface (Nm) then
6312                   Error_Pragma_Arg
6313                     ("pragma% cannot be applied on non-remote procedure",
6314                      Arg1);
6315                end if;
6316
6317                L := Parameter_Specifications (Parent (Nm));
6318                Process_Async_Pragma;
6319                return;
6320
6321             elsif Ekind (Nm) = E_Function then
6322                Error_Pragma_Arg
6323                  ("pragma% cannot be applied to function", Arg1);
6324
6325             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6326
6327                   if Is_Record_Type (Nm) then
6328
6329                   --  A record type that is the Equivalent_Type for a remote
6330                   --  access-to-subprogram type.
6331
6332                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6333
6334                   else
6335                      --  A non-expanded RAS type (distribution is not enabled)
6336
6337                      N := Declaration_Node (Nm);
6338                   end if;
6339
6340                if Nkind (N) = N_Full_Type_Declaration
6341                  and then Nkind (Type_Definition (N)) =
6342                                      N_Access_Procedure_Definition
6343                then
6344                   L := Parameter_Specifications (Type_Definition (N));
6345                   Process_Async_Pragma;
6346
6347                   if Is_Asynchronous (Nm)
6348                     and then Expander_Active
6349                     and then Get_PCS_Name /= Name_No_DSA
6350                   then
6351                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6352                   end if;
6353
6354                else
6355                   Error_Pragma_Arg
6356                     ("pragma% cannot reference access-to-function type",
6357                     Arg1);
6358                end if;
6359
6360             --  Only other possibility is Access-to-class-wide type
6361
6362             elsif Is_Access_Type (Nm)
6363               and then Is_Class_Wide_Type (Designated_Type (Nm))
6364             then
6365                Check_First_Subtype (Arg1);
6366                Set_Is_Asynchronous (Nm);
6367                if Expander_Active then
6368                   RACW_Type_Is_Asynchronous (Nm);
6369                end if;
6370
6371             else
6372                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6373             end if;
6374          end Asynchronous;
6375
6376          ------------
6377          -- Atomic --
6378          ------------
6379
6380          --  pragma Atomic (LOCAL_NAME);
6381
6382          when Pragma_Atomic =>
6383             Process_Atomic_Shared_Volatile;
6384
6385          -----------------------
6386          -- Atomic_Components --
6387          -----------------------
6388
6389          --  pragma Atomic_Components (array_LOCAL_NAME);
6390
6391          --  This processing is shared by Volatile_Components
6392
6393          when Pragma_Atomic_Components   |
6394               Pragma_Volatile_Components =>
6395
6396          Atomic_Components : declare
6397             E_Id : Node_Id;
6398             E    : Entity_Id;
6399             D    : Node_Id;
6400             K    : Node_Kind;
6401
6402          begin
6403             Check_Ada_83_Warning;
6404             Check_No_Identifiers;
6405             Check_Arg_Count (1);
6406             Check_Arg_Is_Local_Name (Arg1);
6407             E_Id := Get_Pragma_Arg (Arg1);
6408
6409             if Etype (E_Id) = Any_Type then
6410                return;
6411             end if;
6412
6413             E := Entity (E_Id);
6414
6415             Check_Duplicate_Pragma (E);
6416
6417             if Rep_Item_Too_Early (E, N)
6418                  or else
6419                Rep_Item_Too_Late (E, N)
6420             then
6421                return;
6422             end if;
6423
6424             D := Declaration_Node (E);
6425             K := Nkind (D);
6426
6427             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6428               or else
6429                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6430                    and then Nkind (D) = N_Object_Declaration
6431                    and then Nkind (Object_Definition (D)) =
6432                                        N_Constrained_Array_Definition)
6433             then
6434                --  The flag is set on the object, or on the base type
6435
6436                if Nkind (D) /= N_Object_Declaration then
6437                   E := Base_Type (E);
6438                end if;
6439
6440                Set_Has_Volatile_Components (E);
6441
6442                if Prag_Id = Pragma_Atomic_Components then
6443                   Set_Has_Atomic_Components (E);
6444                end if;
6445
6446             else
6447                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6448             end if;
6449          end Atomic_Components;
6450
6451          --------------------
6452          -- Attach_Handler --
6453          --------------------
6454
6455          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6456
6457          when Pragma_Attach_Handler =>
6458             Check_Ada_83_Warning;
6459             Check_No_Identifiers;
6460             Check_Arg_Count (2);
6461
6462             if No_Run_Time_Mode then
6463                Error_Msg_CRT ("Attach_Handler pragma", N);
6464             else
6465                Check_Interrupt_Or_Attach_Handler;
6466
6467                --  The expression that designates the attribute may depend on a
6468                --  discriminant, and is therefore a per- object expression, to
6469                --  be expanded in the init proc. If expansion is enabled, then
6470                --  perform semantic checks on a copy only.
6471
6472                if Expander_Active then
6473                   declare
6474                      Temp : constant Node_Id :=
6475                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6476                   begin
6477                      Set_Parent (Temp, N);
6478                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6479                   end;
6480
6481                else
6482                   Analyze (Get_Pragma_Arg (Arg2));
6483                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6484                end if;
6485
6486                Process_Interrupt_Or_Attach_Handler;
6487             end if;
6488
6489          --------------------
6490          -- C_Pass_By_Copy --
6491          --------------------
6492
6493          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6494
6495          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6496             Arg : Node_Id;
6497             Val : Uint;
6498
6499          begin
6500             GNAT_Pragma;
6501             Check_Valid_Configuration_Pragma;
6502             Check_Arg_Count (1);
6503             Check_Optional_Identifier (Arg1, "max_size");
6504
6505             Arg := Get_Pragma_Arg (Arg1);
6506             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6507
6508             Val := Expr_Value (Arg);
6509
6510             if Val <= 0 then
6511                Error_Pragma_Arg
6512                  ("maximum size for pragma% must be positive", Arg1);
6513
6514             elsif UI_Is_In_Int_Range (Val) then
6515                Default_C_Record_Mechanism := UI_To_Int (Val);
6516
6517             --  If a giant value is given, Int'Last will do well enough.
6518             --  If sometime someone complains that a record larger than
6519             --  two gigabytes is not copied, we will worry about it then!
6520
6521             else
6522                Default_C_Record_Mechanism := Mechanism_Type'Last;
6523             end if;
6524          end C_Pass_By_Copy;
6525
6526          -----------
6527          -- Check --
6528          -----------
6529
6530          --  pragma Check ([Name    =>] Identifier,
6531          --                [Check   =>] Boolean_Expression
6532          --              [,[Message =>] String_Expression]);
6533
6534          when Pragma_Check => Check : declare
6535             Expr : Node_Id;
6536             Eloc : Source_Ptr;
6537
6538             Check_On : Boolean;
6539             --  Set True if category of assertions referenced by Name enabled
6540
6541          begin
6542             GNAT_Pragma;
6543             Check_At_Least_N_Arguments (2);
6544             Check_At_Most_N_Arguments (3);
6545             Check_Optional_Identifier (Arg1, Name_Name);
6546             Check_Optional_Identifier (Arg2, Name_Check);
6547
6548             if Arg_Count = 3 then
6549                Check_Optional_Identifier (Arg3, Name_Message);
6550                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6551             end if;
6552
6553             Check_Arg_Is_Identifier (Arg1);
6554
6555             --  Indicate if pragma is enabled. The Original_Node reference here
6556             --  is to deal with pragma Assert rewritten as a Check pragma.
6557
6558             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6559
6560             if Check_On then
6561                Set_Pragma_Enabled (N);
6562                Set_Pragma_Enabled (Original_Node (N));
6563                Set_SCO_Pragma_Enabled (Loc);
6564             end if;
6565
6566             --  If expansion is active and the check is not enabled then we
6567             --  rewrite the Check as:
6568
6569             --    if False and then condition then
6570             --       null;
6571             --    end if;
6572
6573             --  The reason we do this rewriting during semantic analysis rather
6574             --  than as part of normal expansion is that we cannot analyze and
6575             --  expand the code for the boolean expression directly, or it may
6576             --  cause insertion of actions that would escape the attempt to
6577             --  suppress the check code.
6578
6579             --  Note that the Sloc for the if statement corresponds to the
6580             --  argument condition, not the pragma itself. The reason for this
6581             --  is that we may generate a warning if the condition is False at
6582             --  compile time, and we do not want to delete this warning when we
6583             --  delete the if statement.
6584
6585             Expr := Get_Pragma_Arg (Arg2);
6586
6587             if Expander_Active and then not Check_On then
6588                Eloc := Sloc (Expr);
6589
6590                Rewrite (N,
6591                  Make_If_Statement (Eloc,
6592                    Condition =>
6593                      Make_And_Then (Eloc,
6594                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
6595                        Right_Opnd => Expr),
6596                    Then_Statements => New_List (
6597                      Make_Null_Statement (Eloc))));
6598
6599                Analyze (N);
6600
6601             --  Check is active
6602
6603             else
6604                Analyze_And_Resolve (Expr, Any_Boolean);
6605             end if;
6606          end Check;
6607
6608          ----------------
6609          -- Check_Name --
6610          ----------------
6611
6612          --  pragma Check_Name (check_IDENTIFIER);
6613
6614          when Pragma_Check_Name =>
6615             Check_No_Identifiers;
6616             GNAT_Pragma;
6617             Check_Valid_Configuration_Pragma;
6618             Check_Arg_Count (1);
6619             Check_Arg_Is_Identifier (Arg1);
6620
6621             declare
6622                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6623
6624             begin
6625                for J in Check_Names.First .. Check_Names.Last loop
6626                   if Check_Names.Table (J) = Nam then
6627                      return;
6628                   end if;
6629                end loop;
6630
6631                Check_Names.Append (Nam);
6632             end;
6633
6634          ------------------
6635          -- Check_Policy --
6636          ------------------
6637
6638          --  pragma Check_Policy (
6639          --    [Name   =>] IDENTIFIER,
6640          --    [Policy =>] POLICY_IDENTIFIER);
6641
6642          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6643
6644          --  Note: this is a configuration pragma, but it is allowed to appear
6645          --  anywhere else.
6646
6647          when Pragma_Check_Policy =>
6648             GNAT_Pragma;
6649             Check_Arg_Count (2);
6650             Check_Optional_Identifier (Arg1, Name_Name);
6651             Check_Optional_Identifier (Arg2, Name_Policy);
6652             Check_Arg_Is_One_Of
6653               (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6654
6655             --  A Check_Policy pragma can appear either as a configuration
6656             --  pragma, or in a declarative part or a package spec (see RM
6657             --  11.5(5) for rules for Suppress/Unsuppress which are also
6658             --  followed for Check_Policy).
6659
6660             if not Is_Configuration_Pragma then
6661                Check_Is_In_Decl_Part_Or_Package_Spec;
6662             end if;
6663
6664             Set_Next_Pragma (N, Opt.Check_Policy_List);
6665             Opt.Check_Policy_List := N;
6666
6667          ---------------------
6668          -- CIL_Constructor --
6669          ---------------------
6670
6671          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6672
6673          --  Processing for this pragma is shared with Java_Constructor
6674
6675          -------------
6676          -- Comment --
6677          -------------
6678
6679          --  pragma Comment (static_string_EXPRESSION)
6680
6681          --  Processing for pragma Comment shares the circuitry for pragma
6682          --  Ident. The only differences are that Ident enforces a limit of 31
6683          --  characters on its argument, and also enforces limitations on
6684          --  placement for DEC compatibility. Pragma Comment shares neither of
6685          --  these restrictions.
6686
6687          -------------------
6688          -- Common_Object --
6689          -------------------
6690
6691          --  pragma Common_Object (
6692          --        [Internal =>] LOCAL_NAME
6693          --     [, [External =>] EXTERNAL_SYMBOL]
6694          --     [, [Size     =>] EXTERNAL_SYMBOL]);
6695
6696          --  Processing for this pragma is shared with Psect_Object
6697
6698          ------------------------
6699          -- Compile_Time_Error --
6700          ------------------------
6701
6702          --  pragma Compile_Time_Error
6703          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6704
6705          when Pragma_Compile_Time_Error =>
6706             GNAT_Pragma;
6707             Process_Compile_Time_Warning_Or_Error;
6708
6709          --------------------------
6710          -- Compile_Time_Warning --
6711          --------------------------
6712
6713          --  pragma Compile_Time_Warning
6714          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6715
6716          when Pragma_Compile_Time_Warning =>
6717             GNAT_Pragma;
6718             Process_Compile_Time_Warning_Or_Error;
6719
6720          -------------------
6721          -- Compiler_Unit --
6722          -------------------
6723
6724          when Pragma_Compiler_Unit =>
6725             GNAT_Pragma;
6726             Check_Arg_Count (0);
6727             Set_Is_Compiler_Unit (Get_Source_Unit (N));
6728
6729          -----------------------------
6730          -- Complete_Representation --
6731          -----------------------------
6732
6733          --  pragma Complete_Representation;
6734
6735          when Pragma_Complete_Representation =>
6736             GNAT_Pragma;
6737             Check_Arg_Count (0);
6738
6739             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
6740                Error_Pragma
6741                  ("pragma & must appear within record representation clause");
6742             end if;
6743
6744          ----------------------------
6745          -- Complex_Representation --
6746          ----------------------------
6747
6748          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
6749
6750          when Pragma_Complex_Representation => Complex_Representation : declare
6751             E_Id : Entity_Id;
6752             E    : Entity_Id;
6753             Ent  : Entity_Id;
6754
6755          begin
6756             GNAT_Pragma;
6757             Check_Arg_Count (1);
6758             Check_Optional_Identifier (Arg1, Name_Entity);
6759             Check_Arg_Is_Local_Name (Arg1);
6760             E_Id := Get_Pragma_Arg (Arg1);
6761
6762             if Etype (E_Id) = Any_Type then
6763                return;
6764             end if;
6765
6766             E := Entity (E_Id);
6767
6768             if not Is_Record_Type (E) then
6769                Error_Pragma_Arg
6770                  ("argument for pragma% must be record type", Arg1);
6771             end if;
6772
6773             Ent := First_Entity (E);
6774
6775             if No (Ent)
6776               or else No (Next_Entity (Ent))
6777               or else Present (Next_Entity (Next_Entity (Ent)))
6778               or else not Is_Floating_Point_Type (Etype (Ent))
6779               or else Etype (Ent) /= Etype (Next_Entity (Ent))
6780             then
6781                Error_Pragma_Arg
6782                  ("record for pragma% must have two fields of the same "
6783                   & "floating-point type", Arg1);
6784
6785             else
6786                Set_Has_Complex_Representation (Base_Type (E));
6787
6788                --  We need to treat the type has having a non-standard
6789                --  representation, for back-end purposes, even though in
6790                --  general a complex will have the default representation
6791                --  of a record with two real components.
6792
6793                Set_Has_Non_Standard_Rep (Base_Type (E));
6794             end if;
6795          end Complex_Representation;
6796
6797          -------------------------
6798          -- Component_Alignment --
6799          -------------------------
6800
6801          --  pragma Component_Alignment (
6802          --        [Form =>] ALIGNMENT_CHOICE
6803          --     [, [Name =>] type_LOCAL_NAME]);
6804          --
6805          --   ALIGNMENT_CHOICE ::=
6806          --     Component_Size
6807          --   | Component_Size_4
6808          --   | Storage_Unit
6809          --   | Default
6810
6811          when Pragma_Component_Alignment => Component_AlignmentP : declare
6812             Args  : Args_List (1 .. 2);
6813             Names : constant Name_List (1 .. 2) := (
6814                       Name_Form,
6815                       Name_Name);
6816
6817             Form  : Node_Id renames Args (1);
6818             Name  : Node_Id renames Args (2);
6819
6820             Atype : Component_Alignment_Kind;
6821             Typ   : Entity_Id;
6822
6823          begin
6824             GNAT_Pragma;
6825             Gather_Associations (Names, Args);
6826
6827             if No (Form) then
6828                Error_Pragma ("missing Form argument for pragma%");
6829             end if;
6830
6831             Check_Arg_Is_Identifier (Form);
6832
6833             --  Get proper alignment, note that Default = Component_Size on all
6834             --  machines we have so far, and we want to set this value rather
6835             --  than the default value to indicate that it has been explicitly
6836             --  set (and thus will not get overridden by the default component
6837             --  alignment for the current scope)
6838
6839             if Chars (Form) = Name_Component_Size then
6840                Atype := Calign_Component_Size;
6841
6842             elsif Chars (Form) = Name_Component_Size_4 then
6843                Atype := Calign_Component_Size_4;
6844
6845             elsif Chars (Form) = Name_Default then
6846                Atype := Calign_Component_Size;
6847
6848             elsif Chars (Form) = Name_Storage_Unit then
6849                Atype := Calign_Storage_Unit;
6850
6851             else
6852                Error_Pragma_Arg
6853                  ("invalid Form parameter for pragma%", Form);
6854             end if;
6855
6856             --  Case with no name, supplied, affects scope table entry
6857
6858             if No (Name) then
6859                Scope_Stack.Table
6860                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
6861
6862             --  Case of name supplied
6863
6864             else
6865                Check_Arg_Is_Local_Name (Name);
6866                Find_Type (Name);
6867                Typ := Entity (Name);
6868
6869                if Typ = Any_Type
6870                  or else Rep_Item_Too_Early (Typ, N)
6871                then
6872                   return;
6873                else
6874                   Typ := Underlying_Type (Typ);
6875                end if;
6876
6877                if not Is_Record_Type (Typ)
6878                  and then not Is_Array_Type (Typ)
6879                then
6880                   Error_Pragma_Arg
6881                     ("Name parameter of pragma% must identify record or " &
6882                      "array type", Name);
6883                end if;
6884
6885                --  An explicit Component_Alignment pragma overrides an
6886                --  implicit pragma Pack, but not an explicit one.
6887
6888                if not Has_Pragma_Pack (Base_Type (Typ)) then
6889                   Set_Is_Packed (Base_Type (Typ), False);
6890                   Set_Component_Alignment (Base_Type (Typ), Atype);
6891                end if;
6892             end if;
6893          end Component_AlignmentP;
6894
6895          ----------------
6896          -- Controlled --
6897          ----------------
6898
6899          --  pragma Controlled (first_subtype_LOCAL_NAME);
6900
6901          when Pragma_Controlled => Controlled : declare
6902             Arg : Node_Id;
6903
6904          begin
6905             Check_No_Identifiers;
6906             Check_Arg_Count (1);
6907             Check_Arg_Is_Local_Name (Arg1);
6908             Arg := Get_Pragma_Arg (Arg1);
6909
6910             if not Is_Entity_Name (Arg)
6911               or else not Is_Access_Type (Entity (Arg))
6912             then
6913                Error_Pragma_Arg ("pragma% requires access type", Arg1);
6914             else
6915                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
6916             end if;
6917          end Controlled;
6918
6919          ----------------
6920          -- Convention --
6921          ----------------
6922
6923          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
6924          --    [Entity =>] LOCAL_NAME);
6925
6926          when Pragma_Convention => Convention : declare
6927             C : Convention_Id;
6928             E : Entity_Id;
6929             pragma Warnings (Off, C);
6930             pragma Warnings (Off, E);
6931          begin
6932             Check_Arg_Order ((Name_Convention, Name_Entity));
6933             Check_Ada_83_Warning;
6934             Check_Arg_Count (2);
6935             Process_Convention (C, E);
6936          end Convention;
6937
6938          ---------------------------
6939          -- Convention_Identifier --
6940          ---------------------------
6941
6942          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
6943          --    [Convention =>] convention_IDENTIFIER);
6944
6945          when Pragma_Convention_Identifier => Convention_Identifier : declare
6946             Idnam : Name_Id;
6947             Cname : Name_Id;
6948
6949          begin
6950             GNAT_Pragma;
6951             Check_Arg_Order ((Name_Name, Name_Convention));
6952             Check_Arg_Count (2);
6953             Check_Optional_Identifier (Arg1, Name_Name);
6954             Check_Optional_Identifier (Arg2, Name_Convention);
6955             Check_Arg_Is_Identifier (Arg1);
6956             Check_Arg_Is_Identifier (Arg2);
6957             Idnam := Chars (Get_Pragma_Arg (Arg1));
6958             Cname := Chars (Get_Pragma_Arg (Arg2));
6959
6960             if Is_Convention_Name (Cname) then
6961                Record_Convention_Identifier
6962                  (Idnam, Get_Convention_Id (Cname));
6963             else
6964                Error_Pragma_Arg
6965                  ("second arg for % pragma must be convention", Arg2);
6966             end if;
6967          end Convention_Identifier;
6968
6969          ---------------
6970          -- CPP_Class --
6971          ---------------
6972
6973          --  pragma CPP_Class ([Entity =>] local_NAME)
6974
6975          when Pragma_CPP_Class => CPP_Class : declare
6976             Arg : Node_Id;
6977             Typ : Entity_Id;
6978
6979          begin
6980             if Warn_On_Obsolescent_Feature then
6981                Error_Msg_N
6982                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
6983                   " by pragma import?", N);
6984             end if;
6985
6986             GNAT_Pragma;
6987             Check_Arg_Count (1);
6988             Check_Optional_Identifier (Arg1, Name_Entity);
6989             Check_Arg_Is_Local_Name (Arg1);
6990
6991             Arg := Get_Pragma_Arg (Arg1);
6992             Analyze (Arg);
6993
6994             if Etype (Arg) = Any_Type then
6995                return;
6996             end if;
6997
6998             if not Is_Entity_Name (Arg)
6999               or else not Is_Type (Entity (Arg))
7000             then
7001                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7002             end if;
7003
7004             Typ := Entity (Arg);
7005
7006             if not Is_Tagged_Type (Typ) then
7007                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7008             end if;
7009
7010             --  Types treated as CPP classes are treated as limited, but we
7011             --  don't require them to be declared this way. A warning is issued
7012             --  to encourage the user to declare them as limited. This is not
7013             --  an error, for compatibility reasons, because these types have
7014             --  been supported this way for some time.
7015
7016             if not Is_Limited_Type (Typ) then
7017                Error_Msg_N
7018                  ("imported 'C'P'P type should be " &
7019                     "explicitly declared limited?",
7020                   Get_Pragma_Arg (Arg1));
7021                Error_Msg_N
7022                  ("\type will be considered limited",
7023                   Get_Pragma_Arg (Arg1));
7024             end if;
7025
7026             Set_Is_CPP_Class      (Typ);
7027             Set_Is_Limited_Record (Typ);
7028             Set_Convention        (Typ, Convention_CPP);
7029
7030             --  Imported CPP types must not have discriminants (because C++
7031             --  classes do not have discriminants).
7032
7033             if Has_Discriminants (Typ) then
7034                Error_Msg_N
7035                  ("imported 'C'P'P type cannot have discriminants",
7036                   First (Discriminant_Specifications
7037                           (Declaration_Node (Typ))));
7038             end if;
7039
7040             --  Components of imported CPP types must not have default
7041             --  expressions because the constructor (if any) is in the
7042             --  C++ side.
7043
7044             if Is_Incomplete_Or_Private_Type (Typ)
7045               and then No (Underlying_Type (Typ))
7046             then
7047                --  It should be an error to apply pragma CPP to a private
7048                --  type if the underlying type is not visible (as it is
7049                --  for any representation item). For now, for backward
7050                --  compatibility we do nothing but we cannot check components
7051                --  because they are not available at this stage. All this code
7052                --  will be removed when we cleanup this obsolete GNAT pragma???
7053
7054                null;
7055
7056             else
7057                declare
7058                   Tdef  : constant Node_Id :=
7059                             Type_Definition (Declaration_Node (Typ));
7060                   Clist : Node_Id;
7061                   Comp  : Node_Id;
7062
7063                begin
7064                   if Nkind (Tdef) = N_Record_Definition then
7065                      Clist := Component_List (Tdef);
7066                   else
7067                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7068                      Clist := Component_List (Record_Extension_Part (Tdef));
7069                   end if;
7070
7071                   if Present (Clist) then
7072                      Comp := First (Component_Items (Clist));
7073                      while Present (Comp) loop
7074                         if Present (Expression (Comp)) then
7075                            Error_Msg_N
7076                              ("component of imported 'C'P'P type cannot have" &
7077                               " default expression", Expression (Comp));
7078                         end if;
7079
7080                         Next (Comp);
7081                      end loop;
7082                   end if;
7083                end;
7084             end if;
7085          end CPP_Class;
7086
7087          ---------------------
7088          -- CPP_Constructor --
7089          ---------------------
7090
7091          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7092          --    [, [External_Name =>] static_string_EXPRESSION ]
7093          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7094
7095          when Pragma_CPP_Constructor => CPP_Constructor : declare
7096             Elmt    : Elmt_Id;
7097             Id      : Entity_Id;
7098             Def_Id  : Entity_Id;
7099             Tag_Typ : Entity_Id;
7100
7101          begin
7102             GNAT_Pragma;
7103             Check_At_Least_N_Arguments (1);
7104             Check_At_Most_N_Arguments (3);
7105             Check_Optional_Identifier (Arg1, Name_Entity);
7106             Check_Arg_Is_Local_Name (Arg1);
7107
7108             Id := Get_Pragma_Arg (Arg1);
7109             Find_Program_Unit_Name (Id);
7110
7111             --  If we did not find the name, we are done
7112
7113             if Etype (Id) = Any_Type then
7114                return;
7115             end if;
7116
7117             Def_Id := Entity (Id);
7118
7119             --  Check if already defined as constructor
7120
7121             if Is_Constructor (Def_Id) then
7122                Error_Msg_N
7123                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7124                return;
7125             end if;
7126
7127             if Ekind (Def_Id) = E_Function
7128               and then (Is_CPP_Class (Etype (Def_Id))
7129                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7130                                    and then
7131                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7132             then
7133                if Arg_Count >= 2 then
7134                   Set_Imported (Def_Id);
7135                   Set_Is_Public (Def_Id);
7136                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7137                end if;
7138
7139                Set_Has_Completion (Def_Id);
7140                Set_Is_Constructor (Def_Id);
7141
7142                --  Imported C++ constructors are not dispatching primitives
7143                --  because in C++ they don't have a dispatch table slot.
7144                --  However, in Ada the constructor has the profile of a
7145                --  function that returns a tagged type and therefore it has
7146                --  been treated as a primitive operation during semantic
7147                --  analysis. We now remove it from the list of primitive
7148                --  operations of the type.
7149
7150                if Is_Tagged_Type (Etype (Def_Id))
7151                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7152                then
7153                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7154                   Tag_Typ := Etype (Def_Id);
7155
7156                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7157                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7158                      Next_Elmt (Elmt);
7159                   end loop;
7160
7161                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7162                   Set_Is_Dispatching_Operation (Def_Id, False);
7163                end if;
7164
7165                --  For backward compatibility, if the constructor returns a
7166                --  class wide type, and we internally change the return type to
7167                --  the corresponding root type.
7168
7169                if Is_Class_Wide_Type (Etype (Def_Id)) then
7170                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7171                end if;
7172             else
7173                Error_Pragma_Arg
7174                  ("pragma% requires function returning a 'C'P'P_Class type",
7175                    Arg1);
7176             end if;
7177          end CPP_Constructor;
7178
7179          -----------------
7180          -- CPP_Virtual --
7181          -----------------
7182
7183          when Pragma_CPP_Virtual => CPP_Virtual : declare
7184          begin
7185             GNAT_Pragma;
7186
7187             if Warn_On_Obsolescent_Feature then
7188                Error_Msg_N
7189                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7190                   "no effect?", N);
7191             end if;
7192          end CPP_Virtual;
7193
7194          ----------------
7195          -- CPP_Vtable --
7196          ----------------
7197
7198          when Pragma_CPP_Vtable => CPP_Vtable : declare
7199          begin
7200             GNAT_Pragma;
7201
7202             if Warn_On_Obsolescent_Feature then
7203                Error_Msg_N
7204                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7205                   "no effect?", N);
7206             end if;
7207          end CPP_Vtable;
7208
7209          ---------
7210          -- CPU --
7211          ---------
7212
7213          --  pragma CPU (EXPRESSION);
7214
7215          when Pragma_CPU => CPU : declare
7216             P   : constant Node_Id := Parent (N);
7217             Arg : Node_Id;
7218
7219          begin
7220             Ada_2012_Pragma;
7221             Check_No_Identifiers;
7222             Check_Arg_Count (1);
7223
7224             --  Subprogram case
7225
7226             if Nkind (P) = N_Subprogram_Body then
7227                Check_In_Main_Program;
7228
7229                Arg := Get_Pragma_Arg (Arg1);
7230                Analyze_And_Resolve (Arg, Any_Integer);
7231
7232                --  Must be static
7233
7234                if not Is_Static_Expression (Arg) then
7235                   Flag_Non_Static_Expr
7236                     ("main subprogram affinity is not static!", Arg);
7237                   raise Pragma_Exit;
7238
7239                --  If constraint error, then we already signalled an error
7240
7241                elsif Raises_Constraint_Error (Arg) then
7242                   null;
7243
7244                --  Otherwise check in range
7245
7246                else
7247                   declare
7248                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7249                      --  This is the entity System.Multiprocessors.CPU_Range;
7250
7251                      Val : constant Uint := Expr_Value (Arg);
7252
7253                   begin
7254                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7255                           or else
7256                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7257                      then
7258                         Error_Pragma_Arg
7259                           ("main subprogram CPU is out of range", Arg1);
7260                      end if;
7261                   end;
7262                end if;
7263
7264                Set_Main_CPU
7265                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7266
7267             --  Task case
7268
7269             elsif Nkind (P) = N_Task_Definition then
7270                Arg := Get_Pragma_Arg (Arg1);
7271
7272                --  The expression must be analyzed in the special manner
7273                --  described in "Handling of Default and Per-Object
7274                --  Expressions" in sem.ads.
7275
7276                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7277
7278             --  Anything else is incorrect
7279
7280             else
7281                Pragma_Misplaced;
7282             end if;
7283
7284             if Has_Pragma_CPU (P) then
7285                Error_Pragma ("duplicate pragma% not allowed");
7286             else
7287                Set_Has_Pragma_CPU (P, True);
7288
7289                if Nkind (P) = N_Task_Definition then
7290                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7291                end if;
7292             end if;
7293          end CPU;
7294
7295          -----------
7296          -- Debug --
7297          -----------
7298
7299          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7300
7301          when Pragma_Debug => Debug : declare
7302                Cond : Node_Id;
7303
7304          begin
7305             GNAT_Pragma;
7306
7307             Cond :=
7308               New_Occurrence_Of
7309                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7310                  Loc);
7311
7312             if Arg_Count = 2 then
7313                Cond :=
7314                  Make_And_Then (Loc,
7315                    Left_Opnd   => Relocate_Node (Cond),
7316                    Right_Opnd  => Get_Pragma_Arg (Arg1));
7317             end if;
7318
7319             --  Rewrite into a conditional with an appropriate condition. We
7320             --  wrap the procedure call in a block so that overhead from e.g.
7321             --  use of the secondary stack does not generate execution overhead
7322             --  for suppressed conditions.
7323
7324             Rewrite (N, Make_Implicit_If_Statement (N,
7325               Condition => Cond,
7326                  Then_Statements => New_List (
7327                    Make_Block_Statement (Loc,
7328                      Handled_Statement_Sequence =>
7329                        Make_Handled_Sequence_Of_Statements (Loc,
7330                          Statements => New_List (
7331                            Relocate_Node (Debug_Statement (N))))))));
7332             Analyze (N);
7333          end Debug;
7334
7335          ------------------
7336          -- Debug_Policy --
7337          ------------------
7338
7339          --  pragma Debug_Policy (Check | Ignore)
7340
7341          when Pragma_Debug_Policy =>
7342             GNAT_Pragma;
7343             Check_Arg_Count (1);
7344             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7345             Debug_Pragmas_Enabled :=
7346               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7347
7348          -----------------------------
7349          -- Default_Component_Value --
7350          -----------------------------
7351
7352          when Pragma_Default_Component_Value => declare
7353             Arg : Node_Id;
7354             E   : Entity_Id;
7355
7356          begin
7357             GNAT_Pragma;
7358             Check_Arg_Count (2);
7359             Check_Arg_Is_Local_Name (Arg1);
7360
7361             Arg := Get_Pragma_Arg (Arg1);
7362             Analyze (Arg);
7363
7364             if Etype (Arg) = Any_Type then
7365                return;
7366             end if;
7367
7368             if not Is_Entity_Name (Arg)
7369               or else not Is_Array_Type (Entity (Arg))
7370             then
7371                Error_Pragma_Arg ("pragma% requires an array type", Arg1);
7372             end if;
7373
7374             Check_First_Subtype (Arg1);
7375
7376             E := Entity (Arg);
7377             Check_Duplicate_Pragma (E);
7378
7379             --  Check for rep item too early or too late, but skip this if
7380             --  the pragma comes from the corresponding aspect, since we do
7381             --  not need the checks, and more importantly, the pragma is on
7382             --  the rep item chain alreay, and must not be put there twice!
7383
7384             if not From_Aspect_Specification (N) then
7385                if Rep_Item_Too_Early (E, N)
7386                     or else
7387                   Rep_Item_Too_Late (E, N)
7388                then
7389                   return;
7390                end if;
7391             end if;
7392
7393             --  Analyze the default value
7394
7395             Arg := Get_Pragma_Arg (Arg2);
7396             Analyze_And_Resolve (Arg, Component_Type (E));
7397
7398             if not Is_OK_Static_Expression (Arg) then
7399                Flag_Non_Static_Expr
7400                  ("non-static expression not allowed for " &
7401                   "Default_Component_Value",
7402                   Arg2);
7403                raise Pragma_Exit;
7404             end if;
7405
7406             --  Set the flag on the root type and then check for Rep_Item too
7407             --  early or too late, the latter call chains the pragma onto the
7408             --  Rep_Item chain.
7409
7410             Set_Has_Default_Component_Value (Base_Type (E));
7411          end;
7412
7413          -------------------
7414          -- Default_Value --
7415          -------------------
7416
7417          when Pragma_Default_Value => declare
7418             Arg : Node_Id;
7419             E   : Entity_Id;
7420
7421          begin
7422             --  Error checks
7423
7424             GNAT_Pragma;
7425             Check_Arg_Count (2);
7426             Check_Arg_Is_Local_Name (Arg1);
7427
7428             Arg := Get_Pragma_Arg (Arg1);
7429             Analyze (Arg);
7430
7431             if Etype (Arg) = Any_Type then
7432                return;
7433             end if;
7434
7435             if not Is_Entity_Name (Arg)
7436               or else not Is_Scalar_Type (Entity (Arg))
7437             then
7438                Error_Pragma_Arg ("pragma% requires a scalar type", Arg1);
7439             end if;
7440
7441             Check_First_Subtype (Arg1);
7442
7443             E := Entity (Arg);
7444             Check_Duplicate_Pragma (E);
7445
7446             --  Check for rep item too early or too late, but skip this if
7447             --  the pragma comes from the corresponding aspect, since we do
7448             --  not need the checks, and more importantly, the pragma is on
7449             --  the rep item chain alreay, and must not be put there twice!
7450
7451             if not From_Aspect_Specification (N) then
7452                if Rep_Item_Too_Early (E, N)
7453                     or else
7454                   Rep_Item_Too_Late (E, N)
7455                then
7456                   return;
7457                end if;
7458             end if;
7459
7460             --  Analyze the default value. Note that we must do that after
7461             --  checking for Rep_Item_Too_Late since this resolution will
7462             --  freeze the type involved.
7463
7464             Arg := Get_Pragma_Arg (Arg2);
7465             Analyze_And_Resolve (Arg, E);
7466
7467             if not Is_OK_Static_Expression (Arg) then
7468                Flag_Non_Static_Expr
7469                  ("non-static expression not allowed for Default_Value",
7470                   Arg2);
7471                raise Pragma_Exit;
7472             end if;
7473
7474             --  Set the flag on the root type and then check for Rep_Item too
7475             --  early or too late, the latter call chains the pragma onto the
7476             --  Rep_Item chain.
7477
7478             Set_Has_Default_Value (Base_Type (E));
7479          end;
7480
7481          ---------------------
7482          -- Detect_Blocking --
7483          ---------------------
7484
7485          --  pragma Detect_Blocking;
7486
7487          when Pragma_Detect_Blocking =>
7488             Ada_2005_Pragma;
7489             Check_Arg_Count (0);
7490             Check_Valid_Configuration_Pragma;
7491             Detect_Blocking := True;
7492
7493          --------------------------
7494          -- Default_Storage_Pool --
7495          --------------------------
7496
7497          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7498
7499          when Pragma_Default_Storage_Pool =>
7500             Ada_2012_Pragma;
7501             Check_Arg_Count (1);
7502
7503             --  Default_Storage_Pool can appear as a configuration pragma, or
7504             --  in a declarative part or a package spec.
7505
7506             if not Is_Configuration_Pragma then
7507                Check_Is_In_Decl_Part_Or_Package_Spec;
7508             end if;
7509
7510             --  Case of Default_Storage_Pool (null);
7511
7512             if Nkind (Expression (Arg1)) = N_Null then
7513                Analyze (Expression (Arg1));
7514
7515                --  This is an odd case, this is not really an expression, so
7516                --  we don't have a type for it. So just set the type to Empty.
7517
7518                Set_Etype (Expression (Arg1), Empty);
7519
7520             --  Case of Default_Storage_Pool (storage_pool_NAME);
7521
7522             else
7523                --  If it's a configuration pragma, then the only allowed
7524                --  argument is "null".
7525
7526                if Is_Configuration_Pragma then
7527                   Error_Pragma_Arg ("NULL expected", Arg1);
7528                end if;
7529
7530                --  The expected type for a non-"null" argument is
7531                --  Root_Storage_Pool'Class.
7532
7533                Analyze_And_Resolve
7534                  (Get_Pragma_Arg (Arg1),
7535                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7536             end if;
7537
7538             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7539             --  for an access type will use this information to set the
7540             --  appropriate attributes of the access type.
7541
7542             Default_Pool := Expression (Arg1);
7543
7544          ---------------
7545          -- Dimension --
7546          ---------------
7547
7548          when Pragma_Dimension =>
7549             GNAT_Pragma;
7550             Check_Arg_Count (4);
7551             Check_No_Identifiers;
7552             Check_Arg_Is_Local_Name (Arg1);
7553
7554             if not Is_Type (Arg1) then
7555                Error_Pragma ("first argument for pragma% must be subtype");
7556             end if;
7557
7558             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7559             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7560             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7561
7562          -------------------
7563          -- Discard_Names --
7564          -------------------
7565
7566          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7567
7568          when Pragma_Discard_Names => Discard_Names : declare
7569             E    : Entity_Id;
7570             E_Id : Entity_Id;
7571
7572          begin
7573             Check_Ada_83_Warning;
7574
7575             --  Deal with configuration pragma case
7576
7577             if Arg_Count = 0 and then Is_Configuration_Pragma then
7578                Global_Discard_Names := True;
7579                return;
7580
7581             --  Otherwise, check correct appropriate context
7582
7583             else
7584                Check_Is_In_Decl_Part_Or_Package_Spec;
7585
7586                if Arg_Count = 0 then
7587
7588                   --  If there is no parameter, then from now on this pragma
7589                   --  applies to any enumeration, exception or tagged type
7590                   --  defined in the current declarative part, and recursively
7591                   --  to any nested scope.
7592
7593                   Set_Discard_Names (Current_Scope);
7594                   return;
7595
7596                else
7597                   Check_Arg_Count (1);
7598                   Check_Optional_Identifier (Arg1, Name_On);
7599                   Check_Arg_Is_Local_Name (Arg1);
7600
7601                   E_Id := Get_Pragma_Arg (Arg1);
7602
7603                   if Etype (E_Id) = Any_Type then
7604                      return;
7605                   else
7606                      E := Entity (E_Id);
7607                   end if;
7608
7609                   if (Is_First_Subtype (E)
7610                       and then
7611                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7612                     or else Ekind (E) = E_Exception
7613                   then
7614                      Set_Discard_Names (E);
7615                   else
7616                      Error_Pragma_Arg
7617                        ("inappropriate entity for pragma%", Arg1);
7618                   end if;
7619
7620                end if;
7621             end if;
7622          end Discard_Names;
7623
7624          ---------------
7625          -- Elaborate --
7626          ---------------
7627
7628          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7629
7630          when Pragma_Elaborate => Elaborate : declare
7631             Arg   : Node_Id;
7632             Citem : Node_Id;
7633
7634          begin
7635             --  Pragma must be in context items list of a compilation unit
7636
7637             if not Is_In_Context_Clause then
7638                Pragma_Misplaced;
7639             end if;
7640
7641             --  Must be at least one argument
7642
7643             if Arg_Count = 0 then
7644                Error_Pragma ("pragma% requires at least one argument");
7645             end if;
7646
7647             --  In Ada 83 mode, there can be no items following it in the
7648             --  context list except other pragmas and implicit with clauses
7649             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7650             --  placement rule does not apply.
7651
7652             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7653                Citem := Next (N);
7654                while Present (Citem) loop
7655                   if Nkind (Citem) = N_Pragma
7656                     or else (Nkind (Citem) = N_With_Clause
7657                               and then Implicit_With (Citem))
7658                   then
7659                      null;
7660                   else
7661                      Error_Pragma
7662                        ("(Ada 83) pragma% must be at end of context clause");
7663                   end if;
7664
7665                   Next (Citem);
7666                end loop;
7667             end if;
7668
7669             --  Finally, the arguments must all be units mentioned in a with
7670             --  clause in the same context clause. Note we already checked (in
7671             --  Par.Prag) that the arguments are all identifiers or selected
7672             --  components.
7673
7674             Arg := Arg1;
7675             Outer : while Present (Arg) loop
7676                Citem := First (List_Containing (N));
7677                Inner : while Citem /= N loop
7678                   if Nkind (Citem) = N_With_Clause
7679                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7680                   then
7681                      Set_Elaborate_Present (Citem, True);
7682                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7683
7684                      --  With the pragma present, elaboration calls on
7685                      --  subprograms from the named unit need no further
7686                      --  checks, as long as the pragma appears in the current
7687                      --  compilation unit. If the pragma appears in some unit
7688                      --  in the context, there might still be a need for an
7689                      --  Elaborate_All_Desirable from the current compilation
7690                      --  to the named unit, so we keep the check enabled.
7691
7692                      if In_Extended_Main_Source_Unit (N) then
7693                         Set_Suppress_Elaboration_Warnings
7694                           (Entity (Name (Citem)));
7695                      end if;
7696
7697                      exit Inner;
7698                   end if;
7699
7700                   Next (Citem);
7701                end loop Inner;
7702
7703                if Citem = N then
7704                   Error_Pragma_Arg
7705                     ("argument of pragma% is not with'ed unit", Arg);
7706                end if;
7707
7708                Next (Arg);
7709             end loop Outer;
7710
7711             --  Give a warning if operating in static mode with -gnatwl
7712             --  (elaboration warnings enabled) switch set.
7713
7714             if Elab_Warnings and not Dynamic_Elaboration_Checks then
7715                Error_Msg_N
7716                  ("?use of pragma Elaborate may not be safe", N);
7717                Error_Msg_N
7718                  ("?use pragma Elaborate_All instead if possible", N);
7719             end if;
7720          end Elaborate;
7721
7722          -------------------
7723          -- Elaborate_All --
7724          -------------------
7725
7726          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7727
7728          when Pragma_Elaborate_All => Elaborate_All : declare
7729             Arg   : Node_Id;
7730             Citem : Node_Id;
7731
7732          begin
7733             Check_Ada_83_Warning;
7734
7735             --  Pragma must be in context items list of a compilation unit
7736
7737             if not Is_In_Context_Clause then
7738                Pragma_Misplaced;
7739             end if;
7740
7741             --  Must be at least one argument
7742
7743             if Arg_Count = 0 then
7744                Error_Pragma ("pragma% requires at least one argument");
7745             end if;
7746
7747             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
7748             --  have to appear at the end of the context clause, but may
7749             --  appear mixed in with other items, even in Ada 83 mode.
7750
7751             --  Final check: the arguments must all be units mentioned in
7752             --  a with clause in the same context clause. Note that we
7753             --  already checked (in Par.Prag) that all the arguments are
7754             --  either identifiers or selected components.
7755
7756             Arg := Arg1;
7757             Outr : while Present (Arg) loop
7758                Citem := First (List_Containing (N));
7759                Innr : while Citem /= N loop
7760                   if Nkind (Citem) = N_With_Clause
7761                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7762                   then
7763                      Set_Elaborate_All_Present (Citem, True);
7764                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7765
7766                      --  Suppress warnings and elaboration checks on the named
7767                      --  unit if the pragma is in the current compilation, as
7768                      --  for pragma Elaborate.
7769
7770                      if In_Extended_Main_Source_Unit (N) then
7771                         Set_Suppress_Elaboration_Warnings
7772                           (Entity (Name (Citem)));
7773                      end if;
7774                      exit Innr;
7775                   end if;
7776
7777                   Next (Citem);
7778                end loop Innr;
7779
7780                if Citem = N then
7781                   Set_Error_Posted (N);
7782                   Error_Pragma_Arg
7783                     ("argument of pragma% is not with'ed unit", Arg);
7784                end if;
7785
7786                Next (Arg);
7787             end loop Outr;
7788          end Elaborate_All;
7789
7790          --------------------
7791          -- Elaborate_Body --
7792          --------------------
7793
7794          --  pragma Elaborate_Body [( library_unit_NAME )];
7795
7796          when Pragma_Elaborate_Body => Elaborate_Body : declare
7797             Cunit_Node : Node_Id;
7798             Cunit_Ent  : Entity_Id;
7799
7800          begin
7801             Check_Ada_83_Warning;
7802             Check_Valid_Library_Unit_Pragma;
7803
7804             if Nkind (N) = N_Null_Statement then
7805                return;
7806             end if;
7807
7808             Cunit_Node := Cunit (Current_Sem_Unit);
7809             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
7810
7811             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7812                                             N_Subprogram_Body)
7813             then
7814                Error_Pragma ("pragma% must refer to a spec, not a body");
7815             else
7816                Set_Body_Required (Cunit_Node, True);
7817                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7818
7819                --  If we are in dynamic elaboration mode, then we suppress
7820                --  elaboration warnings for the unit, since it is definitely
7821                --  fine NOT to do dynamic checks at the first level (and such
7822                --  checks will be suppressed because no elaboration boolean
7823                --  is created for Elaborate_Body packages).
7824
7825                --  But in the static model of elaboration, Elaborate_Body is
7826                --  definitely NOT good enough to ensure elaboration safety on
7827                --  its own, since the body may WITH other units that are not
7828                --  safe from an elaboration point of view, so a client must
7829                --  still do an Elaborate_All on such units.
7830
7831                --  Debug flag -gnatdD restores the old behavior of 3.13, where
7832                --  Elaborate_Body always suppressed elab warnings.
7833
7834                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
7835                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
7836                end if;
7837             end if;
7838          end Elaborate_Body;
7839
7840          ------------------------
7841          -- Elaboration_Checks --
7842          ------------------------
7843
7844          --  pragma Elaboration_Checks (Static | Dynamic);
7845
7846          when Pragma_Elaboration_Checks =>
7847             GNAT_Pragma;
7848             Check_Arg_Count (1);
7849             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
7850             Dynamic_Elaboration_Checks :=
7851               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
7852
7853          ---------------
7854          -- Eliminate --
7855          ---------------
7856
7857          --  pragma Eliminate (
7858          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
7859          --    [,[Entity     =>] IDENTIFIER |
7860          --                      SELECTED_COMPONENT |
7861          --                      STRING_LITERAL]
7862          --    [,                OVERLOADING_RESOLUTION]);
7863
7864          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
7865          --                             SOURCE_LOCATION
7866
7867          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
7868          --                                        FUNCTION_PROFILE
7869
7870          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
7871
7872          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
7873          --                       Result_Type => result_SUBTYPE_NAME]
7874
7875          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
7876          --  SUBTYPE_NAME    ::= STRING_LITERAL
7877
7878          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
7879          --  SOURCE_TRACE    ::= STRING_LITERAL
7880
7881          when Pragma_Eliminate => Eliminate : declare
7882             Args  : Args_List (1 .. 5);
7883             Names : constant Name_List (1 .. 5) := (
7884                       Name_Unit_Name,
7885                       Name_Entity,
7886                       Name_Parameter_Types,
7887                       Name_Result_Type,
7888                       Name_Source_Location);
7889
7890             Unit_Name       : Node_Id renames Args (1);
7891             Entity          : Node_Id renames Args (2);
7892             Parameter_Types : Node_Id renames Args (3);
7893             Result_Type     : Node_Id renames Args (4);
7894             Source_Location : Node_Id renames Args (5);
7895
7896          begin
7897             GNAT_Pragma;
7898             Check_Valid_Configuration_Pragma;
7899             Gather_Associations (Names, Args);
7900
7901             if No (Unit_Name) then
7902                Error_Pragma ("missing Unit_Name argument for pragma%");
7903             end if;
7904
7905             if No (Entity)
7906               and then (Present (Parameter_Types)
7907                           or else
7908                         Present (Result_Type)
7909                           or else
7910                         Present (Source_Location))
7911             then
7912                Error_Pragma ("missing Entity argument for pragma%");
7913             end if;
7914
7915             if (Present (Parameter_Types)
7916                        or else
7917                 Present (Result_Type))
7918               and then
7919                 Present (Source_Location)
7920             then
7921                Error_Pragma
7922                  ("parameter profile and source location cannot " &
7923                   "be used together in pragma%");
7924             end if;
7925
7926             Process_Eliminate_Pragma
7927               (N,
7928                Unit_Name,
7929                Entity,
7930                Parameter_Types,
7931                Result_Type,
7932                Source_Location);
7933          end Eliminate;
7934
7935          ------------
7936          -- Export --
7937          ------------
7938
7939          --  pragma Export (
7940          --    [   Convention    =>] convention_IDENTIFIER,
7941          --    [   Entity        =>] local_NAME
7942          --    [, [External_Name =>] static_string_EXPRESSION ]
7943          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7944
7945          when Pragma_Export => Export : declare
7946             C      : Convention_Id;
7947             Def_Id : Entity_Id;
7948
7949             pragma Warnings (Off, C);
7950
7951          begin
7952             Check_Ada_83_Warning;
7953             Check_Arg_Order
7954               ((Name_Convention,
7955                 Name_Entity,
7956                 Name_External_Name,
7957                 Name_Link_Name));
7958             Check_At_Least_N_Arguments (2);
7959             Check_At_Most_N_Arguments  (4);
7960             Process_Convention (C, Def_Id);
7961
7962             if Ekind (Def_Id) /= E_Constant then
7963                Note_Possible_Modification
7964                  (Get_Pragma_Arg (Arg2), Sure => False);
7965             end if;
7966
7967             Process_Interface_Name (Def_Id, Arg3, Arg4);
7968             Set_Exported (Def_Id, Arg2);
7969
7970             --  If the entity is a deferred constant, propagate the information
7971             --  to the full view, because gigi elaborates the full view only.
7972
7973             if Ekind (Def_Id) = E_Constant
7974               and then Present (Full_View (Def_Id))
7975             then
7976                declare
7977                   Id2 : constant Entity_Id := Full_View (Def_Id);
7978                begin
7979                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
7980                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
7981                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
7982                end;
7983             end if;
7984          end Export;
7985
7986          ----------------------
7987          -- Export_Exception --
7988          ----------------------
7989
7990          --  pragma Export_Exception (
7991          --        [Internal         =>] LOCAL_NAME
7992          --     [, [External         =>] EXTERNAL_SYMBOL]
7993          --     [, [Form     =>] Ada | VMS]
7994          --     [, [Code     =>] static_integer_EXPRESSION]);
7995
7996          when Pragma_Export_Exception => Export_Exception : declare
7997             Args  : Args_List (1 .. 4);
7998             Names : constant Name_List (1 .. 4) := (
7999                       Name_Internal,
8000                       Name_External,
8001                       Name_Form,
8002                       Name_Code);
8003
8004             Internal : Node_Id renames Args (1);
8005             External : Node_Id renames Args (2);
8006             Form     : Node_Id renames Args (3);
8007             Code     : Node_Id renames Args (4);
8008
8009          begin
8010             GNAT_Pragma;
8011
8012             if Inside_A_Generic then
8013                Error_Pragma ("pragma% cannot be used for generic entities");
8014             end if;
8015
8016             Gather_Associations (Names, Args);
8017             Process_Extended_Import_Export_Exception_Pragma (
8018               Arg_Internal => Internal,
8019               Arg_External => External,
8020               Arg_Form     => Form,
8021               Arg_Code     => Code);
8022
8023             if not Is_VMS_Exception (Entity (Internal)) then
8024                Set_Exported (Entity (Internal), Internal);
8025             end if;
8026          end Export_Exception;
8027
8028          ---------------------
8029          -- Export_Function --
8030          ---------------------
8031
8032          --  pragma Export_Function (
8033          --        [Internal         =>] LOCAL_NAME
8034          --     [, [External         =>] EXTERNAL_SYMBOL]
8035          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8036          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8037          --     [, [Mechanism        =>] MECHANISM]
8038          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8039
8040          --  EXTERNAL_SYMBOL ::=
8041          --    IDENTIFIER
8042          --  | static_string_EXPRESSION
8043
8044          --  PARAMETER_TYPES ::=
8045          --    null
8046          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8047
8048          --  TYPE_DESIGNATOR ::=
8049          --    subtype_NAME
8050          --  | subtype_Name ' Access
8051
8052          --  MECHANISM ::=
8053          --    MECHANISM_NAME
8054          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8055
8056          --  MECHANISM_ASSOCIATION ::=
8057          --    [formal_parameter_NAME =>] MECHANISM_NAME
8058
8059          --  MECHANISM_NAME ::=
8060          --    Value
8061          --  | Reference
8062          --  | Descriptor [([Class =>] CLASS_NAME)]
8063
8064          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8065
8066          when Pragma_Export_Function => Export_Function : declare
8067             Args  : Args_List (1 .. 6);
8068             Names : constant Name_List (1 .. 6) := (
8069                       Name_Internal,
8070                       Name_External,
8071                       Name_Parameter_Types,
8072                       Name_Result_Type,
8073                       Name_Mechanism,
8074                       Name_Result_Mechanism);
8075
8076             Internal         : Node_Id renames Args (1);
8077             External         : Node_Id renames Args (2);
8078             Parameter_Types  : Node_Id renames Args (3);
8079             Result_Type      : Node_Id renames Args (4);
8080             Mechanism        : Node_Id renames Args (5);
8081             Result_Mechanism : Node_Id renames Args (6);
8082
8083          begin
8084             GNAT_Pragma;
8085             Gather_Associations (Names, Args);
8086             Process_Extended_Import_Export_Subprogram_Pragma (
8087               Arg_Internal         => Internal,
8088               Arg_External         => External,
8089               Arg_Parameter_Types  => Parameter_Types,
8090               Arg_Result_Type      => Result_Type,
8091               Arg_Mechanism        => Mechanism,
8092               Arg_Result_Mechanism => Result_Mechanism);
8093          end Export_Function;
8094
8095          -------------------
8096          -- Export_Object --
8097          -------------------
8098
8099          --  pragma Export_Object (
8100          --        [Internal =>] LOCAL_NAME
8101          --     [, [External =>] EXTERNAL_SYMBOL]
8102          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8103
8104          --  EXTERNAL_SYMBOL ::=
8105          --    IDENTIFIER
8106          --  | static_string_EXPRESSION
8107
8108          --  PARAMETER_TYPES ::=
8109          --    null
8110          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8111
8112          --  TYPE_DESIGNATOR ::=
8113          --    subtype_NAME
8114          --  | subtype_Name ' Access
8115
8116          --  MECHANISM ::=
8117          --    MECHANISM_NAME
8118          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8119
8120          --  MECHANISM_ASSOCIATION ::=
8121          --    [formal_parameter_NAME =>] MECHANISM_NAME
8122
8123          --  MECHANISM_NAME ::=
8124          --    Value
8125          --  | Reference
8126          --  | Descriptor [([Class =>] CLASS_NAME)]
8127
8128          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8129
8130          when Pragma_Export_Object => Export_Object : declare
8131             Args  : Args_List (1 .. 3);
8132             Names : constant Name_List (1 .. 3) := (
8133                       Name_Internal,
8134                       Name_External,
8135                       Name_Size);
8136
8137             Internal : Node_Id renames Args (1);
8138             External : Node_Id renames Args (2);
8139             Size     : Node_Id renames Args (3);
8140
8141          begin
8142             GNAT_Pragma;
8143             Gather_Associations (Names, Args);
8144             Process_Extended_Import_Export_Object_Pragma (
8145               Arg_Internal => Internal,
8146               Arg_External => External,
8147               Arg_Size     => Size);
8148          end Export_Object;
8149
8150          ----------------------
8151          -- Export_Procedure --
8152          ----------------------
8153
8154          --  pragma Export_Procedure (
8155          --        [Internal         =>] LOCAL_NAME
8156          --     [, [External         =>] EXTERNAL_SYMBOL]
8157          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8158          --     [, [Mechanism        =>] MECHANISM]);
8159
8160          --  EXTERNAL_SYMBOL ::=
8161          --    IDENTIFIER
8162          --  | static_string_EXPRESSION
8163
8164          --  PARAMETER_TYPES ::=
8165          --    null
8166          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8167
8168          --  TYPE_DESIGNATOR ::=
8169          --    subtype_NAME
8170          --  | subtype_Name ' Access
8171
8172          --  MECHANISM ::=
8173          --    MECHANISM_NAME
8174          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8175
8176          --  MECHANISM_ASSOCIATION ::=
8177          --    [formal_parameter_NAME =>] MECHANISM_NAME
8178
8179          --  MECHANISM_NAME ::=
8180          --    Value
8181          --  | Reference
8182          --  | Descriptor [([Class =>] CLASS_NAME)]
8183
8184          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8185
8186          when Pragma_Export_Procedure => Export_Procedure : declare
8187             Args  : Args_List (1 .. 4);
8188             Names : constant Name_List (1 .. 4) := (
8189                       Name_Internal,
8190                       Name_External,
8191                       Name_Parameter_Types,
8192                       Name_Mechanism);
8193
8194             Internal        : Node_Id renames Args (1);
8195             External        : Node_Id renames Args (2);
8196             Parameter_Types : Node_Id renames Args (3);
8197             Mechanism       : Node_Id renames Args (4);
8198
8199          begin
8200             GNAT_Pragma;
8201             Gather_Associations (Names, Args);
8202             Process_Extended_Import_Export_Subprogram_Pragma (
8203               Arg_Internal        => Internal,
8204               Arg_External        => External,
8205               Arg_Parameter_Types => Parameter_Types,
8206               Arg_Mechanism       => Mechanism);
8207          end Export_Procedure;
8208
8209          ------------------
8210          -- Export_Value --
8211          ------------------
8212
8213          --  pragma Export_Value (
8214          --     [Value     =>] static_integer_EXPRESSION,
8215          --     [Link_Name =>] static_string_EXPRESSION);
8216
8217          when Pragma_Export_Value =>
8218             GNAT_Pragma;
8219             Check_Arg_Order ((Name_Value, Name_Link_Name));
8220             Check_Arg_Count (2);
8221
8222             Check_Optional_Identifier (Arg1, Name_Value);
8223             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8224
8225             Check_Optional_Identifier (Arg2, Name_Link_Name);
8226             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8227
8228          -----------------------------
8229          -- Export_Valued_Procedure --
8230          -----------------------------
8231
8232          --  pragma Export_Valued_Procedure (
8233          --        [Internal         =>] LOCAL_NAME
8234          --     [, [External         =>] EXTERNAL_SYMBOL,]
8235          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8236          --     [, [Mechanism        =>] MECHANISM]);
8237
8238          --  EXTERNAL_SYMBOL ::=
8239          --    IDENTIFIER
8240          --  | static_string_EXPRESSION
8241
8242          --  PARAMETER_TYPES ::=
8243          --    null
8244          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8245
8246          --  TYPE_DESIGNATOR ::=
8247          --    subtype_NAME
8248          --  | subtype_Name ' Access
8249
8250          --  MECHANISM ::=
8251          --    MECHANISM_NAME
8252          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8253
8254          --  MECHANISM_ASSOCIATION ::=
8255          --    [formal_parameter_NAME =>] MECHANISM_NAME
8256
8257          --  MECHANISM_NAME ::=
8258          --    Value
8259          --  | Reference
8260          --  | Descriptor [([Class =>] CLASS_NAME)]
8261
8262          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8263
8264          when Pragma_Export_Valued_Procedure =>
8265          Export_Valued_Procedure : declare
8266             Args  : Args_List (1 .. 4);
8267             Names : constant Name_List (1 .. 4) := (
8268                       Name_Internal,
8269                       Name_External,
8270                       Name_Parameter_Types,
8271                       Name_Mechanism);
8272
8273             Internal        : Node_Id renames Args (1);
8274             External        : Node_Id renames Args (2);
8275             Parameter_Types : Node_Id renames Args (3);
8276             Mechanism       : Node_Id renames Args (4);
8277
8278          begin
8279             GNAT_Pragma;
8280             Gather_Associations (Names, Args);
8281             Process_Extended_Import_Export_Subprogram_Pragma (
8282               Arg_Internal        => Internal,
8283               Arg_External        => External,
8284               Arg_Parameter_Types => Parameter_Types,
8285               Arg_Mechanism       => Mechanism);
8286          end Export_Valued_Procedure;
8287
8288          -------------------
8289          -- Extend_System --
8290          -------------------
8291
8292          --  pragma Extend_System ([Name =>] Identifier);
8293
8294          when Pragma_Extend_System => Extend_System : declare
8295          begin
8296             GNAT_Pragma;
8297             Check_Valid_Configuration_Pragma;
8298             Check_Arg_Count (1);
8299             Check_Optional_Identifier (Arg1, Name_Name);
8300             Check_Arg_Is_Identifier (Arg1);
8301
8302             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8303
8304             if Name_Len > 4
8305               and then Name_Buffer (1 .. 4) = "aux_"
8306             then
8307                if Present (System_Extend_Pragma_Arg) then
8308                   if Chars (Get_Pragma_Arg (Arg1)) =
8309                      Chars (Expression (System_Extend_Pragma_Arg))
8310                   then
8311                      null;
8312                   else
8313                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8314                      Error_Pragma ("pragma% conflicts with that #");
8315                   end if;
8316
8317                else
8318                   System_Extend_Pragma_Arg := Arg1;
8319
8320                   if not GNAT_Mode then
8321                      System_Extend_Unit := Arg1;
8322                   end if;
8323                end if;
8324             else
8325                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8326             end if;
8327          end Extend_System;
8328
8329          ------------------------
8330          -- Extensions_Allowed --
8331          ------------------------
8332
8333          --  pragma Extensions_Allowed (ON | OFF);
8334
8335          when Pragma_Extensions_Allowed =>
8336             GNAT_Pragma;
8337             Check_Arg_Count (1);
8338             Check_No_Identifiers;
8339             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8340
8341             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8342                Extensions_Allowed := True;
8343                Ada_Version := Ada_Version_Type'Last;
8344
8345             else
8346                Extensions_Allowed := False;
8347                Ada_Version := Ada_Version_Explicit;
8348             end if;
8349
8350          --------------
8351          -- External --
8352          --------------
8353
8354          --  pragma External (
8355          --    [   Convention    =>] convention_IDENTIFIER,
8356          --    [   Entity        =>] local_NAME
8357          --    [, [External_Name =>] static_string_EXPRESSION ]
8358          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8359
8360          when Pragma_External => External : declare
8361                Def_Id : Entity_Id;
8362
8363                C : Convention_Id;
8364                pragma Warnings (Off, C);
8365
8366          begin
8367             GNAT_Pragma;
8368             Check_Arg_Order
8369               ((Name_Convention,
8370                 Name_Entity,
8371                 Name_External_Name,
8372                 Name_Link_Name));
8373             Check_At_Least_N_Arguments (2);
8374             Check_At_Most_N_Arguments  (4);
8375             Process_Convention (C, Def_Id);
8376             Note_Possible_Modification
8377               (Get_Pragma_Arg (Arg2), Sure => False);
8378             Process_Interface_Name (Def_Id, Arg3, Arg4);
8379             Set_Exported (Def_Id, Arg2);
8380          end External;
8381
8382          --------------------------
8383          -- External_Name_Casing --
8384          --------------------------
8385
8386          --  pragma External_Name_Casing (
8387          --    UPPERCASE | LOWERCASE
8388          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8389
8390          when Pragma_External_Name_Casing => External_Name_Casing : declare
8391          begin
8392             GNAT_Pragma;
8393             Check_No_Identifiers;
8394
8395             if Arg_Count = 2 then
8396                Check_Arg_Is_One_Of
8397                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8398
8399                case Chars (Get_Pragma_Arg (Arg2)) is
8400                   when Name_As_Is     =>
8401                      Opt.External_Name_Exp_Casing := As_Is;
8402
8403                   when Name_Uppercase =>
8404                      Opt.External_Name_Exp_Casing := Uppercase;
8405
8406                   when Name_Lowercase =>
8407                      Opt.External_Name_Exp_Casing := Lowercase;
8408
8409                   when others =>
8410                      null;
8411                end case;
8412
8413             else
8414                Check_Arg_Count (1);
8415             end if;
8416
8417             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8418
8419             case Chars (Get_Pragma_Arg (Arg1)) is
8420                when Name_Uppercase =>
8421                   Opt.External_Name_Imp_Casing := Uppercase;
8422
8423                when Name_Lowercase =>
8424                   Opt.External_Name_Imp_Casing := Lowercase;
8425
8426                when others =>
8427                   null;
8428             end case;
8429          end External_Name_Casing;
8430
8431          --------------------------
8432          -- Favor_Top_Level --
8433          --------------------------
8434
8435          --  pragma Favor_Top_Level (type_NAME);
8436
8437          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8438                Named_Entity : Entity_Id;
8439
8440          begin
8441             GNAT_Pragma;
8442             Check_No_Identifiers;
8443             Check_Arg_Count (1);
8444             Check_Arg_Is_Local_Name (Arg1);
8445             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8446
8447             --  If it's an access-to-subprogram type (in particular, not a
8448             --  subtype), set the flag on that type.
8449
8450             if Is_Access_Subprogram_Type (Named_Entity) then
8451                Set_Can_Use_Internal_Rep (Named_Entity, False);
8452
8453             --  Otherwise it's an error (name denotes the wrong sort of entity)
8454
8455             else
8456                Error_Pragma_Arg
8457                  ("access-to-subprogram type expected",
8458                   Get_Pragma_Arg (Arg1));
8459             end if;
8460          end Favor_Top_Level;
8461
8462          ---------------
8463          -- Fast_Math --
8464          ---------------
8465
8466          --  pragma Fast_Math;
8467
8468          when Pragma_Fast_Math =>
8469             GNAT_Pragma;
8470             Check_No_Identifiers;
8471             Check_Valid_Configuration_Pragma;
8472             Fast_Math := True;
8473
8474          ---------------------------
8475          -- Finalize_Storage_Only --
8476          ---------------------------
8477
8478          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8479
8480          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8481             Assoc   : constant Node_Id := Arg1;
8482             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8483             Typ     : Entity_Id;
8484
8485          begin
8486             GNAT_Pragma;
8487             Check_No_Identifiers;
8488             Check_Arg_Count (1);
8489             Check_Arg_Is_Local_Name (Arg1);
8490
8491             Find_Type (Type_Id);
8492             Typ := Entity (Type_Id);
8493
8494             if Typ = Any_Type
8495               or else Rep_Item_Too_Early (Typ, N)
8496             then
8497                return;
8498             else
8499                Typ := Underlying_Type (Typ);
8500             end if;
8501
8502             if not Is_Controlled (Typ) then
8503                Error_Pragma ("pragma% must specify controlled type");
8504             end if;
8505
8506             Check_First_Subtype (Arg1);
8507
8508             if Finalize_Storage_Only (Typ) then
8509                Error_Pragma ("duplicate pragma%, only one allowed");
8510
8511             elsif not Rep_Item_Too_Late (Typ, N) then
8512                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8513             end if;
8514          end Finalize_Storage;
8515
8516          --------------------------
8517          -- Float_Representation --
8518          --------------------------
8519
8520          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8521
8522          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8523
8524          when Pragma_Float_Representation => Float_Representation : declare
8525             Argx : Node_Id;
8526             Digs : Nat;
8527             Ent  : Entity_Id;
8528
8529          begin
8530             GNAT_Pragma;
8531
8532             if Arg_Count = 1 then
8533                Check_Valid_Configuration_Pragma;
8534             else
8535                Check_Arg_Count (2);
8536                Check_Optional_Identifier (Arg2, Name_Entity);
8537                Check_Arg_Is_Local_Name (Arg2);
8538             end if;
8539
8540             Check_No_Identifier (Arg1);
8541             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8542
8543             if not OpenVMS_On_Target then
8544                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8545                   Error_Pragma
8546                     ("?pragma% ignored (applies only to Open'V'M'S)");
8547                end if;
8548
8549                return;
8550             end if;
8551
8552             --  One argument case
8553
8554             if Arg_Count = 1 then
8555                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8556                   if Opt.Float_Format = 'I' then
8557                      Error_Pragma ("'I'E'E'E format previously specified");
8558                   end if;
8559
8560                   Opt.Float_Format := 'V';
8561
8562                else
8563                   if Opt.Float_Format = 'V' then
8564                      Error_Pragma ("'V'A'X format previously specified");
8565                   end if;
8566
8567                   Opt.Float_Format := 'I';
8568                end if;
8569
8570                Set_Standard_Fpt_Formats;
8571
8572             --  Two argument case
8573
8574             else
8575                Argx := Get_Pragma_Arg (Arg2);
8576
8577                if not Is_Entity_Name (Argx)
8578                  or else not Is_Floating_Point_Type (Entity (Argx))
8579                then
8580                   Error_Pragma_Arg
8581                     ("second argument of% pragma must be floating-point type",
8582                      Arg2);
8583                end if;
8584
8585                Ent  := Entity (Argx);
8586                Digs := UI_To_Int (Digits_Value (Ent));
8587
8588                --  Two arguments, VAX_Float case
8589
8590                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8591                   case Digs is
8592                      when  6 => Set_F_Float (Ent);
8593                      when  9 => Set_D_Float (Ent);
8594                      when 15 => Set_G_Float (Ent);
8595
8596                      when others =>
8597                         Error_Pragma_Arg
8598                           ("wrong digits value, must be 6,9 or 15", Arg2);
8599                   end case;
8600
8601                --  Two arguments, IEEE_Float case
8602
8603                else
8604                   case Digs is
8605                      when  6 => Set_IEEE_Short (Ent);
8606                      when 15 => Set_IEEE_Long  (Ent);
8607
8608                      when others =>
8609                         Error_Pragma_Arg
8610                           ("wrong digits value, must be 6 or 15", Arg2);
8611                   end case;
8612                end if;
8613             end if;
8614          end Float_Representation;
8615
8616          -----------
8617          -- Ident --
8618          -----------
8619
8620          --  pragma Ident (static_string_EXPRESSION)
8621
8622          --  Note: pragma Comment shares this processing. Pragma Comment is
8623          --  identical to Ident, except that the restriction of the argument to
8624          --  31 characters and the placement restrictions are not enforced for
8625          --  pragma Comment.
8626
8627          when Pragma_Ident | Pragma_Comment => Ident : declare
8628             Str : Node_Id;
8629
8630          begin
8631             GNAT_Pragma;
8632             Check_Arg_Count (1);
8633             Check_No_Identifiers;
8634             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8635             Store_Note (N);
8636
8637             --  For pragma Ident, preserve DEC compatibility by requiring the
8638             --  pragma to appear in a declarative part or package spec.
8639
8640             if Prag_Id = Pragma_Ident then
8641                Check_Is_In_Decl_Part_Or_Package_Spec;
8642             end if;
8643
8644             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8645
8646             declare
8647                CS : Node_Id;
8648                GP : Node_Id;
8649
8650             begin
8651                GP := Parent (Parent (N));
8652
8653                if Nkind_In (GP, N_Package_Declaration,
8654                                 N_Generic_Package_Declaration)
8655                then
8656                   GP := Parent (GP);
8657                end if;
8658
8659                --  If we have a compilation unit, then record the ident value,
8660                --  checking for improper duplication.
8661
8662                if Nkind (GP) = N_Compilation_Unit then
8663                   CS := Ident_String (Current_Sem_Unit);
8664
8665                   if Present (CS) then
8666
8667                      --  For Ident, we do not permit multiple instances
8668
8669                      if Prag_Id = Pragma_Ident then
8670                         Error_Pragma ("duplicate% pragma not permitted");
8671
8672                      --  For Comment, we concatenate the string, unless we want
8673                      --  to preserve the tree structure for ASIS.
8674
8675                      elsif not ASIS_Mode then
8676                         Start_String (Strval (CS));
8677                         Store_String_Char (' ');
8678                         Store_String_Chars (Strval (Str));
8679                         Set_Strval (CS, End_String);
8680                      end if;
8681
8682                   else
8683                      --  In VMS, the effect of IDENT is achieved by passing
8684                      --  --identification=name as a --for-linker switch.
8685
8686                      if OpenVMS_On_Target then
8687                         Start_String;
8688                         Store_String_Chars
8689                           ("--for-linker=--identification=");
8690                         String_To_Name_Buffer (Strval (Str));
8691                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
8692
8693                         --  Only the last processed IDENT is saved. The main
8694                         --  purpose is so an IDENT associated with a main
8695                         --  procedure will be used in preference to an IDENT
8696                         --  associated with a with'd package.
8697
8698                         Replace_Linker_Option_String
8699                           (End_String, "--for-linker=--identification=");
8700                      end if;
8701
8702                      Set_Ident_String (Current_Sem_Unit, Str);
8703                   end if;
8704
8705                --  For subunits, we just ignore the Ident, since in GNAT these
8706                --  are not separate object files, and hence not separate units
8707                --  in the unit table.
8708
8709                elsif Nkind (GP) = N_Subunit then
8710                   null;
8711
8712                --  Otherwise we have a misplaced pragma Ident, but we ignore
8713                --  this if we are in an instantiation, since it comes from
8714                --  a generic, and has no relevance to the instantiation.
8715
8716                elsif Prag_Id = Pragma_Ident then
8717                   if Instantiation_Location (Loc) = No_Location then
8718                      Error_Pragma ("pragma% only allowed at outer level");
8719                   end if;
8720                end if;
8721             end;
8722          end Ident;
8723
8724          -----------------
8725          -- Implemented --
8726          -----------------
8727
8728          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8729          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8730
8731          when Pragma_Implemented => Implemented : declare
8732             Proc_Id : Entity_Id;
8733             Typ     : Entity_Id;
8734
8735          begin
8736             Ada_2012_Pragma;
8737             Check_Arg_Count (2);
8738             Check_No_Identifiers;
8739             Check_Arg_Is_Identifier (Arg1);
8740             Check_Arg_Is_Local_Name (Arg1);
8741             Check_Arg_Is_One_Of
8742               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8743
8744             --  Extract the name of the local procedure
8745
8746             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8747
8748             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8749             --  primitive procedure of a synchronized tagged type.
8750
8751             if Ekind (Proc_Id) = E_Procedure
8752               and then Is_Primitive (Proc_Id)
8753               and then Present (First_Formal (Proc_Id))
8754             then
8755                Typ := Etype (First_Formal (Proc_Id));
8756
8757                if Is_Tagged_Type (Typ)
8758                  and then
8759
8760                   --  Check for a protected, a synchronized or a task interface
8761
8762                    ((Is_Interface (Typ)
8763                        and then Is_Synchronized_Interface (Typ))
8764
8765                   --  Check for a protected type or a task type that implements
8766                   --  an interface.
8767
8768                    or else
8769                     (Is_Concurrent_Record_Type (Typ)
8770                        and then Present (Interfaces (Typ)))
8771
8772                   --  Check for a private record extension with keyword
8773                   --  "synchronized".
8774
8775                    or else
8776                     (Ekind_In (Typ, E_Record_Type_With_Private,
8777                                     E_Record_Subtype_With_Private)
8778                        and then Synchronized_Present (Parent (Typ))))
8779                then
8780                   null;
8781                else
8782                   Error_Pragma_Arg
8783                     ("controlling formal must be of synchronized " &
8784                      "tagged type", Arg1);
8785                   return;
8786                end if;
8787
8788             --  Procedures declared inside a protected type must be accepted
8789
8790             elsif Ekind (Proc_Id) = E_Procedure
8791               and then Is_Protected_Type (Scope (Proc_Id))
8792             then
8793                null;
8794
8795             --  The first argument is not a primitive procedure
8796
8797             else
8798                Error_Pragma_Arg
8799                  ("pragma % must be applied to a primitive procedure", Arg1);
8800                return;
8801             end if;
8802
8803             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8804             --  By_Protected_Procedure to the primitive procedure of a task
8805             --  interface.
8806
8807             if Chars (Arg2) = Name_By_Protected_Procedure
8808               and then Is_Interface (Typ)
8809               and then Is_Task_Interface (Typ)
8810             then
8811                Error_Pragma_Arg
8812                  ("implementation kind By_Protected_Procedure cannot be " &
8813                   "applied to a task interface primitive", Arg2);
8814                return;
8815             end if;
8816
8817             Record_Rep_Item (Proc_Id, N);
8818          end Implemented;
8819
8820          ----------------------
8821          -- Implicit_Packing --
8822          ----------------------
8823
8824          --  pragma Implicit_Packing;
8825
8826          when Pragma_Implicit_Packing =>
8827             GNAT_Pragma;
8828             Check_Arg_Count (0);
8829             Implicit_Packing := True;
8830
8831          ------------
8832          -- Import --
8833          ------------
8834
8835          --  pragma Import (
8836          --       [Convention    =>] convention_IDENTIFIER,
8837          --       [Entity        =>] local_NAME
8838          --    [, [External_Name =>] static_string_EXPRESSION ]
8839          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8840
8841          when Pragma_Import =>
8842             Check_Ada_83_Warning;
8843             Check_Arg_Order
8844               ((Name_Convention,
8845                 Name_Entity,
8846                 Name_External_Name,
8847                 Name_Link_Name));
8848             Check_At_Least_N_Arguments (2);
8849             Check_At_Most_N_Arguments  (4);
8850             Process_Import_Or_Interface;
8851
8852          ----------------------
8853          -- Import_Exception --
8854          ----------------------
8855
8856          --  pragma Import_Exception (
8857          --        [Internal         =>] LOCAL_NAME
8858          --     [, [External         =>] EXTERNAL_SYMBOL]
8859          --     [, [Form     =>] Ada | VMS]
8860          --     [, [Code     =>] static_integer_EXPRESSION]);
8861
8862          when Pragma_Import_Exception => Import_Exception : declare
8863             Args  : Args_List (1 .. 4);
8864             Names : constant Name_List (1 .. 4) := (
8865                       Name_Internal,
8866                       Name_External,
8867                       Name_Form,
8868                       Name_Code);
8869
8870             Internal : Node_Id renames Args (1);
8871             External : Node_Id renames Args (2);
8872             Form     : Node_Id renames Args (3);
8873             Code     : Node_Id renames Args (4);
8874
8875          begin
8876             GNAT_Pragma;
8877             Gather_Associations (Names, Args);
8878
8879             if Present (External) and then Present (Code) then
8880                Error_Pragma
8881                  ("cannot give both External and Code options for pragma%");
8882             end if;
8883
8884             Process_Extended_Import_Export_Exception_Pragma (
8885               Arg_Internal => Internal,
8886               Arg_External => External,
8887               Arg_Form     => Form,
8888               Arg_Code     => Code);
8889
8890             if not Is_VMS_Exception (Entity (Internal)) then
8891                Set_Imported (Entity (Internal));
8892             end if;
8893          end Import_Exception;
8894
8895          ---------------------
8896          -- Import_Function --
8897          ---------------------
8898
8899          --  pragma Import_Function (
8900          --        [Internal                 =>] LOCAL_NAME,
8901          --     [, [External                 =>] EXTERNAL_SYMBOL]
8902          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
8903          --     [, [Result_Type              =>] SUBTYPE_MARK]
8904          --     [, [Mechanism                =>] MECHANISM]
8905          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
8906          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
8907
8908          --  EXTERNAL_SYMBOL ::=
8909          --    IDENTIFIER
8910          --  | static_string_EXPRESSION
8911
8912          --  PARAMETER_TYPES ::=
8913          --    null
8914          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8915
8916          --  TYPE_DESIGNATOR ::=
8917          --    subtype_NAME
8918          --  | subtype_Name ' Access
8919
8920          --  MECHANISM ::=
8921          --    MECHANISM_NAME
8922          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8923
8924          --  MECHANISM_ASSOCIATION ::=
8925          --    [formal_parameter_NAME =>] MECHANISM_NAME
8926
8927          --  MECHANISM_NAME ::=
8928          --    Value
8929          --  | Reference
8930          --  | Descriptor [([Class =>] CLASS_NAME)]
8931
8932          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8933
8934          when Pragma_Import_Function => Import_Function : declare
8935             Args  : Args_List (1 .. 7);
8936             Names : constant Name_List (1 .. 7) := (
8937                       Name_Internal,
8938                       Name_External,
8939                       Name_Parameter_Types,
8940                       Name_Result_Type,
8941                       Name_Mechanism,
8942                       Name_Result_Mechanism,
8943                       Name_First_Optional_Parameter);
8944
8945             Internal                 : Node_Id renames Args (1);
8946             External                 : Node_Id renames Args (2);
8947             Parameter_Types          : Node_Id renames Args (3);
8948             Result_Type              : Node_Id renames Args (4);
8949             Mechanism                : Node_Id renames Args (5);
8950             Result_Mechanism         : Node_Id renames Args (6);
8951             First_Optional_Parameter : Node_Id renames Args (7);
8952
8953          begin
8954             GNAT_Pragma;
8955             Gather_Associations (Names, Args);
8956             Process_Extended_Import_Export_Subprogram_Pragma (
8957               Arg_Internal                 => Internal,
8958               Arg_External                 => External,
8959               Arg_Parameter_Types          => Parameter_Types,
8960               Arg_Result_Type              => Result_Type,
8961               Arg_Mechanism                => Mechanism,
8962               Arg_Result_Mechanism         => Result_Mechanism,
8963               Arg_First_Optional_Parameter => First_Optional_Parameter);
8964          end Import_Function;
8965
8966          -------------------
8967          -- Import_Object --
8968          -------------------
8969
8970          --  pragma Import_Object (
8971          --        [Internal =>] LOCAL_NAME
8972          --     [, [External =>] EXTERNAL_SYMBOL]
8973          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8974
8975          --  EXTERNAL_SYMBOL ::=
8976          --    IDENTIFIER
8977          --  | static_string_EXPRESSION
8978
8979          when Pragma_Import_Object => Import_Object : declare
8980             Args  : Args_List (1 .. 3);
8981             Names : constant Name_List (1 .. 3) := (
8982                       Name_Internal,
8983                       Name_External,
8984                       Name_Size);
8985
8986             Internal : Node_Id renames Args (1);
8987             External : Node_Id renames Args (2);
8988             Size     : Node_Id renames Args (3);
8989
8990          begin
8991             GNAT_Pragma;
8992             Gather_Associations (Names, Args);
8993             Process_Extended_Import_Export_Object_Pragma (
8994               Arg_Internal => Internal,
8995               Arg_External => External,
8996               Arg_Size     => Size);
8997          end Import_Object;
8998
8999          ----------------------
9000          -- Import_Procedure --
9001          ----------------------
9002
9003          --  pragma Import_Procedure (
9004          --        [Internal                 =>] LOCAL_NAME
9005          --     [, [External                 =>] EXTERNAL_SYMBOL]
9006          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9007          --     [, [Mechanism                =>] MECHANISM]
9008          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9009
9010          --  EXTERNAL_SYMBOL ::=
9011          --    IDENTIFIER
9012          --  | static_string_EXPRESSION
9013
9014          --  PARAMETER_TYPES ::=
9015          --    null
9016          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9017
9018          --  TYPE_DESIGNATOR ::=
9019          --    subtype_NAME
9020          --  | subtype_Name ' Access
9021
9022          --  MECHANISM ::=
9023          --    MECHANISM_NAME
9024          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9025
9026          --  MECHANISM_ASSOCIATION ::=
9027          --    [formal_parameter_NAME =>] MECHANISM_NAME
9028
9029          --  MECHANISM_NAME ::=
9030          --    Value
9031          --  | Reference
9032          --  | Descriptor [([Class =>] CLASS_NAME)]
9033
9034          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9035
9036          when Pragma_Import_Procedure => Import_Procedure : declare
9037             Args  : Args_List (1 .. 5);
9038             Names : constant Name_List (1 .. 5) := (
9039                       Name_Internal,
9040                       Name_External,
9041                       Name_Parameter_Types,
9042                       Name_Mechanism,
9043                       Name_First_Optional_Parameter);
9044
9045             Internal                 : Node_Id renames Args (1);
9046             External                 : Node_Id renames Args (2);
9047             Parameter_Types          : Node_Id renames Args (3);
9048             Mechanism                : Node_Id renames Args (4);
9049             First_Optional_Parameter : Node_Id renames Args (5);
9050
9051          begin
9052             GNAT_Pragma;
9053             Gather_Associations (Names, Args);
9054             Process_Extended_Import_Export_Subprogram_Pragma (
9055               Arg_Internal                 => Internal,
9056               Arg_External                 => External,
9057               Arg_Parameter_Types          => Parameter_Types,
9058               Arg_Mechanism                => Mechanism,
9059               Arg_First_Optional_Parameter => First_Optional_Parameter);
9060          end Import_Procedure;
9061
9062          -----------------------------
9063          -- Import_Valued_Procedure --
9064          -----------------------------
9065
9066          --  pragma Import_Valued_Procedure (
9067          --        [Internal                 =>] LOCAL_NAME
9068          --     [, [External                 =>] EXTERNAL_SYMBOL]
9069          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9070          --     [, [Mechanism                =>] MECHANISM]
9071          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9072
9073          --  EXTERNAL_SYMBOL ::=
9074          --    IDENTIFIER
9075          --  | static_string_EXPRESSION
9076
9077          --  PARAMETER_TYPES ::=
9078          --    null
9079          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9080
9081          --  TYPE_DESIGNATOR ::=
9082          --    subtype_NAME
9083          --  | subtype_Name ' Access
9084
9085          --  MECHANISM ::=
9086          --    MECHANISM_NAME
9087          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9088
9089          --  MECHANISM_ASSOCIATION ::=
9090          --    [formal_parameter_NAME =>] MECHANISM_NAME
9091
9092          --  MECHANISM_NAME ::=
9093          --    Value
9094          --  | Reference
9095          --  | Descriptor [([Class =>] CLASS_NAME)]
9096
9097          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9098
9099          when Pragma_Import_Valued_Procedure =>
9100          Import_Valued_Procedure : declare
9101             Args  : Args_List (1 .. 5);
9102             Names : constant Name_List (1 .. 5) := (
9103                       Name_Internal,
9104                       Name_External,
9105                       Name_Parameter_Types,
9106                       Name_Mechanism,
9107                       Name_First_Optional_Parameter);
9108
9109             Internal                 : Node_Id renames Args (1);
9110             External                 : Node_Id renames Args (2);
9111             Parameter_Types          : Node_Id renames Args (3);
9112             Mechanism                : Node_Id renames Args (4);
9113             First_Optional_Parameter : Node_Id renames Args (5);
9114
9115          begin
9116             GNAT_Pragma;
9117             Gather_Associations (Names, Args);
9118             Process_Extended_Import_Export_Subprogram_Pragma (
9119               Arg_Internal                 => Internal,
9120               Arg_External                 => External,
9121               Arg_Parameter_Types          => Parameter_Types,
9122               Arg_Mechanism                => Mechanism,
9123               Arg_First_Optional_Parameter => First_Optional_Parameter);
9124          end Import_Valued_Procedure;
9125
9126          -----------------
9127          -- Independent --
9128          -----------------
9129
9130          --  pragma Independent (LOCAL_NAME);
9131
9132          when Pragma_Independent => Independent : declare
9133             E_Id : Node_Id;
9134             E    : Entity_Id;
9135             D    : Node_Id;
9136             K    : Node_Kind;
9137
9138          begin
9139             Check_Ada_83_Warning;
9140             Ada_2012_Pragma;
9141             Check_No_Identifiers;
9142             Check_Arg_Count (1);
9143             Check_Arg_Is_Local_Name (Arg1);
9144             E_Id := Get_Pragma_Arg (Arg1);
9145
9146             if Etype (E_Id) = Any_Type then
9147                return;
9148             end if;
9149
9150             E := Entity (E_Id);
9151             D := Declaration_Node (E);
9152             K := Nkind (D);
9153
9154             --  Check duplicate before we chain ourselves!
9155
9156             Check_Duplicate_Pragma (E);
9157
9158             --  Check appropriate entity
9159
9160             if Is_Type (E) then
9161                if Rep_Item_Too_Early (E, N)
9162                     or else
9163                   Rep_Item_Too_Late (E, N)
9164                then
9165                   return;
9166                else
9167                   Check_First_Subtype (Arg1);
9168                end if;
9169
9170             elsif K = N_Object_Declaration
9171               or else (K = N_Component_Declaration
9172                        and then Original_Record_Component (E) = E)
9173             then
9174                if Rep_Item_Too_Late (E, N) then
9175                   return;
9176                end if;
9177
9178             else
9179                Error_Pragma_Arg
9180                  ("inappropriate entity for pragma%", Arg1);
9181             end if;
9182
9183             Independence_Checks.Append ((N, E));
9184          end Independent;
9185
9186          ----------------------------
9187          -- Independent_Components --
9188          ----------------------------
9189
9190          --  pragma Atomic_Components (array_LOCAL_NAME);
9191
9192          --  This processing is shared by Volatile_Components
9193
9194          when Pragma_Independent_Components => Independent_Components : declare
9195             E_Id : Node_Id;
9196             E    : Entity_Id;
9197             D    : Node_Id;
9198             K    : Node_Kind;
9199
9200          begin
9201             Check_Ada_83_Warning;
9202             Ada_2012_Pragma;
9203             Check_No_Identifiers;
9204             Check_Arg_Count (1);
9205             Check_Arg_Is_Local_Name (Arg1);
9206             E_Id := Get_Pragma_Arg (Arg1);
9207
9208             if Etype (E_Id) = Any_Type then
9209                return;
9210             end if;
9211
9212             E := Entity (E_Id);
9213
9214             --  Check duplicate before we chain ourselves!
9215
9216             Check_Duplicate_Pragma (E);
9217
9218             --  Check appropriate entity
9219
9220             if Rep_Item_Too_Early (E, N)
9221                  or else
9222                Rep_Item_Too_Late (E, N)
9223             then
9224                return;
9225             end if;
9226
9227             D := Declaration_Node (E);
9228             K := Nkind (D);
9229
9230             if (K = N_Full_Type_Declaration
9231                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9232               or else
9233                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9234                    and then Nkind (D) = N_Object_Declaration
9235                    and then Nkind (Object_Definition (D)) =
9236                                        N_Constrained_Array_Definition)
9237             then
9238                Independence_Checks.Append ((N, E));
9239
9240             else
9241                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9242             end if;
9243          end Independent_Components;
9244
9245          ------------------------
9246          -- Initialize_Scalars --
9247          ------------------------
9248
9249          --  pragma Initialize_Scalars;
9250
9251          when Pragma_Initialize_Scalars =>
9252             GNAT_Pragma;
9253             Check_Arg_Count (0);
9254             Check_Valid_Configuration_Pragma;
9255             Check_Restriction (No_Initialize_Scalars, N);
9256
9257             --  Initialize_Scalars creates false positives in CodePeer,
9258             --  so ignore this pragma in this mode.
9259
9260             if not Restriction_Active (No_Initialize_Scalars)
9261               and then not CodePeer_Mode
9262             then
9263                Init_Or_Norm_Scalars := True;
9264                Initialize_Scalars := True;
9265             end if;
9266
9267          ------------
9268          -- Inline --
9269          ------------
9270
9271          --  pragma Inline ( NAME {, NAME} );
9272
9273          when Pragma_Inline =>
9274
9275             --  Pragma is active if inlining option is active
9276
9277             Process_Inline (Inline_Active);
9278
9279          -------------------
9280          -- Inline_Always --
9281          -------------------
9282
9283          --  pragma Inline_Always ( NAME {, NAME} );
9284
9285          when Pragma_Inline_Always =>
9286             GNAT_Pragma;
9287
9288             --  Pragma always active unless in CodePeer mode, since this causes
9289             --  walk order issues.
9290
9291             if not CodePeer_Mode then
9292                Process_Inline (True);
9293             end if;
9294
9295          --------------------
9296          -- Inline_Generic --
9297          --------------------
9298
9299          --  pragma Inline_Generic (NAME {, NAME});
9300
9301          when Pragma_Inline_Generic =>
9302             GNAT_Pragma;
9303             Process_Generic_List;
9304
9305          ----------------------
9306          -- Inspection_Point --
9307          ----------------------
9308
9309          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9310
9311          when Pragma_Inspection_Point => Inspection_Point : declare
9312             Arg : Node_Id;
9313             Exp : Node_Id;
9314
9315          begin
9316             if Arg_Count > 0 then
9317                Arg := Arg1;
9318                loop
9319                   Exp := Get_Pragma_Arg (Arg);
9320                   Analyze (Exp);
9321
9322                   if not Is_Entity_Name (Exp)
9323                     or else not Is_Object (Entity (Exp))
9324                   then
9325                      Error_Pragma_Arg ("object name required", Arg);
9326                   end if;
9327
9328                   Next (Arg);
9329                   exit when No (Arg);
9330                end loop;
9331             end if;
9332          end Inspection_Point;
9333
9334          ---------------
9335          -- Interface --
9336          ---------------
9337
9338          --  pragma Interface (
9339          --    [   Convention    =>] convention_IDENTIFIER,
9340          --    [   Entity        =>] local_NAME
9341          --    [, [External_Name =>] static_string_EXPRESSION ]
9342          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9343
9344          when Pragma_Interface =>
9345             GNAT_Pragma;
9346             Check_Arg_Order
9347               ((Name_Convention,
9348                 Name_Entity,
9349                 Name_External_Name,
9350                 Name_Link_Name));
9351             Check_At_Least_N_Arguments (2);
9352             Check_At_Most_N_Arguments  (4);
9353             Process_Import_Or_Interface;
9354
9355             --  In Ada 2005, the permission to use Interface (a reserved word)
9356             --  as a pragma name is considered an obsolescent feature.
9357
9358             if Ada_Version >= Ada_2005 then
9359                Check_Restriction
9360                  (No_Obsolescent_Features, Pragma_Identifier (N));
9361             end if;
9362
9363          --------------------
9364          -- Interface_Name --
9365          --------------------
9366
9367          --  pragma Interface_Name (
9368          --    [  Entity        =>] local_NAME
9369          --    [,[External_Name =>] static_string_EXPRESSION ]
9370          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9371
9372          when Pragma_Interface_Name => Interface_Name : declare
9373             Id     : Node_Id;
9374             Def_Id : Entity_Id;
9375             Hom_Id : Entity_Id;
9376             Found  : Boolean;
9377
9378          begin
9379             GNAT_Pragma;
9380             Check_Arg_Order
9381               ((Name_Entity, Name_External_Name, Name_Link_Name));
9382             Check_At_Least_N_Arguments (2);
9383             Check_At_Most_N_Arguments  (3);
9384             Id := Get_Pragma_Arg (Arg1);
9385             Analyze (Id);
9386
9387             if not Is_Entity_Name (Id) then
9388                Error_Pragma_Arg
9389                  ("first argument for pragma% must be entity name", Arg1);
9390             elsif Etype (Id) = Any_Type then
9391                return;
9392             else
9393                Def_Id := Entity (Id);
9394             end if;
9395
9396             --  Special DEC-compatible processing for the object case, forces
9397             --  object to be imported.
9398
9399             if Ekind (Def_Id) = E_Variable then
9400                Kill_Size_Check_Code (Def_Id);
9401                Note_Possible_Modification (Id, Sure => False);
9402
9403                --  Initialization is not allowed for imported variable
9404
9405                if Present (Expression (Parent (Def_Id)))
9406                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9407                then
9408                   Error_Msg_Sloc := Sloc (Def_Id);
9409                   Error_Pragma_Arg
9410                     ("no initialization allowed for declaration of& #",
9411                      Arg2);
9412
9413                else
9414                   --  For compatibility, support VADS usage of providing both
9415                   --  pragmas Interface and Interface_Name to obtain the effect
9416                   --  of a single Import pragma.
9417
9418                   if Is_Imported (Def_Id)
9419                     and then Present (First_Rep_Item (Def_Id))
9420                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9421                     and then
9422                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9423                   then
9424                      null;
9425                   else
9426                      Set_Imported (Def_Id);
9427                   end if;
9428
9429                   Set_Is_Public (Def_Id);
9430                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9431                end if;
9432
9433             --  Otherwise must be subprogram
9434
9435             elsif not Is_Subprogram (Def_Id) then
9436                Error_Pragma_Arg
9437                  ("argument of pragma% is not subprogram", Arg1);
9438
9439             else
9440                Check_At_Most_N_Arguments (3);
9441                Hom_Id := Def_Id;
9442                Found := False;
9443
9444                --  Loop through homonyms
9445
9446                loop
9447                   Def_Id := Get_Base_Subprogram (Hom_Id);
9448
9449                   if Is_Imported (Def_Id) then
9450                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9451                      Found := True;
9452                   end if;
9453
9454                   exit when From_Aspect_Specification (N);
9455                   Hom_Id := Homonym (Hom_Id);
9456
9457                   exit when No (Hom_Id)
9458                     or else Scope (Hom_Id) /= Current_Scope;
9459                end loop;
9460
9461                if not Found then
9462                   Error_Pragma_Arg
9463                     ("argument of pragma% is not imported subprogram",
9464                      Arg1);
9465                end if;
9466             end if;
9467          end Interface_Name;
9468
9469          -----------------------
9470          -- Interrupt_Handler --
9471          -----------------------
9472
9473          --  pragma Interrupt_Handler (handler_NAME);
9474
9475          when Pragma_Interrupt_Handler =>
9476             Check_Ada_83_Warning;
9477             Check_Arg_Count (1);
9478             Check_No_Identifiers;
9479
9480             if No_Run_Time_Mode then
9481                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9482             else
9483                Check_Interrupt_Or_Attach_Handler;
9484                Process_Interrupt_Or_Attach_Handler;
9485             end if;
9486
9487          ------------------------
9488          -- Interrupt_Priority --
9489          ------------------------
9490
9491          --  pragma Interrupt_Priority [(EXPRESSION)];
9492
9493          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9494             P   : constant Node_Id := Parent (N);
9495             Arg : Node_Id;
9496
9497          begin
9498             Check_Ada_83_Warning;
9499
9500             if Arg_Count /= 0 then
9501                Arg := Get_Pragma_Arg (Arg1);
9502                Check_Arg_Count (1);
9503                Check_No_Identifiers;
9504
9505                --  The expression must be analyzed in the special manner
9506                --  described in "Handling of Default and Per-Object
9507                --  Expressions" in sem.ads.
9508
9509                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9510             end if;
9511
9512             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9513                Pragma_Misplaced;
9514                return;
9515
9516             elsif Has_Pragma_Priority (P) then
9517                Error_Pragma ("duplicate pragma% not allowed");
9518
9519             else
9520                Set_Has_Pragma_Priority (P, True);
9521                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9522             end if;
9523          end Interrupt_Priority;
9524
9525          ---------------------
9526          -- Interrupt_State --
9527          ---------------------
9528
9529          --  pragma Interrupt_State (
9530          --    [Name  =>] INTERRUPT_ID,
9531          --    [State =>] INTERRUPT_STATE);
9532
9533          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9534          --  INTERRUPT_STATE => System | Runtime | User
9535
9536          --  Note: if the interrupt id is given as an identifier, then it must
9537          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9538          --  given as a static integer expression which must be in the range of
9539          --  Ada.Interrupts.Interrupt_ID.
9540
9541          when Pragma_Interrupt_State => Interrupt_State : declare
9542
9543             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9544             --  This is the entity Ada.Interrupts.Interrupt_ID;
9545
9546             State_Type : Character;
9547             --  Set to 's'/'r'/'u' for System/Runtime/User
9548
9549             IST_Num : Pos;
9550             --  Index to entry in Interrupt_States table
9551
9552             Int_Val : Uint;
9553             --  Value of interrupt
9554
9555             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9556             --  The first argument to the pragma
9557
9558             Int_Ent : Entity_Id;
9559             --  Interrupt entity in Ada.Interrupts.Names
9560
9561          begin
9562             GNAT_Pragma;
9563             Check_Arg_Order ((Name_Name, Name_State));
9564             Check_Arg_Count (2);
9565
9566             Check_Optional_Identifier (Arg1, Name_Name);
9567             Check_Optional_Identifier (Arg2, Name_State);
9568             Check_Arg_Is_Identifier (Arg2);
9569
9570             --  First argument is identifier
9571
9572             if Nkind (Arg1X) = N_Identifier then
9573
9574                --  Search list of names in Ada.Interrupts.Names
9575
9576                Int_Ent := First_Entity (RTE (RE_Names));
9577                loop
9578                   if No (Int_Ent) then
9579                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9580
9581                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9582                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9583                      exit;
9584                   end if;
9585
9586                   Next_Entity (Int_Ent);
9587                end loop;
9588
9589             --  First argument is not an identifier, so it must be a static
9590             --  expression of type Ada.Interrupts.Interrupt_ID.
9591
9592             else
9593                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9594                Int_Val := Expr_Value (Arg1X);
9595
9596                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9597                     or else
9598                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9599                then
9600                   Error_Pragma_Arg
9601                     ("value not in range of type " &
9602                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9603                end if;
9604             end if;
9605
9606             --  Check OK state
9607
9608             case Chars (Get_Pragma_Arg (Arg2)) is
9609                when Name_Runtime => State_Type := 'r';
9610                when Name_System  => State_Type := 's';
9611                when Name_User    => State_Type := 'u';
9612
9613                when others =>
9614                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
9615             end case;
9616
9617             --  Check if entry is already stored
9618
9619             IST_Num := Interrupt_States.First;
9620             loop
9621                --  If entry not found, add it
9622
9623                if IST_Num > Interrupt_States.Last then
9624                   Interrupt_States.Append
9625                     ((Interrupt_Number => UI_To_Int (Int_Val),
9626                       Interrupt_State  => State_Type,
9627                       Pragma_Loc       => Loc));
9628                   exit;
9629
9630                --  Case of entry for the same entry
9631
9632                elsif Int_Val = Interrupt_States.Table (IST_Num).
9633                                                            Interrupt_Number
9634                then
9635                   --  If state matches, done, no need to make redundant entry
9636
9637                   exit when
9638                     State_Type = Interrupt_States.Table (IST_Num).
9639                                                            Interrupt_State;
9640
9641                   --  Otherwise if state does not match, error
9642
9643                   Error_Msg_Sloc :=
9644                     Interrupt_States.Table (IST_Num).Pragma_Loc;
9645                   Error_Pragma_Arg
9646                     ("state conflicts with that given #", Arg2);
9647                   exit;
9648                end if;
9649
9650                IST_Num := IST_Num + 1;
9651             end loop;
9652          end Interrupt_State;
9653
9654          ---------------
9655          -- Invariant --
9656          ---------------
9657
9658          --  pragma Invariant
9659          --    ([Entity =>]    type_LOCAL_NAME,
9660          --     [Check  =>]    EXPRESSION
9661          --     [,[Message =>] String_Expression]);
9662
9663          when Pragma_Invariant => Invariant : declare
9664             Type_Id : Node_Id;
9665             Typ     : Entity_Id;
9666
9667             Discard : Boolean;
9668             pragma Unreferenced (Discard);
9669
9670          begin
9671             GNAT_Pragma;
9672             Check_At_Least_N_Arguments (2);
9673             Check_At_Most_N_Arguments (3);
9674             Check_Optional_Identifier (Arg1, Name_Entity);
9675             Check_Optional_Identifier (Arg2, Name_Check);
9676
9677             if Arg_Count = 3 then
9678                Check_Optional_Identifier (Arg3, Name_Message);
9679                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9680             end if;
9681
9682             Check_Arg_Is_Local_Name (Arg1);
9683
9684             Type_Id := Get_Pragma_Arg (Arg1);
9685             Find_Type (Type_Id);
9686             Typ := Entity (Type_Id);
9687
9688             if Typ = Any_Type then
9689                return;
9690
9691             elsif not Ekind_In (Typ, E_Private_Type,
9692                                      E_Record_Type_With_Private,
9693                                      E_Limited_Private_Type)
9694             then
9695                Error_Pragma_Arg
9696                  ("pragma% only allowed for private type", Arg1);
9697             end if;
9698
9699             --  Note that the type has at least one invariant, and also that
9700             --  it has inheritable invariants if we have Invariant'Class.
9701
9702             Set_Has_Invariants (Typ);
9703
9704             if Class_Present (N) then
9705                Set_Has_Inheritable_Invariants (Typ);
9706             end if;
9707
9708             --  The remaining processing is simply to link the pragma on to
9709             --  the rep item chain, for processing when the type is frozen.
9710             --  This is accomplished by a call to Rep_Item_Too_Late.
9711
9712             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9713          end Invariant;
9714
9715          ----------------------
9716          -- Java_Constructor --
9717          ----------------------
9718
9719          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9720
9721          --  Also handles pragma CIL_Constructor
9722
9723          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9724          Java_Constructor : declare
9725             Convention  : Convention_Id;
9726             Def_Id      : Entity_Id;
9727             Hom_Id      : Entity_Id;
9728             Id          : Entity_Id;
9729             This_Formal : Entity_Id;
9730
9731          begin
9732             GNAT_Pragma;
9733             Check_Arg_Count (1);
9734             Check_Optional_Identifier (Arg1, Name_Entity);
9735             Check_Arg_Is_Local_Name (Arg1);
9736
9737             Id := Get_Pragma_Arg (Arg1);
9738             Find_Program_Unit_Name (Id);
9739
9740             --  If we did not find the name, we are done
9741
9742             if Etype (Id) = Any_Type then
9743                return;
9744             end if;
9745
9746             --  Check wrong use of pragma in wrong VM target
9747
9748             if VM_Target = No_VM then
9749                return;
9750
9751             elsif VM_Target = CLI_Target
9752               and then Prag_Id = Pragma_Java_Constructor
9753             then
9754                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9755
9756             elsif VM_Target = JVM_Target
9757               and then Prag_Id = Pragma_CIL_Constructor
9758             then
9759                Error_Pragma ("must use pragma 'Java_'Constructor");
9760             end if;
9761
9762             case Prag_Id is
9763                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
9764                when Pragma_Java_Constructor => Convention := Convention_Java;
9765                when others                  => null;
9766             end case;
9767
9768             Hom_Id := Entity (Id);
9769
9770             --  Loop through homonyms
9771
9772             loop
9773                Def_Id := Get_Base_Subprogram (Hom_Id);
9774
9775                --  The constructor is required to be a function
9776
9777                if Ekind (Def_Id) /= E_Function then
9778                   if VM_Target = JVM_Target then
9779                      Error_Pragma_Arg
9780                        ("pragma% requires function returning a " &
9781                         "'Java access type", Def_Id);
9782                   else
9783                      Error_Pragma_Arg
9784                        ("pragma% requires function returning a " &
9785                         "'C'I'L access type", Def_Id);
9786                   end if;
9787                end if;
9788
9789                --  Check arguments: For tagged type the first formal must be
9790                --  named "this" and its type must be a named access type
9791                --  designating a class-wide tagged type that has convention
9792                --  CIL/Java. The first formal must also have a null default
9793                --  value. For example:
9794
9795                --      type Typ is tagged ...
9796                --      type Ref is access all Typ;
9797                --      pragma Convention (CIL, Typ);
9798
9799                --      function New_Typ (This : Ref) return Ref;
9800                --      function New_Typ (This : Ref; I : Integer) return Ref;
9801                --      pragma Cil_Constructor (New_Typ);
9802
9803                --  Reason: The first formal must NOT be a primitive of the
9804                --  tagged type.
9805
9806                --  This rule also applies to constructors of delegates used
9807                --  to interface with standard target libraries. For example:
9808
9809                --      type Delegate is access procedure ...
9810                --      pragma Import (CIL, Delegate, ...);
9811
9812                --      function new_Delegate
9813                --        (This : Delegate := null; ... ) return Delegate;
9814
9815                --  For value-types this rule does not apply.
9816
9817                if not Is_Value_Type (Etype (Def_Id)) then
9818                   if No (First_Formal (Def_Id)) then
9819                      Error_Msg_Name_1 := Pname;
9820                      Error_Msg_N ("% function must have parameters", Def_Id);
9821                      return;
9822                   end if;
9823
9824                   --  In the JRE library we have several occurrences in which
9825                   --  the "this" parameter is not the first formal.
9826
9827                   This_Formal := First_Formal (Def_Id);
9828
9829                   --  In the JRE library we have several occurrences in which
9830                   --  the "this" parameter is not the first formal. Search for
9831                   --  it.
9832
9833                   if VM_Target = JVM_Target then
9834                      while Present (This_Formal)
9835                        and then Get_Name_String (Chars (This_Formal)) /= "this"
9836                      loop
9837                         Next_Formal (This_Formal);
9838                      end loop;
9839
9840                      if No (This_Formal) then
9841                         This_Formal := First_Formal (Def_Id);
9842                      end if;
9843                   end if;
9844
9845                   --  Warning: The first parameter should be named "this".
9846                   --  We temporarily allow it because we have the following
9847                   --  case in the Java runtime (file s-osinte.ads) ???
9848
9849                   --    function new_Thread
9850                   --      (Self_Id : System.Address) return Thread_Id;
9851                   --    pragma Java_Constructor (new_Thread);
9852
9853                   if VM_Target = JVM_Target
9854                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
9855                                = "self_id"
9856                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
9857                   then
9858                      null;
9859
9860                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
9861                      Error_Msg_Name_1 := Pname;
9862                      Error_Msg_N
9863                        ("first formal of % function must be named `this`",
9864                         Parent (This_Formal));
9865
9866                   elsif not Is_Access_Type (Etype (This_Formal)) then
9867                      Error_Msg_Name_1 := Pname;
9868                      Error_Msg_N
9869                        ("first formal of % function must be an access type",
9870                         Parameter_Type (Parent (This_Formal)));
9871
9872                   --  For delegates the type of the first formal must be a
9873                   --  named access-to-subprogram type (see previous example)
9874
9875                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
9876                     and then Ekind (Etype (This_Formal))
9877                                /= E_Access_Subprogram_Type
9878                   then
9879                      Error_Msg_Name_1 := Pname;
9880                      Error_Msg_N
9881                        ("first formal of % function must be a named access" &
9882                         " to subprogram type",
9883                         Parameter_Type (Parent (This_Formal)));
9884
9885                   --  Warning: We should reject anonymous access types because
9886                   --  the constructor must not be handled as a primitive of the
9887                   --  tagged type. We temporarily allow it because this profile
9888                   --  is currently generated by cil2ada???
9889
9890                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
9891                     and then not Ekind_In (Etype (This_Formal),
9892                                              E_Access_Type,
9893                                              E_General_Access_Type,
9894                                              E_Anonymous_Access_Type)
9895                   then
9896                      Error_Msg_Name_1 := Pname;
9897                      Error_Msg_N
9898                        ("first formal of % function must be a named access" &
9899                         " type",
9900                         Parameter_Type (Parent (This_Formal)));
9901
9902                   elsif Atree.Convention
9903                          (Designated_Type (Etype (This_Formal))) /= Convention
9904                   then
9905                      Error_Msg_Name_1 := Pname;
9906
9907                      if Convention = Convention_Java then
9908                         Error_Msg_N
9909                           ("pragma% requires convention 'Cil in designated" &
9910                            " type",
9911                            Parameter_Type (Parent (This_Formal)));
9912                      else
9913                         Error_Msg_N
9914                           ("pragma% requires convention 'Java in designated" &
9915                            " type",
9916                            Parameter_Type (Parent (This_Formal)));
9917                      end if;
9918
9919                   elsif No (Expression (Parent (This_Formal)))
9920                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
9921                   then
9922                      Error_Msg_Name_1 := Pname;
9923                      Error_Msg_N
9924                        ("pragma% requires first formal with default `null`",
9925                         Parameter_Type (Parent (This_Formal)));
9926                   end if;
9927                end if;
9928
9929                --  Check result type: the constructor must be a function
9930                --  returning:
9931                --   * a value type (only allowed in the CIL compiler)
9932                --   * an access-to-subprogram type with convention Java/CIL
9933                --   * an access-type designating a type that has convention
9934                --     Java/CIL.
9935
9936                if Is_Value_Type (Etype (Def_Id)) then
9937                   null;
9938
9939                --  Access-to-subprogram type with convention Java/CIL
9940
9941                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
9942                   if Atree.Convention (Etype (Def_Id)) /= Convention then
9943                      if Convention = Convention_Java then
9944                         Error_Pragma_Arg
9945                           ("pragma% requires function returning a " &
9946                            "'Java access type", Arg1);
9947                      else
9948                         pragma Assert (Convention = Convention_CIL);
9949                         Error_Pragma_Arg
9950                           ("pragma% requires function returning a " &
9951                            "'C'I'L access type", Arg1);
9952                      end if;
9953                   end if;
9954
9955                elsif Ekind (Etype (Def_Id)) in Access_Kind then
9956                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
9957                                                    E_General_Access_Type)
9958                     or else
9959                       Atree.Convention
9960                         (Designated_Type (Etype (Def_Id))) /= Convention
9961                   then
9962                      Error_Msg_Name_1 := Pname;
9963
9964                      if Convention = Convention_Java then
9965                         Error_Pragma_Arg
9966                           ("pragma% requires function returning a named" &
9967                            "'Java access type", Arg1);
9968                      else
9969                         Error_Pragma_Arg
9970                           ("pragma% requires function returning a named" &
9971                            "'C'I'L access type", Arg1);
9972                      end if;
9973                   end if;
9974                end if;
9975
9976                Set_Is_Constructor (Def_Id);
9977                Set_Convention     (Def_Id, Convention);
9978                Set_Is_Imported    (Def_Id);
9979
9980                exit when From_Aspect_Specification (N);
9981                Hom_Id := Homonym (Hom_Id);
9982
9983                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
9984             end loop;
9985          end Java_Constructor;
9986
9987          ----------------------
9988          -- Java_Interface --
9989          ----------------------
9990
9991          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
9992
9993          when Pragma_Java_Interface => Java_Interface : declare
9994             Arg : Node_Id;
9995             Typ : Entity_Id;
9996
9997          begin
9998             GNAT_Pragma;
9999             Check_Arg_Count (1);
10000             Check_Optional_Identifier (Arg1, Name_Entity);
10001             Check_Arg_Is_Local_Name (Arg1);
10002
10003             Arg := Get_Pragma_Arg (Arg1);
10004             Analyze (Arg);
10005
10006             if Etype (Arg) = Any_Type then
10007                return;
10008             end if;
10009
10010             if not Is_Entity_Name (Arg)
10011               or else not Is_Type (Entity (Arg))
10012             then
10013                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10014             end if;
10015
10016             Typ := Underlying_Type (Entity (Arg));
10017
10018             --  For now simply check some of the semantic constraints on the
10019             --  type. This currently leaves out some restrictions on interface
10020             --  types, namely that the parent type must be java.lang.Object.Typ
10021             --  and that all primitives of the type should be declared
10022             --  abstract. ???
10023
10024             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10025                Error_Pragma_Arg ("pragma% requires an abstract "
10026                  & "tagged type", Arg1);
10027
10028             elsif not Has_Discriminants (Typ)
10029               or else Ekind (Etype (First_Discriminant (Typ)))
10030                         /= E_Anonymous_Access_Type
10031               or else
10032                 not Is_Class_Wide_Type
10033                       (Designated_Type (Etype (First_Discriminant (Typ))))
10034             then
10035                Error_Pragma_Arg
10036                  ("type must have a class-wide access discriminant", Arg1);
10037             end if;
10038          end Java_Interface;
10039
10040          ----------------
10041          -- Keep_Names --
10042          ----------------
10043
10044          --  pragma Keep_Names ([On => ] local_NAME);
10045
10046          when Pragma_Keep_Names => Keep_Names : declare
10047             Arg : Node_Id;
10048
10049          begin
10050             GNAT_Pragma;
10051             Check_Arg_Count (1);
10052             Check_Optional_Identifier (Arg1, Name_On);
10053             Check_Arg_Is_Local_Name (Arg1);
10054
10055             Arg := Get_Pragma_Arg (Arg1);
10056             Analyze (Arg);
10057
10058             if Etype (Arg) = Any_Type then
10059                return;
10060             end if;
10061
10062             if not Is_Entity_Name (Arg)
10063               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10064             then
10065                Error_Pragma_Arg
10066                  ("pragma% requires a local enumeration type", Arg1);
10067             end if;
10068
10069             Set_Discard_Names (Entity (Arg), False);
10070          end Keep_Names;
10071
10072          -------------
10073          -- License --
10074          -------------
10075
10076          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10077
10078          when Pragma_License =>
10079             GNAT_Pragma;
10080             Check_Arg_Count (1);
10081             Check_No_Identifiers;
10082             Check_Valid_Configuration_Pragma;
10083             Check_Arg_Is_Identifier (Arg1);
10084
10085             declare
10086                Sind : constant Source_File_Index :=
10087                         Source_Index (Current_Sem_Unit);
10088
10089             begin
10090                case Chars (Get_Pragma_Arg (Arg1)) is
10091                   when Name_GPL =>
10092                      Set_License (Sind, GPL);
10093
10094                   when Name_Modified_GPL =>
10095                      Set_License (Sind, Modified_GPL);
10096
10097                   when Name_Restricted =>
10098                      Set_License (Sind, Restricted);
10099
10100                   when Name_Unrestricted =>
10101                      Set_License (Sind, Unrestricted);
10102
10103                   when others =>
10104                      Error_Pragma_Arg ("invalid license name", Arg1);
10105                end case;
10106             end;
10107
10108          ---------------
10109          -- Link_With --
10110          ---------------
10111
10112          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10113
10114          when Pragma_Link_With => Link_With : declare
10115             Arg : Node_Id;
10116
10117          begin
10118             GNAT_Pragma;
10119
10120             if Operating_Mode = Generate_Code
10121               and then In_Extended_Main_Source_Unit (N)
10122             then
10123                Check_At_Least_N_Arguments (1);
10124                Check_No_Identifiers;
10125                Check_Is_In_Decl_Part_Or_Package_Spec;
10126                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10127                Start_String;
10128
10129                Arg := Arg1;
10130                while Present (Arg) loop
10131                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10132
10133                   --  Store argument, converting sequences of spaces to a
10134                   --  single null character (this is one of the differences
10135                   --  in processing between Link_With and Linker_Options).
10136
10137                   Arg_Store : declare
10138                      C : constant Char_Code := Get_Char_Code (' ');
10139                      S : constant String_Id :=
10140                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10141                      L : constant Nat := String_Length (S);
10142                      F : Nat := 1;
10143
10144                      procedure Skip_Spaces;
10145                      --  Advance F past any spaces
10146
10147                      -----------------
10148                      -- Skip_Spaces --
10149                      -----------------
10150
10151                      procedure Skip_Spaces is
10152                      begin
10153                         while F <= L and then Get_String_Char (S, F) = C loop
10154                            F := F + 1;
10155                         end loop;
10156                      end Skip_Spaces;
10157
10158                   --  Start of processing for Arg_Store
10159
10160                   begin
10161                      Skip_Spaces; -- skip leading spaces
10162
10163                      --  Loop through characters, changing any embedded
10164                      --  sequence of spaces to a single null character (this
10165                      --  is how Link_With/Linker_Options differ)
10166
10167                      while F <= L loop
10168                         if Get_String_Char (S, F) = C then
10169                            Skip_Spaces;
10170                            exit when F > L;
10171                            Store_String_Char (ASCII.NUL);
10172
10173                         else
10174                            Store_String_Char (Get_String_Char (S, F));
10175                            F := F + 1;
10176                         end if;
10177                      end loop;
10178                   end Arg_Store;
10179
10180                   Arg := Next (Arg);
10181
10182                   if Present (Arg) then
10183                      Store_String_Char (ASCII.NUL);
10184                   end if;
10185                end loop;
10186
10187                Store_Linker_Option_String (End_String);
10188             end if;
10189          end Link_With;
10190
10191          ------------------
10192          -- Linker_Alias --
10193          ------------------
10194
10195          --  pragma Linker_Alias (
10196          --      [Entity =>]  LOCAL_NAME
10197          --      [Target =>]  static_string_EXPRESSION);
10198
10199          when Pragma_Linker_Alias =>
10200             GNAT_Pragma;
10201             Check_Arg_Order ((Name_Entity, Name_Target));
10202             Check_Arg_Count (2);
10203             Check_Optional_Identifier (Arg1, Name_Entity);
10204             Check_Optional_Identifier (Arg2, Name_Target);
10205             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10206             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10207
10208             --  The only processing required is to link this item on to the
10209             --  list of rep items for the given entity. This is accomplished
10210             --  by the call to Rep_Item_Too_Late (when no error is detected
10211             --  and False is returned).
10212
10213             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10214                return;
10215             else
10216                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10217             end if;
10218
10219          ------------------------
10220          -- Linker_Constructor --
10221          ------------------------
10222
10223          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10224
10225          --  Code is shared with Linker_Destructor
10226
10227          -----------------------
10228          -- Linker_Destructor --
10229          -----------------------
10230
10231          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10232
10233          when Pragma_Linker_Constructor |
10234               Pragma_Linker_Destructor =>
10235          Linker_Constructor : declare
10236             Arg1_X : Node_Id;
10237             Proc   : Entity_Id;
10238
10239          begin
10240             GNAT_Pragma;
10241             Check_Arg_Count (1);
10242             Check_No_Identifiers;
10243             Check_Arg_Is_Local_Name (Arg1);
10244             Arg1_X := Get_Pragma_Arg (Arg1);
10245             Analyze (Arg1_X);
10246             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10247
10248             if not Is_Library_Level_Entity (Proc) then
10249                Error_Pragma_Arg
10250                 ("argument for pragma% must be library level entity", Arg1);
10251             end if;
10252
10253             --  The only processing required is to link this item on to the
10254             --  list of rep items for the given entity. This is accomplished
10255             --  by the call to Rep_Item_Too_Late (when no error is detected
10256             --  and False is returned).
10257
10258             if Rep_Item_Too_Late (Proc, N) then
10259                return;
10260             else
10261                Set_Has_Gigi_Rep_Item (Proc);
10262             end if;
10263          end Linker_Constructor;
10264
10265          --------------------
10266          -- Linker_Options --
10267          --------------------
10268
10269          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10270
10271          when Pragma_Linker_Options => Linker_Options : declare
10272             Arg : Node_Id;
10273
10274          begin
10275             Check_Ada_83_Warning;
10276             Check_No_Identifiers;
10277             Check_Arg_Count (1);
10278             Check_Is_In_Decl_Part_Or_Package_Spec;
10279             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10280             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10281
10282             Arg := Arg2;
10283             while Present (Arg) loop
10284                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10285                Store_String_Char (ASCII.NUL);
10286                Store_String_Chars
10287                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10288                Arg := Next (Arg);
10289             end loop;
10290
10291             if Operating_Mode = Generate_Code
10292               and then In_Extended_Main_Source_Unit (N)
10293             then
10294                Store_Linker_Option_String (End_String);
10295             end if;
10296          end Linker_Options;
10297
10298          --------------------
10299          -- Linker_Section --
10300          --------------------
10301
10302          --  pragma Linker_Section (
10303          --      [Entity  =>]  LOCAL_NAME
10304          --      [Section =>]  static_string_EXPRESSION);
10305
10306          when Pragma_Linker_Section =>
10307             GNAT_Pragma;
10308             Check_Arg_Order ((Name_Entity, Name_Section));
10309             Check_Arg_Count (2);
10310             Check_Optional_Identifier (Arg1, Name_Entity);
10311             Check_Optional_Identifier (Arg2, Name_Section);
10312             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10313             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10314
10315             --  This pragma applies only to objects
10316
10317             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10318                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10319             end if;
10320
10321             --  The only processing required is to link this item on to the
10322             --  list of rep items for the given entity. This is accomplished
10323             --  by the call to Rep_Item_Too_Late (when no error is detected
10324             --  and False is returned).
10325
10326             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10327                return;
10328             else
10329                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10330             end if;
10331
10332          ----------
10333          -- List --
10334          ----------
10335
10336          --  pragma List (On | Off)
10337
10338          --  There is nothing to do here, since we did all the processing for
10339          --  this pragma in Par.Prag (so that it works properly even in syntax
10340          --  only mode).
10341
10342          when Pragma_List =>
10343             null;
10344
10345          --------------------
10346          -- Locking_Policy --
10347          --------------------
10348
10349          --  pragma Locking_Policy (policy_IDENTIFIER);
10350
10351          when Pragma_Locking_Policy => declare
10352             LP : Character;
10353
10354          begin
10355             Check_Ada_83_Warning;
10356             Check_Arg_Count (1);
10357             Check_No_Identifiers;
10358             Check_Arg_Is_Locking_Policy (Arg1);
10359             Check_Valid_Configuration_Pragma;
10360             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10361             LP := Fold_Upper (Name_Buffer (1));
10362
10363             if Locking_Policy /= ' '
10364               and then Locking_Policy /= LP
10365             then
10366                Error_Msg_Sloc := Locking_Policy_Sloc;
10367                Error_Pragma ("locking policy incompatible with policy#");
10368
10369             --  Set new policy, but always preserve System_Location since we
10370             --  like the error message with the run time name.
10371
10372             else
10373                Locking_Policy := LP;
10374
10375                if Locking_Policy_Sloc /= System_Location then
10376                   Locking_Policy_Sloc := Loc;
10377                end if;
10378             end if;
10379          end;
10380
10381          ----------------
10382          -- Long_Float --
10383          ----------------
10384
10385          --  pragma Long_Float (D_Float | G_Float);
10386
10387          when Pragma_Long_Float =>
10388             GNAT_Pragma;
10389             Check_Valid_Configuration_Pragma;
10390             Check_Arg_Count (1);
10391             Check_No_Identifier (Arg1);
10392             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10393
10394             if not OpenVMS_On_Target then
10395                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10396             end if;
10397
10398             --  D_Float case
10399
10400             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10401                if Opt.Float_Format_Long = 'G' then
10402                   Error_Pragma ("G_Float previously specified");
10403                end if;
10404
10405                Opt.Float_Format_Long := 'D';
10406
10407             --  G_Float case (this is the default, does not need overriding)
10408
10409             else
10410                if Opt.Float_Format_Long = 'D' then
10411                   Error_Pragma ("D_Float previously specified");
10412                end if;
10413
10414                Opt.Float_Format_Long := 'G';
10415             end if;
10416
10417             Set_Standard_Fpt_Formats;
10418
10419          -----------------------
10420          -- Machine_Attribute --
10421          -----------------------
10422
10423          --  pragma Machine_Attribute (
10424          --       [Entity         =>] LOCAL_NAME,
10425          --       [Attribute_Name =>] static_string_EXPRESSION
10426          --    [, [Info           =>] static_EXPRESSION] );
10427
10428          when Pragma_Machine_Attribute => Machine_Attribute : declare
10429             Def_Id : Entity_Id;
10430
10431          begin
10432             GNAT_Pragma;
10433             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10434
10435             if Arg_Count = 3 then
10436                Check_Optional_Identifier (Arg3, Name_Info);
10437                Check_Arg_Is_Static_Expression (Arg3);
10438             else
10439                Check_Arg_Count (2);
10440             end if;
10441
10442             Check_Optional_Identifier (Arg1, Name_Entity);
10443             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10444             Check_Arg_Is_Local_Name (Arg1);
10445             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10446             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10447
10448             if Is_Access_Type (Def_Id) then
10449                Def_Id := Designated_Type (Def_Id);
10450             end if;
10451
10452             if Rep_Item_Too_Early (Def_Id, N) then
10453                return;
10454             end if;
10455
10456             Def_Id := Underlying_Type (Def_Id);
10457
10458             --  The only processing required is to link this item on to the
10459             --  list of rep items for the given entity. This is accomplished
10460             --  by the call to Rep_Item_Too_Late (when no error is detected
10461             --  and False is returned).
10462
10463             if Rep_Item_Too_Late (Def_Id, N) then
10464                return;
10465             else
10466                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10467             end if;
10468          end Machine_Attribute;
10469
10470          ----------
10471          -- Main --
10472          ----------
10473
10474          --  pragma Main
10475          --   (MAIN_OPTION [, MAIN_OPTION]);
10476
10477          --  MAIN_OPTION ::=
10478          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10479          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10480          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10481
10482          when Pragma_Main => Main : declare
10483             Args  : Args_List (1 .. 3);
10484             Names : constant Name_List (1 .. 3) := (
10485                       Name_Stack_Size,
10486                       Name_Task_Stack_Size_Default,
10487                       Name_Time_Slicing_Enabled);
10488
10489             Nod : Node_Id;
10490
10491          begin
10492             GNAT_Pragma;
10493             Gather_Associations (Names, Args);
10494
10495             for J in 1 .. 2 loop
10496                if Present (Args (J)) then
10497                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10498                end if;
10499             end loop;
10500
10501             if Present (Args (3)) then
10502                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10503             end if;
10504
10505             Nod := Next (N);
10506             while Present (Nod) loop
10507                if Nkind (Nod) = N_Pragma
10508                  and then Pragma_Name (Nod) = Name_Main
10509                then
10510                   Error_Msg_Name_1 := Pname;
10511                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10512                end if;
10513
10514                Next (Nod);
10515             end loop;
10516          end Main;
10517
10518          ------------------
10519          -- Main_Storage --
10520          ------------------
10521
10522          --  pragma Main_Storage
10523          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10524
10525          --  MAIN_STORAGE_OPTION ::=
10526          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10527          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10528
10529          when Pragma_Main_Storage => Main_Storage : declare
10530             Args  : Args_List (1 .. 2);
10531             Names : constant Name_List (1 .. 2) := (
10532                       Name_Working_Storage,
10533                       Name_Top_Guard);
10534
10535             Nod : Node_Id;
10536
10537          begin
10538             GNAT_Pragma;
10539             Gather_Associations (Names, Args);
10540
10541             for J in 1 .. 2 loop
10542                if Present (Args (J)) then
10543                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10544                end if;
10545             end loop;
10546
10547             Check_In_Main_Program;
10548
10549             Nod := Next (N);
10550             while Present (Nod) loop
10551                if Nkind (Nod) = N_Pragma
10552                  and then Pragma_Name (Nod) = Name_Main_Storage
10553                then
10554                   Error_Msg_Name_1 := Pname;
10555                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10556                end if;
10557
10558                Next (Nod);
10559             end loop;
10560          end Main_Storage;
10561
10562          -----------------
10563          -- Memory_Size --
10564          -----------------
10565
10566          --  pragma Memory_Size (NUMERIC_LITERAL)
10567
10568          when Pragma_Memory_Size =>
10569             GNAT_Pragma;
10570
10571             --  Memory size is simply ignored
10572
10573             Check_No_Identifiers;
10574             Check_Arg_Count (1);
10575             Check_Arg_Is_Integer_Literal (Arg1);
10576
10577          -------------
10578          -- No_Body --
10579          -------------
10580
10581          --  pragma No_Body;
10582
10583          --  The only correct use of this pragma is on its own in a file, in
10584          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10585          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10586          --  check for a file containing nothing but a No_Body pragma). If we
10587          --  attempt to process it during normal semantics processing, it means
10588          --  it was misplaced.
10589
10590          when Pragma_No_Body =>
10591             GNAT_Pragma;
10592             Pragma_Misplaced;
10593
10594          ---------------
10595          -- No_Return --
10596          ---------------
10597
10598          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10599
10600          when Pragma_No_Return => No_Return : declare
10601             Id    : Node_Id;
10602             E     : Entity_Id;
10603             Found : Boolean;
10604             Arg   : Node_Id;
10605
10606          begin
10607             Ada_2005_Pragma;
10608             Check_At_Least_N_Arguments (1);
10609
10610             --  Loop through arguments of pragma
10611
10612             Arg := Arg1;
10613             while Present (Arg) loop
10614                Check_Arg_Is_Local_Name (Arg);
10615                Id := Get_Pragma_Arg (Arg);
10616                Analyze (Id);
10617
10618                if not Is_Entity_Name (Id) then
10619                   Error_Pragma_Arg ("entity name required", Arg);
10620                end if;
10621
10622                if Etype (Id) = Any_Type then
10623                   raise Pragma_Exit;
10624                end if;
10625
10626                --  Loop to find matching procedures
10627
10628                E := Entity (Id);
10629                Found := False;
10630                while Present (E)
10631                  and then Scope (E) = Current_Scope
10632                loop
10633                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10634                      Set_No_Return (E);
10635
10636                      --  Set flag on any alias as well
10637
10638                      if Is_Overloadable (E) and then Present (Alias (E)) then
10639                         Set_No_Return (Alias (E));
10640                      end if;
10641
10642                      Found := True;
10643                   end if;
10644
10645                   exit when From_Aspect_Specification (N);
10646                   E := Homonym (E);
10647                end loop;
10648
10649                if not Found then
10650                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10651                end if;
10652
10653                Next (Arg);
10654             end loop;
10655          end No_Return;
10656
10657          -----------------
10658          -- No_Run_Time --
10659          -----------------
10660
10661          --  pragma No_Run_Time;
10662
10663          --  Note: this pragma is retained for backwards compatibility. See
10664          --  body of Rtsfind for full details on its handling.
10665
10666          when Pragma_No_Run_Time =>
10667             GNAT_Pragma;
10668             Check_Valid_Configuration_Pragma;
10669             Check_Arg_Count (0);
10670
10671             No_Run_Time_Mode           := True;
10672             Configurable_Run_Time_Mode := True;
10673
10674             --  Set Duration to 32 bits if word size is 32
10675
10676             if Ttypes.System_Word_Size = 32 then
10677                Duration_32_Bits_On_Target := True;
10678             end if;
10679
10680             --  Set appropriate restrictions
10681
10682             Set_Restriction (No_Finalization, N);
10683             Set_Restriction (No_Exception_Handlers, N);
10684             Set_Restriction (Max_Tasks, N, 0);
10685             Set_Restriction (No_Tasking, N);
10686
10687          ------------------------
10688          -- No_Strict_Aliasing --
10689          ------------------------
10690
10691          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10692
10693          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10694             E_Id : Entity_Id;
10695
10696          begin
10697             GNAT_Pragma;
10698             Check_At_Most_N_Arguments (1);
10699
10700             if Arg_Count = 0 then
10701                Check_Valid_Configuration_Pragma;
10702                Opt.No_Strict_Aliasing := True;
10703
10704             else
10705                Check_Optional_Identifier (Arg2, Name_Entity);
10706                Check_Arg_Is_Local_Name (Arg1);
10707                E_Id := Entity (Get_Pragma_Arg (Arg1));
10708
10709                if E_Id = Any_Type then
10710                   return;
10711                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10712                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
10713                end if;
10714
10715                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10716             end if;
10717          end No_Strict_Aliasing;
10718
10719          -----------------------
10720          -- Normalize_Scalars --
10721          -----------------------
10722
10723          --  pragma Normalize_Scalars;
10724
10725          when Pragma_Normalize_Scalars =>
10726             Check_Ada_83_Warning;
10727             Check_Arg_Count (0);
10728             Check_Valid_Configuration_Pragma;
10729
10730             --  Normalize_Scalars creates false positives in CodePeer, so
10731             --  ignore this pragma in this mode.
10732
10733             if not CodePeer_Mode then
10734                Normalize_Scalars := True;
10735                Init_Or_Norm_Scalars := True;
10736             end if;
10737
10738          -----------------
10739          -- Obsolescent --
10740          -----------------
10741
10742          --  pragma Obsolescent;
10743
10744          --  pragma Obsolescent (
10745          --    [Message =>] static_string_EXPRESSION
10746          --  [,[Version =>] Ada_05]]);
10747
10748          --  pragma Obsolescent (
10749          --    [Entity  =>] NAME
10750          --  [,[Message =>] static_string_EXPRESSION
10751          --  [,[Version =>] Ada_05]] );
10752
10753          when Pragma_Obsolescent => Obsolescent : declare
10754             Ename : Node_Id;
10755             Decl  : Node_Id;
10756
10757             procedure Set_Obsolescent (E : Entity_Id);
10758             --  Given an entity Ent, mark it as obsolescent if appropriate
10759
10760             ---------------------
10761             -- Set_Obsolescent --
10762             ---------------------
10763
10764             procedure Set_Obsolescent (E : Entity_Id) is
10765                Active : Boolean;
10766                Ent    : Entity_Id;
10767                S      : String_Id;
10768
10769             begin
10770                Active := True;
10771                Ent    := E;
10772
10773                --  Entity name was given
10774
10775                if Present (Ename) then
10776
10777                   --  If entity name matches, we are fine. Save entity in
10778                   --  pragma argument, for ASIS use.
10779
10780                   if Chars (Ename) = Chars (Ent) then
10781                      Set_Entity (Ename, Ent);
10782                      Generate_Reference (Ent, Ename);
10783
10784                   --  If entity name does not match, only possibility is an
10785                   --  enumeration literal from an enumeration type declaration.
10786
10787                   elsif Ekind (Ent) /= E_Enumeration_Type then
10788                      Error_Pragma
10789                        ("pragma % entity name does not match declaration");
10790
10791                   else
10792                      Ent := First_Literal (E);
10793                      loop
10794                         if No (Ent) then
10795                            Error_Pragma
10796                              ("pragma % entity name does not match any " &
10797                               "enumeration literal");
10798
10799                         elsif Chars (Ent) = Chars (Ename) then
10800                            Set_Entity (Ename, Ent);
10801                            Generate_Reference (Ent, Ename);
10802                            exit;
10803
10804                         else
10805                            Ent := Next_Literal (Ent);
10806                         end if;
10807                      end loop;
10808                   end if;
10809                end if;
10810
10811                --  Ent points to entity to be marked
10812
10813                if Arg_Count >= 1 then
10814
10815                   --  Deal with static string argument
10816
10817                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10818                   S := Strval (Get_Pragma_Arg (Arg1));
10819
10820                   for J in 1 .. String_Length (S) loop
10821                      if not In_Character_Range (Get_String_Char (S, J)) then
10822                         Error_Pragma_Arg
10823                           ("pragma% argument does not allow wide characters",
10824                            Arg1);
10825                      end if;
10826                   end loop;
10827
10828                   Obsolescent_Warnings.Append
10829                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10830
10831                   --  Check for Ada_05 parameter
10832
10833                   if Arg_Count /= 1 then
10834                      Check_Arg_Count (2);
10835
10836                      declare
10837                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
10838
10839                      begin
10840                         Check_Arg_Is_Identifier (Argx);
10841
10842                         if Chars (Argx) /= Name_Ada_05 then
10843                            Error_Msg_Name_2 := Name_Ada_05;
10844                            Error_Pragma_Arg
10845                              ("only allowed argument for pragma% is %", Argx);
10846                         end if;
10847
10848                         if Ada_Version_Explicit < Ada_2005
10849                           or else not Warn_On_Ada_2005_Compatibility
10850                         then
10851                            Active := False;
10852                         end if;
10853                      end;
10854                   end if;
10855                end if;
10856
10857                --  Set flag if pragma active
10858
10859                if Active then
10860                   Set_Is_Obsolescent (Ent);
10861                end if;
10862
10863                return;
10864             end Set_Obsolescent;
10865
10866          --  Start of processing for pragma Obsolescent
10867
10868          begin
10869             GNAT_Pragma;
10870
10871             Check_At_Most_N_Arguments (3);
10872
10873             --  See if first argument specifies an entity name
10874
10875             if Arg_Count >= 1
10876               and then
10877                 (Chars (Arg1) = Name_Entity
10878                    or else
10879                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
10880                                                       N_Identifier,
10881                                                       N_Operator_Symbol))
10882             then
10883                Ename := Get_Pragma_Arg (Arg1);
10884
10885                --  Eliminate first argument, so we can share processing
10886
10887                Arg1 := Arg2;
10888                Arg2 := Arg3;
10889                Arg_Count := Arg_Count - 1;
10890
10891             --  No Entity name argument given
10892
10893             else
10894                Ename := Empty;
10895             end if;
10896
10897             if Arg_Count >= 1 then
10898                Check_Optional_Identifier (Arg1, Name_Message);
10899
10900                if Arg_Count = 2 then
10901                   Check_Optional_Identifier (Arg2, Name_Version);
10902                end if;
10903             end if;
10904
10905             --  Get immediately preceding declaration
10906
10907             Decl := Prev (N);
10908             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
10909                Prev (Decl);
10910             end loop;
10911
10912             --  Cases where we do not follow anything other than another pragma
10913
10914             if No (Decl) then
10915
10916                --  First case: library level compilation unit declaration with
10917                --  the pragma immediately following the declaration.
10918
10919                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
10920                   Set_Obsolescent
10921                     (Defining_Entity (Unit (Parent (Parent (N)))));
10922                   return;
10923
10924                --  Case 2: library unit placement for package
10925
10926                else
10927                   declare
10928                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
10929                   begin
10930                      if Is_Package_Or_Generic_Package (Ent) then
10931                         Set_Obsolescent (Ent);
10932                         return;
10933                      end if;
10934                   end;
10935                end if;
10936
10937             --  Cases where we must follow a declaration
10938
10939             else
10940                if         Nkind (Decl) not in N_Declaration
10941                  and then Nkind (Decl) not in N_Later_Decl_Item
10942                  and then Nkind (Decl) not in N_Generic_Declaration
10943                  and then Nkind (Decl) not in N_Renaming_Declaration
10944                then
10945                   Error_Pragma
10946                     ("pragma% misplaced, "
10947                      & "must immediately follow a declaration");
10948
10949                else
10950                   Set_Obsolescent (Defining_Entity (Decl));
10951                   return;
10952                end if;
10953             end if;
10954          end Obsolescent;
10955
10956          --------------
10957          -- Optimize --
10958          --------------
10959
10960          --  pragma Optimize (Time | Space | Off);
10961
10962          --  The actual check for optimize is done in Gigi. Note that this
10963          --  pragma does not actually change the optimization setting, it
10964          --  simply checks that it is consistent with the pragma.
10965
10966          when Pragma_Optimize =>
10967             Check_No_Identifiers;
10968             Check_Arg_Count (1);
10969             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
10970
10971          ------------------------
10972          -- Optimize_Alignment --
10973          ------------------------
10974
10975          --  pragma Optimize_Alignment (Time | Space | Off);
10976
10977          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
10978             GNAT_Pragma;
10979             Check_No_Identifiers;
10980             Check_Arg_Count (1);
10981             Check_Valid_Configuration_Pragma;
10982
10983             declare
10984                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
10985             begin
10986                case Nam is
10987                   when Name_Time =>
10988                      Opt.Optimize_Alignment := 'T';
10989                   when Name_Space =>
10990                      Opt.Optimize_Alignment := 'S';
10991                   when Name_Off =>
10992                      Opt.Optimize_Alignment := 'O';
10993                   when others =>
10994                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
10995                end case;
10996             end;
10997
10998             --  Set indication that mode is set locally. If we are in fact in a
10999             --  configuration pragma file, this setting is harmless since the
11000             --  switch will get reset anyway at the start of each unit.
11001
11002             Optimize_Alignment_Local := True;
11003          end Optimize_Alignment;
11004
11005          -------------
11006          -- Ordered --
11007          -------------
11008
11009          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11010
11011          when Pragma_Ordered => Ordered : declare
11012             Assoc   : constant Node_Id := Arg1;
11013             Type_Id : Node_Id;
11014             Typ     : Entity_Id;
11015
11016          begin
11017             GNAT_Pragma;
11018             Check_No_Identifiers;
11019             Check_Arg_Count (1);
11020             Check_Arg_Is_Local_Name (Arg1);
11021
11022             Type_Id := Get_Pragma_Arg (Assoc);
11023             Find_Type (Type_Id);
11024             Typ := Entity (Type_Id);
11025
11026             if Typ = Any_Type then
11027                return;
11028             else
11029                Typ := Underlying_Type (Typ);
11030             end if;
11031
11032             if not Is_Enumeration_Type (Typ) then
11033                Error_Pragma ("pragma% must specify enumeration type");
11034             end if;
11035
11036             Check_First_Subtype (Arg1);
11037             Set_Has_Pragma_Ordered (Base_Type (Typ));
11038          end Ordered;
11039
11040          ----------
11041          -- Pack --
11042          ----------
11043
11044          --  pragma Pack (first_subtype_LOCAL_NAME);
11045
11046          when Pragma_Pack => Pack : declare
11047             Assoc   : constant Node_Id := Arg1;
11048             Type_Id : Node_Id;
11049             Typ     : Entity_Id;
11050             Ctyp    : Entity_Id;
11051             Ignore  : Boolean := False;
11052
11053          begin
11054             Check_No_Identifiers;
11055             Check_Arg_Count (1);
11056             Check_Arg_Is_Local_Name (Arg1);
11057
11058             Type_Id := Get_Pragma_Arg (Assoc);
11059             Find_Type (Type_Id);
11060             Typ := Entity (Type_Id);
11061
11062             if Typ = Any_Type
11063               or else Rep_Item_Too_Early (Typ, N)
11064             then
11065                return;
11066             else
11067                Typ := Underlying_Type (Typ);
11068             end if;
11069
11070             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11071                Error_Pragma ("pragma% must specify array or record type");
11072             end if;
11073
11074             Check_First_Subtype (Arg1);
11075             Check_Duplicate_Pragma (Typ);
11076
11077             --  Array type
11078
11079             if Is_Array_Type (Typ) then
11080                Ctyp := Component_Type (Typ);
11081
11082                --  Ignore pack that does nothing
11083
11084                if Known_Static_Esize (Ctyp)
11085                  and then Known_Static_RM_Size (Ctyp)
11086                  and then Esize (Ctyp) = RM_Size (Ctyp)
11087                  and then Addressable (Esize (Ctyp))
11088                then
11089                   Ignore := True;
11090                end if;
11091
11092                --  Process OK pragma Pack. Note that if there is a separate
11093                --  component clause present, the Pack will be cancelled. This
11094                --  processing is in Freeze.
11095
11096                if not Rep_Item_Too_Late (Typ, N) then
11097
11098                   --  In the context of static code analysis, we do not need
11099                   --  complex front-end expansions related to pragma Pack,
11100                   --  so disable handling of pragma Pack in this case.
11101
11102                   if CodePeer_Mode then
11103                      null;
11104
11105                   --  Don't attempt any packing for VM targets. We possibly
11106                   --  could deal with some cases of array bit-packing, but we
11107                   --  don't bother, since this is not a typical kind of
11108                   --  representation in the VM context anyway (and would not
11109                   --  for example work nicely with the debugger).
11110
11111                   elsif VM_Target /= No_VM then
11112                      if not GNAT_Mode then
11113                         Error_Pragma
11114                           ("?pragma% ignored in this configuration");
11115                      end if;
11116
11117                   --  Normal case where we do the pack action
11118
11119                   else
11120                      if not Ignore then
11121                         Set_Is_Packed            (Base_Type (Typ));
11122                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11123                      end if;
11124
11125                      Set_Has_Pragma_Pack (Base_Type (Typ));
11126                   end if;
11127                end if;
11128
11129             --  For record types, the pack is always effective
11130
11131             else pragma Assert (Is_Record_Type (Typ));
11132                if not Rep_Item_Too_Late (Typ, N) then
11133
11134                   --  Ignore pack request with warning in VM mode (skip warning
11135                   --  if we are compiling GNAT run time library).
11136
11137                   if VM_Target /= No_VM then
11138                      if not GNAT_Mode then
11139                         Error_Pragma
11140                           ("?pragma% ignored in this configuration");
11141                      end if;
11142
11143                   --  Normal case of pack request active
11144
11145                   else
11146                      Set_Is_Packed            (Base_Type (Typ));
11147                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11148                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11149                   end if;
11150                end if;
11151             end if;
11152          end Pack;
11153
11154          ----------
11155          -- Page --
11156          ----------
11157
11158          --  pragma Page;
11159
11160          --  There is nothing to do here, since we did all the processing for
11161          --  this pragma in Par.Prag (so that it works properly even in syntax
11162          --  only mode).
11163
11164          when Pragma_Page =>
11165             null;
11166
11167          -------------
11168          -- Passive --
11169          -------------
11170
11171          --  pragma Passive [(PASSIVE_FORM)];
11172
11173          --  PASSIVE_FORM ::= Semaphore | No
11174
11175          when Pragma_Passive =>
11176             GNAT_Pragma;
11177
11178             if Nkind (Parent (N)) /= N_Task_Definition then
11179                Error_Pragma ("pragma% must be within task definition");
11180             end if;
11181
11182             if Arg_Count /= 0 then
11183                Check_Arg_Count (1);
11184                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11185             end if;
11186
11187          ----------------------------------
11188          -- Preelaborable_Initialization --
11189          ----------------------------------
11190
11191          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11192
11193          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11194             Ent : Entity_Id;
11195
11196          begin
11197             Ada_2005_Pragma;
11198             Check_Arg_Count (1);
11199             Check_No_Identifiers;
11200             Check_Arg_Is_Identifier (Arg1);
11201             Check_Arg_Is_Local_Name (Arg1);
11202             Check_First_Subtype (Arg1);
11203             Ent := Entity (Get_Pragma_Arg (Arg1));
11204
11205             if not (Is_Private_Type (Ent)
11206                       or else
11207                     Is_Protected_Type (Ent)
11208                       or else
11209                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11210             then
11211                Error_Pragma_Arg
11212                  ("pragma % can only be applied to private, formal derived or "
11213                   & "protected type",
11214                   Arg1);
11215             end if;
11216
11217             --  Give an error if the pragma is applied to a protected type that
11218             --  does not qualify (due to having entries, or due to components
11219             --  that do not qualify).
11220
11221             if Is_Protected_Type (Ent)
11222               and then not Has_Preelaborable_Initialization (Ent)
11223             then
11224                Error_Msg_N
11225                  ("protected type & does not have preelaborable " &
11226                   "initialization", Ent);
11227
11228             --  Otherwise mark the type as definitely having preelaborable
11229             --  initialization.
11230
11231             else
11232                Set_Known_To_Have_Preelab_Init (Ent);
11233             end if;
11234
11235             if Has_Pragma_Preelab_Init (Ent)
11236               and then Warn_On_Redundant_Constructs
11237             then
11238                Error_Pragma ("?duplicate pragma%!");
11239             else
11240                Set_Has_Pragma_Preelab_Init (Ent);
11241             end if;
11242          end Preelab_Init;
11243
11244          --------------------
11245          -- Persistent_BSS --
11246          --------------------
11247
11248          --  pragma Persistent_BSS [(object_NAME)];
11249
11250          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11251             Decl : Node_Id;
11252             Ent  : Entity_Id;
11253             Prag : Node_Id;
11254
11255          begin
11256             GNAT_Pragma;
11257             Check_At_Most_N_Arguments (1);
11258
11259             --  Case of application to specific object (one argument)
11260
11261             if Arg_Count = 1 then
11262                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11263
11264                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11265                  or else not
11266                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11267                                                             E_Constant)
11268                then
11269                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11270                end if;
11271
11272                Ent := Entity (Get_Pragma_Arg (Arg1));
11273                Decl := Parent (Ent);
11274
11275                if Rep_Item_Too_Late (Ent, N) then
11276                   return;
11277                end if;
11278
11279                if Present (Expression (Decl)) then
11280                   Error_Pragma_Arg
11281                     ("object for pragma% cannot have initialization", Arg1);
11282                end if;
11283
11284                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11285                   Error_Pragma_Arg
11286                     ("object type for pragma% is not potentially persistent",
11287                      Arg1);
11288                end if;
11289
11290                Check_Duplicate_Pragma (Ent);
11291
11292                Prag :=
11293                  Make_Linker_Section_Pragma
11294                    (Ent, Sloc (N), ".persistent.bss");
11295                Insert_After (N, Prag);
11296                Analyze (Prag);
11297
11298             --  Case of use as configuration pragma with no arguments
11299
11300             else
11301                Check_Valid_Configuration_Pragma;
11302                Persistent_BSS_Mode := True;
11303             end if;
11304          end Persistent_BSS;
11305
11306          -------------
11307          -- Polling --
11308          -------------
11309
11310          --  pragma Polling (ON | OFF);
11311
11312          when Pragma_Polling =>
11313             GNAT_Pragma;
11314             Check_Arg_Count (1);
11315             Check_No_Identifiers;
11316             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11317             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11318
11319          -------------------
11320          -- Postcondition --
11321          -------------------
11322
11323          --  pragma Postcondition ([Check   =>] Boolean_Expression
11324          --                      [,[Message =>] String_Expression]);
11325
11326          when Pragma_Postcondition => Postcondition : declare
11327             In_Body : Boolean;
11328             pragma Warnings (Off, In_Body);
11329
11330          begin
11331             GNAT_Pragma;
11332             Check_At_Least_N_Arguments (1);
11333             Check_At_Most_N_Arguments (2);
11334             Check_Optional_Identifier (Arg1, Name_Check);
11335
11336             --  All we need to do here is call the common check procedure,
11337             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11338
11339             Check_Precondition_Postcondition (In_Body);
11340          end Postcondition;
11341
11342          ------------------
11343          -- Precondition --
11344          ------------------
11345
11346          --  pragma Precondition ([Check   =>] Boolean_Expression
11347          --                     [,[Message =>] String_Expression]);
11348
11349          when Pragma_Precondition => Precondition : declare
11350             In_Body : Boolean;
11351
11352          begin
11353             GNAT_Pragma;
11354             Check_At_Least_N_Arguments (1);
11355             Check_At_Most_N_Arguments (2);
11356             Check_Optional_Identifier (Arg1, Name_Check);
11357             Check_Precondition_Postcondition (In_Body);
11358
11359             --  If in spec, nothing more to do. If in body, then we convert the
11360             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11361             --  this whether or not precondition checks are enabled. That works
11362             --  fine since pragma Check will do this check, and will also
11363             --  analyze the condition itself in the proper context.
11364
11365             if In_Body then
11366                Rewrite (N,
11367                  Make_Pragma (Loc,
11368                    Chars => Name_Check,
11369                    Pragma_Argument_Associations => New_List (
11370                      Make_Pragma_Argument_Association (Loc,
11371                        Expression => Make_Identifier (Loc, Name_Precondition)),
11372
11373                      Make_Pragma_Argument_Association (Sloc (Arg1),
11374                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11375
11376                if Arg_Count = 2 then
11377                   Append_To (Pragma_Argument_Associations (N),
11378                     Make_Pragma_Argument_Association (Sloc (Arg2),
11379                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11380                end if;
11381
11382                Analyze (N);
11383             end if;
11384          end Precondition;
11385
11386          ---------------
11387          -- Predicate --
11388          ---------------
11389
11390          --  pragma Predicate
11391          --    ([Entity =>] type_LOCAL_NAME,
11392          --     [Check  =>] EXPRESSION);
11393
11394          when Pragma_Predicate => Predicate : declare
11395             Type_Id : Node_Id;
11396             Typ     : Entity_Id;
11397
11398             Discard : Boolean;
11399             pragma Unreferenced (Discard);
11400
11401          begin
11402             GNAT_Pragma;
11403             Check_Arg_Count (2);
11404             Check_Optional_Identifier (Arg1, Name_Entity);
11405             Check_Optional_Identifier (Arg2, Name_Check);
11406
11407             Check_Arg_Is_Local_Name (Arg1);
11408
11409             Type_Id := Get_Pragma_Arg (Arg1);
11410             Find_Type (Type_Id);
11411             Typ := Entity (Type_Id);
11412
11413             if Typ = Any_Type then
11414                return;
11415             end if;
11416
11417             --  The remaining processing is simply to link the pragma on to
11418             --  the rep item chain, for processing when the type is frozen.
11419             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11420             --  mark the type as having predicates.
11421
11422             Set_Has_Predicates (Typ);
11423             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11424          end Predicate;
11425
11426          ------------------
11427          -- Preelaborate --
11428          ------------------
11429
11430          --  pragma Preelaborate [(library_unit_NAME)];
11431
11432          --  Set the flag Is_Preelaborated of program unit name entity
11433
11434          when Pragma_Preelaborate => Preelaborate : declare
11435             Pa  : constant Node_Id   := Parent (N);
11436             Pk  : constant Node_Kind := Nkind (Pa);
11437             Ent : Entity_Id;
11438
11439          begin
11440             Check_Ada_83_Warning;
11441             Check_Valid_Library_Unit_Pragma;
11442
11443             if Nkind (N) = N_Null_Statement then
11444                return;
11445             end if;
11446
11447             Ent := Find_Lib_Unit_Name;
11448             Check_Duplicate_Pragma (Ent);
11449
11450             --  This filters out pragmas inside generic parent then
11451             --  show up inside instantiation
11452
11453             if Present (Ent)
11454               and then not (Pk = N_Package_Specification
11455                              and then Present (Generic_Parent (Pa)))
11456             then
11457                if not Debug_Flag_U then
11458                   Set_Is_Preelaborated (Ent);
11459                   Set_Suppress_Elaboration_Warnings (Ent);
11460                end if;
11461             end if;
11462          end Preelaborate;
11463
11464          ---------------------
11465          -- Preelaborate_05 --
11466          ---------------------
11467
11468          --  pragma Preelaborate_05 [(library_unit_NAME)];
11469
11470          --  This pragma is useable only in GNAT_Mode, where it is used like
11471          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11472          --  (otherwise it is ignored). This is used to implement AI-362 which
11473          --  recategorizes some run-time packages in Ada 2005 mode.
11474
11475          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11476             Ent : Entity_Id;
11477
11478          begin
11479             GNAT_Pragma;
11480             Check_Valid_Library_Unit_Pragma;
11481
11482             if not GNAT_Mode then
11483                Error_Pragma ("pragma% only available in GNAT mode");
11484             end if;
11485
11486             if Nkind (N) = N_Null_Statement then
11487                return;
11488             end if;
11489
11490             --  This is one of the few cases where we need to test the value of
11491             --  Ada_Version_Explicit rather than Ada_Version (which is always
11492             --  set to Ada_2012 in a predefined unit), we need to know the
11493             --  explicit version set to know if this pragma is active.
11494
11495             if Ada_Version_Explicit >= Ada_2005 then
11496                Ent := Find_Lib_Unit_Name;
11497                Set_Is_Preelaborated (Ent);
11498                Set_Suppress_Elaboration_Warnings (Ent);
11499             end if;
11500          end Preelaborate_05;
11501
11502          --------------
11503          -- Priority --
11504          --------------
11505
11506          --  pragma Priority (EXPRESSION);
11507
11508          when Pragma_Priority => Priority : declare
11509             P   : constant Node_Id := Parent (N);
11510             Arg : Node_Id;
11511
11512          begin
11513             Check_No_Identifiers;
11514             Check_Arg_Count (1);
11515
11516             --  Subprogram case
11517
11518             if Nkind (P) = N_Subprogram_Body then
11519                Check_In_Main_Program;
11520
11521                Arg := Get_Pragma_Arg (Arg1);
11522                Analyze_And_Resolve (Arg, Standard_Integer);
11523
11524                --  Must be static
11525
11526                if not Is_Static_Expression (Arg) then
11527                   Flag_Non_Static_Expr
11528                     ("main subprogram priority is not static!", Arg);
11529                   raise Pragma_Exit;
11530
11531                --  If constraint error, then we already signalled an error
11532
11533                elsif Raises_Constraint_Error (Arg) then
11534                   null;
11535
11536                --  Otherwise check in range
11537
11538                else
11539                   declare
11540                      Val : constant Uint := Expr_Value (Arg);
11541
11542                   begin
11543                      if Val < 0
11544                        or else Val > Expr_Value (Expression
11545                                        (Parent (RTE (RE_Max_Priority))))
11546                      then
11547                         Error_Pragma_Arg
11548                           ("main subprogram priority is out of range", Arg1);
11549                      end if;
11550                   end;
11551                end if;
11552
11553                Set_Main_Priority
11554                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11555
11556                --  Load an arbitrary entity from System.Tasking to make sure
11557                --  this package is implicitly with'ed, since we need to have
11558                --  the tasking run-time active for the pragma Priority to have
11559                --  any effect.
11560
11561                declare
11562                   Discard : Entity_Id;
11563                   pragma Warnings (Off, Discard);
11564                begin
11565                   Discard := RTE (RE_Task_List);
11566                end;
11567
11568             --  Task or Protected, must be of type Integer
11569
11570             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11571                Arg := Get_Pragma_Arg (Arg1);
11572
11573                --  The expression must be analyzed in the special manner
11574                --  described in "Handling of Default and Per-Object
11575                --  Expressions" in sem.ads.
11576
11577                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11578
11579                if not Is_Static_Expression (Arg) then
11580                   Check_Restriction (Static_Priorities, Arg);
11581                end if;
11582
11583             --  Anything else is incorrect
11584
11585             else
11586                Pragma_Misplaced;
11587             end if;
11588
11589             if Has_Pragma_Priority (P) then
11590                Error_Pragma ("duplicate pragma% not allowed");
11591             else
11592                Set_Has_Pragma_Priority (P, True);
11593
11594                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11595                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11596                   --  exp_ch9 should use this ???
11597                end if;
11598             end if;
11599          end Priority;
11600
11601          -----------------------------------
11602          -- Priority_Specific_Dispatching --
11603          -----------------------------------
11604
11605          --  pragma Priority_Specific_Dispatching (
11606          --    policy_IDENTIFIER,
11607          --    first_priority_EXPRESSION,
11608          --    last_priority_EXPRESSION);
11609
11610          when Pragma_Priority_Specific_Dispatching =>
11611          Priority_Specific_Dispatching : declare
11612             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11613             --  This is the entity System.Any_Priority;
11614
11615             DP          : Character;
11616             Lower_Bound : Node_Id;
11617             Upper_Bound : Node_Id;
11618             Lower_Val   : Uint;
11619             Upper_Val   : Uint;
11620
11621          begin
11622             Ada_2005_Pragma;
11623             Check_Arg_Count (3);
11624             Check_No_Identifiers;
11625             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11626             Check_Valid_Configuration_Pragma;
11627             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11628             DP := Fold_Upper (Name_Buffer (1));
11629
11630             Lower_Bound := Get_Pragma_Arg (Arg2);
11631             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11632             Lower_Val := Expr_Value (Lower_Bound);
11633
11634             Upper_Bound := Get_Pragma_Arg (Arg3);
11635             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11636             Upper_Val := Expr_Value (Upper_Bound);
11637
11638             --  It is not allowed to use Task_Dispatching_Policy and
11639             --  Priority_Specific_Dispatching in the same partition.
11640
11641             if Task_Dispatching_Policy /= ' ' then
11642                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11643                Error_Pragma
11644                  ("pragma% incompatible with Task_Dispatching_Policy#");
11645
11646             --  Check lower bound in range
11647
11648             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11649                     or else
11650                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11651             then
11652                Error_Pragma_Arg
11653                  ("first_priority is out of range", Arg2);
11654
11655             --  Check upper bound in range
11656
11657             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11658                     or else
11659                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11660             then
11661                Error_Pragma_Arg
11662                  ("last_priority is out of range", Arg3);
11663
11664             --  Check that the priority range is valid
11665
11666             elsif Lower_Val > Upper_Val then
11667                Error_Pragma
11668                  ("last_priority_expression must be greater than" &
11669                   " or equal to first_priority_expression");
11670
11671             --  Store the new policy, but always preserve System_Location since
11672             --  we like the error message with the run-time name.
11673
11674             else
11675                --  Check overlapping in the priority ranges specified in other
11676                --  Priority_Specific_Dispatching pragmas within the same
11677                --  partition. We can only check those we know about!
11678
11679                for J in
11680                   Specific_Dispatching.First .. Specific_Dispatching.Last
11681                loop
11682                   if Specific_Dispatching.Table (J).First_Priority in
11683                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11684                   or else Specific_Dispatching.Table (J).Last_Priority in
11685                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11686                   then
11687                      Error_Msg_Sloc :=
11688                        Specific_Dispatching.Table (J).Pragma_Loc;
11689                         Error_Pragma
11690                           ("priority range overlaps with "
11691                            & "Priority_Specific_Dispatching#");
11692                   end if;
11693                end loop;
11694
11695                --  The use of Priority_Specific_Dispatching is incompatible
11696                --  with Task_Dispatching_Policy.
11697
11698                if Task_Dispatching_Policy /= ' ' then
11699                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11700                      Error_Pragma
11701                        ("Priority_Specific_Dispatching incompatible "
11702                         & "with Task_Dispatching_Policy#");
11703                end if;
11704
11705                --  The use of Priority_Specific_Dispatching forces ceiling
11706                --  locking policy.
11707
11708                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11709                   Error_Msg_Sloc := Locking_Policy_Sloc;
11710                      Error_Pragma
11711                        ("Priority_Specific_Dispatching incompatible "
11712                         & "with Locking_Policy#");
11713
11714                --  Set the Ceiling_Locking policy, but preserve System_Location
11715                --  since we like the error message with the run time name.
11716
11717                else
11718                   Locking_Policy := 'C';
11719
11720                   if Locking_Policy_Sloc /= System_Location then
11721                      Locking_Policy_Sloc := Loc;
11722                   end if;
11723                end if;
11724
11725                --  Add entry in the table
11726
11727                Specific_Dispatching.Append
11728                     ((Dispatching_Policy => DP,
11729                       First_Priority     => UI_To_Int (Lower_Val),
11730                       Last_Priority      => UI_To_Int (Upper_Val),
11731                       Pragma_Loc         => Loc));
11732             end if;
11733          end Priority_Specific_Dispatching;
11734
11735          -------------
11736          -- Profile --
11737          -------------
11738
11739          --  pragma Profile (profile_IDENTIFIER);
11740
11741          --  profile_IDENTIFIER => Restricted | Ravenscar
11742
11743          when Pragma_Profile =>
11744             Ada_2005_Pragma;
11745             Check_Arg_Count (1);
11746             Check_Valid_Configuration_Pragma;
11747             Check_No_Identifiers;
11748
11749             declare
11750                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11751             begin
11752                if Chars (Argx) = Name_Ravenscar then
11753                   Set_Ravenscar_Profile (N);
11754                elsif Chars (Argx) = Name_Restricted then
11755                   Set_Profile_Restrictions
11756                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11757                else
11758                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11759                end if;
11760             end;
11761
11762          ----------------------
11763          -- Profile_Warnings --
11764          ----------------------
11765
11766          --  pragma Profile_Warnings (profile_IDENTIFIER);
11767
11768          --  profile_IDENTIFIER => Restricted | Ravenscar
11769
11770          when Pragma_Profile_Warnings =>
11771             GNAT_Pragma;
11772             Check_Arg_Count (1);
11773             Check_Valid_Configuration_Pragma;
11774             Check_No_Identifiers;
11775
11776             declare
11777                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11778             begin
11779                if Chars (Argx) = Name_Ravenscar then
11780                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11781                elsif Chars (Argx) = Name_Restricted then
11782                   Set_Profile_Restrictions (Restricted, N, Warn => True);
11783                else
11784                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11785                end if;
11786             end;
11787
11788          --------------------------
11789          -- Propagate_Exceptions --
11790          --------------------------
11791
11792          --  pragma Propagate_Exceptions;
11793
11794          --  Note: this pragma is obsolete and has no effect
11795
11796          when Pragma_Propagate_Exceptions =>
11797             GNAT_Pragma;
11798             Check_Arg_Count (0);
11799
11800             if In_Extended_Main_Source_Unit (N) then
11801                Propagate_Exceptions := True;
11802             end if;
11803
11804          ------------------
11805          -- Psect_Object --
11806          ------------------
11807
11808          --  pragma Psect_Object (
11809          --        [Internal =>] LOCAL_NAME,
11810          --     [, [External =>] EXTERNAL_SYMBOL]
11811          --     [, [Size     =>] EXTERNAL_SYMBOL]);
11812
11813          when Pragma_Psect_Object | Pragma_Common_Object =>
11814          Psect_Object : declare
11815             Args  : Args_List (1 .. 3);
11816             Names : constant Name_List (1 .. 3) := (
11817                       Name_Internal,
11818                       Name_External,
11819                       Name_Size);
11820
11821             Internal : Node_Id renames Args (1);
11822             External : Node_Id renames Args (2);
11823             Size     : Node_Id renames Args (3);
11824
11825             Def_Id : Entity_Id;
11826
11827             procedure Check_Too_Long (Arg : Node_Id);
11828             --  Posts message if the argument is an identifier with more
11829             --  than 31 characters, or a string literal with more than
11830             --  31 characters, and we are operating under VMS
11831
11832             --------------------
11833             -- Check_Too_Long --
11834             --------------------
11835
11836             procedure Check_Too_Long (Arg : Node_Id) is
11837                X : constant Node_Id := Original_Node (Arg);
11838
11839             begin
11840                if not Nkind_In (X, N_String_Literal, N_Identifier) then
11841                   Error_Pragma_Arg
11842                     ("inappropriate argument for pragma %", Arg);
11843                end if;
11844
11845                if OpenVMS_On_Target then
11846                   if (Nkind (X) = N_String_Literal
11847                        and then String_Length (Strval (X)) > 31)
11848                     or else
11849                      (Nkind (X) = N_Identifier
11850                        and then Length_Of_Name (Chars (X)) > 31)
11851                   then
11852                      Error_Pragma_Arg
11853                        ("argument for pragma % is longer than 31 characters",
11854                         Arg);
11855                   end if;
11856                end if;
11857             end Check_Too_Long;
11858
11859          --  Start of processing for Common_Object/Psect_Object
11860
11861          begin
11862             GNAT_Pragma;
11863             Gather_Associations (Names, Args);
11864             Process_Extended_Import_Export_Internal_Arg (Internal);
11865
11866             Def_Id := Entity (Internal);
11867
11868             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
11869                Error_Pragma_Arg
11870                  ("pragma% must designate an object", Internal);
11871             end if;
11872
11873             Check_Too_Long (Internal);
11874
11875             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
11876                Error_Pragma_Arg
11877                  ("cannot use pragma% for imported/exported object",
11878                   Internal);
11879             end if;
11880
11881             if Is_Concurrent_Type (Etype (Internal)) then
11882                Error_Pragma_Arg
11883                  ("cannot specify pragma % for task/protected object",
11884                   Internal);
11885             end if;
11886
11887             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
11888                  or else
11889                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
11890             then
11891                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
11892             end if;
11893
11894             if Ekind (Def_Id) = E_Constant then
11895                Error_Pragma_Arg
11896                  ("cannot specify pragma % for a constant", Internal);
11897             end if;
11898
11899             if Is_Record_Type (Etype (Internal)) then
11900                declare
11901                   Ent  : Entity_Id;
11902                   Decl : Entity_Id;
11903
11904                begin
11905                   Ent := First_Entity (Etype (Internal));
11906                   while Present (Ent) loop
11907                      Decl := Declaration_Node (Ent);
11908
11909                      if Ekind (Ent) = E_Component
11910                        and then Nkind (Decl) = N_Component_Declaration
11911                        and then Present (Expression (Decl))
11912                        and then Warn_On_Export_Import
11913                      then
11914                         Error_Msg_N
11915                           ("?object for pragma % has defaults", Internal);
11916                         exit;
11917
11918                      else
11919                         Next_Entity (Ent);
11920                      end if;
11921                   end loop;
11922                end;
11923             end if;
11924
11925             if Present (Size) then
11926                Check_Too_Long (Size);
11927             end if;
11928
11929             if Present (External) then
11930                Check_Arg_Is_External_Name (External);
11931                Check_Too_Long (External);
11932             end if;
11933
11934             --  If all error tests pass, link pragma on to the rep item chain
11935
11936             Record_Rep_Item (Def_Id, N);
11937          end Psect_Object;
11938
11939          ----------
11940          -- Pure --
11941          ----------
11942
11943          --  pragma Pure [(library_unit_NAME)];
11944
11945          when Pragma_Pure => Pure : declare
11946             Ent : Entity_Id;
11947
11948          begin
11949             Check_Ada_83_Warning;
11950             Check_Valid_Library_Unit_Pragma;
11951
11952             if Nkind (N) = N_Null_Statement then
11953                return;
11954             end if;
11955
11956             Ent := Find_Lib_Unit_Name;
11957             Set_Is_Pure (Ent);
11958             Set_Has_Pragma_Pure (Ent);
11959             Set_Suppress_Elaboration_Warnings (Ent);
11960          end Pure;
11961
11962          -------------
11963          -- Pure_05 --
11964          -------------
11965
11966          --  pragma Pure_05 [(library_unit_NAME)];
11967
11968          --  This pragma is useable only in GNAT_Mode, where it is used like
11969          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
11970          --  it is ignored). It may be used after a pragma Preelaborate, in
11971          --  which case it overrides the effect of the pragma Preelaborate.
11972          --  This is used to implement AI-362 which recategorizes some run-time
11973          --  packages in Ada 2005 mode.
11974
11975          when Pragma_Pure_05 => Pure_05 : declare
11976             Ent : Entity_Id;
11977
11978          begin
11979             GNAT_Pragma;
11980             Check_Valid_Library_Unit_Pragma;
11981
11982             if not GNAT_Mode then
11983                Error_Pragma ("pragma% only available in GNAT mode");
11984             end if;
11985
11986             if Nkind (N) = N_Null_Statement then
11987                return;
11988             end if;
11989
11990             --  This is one of the few cases where we need to test the value of
11991             --  Ada_Version_Explicit rather than Ada_Version (which is always
11992             --  set to Ada_2012 in a predefined unit), we need to know the
11993             --  explicit version set to know if this pragma is active.
11994
11995             if Ada_Version_Explicit >= Ada_2005 then
11996                Ent := Find_Lib_Unit_Name;
11997                Set_Is_Preelaborated (Ent, False);
11998                Set_Is_Pure (Ent);
11999                Set_Suppress_Elaboration_Warnings (Ent);
12000             end if;
12001          end Pure_05;
12002
12003          -------------------
12004          -- Pure_Function --
12005          -------------------
12006
12007          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12008
12009          when Pragma_Pure_Function => Pure_Function : declare
12010             E_Id      : Node_Id;
12011             E         : Entity_Id;
12012             Def_Id    : Entity_Id;
12013             Effective : Boolean := False;
12014
12015          begin
12016             GNAT_Pragma;
12017             Check_Arg_Count (1);
12018             Check_Optional_Identifier (Arg1, Name_Entity);
12019             Check_Arg_Is_Local_Name (Arg1);
12020             E_Id := Get_Pragma_Arg (Arg1);
12021
12022             if Error_Posted (E_Id) then
12023                return;
12024             end if;
12025
12026             --  Loop through homonyms (overloadings) of referenced entity
12027
12028             E := Entity (E_Id);
12029
12030             if Present (E) then
12031                loop
12032                   Def_Id := Get_Base_Subprogram (E);
12033
12034                   if not Ekind_In (Def_Id, E_Function,
12035                                            E_Generic_Function,
12036                                            E_Operator)
12037                   then
12038                      Error_Pragma_Arg
12039                        ("pragma% requires a function name", Arg1);
12040                   end if;
12041
12042                   Set_Is_Pure (Def_Id);
12043
12044                   if not Has_Pragma_Pure_Function (Def_Id) then
12045                      Set_Has_Pragma_Pure_Function (Def_Id);
12046                      Effective := True;
12047                   end if;
12048
12049                   exit when From_Aspect_Specification (N);
12050                   E := Homonym (E);
12051                   exit when No (E) or else Scope (E) /= Current_Scope;
12052                end loop;
12053
12054                if not Effective
12055                  and then Warn_On_Redundant_Constructs
12056                then
12057                   Error_Msg_NE
12058                     ("pragma Pure_Function on& is redundant?",
12059                      N, Entity (E_Id));
12060                end if;
12061             end if;
12062          end Pure_Function;
12063
12064          --------------------
12065          -- Queuing_Policy --
12066          --------------------
12067
12068          --  pragma Queuing_Policy (policy_IDENTIFIER);
12069
12070          when Pragma_Queuing_Policy => declare
12071             QP : Character;
12072
12073          begin
12074             Check_Ada_83_Warning;
12075             Check_Arg_Count (1);
12076             Check_No_Identifiers;
12077             Check_Arg_Is_Queuing_Policy (Arg1);
12078             Check_Valid_Configuration_Pragma;
12079             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12080             QP := Fold_Upper (Name_Buffer (1));
12081
12082             if Queuing_Policy /= ' '
12083               and then Queuing_Policy /= QP
12084             then
12085                Error_Msg_Sloc := Queuing_Policy_Sloc;
12086                Error_Pragma ("queuing policy incompatible with policy#");
12087
12088             --  Set new policy, but always preserve System_Location since we
12089             --  like the error message with the run time name.
12090
12091             else
12092                Queuing_Policy := QP;
12093
12094                if Queuing_Policy_Sloc /= System_Location then
12095                   Queuing_Policy_Sloc := Loc;
12096                end if;
12097             end if;
12098          end;
12099
12100          -----------------------
12101          -- Relative_Deadline --
12102          -----------------------
12103
12104          --  pragma Relative_Deadline (time_span_EXPRESSION);
12105
12106          when Pragma_Relative_Deadline => Relative_Deadline : declare
12107             P   : constant Node_Id := Parent (N);
12108             Arg : Node_Id;
12109
12110          begin
12111             Ada_2005_Pragma;
12112             Check_No_Identifiers;
12113             Check_Arg_Count (1);
12114
12115             Arg := Get_Pragma_Arg (Arg1);
12116
12117             --  The expression must be analyzed in the special manner described
12118             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12119
12120             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12121
12122             --  Subprogram case
12123
12124             if Nkind (P) = N_Subprogram_Body then
12125                Check_In_Main_Program;
12126
12127             --  Tasks
12128
12129             elsif Nkind (P) = N_Task_Definition then
12130                null;
12131
12132             --  Anything else is incorrect
12133
12134             else
12135                Pragma_Misplaced;
12136             end if;
12137
12138             if Has_Relative_Deadline_Pragma (P) then
12139                Error_Pragma ("duplicate pragma% not allowed");
12140             else
12141                Set_Has_Relative_Deadline_Pragma (P, True);
12142
12143                if Nkind (P) = N_Task_Definition then
12144                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12145                end if;
12146             end if;
12147          end Relative_Deadline;
12148
12149          ---------------------------
12150          -- Remote_Call_Interface --
12151          ---------------------------
12152
12153          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12154
12155          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12156             Cunit_Node : Node_Id;
12157             Cunit_Ent  : Entity_Id;
12158             K          : Node_Kind;
12159
12160          begin
12161             Check_Ada_83_Warning;
12162             Check_Valid_Library_Unit_Pragma;
12163
12164             if Nkind (N) = N_Null_Statement then
12165                return;
12166             end if;
12167
12168             Cunit_Node := Cunit (Current_Sem_Unit);
12169             K          := Nkind (Unit (Cunit_Node));
12170             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12171
12172             if K = N_Package_Declaration
12173               or else K = N_Generic_Package_Declaration
12174               or else K = N_Subprogram_Declaration
12175               or else K = N_Generic_Subprogram_Declaration
12176               or else (K = N_Subprogram_Body
12177                          and then Acts_As_Spec (Unit (Cunit_Node)))
12178             then
12179                null;
12180             else
12181                Error_Pragma (
12182                  "pragma% must apply to package or subprogram declaration");
12183             end if;
12184
12185             Set_Is_Remote_Call_Interface (Cunit_Ent);
12186          end Remote_Call_Interface;
12187
12188          ------------------
12189          -- Remote_Types --
12190          ------------------
12191
12192          --  pragma Remote_Types [(library_unit_NAME)];
12193
12194          when Pragma_Remote_Types => Remote_Types : declare
12195             Cunit_Node : Node_Id;
12196             Cunit_Ent  : Entity_Id;
12197
12198          begin
12199             Check_Ada_83_Warning;
12200             Check_Valid_Library_Unit_Pragma;
12201
12202             if Nkind (N) = N_Null_Statement then
12203                return;
12204             end if;
12205
12206             Cunit_Node := Cunit (Current_Sem_Unit);
12207             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12208
12209             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12210                                                 N_Generic_Package_Declaration)
12211             then
12212                Error_Pragma
12213                  ("pragma% can only apply to a package declaration");
12214             end if;
12215
12216             Set_Is_Remote_Types (Cunit_Ent);
12217          end Remote_Types;
12218
12219          ---------------
12220          -- Ravenscar --
12221          ---------------
12222
12223          --  pragma Ravenscar;
12224
12225          when Pragma_Ravenscar =>
12226             GNAT_Pragma;
12227             Check_Arg_Count (0);
12228             Check_Valid_Configuration_Pragma;
12229             Set_Ravenscar_Profile (N);
12230
12231             if Warn_On_Obsolescent_Feature then
12232                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12233                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12234             end if;
12235
12236          -------------------------
12237          -- Restricted_Run_Time --
12238          -------------------------
12239
12240          --  pragma Restricted_Run_Time;
12241
12242          when Pragma_Restricted_Run_Time =>
12243             GNAT_Pragma;
12244             Check_Arg_Count (0);
12245             Check_Valid_Configuration_Pragma;
12246             Set_Profile_Restrictions
12247               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12248
12249             if Warn_On_Obsolescent_Feature then
12250                Error_Msg_N
12251                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12252                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12253             end if;
12254
12255          ------------------
12256          -- Restrictions --
12257          ------------------
12258
12259          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12260
12261          --  RESTRICTION ::=
12262          --    restriction_IDENTIFIER
12263          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12264
12265          when Pragma_Restrictions =>
12266             Process_Restrictions_Or_Restriction_Warnings
12267               (Warn => Treat_Restrictions_As_Warnings);
12268
12269          --------------------------
12270          -- Restriction_Warnings --
12271          --------------------------
12272
12273          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12274
12275          --  RESTRICTION ::=
12276          --    restriction_IDENTIFIER
12277          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12278
12279          when Pragma_Restriction_Warnings =>
12280             GNAT_Pragma;
12281             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12282
12283          ----------------
12284          -- Reviewable --
12285          ----------------
12286
12287          --  pragma Reviewable;
12288
12289          when Pragma_Reviewable =>
12290             Check_Ada_83_Warning;
12291             Check_Arg_Count (0);
12292
12293             --  Call dummy debugging function rv. This is done to assist front
12294             --  end debugging. By placing a Reviewable pragma in the source
12295             --  program, a breakpoint on rv catches this place in the source,
12296             --  allowing convenient stepping to the point of interest.
12297
12298             rv;
12299
12300          --------------------------
12301          -- Short_Circuit_And_Or --
12302          --------------------------
12303
12304          when Pragma_Short_Circuit_And_Or =>
12305             GNAT_Pragma;
12306             Check_Arg_Count (0);
12307             Check_Valid_Configuration_Pragma;
12308             Short_Circuit_And_Or := True;
12309
12310          -------------------
12311          -- Share_Generic --
12312          -------------------
12313
12314          --  pragma Share_Generic (NAME {, NAME});
12315
12316          when Pragma_Share_Generic =>
12317             GNAT_Pragma;
12318             Process_Generic_List;
12319
12320          ------------
12321          -- Shared --
12322          ------------
12323
12324          --  pragma Shared (LOCAL_NAME);
12325
12326          when Pragma_Shared =>
12327             GNAT_Pragma;
12328             Process_Atomic_Shared_Volatile;
12329
12330          --------------------
12331          -- Shared_Passive --
12332          --------------------
12333
12334          --  pragma Shared_Passive [(library_unit_NAME)];
12335
12336          --  Set the flag Is_Shared_Passive of program unit name entity
12337
12338          when Pragma_Shared_Passive => Shared_Passive : declare
12339             Cunit_Node : Node_Id;
12340             Cunit_Ent  : Entity_Id;
12341
12342          begin
12343             Check_Ada_83_Warning;
12344             Check_Valid_Library_Unit_Pragma;
12345
12346             if Nkind (N) = N_Null_Statement then
12347                return;
12348             end if;
12349
12350             Cunit_Node := Cunit (Current_Sem_Unit);
12351             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12352
12353             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12354                                                 N_Generic_Package_Declaration)
12355             then
12356                Error_Pragma
12357                  ("pragma% can only apply to a package declaration");
12358             end if;
12359
12360             Set_Is_Shared_Passive (Cunit_Ent);
12361          end Shared_Passive;
12362
12363          -----------------------
12364          -- Short_Descriptors --
12365          -----------------------
12366
12367          --  pragma Short_Descriptors;
12368
12369          when Pragma_Short_Descriptors =>
12370             GNAT_Pragma;
12371             Check_Arg_Count (0);
12372             Check_Valid_Configuration_Pragma;
12373             Short_Descriptors := True;
12374
12375          ----------------------
12376          -- Source_File_Name --
12377          ----------------------
12378
12379          --  There are five forms for this pragma:
12380
12381          --  pragma Source_File_Name (
12382          --    [UNIT_NAME      =>] unit_NAME,
12383          --     BODY_FILE_NAME =>  STRING_LITERAL
12384          --    [, [INDEX =>] INTEGER_LITERAL]);
12385
12386          --  pragma Source_File_Name (
12387          --    [UNIT_NAME      =>] unit_NAME,
12388          --     SPEC_FILE_NAME =>  STRING_LITERAL
12389          --    [, [INDEX =>] INTEGER_LITERAL]);
12390
12391          --  pragma Source_File_Name (
12392          --     BODY_FILE_NAME  => STRING_LITERAL
12393          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12394          --  [, CASING          => CASING_SPEC]);
12395
12396          --  pragma Source_File_Name (
12397          --     SPEC_FILE_NAME  => STRING_LITERAL
12398          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12399          --  [, CASING          => CASING_SPEC]);
12400
12401          --  pragma Source_File_Name (
12402          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12403          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12404          --  [, CASING             => CASING_SPEC]);
12405
12406          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12407
12408          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12409          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12410          --  only be used when no project file is used, while SFNP can only be
12411          --  used when a project file is used.
12412
12413          --  No processing here. Processing was completed during parsing, since
12414          --  we need to have file names set as early as possible. Units are
12415          --  loaded well before semantic processing starts.
12416
12417          --  The only processing we defer to this point is the check for
12418          --  correct placement.
12419
12420          when Pragma_Source_File_Name =>
12421             GNAT_Pragma;
12422             Check_Valid_Configuration_Pragma;
12423
12424          ------------------------------
12425          -- Source_File_Name_Project --
12426          ------------------------------
12427
12428          --  See Source_File_Name for syntax
12429
12430          --  No processing here. Processing was completed during parsing, since
12431          --  we need to have file names set as early as possible. Units are
12432          --  loaded well before semantic processing starts.
12433
12434          --  The only processing we defer to this point is the check for
12435          --  correct placement.
12436
12437          when Pragma_Source_File_Name_Project =>
12438             GNAT_Pragma;
12439             Check_Valid_Configuration_Pragma;
12440
12441             --  Check that a pragma Source_File_Name_Project is used only in a
12442             --  configuration pragmas file.
12443
12444             --  Pragmas Source_File_Name_Project should only be generated by
12445             --  the Project Manager in configuration pragmas files.
12446
12447             --  This is really an ugly test. It seems to depend on some
12448             --  accidental and undocumented property. At the very least it
12449             --  needs to be documented, but it would be better to have a
12450             --  clean way of testing if we are in a configuration file???
12451
12452             if Present (Parent (N)) then
12453                Error_Pragma
12454                  ("pragma% can only appear in a configuration pragmas file");
12455             end if;
12456
12457          ----------------------
12458          -- Source_Reference --
12459          ----------------------
12460
12461          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12462
12463          --  Nothing to do, all processing completed in Par.Prag, since we need
12464          --  the information for possible parser messages that are output.
12465
12466          when Pragma_Source_Reference =>
12467             GNAT_Pragma;
12468
12469          --------------------------------
12470          -- Static_Elaboration_Desired --
12471          --------------------------------
12472
12473          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12474
12475          when Pragma_Static_Elaboration_Desired =>
12476             GNAT_Pragma;
12477             Check_At_Most_N_Arguments (1);
12478
12479             if Is_Compilation_Unit (Current_Scope)
12480               and then Ekind (Current_Scope) = E_Package
12481             then
12482                Set_Static_Elaboration_Desired (Current_Scope, True);
12483             else
12484                Error_Pragma ("pragma% must apply to a library-level package");
12485             end if;
12486
12487          ------------------
12488          -- Storage_Size --
12489          ------------------
12490
12491          --  pragma Storage_Size (EXPRESSION);
12492
12493          when Pragma_Storage_Size => Storage_Size : declare
12494             P   : constant Node_Id := Parent (N);
12495             Arg : Node_Id;
12496
12497          begin
12498             Check_No_Identifiers;
12499             Check_Arg_Count (1);
12500
12501             --  The expression must be analyzed in the special manner described
12502             --  in "Handling of Default Expressions" in sem.ads.
12503
12504             Arg := Get_Pragma_Arg (Arg1);
12505             Preanalyze_Spec_Expression (Arg, Any_Integer);
12506
12507             if not Is_Static_Expression (Arg) then
12508                Check_Restriction (Static_Storage_Size, Arg);
12509             end if;
12510
12511             if Nkind (P) /= N_Task_Definition then
12512                Pragma_Misplaced;
12513                return;
12514
12515             else
12516                if Has_Storage_Size_Pragma (P) then
12517                   Error_Pragma ("duplicate pragma% not allowed");
12518                else
12519                   Set_Has_Storage_Size_Pragma (P, True);
12520                end if;
12521
12522                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12523                --  ???  exp_ch9 should use this!
12524             end if;
12525          end Storage_Size;
12526
12527          ------------------
12528          -- Storage_Unit --
12529          ------------------
12530
12531          --  pragma Storage_Unit (NUMERIC_LITERAL);
12532
12533          --  Only permitted argument is System'Storage_Unit value
12534
12535          when Pragma_Storage_Unit =>
12536             Check_No_Identifiers;
12537             Check_Arg_Count (1);
12538             Check_Arg_Is_Integer_Literal (Arg1);
12539
12540             if Intval (Get_Pragma_Arg (Arg1)) /=
12541               UI_From_Int (Ttypes.System_Storage_Unit)
12542             then
12543                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12544                Error_Pragma_Arg
12545                  ("the only allowed argument for pragma% is ^", Arg1);
12546             end if;
12547
12548          --------------------
12549          -- Stream_Convert --
12550          --------------------
12551
12552          --  pragma Stream_Convert (
12553          --    [Entity =>] type_LOCAL_NAME,
12554          --    [Read   =>] function_NAME,
12555          --    [Write  =>] function NAME);
12556
12557          when Pragma_Stream_Convert => Stream_Convert : declare
12558
12559             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12560             --  Check that the given argument is the name of a local function
12561             --  of one argument that is not overloaded earlier in the current
12562             --  local scope. A check is also made that the argument is a
12563             --  function with one parameter.
12564
12565             --------------------------------------
12566             -- Check_OK_Stream_Convert_Function --
12567             --------------------------------------
12568
12569             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12570                Ent : Entity_Id;
12571
12572             begin
12573                Check_Arg_Is_Local_Name (Arg);
12574                Ent := Entity (Get_Pragma_Arg (Arg));
12575
12576                if Has_Homonym (Ent) then
12577                   Error_Pragma_Arg
12578                     ("argument for pragma% may not be overloaded", Arg);
12579                end if;
12580
12581                if Ekind (Ent) /= E_Function
12582                  or else No (First_Formal (Ent))
12583                  or else Present (Next_Formal (First_Formal (Ent)))
12584                then
12585                   Error_Pragma_Arg
12586                     ("argument for pragma% must be" &
12587                      " function of one argument", Arg);
12588                end if;
12589             end Check_OK_Stream_Convert_Function;
12590
12591          --  Start of processing for Stream_Convert
12592
12593          begin
12594             GNAT_Pragma;
12595             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12596             Check_Arg_Count (3);
12597             Check_Optional_Identifier (Arg1, Name_Entity);
12598             Check_Optional_Identifier (Arg2, Name_Read);
12599             Check_Optional_Identifier (Arg3, Name_Write);
12600             Check_Arg_Is_Local_Name (Arg1);
12601             Check_OK_Stream_Convert_Function (Arg2);
12602             Check_OK_Stream_Convert_Function (Arg3);
12603
12604             declare
12605                Typ   : constant Entity_Id :=
12606                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12607                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12608                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12609
12610             begin
12611                Check_First_Subtype (Arg1);
12612
12613                --  Check for too early or too late. Note that we don't enforce
12614                --  the rule about primitive operations in this case, since, as
12615                --  is the case for explicit stream attributes themselves, these
12616                --  restrictions are not appropriate. Note that the chaining of
12617                --  the pragma by Rep_Item_Too_Late is actually the critical
12618                --  processing done for this pragma.
12619
12620                if Rep_Item_Too_Early (Typ, N)
12621                     or else
12622                   Rep_Item_Too_Late (Typ, N, FOnly => True)
12623                then
12624                   return;
12625                end if;
12626
12627                --  Return if previous error
12628
12629                if Etype (Typ) = Any_Type
12630                     or else
12631                   Etype (Read) = Any_Type
12632                     or else
12633                   Etype (Write) = Any_Type
12634                then
12635                   return;
12636                end if;
12637
12638                --  Error checks
12639
12640                if Underlying_Type (Etype (Read)) /= Typ then
12641                   Error_Pragma_Arg
12642                     ("incorrect return type for function&", Arg2);
12643                end if;
12644
12645                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12646                   Error_Pragma_Arg
12647                     ("incorrect parameter type for function&", Arg3);
12648                end if;
12649
12650                if Underlying_Type (Etype (First_Formal (Read))) /=
12651                   Underlying_Type (Etype (Write))
12652                then
12653                   Error_Pragma_Arg
12654                     ("result type of & does not match Read parameter type",
12655                      Arg3);
12656                end if;
12657             end;
12658          end Stream_Convert;
12659
12660          -------------------------
12661          -- Style_Checks (GNAT) --
12662          -------------------------
12663
12664          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12665
12666          --  This is processed by the parser since some of the style checks
12667          --  take place during source scanning and parsing. This means that
12668          --  we don't need to issue error messages here.
12669
12670          when Pragma_Style_Checks => Style_Checks : declare
12671             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
12672             S  : String_Id;
12673             C  : Char_Code;
12674
12675          begin
12676             GNAT_Pragma;
12677             Check_No_Identifiers;
12678
12679             --  Two argument form
12680
12681             if Arg_Count = 2 then
12682                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12683
12684                declare
12685                   E_Id : Node_Id;
12686                   E    : Entity_Id;
12687
12688                begin
12689                   E_Id := Get_Pragma_Arg (Arg2);
12690                   Analyze (E_Id);
12691
12692                   if not Is_Entity_Name (E_Id) then
12693                      Error_Pragma_Arg
12694                        ("second argument of pragma% must be entity name",
12695                         Arg2);
12696                   end if;
12697
12698                   E := Entity (E_Id);
12699
12700                   if E = Any_Id then
12701                      return;
12702                   else
12703                      loop
12704                         Set_Suppress_Style_Checks (E,
12705                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12706                         exit when No (Homonym (E));
12707                         E := Homonym (E);
12708                      end loop;
12709                   end if;
12710                end;
12711
12712             --  One argument form
12713
12714             else
12715                Check_Arg_Count (1);
12716
12717                if Nkind (A) = N_String_Literal then
12718                   S   := Strval (A);
12719
12720                   declare
12721                      Slen    : constant Natural := Natural (String_Length (S));
12722                      Options : String (1 .. Slen);
12723                      J       : Natural;
12724
12725                   begin
12726                      J := 1;
12727                      loop
12728                         C := Get_String_Char (S, Int (J));
12729                         exit when not In_Character_Range (C);
12730                         Options (J) := Get_Character (C);
12731
12732                         --  If at end of string, set options. As per discussion
12733                         --  above, no need to check for errors, since we issued
12734                         --  them in the parser.
12735
12736                         if J = Slen then
12737                            Set_Style_Check_Options (Options);
12738                            exit;
12739                         end if;
12740
12741                         J := J + 1;
12742                      end loop;
12743                   end;
12744
12745                elsif Nkind (A) = N_Identifier then
12746                   if Chars (A) = Name_All_Checks then
12747                      if GNAT_Mode then
12748                         Set_GNAT_Style_Check_Options;
12749                      else
12750                         Set_Default_Style_Check_Options;
12751                      end if;
12752
12753                   elsif Chars (A) = Name_On then
12754                      Style_Check := True;
12755
12756                   elsif Chars (A) = Name_Off then
12757                      Style_Check := False;
12758                   end if;
12759                end if;
12760             end if;
12761          end Style_Checks;
12762
12763          --------------
12764          -- Subtitle --
12765          --------------
12766
12767          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12768
12769          when Pragma_Subtitle =>
12770             GNAT_Pragma;
12771             Check_Arg_Count (1);
12772             Check_Optional_Identifier (Arg1, Name_Subtitle);
12773             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12774             Store_Note (N);
12775
12776          --------------
12777          -- Suppress --
12778          --------------
12779
12780          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12781
12782          when Pragma_Suppress =>
12783             Process_Suppress_Unsuppress (True);
12784
12785          ------------------
12786          -- Suppress_All --
12787          ------------------
12788
12789          --  pragma Suppress_All;
12790
12791          --  The only check made here is that the pragma has no arguments.
12792          --  There are no placement rules, and the processing required (setting
12793          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
12794          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
12795          --  then creates and inserts a pragma Suppress (All_Checks).
12796
12797          when Pragma_Suppress_All =>
12798             GNAT_Pragma;
12799             Check_Arg_Count (0);
12800
12801          -------------------------
12802          -- Suppress_Debug_Info --
12803          -------------------------
12804
12805          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12806
12807          when Pragma_Suppress_Debug_Info =>
12808             GNAT_Pragma;
12809             Check_Arg_Count (1);
12810             Check_Optional_Identifier (Arg1, Name_Entity);
12811             Check_Arg_Is_Local_Name (Arg1);
12812             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12813
12814          ----------------------------------
12815          -- Suppress_Exception_Locations --
12816          ----------------------------------
12817
12818          --  pragma Suppress_Exception_Locations;
12819
12820          when Pragma_Suppress_Exception_Locations =>
12821             GNAT_Pragma;
12822             Check_Arg_Count (0);
12823             Check_Valid_Configuration_Pragma;
12824             Exception_Locations_Suppressed := True;
12825
12826          -----------------------------
12827          -- Suppress_Initialization --
12828          -----------------------------
12829
12830          --  pragma Suppress_Initialization ([Entity =>] type_Name);
12831
12832          when Pragma_Suppress_Initialization => Suppress_Init : declare
12833             E_Id : Node_Id;
12834             E    : Entity_Id;
12835
12836          begin
12837             GNAT_Pragma;
12838             Check_Arg_Count (1);
12839             Check_Optional_Identifier (Arg1, Name_Entity);
12840             Check_Arg_Is_Local_Name (Arg1);
12841
12842             E_Id := Get_Pragma_Arg (Arg1);
12843
12844             if Etype (E_Id) = Any_Type then
12845                return;
12846             end if;
12847
12848             E := Entity (E_Id);
12849
12850             if Is_Type (E) then
12851                if Is_Incomplete_Or_Private_Type (E) then
12852                   if No (Full_View (Base_Type (E))) then
12853                      Error_Pragma_Arg
12854                        ("argument of pragma% cannot be an incomplete type",
12855                          Arg1);
12856                   else
12857                      Set_Suppress_Init_Proc (Full_View (Base_Type (E)));
12858                   end if;
12859                else
12860                   Set_Suppress_Init_Proc (Base_Type (E));
12861                end if;
12862
12863             else
12864                Error_Pragma_Arg
12865                  ("pragma% requires argument that is a type name", Arg1);
12866             end if;
12867          end Suppress_Init;
12868
12869          -----------------
12870          -- System_Name --
12871          -----------------
12872
12873          --  pragma System_Name (DIRECT_NAME);
12874
12875          --  Syntax check: one argument, which must be the identifier GNAT or
12876          --  the identifier GCC, no other identifiers are acceptable.
12877
12878          when Pragma_System_Name =>
12879             GNAT_Pragma;
12880             Check_No_Identifiers;
12881             Check_Arg_Count (1);
12882             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
12883
12884          -----------------------------
12885          -- Task_Dispatching_Policy --
12886          -----------------------------
12887
12888          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
12889
12890          when Pragma_Task_Dispatching_Policy => declare
12891             DP : Character;
12892
12893          begin
12894             Check_Ada_83_Warning;
12895             Check_Arg_Count (1);
12896             Check_No_Identifiers;
12897             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12898             Check_Valid_Configuration_Pragma;
12899             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12900             DP := Fold_Upper (Name_Buffer (1));
12901
12902             if Task_Dispatching_Policy /= ' '
12903               and then Task_Dispatching_Policy /= DP
12904             then
12905                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12906                Error_Pragma
12907                  ("task dispatching policy incompatible with policy#");
12908
12909             --  Set new policy, but always preserve System_Location since we
12910             --  like the error message with the run time name.
12911
12912             else
12913                Task_Dispatching_Policy := DP;
12914
12915                if Task_Dispatching_Policy_Sloc /= System_Location then
12916                   Task_Dispatching_Policy_Sloc := Loc;
12917                end if;
12918             end if;
12919          end;
12920
12921          --------------
12922          -- Task_Info --
12923          --------------
12924
12925          --  pragma Task_Info (EXPRESSION);
12926
12927          when Pragma_Task_Info => Task_Info : declare
12928             P : constant Node_Id := Parent (N);
12929
12930          begin
12931             GNAT_Pragma;
12932
12933             if Nkind (P) /= N_Task_Definition then
12934                Error_Pragma ("pragma% must appear in task definition");
12935             end if;
12936
12937             Check_No_Identifiers;
12938             Check_Arg_Count (1);
12939
12940             Analyze_And_Resolve
12941               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
12942
12943             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
12944                return;
12945             end if;
12946
12947             if Has_Task_Info_Pragma (P) then
12948                Error_Pragma ("duplicate pragma% not allowed");
12949             else
12950                Set_Has_Task_Info_Pragma (P, True);
12951             end if;
12952          end Task_Info;
12953
12954          ---------------
12955          -- Task_Name --
12956          ---------------
12957
12958          --  pragma Task_Name (string_EXPRESSION);
12959
12960          when Pragma_Task_Name => Task_Name : declare
12961             P   : constant Node_Id := Parent (N);
12962             Arg : Node_Id;
12963
12964          begin
12965             Check_No_Identifiers;
12966             Check_Arg_Count (1);
12967
12968             Arg := Get_Pragma_Arg (Arg1);
12969
12970             --  The expression is used in the call to Create_Task, and must be
12971             --  expanded there, not in the context of the current spec. It must
12972             --  however be analyzed to capture global references, in case it
12973             --  appears in a generic context.
12974
12975             Preanalyze_And_Resolve (Arg, Standard_String);
12976
12977             if Nkind (P) /= N_Task_Definition then
12978                Pragma_Misplaced;
12979             end if;
12980
12981             if Has_Task_Name_Pragma (P) then
12982                Error_Pragma ("duplicate pragma% not allowed");
12983             else
12984                Set_Has_Task_Name_Pragma (P, True);
12985                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12986             end if;
12987          end Task_Name;
12988
12989          ------------------
12990          -- Task_Storage --
12991          ------------------
12992
12993          --  pragma Task_Storage (
12994          --     [Task_Type =>] LOCAL_NAME,
12995          --     [Top_Guard =>] static_integer_EXPRESSION);
12996
12997          when Pragma_Task_Storage => Task_Storage : declare
12998             Args  : Args_List (1 .. 2);
12999             Names : constant Name_List (1 .. 2) := (
13000                       Name_Task_Type,
13001                       Name_Top_Guard);
13002
13003             Task_Type : Node_Id renames Args (1);
13004             Top_Guard : Node_Id renames Args (2);
13005
13006             Ent : Entity_Id;
13007
13008          begin
13009             GNAT_Pragma;
13010             Gather_Associations (Names, Args);
13011
13012             if No (Task_Type) then
13013                Error_Pragma
13014                  ("missing task_type argument for pragma%");
13015             end if;
13016
13017             Check_Arg_Is_Local_Name (Task_Type);
13018
13019             Ent := Entity (Task_Type);
13020
13021             if not Is_Task_Type (Ent) then
13022                Error_Pragma_Arg
13023                  ("argument for pragma% must be task type", Task_Type);
13024             end if;
13025
13026             if No (Top_Guard) then
13027                Error_Pragma_Arg
13028                  ("pragma% takes two arguments", Task_Type);
13029             else
13030                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13031             end if;
13032
13033             Check_First_Subtype (Task_Type);
13034
13035             if Rep_Item_Too_Late (Ent, N) then
13036                raise Pragma_Exit;
13037             end if;
13038          end Task_Storage;
13039
13040          --------------------------
13041          -- Thread_Local_Storage --
13042          --------------------------
13043
13044          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13045
13046          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13047             Id : Node_Id;
13048             E  : Entity_Id;
13049
13050          begin
13051             GNAT_Pragma;
13052             Check_Arg_Count (1);
13053             Check_Optional_Identifier (Arg1, Name_Entity);
13054             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13055
13056             Id := Get_Pragma_Arg (Arg1);
13057             Analyze (Id);
13058
13059             if not Is_Entity_Name (Id)
13060               or else Ekind (Entity (Id)) /= E_Variable
13061             then
13062                Error_Pragma_Arg ("local variable name required", Arg1);
13063             end if;
13064
13065             E := Entity (Id);
13066
13067             if Rep_Item_Too_Early (E, N)
13068               or else Rep_Item_Too_Late (E, N)
13069             then
13070                raise Pragma_Exit;
13071             end if;
13072
13073             Set_Has_Pragma_Thread_Local_Storage (E);
13074             Set_Has_Gigi_Rep_Item (E);
13075          end Thread_Local_Storage;
13076
13077          ----------------
13078          -- Time_Slice --
13079          ----------------
13080
13081          --  pragma Time_Slice (static_duration_EXPRESSION);
13082
13083          when Pragma_Time_Slice => Time_Slice : declare
13084             Val : Ureal;
13085             Nod : Node_Id;
13086
13087          begin
13088             GNAT_Pragma;
13089             Check_Arg_Count (1);
13090             Check_No_Identifiers;
13091             Check_In_Main_Program;
13092             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13093
13094             if not Error_Posted (Arg1) then
13095                Nod := Next (N);
13096                while Present (Nod) loop
13097                   if Nkind (Nod) = N_Pragma
13098                     and then Pragma_Name (Nod) = Name_Time_Slice
13099                   then
13100                      Error_Msg_Name_1 := Pname;
13101                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13102                   end if;
13103
13104                   Next (Nod);
13105                end loop;
13106             end if;
13107
13108             --  Process only if in main unit
13109
13110             if Get_Source_Unit (Loc) = Main_Unit then
13111                Opt.Time_Slice_Set := True;
13112                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13113
13114                if Val <= Ureal_0 then
13115                   Opt.Time_Slice_Value := 0;
13116
13117                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13118                   Opt.Time_Slice_Value := 1_000_000_000;
13119
13120                else
13121                   Opt.Time_Slice_Value :=
13122                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13123                end if;
13124             end if;
13125          end Time_Slice;
13126
13127          -----------
13128          -- Title --
13129          -----------
13130
13131          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13132
13133          --   TITLING_OPTION ::=
13134          --     [Title =>] STRING_LITERAL
13135          --   | [Subtitle =>] STRING_LITERAL
13136
13137          when Pragma_Title => Title : declare
13138             Args  : Args_List (1 .. 2);
13139             Names : constant Name_List (1 .. 2) := (
13140                       Name_Title,
13141                       Name_Subtitle);
13142
13143          begin
13144             GNAT_Pragma;
13145             Gather_Associations (Names, Args);
13146             Store_Note (N);
13147
13148             for J in 1 .. 2 loop
13149                if Present (Args (J)) then
13150                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13151                end if;
13152             end loop;
13153          end Title;
13154
13155          ---------------------
13156          -- Unchecked_Union --
13157          ---------------------
13158
13159          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13160
13161          when Pragma_Unchecked_Union => Unchecked_Union : declare
13162             Assoc   : constant Node_Id := Arg1;
13163             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13164             Typ     : Entity_Id;
13165             Discr   : Entity_Id;
13166             Tdef    : Node_Id;
13167             Clist   : Node_Id;
13168             Vpart   : Node_Id;
13169             Comp    : Node_Id;
13170             Variant : Node_Id;
13171
13172          begin
13173             Ada_2005_Pragma;
13174             Check_No_Identifiers;
13175             Check_Arg_Count (1);
13176             Check_Arg_Is_Local_Name (Arg1);
13177
13178             Find_Type (Type_Id);
13179             Typ := Entity (Type_Id);
13180
13181             if Typ = Any_Type
13182               or else Rep_Item_Too_Early (Typ, N)
13183             then
13184                return;
13185             else
13186                Typ := Underlying_Type (Typ);
13187             end if;
13188
13189             if Rep_Item_Too_Late (Typ, N) then
13190                return;
13191             end if;
13192
13193             Check_First_Subtype (Arg1);
13194
13195             --  Note remaining cases are references to a type in the current
13196             --  declarative part. If we find an error, we post the error on
13197             --  the relevant type declaration at an appropriate point.
13198
13199             if not Is_Record_Type (Typ) then
13200                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13201                return;
13202
13203             elsif Is_Tagged_Type (Typ) then
13204                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13205                return;
13206
13207             elsif Is_Limited_Type (Typ) then
13208                Error_Msg_N
13209                  ("Unchecked_Union must not be limited record type", Typ);
13210                Explain_Limited_Type (Typ, Typ);
13211                return;
13212
13213             else
13214                if not Has_Discriminants (Typ) then
13215                   Error_Msg_N
13216                     ("Unchecked_Union must have one discriminant", Typ);
13217                   return;
13218                end if;
13219
13220                Discr := First_Discriminant (Typ);
13221                while Present (Discr) loop
13222                   if No (Discriminant_Default_Value (Discr)) then
13223                      Error_Msg_N
13224                        ("Unchecked_Union discriminant must have default value",
13225                         Discr);
13226                   end if;
13227
13228                   Next_Discriminant (Discr);
13229                end loop;
13230
13231                Tdef  := Type_Definition (Declaration_Node (Typ));
13232                Clist := Component_List (Tdef);
13233
13234                Comp := First (Component_Items (Clist));
13235                while Present (Comp) loop
13236                   Check_Component (Comp, Typ);
13237                   Next (Comp);
13238                end loop;
13239
13240                if No (Clist) or else No (Variant_Part (Clist)) then
13241                   Error_Msg_N
13242                     ("Unchecked_Union must have variant part",
13243                      Tdef);
13244                   return;
13245                end if;
13246
13247                Vpart := Variant_Part (Clist);
13248
13249                Variant := First (Variants (Vpart));
13250                while Present (Variant) loop
13251                   Check_Variant (Variant, Typ);
13252                   Next (Variant);
13253                end loop;
13254             end if;
13255
13256             Set_Is_Unchecked_Union  (Typ);
13257             Set_Convention (Typ, Convention_C);
13258             Set_Has_Unchecked_Union (Base_Type (Typ));
13259             Set_Is_Unchecked_Union  (Base_Type (Typ));
13260          end Unchecked_Union;
13261
13262          ------------------------
13263          -- Unimplemented_Unit --
13264          ------------------------
13265
13266          --  pragma Unimplemented_Unit;
13267
13268          --  Note: this only gives an error if we are generating code, or if
13269          --  we are in a generic library unit (where the pragma appears in the
13270          --  body, not in the spec).
13271
13272          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13273             Cunitent : constant Entity_Id :=
13274                          Cunit_Entity (Get_Source_Unit (Loc));
13275             Ent_Kind : constant Entity_Kind :=
13276                          Ekind (Cunitent);
13277
13278          begin
13279             GNAT_Pragma;
13280             Check_Arg_Count (0);
13281
13282             if Operating_Mode = Generate_Code
13283               or else Ent_Kind = E_Generic_Function
13284               or else Ent_Kind = E_Generic_Procedure
13285               or else Ent_Kind = E_Generic_Package
13286             then
13287                Get_Name_String (Chars (Cunitent));
13288                Set_Casing (Mixed_Case);
13289                Write_Str (Name_Buffer (1 .. Name_Len));
13290                Write_Str (" is not supported in this configuration");
13291                Write_Eol;
13292                raise Unrecoverable_Error;
13293             end if;
13294          end Unimplemented_Unit;
13295
13296          ------------------------
13297          -- Universal_Aliasing --
13298          ------------------------
13299
13300          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13301
13302          when Pragma_Universal_Aliasing => Universal_Alias : declare
13303             E_Id : Entity_Id;
13304
13305          begin
13306             GNAT_Pragma;
13307             Check_Arg_Count (1);
13308             Check_Optional_Identifier (Arg2, Name_Entity);
13309             Check_Arg_Is_Local_Name (Arg1);
13310             E_Id := Entity (Get_Pragma_Arg (Arg1));
13311
13312             if E_Id = Any_Type then
13313                return;
13314             elsif No (E_Id) or else not Is_Type (E_Id) then
13315                Error_Pragma_Arg ("pragma% requires type", Arg1);
13316             end if;
13317
13318             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13319          end Universal_Alias;
13320
13321          --------------------
13322          -- Universal_Data --
13323          --------------------
13324
13325          --  pragma Universal_Data [(library_unit_NAME)];
13326
13327          when Pragma_Universal_Data =>
13328             GNAT_Pragma;
13329
13330             --  If this is a configuration pragma, then set the universal
13331             --  addressing option, otherwise confirm that the pragma satisfies
13332             --  the requirements of library unit pragma placement and leave it
13333             --  to the GNAAMP back end to detect the pragma (avoids transitive
13334             --  setting of the option due to withed units).
13335
13336             if Is_Configuration_Pragma then
13337                Universal_Addressing_On_AAMP := True;
13338             else
13339                Check_Valid_Library_Unit_Pragma;
13340             end if;
13341
13342             if not AAMP_On_Target then
13343                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13344             end if;
13345
13346          ----------------
13347          -- Unmodified --
13348          ----------------
13349
13350          --  pragma Unmodified (local_Name {, local_Name});
13351
13352          when Pragma_Unmodified => Unmodified : declare
13353             Arg_Node : Node_Id;
13354             Arg_Expr : Node_Id;
13355             Arg_Ent  : Entity_Id;
13356
13357          begin
13358             GNAT_Pragma;
13359             Check_At_Least_N_Arguments (1);
13360
13361             --  Loop through arguments
13362
13363             Arg_Node := Arg1;
13364             while Present (Arg_Node) loop
13365                Check_No_Identifier (Arg_Node);
13366
13367                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13368                --  in fact generate reference, so that the entity will have a
13369                --  reference, which will inhibit any warnings about it not
13370                --  being referenced, and also properly show up in the ali file
13371                --  as a reference. But this reference is recorded before the
13372                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13373                --  generated for this reference.
13374
13375                Check_Arg_Is_Local_Name (Arg_Node);
13376                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13377
13378                if Is_Entity_Name (Arg_Expr) then
13379                   Arg_Ent := Entity (Arg_Expr);
13380
13381                   if not Is_Assignable (Arg_Ent) then
13382                      Error_Pragma_Arg
13383                        ("pragma% can only be applied to a variable",
13384                         Arg_Expr);
13385                   else
13386                      Set_Has_Pragma_Unmodified (Arg_Ent);
13387                   end if;
13388                end if;
13389
13390                Next (Arg_Node);
13391             end loop;
13392          end Unmodified;
13393
13394          ------------------
13395          -- Unreferenced --
13396          ------------------
13397
13398          --  pragma Unreferenced (local_Name {, local_Name});
13399
13400          --    or when used in a context clause:
13401
13402          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13403
13404          when Pragma_Unreferenced => Unreferenced : declare
13405             Arg_Node : Node_Id;
13406             Arg_Expr : Node_Id;
13407             Arg_Ent  : Entity_Id;
13408             Citem    : Node_Id;
13409
13410          begin
13411             GNAT_Pragma;
13412             Check_At_Least_N_Arguments (1);
13413
13414             --  Check case of appearing within context clause
13415
13416             if Is_In_Context_Clause then
13417
13418                --  The arguments must all be units mentioned in a with clause
13419                --  in the same context clause. Note we already checked (in
13420                --  Par.Prag) that the arguments are either identifiers or
13421                --  selected components.
13422
13423                Arg_Node := Arg1;
13424                while Present (Arg_Node) loop
13425                   Citem := First (List_Containing (N));
13426                   while Citem /= N loop
13427                      if Nkind (Citem) = N_With_Clause
13428                        and then
13429                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13430                      then
13431                         Set_Has_Pragma_Unreferenced
13432                           (Cunit_Entity
13433                              (Get_Source_Unit
13434                                 (Library_Unit (Citem))));
13435                         Set_Unit_Name
13436                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
13437                         exit;
13438                      end if;
13439
13440                      Next (Citem);
13441                   end loop;
13442
13443                   if Citem = N then
13444                      Error_Pragma_Arg
13445                        ("argument of pragma% is not with'ed unit", Arg_Node);
13446                   end if;
13447
13448                   Next (Arg_Node);
13449                end loop;
13450
13451             --  Case of not in list of context items
13452
13453             else
13454                Arg_Node := Arg1;
13455                while Present (Arg_Node) loop
13456                   Check_No_Identifier (Arg_Node);
13457
13458                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
13459                   --  will in fact generate reference, so that the entity will
13460                   --  have a reference, which will inhibit any warnings about
13461                   --  it not being referenced, and also properly show up in the
13462                   --  ali file as a reference. But this reference is recorded
13463                   --  before the Has_Pragma_Unreferenced flag is set, so that
13464                   --  no warning is generated for this reference.
13465
13466                   Check_Arg_Is_Local_Name (Arg_Node);
13467                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
13468
13469                   if Is_Entity_Name (Arg_Expr) then
13470                      Arg_Ent := Entity (Arg_Expr);
13471
13472                      --  If the entity is overloaded, the pragma applies to the
13473                      --  most recent overloading, as documented. In this case,
13474                      --  name resolution does not generate a reference, so it
13475                      --  must be done here explicitly.
13476
13477                      if Is_Overloaded (Arg_Expr) then
13478                         Generate_Reference (Arg_Ent, N);
13479                      end if;
13480
13481                      Set_Has_Pragma_Unreferenced (Arg_Ent);
13482                   end if;
13483
13484                   Next (Arg_Node);
13485                end loop;
13486             end if;
13487          end Unreferenced;
13488
13489          --------------------------
13490          -- Unreferenced_Objects --
13491          --------------------------
13492
13493          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13494
13495          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13496             Arg_Node : Node_Id;
13497             Arg_Expr : Node_Id;
13498
13499          begin
13500             GNAT_Pragma;
13501             Check_At_Least_N_Arguments (1);
13502
13503             Arg_Node := Arg1;
13504             while Present (Arg_Node) loop
13505                Check_No_Identifier (Arg_Node);
13506                Check_Arg_Is_Local_Name (Arg_Node);
13507                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13508
13509                if not Is_Entity_Name (Arg_Expr)
13510                  or else not Is_Type (Entity (Arg_Expr))
13511                then
13512                   Error_Pragma_Arg
13513                     ("argument for pragma% must be type or subtype", Arg_Node);
13514                end if;
13515
13516                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13517                Next (Arg_Node);
13518             end loop;
13519          end Unreferenced_Objects;
13520
13521          ------------------------------
13522          -- Unreserve_All_Interrupts --
13523          ------------------------------
13524
13525          --  pragma Unreserve_All_Interrupts;
13526
13527          when Pragma_Unreserve_All_Interrupts =>
13528             GNAT_Pragma;
13529             Check_Arg_Count (0);
13530
13531             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13532                Unreserve_All_Interrupts := True;
13533             end if;
13534
13535          ----------------
13536          -- Unsuppress --
13537          ----------------
13538
13539          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13540
13541          when Pragma_Unsuppress =>
13542             Ada_2005_Pragma;
13543             Process_Suppress_Unsuppress (False);
13544
13545          -------------------
13546          -- Use_VADS_Size --
13547          -------------------
13548
13549          --  pragma Use_VADS_Size;
13550
13551          when Pragma_Use_VADS_Size =>
13552             GNAT_Pragma;
13553             Check_Arg_Count (0);
13554             Check_Valid_Configuration_Pragma;
13555             Use_VADS_Size := True;
13556
13557          ---------------------
13558          -- Validity_Checks --
13559          ---------------------
13560
13561          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13562
13563          when Pragma_Validity_Checks => Validity_Checks : declare
13564             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13565             S  : String_Id;
13566             C  : Char_Code;
13567
13568          begin
13569             GNAT_Pragma;
13570             Check_Arg_Count (1);
13571             Check_No_Identifiers;
13572
13573             if Nkind (A) = N_String_Literal then
13574                S   := Strval (A);
13575
13576                declare
13577                   Slen    : constant Natural := Natural (String_Length (S));
13578                   Options : String (1 .. Slen);
13579                   J       : Natural;
13580
13581                begin
13582                   J := 1;
13583                   loop
13584                      C := Get_String_Char (S, Int (J));
13585                      exit when not In_Character_Range (C);
13586                      Options (J) := Get_Character (C);
13587
13588                      if J = Slen then
13589                         Set_Validity_Check_Options (Options);
13590                         exit;
13591                      else
13592                         J := J + 1;
13593                      end if;
13594                   end loop;
13595                end;
13596
13597             elsif Nkind (A) = N_Identifier then
13598
13599                if Chars (A) = Name_All_Checks then
13600                   Set_Validity_Check_Options ("a");
13601
13602                elsif Chars (A) = Name_On then
13603                   Validity_Checks_On := True;
13604
13605                elsif Chars (A) = Name_Off then
13606                   Validity_Checks_On := False;
13607
13608                end if;
13609             end if;
13610          end Validity_Checks;
13611
13612          --------------
13613          -- Volatile --
13614          --------------
13615
13616          --  pragma Volatile (LOCAL_NAME);
13617
13618          when Pragma_Volatile =>
13619             Process_Atomic_Shared_Volatile;
13620
13621          -------------------------
13622          -- Volatile_Components --
13623          -------------------------
13624
13625          --  pragma Volatile_Components (array_LOCAL_NAME);
13626
13627          --  Volatile is handled by the same circuit as Atomic_Components
13628
13629          --------------
13630          -- Warnings --
13631          --------------
13632
13633          --  pragma Warnings (On | Off);
13634          --  pragma Warnings (On | Off, LOCAL_NAME);
13635          --  pragma Warnings (static_string_EXPRESSION);
13636          --  pragma Warnings (On | Off, STRING_LITERAL);
13637
13638          when Pragma_Warnings => Warnings : begin
13639             GNAT_Pragma;
13640             Check_At_Least_N_Arguments (1);
13641             Check_No_Identifiers;
13642
13643             --  If debug flag -gnatd.i is set, pragma is ignored
13644
13645             if Debug_Flag_Dot_I then
13646                return;
13647             end if;
13648
13649             --  Process various forms of the pragma
13650
13651             declare
13652                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13653
13654             begin
13655                --  One argument case
13656
13657                if Arg_Count = 1 then
13658
13659                   --  On/Off one argument case was processed by parser
13660
13661                   if Nkind (Argx) = N_Identifier
13662                     and then
13663                       (Chars (Argx) = Name_On
13664                          or else
13665                        Chars (Argx) = Name_Off)
13666                   then
13667                      null;
13668
13669                   --  One argument case must be ON/OFF or static string expr
13670
13671                   elsif not Is_Static_String_Expression (Arg1) then
13672                      Error_Pragma_Arg
13673                        ("argument of pragma% must be On/Off or " &
13674                         "static string expression", Arg1);
13675
13676                   --  One argument string expression case
13677
13678                   else
13679                      declare
13680                         Lit : constant Node_Id   := Expr_Value_S (Argx);
13681                         Str : constant String_Id := Strval (Lit);
13682                         Len : constant Nat       := String_Length (Str);
13683                         C   : Char_Code;
13684                         J   : Nat;
13685                         OK  : Boolean;
13686                         Chr : Character;
13687
13688                      begin
13689                         J := 1;
13690                         while J <= Len loop
13691                            C := Get_String_Char (Str, J);
13692                            OK := In_Character_Range (C);
13693
13694                            if OK then
13695                               Chr := Get_Character (C);
13696
13697                               --  Dot case
13698
13699                               if J < Len and then Chr = '.' then
13700                                  J := J + 1;
13701                                  C := Get_String_Char (Str, J);
13702                                  Chr := Get_Character (C);
13703
13704                                  if not Set_Dot_Warning_Switch (Chr) then
13705                                     Error_Pragma_Arg
13706                                       ("invalid warning switch character " &
13707                                        '.' & Chr, Arg1);
13708                                  end if;
13709
13710                               --  Non-Dot case
13711
13712                               else
13713                                  OK := Set_Warning_Switch (Chr);
13714                               end if;
13715                            end if;
13716
13717                            if not OK then
13718                               Error_Pragma_Arg
13719                                 ("invalid warning switch character " & Chr,
13720                                  Arg1);
13721                            end if;
13722
13723                            J := J + 1;
13724                         end loop;
13725                      end;
13726                   end if;
13727
13728                   --  Two or more arguments (must be two)
13729
13730                else
13731                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13732                   Check_At_Most_N_Arguments (2);
13733
13734                   declare
13735                      E_Id : Node_Id;
13736                      E    : Entity_Id;
13737                      Err  : Boolean;
13738
13739                   begin
13740                      E_Id := Get_Pragma_Arg (Arg2);
13741                      Analyze (E_Id);
13742
13743                      --  In the expansion of an inlined body, a reference to
13744                      --  the formal may be wrapped in a conversion if the
13745                      --  actual is a conversion. Retrieve the real entity name.
13746
13747                      if (In_Instance_Body
13748                          or else In_Inlined_Body)
13749                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13750                      then
13751                         E_Id := Expression (E_Id);
13752                      end if;
13753
13754                      --  Entity name case
13755
13756                      if Is_Entity_Name (E_Id) then
13757                         E := Entity (E_Id);
13758
13759                         if E = Any_Id then
13760                            return;
13761                         else
13762                            loop
13763                               Set_Warnings_Off
13764                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13765                                                               Name_Off));
13766
13767                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13768                                 and then Warn_On_Warnings_Off
13769                               then
13770                                  Warnings_Off_Pragmas.Append ((N, E));
13771                               end if;
13772
13773                               if Is_Enumeration_Type (E) then
13774                                  declare
13775                                     Lit : Entity_Id;
13776                                  begin
13777                                     Lit := First_Literal (E);
13778                                     while Present (Lit) loop
13779                                        Set_Warnings_Off (Lit);
13780                                        Next_Literal (Lit);
13781                                     end loop;
13782                                  end;
13783                               end if;
13784
13785                               exit when No (Homonym (E));
13786                               E := Homonym (E);
13787                            end loop;
13788                         end if;
13789
13790                      --  Error if not entity or static string literal case
13791
13792                      elsif not Is_Static_String_Expression (Arg2) then
13793                         Error_Pragma_Arg
13794                           ("second argument of pragma% must be entity " &
13795                            "name or static string expression", Arg2);
13796
13797                      --  String literal case
13798
13799                      else
13800                         String_To_Name_Buffer
13801                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
13802
13803                         --  Note on configuration pragma case: If this is a
13804                         --  configuration pragma, then for an OFF pragma, we
13805                         --  just set Config True in the call, which is all
13806                         --  that needs to be done. For the case of ON, this
13807                         --  is normally an error, unless it is canceling the
13808                         --  effect of a previous OFF pragma in the same file.
13809                         --  In any other case, an error will be signalled (ON
13810                         --  with no matching OFF).
13811
13812                         if Chars (Argx) = Name_Off then
13813                            Set_Specific_Warning_Off
13814                              (Loc, Name_Buffer (1 .. Name_Len),
13815                               Config => Is_Configuration_Pragma);
13816
13817                         elsif Chars (Argx) = Name_On then
13818                            Set_Specific_Warning_On
13819                              (Loc, Name_Buffer (1 .. Name_Len), Err);
13820
13821                            if Err then
13822                               Error_Msg
13823                                 ("?pragma Warnings On with no " &
13824                                  "matching Warnings Off",
13825                                  Loc);
13826                            end if;
13827                         end if;
13828                      end if;
13829                   end;
13830                end if;
13831             end;
13832          end Warnings;
13833
13834          -------------------
13835          -- Weak_External --
13836          -------------------
13837
13838          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
13839
13840          when Pragma_Weak_External => Weak_External : declare
13841             Ent : Entity_Id;
13842
13843          begin
13844             GNAT_Pragma;
13845             Check_Arg_Count (1);
13846             Check_Optional_Identifier (Arg1, Name_Entity);
13847             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13848             Ent := Entity (Get_Pragma_Arg (Arg1));
13849
13850             if Rep_Item_Too_Early (Ent, N) then
13851                return;
13852             else
13853                Ent := Underlying_Type (Ent);
13854             end if;
13855
13856             --  The only processing required is to link this item on to the
13857             --  list of rep items for the given entity. This is accomplished
13858             --  by the call to Rep_Item_Too_Late (when no error is detected
13859             --  and False is returned).
13860
13861             if Rep_Item_Too_Late (Ent, N) then
13862                return;
13863             else
13864                Set_Has_Gigi_Rep_Item (Ent);
13865             end if;
13866          end Weak_External;
13867
13868          -----------------------------
13869          -- Wide_Character_Encoding --
13870          -----------------------------
13871
13872          --  pragma Wide_Character_Encoding (IDENTIFIER);
13873
13874          when Pragma_Wide_Character_Encoding =>
13875             GNAT_Pragma;
13876
13877             --  Nothing to do, handled in parser. Note that we do not enforce
13878             --  configuration pragma placement, this pragma can appear at any
13879             --  place in the source, allowing mixed encodings within a single
13880             --  source program.
13881
13882             null;
13883
13884          --------------------
13885          -- Unknown_Pragma --
13886          --------------------
13887
13888          --  Should be impossible, since the case of an unknown pragma is
13889          --  separately processed before the case statement is entered.
13890
13891          when Unknown_Pragma =>
13892             raise Program_Error;
13893       end case;
13894
13895       --  AI05-0144: detect dangerous order dependence. Disabled for now,
13896       --  until AI is formally approved.
13897
13898       --  Check_Order_Dependence;
13899
13900    exception
13901       when Pragma_Exit => null;
13902    end Analyze_Pragma;
13903
13904    -------------------
13905    -- Check_Enabled --
13906    -------------------
13907
13908    function Check_Enabled (Nam : Name_Id) return Boolean is
13909       PP : Node_Id;
13910
13911    begin
13912       --  Loop through entries in check policy list
13913
13914       PP := Opt.Check_Policy_List;
13915       loop
13916          --  If there are no specific entries that matched, then we let the
13917          --  setting of assertions govern. Note that this provides the needed
13918          --  compatibility with the RM for the cases of assertion, invariant,
13919          --  precondition, predicate, and postcondition.
13920
13921          if No (PP) then
13922             return Assertions_Enabled;
13923
13924          --  Here we have an entry see if it matches
13925
13926          else
13927             declare
13928                PPA : constant List_Id := Pragma_Argument_Associations (PP);
13929
13930             begin
13931                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
13932                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
13933                      when Name_On | Name_Check =>
13934                         return True;
13935                      when Name_Off | Name_Ignore =>
13936                         return False;
13937                      when others =>
13938                         raise Program_Error;
13939                   end case;
13940
13941                else
13942                   PP := Next_Pragma (PP);
13943                end if;
13944             end;
13945          end if;
13946       end loop;
13947    end Check_Enabled;
13948
13949    ---------------------------------
13950    -- Delay_Config_Pragma_Analyze --
13951    ---------------------------------
13952
13953    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
13954    begin
13955       return Pragma_Name (N) = Name_Interrupt_State
13956                or else
13957              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
13958    end Delay_Config_Pragma_Analyze;
13959
13960    -------------------------
13961    -- Get_Base_Subprogram --
13962    -------------------------
13963
13964    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
13965       Result : Entity_Id;
13966
13967    begin
13968       --  Follow subprogram renaming chain
13969
13970       Result := Def_Id;
13971       while Is_Subprogram (Result)
13972         and then
13973           (Is_Generic_Instance (Result)
13974             or else Nkind (Parent (Declaration_Node (Result))) =
13975                                          N_Subprogram_Renaming_Declaration)
13976         and then Present (Alias (Result))
13977       loop
13978          Result := Alias (Result);
13979       end loop;
13980
13981       return Result;
13982    end Get_Base_Subprogram;
13983
13984    ----------------
13985    -- Initialize --
13986    ----------------
13987
13988    procedure Initialize is
13989    begin
13990       Externals.Init;
13991    end Initialize;
13992
13993    -----------------------------
13994    -- Is_Config_Static_String --
13995    -----------------------------
13996
13997    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
13998
13999       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14000       --  This is an internal recursive function that is just like the outer
14001       --  function except that it adds the string to the name buffer rather
14002       --  than placing the string in the name buffer.
14003
14004       ------------------------------
14005       -- Add_Config_Static_String --
14006       ------------------------------
14007
14008       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14009          N : Node_Id;
14010          C : Char_Code;
14011
14012       begin
14013          N := Arg;
14014
14015          if Nkind (N) = N_Op_Concat then
14016             if Add_Config_Static_String (Left_Opnd (N)) then
14017                N := Right_Opnd (N);
14018             else
14019                return False;
14020             end if;
14021          end if;
14022
14023          if Nkind (N) /= N_String_Literal then
14024             Error_Msg_N ("string literal expected for pragma argument", N);
14025             return False;
14026
14027          else
14028             for J in 1 .. String_Length (Strval (N)) loop
14029                C := Get_String_Char (Strval (N), J);
14030
14031                if not In_Character_Range (C) then
14032                   Error_Msg
14033                     ("string literal contains invalid wide character",
14034                      Sloc (N) + 1 + Source_Ptr (J));
14035                   return False;
14036                end if;
14037
14038                Add_Char_To_Name_Buffer (Get_Character (C));
14039             end loop;
14040          end if;
14041
14042          return True;
14043       end Add_Config_Static_String;
14044
14045    --  Start of processing for Is_Config_Static_String
14046
14047    begin
14048
14049       Name_Len := 0;
14050       return Add_Config_Static_String (Arg);
14051    end Is_Config_Static_String;
14052
14053    -----------------------------------------
14054    -- Is_Non_Significant_Pragma_Reference --
14055    -----------------------------------------
14056
14057    --  This function makes use of the following static table which indicates
14058    --  whether a given pragma is significant.
14059
14060    --  -1  indicates that references in any argument position are significant
14061    --  0   indicates that appearance in any argument is not significant
14062    --  +n  indicates that appearance as argument n is significant, but all
14063    --      other arguments are not significant
14064    --  99  special processing required (e.g. for pragma Check)
14065
14066    Sig_Flags : constant array (Pragma_Id) of Int :=
14067      (Pragma_AST_Entry                     => -1,
14068       Pragma_Abort_Defer                   => -1,
14069       Pragma_Ada_83                        => -1,
14070       Pragma_Ada_95                        => -1,
14071       Pragma_Ada_05                        => -1,
14072       Pragma_Ada_2005                      => -1,
14073       Pragma_Ada_12                        => -1,
14074       Pragma_Ada_2012                      => -1,
14075       Pragma_All_Calls_Remote              => -1,
14076       Pragma_Annotate                      => -1,
14077       Pragma_Assert                        => -1,
14078       Pragma_Assertion_Policy              =>  0,
14079       Pragma_Assume_No_Invalid_Values      =>  0,
14080       Pragma_Asynchronous                  => -1,
14081       Pragma_Atomic                        =>  0,
14082       Pragma_Atomic_Components             =>  0,
14083       Pragma_Attach_Handler                => -1,
14084       Pragma_Check                         => 99,
14085       Pragma_Check_Name                    =>  0,
14086       Pragma_Check_Policy                  =>  0,
14087       Pragma_CIL_Constructor               => -1,
14088       Pragma_CPP_Class                     =>  0,
14089       Pragma_CPP_Constructor               =>  0,
14090       Pragma_CPP_Virtual                   =>  0,
14091       Pragma_CPP_Vtable                    =>  0,
14092       Pragma_CPU                           => -1,
14093       Pragma_C_Pass_By_Copy                =>  0,
14094       Pragma_Comment                       =>  0,
14095       Pragma_Common_Object                 => -1,
14096       Pragma_Compile_Time_Error            => -1,
14097       Pragma_Compile_Time_Warning          => -1,
14098       Pragma_Compiler_Unit                 =>  0,
14099       Pragma_Complete_Representation       =>  0,
14100       Pragma_Complex_Representation        =>  0,
14101       Pragma_Component_Alignment           => -1,
14102       Pragma_Controlled                    =>  0,
14103       Pragma_Convention                    =>  0,
14104       Pragma_Convention_Identifier         =>  0,
14105       Pragma_Debug                         => -1,
14106       Pragma_Debug_Policy                  =>  0,
14107       Pragma_Default_Value                 => -1,
14108       Pragma_Default_Component_Value       => -1,
14109       Pragma_Detect_Blocking               => -1,
14110       Pragma_Default_Storage_Pool          => -1,
14111       Pragma_Dimension                     => -1,
14112       Pragma_Discard_Names                 =>  0,
14113       Pragma_Elaborate                     => -1,
14114       Pragma_Elaborate_All                 => -1,
14115       Pragma_Elaborate_Body                => -1,
14116       Pragma_Elaboration_Checks            => -1,
14117       Pragma_Eliminate                     => -1,
14118       Pragma_Export                        => -1,
14119       Pragma_Export_Exception              => -1,
14120       Pragma_Export_Function               => -1,
14121       Pragma_Export_Object                 => -1,
14122       Pragma_Export_Procedure              => -1,
14123       Pragma_Export_Value                  => -1,
14124       Pragma_Export_Valued_Procedure       => -1,
14125       Pragma_Extend_System                 => -1,
14126       Pragma_Extensions_Allowed            => -1,
14127       Pragma_External                      => -1,
14128       Pragma_Favor_Top_Level               => -1,
14129       Pragma_External_Name_Casing          => -1,
14130       Pragma_Fast_Math                     => -1,
14131       Pragma_Finalize_Storage_Only         =>  0,
14132       Pragma_Float_Representation          =>  0,
14133       Pragma_Ident                         => -1,
14134       Pragma_Implemented                   => -1,
14135       Pragma_Implicit_Packing              =>  0,
14136       Pragma_Import                        => +2,
14137       Pragma_Import_Exception              =>  0,
14138       Pragma_Import_Function               =>  0,
14139       Pragma_Import_Object                 =>  0,
14140       Pragma_Import_Procedure              =>  0,
14141       Pragma_Import_Valued_Procedure       =>  0,
14142       Pragma_Independent                   =>  0,
14143       Pragma_Independent_Components        =>  0,
14144       Pragma_Initialize_Scalars            => -1,
14145       Pragma_Inline                        =>  0,
14146       Pragma_Inline_Always                 =>  0,
14147       Pragma_Inline_Generic                =>  0,
14148       Pragma_Inspection_Point              => -1,
14149       Pragma_Interface                     => +2,
14150       Pragma_Interface_Name                => +2,
14151       Pragma_Interrupt_Handler             => -1,
14152       Pragma_Interrupt_Priority            => -1,
14153       Pragma_Interrupt_State               => -1,
14154       Pragma_Invariant                     => -1,
14155       Pragma_Java_Constructor              => -1,
14156       Pragma_Java_Interface                => -1,
14157       Pragma_Keep_Names                    =>  0,
14158       Pragma_License                       => -1,
14159       Pragma_Link_With                     => -1,
14160       Pragma_Linker_Alias                  => -1,
14161       Pragma_Linker_Constructor            => -1,
14162       Pragma_Linker_Destructor             => -1,
14163       Pragma_Linker_Options                => -1,
14164       Pragma_Linker_Section                => -1,
14165       Pragma_List                          => -1,
14166       Pragma_Locking_Policy                => -1,
14167       Pragma_Long_Float                    => -1,
14168       Pragma_Machine_Attribute             => -1,
14169       Pragma_Main                          => -1,
14170       Pragma_Main_Storage                  => -1,
14171       Pragma_Memory_Size                   => -1,
14172       Pragma_No_Return                     =>  0,
14173       Pragma_No_Body                       =>  0,
14174       Pragma_No_Run_Time                   => -1,
14175       Pragma_No_Strict_Aliasing            => -1,
14176       Pragma_Normalize_Scalars             => -1,
14177       Pragma_Obsolescent                   =>  0,
14178       Pragma_Optimize                      => -1,
14179       Pragma_Optimize_Alignment            => -1,
14180       Pragma_Ordered                       =>  0,
14181       Pragma_Pack                          =>  0,
14182       Pragma_Page                          => -1,
14183       Pragma_Passive                       => -1,
14184       Pragma_Preelaborable_Initialization  => -1,
14185       Pragma_Polling                       => -1,
14186       Pragma_Persistent_BSS                =>  0,
14187       Pragma_Postcondition                 => -1,
14188       Pragma_Precondition                  => -1,
14189       Pragma_Predicate                     => -1,
14190       Pragma_Preelaborate                  => -1,
14191       Pragma_Preelaborate_05               => -1,
14192       Pragma_Priority                      => -1,
14193       Pragma_Priority_Specific_Dispatching => -1,
14194       Pragma_Profile                       =>  0,
14195       Pragma_Profile_Warnings              =>  0,
14196       Pragma_Propagate_Exceptions          => -1,
14197       Pragma_Psect_Object                  => -1,
14198       Pragma_Pure                          => -1,
14199       Pragma_Pure_05                       => -1,
14200       Pragma_Pure_Function                 => -1,
14201       Pragma_Queuing_Policy                => -1,
14202       Pragma_Ravenscar                     => -1,
14203       Pragma_Relative_Deadline             => -1,
14204       Pragma_Remote_Call_Interface         => -1,
14205       Pragma_Remote_Types                  => -1,
14206       Pragma_Restricted_Run_Time           => -1,
14207       Pragma_Restriction_Warnings          => -1,
14208       Pragma_Restrictions                  => -1,
14209       Pragma_Reviewable                    => -1,
14210       Pragma_Short_Circuit_And_Or          => -1,
14211       Pragma_Share_Generic                 => -1,
14212       Pragma_Shared                        => -1,
14213       Pragma_Shared_Passive                => -1,
14214       Pragma_Short_Descriptors             =>  0,
14215       Pragma_Source_File_Name              => -1,
14216       Pragma_Source_File_Name_Project      => -1,
14217       Pragma_Source_Reference              => -1,
14218       Pragma_Storage_Size                  => -1,
14219       Pragma_Storage_Unit                  => -1,
14220       Pragma_Static_Elaboration_Desired    => -1,
14221       Pragma_Stream_Convert                => -1,
14222       Pragma_Style_Checks                  => -1,
14223       Pragma_Subtitle                      => -1,
14224       Pragma_Suppress                      =>  0,
14225       Pragma_Suppress_Exception_Locations  =>  0,
14226       Pragma_Suppress_All                  => -1,
14227       Pragma_Suppress_Debug_Info           =>  0,
14228       Pragma_Suppress_Initialization       =>  0,
14229       Pragma_System_Name                   => -1,
14230       Pragma_Task_Dispatching_Policy       => -1,
14231       Pragma_Task_Info                     => -1,
14232       Pragma_Task_Name                     => -1,
14233       Pragma_Task_Storage                  =>  0,
14234       Pragma_Thread_Local_Storage          =>  0,
14235       Pragma_Time_Slice                    => -1,
14236       Pragma_Title                         => -1,
14237       Pragma_Unchecked_Union               =>  0,
14238       Pragma_Unimplemented_Unit            => -1,
14239       Pragma_Universal_Aliasing            => -1,
14240       Pragma_Universal_Data                => -1,
14241       Pragma_Unmodified                    => -1,
14242       Pragma_Unreferenced                  => -1,
14243       Pragma_Unreferenced_Objects          => -1,
14244       Pragma_Unreserve_All_Interrupts      => -1,
14245       Pragma_Unsuppress                    =>  0,
14246       Pragma_Use_VADS_Size                 => -1,
14247       Pragma_Validity_Checks               => -1,
14248       Pragma_Volatile                      =>  0,
14249       Pragma_Volatile_Components           =>  0,
14250       Pragma_Warnings                      => -1,
14251       Pragma_Weak_External                 => -1,
14252       Pragma_Wide_Character_Encoding       =>  0,
14253       Unknown_Pragma                       =>  0);
14254
14255    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14256       Id : Pragma_Id;
14257       P  : Node_Id;
14258       C  : Int;
14259       A  : Node_Id;
14260
14261    begin
14262       P := Parent (N);
14263
14264       if Nkind (P) /= N_Pragma_Argument_Association then
14265          return False;
14266
14267       else
14268          Id := Get_Pragma_Id (Parent (P));
14269          C := Sig_Flags (Id);
14270
14271          case C is
14272             when -1 =>
14273                return False;
14274
14275             when 0 =>
14276                return True;
14277
14278             when 99 =>
14279                case Id is
14280
14281                   --  For pragma Check, the first argument is not significant,
14282                   --  the second and the third (if present) arguments are
14283                   --  significant.
14284
14285                   when Pragma_Check =>
14286                      return
14287                        P = First (Pragma_Argument_Associations (Parent (P)));
14288
14289                   when others =>
14290                      raise Program_Error;
14291                end case;
14292
14293             when others =>
14294                A := First (Pragma_Argument_Associations (Parent (P)));
14295                for J in 1 .. C - 1 loop
14296                   if No (A) then
14297                      return False;
14298                   end if;
14299
14300                   Next (A);
14301                end loop;
14302
14303                return A = P; -- is this wrong way round ???
14304          end case;
14305       end if;
14306    end Is_Non_Significant_Pragma_Reference;
14307
14308    ------------------------------
14309    -- Is_Pragma_String_Literal --
14310    ------------------------------
14311
14312    --  This function returns true if the corresponding pragma argument is a
14313    --  static string expression. These are the only cases in which string
14314    --  literals can appear as pragma arguments. We also allow a string literal
14315    --  as the first argument to pragma Assert (although it will of course
14316    --  always generate a type error).
14317
14318    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14319       Pragn : constant Node_Id := Parent (Par);
14320       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14321       Pname : constant Name_Id := Pragma_Name (Pragn);
14322       Argn  : Natural;
14323       N     : Node_Id;
14324
14325    begin
14326       Argn := 1;
14327       N := First (Assoc);
14328       loop
14329          exit when N = Par;
14330          Argn := Argn + 1;
14331          Next (N);
14332       end loop;
14333
14334       if Pname = Name_Assert then
14335          return True;
14336
14337       elsif Pname = Name_Export then
14338          return Argn > 2;
14339
14340       elsif Pname = Name_Ident then
14341          return Argn = 1;
14342
14343       elsif Pname = Name_Import then
14344          return Argn > 2;
14345
14346       elsif Pname = Name_Interface_Name then
14347          return Argn > 1;
14348
14349       elsif Pname = Name_Linker_Alias then
14350          return Argn = 2;
14351
14352       elsif Pname = Name_Linker_Section then
14353          return Argn = 2;
14354
14355       elsif Pname = Name_Machine_Attribute then
14356          return Argn = 2;
14357
14358       elsif Pname = Name_Source_File_Name then
14359          return True;
14360
14361       elsif Pname = Name_Source_Reference then
14362          return Argn = 2;
14363
14364       elsif Pname = Name_Title then
14365          return True;
14366
14367       elsif Pname = Name_Subtitle then
14368          return True;
14369
14370       else
14371          return False;
14372       end if;
14373    end Is_Pragma_String_Literal;
14374
14375    --------------------------------------
14376    -- Process_Compilation_Unit_Pragmas --
14377    --------------------------------------
14378
14379    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14380    begin
14381       --  A special check for pragma Suppress_All, a very strange DEC pragma,
14382       --  strange because it comes at the end of the unit. Rational has the
14383       --  same name for a pragma, but treats it as a program unit pragma, In
14384       --  GNAT we just decide to allow it anywhere at all. If it appeared then
14385       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
14386       --  node, and we insert a pragma Suppress (All_Checks) at the start of
14387       --  the context clause to ensure the correct processing.
14388
14389       if Has_Pragma_Suppress_All (N) then
14390          Prepend_To (Context_Items (N),
14391            Make_Pragma (Sloc (N),
14392              Chars                        => Name_Suppress,
14393              Pragma_Argument_Associations => New_List (
14394                Make_Pragma_Argument_Association (Sloc (N),
14395                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14396       end if;
14397
14398       --  Nothing else to do at the current time!
14399
14400    end Process_Compilation_Unit_Pragmas;
14401
14402    --------
14403    -- rv --
14404    --------
14405
14406    procedure rv is
14407    begin
14408       null;
14409    end rv;
14410
14411    --------------------------------
14412    -- Set_Encoded_Interface_Name --
14413    --------------------------------
14414
14415    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14416       Str : constant String_Id := Strval (S);
14417       Len : constant Int       := String_Length (Str);
14418       CC  : Char_Code;
14419       C   : Character;
14420       J   : Int;
14421
14422       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14423
14424       procedure Encode;
14425       --  Stores encoded value of character code CC. The encoding we use an
14426       --  underscore followed by four lower case hex digits.
14427
14428       ------------
14429       -- Encode --
14430       ------------
14431
14432       procedure Encode is
14433       begin
14434          Store_String_Char (Get_Char_Code ('_'));
14435          Store_String_Char
14436            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14437          Store_String_Char
14438            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14439          Store_String_Char
14440            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14441          Store_String_Char
14442            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14443       end Encode;
14444
14445    --  Start of processing for Set_Encoded_Interface_Name
14446
14447    begin
14448       --  If first character is asterisk, this is a link name, and we leave it
14449       --  completely unmodified. We also ignore null strings (the latter case
14450       --  happens only in error cases) and no encoding should occur for Java or
14451       --  AAMP interface names.
14452
14453       if Len = 0
14454         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14455         or else VM_Target /= No_VM
14456         or else AAMP_On_Target
14457       then
14458          Set_Interface_Name (E, S);
14459
14460       else
14461          J := 1;
14462          loop
14463             CC := Get_String_Char (Str, J);
14464
14465             exit when not In_Character_Range (CC);
14466
14467             C := Get_Character (CC);
14468
14469             exit when C /= '_' and then C /= '$'
14470               and then C not in '0' .. '9'
14471               and then C not in 'a' .. 'z'
14472               and then C not in 'A' .. 'Z';
14473
14474             if J = Len then
14475                Set_Interface_Name (E, S);
14476                return;
14477
14478             else
14479                J := J + 1;
14480             end if;
14481          end loop;
14482
14483          --  Here we need to encode. The encoding we use as follows:
14484          --     three underscores  + four hex digits (lower case)
14485
14486          Start_String;
14487
14488          for J in 1 .. String_Length (Str) loop
14489             CC := Get_String_Char (Str, J);
14490
14491             if not In_Character_Range (CC) then
14492                Encode;
14493             else
14494                C := Get_Character (CC);
14495
14496                if C = '_' or else C = '$'
14497                  or else C in '0' .. '9'
14498                  or else C in 'a' .. 'z'
14499                  or else C in 'A' .. 'Z'
14500                then
14501                   Store_String_Char (CC);
14502                else
14503                   Encode;
14504                end if;
14505             end if;
14506          end loop;
14507
14508          Set_Interface_Name (E,
14509            Make_String_Literal (Sloc (S),
14510              Strval => End_String));
14511       end if;
14512    end Set_Encoded_Interface_Name;
14513
14514    -------------------
14515    -- Set_Unit_Name --
14516    -------------------
14517
14518    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14519       Pref : Node_Id;
14520       Scop : Entity_Id;
14521
14522    begin
14523       if Nkind (N) = N_Identifier
14524         and then Nkind (With_Item) = N_Identifier
14525       then
14526          Set_Entity (N, Entity (With_Item));
14527
14528       elsif Nkind (N) = N_Selected_Component then
14529          Change_Selected_Component_To_Expanded_Name (N);
14530          Set_Entity (N, Entity (With_Item));
14531          Set_Entity (Selector_Name (N), Entity (N));
14532
14533          Pref := Prefix (N);
14534          Scop := Scope (Entity (N));
14535          while Nkind (Pref) = N_Selected_Component loop
14536             Change_Selected_Component_To_Expanded_Name (Pref);
14537             Set_Entity (Selector_Name (Pref), Scop);
14538             Set_Entity (Pref, Scop);
14539             Pref := Prefix (Pref);
14540             Scop := Scope (Scop);
14541          end loop;
14542
14543          Set_Entity (Pref, Scop);
14544       end if;
14545    end Set_Unit_Name;
14546
14547 end Sem_Prag;