OSDN Git Service

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