OSDN Git Service

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