OSDN Git Service

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