OSDN Git Service

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