OSDN Git Service

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