OSDN Git Service

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