OSDN Git Service

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