OSDN Git Service

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