OSDN Git Service

2011-11-21 Pascal Obry <obry@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-2011, 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 Aspects;  use Aspects;
33 with Atree;    use Atree;
34 with Casing;   use Casing;
35 with Checks;   use Checks;
36 with Csets;    use Csets;
37 with Debug;    use Debug;
38 with Einfo;    use Einfo;
39 with Elists;   use Elists;
40 with Errout;   use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze;   use Freeze;
44 with Lib;      use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists;   use Nlists;
49 with Nmake;    use Nmake;
50 with Opt;      use Opt;
51 with Output;   use Output;
52 with Par_SCO;  use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident;   use Rident;
55 with Rtsfind;  use Rtsfind;
56 with Sem;      use Sem;
57 with Sem_Aux;  use Sem_Aux;
58 with Sem_Ch3;  use Sem_Ch3;
59 with Sem_Ch6;  use Sem_Ch6;
60 with Sem_Ch8;  use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res;  use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand;    use Stand;
75 with Sinfo;    use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput;   use Sinput;
78 with Snames;   use Snames;
79 with Stringt;  use Stringt;
80 with Stylesw;  use Stylesw;
81 with Table;
82 with Targparm; use Targparm;
83 with Tbuild;   use Tbuild;
84 with Ttypes;
85 with Uintp;    use Uintp;
86 with Uname;    use Uname;
87 with Urealp;   use Urealp;
88 with Validsw;  use Validsw;
89 with Warnsw;   use Warnsw;
90
91 package body Sem_Prag is
92
93    ----------------------------------------------
94    -- Common Handling of Import-Export Pragmas --
95    ----------------------------------------------
96
97    --  In the following section, a number of Import_xxx and Export_xxx pragmas
98    --  are defined by GNAT. These are compatible with the DEC pragmas of the
99    --  same name, and all have the following common form and processing:
100
101    --  pragma Export_xxx
102    --        [Internal                 =>] LOCAL_NAME
103    --     [, [External                 =>] EXTERNAL_SYMBOL]
104    --     [, other optional parameters   ]);
105
106    --  pragma Import_xxx
107    --        [Internal                 =>] LOCAL_NAME
108    --     [, [External                 =>] EXTERNAL_SYMBOL]
109    --     [, other optional parameters   ]);
110
111    --   EXTERNAL_SYMBOL ::=
112    --     IDENTIFIER
113    --   | static_string_EXPRESSION
114
115    --  The internal LOCAL_NAME designates the entity that is imported or
116    --  exported, and must refer to an entity in the current declarative
117    --  part (as required by the rules for LOCAL_NAME).
118
119    --  The external linker name is designated by the External parameter if
120    --  given, or the Internal parameter if not (if there is no External
121    --  parameter, the External parameter is a copy of the Internal name).
122
123    --  If the External parameter is given as a string, then this string is
124    --  treated as an external name (exactly as though it had been given as an
125    --  External_Name parameter for a normal Import pragma).
126
127    --  If the External parameter is given as an identifier (or there is no
128    --  External parameter, so that the Internal identifier is used), then
129    --  the external name is the characters of the identifier, translated
130    --  to all upper case letters for OpenVMS versions of GNAT, and to all
131    --  lower case letters for all other versions
132
133    --  Note: the external name specified or implied by any of these special
134    --  Import_xxx or Export_xxx pragmas override an external or link name
135    --  specified in a previous Import or Export pragma.
136
137    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
138    --  named notation, following the standard rules for subprogram calls, i.e.
139    --  parameters can be given in any order if named notation is used, and
140    --  positional and named notation can be mixed, subject to the rule that all
141    --  positional parameters must appear first.
142
143    --  Note: All these pragmas are implemented exactly following the DEC design
144    --  and implementation and are intended to be fully compatible with the use
145    --  of these pragmas in the DEC Ada compiler.
146
147    --------------------------------------------
148    -- Checking for Duplicated External Names --
149    --------------------------------------------
150
151    --  It is suspicious if two separate Export pragmas use the same external
152    --  name. The following table is used to diagnose this situation so that
153    --  an appropriate warning can be issued.
154
155    --  The Node_Id stored is for the N_String_Literal node created to hold
156    --  the value of the external name. The Sloc of this node is used to
157    --  cross-reference the location of the duplication.
158
159    package Externals is new Table.Table (
160      Table_Component_Type => Node_Id,
161      Table_Index_Type     => Int,
162      Table_Low_Bound      => 0,
163      Table_Initial        => 100,
164      Table_Increment      => 100,
165      Table_Name           => "Name_Externals");
166
167    -------------------------------------
168    -- Local Subprograms and Variables --
169    -------------------------------------
170
171    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172    --  This routine is used for possible casing adjustment of an explicit
173    --  external name supplied as a string literal (the node N), according to
174    --  the casing requirement of Opt.External_Name_Casing. If this is set to
175    --  As_Is, then the string literal is returned unchanged, but if it is set
176    --  to Uppercase or Lowercase, then a new string literal with appropriate
177    --  casing is constructed.
178
179    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
181    --  original one, following the renaming chain) is returned. Otherwise the
182    --  entity is returned unchanged. Should be in Einfo???
183
184    procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185    --  Preanalyze the boolean expressions in the Requires and Ensures arguments
186    --  of a Test_Case pragma if present (possibly Empty). We treat these as
187    --  spec expressions (i.e. similar to a default expression).
188
189    procedure rv;
190    --  This is a dummy function called by the processing for pragma Reviewable.
191    --  It is there for assisting front end debugging. By placing a Reviewable
192    --  pragma in the source program, a breakpoint on rv catches this place in
193    --  the source, allowing convenient stepping to the point of interest.
194
195    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196    --  Place semantic information on the argument of an Elaborate/Elaborate_All
197    --  pragma. Entity name for unit and its parents is taken from item in
198    --  previous with_clause that mentions the unit.
199
200    -------------------------------
201    -- Adjust_External_Name_Case --
202    -------------------------------
203
204    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
205       CC : Char_Code;
206
207    begin
208       --  Adjust case of literal if required
209
210       if Opt.External_Name_Exp_Casing = As_Is then
211          return N;
212
213       else
214          --  Copy existing string
215
216          Start_String;
217
218          --  Set proper casing
219
220          for J in 1 .. String_Length (Strval (N)) loop
221             CC := Get_String_Char (Strval (N), J);
222
223             if Opt.External_Name_Exp_Casing = Uppercase
224               and then CC >= Get_Char_Code ('a')
225               and then CC <= Get_Char_Code ('z')
226             then
227                Store_String_Char (CC - 32);
228
229             elsif Opt.External_Name_Exp_Casing = Lowercase
230               and then CC >= Get_Char_Code ('A')
231               and then CC <= Get_Char_Code ('Z')
232             then
233                Store_String_Char (CC + 32);
234
235             else
236                Store_String_Char (CC);
237             end if;
238          end loop;
239
240          return
241            Make_String_Literal (Sloc (N),
242              Strval => End_String);
243       end if;
244    end Adjust_External_Name_Case;
245
246    ------------------------------
247    -- Analyze_PPC_In_Decl_Part --
248    ------------------------------
249
250    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
252
253    begin
254       --  Install formals and push subprogram spec onto scope stack so that we
255       --  can see the formals from the pragma.
256
257       Install_Formals (S);
258       Push_Scope (S);
259
260       --  Preanalyze the boolean expression, we treat this as a spec expression
261       --  (i.e. similar to a default expression).
262
263       Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
264
265       --  In ASIS mode, for a pragma generated from a source aspect, also
266       --  analyze the original aspect expression.
267
268       if ASIS_Mode
269         and then Present (Corresponding_Aspect (N))
270       then
271          Preanalyze_Spec_Expression
272            (Expression (Corresponding_Aspect (N)), Standard_Boolean);
273       end if;
274
275       --  For a class-wide condition, a reference to a controlling formal must
276       --  be interpreted as having the class-wide type (or an access to such)
277       --  so that the inherited condition can be properly applied to any
278       --  overriding operation (see ARM12 6.6.1 (7)).
279
280       if Class_Present (N) then
281          declare
282             T   : constant Entity_Id := Find_Dispatching_Type (S);
283
284             ACW : Entity_Id := Empty;
285             --  Access to T'class, created if there is a controlling formal
286             --  that is an access parameter.
287
288             function Get_ACW return Entity_Id;
289             --  If the expression has a reference to an controlling access
290             --  parameter, create an access to T'class for the necessary
291             --  conversions if one does not exist.
292
293             function Process (N : Node_Id) return Traverse_Result;
294             --  ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295             --  aspect for a primitive subprogram of a tagged type T, a name
296             --  that denotes a formal parameter of type T is interpreted as
297             --  having type T'Class. Similarly, a name that denotes a formal
298             --  accessparameter of type access-to-T is interpreted as having
299             --  type access-to-T'Class. This ensures the expression is well-
300             --  defined for a primitive subprogram of a type descended from T.
301
302             -------------
303             -- Get_ACW --
304             -------------
305
306             function Get_ACW return Entity_Id is
307                Loc  : constant Source_Ptr := Sloc (N);
308                Decl : Node_Id;
309
310             begin
311                if No (ACW) then
312                   Decl := Make_Full_Type_Declaration (Loc,
313                     Defining_Identifier => Make_Temporary (Loc, 'T'),
314                     Type_Definition =>
315                        Make_Access_To_Object_Definition (Loc,
316                        Subtype_Indication =>
317                          New_Occurrence_Of (Class_Wide_Type (T), Loc),
318                        All_Present => True));
319
320                   Insert_Before (Unit_Declaration_Node (S), Decl);
321                   Analyze (Decl);
322                   ACW := Defining_Identifier (Decl);
323                   Freeze_Before (Unit_Declaration_Node (S), ACW);
324                end if;
325
326                return ACW;
327             end Get_ACW;
328
329             -------------
330             -- Process --
331             -------------
332
333             function Process (N : Node_Id) return Traverse_Result is
334                Loc : constant Source_Ptr := Sloc (N);
335                Typ : Entity_Id;
336
337             begin
338                if Is_Entity_Name (N)
339                  and then Is_Formal (Entity (N))
340                  and then Nkind (Parent (N)) /= N_Type_Conversion
341                then
342                   if Etype (Entity (N)) = T then
343                      Typ := Class_Wide_Type (T);
344
345                   elsif Is_Access_Type (Etype (Entity (N)))
346                     and then Designated_Type (Etype (Entity (N))) = T
347                   then
348                      Typ := Get_ACW;
349                   else
350                      Typ := Empty;
351                   end if;
352
353                   if Present (Typ) then
354                      Rewrite (N,
355                        Make_Type_Conversion (Loc,
356                          Subtype_Mark =>
357                            New_Occurrence_Of (Typ, Loc),
358                          Expression  => New_Occurrence_Of (Entity (N), Loc)));
359                      Set_Etype (N, Typ);
360                   end if;
361                end if;
362
363                return OK;
364             end Process;
365
366             procedure Replace_Type is new Traverse_Proc (Process);
367
368          begin
369             Replace_Type (Get_Pragma_Arg (Arg1));
370          end;
371       end if;
372
373       --  Remove the subprogram from the scope stack now that the pre-analysis
374       --  of the precondition/postcondition is done.
375
376       End_Scope;
377    end Analyze_PPC_In_Decl_Part;
378
379    --------------------
380    -- Analyze_Pragma --
381    --------------------
382
383    procedure Analyze_Pragma (N : Node_Id) is
384       Loc     : constant Source_Ptr := Sloc (N);
385       Prag_Id : Pragma_Id;
386
387       Pname : Name_Id;
388       --  Name of the source pragma, or name of the corresponding aspect for
389       --  pragmas which originate in a source aspect. In the latter case, the
390       --  name may be different from the pragma name.
391
392       Pragma_Exit : exception;
393       --  This exception is used to exit pragma processing completely. It is
394       --  used when an error is detected, and no further processing is
395       --  required. It is also used if an earlier error has left the tree in
396       --  a state where the pragma should not be processed.
397
398       Arg_Count : Nat;
399       --  Number of pragma argument associations
400
401       Arg1 : Node_Id;
402       Arg2 : Node_Id;
403       Arg3 : Node_Id;
404       Arg4 : Node_Id;
405       --  First four pragma arguments (pragma argument association nodes, or
406       --  Empty if the corresponding argument does not exist).
407
408       type Name_List is array (Natural range <>) of Name_Id;
409       type Args_List is array (Natural range <>) of Node_Id;
410       --  Types used for arguments to Check_Arg_Order and Gather_Associations
411
412       procedure Ada_2005_Pragma;
413       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414       --  Ada 95 mode, these are implementation defined pragmas, so should be
415       --  caught by the No_Implementation_Pragmas restriction.
416
417       procedure Ada_2012_Pragma;
418       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
420       --  should be caught by the No_Implementation_Pragmas restriction.
421
422       procedure Check_Ada_83_Warning;
423       --  Issues a warning message for the current pragma if operating in Ada
424       --  83 mode (used for language pragmas that are not a standard part of
425       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
426       --  of 95 pragma.
427
428       procedure Check_Arg_Count (Required : Nat);
429       --  Check argument count for pragma is equal to given parameter. If not,
430       --  then issue an error message and raise Pragma_Exit.
431
432       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
433       --  Arg which can either be a pragma argument association, in which case
434       --  the check is applied to the expression of the association or an
435       --  expression directly.
436
437       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438       --  Check that an argument has the right form for an EXTERNAL_NAME
439       --  parameter of an extended import/export pragma. The rule is that the
440       --  name must be an identifier or string literal (in Ada 83 mode) or a
441       --  static string expression (in Ada 95 mode).
442
443       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444       --  Check the specified argument Arg to make sure that it is an
445       --  identifier. If not give error and raise Pragma_Exit.
446
447       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
448       --  Check the specified argument Arg to make sure that it is an integer
449       --  literal. If not give error and raise Pragma_Exit.
450
451       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
452       --  Check the specified argument Arg to make sure that it has the proper
453       --  syntactic form for a local name and meets the semantic requirements
454       --  for a local name. The local name is analyzed as part of the
455       --  processing for this call. In addition, the local name is required
456       --  to represent an entity at the library level.
457
458       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
459       --  Check the specified argument Arg to make sure that it has the proper
460       --  syntactic form for a local name and meets the semantic requirements
461       --  for a local name. The local name is analyzed as part of the
462       --  processing for this call.
463
464       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465       --  Check the specified argument Arg to make sure that it is a valid
466       --  locking policy name. If not give error and raise Pragma_Exit.
467
468       procedure Check_Arg_Is_One_Of
469         (Arg                : Node_Id;
470          N1, N2             : Name_Id);
471       procedure Check_Arg_Is_One_Of
472         (Arg                : Node_Id;
473          N1, N2, N3         : Name_Id);
474       procedure Check_Arg_Is_One_Of
475         (Arg                : Node_Id;
476          N1, N2, N3, N4, N5 : Name_Id);
477       --  Check the specified argument Arg to make sure that it is an
478       --  identifier whose name matches either N1 or N2 (or N3, N4, N5 if
479       --  present). If not then give error and raise Pragma_Exit.
480
481       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
482       --  Check the specified argument Arg to make sure that it is a valid
483       --  queuing policy name. If not give error and raise Pragma_Exit.
484
485       procedure Check_Arg_Is_Static_Expression
486         (Arg : Node_Id;
487          Typ : Entity_Id := Empty);
488       --  Check the specified argument Arg to make sure that it is a static
489       --  expression of the given type (i.e. it will be analyzed and resolved
490       --  using this type, which can be any valid argument to Resolve, e.g.
491       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
492       --  Typ is left Empty, then any static expression is allowed.
493
494       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
495       --  Check the specified argument Arg to make sure that it is a valid task
496       --  dispatching policy name. If not give error and raise Pragma_Exit.
497
498       procedure Check_Arg_Order (Names : Name_List);
499       --  Checks for an instance of two arguments with identifiers for the
500       --  current pragma which are not in the sequence indicated by Names,
501       --  and if so, generates a fatal message about bad order of arguments.
502
503       procedure Check_At_Least_N_Arguments (N : Nat);
504       --  Check there are at least N arguments present
505
506       procedure Check_At_Most_N_Arguments (N : Nat);
507       --  Check there are no more than N arguments present
508
509       procedure Check_Component
510         (Comp            : Node_Id;
511          UU_Typ          : Entity_Id;
512          In_Variant_Part : Boolean := False);
513       --  Examine an Unchecked_Union component for correct use of per-object
514       --  constrained subtypes, and for restrictions on finalizable components.
515       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
516       --  should be set when Comp comes from a record variant.
517
518       procedure Check_Duplicate_Pragma (E : Entity_Id);
519       --  Check if a pragma of the same name as the current pragma is already
520       --  chained as a rep pragma to the given entity. If so give a message
521       --  about the duplicate, and then raise Pragma_Exit so does not return.
522       --  Also checks for delayed aspect specification node in the chain.
523
524       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
525       --  Nam is an N_String_Literal node containing the external name set by
526       --  an Import or Export pragma (or extended Import or Export pragma).
527       --  This procedure checks for possible duplications if this is the export
528       --  case, and if found, issues an appropriate error message.
529
530       procedure Check_Expr_Is_Static_Expression
531         (Expr : Node_Id;
532          Typ  : Entity_Id := Empty);
533       --  Check the specified expression Expr to make sure that it is a static
534       --  expression of the given type (i.e. it will be analyzed and resolved
535       --  using this type, which can be any valid argument to Resolve, e.g.
536       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
537       --  Typ is left Empty, then any static expression is allowed.
538
539       procedure Check_First_Subtype (Arg : Node_Id);
540       --  Checks that Arg, whose expression is an entity name, references a
541       --  first subtype.
542
543       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
544       --  Checks that the given argument has an identifier, and if so, requires
545       --  it to match the given identifier name. If there is no identifier, or
546       --  a non-matching identifier, then an error message is given and
547       --  Pragma_Exit is raised.
548
549       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
550       --  Checks that the given argument has an identifier, and if so, requires
551       --  it to match one of the given identifier names. If there is no
552       --  identifier, or a non-matching identifier, then an error message is
553       --  given and Pragma_Exit is raised.
554
555       procedure Check_In_Main_Program;
556       --  Common checks for pragmas that appear within a main program
557       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
558
559       procedure Check_Interrupt_Or_Attach_Handler;
560       --  Common processing for first argument of pragma Interrupt_Handler or
561       --  pragma Attach_Handler.
562
563       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
564       --  Check that pragma appears in a declarative part, or in a package
565       --  specification, i.e. that it does not occur in a statement sequence
566       --  in a body.
567
568       procedure Check_No_Identifier (Arg : Node_Id);
569       --  Checks that the given argument does not have an identifier. If
570       --  an identifier is present, then an error message is issued, and
571       --  Pragma_Exit is raised.
572
573       procedure Check_No_Identifiers;
574       --  Checks that none of the arguments to the pragma has an identifier.
575       --  If any argument has an identifier, then an error message is issued,
576       --  and Pragma_Exit is raised.
577
578       procedure Check_No_Link_Name;
579       --  Checks that no link name is specified
580
581       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
582       --  Checks if the given argument has an identifier, and if so, requires
583       --  it to match the given identifier name. If there is a non-matching
584       --  identifier, then an error message is given and Pragma_Exit is raised.
585
586       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
587       --  Checks if the given argument has an identifier, and if so, requires
588       --  it to match the given identifier name. If there is a non-matching
589       --  identifier, then an error message is given and Pragma_Exit is raised.
590       --  In this version of the procedure, the identifier name is given as
591       --  a string with lower case letters.
592
593       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
594       --  Called to process a precondition or postcondition pragma. There are
595       --  three cases:
596       --
597       --    The pragma appears after a subprogram spec
598       --
599       --      If the corresponding check is not enabled, the pragma is analyzed
600       --      but otherwise ignored and control returns with In_Body set False.
601       --
602       --      If the check is enabled, then the first step is to analyze the
603       --      pragma, but this is skipped if the subprogram spec appears within
604       --      a package specification (because this is the case where we delay
605       --      analysis till the end of the spec). Then (whether or not it was
606       --      analyzed), the pragma is chained to the subprogram in question
607       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
608       --      caller with In_Body set False.
609       --
610       --    The pragma appears at the start of subprogram body declarations
611       --
612       --      In this case an immediate return to the caller is made with
613       --      In_Body set True, and the pragma is NOT analyzed.
614       --
615       --    In all other cases, an error message for bad placement is given
616
617       procedure Check_Static_Constraint (Constr : Node_Id);
618       --  Constr is a constraint from an N_Subtype_Indication node from a
619       --  component constraint in an Unchecked_Union type. This routine checks
620       --  that the constraint is static as required by the restrictions for
621       --  Unchecked_Union.
622
623       procedure Check_Test_Case;
624       --  Called to process a test-case pragma. The treatment is similar to the
625       --  one for pre- and postcondition in Check_Precondition_Postcondition,
626       --  except the placement rules for the test-case pragma are stricter.
627       --  This pragma may only occur after a subprogram spec declared directly
628       --  in a package spec unit. In this case, the pragma is chained to the
629       --  subprogram in question (using Spec_TC_List and Next_Pragma) and
630       --  analysis of the pragma is delayed till the end of the spec. In
631       --  all other cases, an error message for bad placement is given.
632
633       procedure Check_Valid_Configuration_Pragma;
634       --  Legality checks for placement of a configuration pragma
635
636       procedure Check_Valid_Library_Unit_Pragma;
637       --  Legality checks for library unit pragmas. A special case arises for
638       --  pragmas in generic instances that come from copies of the original
639       --  library unit pragmas in the generic templates. In the case of other
640       --  than library level instantiations these can appear in contexts which
641       --  would normally be invalid (they only apply to the original template
642       --  and to library level instantiations), and they are simply ignored,
643       --  which is implemented by rewriting them as null statements.
644
645       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
646       --  Check an Unchecked_Union variant for lack of nested variants and
647       --  presence of at least one component. UU_Typ is the related Unchecked_
648       --  Union type.
649
650       procedure Error_Pragma (Msg : String);
651       pragma No_Return (Error_Pragma);
652       --  Outputs error message for current pragma. The message contains a %
653       --  that will be replaced with the pragma name, and the flag is placed
654       --  on the pragma itself. Pragma_Exit is then raised.
655
656       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
657       pragma No_Return (Error_Pragma_Arg);
658       --  Outputs error message for current pragma. The message may contain
659       --  a % that will be replaced with the pragma name. The parameter Arg
660       --  may either be a pragma argument association, in which case the flag
661       --  is placed on the expression of this association, or an expression,
662       --  in which case the flag is placed directly on the expression. The
663       --  message is placed using Error_Msg_N, so the message may also contain
664       --  an & insertion character which will reference the given Arg value.
665       --  After placing the message, Pragma_Exit is raised.
666
667       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
668       pragma No_Return (Error_Pragma_Arg);
669       --  Similar to above form of Error_Pragma_Arg except that two messages
670       --  are provided, the second is a continuation comment starting with \.
671
672       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
673       pragma No_Return (Error_Pragma_Arg_Ident);
674       --  Outputs error message for current pragma. The message may contain
675       --  a % that will be replaced with the pragma name. The parameter Arg
676       --  must be a pragma argument association with a non-empty identifier
677       --  (i.e. its Chars field must be set), and the error message is placed
678       --  on the identifier. The message is placed using Error_Msg_N so
679       --  the message may also contain an & insertion character which will
680       --  reference the identifier. After placing the message, Pragma_Exit
681       --  is raised.
682
683       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
684       pragma No_Return (Error_Pragma_Ref);
685       --  Outputs error message for current pragma. The message may contain
686       --  a % that will be replaced with the pragma name. The parameter Ref
687       --  must be an entity whose name can be referenced by & and sloc by #.
688       --  After placing the message, Pragma_Exit is raised.
689
690       function Find_Lib_Unit_Name return Entity_Id;
691       --  Used for a library unit pragma to find the entity to which the
692       --  library unit pragma applies, returns the entity found.
693
694       procedure Find_Program_Unit_Name (Id : Node_Id);
695       --  If the pragma is a compilation unit pragma, the id must denote the
696       --  compilation unit in the same compilation, and the pragma must appear
697       --  in the list of preceding or trailing pragmas. If it is a program
698       --  unit pragma that is not a compilation unit pragma, then the
699       --  identifier must be visible.
700
701       function Find_Unique_Parameterless_Procedure
702         (Name : Entity_Id;
703          Arg  : Node_Id) return Entity_Id;
704       --  Used for a procedure pragma to find the unique parameterless
705       --  procedure identified by Name, returns it if it exists, otherwise
706       --  errors out and uses Arg as the pragma argument for the message.
707
708       procedure Fix_Error (Msg : in out String);
709       --  This is called prior to issuing an error message. Msg is a string
710       --  which typically contains the substring pragma. If the current pragma
711       --  comes from an aspect, each such "pragma" substring is replaced with
712       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
713       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
714
715       procedure Gather_Associations
716         (Names : Name_List;
717          Args  : out Args_List);
718       --  This procedure is used to gather the arguments for a pragma that
719       --  permits arbitrary ordering of parameters using the normal rules
720       --  for named and positional parameters. The Names argument is a list
721       --  of Name_Id values that corresponds to the allowed pragma argument
722       --  association identifiers in order. The result returned in Args is
723       --  a list of corresponding expressions that are the pragma arguments.
724       --  Note that this is a list of expressions, not of pragma argument
725       --  associations (Gather_Associations has completely checked all the
726       --  optional identifiers when it returns). An entry in Args is Empty
727       --  on return if the corresponding argument is not present.
728
729       procedure GNAT_Pragma;
730       --  Called for all GNAT defined pragmas to check the relevant restriction
731       --  (No_Implementation_Pragmas).
732
733       function Is_Before_First_Decl
734         (Pragma_Node : Node_Id;
735          Decls       : List_Id) return Boolean;
736       --  Return True if Pragma_Node is before the first declarative item in
737       --  Decls where Decls is the list of declarative items.
738
739       function Is_Configuration_Pragma return Boolean;
740       --  Determines if the placement of the current pragma is appropriate
741       --  for a configuration pragma.
742
743       function Is_In_Context_Clause return Boolean;
744       --  Returns True if pragma appears within the context clause of a unit,
745       --  and False for any other placement (does not generate any messages).
746
747       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
748       --  Analyzes the argument, and determines if it is a static string
749       --  expression, returns True if so, False if non-static or not String.
750
751       procedure Pragma_Misplaced;
752       pragma No_Return (Pragma_Misplaced);
753       --  Issue fatal error message for misplaced pragma
754
755       procedure Process_Atomic_Shared_Volatile;
756       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
757       --  Shared is an obsolete Ada 83 pragma, treated as being identical
758       --  in effect to pragma Atomic.
759
760       procedure Process_Compile_Time_Warning_Or_Error;
761       --  Common processing for Compile_Time_Error and Compile_Time_Warning
762
763       procedure Process_Convention
764         (C   : out Convention_Id;
765          Ent : out Entity_Id);
766       --  Common processing for Convention, Interface, Import and Export.
767       --  Checks first two arguments of pragma, and sets the appropriate
768       --  convention value in the specified entity or entities. On return
769       --  C is the convention, Ent is the referenced entity.
770
771       procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
772       --  Common processing for Disable/Enable_Atomic_Synchronization. Nam is
773       --  Name_Suppress for Disable and Name_Unsuppress for Enable.
774
775       procedure Process_Extended_Import_Export_Exception_Pragma
776         (Arg_Internal : Node_Id;
777          Arg_External : Node_Id;
778          Arg_Form     : Node_Id;
779          Arg_Code     : Node_Id);
780       --  Common processing for the pragmas Import/Export_Exception. The three
781       --  arguments correspond to the three named parameters of the pragma. An
782       --  argument is empty if the corresponding parameter is not present in
783       --  the pragma.
784
785       procedure Process_Extended_Import_Export_Object_Pragma
786         (Arg_Internal : Node_Id;
787          Arg_External : Node_Id;
788          Arg_Size     : Node_Id);
789       --  Common processing for the pragmas Import/Export_Object. The three
790       --  arguments correspond to the three named parameters of the pragmas. An
791       --  argument is empty if the corresponding parameter is not present in
792       --  the pragma.
793
794       procedure Process_Extended_Import_Export_Internal_Arg
795         (Arg_Internal : Node_Id := Empty);
796       --  Common processing for all extended Import and Export pragmas. The
797       --  argument is the pragma parameter for the Internal argument. If
798       --  Arg_Internal is empty or inappropriate, an error message is posted.
799       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
800       --  set to identify the referenced entity.
801
802       procedure Process_Extended_Import_Export_Subprogram_Pragma
803         (Arg_Internal                 : Node_Id;
804          Arg_External                 : Node_Id;
805          Arg_Parameter_Types          : Node_Id;
806          Arg_Result_Type              : Node_Id := Empty;
807          Arg_Mechanism                : Node_Id;
808          Arg_Result_Mechanism         : Node_Id := Empty;
809          Arg_First_Optional_Parameter : Node_Id := Empty);
810       --  Common processing for all extended Import and Export pragmas applying
811       --  to subprograms. The caller omits any arguments that do not apply to
812       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
813       --  only in the Import_Function and Export_Function cases). The argument
814       --  names correspond to the allowed pragma association identifiers.
815
816       procedure Process_Generic_List;
817       --  Common processing for Share_Generic and Inline_Generic
818
819       procedure Process_Import_Or_Interface;
820       --  Common processing for Import of Interface
821
822       procedure Process_Import_Predefined_Type;
823       --  Processing for completing a type with pragma Import. This is used
824       --  to declare types that match predefined C types, especially for cases
825       --  without corresponding Ada predefined type.
826
827       procedure Process_Inline (Active : Boolean);
828       --  Common processing for Inline and Inline_Always. The parameter
829       --  indicates if the inline pragma is active, i.e. if it should actually
830       --  cause inlining to occur.
831
832       procedure Process_Interface_Name
833         (Subprogram_Def : Entity_Id;
834          Ext_Arg        : Node_Id;
835          Link_Arg       : Node_Id);
836       --  Given the last two arguments of pragma Import, pragma Export, or
837       --  pragma Interface_Name, performs validity checks and sets the
838       --  Interface_Name field of the given subprogram entity to the
839       --  appropriate external or link name, depending on the arguments given.
840       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
841       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
842       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
843       --  nor Link_Arg is present, the interface name is set to the default
844       --  from the subprogram name.
845
846       procedure Process_Interrupt_Or_Attach_Handler;
847       --  Common processing for Interrupt and Attach_Handler pragmas
848
849       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
850       --  Common processing for Restrictions and Restriction_Warnings pragmas.
851       --  Warn is True for Restriction_Warnings, or for Restrictions if the
852       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
853       --  is not set in the Restrictions case.
854
855       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
856       --  Common processing for Suppress and Unsuppress. The boolean parameter
857       --  Suppress_Case is True for the Suppress case, and False for the
858       --  Unsuppress case.
859
860       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
861       --  This procedure sets the Is_Exported flag for the given entity,
862       --  checking that the entity was not previously imported. Arg is
863       --  the argument that specified the entity. A check is also made
864       --  for exporting inappropriate entities.
865
866       procedure Set_Extended_Import_Export_External_Name
867         (Internal_Ent : Entity_Id;
868          Arg_External : Node_Id);
869       --  Common processing for all extended import export pragmas. The first
870       --  argument, Internal_Ent, is the internal entity, which has already
871       --  been checked for validity by the caller. Arg_External is from the
872       --  Import or Export pragma, and may be null if no External parameter
873       --  was present. If Arg_External is present and is a non-null string
874       --  (a null string is treated as the default), then the Interface_Name
875       --  field of Internal_Ent is set appropriately.
876
877       procedure Set_Imported (E : Entity_Id);
878       --  This procedure sets the Is_Imported flag for the given entity,
879       --  checking that it is not previously exported or imported.
880
881       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
882       --  Mech is a parameter passing mechanism (see Import_Function syntax
883       --  for MECHANISM_NAME). This routine checks that the mechanism argument
884       --  has the right form, and if not issues an error message. If the
885       --  argument has the right form then the Mechanism field of Ent is
886       --  set appropriately.
887
888       procedure Set_Ravenscar_Profile (N : Node_Id);
889       --  Activate the set of configuration pragmas and restrictions that make
890       --  up the Ravenscar Profile. N is the corresponding pragma node, which
891       --  is used for error messages on any constructs that violate the
892       --  profile.
893
894       ---------------------
895       -- Ada_2005_Pragma --
896       ---------------------
897
898       procedure Ada_2005_Pragma is
899       begin
900          if Ada_Version <= Ada_95 then
901             Check_Restriction (No_Implementation_Pragmas, N);
902          end if;
903       end Ada_2005_Pragma;
904
905       ---------------------
906       -- Ada_2012_Pragma --
907       ---------------------
908
909       procedure Ada_2012_Pragma is
910       begin
911          if Ada_Version <= Ada_2005 then
912             Check_Restriction (No_Implementation_Pragmas, N);
913          end if;
914       end Ada_2012_Pragma;
915
916       --------------------------
917       -- Check_Ada_83_Warning --
918       --------------------------
919
920       procedure Check_Ada_83_Warning is
921       begin
922          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
923             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
924          end if;
925       end Check_Ada_83_Warning;
926
927       ---------------------
928       -- Check_Arg_Count --
929       ---------------------
930
931       procedure Check_Arg_Count (Required : Nat) is
932       begin
933          if Arg_Count /= Required then
934             Error_Pragma ("wrong number of arguments for pragma%");
935          end if;
936       end Check_Arg_Count;
937
938       --------------------------------
939       -- Check_Arg_Is_External_Name --
940       --------------------------------
941
942       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
943          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
944
945       begin
946          if Nkind (Argx) = N_Identifier then
947             return;
948
949          else
950             Analyze_And_Resolve (Argx, Standard_String);
951
952             if Is_OK_Static_Expression (Argx) then
953                return;
954
955             elsif Etype (Argx) = Any_Type then
956                raise Pragma_Exit;
957
958             --  An interesting special case, if we have a string literal and
959             --  we are in Ada 83 mode, then we allow it even though it will
960             --  not be flagged as static. This allows expected Ada 83 mode
961             --  use of external names which are string literals, even though
962             --  technically these are not static in Ada 83.
963
964             elsif Ada_Version = Ada_83
965               and then Nkind (Argx) = N_String_Literal
966             then
967                return;
968
969             --  Static expression that raises Constraint_Error. This has
970             --  already been flagged, so just exit from pragma processing.
971
972             elsif Is_Static_Expression (Argx) then
973                raise Pragma_Exit;
974
975             --  Here we have a real error (non-static expression)
976
977             else
978                Error_Msg_Name_1 := Pname;
979
980                declare
981                   Msg : String :=
982                           "argument for pragma% must be a identifier or "
983                           & "static string expression!";
984                begin
985                   Fix_Error (Msg);
986                   Flag_Non_Static_Expr (Msg, Argx);
987                   raise Pragma_Exit;
988                end;
989             end if;
990          end if;
991       end Check_Arg_Is_External_Name;
992
993       -----------------------------
994       -- Check_Arg_Is_Identifier --
995       -----------------------------
996
997       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
998          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
999       begin
1000          if Nkind (Argx) /= N_Identifier then
1001             Error_Pragma_Arg
1002               ("argument for pragma% must be identifier", Argx);
1003          end if;
1004       end Check_Arg_Is_Identifier;
1005
1006       ----------------------------------
1007       -- Check_Arg_Is_Integer_Literal --
1008       ----------------------------------
1009
1010       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1011          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1012       begin
1013          if Nkind (Argx) /= N_Integer_Literal then
1014             Error_Pragma_Arg
1015               ("argument for pragma% must be integer literal", Argx);
1016          end if;
1017       end Check_Arg_Is_Integer_Literal;
1018
1019       -------------------------------------------
1020       -- Check_Arg_Is_Library_Level_Local_Name --
1021       -------------------------------------------
1022
1023       --  LOCAL_NAME ::=
1024       --    DIRECT_NAME
1025       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1026       --  | library_unit_NAME
1027
1028       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1029       begin
1030          Check_Arg_Is_Local_Name (Arg);
1031
1032          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1033            and then Comes_From_Source (N)
1034          then
1035             Error_Pragma_Arg
1036               ("argument for pragma% must be library level entity", Arg);
1037          end if;
1038       end Check_Arg_Is_Library_Level_Local_Name;
1039
1040       -----------------------------
1041       -- Check_Arg_Is_Local_Name --
1042       -----------------------------
1043
1044       --  LOCAL_NAME ::=
1045       --    DIRECT_NAME
1046       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1047       --  | library_unit_NAME
1048
1049       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1050          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1051
1052       begin
1053          Analyze (Argx);
1054
1055          if Nkind (Argx) not in N_Direct_Name
1056            and then (Nkind (Argx) /= N_Attribute_Reference
1057                       or else Present (Expressions (Argx))
1058                       or else Nkind (Prefix (Argx)) /= N_Identifier)
1059            and then (not Is_Entity_Name (Argx)
1060                       or else not Is_Compilation_Unit (Entity (Argx)))
1061          then
1062             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1063          end if;
1064
1065          --  No further check required if not an entity name
1066
1067          if not Is_Entity_Name (Argx) then
1068             null;
1069
1070          else
1071             declare
1072                OK   : Boolean;
1073                Ent  : constant Entity_Id := Entity (Argx);
1074                Scop : constant Entity_Id := Scope (Ent);
1075             begin
1076                --  Case of a pragma applied to a compilation unit: pragma must
1077                --  occur immediately after the program unit in the compilation.
1078
1079                if Is_Compilation_Unit (Ent) then
1080                   declare
1081                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1082
1083                   begin
1084                      --  Case of pragma placed immediately after spec
1085
1086                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1087                         OK := True;
1088
1089                      --  Case of pragma placed immediately after body
1090
1091                      elsif Nkind (Decl) = N_Subprogram_Declaration
1092                              and then Present (Corresponding_Body (Decl))
1093                      then
1094                         OK := Parent (N) =
1095                                 Aux_Decls_Node
1096                                   (Parent (Unit_Declaration_Node
1097                                              (Corresponding_Body (Decl))));
1098
1099                      --  All other cases are illegal
1100
1101                      else
1102                         OK := False;
1103                      end if;
1104                   end;
1105
1106                --  Special restricted placement rule from 10.2.1(11.8/2)
1107
1108                elsif Is_Generic_Formal (Ent)
1109                        and then Prag_Id = Pragma_Preelaborable_Initialization
1110                then
1111                   OK := List_Containing (N) =
1112                           Generic_Formal_Declarations
1113                             (Unit_Declaration_Node (Scop));
1114
1115                --  Default case, just check that the pragma occurs in the scope
1116                --  of the entity denoted by the name.
1117
1118                else
1119                   OK := Current_Scope = Scop;
1120                end if;
1121
1122                if not OK then
1123                   Error_Pragma_Arg
1124                     ("pragma% argument must be in same declarative part", Arg);
1125                end if;
1126             end;
1127          end if;
1128       end Check_Arg_Is_Local_Name;
1129
1130       ---------------------------------
1131       -- Check_Arg_Is_Locking_Policy --
1132       ---------------------------------
1133
1134       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1135          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1136
1137       begin
1138          Check_Arg_Is_Identifier (Argx);
1139
1140          if not Is_Locking_Policy_Name (Chars (Argx)) then
1141             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1142          end if;
1143       end Check_Arg_Is_Locking_Policy;
1144
1145       -------------------------
1146       -- Check_Arg_Is_One_Of --
1147       -------------------------
1148
1149       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1150          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1151
1152       begin
1153          Check_Arg_Is_Identifier (Argx);
1154
1155          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1156             Error_Msg_Name_2 := N1;
1157             Error_Msg_Name_3 := N2;
1158             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1159          end if;
1160       end Check_Arg_Is_One_Of;
1161
1162       procedure Check_Arg_Is_One_Of
1163         (Arg        : Node_Id;
1164          N1, N2, N3 : Name_Id)
1165       is
1166          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1167
1168       begin
1169          Check_Arg_Is_Identifier (Argx);
1170
1171          if Chars (Argx) /= N1
1172            and then Chars (Argx) /= N2
1173            and then Chars (Argx) /= N3
1174          then
1175             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1176          end if;
1177       end Check_Arg_Is_One_Of;
1178
1179       procedure Check_Arg_Is_One_Of
1180         (Arg                : Node_Id;
1181          N1, N2, N3, N4, N5 : Name_Id)
1182       is
1183          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1184
1185       begin
1186          Check_Arg_Is_Identifier (Argx);
1187
1188          if Chars (Argx) /= N1
1189            and then Chars (Argx) /= N2
1190            and then Chars (Argx) /= N3
1191            and then Chars (Argx) /= N4
1192            and then Chars (Argx) /= N5
1193          then
1194             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1195          end if;
1196       end Check_Arg_Is_One_Of;
1197       ---------------------------------
1198       -- Check_Arg_Is_Queuing_Policy --
1199       ---------------------------------
1200
1201       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1202          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1203
1204       begin
1205          Check_Arg_Is_Identifier (Argx);
1206
1207          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1208             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1209          end if;
1210       end Check_Arg_Is_Queuing_Policy;
1211
1212       ------------------------------------
1213       -- Check_Arg_Is_Static_Expression --
1214       ------------------------------------
1215
1216       procedure Check_Arg_Is_Static_Expression
1217         (Arg : Node_Id;
1218          Typ : Entity_Id := Empty)
1219       is
1220       begin
1221          Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1222       end Check_Arg_Is_Static_Expression;
1223
1224       ------------------------------------------
1225       -- Check_Arg_Is_Task_Dispatching_Policy --
1226       ------------------------------------------
1227
1228       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1229          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1230
1231       begin
1232          Check_Arg_Is_Identifier (Argx);
1233
1234          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1235             Error_Pragma_Arg
1236               ("& is not a valid task dispatching policy name", Argx);
1237          end if;
1238       end Check_Arg_Is_Task_Dispatching_Policy;
1239
1240       ---------------------
1241       -- Check_Arg_Order --
1242       ---------------------
1243
1244       procedure Check_Arg_Order (Names : Name_List) is
1245          Arg : Node_Id;
1246
1247          Highest_So_Far : Natural := 0;
1248          --  Highest index in Names seen do far
1249
1250       begin
1251          Arg := Arg1;
1252          for J in 1 .. Arg_Count loop
1253             if Chars (Arg) /= No_Name then
1254                for K in Names'Range loop
1255                   if Chars (Arg) = Names (K) then
1256                      if K < Highest_So_Far then
1257                         Error_Msg_Name_1 := Pname;
1258                         Error_Msg_N
1259                           ("parameters out of order for pragma%", Arg);
1260                         Error_Msg_Name_1 := Names (K);
1261                         Error_Msg_Name_2 := Names (Highest_So_Far);
1262                         Error_Msg_N ("\% must appear before %", Arg);
1263                         raise Pragma_Exit;
1264
1265                      else
1266                         Highest_So_Far := K;
1267                      end if;
1268                   end if;
1269                end loop;
1270             end if;
1271
1272             Arg := Next (Arg);
1273          end loop;
1274       end Check_Arg_Order;
1275
1276       --------------------------------
1277       -- Check_At_Least_N_Arguments --
1278       --------------------------------
1279
1280       procedure Check_At_Least_N_Arguments (N : Nat) is
1281       begin
1282          if Arg_Count < N then
1283             Error_Pragma ("too few arguments for pragma%");
1284          end if;
1285       end Check_At_Least_N_Arguments;
1286
1287       -------------------------------
1288       -- Check_At_Most_N_Arguments --
1289       -------------------------------
1290
1291       procedure Check_At_Most_N_Arguments (N : Nat) is
1292          Arg : Node_Id;
1293       begin
1294          if Arg_Count > N then
1295             Arg := Arg1;
1296             for J in 1 .. N loop
1297                Next (Arg);
1298                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1299             end loop;
1300          end if;
1301       end Check_At_Most_N_Arguments;
1302
1303       ---------------------
1304       -- Check_Component --
1305       ---------------------
1306
1307       procedure Check_Component
1308         (Comp            : Node_Id;
1309          UU_Typ          : Entity_Id;
1310          In_Variant_Part : Boolean := False)
1311       is
1312          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1313          Sindic  : constant Node_Id :=
1314                      Subtype_Indication (Component_Definition (Comp));
1315          Typ     : constant Entity_Id := Etype (Comp_Id);
1316
1317          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1318          --  Determine whether entity Id appears inside a generic body.
1319          --  Shouldn't this be in a more general place ???
1320
1321          -------------------------
1322          -- Inside_Generic_Body --
1323          -------------------------
1324
1325          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1326             S : Entity_Id;
1327
1328          begin
1329             S := Id;
1330             while Present (S) and then S /= Standard_Standard loop
1331                if Ekind (S) = E_Generic_Package
1332                  and then In_Package_Body (S)
1333                then
1334                   return True;
1335                end if;
1336
1337                S := Scope (S);
1338             end loop;
1339
1340             return False;
1341          end Inside_Generic_Body;
1342
1343       --  Start of processing for Check_Component
1344
1345       begin
1346          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1347          --  object constraint, then the component type shall be an Unchecked_
1348          --  Union.
1349
1350          if Nkind (Sindic) = N_Subtype_Indication
1351            and then Has_Per_Object_Constraint (Comp_Id)
1352            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1353          then
1354             Error_Msg_N
1355               ("component subtype subject to per-object constraint " &
1356                "must be an Unchecked_Union", Comp);
1357
1358          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1359          --  the body of a generic unit, or within the body of any of its
1360          --  descendant library units, no part of the type of a component
1361          --  declared in a variant_part of the unchecked union type shall be of
1362          --  a formal private type or formal private extension declared within
1363          --  the formal part of the generic unit.
1364
1365          elsif Ada_Version >= Ada_2012
1366            and then Inside_Generic_Body (UU_Typ)
1367            and then In_Variant_Part
1368            and then Is_Private_Type (Typ)
1369            and then Is_Generic_Type (Typ)
1370          then
1371             Error_Msg_N
1372               ("component of Unchecked_Union cannot be of generic type", Comp);
1373
1374          elsif Needs_Finalization (Typ) then
1375             Error_Msg_N
1376               ("component of Unchecked_Union cannot be controlled", Comp);
1377
1378          elsif Has_Task (Typ) then
1379             Error_Msg_N
1380               ("component of Unchecked_Union cannot have tasks", Comp);
1381          end if;
1382       end Check_Component;
1383
1384       ----------------------------
1385       -- Check_Duplicate_Pragma --
1386       ----------------------------
1387
1388       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1389          P : Node_Id;
1390
1391       begin
1392          --  Nothing to do if this pragma comes from an aspect specification,
1393          --  since we could not be duplicating a pragma, and we dealt with the
1394          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1395
1396          if From_Aspect_Specification (N) then
1397             return;
1398          end if;
1399
1400          --  Otherwise current pragma may duplicate previous pragma or a
1401          --  previously given aspect specification for the same pragma.
1402
1403          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1404
1405          if Present (P) then
1406             Error_Msg_Name_1 := Pragma_Name (N);
1407             Error_Msg_Sloc := Sloc (P);
1408
1409             if Nkind (P) = N_Aspect_Specification
1410               or else From_Aspect_Specification (P)
1411             then
1412                Error_Msg_NE ("aspect% for & previously given#", N, E);
1413             else
1414                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1415             end if;
1416
1417             raise Pragma_Exit;
1418          end if;
1419       end Check_Duplicate_Pragma;
1420
1421       ----------------------------------
1422       -- Check_Duplicated_Export_Name --
1423       ----------------------------------
1424
1425       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1426          String_Val : constant String_Id := Strval (Nam);
1427
1428       begin
1429          --  We are only interested in the export case, and in the case of
1430          --  generics, it is the instance, not the template, that is the
1431          --  problem (the template will generate a warning in any case).
1432
1433          if not Inside_A_Generic
1434            and then (Prag_Id = Pragma_Export
1435                        or else
1436                      Prag_Id = Pragma_Export_Procedure
1437                        or else
1438                      Prag_Id = Pragma_Export_Valued_Procedure
1439                        or else
1440                      Prag_Id = Pragma_Export_Function)
1441          then
1442             for J in Externals.First .. Externals.Last loop
1443                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1444                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1445                   Error_Msg_N ("external name duplicates name given#", Nam);
1446                   exit;
1447                end if;
1448             end loop;
1449
1450             Externals.Append (Nam);
1451          end if;
1452       end Check_Duplicated_Export_Name;
1453
1454       -------------------------------------
1455       -- Check_Expr_Is_Static_Expression --
1456       -------------------------------------
1457
1458       procedure Check_Expr_Is_Static_Expression
1459         (Expr : Node_Id;
1460          Typ  : Entity_Id := Empty)
1461       is
1462       begin
1463          if Present (Typ) then
1464             Analyze_And_Resolve (Expr, Typ);
1465          else
1466             Analyze_And_Resolve (Expr);
1467          end if;
1468
1469          if Is_OK_Static_Expression (Expr) then
1470             return;
1471
1472          elsif Etype (Expr) = Any_Type then
1473             raise Pragma_Exit;
1474
1475          --  An interesting special case, if we have a string literal and we
1476          --  are in Ada 83 mode, then we allow it even though it will not be
1477          --  flagged as static. This allows the use of Ada 95 pragmas like
1478          --  Import in Ada 83 mode. They will of course be flagged with
1479          --  warnings as usual, but will not cause errors.
1480
1481          elsif Ada_Version = Ada_83
1482            and then Nkind (Expr) = N_String_Literal
1483          then
1484             return;
1485
1486          --  Static expression that raises Constraint_Error. This has already
1487          --  been flagged, so just exit from pragma processing.
1488
1489          elsif Is_Static_Expression (Expr) then
1490             raise Pragma_Exit;
1491
1492          --  Finally, we have a real error
1493
1494          else
1495             Error_Msg_Name_1 := Pname;
1496
1497             declare
1498                Msg : String :=
1499                        "argument for pragma% must be a static expression!";
1500             begin
1501                Fix_Error (Msg);
1502                Flag_Non_Static_Expr (Msg, Expr);
1503             end;
1504
1505             raise Pragma_Exit;
1506          end if;
1507       end Check_Expr_Is_Static_Expression;
1508
1509       -------------------------
1510       -- Check_First_Subtype --
1511       -------------------------
1512
1513       procedure Check_First_Subtype (Arg : Node_Id) is
1514          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1515          Ent  : constant Entity_Id := Entity (Argx);
1516
1517       begin
1518          if Is_First_Subtype (Ent) then
1519             null;
1520
1521          elsif Is_Type (Ent) then
1522             Error_Pragma_Arg
1523               ("pragma% cannot apply to subtype", Argx);
1524
1525          elsif Is_Object (Ent) then
1526             Error_Pragma_Arg
1527               ("pragma% cannot apply to object, requires a type", Argx);
1528
1529          else
1530             Error_Pragma_Arg
1531               ("pragma% cannot apply to&, requires a type", Argx);
1532          end if;
1533       end Check_First_Subtype;
1534
1535       ----------------------
1536       -- Check_Identifier --
1537       ----------------------
1538
1539       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1540       begin
1541          if Present (Arg)
1542            and then Nkind (Arg) = N_Pragma_Argument_Association
1543          then
1544             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1545                Error_Msg_Name_1 := Pname;
1546                Error_Msg_Name_2 := Id;
1547                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1548                raise Pragma_Exit;
1549             end if;
1550          end if;
1551       end Check_Identifier;
1552
1553       --------------------------------
1554       -- Check_Identifier_Is_One_Of --
1555       --------------------------------
1556
1557       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1558       begin
1559          if Present (Arg)
1560            and then Nkind (Arg) = N_Pragma_Argument_Association
1561          then
1562             if Chars (Arg) = No_Name then
1563                Error_Msg_Name_1 := Pname;
1564                Error_Msg_N ("pragma% argument expects an identifier", Arg);
1565                raise Pragma_Exit;
1566
1567             elsif Chars (Arg) /= N1
1568               and then Chars (Arg) /= N2
1569             then
1570                Error_Msg_Name_1 := Pname;
1571                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1572                raise Pragma_Exit;
1573             end if;
1574          end if;
1575       end Check_Identifier_Is_One_Of;
1576
1577       ---------------------------
1578       -- Check_In_Main_Program --
1579       ---------------------------
1580
1581       procedure Check_In_Main_Program is
1582          P : constant Node_Id := Parent (N);
1583
1584       begin
1585          --  Must be at in subprogram body
1586
1587          if Nkind (P) /= N_Subprogram_Body then
1588             Error_Pragma ("% pragma allowed only in subprogram");
1589
1590          --  Otherwise warn if obviously not main program
1591
1592          elsif Present (Parameter_Specifications (Specification (P)))
1593            or else not Is_Compilation_Unit (Defining_Entity (P))
1594          then
1595             Error_Msg_Name_1 := Pname;
1596             Error_Msg_N
1597               ("?pragma% is only effective in main program", N);
1598          end if;
1599       end Check_In_Main_Program;
1600
1601       ---------------------------------------
1602       -- Check_Interrupt_Or_Attach_Handler --
1603       ---------------------------------------
1604
1605       procedure Check_Interrupt_Or_Attach_Handler is
1606          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1607          Handler_Proc, Proc_Scope : Entity_Id;
1608
1609       begin
1610          Analyze (Arg1_X);
1611
1612          if Prag_Id = Pragma_Interrupt_Handler then
1613             Check_Restriction (No_Dynamic_Attachment, N);
1614          end if;
1615
1616          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1617          Proc_Scope := Scope (Handler_Proc);
1618
1619          --  On AAMP only, a pragma Interrupt_Handler is supported for
1620          --  nonprotected parameterless procedures.
1621
1622          if not AAMP_On_Target
1623            or else Prag_Id = Pragma_Attach_Handler
1624          then
1625             if Ekind (Proc_Scope) /= E_Protected_Type then
1626                Error_Pragma_Arg
1627                  ("argument of pragma% must be protected procedure", Arg1);
1628             end if;
1629
1630             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1631                Error_Pragma ("pragma% must be in protected definition");
1632             end if;
1633          end if;
1634
1635          if not Is_Library_Level_Entity (Proc_Scope)
1636            or else (AAMP_On_Target
1637                      and then not Is_Library_Level_Entity (Handler_Proc))
1638          then
1639             Error_Pragma_Arg
1640               ("argument for pragma% must be library level entity", Arg1);
1641          end if;
1642
1643          --  AI05-0033: A pragma cannot appear within a generic body, because
1644          --  instance can be in a nested scope. The check that protected type
1645          --  is itself a library-level declaration is done elsewhere.
1646
1647          --  Note: we omit this check in Codepeer mode to properly handle code
1648          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1649
1650          if Inside_A_Generic then
1651             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1652               and then In_Package_Body (Scope (Current_Scope))
1653               and then not CodePeer_Mode
1654             then
1655                Error_Pragma ("pragma% cannot be used inside a generic");
1656             end if;
1657          end if;
1658       end Check_Interrupt_Or_Attach_Handler;
1659
1660       -------------------------------------------
1661       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1662       -------------------------------------------
1663
1664       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1665          P : Node_Id;
1666
1667       begin
1668          P := Parent (N);
1669          loop
1670             if No (P) then
1671                exit;
1672
1673             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1674                exit;
1675
1676             elsif Nkind_In (P, N_Package_Specification,
1677                                N_Block_Statement)
1678             then
1679                return;
1680
1681             --  Note: the following tests seem a little peculiar, because
1682             --  they test for bodies, but if we were in the statement part
1683             --  of the body, we would already have hit the handled statement
1684             --  sequence, so the only way we get here is by being in the
1685             --  declarative part of the body.
1686
1687             elsif Nkind_In (P, N_Subprogram_Body,
1688                                N_Package_Body,
1689                                N_Task_Body,
1690                                N_Entry_Body)
1691             then
1692                return;
1693             end if;
1694
1695             P := Parent (P);
1696          end loop;
1697
1698          Error_Pragma ("pragma% is not in declarative part or package spec");
1699       end Check_Is_In_Decl_Part_Or_Package_Spec;
1700
1701       -------------------------
1702       -- Check_No_Identifier --
1703       -------------------------
1704
1705       procedure Check_No_Identifier (Arg : Node_Id) is
1706       begin
1707          if Nkind (Arg) = N_Pragma_Argument_Association
1708            and then Chars (Arg) /= No_Name
1709          then
1710             Error_Pragma_Arg_Ident
1711               ("pragma% does not permit identifier& here", Arg);
1712          end if;
1713       end Check_No_Identifier;
1714
1715       --------------------------
1716       -- Check_No_Identifiers --
1717       --------------------------
1718
1719       procedure Check_No_Identifiers is
1720          Arg_Node : Node_Id;
1721       begin
1722          if Arg_Count > 0 then
1723             Arg_Node := Arg1;
1724             while Present (Arg_Node) loop
1725                Check_No_Identifier (Arg_Node);
1726                Next (Arg_Node);
1727             end loop;
1728          end if;
1729       end Check_No_Identifiers;
1730
1731       ------------------------
1732       -- Check_No_Link_Name --
1733       ------------------------
1734
1735       procedure Check_No_Link_Name is
1736       begin
1737          if Present (Arg3)
1738            and then Chars (Arg3) = Name_Link_Name
1739          then
1740             Arg4 := Arg3;
1741          end if;
1742
1743          if Present (Arg4) then
1744             Error_Pragma_Arg
1745               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1746          end if;
1747       end Check_No_Link_Name;
1748
1749       -------------------------------
1750       -- Check_Optional_Identifier --
1751       -------------------------------
1752
1753       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1754       begin
1755          if Present (Arg)
1756            and then Nkind (Arg) = N_Pragma_Argument_Association
1757            and then Chars (Arg) /= No_Name
1758          then
1759             if Chars (Arg) /= Id then
1760                Error_Msg_Name_1 := Pname;
1761                Error_Msg_Name_2 := Id;
1762                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1763                raise Pragma_Exit;
1764             end if;
1765          end if;
1766       end Check_Optional_Identifier;
1767
1768       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1769       begin
1770          Name_Buffer (1 .. Id'Length) := Id;
1771          Name_Len := Id'Length;
1772          Check_Optional_Identifier (Arg, Name_Find);
1773       end Check_Optional_Identifier;
1774
1775       --------------------------------------
1776       -- Check_Precondition_Postcondition --
1777       --------------------------------------
1778
1779       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1780          P  : Node_Id;
1781          PO : Node_Id;
1782
1783          procedure Chain_PPC (PO : Node_Id);
1784          --  If PO is an entry or a [generic] subprogram declaration node, then
1785          --  the precondition/postcondition applies to this subprogram and the
1786          --  processing for the pragma is completed. Otherwise the pragma is
1787          --  misplaced.
1788
1789          ---------------
1790          -- Chain_PPC --
1791          ---------------
1792
1793          procedure Chain_PPC (PO : Node_Id) is
1794             S   : Entity_Id;
1795             P   : Node_Id;
1796
1797          begin
1798             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1799                if not From_Aspect_Specification (N) then
1800                   Error_Pragma
1801                     ("pragma% cannot be applied to abstract subprogram");
1802
1803                elsif Class_Present (N) then
1804                   null;
1805
1806                else
1807                   Error_Pragma
1808                     ("aspect % requires ''Class for abstract subprogram");
1809                end if;
1810
1811             --  AI05-0230: The same restriction applies to null procedures. For
1812             --  compatibility with earlier uses of the Ada pragma, apply this
1813             --  rule only to aspect specifications.
1814
1815             --  The above discrpency needs documentation. Robert is dubious
1816             --  about whether it is a good idea ???
1817
1818             elsif Nkind (PO) = N_Subprogram_Declaration
1819               and then Nkind (Specification (PO)) = N_Procedure_Specification
1820               and then Null_Present (Specification (PO))
1821               and then From_Aspect_Specification (N)
1822               and then not Class_Present (N)
1823             then
1824                Error_Pragma
1825                  ("aspect % requires ''Class for null procedure");
1826
1827             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1828                                     N_Generic_Subprogram_Declaration,
1829                                     N_Entry_Declaration)
1830             then
1831                Pragma_Misplaced;
1832             end if;
1833
1834             --  Here if we have [generic] subprogram or entry declaration
1835
1836             if Nkind (PO) = N_Entry_Declaration then
1837                S := Defining_Entity (PO);
1838             else
1839                S := Defining_Unit_Name (Specification (PO));
1840             end if;
1841
1842             --  Make sure we do not have the case of a precondition pragma when
1843             --  the Pre'Class aspect is present.
1844
1845             --  We do this by looking at pragmas already chained to the entity
1846             --  since the aspect derived pragma will be put on this list first.
1847
1848             if Pragma_Name (N) = Name_Precondition then
1849                if not From_Aspect_Specification (N) then
1850                   P := Spec_PPC_List (Contract (S));
1851                   while Present (P) loop
1852                      if Pragma_Name (P) = Name_Precondition
1853                        and then From_Aspect_Specification (P)
1854                        and then Class_Present (P)
1855                      then
1856                         Error_Msg_Sloc := Sloc (P);
1857                         Error_Pragma
1858                           ("pragma% not allowed, `Pre''Class` aspect given#");
1859                      end if;
1860
1861                      P := Next_Pragma (P);
1862                   end loop;
1863                end if;
1864             end if;
1865
1866             --  Similarly check for Pre with inherited Pre'Class. Note that
1867             --  we cover the aspect case as well here.
1868
1869             if Pragma_Name (N) = Name_Precondition
1870               and then not Class_Present (N)
1871             then
1872                declare
1873                   Inherited : constant Subprogram_List :=
1874                                 Inherited_Subprograms (S);
1875                   P         : Node_Id;
1876
1877                begin
1878                   for J in Inherited'Range loop
1879                      P := Spec_PPC_List (Contract (Inherited (J)));
1880                      while Present (P) loop
1881                         if Pragma_Name (P) = Name_Precondition
1882                           and then Class_Present (P)
1883                         then
1884                            Error_Msg_Sloc := Sloc (P);
1885                            Error_Pragma
1886                              ("pragma% not allowed, `Pre''Class` "
1887                               & "aspect inherited from#");
1888                         end if;
1889
1890                         P := Next_Pragma (P);
1891                      end loop;
1892                   end loop;
1893                end;
1894             end if;
1895
1896             --  Note: we do not analyze the pragma at this point. Instead we
1897             --  delay this analysis until the end of the declarative part in
1898             --  which the pragma appears. This implements the required delay
1899             --  in this analysis, allowing forward references. The analysis
1900             --  happens at the end of Analyze_Declarations.
1901
1902             --  Chain spec PPC pragma to list for subprogram
1903
1904             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1905             Set_Spec_PPC_List (Contract (S), N);
1906
1907             --  Return indicating spec case
1908
1909             In_Body := False;
1910             return;
1911          end Chain_PPC;
1912
1913       --  Start of processing for Check_Precondition_Postcondition
1914
1915       begin
1916          if not Is_List_Member (N) then
1917             Pragma_Misplaced;
1918          end if;
1919
1920          --  Preanalyze message argument if present. Visibility in this
1921          --  argument is established at the point of pragma occurrence.
1922
1923          if Arg_Count = 2 then
1924             Check_Optional_Identifier (Arg2, Name_Message);
1925             Preanalyze_Spec_Expression
1926               (Get_Pragma_Arg (Arg2), Standard_String);
1927          end if;
1928
1929          --  Record if pragma is disabled
1930
1931          if Check_Enabled (Pname) then
1932             Set_SCO_Pragma_Enabled (Loc);
1933          end if;
1934
1935          --  If we are within an inlined body, the legality of the pragma
1936          --  has been checked already.
1937
1938          if In_Inlined_Body then
1939             In_Body := True;
1940             return;
1941          end if;
1942
1943          --  Search prior declarations
1944
1945          P := N;
1946          while Present (Prev (P)) loop
1947             P := Prev (P);
1948
1949             --  If the previous node is a generic subprogram, do not go to to
1950             --  the original node, which is the unanalyzed tree: we need to
1951             --  attach the pre/postconditions to the analyzed version at this
1952             --  point. They get propagated to the original tree when analyzing
1953             --  the corresponding body.
1954
1955             if Nkind (P) not in N_Generic_Declaration then
1956                PO := Original_Node (P);
1957             else
1958                PO := P;
1959             end if;
1960
1961             --  Skip past prior pragma
1962
1963             if Nkind (PO) = N_Pragma then
1964                null;
1965
1966             --  Skip stuff not coming from source
1967
1968             elsif not Comes_From_Source (PO) then
1969
1970                --  The condition may apply to a subprogram instantiation
1971
1972                if Nkind (PO) = N_Subprogram_Declaration
1973                  and then Present (Generic_Parent (Specification (PO)))
1974                then
1975                   Chain_PPC (PO);
1976                   return;
1977
1978                elsif Nkind (PO) = N_Subprogram_Declaration
1979                  and then In_Instance
1980                then
1981                   Chain_PPC (PO);
1982                   return;
1983
1984                --  For all other cases of non source code, do nothing
1985
1986                else
1987                   null;
1988                end if;
1989
1990             --  Only remaining possibility is subprogram declaration
1991
1992             else
1993                Chain_PPC (PO);
1994                return;
1995             end if;
1996          end loop;
1997
1998          --  If we fall through loop, pragma is at start of list, so see if it
1999          --  is at the start of declarations of a subprogram body.
2000
2001          if Nkind (Parent (N)) = N_Subprogram_Body
2002            and then List_Containing (N) = Declarations (Parent (N))
2003          then
2004             if Operating_Mode /= Generate_Code
2005               or else Inside_A_Generic
2006             then
2007                --  Analyze pragma expression for correctness and for ASIS use
2008
2009                Preanalyze_Spec_Expression
2010                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
2011
2012                --  In ASIS mode, for a pragma generated from a source aspect,
2013                --  also analyze the original aspect expression.
2014
2015                if ASIS_Mode
2016                  and then Present (Corresponding_Aspect (N))
2017                then
2018                   Preanalyze_Spec_Expression
2019                     (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2020                end if;
2021             end if;
2022
2023             In_Body := True;
2024             return;
2025
2026          --  See if it is in the pragmas after a library level subprogram
2027
2028          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2029
2030             --  In formal verification mode, analyze pragma expression for
2031             --  correctness, as it is not expanded later.
2032
2033             if Alfa_Mode then
2034                Analyze_PPC_In_Decl_Part
2035                  (N, Defining_Entity (Unit (Parent (Parent (N)))));
2036             end if;
2037
2038             Chain_PPC (Unit (Parent (Parent (N))));
2039             return;
2040          end if;
2041
2042          --  If we fall through, pragma was misplaced
2043
2044          Pragma_Misplaced;
2045       end Check_Precondition_Postcondition;
2046
2047       -----------------------------
2048       -- Check_Static_Constraint --
2049       -----------------------------
2050
2051       --  Note: for convenience in writing this procedure, in addition to
2052       --  the officially (i.e. by spec) allowed argument which is always a
2053       --  constraint, it also allows ranges and discriminant associations.
2054       --  Above is not clear ???
2055
2056       procedure Check_Static_Constraint (Constr : Node_Id) is
2057
2058          procedure Require_Static (E : Node_Id);
2059          --  Require given expression to be static expression
2060
2061          --------------------
2062          -- Require_Static --
2063          --------------------
2064
2065          procedure Require_Static (E : Node_Id) is
2066          begin
2067             if not Is_OK_Static_Expression (E) then
2068                Flag_Non_Static_Expr
2069                  ("non-static constraint not allowed in Unchecked_Union!", E);
2070                raise Pragma_Exit;
2071             end if;
2072          end Require_Static;
2073
2074       --  Start of processing for Check_Static_Constraint
2075
2076       begin
2077          case Nkind (Constr) is
2078             when N_Discriminant_Association =>
2079                Require_Static (Expression (Constr));
2080
2081             when N_Range =>
2082                Require_Static (Low_Bound (Constr));
2083                Require_Static (High_Bound (Constr));
2084
2085             when N_Attribute_Reference =>
2086                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
2087                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2088
2089             when N_Range_Constraint =>
2090                Check_Static_Constraint (Range_Expression (Constr));
2091
2092             when N_Index_Or_Discriminant_Constraint =>
2093                declare
2094                   IDC : Entity_Id;
2095                begin
2096                   IDC := First (Constraints (Constr));
2097                   while Present (IDC) loop
2098                      Check_Static_Constraint (IDC);
2099                      Next (IDC);
2100                   end loop;
2101                end;
2102
2103             when others =>
2104                null;
2105          end case;
2106       end Check_Static_Constraint;
2107
2108       ---------------------
2109       -- Check_Test_Case --
2110       ---------------------
2111
2112       procedure Check_Test_Case is
2113          P  : Node_Id;
2114          PO : Node_Id;
2115
2116          procedure Chain_TC (PO : Node_Id);
2117          --  If PO is a [generic] subprogram declaration node, then the
2118          --  test-case applies to this subprogram and the processing for the
2119          --  pragma is completed. Otherwise the pragma is misplaced.
2120
2121          --------------
2122          -- Chain_TC --
2123          --------------
2124
2125          procedure Chain_TC (PO : Node_Id) is
2126             S   : Entity_Id;
2127
2128          begin
2129             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2130                if From_Aspect_Specification (N) then
2131                   Error_Pragma
2132                     ("aspect% cannot be applied to abstract subprogram");
2133                else
2134                   Error_Pragma
2135                     ("pragma% cannot be applied to abstract subprogram");
2136                end if;
2137
2138             elsif Nkind (PO) = N_Entry_Declaration then
2139                if From_Aspect_Specification (N) then
2140                   Error_Pragma ("aspect% cannot be applied to entry");
2141                else
2142                   Error_Pragma ("pragma% cannot be applied to entry");
2143                end if;
2144
2145             elsif not Nkind_In (PO, N_Subprogram_Declaration,
2146                                     N_Generic_Subprogram_Declaration)
2147             then
2148                Pragma_Misplaced;
2149             end if;
2150
2151             --  Here if we have [generic] subprogram declaration
2152
2153             S := Defining_Unit_Name (Specification (PO));
2154
2155             --  Note: we do not analyze the pragma at this point. Instead we
2156             --  delay this analysis until the end of the declarative part in
2157             --  which the pragma appears. This implements the required delay
2158             --  in this analysis, allowing forward references. The analysis
2159             --  happens at the end of Analyze_Declarations.
2160
2161             --  There should not be another test case with the same name
2162             --  associated to this subprogram.
2163
2164             declare
2165                Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2166                TC   : Node_Id;
2167
2168             begin
2169                TC := Spec_TC_List (Contract (S));
2170                while Present (TC) loop
2171
2172                   if String_Equal
2173                     (Name, Get_Name_From_Test_Case_Pragma (TC))
2174                   then
2175                      Error_Msg_Sloc := Sloc (TC);
2176
2177                      if From_Aspect_Specification (N) then
2178                         Error_Pragma ("name for aspect% is already used#");
2179                      else
2180                         Error_Pragma ("name for pragma% is already used#");
2181                      end if;
2182                   end if;
2183
2184                   TC := Next_Pragma (TC);
2185                end loop;
2186             end;
2187
2188             --  Chain spec TC pragma to list for subprogram
2189
2190             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2191             Set_Spec_TC_List (Contract (S), N);
2192          end Chain_TC;
2193
2194       --  Start of processing for Check_Test_Case
2195
2196       begin
2197          if not Is_List_Member (N) then
2198             Pragma_Misplaced;
2199          end if;
2200
2201          --  Test cases should only appear in package spec unit
2202
2203          if Get_Source_Unit (N) = No_Unit
2204            or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2205                                  N_Package_Declaration,
2206                                  N_Generic_Package_Declaration)
2207          then
2208             Pragma_Misplaced;
2209          end if;
2210
2211          --  Search prior declarations
2212
2213          P := N;
2214          while Present (Prev (P)) loop
2215             P := Prev (P);
2216
2217             --  If the previous node is a generic subprogram, do not go to to
2218             --  the original node, which is the unanalyzed tree: we need to
2219             --  attach the test-case to the analyzed version at this point.
2220             --  They get propagated to the original tree when analyzing the
2221             --  corresponding body.
2222
2223             if Nkind (P) not in N_Generic_Declaration then
2224                PO := Original_Node (P);
2225             else
2226                PO := P;
2227             end if;
2228
2229             --  Skip past prior pragma
2230
2231             if Nkind (PO) = N_Pragma then
2232                null;
2233
2234             --  Skip stuff not coming from source
2235
2236             elsif not Comes_From_Source (PO) then
2237                null;
2238
2239             --  Only remaining possibility is subprogram declaration. First
2240             --  check that it is declared directly in a package declaration.
2241             --  This may be either the package declaration for the current unit
2242             --  being defined or a local package declaration.
2243
2244             elsif not Present (Parent (Parent (PO)))
2245               or else not Present (Parent (Parent (Parent (PO))))
2246               or else not Nkind_In (Parent (Parent (PO)),
2247                                     N_Package_Declaration,
2248                                     N_Generic_Package_Declaration)
2249             then
2250                Pragma_Misplaced;
2251
2252             else
2253                Chain_TC (PO);
2254                return;
2255             end if;
2256          end loop;
2257
2258          --  If we fall through, pragma was misplaced
2259
2260          Pragma_Misplaced;
2261       end Check_Test_Case;
2262
2263       --------------------------------------
2264       -- Check_Valid_Configuration_Pragma --
2265       --------------------------------------
2266
2267       --  A configuration pragma must appear in the context clause of a
2268       --  compilation unit, and only other pragmas may precede it. Note that
2269       --  the test also allows use in a configuration pragma file.
2270
2271       procedure Check_Valid_Configuration_Pragma is
2272       begin
2273          if not Is_Configuration_Pragma then
2274             Error_Pragma ("incorrect placement for configuration pragma%");
2275          end if;
2276       end Check_Valid_Configuration_Pragma;
2277
2278       -------------------------------------
2279       -- Check_Valid_Library_Unit_Pragma --
2280       -------------------------------------
2281
2282       procedure Check_Valid_Library_Unit_Pragma is
2283          Plist       : List_Id;
2284          Parent_Node : Node_Id;
2285          Unit_Name   : Entity_Id;
2286          Unit_Kind   : Node_Kind;
2287          Unit_Node   : Node_Id;
2288          Sindex      : Source_File_Index;
2289
2290       begin
2291          if not Is_List_Member (N) then
2292             Pragma_Misplaced;
2293
2294          else
2295             Plist := List_Containing (N);
2296             Parent_Node := Parent (Plist);
2297
2298             if Parent_Node = Empty then
2299                Pragma_Misplaced;
2300
2301             --  Case of pragma appearing after a compilation unit. In this case
2302             --  it must have an argument with the corresponding name and must
2303             --  be part of the following pragmas of its parent.
2304
2305             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2306                if Plist /= Pragmas_After (Parent_Node) then
2307                   Pragma_Misplaced;
2308
2309                elsif Arg_Count = 0 then
2310                   Error_Pragma
2311                     ("argument required if outside compilation unit");
2312
2313                else
2314                   Check_No_Identifiers;
2315                   Check_Arg_Count (1);
2316                   Unit_Node := Unit (Parent (Parent_Node));
2317                   Unit_Kind := Nkind (Unit_Node);
2318
2319                   Analyze (Get_Pragma_Arg (Arg1));
2320
2321                   if Unit_Kind = N_Generic_Subprogram_Declaration
2322                     or else Unit_Kind = N_Subprogram_Declaration
2323                   then
2324                      Unit_Name := Defining_Entity (Unit_Node);
2325
2326                   elsif Unit_Kind in N_Generic_Instantiation then
2327                      Unit_Name := Defining_Entity (Unit_Node);
2328
2329                   else
2330                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2331                   end if;
2332
2333                   if Chars (Unit_Name) /=
2334                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2335                   then
2336                      Error_Pragma_Arg
2337                        ("pragma% argument is not current unit name", Arg1);
2338                   end if;
2339
2340                   if Ekind (Unit_Name) = E_Package
2341                     and then Present (Renamed_Entity (Unit_Name))
2342                   then
2343                      Error_Pragma ("pragma% not allowed for renamed package");
2344                   end if;
2345                end if;
2346
2347             --  Pragma appears other than after a compilation unit
2348
2349             else
2350                --  Here we check for the generic instantiation case and also
2351                --  for the case of processing a generic formal package. We
2352                --  detect these cases by noting that the Sloc on the node
2353                --  does not belong to the current compilation unit.
2354
2355                Sindex := Source_Index (Current_Sem_Unit);
2356
2357                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2358                   Rewrite (N, Make_Null_Statement (Loc));
2359                   return;
2360
2361                --  If before first declaration, the pragma applies to the
2362                --  enclosing unit, and the name if present must be this name.
2363
2364                elsif Is_Before_First_Decl (N, Plist) then
2365                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2366                   Unit_Kind := Nkind (Unit_Node);
2367
2368                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2369                      Pragma_Misplaced;
2370
2371                   elsif Unit_Kind = N_Subprogram_Body
2372                     and then not Acts_As_Spec (Unit_Node)
2373                   then
2374                      Pragma_Misplaced;
2375
2376                   elsif Nkind (Parent_Node) = N_Package_Body then
2377                      Pragma_Misplaced;
2378
2379                   elsif Nkind (Parent_Node) = N_Package_Specification
2380                     and then Plist = Private_Declarations (Parent_Node)
2381                   then
2382                      Pragma_Misplaced;
2383
2384                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2385                            or else Nkind (Parent_Node) =
2386                                              N_Generic_Subprogram_Declaration)
2387                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2388                   then
2389                      Pragma_Misplaced;
2390
2391                   elsif Arg_Count > 0 then
2392                      Analyze (Get_Pragma_Arg (Arg1));
2393
2394                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2395                         Error_Pragma_Arg
2396                           ("name in pragma% must be enclosing unit", Arg1);
2397                      end if;
2398
2399                   --  It is legal to have no argument in this context
2400
2401                   else
2402                      return;
2403                   end if;
2404
2405                --  Error if not before first declaration. This is because a
2406                --  library unit pragma argument must be the name of a library
2407                --  unit (RM 10.1.5(7)), but the only names permitted in this
2408                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2409                --  generic subprogram declarations or generic instantiations.
2410
2411                else
2412                   Error_Pragma
2413                     ("pragma% misplaced, must be before first declaration");
2414                end if;
2415             end if;
2416          end if;
2417       end Check_Valid_Library_Unit_Pragma;
2418
2419       -------------------
2420       -- Check_Variant --
2421       -------------------
2422
2423       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2424          Clist : constant Node_Id := Component_List (Variant);
2425          Comp  : Node_Id;
2426
2427       begin
2428          if not Is_Non_Empty_List (Component_Items (Clist)) then
2429             Error_Msg_N
2430               ("Unchecked_Union may not have empty component list",
2431                Variant);
2432             return;
2433          end if;
2434
2435          Comp := First (Component_Items (Clist));
2436          while Present (Comp) loop
2437             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2438             Next (Comp);
2439          end loop;
2440       end Check_Variant;
2441
2442       ------------------
2443       -- Error_Pragma --
2444       ------------------
2445
2446       procedure Error_Pragma (Msg : String) is
2447          MsgF : String := Msg;
2448       begin
2449          Error_Msg_Name_1 := Pname;
2450          Fix_Error (MsgF);
2451          Error_Msg_N (MsgF, N);
2452          raise Pragma_Exit;
2453       end Error_Pragma;
2454
2455       ----------------------
2456       -- Error_Pragma_Arg --
2457       ----------------------
2458
2459       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2460          MsgF : String := Msg;
2461       begin
2462          Error_Msg_Name_1 := Pname;
2463          Fix_Error (MsgF);
2464          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2465          raise Pragma_Exit;
2466       end Error_Pragma_Arg;
2467
2468       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2469          MsgF : String := Msg1;
2470       begin
2471          Error_Msg_Name_1 := Pname;
2472          Fix_Error (MsgF);
2473          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2474          Error_Pragma_Arg (Msg2, Arg);
2475       end Error_Pragma_Arg;
2476
2477       ----------------------------
2478       -- Error_Pragma_Arg_Ident --
2479       ----------------------------
2480
2481       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2482          MsgF : String := Msg;
2483       begin
2484          Error_Msg_Name_1 := Pname;
2485          Fix_Error (MsgF);
2486          Error_Msg_N (MsgF, Arg);
2487          raise Pragma_Exit;
2488       end Error_Pragma_Arg_Ident;
2489
2490       ----------------------
2491       -- Error_Pragma_Ref --
2492       ----------------------
2493
2494       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2495          MsgF : String := Msg;
2496       begin
2497          Error_Msg_Name_1 := Pname;
2498          Fix_Error (MsgF);
2499          Error_Msg_Sloc   := Sloc (Ref);
2500          Error_Msg_NE (MsgF, N, Ref);
2501          raise Pragma_Exit;
2502       end Error_Pragma_Ref;
2503
2504       ------------------------
2505       -- Find_Lib_Unit_Name --
2506       ------------------------
2507
2508       function Find_Lib_Unit_Name return Entity_Id is
2509       begin
2510          --  Return inner compilation unit entity, for case of nested
2511          --  categorization pragmas. This happens in generic unit.
2512
2513          if Nkind (Parent (N)) = N_Package_Specification
2514            and then Defining_Entity (Parent (N)) /= Current_Scope
2515          then
2516             return Defining_Entity (Parent (N));
2517          else
2518             return Current_Scope;
2519          end if;
2520       end Find_Lib_Unit_Name;
2521
2522       ----------------------------
2523       -- Find_Program_Unit_Name --
2524       ----------------------------
2525
2526       procedure Find_Program_Unit_Name (Id : Node_Id) is
2527          Unit_Name : Entity_Id;
2528          Unit_Kind : Node_Kind;
2529          P         : constant Node_Id := Parent (N);
2530
2531       begin
2532          if Nkind (P) = N_Compilation_Unit then
2533             Unit_Kind := Nkind (Unit (P));
2534
2535             if Unit_Kind = N_Subprogram_Declaration
2536               or else Unit_Kind = N_Package_Declaration
2537               or else Unit_Kind in N_Generic_Declaration
2538             then
2539                Unit_Name := Defining_Entity (Unit (P));
2540
2541                if Chars (Id) = Chars (Unit_Name) then
2542                   Set_Entity (Id, Unit_Name);
2543                   Set_Etype (Id, Etype (Unit_Name));
2544                else
2545                   Set_Etype (Id, Any_Type);
2546                   Error_Pragma
2547                     ("cannot find program unit referenced by pragma%");
2548                end if;
2549
2550             else
2551                Set_Etype (Id, Any_Type);
2552                Error_Pragma ("pragma% inapplicable to this unit");
2553             end if;
2554
2555          else
2556             Analyze (Id);
2557          end if;
2558       end Find_Program_Unit_Name;
2559
2560       -----------------------------------------
2561       -- Find_Unique_Parameterless_Procedure --
2562       -----------------------------------------
2563
2564       function Find_Unique_Parameterless_Procedure
2565         (Name : Entity_Id;
2566          Arg  : Node_Id) return Entity_Id
2567       is
2568          Proc : Entity_Id := Empty;
2569
2570       begin
2571          --  The body of this procedure needs some comments ???
2572
2573          if not Is_Entity_Name (Name) then
2574             Error_Pragma_Arg
2575               ("argument of pragma% must be entity name", Arg);
2576
2577          elsif not Is_Overloaded (Name) then
2578             Proc := Entity (Name);
2579
2580             if Ekind (Proc) /= E_Procedure
2581               or else Present (First_Formal (Proc))
2582             then
2583                Error_Pragma_Arg
2584                  ("argument of pragma% must be parameterless procedure", Arg);
2585             end if;
2586
2587          else
2588             declare
2589                Found : Boolean := False;
2590                It    : Interp;
2591                Index : Interp_Index;
2592
2593             begin
2594                Get_First_Interp (Name, Index, It);
2595                while Present (It.Nam) loop
2596                   Proc := It.Nam;
2597
2598                   if Ekind (Proc) = E_Procedure
2599                     and then No (First_Formal (Proc))
2600                   then
2601                      if not Found then
2602                         Found := True;
2603                         Set_Entity (Name, Proc);
2604                         Set_Is_Overloaded (Name, False);
2605                      else
2606                         Error_Pragma_Arg
2607                           ("ambiguous handler name for pragma% ", Arg);
2608                      end if;
2609                   end if;
2610
2611                   Get_Next_Interp (Index, It);
2612                end loop;
2613
2614                if not Found then
2615                   Error_Pragma_Arg
2616                     ("argument of pragma% must be parameterless procedure",
2617                      Arg);
2618                else
2619                   Proc := Entity (Name);
2620                end if;
2621             end;
2622          end if;
2623
2624          return Proc;
2625       end Find_Unique_Parameterless_Procedure;
2626
2627       ---------------
2628       -- Fix_Error --
2629       ---------------
2630
2631       procedure Fix_Error (Msg : in out String) is
2632       begin
2633          if From_Aspect_Specification (N) then
2634             for J in Msg'First .. Msg'Last - 5 loop
2635                if Msg (J .. J + 5) = "pragma" then
2636                   Msg (J .. J + 5) := "aspect";
2637                end if;
2638             end loop;
2639
2640             if Error_Msg_Name_1 = Name_Precondition then
2641                Error_Msg_Name_1 := Name_Pre;
2642             elsif Error_Msg_Name_1 = Name_Postcondition then
2643                Error_Msg_Name_1 := Name_Post;
2644             end if;
2645          end if;
2646       end Fix_Error;
2647
2648       -------------------------
2649       -- Gather_Associations --
2650       -------------------------
2651
2652       procedure Gather_Associations
2653         (Names : Name_List;
2654          Args  : out Args_List)
2655       is
2656          Arg : Node_Id;
2657
2658       begin
2659          --  Initialize all parameters to Empty
2660
2661          for J in Args'Range loop
2662             Args (J) := Empty;
2663          end loop;
2664
2665          --  That's all we have to do if there are no argument associations
2666
2667          if No (Pragma_Argument_Associations (N)) then
2668             return;
2669          end if;
2670
2671          --  Otherwise first deal with any positional parameters present
2672
2673          Arg := First (Pragma_Argument_Associations (N));
2674          for Index in Args'Range loop
2675             exit when No (Arg) or else Chars (Arg) /= No_Name;
2676             Args (Index) := Get_Pragma_Arg (Arg);
2677             Next (Arg);
2678          end loop;
2679
2680          --  Positional parameters all processed, if any left, then we
2681          --  have too many positional parameters.
2682
2683          if Present (Arg) and then Chars (Arg) = No_Name then
2684             Error_Pragma_Arg
2685               ("too many positional associations for pragma%", Arg);
2686          end if;
2687
2688          --  Process named parameters if any are present
2689
2690          while Present (Arg) loop
2691             if Chars (Arg) = No_Name then
2692                Error_Pragma_Arg
2693                  ("positional association cannot follow named association",
2694                   Arg);
2695
2696             else
2697                for Index in Names'Range loop
2698                   if Names (Index) = Chars (Arg) then
2699                      if Present (Args (Index)) then
2700                         Error_Pragma_Arg
2701                           ("duplicate argument association for pragma%", Arg);
2702                      else
2703                         Args (Index) := Get_Pragma_Arg (Arg);
2704                         exit;
2705                      end if;
2706                   end if;
2707
2708                   if Index = Names'Last then
2709                      Error_Msg_Name_1 := Pname;
2710                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2711
2712                      --  Check for possible misspelling
2713
2714                      for Index1 in Names'Range loop
2715                         if Is_Bad_Spelling_Of
2716                              (Chars (Arg), Names (Index1))
2717                         then
2718                            Error_Msg_Name_1 := Names (Index1);
2719                            Error_Msg_N -- CODEFIX
2720                              ("\possible misspelling of%", Arg);
2721                            exit;
2722                         end if;
2723                      end loop;
2724
2725                      raise Pragma_Exit;
2726                   end if;
2727                end loop;
2728             end if;
2729
2730             Next (Arg);
2731          end loop;
2732       end Gather_Associations;
2733
2734       -----------------
2735       -- GNAT_Pragma --
2736       -----------------
2737
2738       procedure GNAT_Pragma is
2739       begin
2740          Check_Restriction (No_Implementation_Pragmas, N);
2741       end GNAT_Pragma;
2742
2743       --------------------------
2744       -- Is_Before_First_Decl --
2745       --------------------------
2746
2747       function Is_Before_First_Decl
2748         (Pragma_Node : Node_Id;
2749          Decls       : List_Id) return Boolean
2750       is
2751          Item : Node_Id := First (Decls);
2752
2753       begin
2754          --  Only other pragmas can come before this pragma
2755
2756          loop
2757             if No (Item) or else Nkind (Item) /= N_Pragma then
2758                return False;
2759
2760             elsif Item = Pragma_Node then
2761                return True;
2762             end if;
2763
2764             Next (Item);
2765          end loop;
2766       end Is_Before_First_Decl;
2767
2768       -----------------------------
2769       -- Is_Configuration_Pragma --
2770       -----------------------------
2771
2772       --  A configuration pragma must appear in the context clause of a
2773       --  compilation unit, and only other pragmas may precede it. Note that
2774       --  the test below also permits use in a configuration pragma file.
2775
2776       function Is_Configuration_Pragma return Boolean is
2777          Lis : constant List_Id := List_Containing (N);
2778          Par : constant Node_Id := Parent (N);
2779          Prg : Node_Id;
2780
2781       begin
2782          --  If no parent, then we are in the configuration pragma file,
2783          --  so the placement is definitely appropriate.
2784
2785          if No (Par) then
2786             return True;
2787
2788          --  Otherwise we must be in the context clause of a compilation unit
2789          --  and the only thing allowed before us in the context list is more
2790          --  configuration pragmas.
2791
2792          elsif Nkind (Par) = N_Compilation_Unit
2793            and then Context_Items (Par) = Lis
2794          then
2795             Prg := First (Lis);
2796
2797             loop
2798                if Prg = N then
2799                   return True;
2800                elsif Nkind (Prg) /= N_Pragma then
2801                   return False;
2802                end if;
2803
2804                Next (Prg);
2805             end loop;
2806
2807          else
2808             return False;
2809          end if;
2810       end Is_Configuration_Pragma;
2811
2812       --------------------------
2813       -- Is_In_Context_Clause --
2814       --------------------------
2815
2816       function Is_In_Context_Clause return Boolean is
2817          Plist       : List_Id;
2818          Parent_Node : Node_Id;
2819
2820       begin
2821          if not Is_List_Member (N) then
2822             return False;
2823
2824          else
2825             Plist := List_Containing (N);
2826             Parent_Node := Parent (Plist);
2827
2828             if Parent_Node = Empty
2829               or else Nkind (Parent_Node) /= N_Compilation_Unit
2830               or else Context_Items (Parent_Node) /= Plist
2831             then
2832                return False;
2833             end if;
2834          end if;
2835
2836          return True;
2837       end Is_In_Context_Clause;
2838
2839       ---------------------------------
2840       -- Is_Static_String_Expression --
2841       ---------------------------------
2842
2843       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2844          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2845
2846       begin
2847          Analyze_And_Resolve (Argx);
2848          return Is_OK_Static_Expression (Argx)
2849            and then Nkind (Argx) = N_String_Literal;
2850       end Is_Static_String_Expression;
2851
2852       ----------------------
2853       -- Pragma_Misplaced --
2854       ----------------------
2855
2856       procedure Pragma_Misplaced is
2857       begin
2858          Error_Pragma ("incorrect placement of pragma%");
2859       end Pragma_Misplaced;
2860
2861       ------------------------------------
2862       -- Process Atomic_Shared_Volatile --
2863       ------------------------------------
2864
2865       procedure Process_Atomic_Shared_Volatile is
2866          E_Id : Node_Id;
2867          E    : Entity_Id;
2868          D    : Node_Id;
2869          K    : Node_Kind;
2870          Utyp : Entity_Id;
2871
2872          procedure Set_Atomic (E : Entity_Id);
2873          --  Set given type as atomic, and if no explicit alignment was given,
2874          --  set alignment to unknown, since back end knows what the alignment
2875          --  requirements are for atomic arrays. Note: this step is necessary
2876          --  for derived types.
2877
2878          ----------------
2879          -- Set_Atomic --
2880          ----------------
2881
2882          procedure Set_Atomic (E : Entity_Id) is
2883          begin
2884             Set_Is_Atomic (E);
2885
2886             if not Has_Alignment_Clause (E) then
2887                Set_Alignment (E, Uint_0);
2888             end if;
2889          end Set_Atomic;
2890
2891       --  Start of processing for Process_Atomic_Shared_Volatile
2892
2893       begin
2894          Check_Ada_83_Warning;
2895          Check_No_Identifiers;
2896          Check_Arg_Count (1);
2897          Check_Arg_Is_Local_Name (Arg1);
2898          E_Id := Get_Pragma_Arg (Arg1);
2899
2900          if Etype (E_Id) = Any_Type then
2901             return;
2902          end if;
2903
2904          E := Entity (E_Id);
2905          D := Declaration_Node (E);
2906          K := Nkind (D);
2907
2908          --  Check duplicate before we chain ourselves!
2909
2910          Check_Duplicate_Pragma (E);
2911
2912          --  Now check appropriateness of the entity
2913
2914          if Is_Type (E) then
2915             if Rep_Item_Too_Early (E, N)
2916                  or else
2917                Rep_Item_Too_Late (E, N)
2918             then
2919                return;
2920             else
2921                Check_First_Subtype (Arg1);
2922             end if;
2923
2924             if Prag_Id /= Pragma_Volatile then
2925                Set_Atomic (E);
2926                Set_Atomic (Underlying_Type (E));
2927                Set_Atomic (Base_Type (E));
2928             end if;
2929
2930             --  Attribute belongs on the base type. If the view of the type is
2931             --  currently private, it also belongs on the underlying type.
2932
2933             Set_Is_Volatile (Base_Type (E));
2934             Set_Is_Volatile (Underlying_Type (E));
2935
2936             Set_Treat_As_Volatile (E);
2937             Set_Treat_As_Volatile (Underlying_Type (E));
2938
2939          elsif K = N_Object_Declaration
2940            or else (K = N_Component_Declaration
2941                      and then Original_Record_Component (E) = E)
2942          then
2943             if Rep_Item_Too_Late (E, N) then
2944                return;
2945             end if;
2946
2947             if Prag_Id /= Pragma_Volatile then
2948                Set_Is_Atomic (E);
2949
2950                --  If the object declaration has an explicit initialization, a
2951                --  temporary may have to be created to hold the expression, to
2952                --  ensure that access to the object remain atomic.
2953
2954                if Nkind (Parent (E)) = N_Object_Declaration
2955                  and then Present (Expression (Parent (E)))
2956                then
2957                   Set_Has_Delayed_Freeze (E);
2958                end if;
2959
2960                --  An interesting improvement here. If an object of type X is
2961                --  declared atomic, and the type X is not atomic, that's a
2962                --  pity, since it may not have appropriate alignment etc. We
2963                --  can rescue this in the special case where the object and
2964                --  type are in the same unit by just setting the type as
2965                --  atomic, so that the back end will process it as atomic.
2966
2967                Utyp := Underlying_Type (Etype (E));
2968
2969                if Present (Utyp)
2970                  and then Sloc (E) > No_Location
2971                  and then Sloc (Utyp) > No_Location
2972                  and then
2973                    Get_Source_File_Index (Sloc (E)) =
2974                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2975                then
2976                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2977                end if;
2978             end if;
2979
2980             Set_Is_Volatile (E);
2981             Set_Treat_As_Volatile (E);
2982
2983          else
2984             Error_Pragma_Arg
2985               ("inappropriate entity for pragma%", Arg1);
2986          end if;
2987       end Process_Atomic_Shared_Volatile;
2988
2989       -------------------------------------------
2990       -- Process_Compile_Time_Warning_Or_Error --
2991       -------------------------------------------
2992
2993       procedure Process_Compile_Time_Warning_Or_Error is
2994          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2995
2996       begin
2997          Check_Arg_Count (2);
2998          Check_No_Identifiers;
2999          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3000          Analyze_And_Resolve (Arg1x, Standard_Boolean);
3001
3002          if Compile_Time_Known_Value (Arg1x) then
3003             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3004                declare
3005                   Str   : constant String_Id :=
3006                             Strval (Get_Pragma_Arg (Arg2));
3007                   Len   : constant Int := String_Length (Str);
3008                   Cont  : Boolean;
3009                   Ptr   : Nat;
3010                   CC    : Char_Code;
3011                   C     : Character;
3012                   Cent  : constant Entity_Id :=
3013                             Cunit_Entity (Current_Sem_Unit);
3014
3015                   Force : constant Boolean :=
3016                             Prag_Id = Pragma_Compile_Time_Warning
3017                               and then
3018                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3019                               and then (Ekind (Cent) /= E_Package
3020                                           or else not In_Private_Part (Cent));
3021                   --  Set True if this is the warning case, and we are in the
3022                   --  visible part of a package spec, or in a subprogram spec,
3023                   --  in which case we want to force the client to see the
3024                   --  warning, even though it is not in the main unit.
3025
3026                begin
3027                   --  Loop through segments of message separated by line feeds.
3028                   --  We output these segments as separate messages with
3029                   --  continuation marks for all but the first.
3030
3031                   Cont := False;
3032                   Ptr := 1;
3033                   loop
3034                      Error_Msg_Strlen := 0;
3035
3036                      --  Loop to copy characters from argument to error message
3037                      --  string buffer.
3038
3039                      loop
3040                         exit when Ptr > Len;
3041                         CC := Get_String_Char (Str, Ptr);
3042                         Ptr := Ptr + 1;
3043
3044                         --  Ignore wide chars ??? else store character
3045
3046                         if In_Character_Range (CC) then
3047                            C := Get_Character (CC);
3048                            exit when C = ASCII.LF;
3049                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
3050                            Error_Msg_String (Error_Msg_Strlen) := C;
3051                         end if;
3052                      end loop;
3053
3054                      --  Here with one line ready to go
3055
3056                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3057
3058                      --  If this is a warning in a spec, then we want clients
3059                      --  to see the warning, so mark the message with the
3060                      --  special sequence !! to force the warning. In the case
3061                      --  of a package spec, we do not force this if we are in
3062                      --  the private part of the spec.
3063
3064                      if Force then
3065                         if Cont = False then
3066                            Error_Msg_N ("<~!!", Arg1);
3067                            Cont := True;
3068                         else
3069                            Error_Msg_N ("\<~!!", Arg1);
3070                         end if;
3071
3072                      --  Error, rather than warning, or in a body, so we do not
3073                      --  need to force visibility for client (error will be
3074                      --  output in any case, and this is the situation in which
3075                      --  we do not want a client to get a warning, since the
3076                      --  warning is in the body or the spec private part).
3077
3078                      else
3079                         if Cont = False then
3080                            Error_Msg_N ("<~", Arg1);
3081                            Cont := True;
3082                         else
3083                            Error_Msg_N ("\<~", Arg1);
3084                         end if;
3085                      end if;
3086
3087                      exit when Ptr > Len;
3088                   end loop;
3089                end;
3090             end if;
3091          end if;
3092       end Process_Compile_Time_Warning_Or_Error;
3093
3094       ------------------------
3095       -- Process_Convention --
3096       ------------------------
3097
3098       procedure Process_Convention
3099         (C   : out Convention_Id;
3100          Ent : out Entity_Id)
3101       is
3102          Id        : Node_Id;
3103          E         : Entity_Id;
3104          E1        : Entity_Id;
3105          Cname     : Name_Id;
3106          Comp_Unit : Unit_Number_Type;
3107
3108          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3109          --  Called if we have more than one Export/Import/Convention pragma.
3110          --  This is generally illegal, but we have a special case of allowing
3111          --  Import and Interface to coexist if they specify the convention in
3112          --  a consistent manner. We are allowed to do this, since Interface is
3113          --  an implementation defined pragma, and we choose to do it since we
3114          --  know Rational allows this combination. S is the entity id of the
3115          --  subprogram in question. This procedure also sets the special flag
3116          --  Import_Interface_Present in both pragmas in the case where we do
3117          --  have matching Import and Interface pragmas.
3118
3119          procedure Set_Convention_From_Pragma (E : Entity_Id);
3120          --  Set convention in entity E, and also flag that the entity has a
3121          --  convention pragma. If entity is for a private or incomplete type,
3122          --  also set convention and flag on underlying type. This procedure
3123          --  also deals with the special case of C_Pass_By_Copy convention.
3124
3125          -------------------------------
3126          -- Diagnose_Multiple_Pragmas --
3127          -------------------------------
3128
3129          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3130             Pdec : constant Node_Id := Declaration_Node (S);
3131             Decl : Node_Id;
3132             Err  : Boolean;
3133
3134             function Same_Convention (Decl : Node_Id) return Boolean;
3135             --  Decl is a pragma node. This function returns True if this
3136             --  pragma has a first argument that is an identifier with a
3137             --  Chars field corresponding to the Convention_Id C.
3138
3139             function Same_Name (Decl : Node_Id) return Boolean;
3140             --  Decl is a pragma node. This function returns True if this
3141             --  pragma has a second argument that is an identifier with a
3142             --  Chars field that matches the Chars of the current subprogram.
3143
3144             ---------------------
3145             -- Same_Convention --
3146             ---------------------
3147
3148             function Same_Convention (Decl : Node_Id) return Boolean is
3149                Arg1 : constant Node_Id :=
3150                         First (Pragma_Argument_Associations (Decl));
3151
3152             begin
3153                if Present (Arg1) then
3154                   declare
3155                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3156                   begin
3157                      if Nkind (Arg) = N_Identifier
3158                        and then Is_Convention_Name (Chars (Arg))
3159                        and then Get_Convention_Id (Chars (Arg)) = C
3160                      then
3161                         return True;
3162                      end if;
3163                   end;
3164                end if;
3165
3166                return False;
3167             end Same_Convention;
3168
3169             ---------------
3170             -- Same_Name --
3171             ---------------
3172
3173             function Same_Name (Decl : Node_Id) return Boolean is
3174                Arg1 : constant Node_Id :=
3175                         First (Pragma_Argument_Associations (Decl));
3176                Arg2 : Node_Id;
3177
3178             begin
3179                if No (Arg1) then
3180                   return False;
3181                end if;
3182
3183                Arg2 := Next (Arg1);
3184
3185                if No (Arg2) then
3186                   return False;
3187                end if;
3188
3189                declare
3190                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3191                begin
3192                   if Nkind (Arg) = N_Identifier
3193                     and then Chars (Arg) = Chars (S)
3194                   then
3195                      return True;
3196                   end if;
3197                end;
3198
3199                return False;
3200             end Same_Name;
3201
3202          --  Start of processing for Diagnose_Multiple_Pragmas
3203
3204          begin
3205             Err := True;
3206
3207             --  Definitely give message if we have Convention/Export here
3208
3209             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3210                null;
3211
3212                --  If we have an Import or Export, scan back from pragma to
3213                --  find any previous pragma applying to the same procedure.
3214                --  The scan will be terminated by the start of the list, or
3215                --  hitting the subprogram declaration. This won't allow one
3216                --  pragma to appear in the public part and one in the private
3217                --  part, but that seems very unlikely in practice.
3218
3219             else
3220                Decl := Prev (N);
3221                while Present (Decl) and then Decl /= Pdec loop
3222
3223                   --  Look for pragma with same name as us
3224
3225                   if Nkind (Decl) = N_Pragma
3226                     and then Same_Name (Decl)
3227                   then
3228                      --  Give error if same as our pragma or Export/Convention
3229
3230                      if Pragma_Name (Decl) = Name_Export
3231                           or else
3232                         Pragma_Name (Decl) = Name_Convention
3233                           or else
3234                         Pragma_Name (Decl) = Pragma_Name (N)
3235                      then
3236                         exit;
3237
3238                      --  Case of Import/Interface or the other way round
3239
3240                      elsif Pragma_Name (Decl) = Name_Interface
3241                              or else
3242                            Pragma_Name (Decl) = Name_Import
3243                      then
3244                         --  Here we know that we have Import and Interface. It
3245                         --  doesn't matter which way round they are. See if
3246                         --  they specify the same convention. If so, all OK,
3247                         --  and set special flags to stop other messages
3248
3249                         if Same_Convention (Decl) then
3250                            Set_Import_Interface_Present (N);
3251                            Set_Import_Interface_Present (Decl);
3252                            Err := False;
3253
3254                         --  If different conventions, special message
3255
3256                         else
3257                            Error_Msg_Sloc := Sloc (Decl);
3258                            Error_Pragma_Arg
3259                              ("convention differs from that given#", Arg1);
3260                            return;
3261                         end if;
3262                      end if;
3263                   end if;
3264
3265                   Next (Decl);
3266                end loop;
3267             end if;
3268
3269             --  Give message if needed if we fall through those tests
3270
3271             if Err then
3272                Error_Pragma_Arg
3273                  ("at most one Convention/Export/Import pragma is allowed",
3274                   Arg2);
3275             end if;
3276          end Diagnose_Multiple_Pragmas;
3277
3278          --------------------------------
3279          -- Set_Convention_From_Pragma --
3280          --------------------------------
3281
3282          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3283          begin
3284             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3285             --  for an overridden dispatching operation. Technically this is
3286             --  an amendment and should only be done in Ada 2005 mode. However,
3287             --  this is clearly a mistake, since the problem that is addressed
3288             --  by this AI is that there is a clear gap in the RM!
3289
3290             if Is_Dispatching_Operation (E)
3291               and then Present (Overridden_Operation (E))
3292               and then C /= Convention (Overridden_Operation (E))
3293             then
3294                Error_Pragma_Arg
3295                  ("cannot change convention for " &
3296                   "overridden dispatching operation",
3297                   Arg1);
3298             end if;
3299
3300             --  Set the convention
3301
3302             Set_Convention (E, C);
3303             Set_Has_Convention_Pragma (E);
3304
3305             if Is_Incomplete_Or_Private_Type (E)
3306               and then Present (Underlying_Type (E))
3307             then
3308                Set_Convention            (Underlying_Type (E), C);
3309                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3310             end if;
3311
3312             --  A class-wide type should inherit the convention of the specific
3313             --  root type (although this isn't specified clearly by the RM).
3314
3315             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3316                Set_Convention (Class_Wide_Type (E), C);
3317             end if;
3318
3319             --  If the entity is a record type, then check for special case of
3320             --  C_Pass_By_Copy, which is treated the same as C except that the
3321             --  special record flag is set. This convention is only permitted
3322             --  on record types (see AI95-00131).
3323
3324             if Cname = Name_C_Pass_By_Copy then
3325                if Is_Record_Type (E) then
3326                   Set_C_Pass_By_Copy (Base_Type (E));
3327                elsif Is_Incomplete_Or_Private_Type (E)
3328                  and then Is_Record_Type (Underlying_Type (E))
3329                then
3330                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3331                else
3332                   Error_Pragma_Arg
3333                     ("C_Pass_By_Copy convention allowed only for record type",
3334                      Arg2);
3335                end if;
3336             end if;
3337
3338             --  If the entity is a derived boolean type, check for the special
3339             --  case of convention C, C++, or Fortran, where we consider any
3340             --  nonzero value to represent true.
3341
3342             if Is_Discrete_Type (E)
3343               and then Root_Type (Etype (E)) = Standard_Boolean
3344               and then
3345                 (C = Convention_C
3346                    or else
3347                  C = Convention_CPP
3348                    or else
3349                  C = Convention_Fortran)
3350             then
3351                Set_Nonzero_Is_True (Base_Type (E));
3352             end if;
3353          end Set_Convention_From_Pragma;
3354
3355       --  Start of processing for Process_Convention
3356
3357       begin
3358          Check_At_Least_N_Arguments (2);
3359          Check_Optional_Identifier (Arg1, Name_Convention);
3360          Check_Arg_Is_Identifier (Arg1);
3361          Cname := Chars (Get_Pragma_Arg (Arg1));
3362
3363          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3364          --  tested again below to set the critical flag).
3365
3366          if Cname = Name_C_Pass_By_Copy then
3367             C := Convention_C;
3368
3369          --  Otherwise we must have something in the standard convention list
3370
3371          elsif Is_Convention_Name (Cname) then
3372             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3373
3374          --  In DEC VMS, it seems that there is an undocumented feature that
3375          --  any unrecognized convention is treated as the default, which for
3376          --  us is convention C. It does not seem so terrible to do this
3377          --  unconditionally, silently in the VMS case, and with a warning
3378          --  in the non-VMS case.
3379
3380          else
3381             if Warn_On_Export_Import and not OpenVMS_On_Target then
3382                Error_Msg_N
3383                  ("?unrecognized convention name, C assumed",
3384                   Get_Pragma_Arg (Arg1));
3385             end if;
3386
3387             C := Convention_C;
3388          end if;
3389
3390          Check_Optional_Identifier (Arg2, Name_Entity);
3391          Check_Arg_Is_Local_Name (Arg2);
3392
3393          Id := Get_Pragma_Arg (Arg2);
3394          Analyze (Id);
3395
3396          if not Is_Entity_Name (Id) then
3397             Error_Pragma_Arg ("entity name required", Arg2);
3398          end if;
3399
3400          E := Entity (Id);
3401
3402          --  Set entity to return
3403
3404          Ent := E;
3405
3406          --  Ada_Pass_By_Copy special checking
3407
3408          if C = Convention_Ada_Pass_By_Copy then
3409             if not Is_First_Subtype (E) then
3410                Error_Pragma_Arg
3411                  ("convention `Ada_Pass_By_Copy` only "
3412                   & "allowed for types", Arg2);
3413             end if;
3414
3415             if Is_By_Reference_Type (E) then
3416                Error_Pragma_Arg
3417                  ("convention `Ada_Pass_By_Copy` not allowed for "
3418                   & "by-reference type", Arg1);
3419             end if;
3420          end if;
3421
3422          --  Ada_Pass_By_Reference special checking
3423
3424          if C = Convention_Ada_Pass_By_Reference then
3425             if not Is_First_Subtype (E) then
3426                Error_Pragma_Arg
3427                  ("convention `Ada_Pass_By_Reference` only "
3428                   & "allowed for types", Arg2);
3429             end if;
3430
3431             if Is_By_Copy_Type (E) then
3432                Error_Pragma_Arg
3433                  ("convention `Ada_Pass_By_Reference` not allowed for "
3434                   & "by-copy type", Arg1);
3435             end if;
3436          end if;
3437
3438          --  Go to renamed subprogram if present, since convention applies to
3439          --  the actual renamed entity, not to the renaming entity. If the
3440          --  subprogram is inherited, go to parent subprogram.
3441
3442          if Is_Subprogram (E)
3443            and then Present (Alias (E))
3444          then
3445             if Nkind (Parent (Declaration_Node (E))) =
3446                                        N_Subprogram_Renaming_Declaration
3447             then
3448                if Scope (E) /= Scope (Alias (E)) then
3449                   Error_Pragma_Ref
3450                     ("cannot apply pragma% to non-local entity&#", E);
3451                end if;
3452
3453                E := Alias (E);
3454
3455             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3456                                         N_Private_Extension_Declaration)
3457               and then Scope (E) = Scope (Alias (E))
3458             then
3459                E := Alias (E);
3460
3461                --  Return the parent subprogram the entity was inherited from
3462
3463                Ent := E;
3464             end if;
3465          end if;
3466
3467          --  Check that we are not applying this to a specless body
3468
3469          if Is_Subprogram (E)
3470            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3471          then
3472             Error_Pragma
3473               ("pragma% requires separate spec and must come before body");
3474          end if;
3475
3476          --  Check that we are not applying this to a named constant
3477
3478          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3479             Error_Msg_Name_1 := Pname;
3480             Error_Msg_N
3481               ("cannot apply pragma% to named constant!",
3482                Get_Pragma_Arg (Arg2));
3483             Error_Pragma_Arg
3484               ("\supply appropriate type for&!", Arg2);
3485          end if;
3486
3487          if Ekind (E) = E_Enumeration_Literal then
3488             Error_Pragma ("enumeration literal not allowed for pragma%");
3489          end if;
3490
3491          --  Check for rep item appearing too early or too late
3492
3493          if Etype (E) = Any_Type
3494            or else Rep_Item_Too_Early (E, N)
3495          then
3496             raise Pragma_Exit;
3497
3498          elsif Present (Underlying_Type (E)) then
3499             E := Underlying_Type (E);
3500          end if;
3501
3502          if Rep_Item_Too_Late (E, N) then
3503             raise Pragma_Exit;
3504          end if;
3505
3506          if Has_Convention_Pragma (E) then
3507             Diagnose_Multiple_Pragmas (E);
3508
3509          elsif Convention (E) = Convention_Protected
3510            or else Ekind (Scope (E)) = E_Protected_Type
3511          then
3512             Error_Pragma_Arg
3513               ("a protected operation cannot be given a different convention",
3514                 Arg2);
3515          end if;
3516
3517          --  For Intrinsic, a subprogram is required
3518
3519          if C = Convention_Intrinsic
3520            and then not Is_Subprogram (E)
3521            and then not Is_Generic_Subprogram (E)
3522          then
3523             Error_Pragma_Arg
3524               ("second argument of pragma% must be a subprogram", Arg2);
3525          end if;
3526
3527          --  For Stdcall, a subprogram, variable or subprogram type is required
3528
3529          if C = Convention_Stdcall
3530            and then
3531              ((not Is_Subprogram (E) and then not Is_Generic_Subprogram (E))
3532                 or else Is_Dispatching_Operation (E))
3533            and then Ekind (E) /= E_Variable
3534            and then not
3535              (Is_Access_Type (E)
3536                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3537          then
3538             Error_Pragma_Arg
3539               ("second argument of pragma% must be subprogram (type)",
3540                Arg2);
3541          end if;
3542
3543          if not Is_Subprogram (E)
3544            and then not Is_Generic_Subprogram (E)
3545          then
3546             Set_Convention_From_Pragma (E);
3547
3548             if Is_Type (E) then
3549                Check_First_Subtype (Arg2);
3550                Set_Convention_From_Pragma (Base_Type (E));
3551
3552                --  For subprograms, we must set the convention on the
3553                --  internally generated directly designated type as well.
3554
3555                if Ekind (E) = E_Access_Subprogram_Type then
3556                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3557                end if;
3558             end if;
3559
3560          --  For the subprogram case, set proper convention for all homonyms
3561          --  in same scope and the same declarative part, i.e. the same
3562          --  compilation unit.
3563
3564          else
3565             Comp_Unit := Get_Source_Unit (E);
3566             Set_Convention_From_Pragma (E);
3567
3568             --  Treat a pragma Import as an implicit body, for GPS use
3569
3570             if Prag_Id = Pragma_Import then
3571                Generate_Reference (E, Id, 'b');
3572             end if;
3573
3574             --  Loop through the homonyms of the pragma argument's entity
3575
3576             E1 := Ent;
3577             loop
3578                E1 := Homonym (E1);
3579                exit when No (E1) or else Scope (E1) /= Current_Scope;
3580
3581                --  Do not set the pragma on inherited operations or on formal
3582                --  subprograms.
3583
3584                if Comes_From_Source (E1)
3585                  and then Comp_Unit = Get_Source_Unit (E1)
3586                  and then not Is_Formal_Subprogram (E1)
3587                  and then Nkind (Original_Node (Parent (E1))) /=
3588                                                     N_Full_Type_Declaration
3589                then
3590                   if Present (Alias (E1))
3591                     and then Scope (E1) /= Scope (Alias (E1))
3592                   then
3593                      Error_Pragma_Ref
3594                        ("cannot apply pragma% to non-local entity& declared#",
3595                         E1);
3596                   end if;
3597
3598                   Set_Convention_From_Pragma (E1);
3599
3600                   if Prag_Id = Pragma_Import then
3601                      Generate_Reference (E1, Id, 'b');
3602                   end if;
3603                end if;
3604
3605                --  For aspect case, do NOT apply to homonyms
3606
3607                exit when From_Aspect_Specification (N);
3608             end loop;
3609          end if;
3610       end Process_Convention;
3611
3612       ----------------------------------------
3613       -- Process_Disable_Enable_Atomic_Sync --
3614       ----------------------------------------
3615
3616       procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3617       begin
3618          GNAT_Pragma;
3619          Check_No_Identifiers;
3620          Check_At_Most_N_Arguments (1);
3621
3622          --  Modeled internally as
3623          --    pragma Unsuppress (Atomic_Synchronization [,Entity])
3624
3625          Rewrite (N,
3626            Make_Pragma (Loc,
3627              Pragma_Identifier            =>
3628                Make_Identifier (Loc, Nam),
3629              Pragma_Argument_Associations => New_List (
3630                Make_Pragma_Argument_Association (Loc,
3631                  Expression =>
3632                    Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3633
3634          if Present (Arg1) then
3635             Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3636          end if;
3637
3638          Analyze (N);
3639       end Process_Disable_Enable_Atomic_Sync;
3640
3641       -----------------------------------------------------
3642       -- Process_Extended_Import_Export_Exception_Pragma --
3643       -----------------------------------------------------
3644
3645       procedure Process_Extended_Import_Export_Exception_Pragma
3646         (Arg_Internal : Node_Id;
3647          Arg_External : Node_Id;
3648          Arg_Form     : Node_Id;
3649          Arg_Code     : Node_Id)
3650       is
3651          Def_Id   : Entity_Id;
3652          Code_Val : Uint;
3653
3654       begin
3655          if not OpenVMS_On_Target then
3656             Error_Pragma
3657               ("?pragma% ignored (applies only to Open'V'M'S)");
3658          end if;
3659
3660          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3661          Def_Id := Entity (Arg_Internal);
3662
3663          if Ekind (Def_Id) /= E_Exception then
3664             Error_Pragma_Arg
3665               ("pragma% must refer to declared exception", Arg_Internal);
3666          end if;
3667
3668          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3669
3670          if Present (Arg_Form) then
3671             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3672          end if;
3673
3674          if Present (Arg_Form)
3675            and then Chars (Arg_Form) = Name_Ada
3676          then
3677             null;
3678          else
3679             Set_Is_VMS_Exception (Def_Id);
3680             Set_Exception_Code (Def_Id, No_Uint);
3681          end if;
3682
3683          if Present (Arg_Code) then
3684             if not Is_VMS_Exception (Def_Id) then
3685                Error_Pragma_Arg
3686                  ("Code option for pragma% not allowed for Ada case",
3687                   Arg_Code);
3688             end if;
3689
3690             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3691             Code_Val := Expr_Value (Arg_Code);
3692
3693             if not UI_Is_In_Int_Range (Code_Val) then
3694                Error_Pragma_Arg
3695                  ("Code option for pragma% must be in 32-bit range",
3696                   Arg_Code);
3697
3698             else
3699                Set_Exception_Code (Def_Id, Code_Val);
3700             end if;
3701          end if;
3702       end Process_Extended_Import_Export_Exception_Pragma;
3703
3704       -------------------------------------------------
3705       -- Process_Extended_Import_Export_Internal_Arg --
3706       -------------------------------------------------
3707
3708       procedure Process_Extended_Import_Export_Internal_Arg
3709         (Arg_Internal : Node_Id := Empty)
3710       is
3711       begin
3712          if No (Arg_Internal) then
3713             Error_Pragma ("Internal parameter required for pragma%");
3714          end if;
3715
3716          if Nkind (Arg_Internal) = N_Identifier then
3717             null;
3718
3719          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3720            and then (Prag_Id = Pragma_Import_Function
3721                        or else
3722                      Prag_Id = Pragma_Export_Function)
3723          then
3724             null;
3725
3726          else
3727             Error_Pragma_Arg
3728               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3729          end if;
3730
3731          Check_Arg_Is_Local_Name (Arg_Internal);
3732       end Process_Extended_Import_Export_Internal_Arg;
3733
3734       --------------------------------------------------
3735       -- Process_Extended_Import_Export_Object_Pragma --
3736       --------------------------------------------------
3737
3738       procedure Process_Extended_Import_Export_Object_Pragma
3739         (Arg_Internal : Node_Id;
3740          Arg_External : Node_Id;
3741          Arg_Size     : Node_Id)
3742       is
3743          Def_Id : Entity_Id;
3744
3745       begin
3746          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3747          Def_Id := Entity (Arg_Internal);
3748
3749          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3750             Error_Pragma_Arg
3751               ("pragma% must designate an object", Arg_Internal);
3752          end if;
3753
3754          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3755               or else
3756             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3757          then
3758             Error_Pragma_Arg
3759               ("previous Common/Psect_Object applies, pragma % not permitted",
3760                Arg_Internal);
3761          end if;
3762
3763          if Rep_Item_Too_Late (Def_Id, N) then
3764             raise Pragma_Exit;
3765          end if;
3766
3767          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3768
3769          if Present (Arg_Size) then
3770             Check_Arg_Is_External_Name (Arg_Size);
3771          end if;
3772
3773          --  Export_Object case
3774
3775          if Prag_Id = Pragma_Export_Object then
3776             if not Is_Library_Level_Entity (Def_Id) then
3777                Error_Pragma_Arg
3778                  ("argument for pragma% must be library level entity",
3779                   Arg_Internal);
3780             end if;
3781
3782             if Ekind (Current_Scope) = E_Generic_Package then
3783                Error_Pragma ("pragma& cannot appear in a generic unit");
3784             end if;
3785
3786             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3787                Error_Pragma_Arg
3788                  ("exported object must have compile time known size",
3789                   Arg_Internal);
3790             end if;
3791
3792             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3793                Error_Msg_N ("?duplicate Export_Object pragma", N);
3794             else
3795                Set_Exported (Def_Id, Arg_Internal);
3796             end if;
3797
3798          --  Import_Object case
3799
3800          else
3801             if Is_Concurrent_Type (Etype (Def_Id)) then
3802                Error_Pragma_Arg
3803                  ("cannot use pragma% for task/protected object",
3804                   Arg_Internal);
3805             end if;
3806
3807             if Ekind (Def_Id) = E_Constant then
3808                Error_Pragma_Arg
3809                  ("cannot import a constant", Arg_Internal);
3810             end if;
3811
3812             if Warn_On_Export_Import
3813               and then Has_Discriminants (Etype (Def_Id))
3814             then
3815                Error_Msg_N
3816                  ("imported value must be initialized?", Arg_Internal);
3817             end if;
3818
3819             if Warn_On_Export_Import
3820               and then Is_Access_Type (Etype (Def_Id))
3821             then
3822                Error_Pragma_Arg
3823                  ("cannot import object of an access type?", Arg_Internal);
3824             end if;
3825
3826             if Warn_On_Export_Import
3827               and then Is_Imported (Def_Id)
3828             then
3829                Error_Msg_N
3830                  ("?duplicate Import_Object pragma", N);
3831
3832             --  Check for explicit initialization present. Note that an
3833             --  initialization generated by the code generator, e.g. for an
3834             --  access type, does not count here.
3835
3836             elsif Present (Expression (Parent (Def_Id)))
3837                and then
3838                  Comes_From_Source
3839                    (Original_Node (Expression (Parent (Def_Id))))
3840             then
3841                Error_Msg_Sloc := Sloc (Def_Id);
3842                Error_Pragma_Arg
3843                  ("imported entities cannot be initialized (RM B.1(24))",
3844                   "\no initialization allowed for & declared#", Arg1);
3845             else
3846                Set_Imported (Def_Id);
3847                Note_Possible_Modification (Arg_Internal, Sure => False);
3848             end if;
3849          end if;
3850       end Process_Extended_Import_Export_Object_Pragma;
3851
3852       ------------------------------------------------------
3853       -- Process_Extended_Import_Export_Subprogram_Pragma --
3854       ------------------------------------------------------
3855
3856       procedure Process_Extended_Import_Export_Subprogram_Pragma
3857         (Arg_Internal                 : Node_Id;
3858          Arg_External                 : Node_Id;
3859          Arg_Parameter_Types          : Node_Id;
3860          Arg_Result_Type              : Node_Id := Empty;
3861          Arg_Mechanism                : Node_Id;
3862          Arg_Result_Mechanism         : Node_Id := Empty;
3863          Arg_First_Optional_Parameter : Node_Id := Empty)
3864       is
3865          Ent       : Entity_Id;
3866          Def_Id    : Entity_Id;
3867          Hom_Id    : Entity_Id;
3868          Formal    : Entity_Id;
3869          Ambiguous : Boolean;
3870          Match     : Boolean;
3871          Dval      : Node_Id;
3872
3873          function Same_Base_Type
3874           (Ptype  : Node_Id;
3875            Formal : Entity_Id) return Boolean;
3876          --  Determines if Ptype references the type of Formal. Note that only
3877          --  the base types need to match according to the spec. Ptype here is
3878          --  the argument from the pragma, which is either a type name, or an
3879          --  access attribute.
3880
3881          --------------------
3882          -- Same_Base_Type --
3883          --------------------
3884
3885          function Same_Base_Type
3886            (Ptype  : Node_Id;
3887             Formal : Entity_Id) return Boolean
3888          is
3889             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3890             Pref : Node_Id;
3891
3892          begin
3893             --  Case where pragma argument is typ'Access
3894
3895             if Nkind (Ptype) = N_Attribute_Reference
3896               and then Attribute_Name (Ptype) = Name_Access
3897             then
3898                Pref := Prefix (Ptype);
3899                Find_Type (Pref);
3900
3901                if not Is_Entity_Name (Pref)
3902                  or else Entity (Pref) = Any_Type
3903                then
3904                   raise Pragma_Exit;
3905                end if;
3906
3907                --  We have a match if the corresponding argument is of an
3908                --  anonymous access type, and its designated type matches the
3909                --  type of the prefix of the access attribute
3910
3911                return Ekind (Ftyp) = E_Anonymous_Access_Type
3912                  and then Base_Type (Entity (Pref)) =
3913                             Base_Type (Etype (Designated_Type (Ftyp)));
3914
3915             --  Case where pragma argument is a type name
3916
3917             else
3918                Find_Type (Ptype);
3919
3920                if not Is_Entity_Name (Ptype)
3921                  or else Entity (Ptype) = Any_Type
3922                then
3923                   raise Pragma_Exit;
3924                end if;
3925
3926                --  We have a match if the corresponding argument is of the type
3927                --  given in the pragma (comparing base types)
3928
3929                return Base_Type (Entity (Ptype)) = Ftyp;
3930             end if;
3931          end Same_Base_Type;
3932
3933       --  Start of processing for
3934       --  Process_Extended_Import_Export_Subprogram_Pragma
3935
3936       begin
3937          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3938          Ent := Empty;
3939          Ambiguous := False;
3940
3941          --  Loop through homonyms (overloadings) of the entity
3942
3943          Hom_Id := Entity (Arg_Internal);
3944          while Present (Hom_Id) loop
3945             Def_Id := Get_Base_Subprogram (Hom_Id);
3946
3947             --  We need a subprogram in the current scope
3948
3949             if not Is_Subprogram (Def_Id)
3950               or else Scope (Def_Id) /= Current_Scope
3951             then
3952                null;
3953
3954             else
3955                Match := True;
3956
3957                --  Pragma cannot apply to subprogram body
3958
3959                if Is_Subprogram (Def_Id)
3960                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3961                                                              N_Subprogram_Body
3962                then
3963                   Error_Pragma
3964                     ("pragma% requires separate spec"
3965                       & " and must come before body");
3966                end if;
3967
3968                --  Test result type if given, note that the result type
3969                --  parameter can only be present for the function cases.
3970
3971                if Present (Arg_Result_Type)
3972                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3973                then
3974                   Match := False;
3975
3976                elsif Etype (Def_Id) /= Standard_Void_Type
3977                  and then
3978                    (Pname = Name_Export_Procedure
3979                       or else
3980                     Pname = Name_Import_Procedure)
3981                then
3982                   Match := False;
3983
3984                --  Test parameter types if given. Note that this parameter
3985                --  has not been analyzed (and must not be, since it is
3986                --  semantic nonsense), so we get it as the parser left it.
3987
3988                elsif Present (Arg_Parameter_Types) then
3989                   Check_Matching_Types : declare
3990                      Formal : Entity_Id;
3991                      Ptype  : Node_Id;
3992
3993                   begin
3994                      Formal := First_Formal (Def_Id);
3995
3996                      if Nkind (Arg_Parameter_Types) = N_Null then
3997                         if Present (Formal) then
3998                            Match := False;
3999                         end if;
4000
4001                      --  A list of one type, e.g. (List) is parsed as
4002                      --  a parenthesized expression.
4003
4004                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4005                        and then Paren_Count (Arg_Parameter_Types) = 1
4006                      then
4007                         if No (Formal)
4008                           or else Present (Next_Formal (Formal))
4009                         then
4010                            Match := False;
4011                         else
4012                            Match :=
4013                              Same_Base_Type (Arg_Parameter_Types, Formal);
4014                         end if;
4015
4016                      --  A list of more than one type is parsed as a aggregate
4017
4018                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4019                        and then Paren_Count (Arg_Parameter_Types) = 0
4020                      then
4021                         Ptype := First (Expressions (Arg_Parameter_Types));
4022                         while Present (Ptype) or else Present (Formal) loop
4023                            if No (Ptype)
4024                              or else No (Formal)
4025                              or else not Same_Base_Type (Ptype, Formal)
4026                            then
4027                               Match := False;
4028                               exit;
4029                            else
4030                               Next_Formal (Formal);
4031                               Next (Ptype);
4032                            end if;
4033                         end loop;
4034
4035                      --  Anything else is of the wrong form
4036
4037                      else
4038                         Error_Pragma_Arg
4039                           ("wrong form for Parameter_Types parameter",
4040                            Arg_Parameter_Types);
4041                      end if;
4042                   end Check_Matching_Types;
4043                end if;
4044
4045                --  Match is now False if the entry we found did not match
4046                --  either a supplied Parameter_Types or Result_Types argument
4047
4048                if Match then
4049                   if No (Ent) then
4050                      Ent := Def_Id;
4051
4052                   --  Ambiguous case, the flag Ambiguous shows if we already
4053                   --  detected this and output the initial messages.
4054
4055                   else
4056                      if not Ambiguous then
4057                         Ambiguous := True;
4058                         Error_Msg_Name_1 := Pname;
4059                         Error_Msg_N
4060                           ("pragma% does not uniquely identify subprogram!",
4061                            N);
4062                         Error_Msg_Sloc := Sloc (Ent);
4063                         Error_Msg_N ("matching subprogram #!", N);
4064                         Ent := Empty;
4065                      end if;
4066
4067                      Error_Msg_Sloc := Sloc (Def_Id);
4068                      Error_Msg_N ("matching subprogram #!", N);
4069                   end if;
4070                end if;
4071             end if;
4072
4073             Hom_Id := Homonym (Hom_Id);
4074          end loop;
4075
4076          --  See if we found an entry
4077
4078          if No (Ent) then
4079             if not Ambiguous then
4080                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4081                   Error_Pragma
4082                     ("pragma% cannot be given for generic subprogram");
4083                else
4084                   Error_Pragma
4085                     ("pragma% does not identify local subprogram");
4086                end if;
4087             end if;
4088
4089             return;
4090          end if;
4091
4092          --  Import pragmas must be for imported entities
4093
4094          if Prag_Id = Pragma_Import_Function
4095               or else
4096             Prag_Id = Pragma_Import_Procedure
4097               or else
4098             Prag_Id = Pragma_Import_Valued_Procedure
4099          then
4100             if not Is_Imported (Ent) then
4101                Error_Pragma
4102                  ("pragma Import or Interface must precede pragma%");
4103             end if;
4104
4105          --  Here we have the Export case which can set the entity as exported
4106
4107          --  But does not do so if the specified external name is null, since
4108          --  that is taken as a signal in DEC Ada 83 (with which we want to be
4109          --  compatible) to request no external name.
4110
4111          elsif Nkind (Arg_External) = N_String_Literal
4112            and then String_Length (Strval (Arg_External)) = 0
4113          then
4114             null;
4115
4116          --  In all other cases, set entity as exported
4117
4118          else
4119             Set_Exported (Ent, Arg_Internal);
4120          end if;
4121
4122          --  Special processing for Valued_Procedure cases
4123
4124          if Prag_Id = Pragma_Import_Valued_Procedure
4125            or else
4126             Prag_Id = Pragma_Export_Valued_Procedure
4127          then
4128             Formal := First_Formal (Ent);
4129
4130             if No (Formal) then
4131                Error_Pragma ("at least one parameter required for pragma%");
4132
4133             elsif Ekind (Formal) /= E_Out_Parameter then
4134                Error_Pragma ("first parameter must have mode out for pragma%");
4135
4136             else
4137                Set_Is_Valued_Procedure (Ent);
4138             end if;
4139          end if;
4140
4141          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4142
4143          --  Process Result_Mechanism argument if present. We have already
4144          --  checked that this is only allowed for the function case.
4145
4146          if Present (Arg_Result_Mechanism) then
4147             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4148          end if;
4149
4150          --  Process Mechanism parameter if present. Note that this parameter
4151          --  is not analyzed, and must not be analyzed since it is semantic
4152          --  nonsense, so we get it in exactly as the parser left it.
4153
4154          if Present (Arg_Mechanism) then
4155             declare
4156                Formal : Entity_Id;
4157                Massoc : Node_Id;
4158                Mname  : Node_Id;
4159                Choice : Node_Id;
4160
4161             begin
4162                --  A single mechanism association without a formal parameter
4163                --  name is parsed as a parenthesized expression. All other
4164                --  cases are parsed as aggregates, so we rewrite the single
4165                --  parameter case as an aggregate for consistency.
4166
4167                if Nkind (Arg_Mechanism) /= N_Aggregate
4168                  and then Paren_Count (Arg_Mechanism) = 1
4169                then
4170                   Rewrite (Arg_Mechanism,
4171                     Make_Aggregate (Sloc (Arg_Mechanism),
4172                       Expressions => New_List (
4173                         Relocate_Node (Arg_Mechanism))));
4174                end if;
4175
4176                --  Case of only mechanism name given, applies to all formals
4177
4178                if Nkind (Arg_Mechanism) /= N_Aggregate then
4179                   Formal := First_Formal (Ent);
4180                   while Present (Formal) loop
4181                      Set_Mechanism_Value (Formal, Arg_Mechanism);
4182                      Next_Formal (Formal);
4183                   end loop;
4184
4185                --  Case of list of mechanism associations given
4186
4187                else
4188                   if Null_Record_Present (Arg_Mechanism) then
4189                      Error_Pragma_Arg
4190                        ("inappropriate form for Mechanism parameter",
4191                         Arg_Mechanism);
4192                   end if;
4193
4194                   --  Deal with positional ones first
4195
4196                   Formal := First_Formal (Ent);
4197
4198                   if Present (Expressions (Arg_Mechanism)) then
4199                      Mname := First (Expressions (Arg_Mechanism));
4200                      while Present (Mname) loop
4201                         if No (Formal) then
4202                            Error_Pragma_Arg
4203                              ("too many mechanism associations", Mname);
4204                         end if;
4205
4206                         Set_Mechanism_Value (Formal, Mname);
4207                         Next_Formal (Formal);
4208                         Next (Mname);
4209                      end loop;
4210                   end if;
4211
4212                   --  Deal with named entries
4213
4214                   if Present (Component_Associations (Arg_Mechanism)) then
4215                      Massoc := First (Component_Associations (Arg_Mechanism));
4216                      while Present (Massoc) loop
4217                         Choice := First (Choices (Massoc));
4218
4219                         if Nkind (Choice) /= N_Identifier
4220                           or else Present (Next (Choice))
4221                         then
4222                            Error_Pragma_Arg
4223                              ("incorrect form for mechanism association",
4224                               Massoc);
4225                         end if;
4226
4227                         Formal := First_Formal (Ent);
4228                         loop
4229                            if No (Formal) then
4230                               Error_Pragma_Arg
4231                                 ("parameter name & not present", Choice);
4232                            end if;
4233
4234                            if Chars (Choice) = Chars (Formal) then
4235                               Set_Mechanism_Value
4236                                 (Formal, Expression (Massoc));
4237
4238                               --  Set entity on identifier (needed by ASIS)
4239
4240                               Set_Entity (Choice, Formal);
4241
4242                               exit;
4243                            end if;
4244
4245                            Next_Formal (Formal);
4246                         end loop;
4247
4248                         Next (Massoc);
4249                      end loop;
4250                   end if;
4251                end if;
4252             end;
4253          end if;
4254
4255          --  Process First_Optional_Parameter argument if present. We have
4256          --  already checked that this is only allowed for the Import case.
4257
4258          if Present (Arg_First_Optional_Parameter) then
4259             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4260                Error_Pragma_Arg
4261                  ("first optional parameter must be formal parameter name",
4262                   Arg_First_Optional_Parameter);
4263             end if;
4264
4265             Formal := First_Formal (Ent);
4266             loop
4267                if No (Formal) then
4268                   Error_Pragma_Arg
4269                     ("specified formal parameter& not found",
4270                      Arg_First_Optional_Parameter);
4271                end if;
4272
4273                exit when Chars (Formal) =
4274                          Chars (Arg_First_Optional_Parameter);
4275
4276                Next_Formal (Formal);
4277             end loop;
4278
4279             Set_First_Optional_Parameter (Ent, Formal);
4280
4281             --  Check specified and all remaining formals have right form
4282
4283             while Present (Formal) loop
4284                if Ekind (Formal) /= E_In_Parameter then
4285                   Error_Msg_NE
4286                     ("optional formal& is not of mode in!",
4287                      Arg_First_Optional_Parameter, Formal);
4288
4289                else
4290                   Dval := Default_Value (Formal);
4291
4292                   if No (Dval) then
4293                      Error_Msg_NE
4294                        ("optional formal& does not have default value!",
4295                         Arg_First_Optional_Parameter, Formal);
4296
4297                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4298                      null;
4299
4300                   else
4301                      Error_Msg_FE
4302                        ("default value for optional formal& is non-static!",
4303                         Arg_First_Optional_Parameter, Formal);
4304                   end if;
4305                end if;
4306
4307                Set_Is_Optional_Parameter (Formal);
4308                Next_Formal (Formal);
4309             end loop;
4310          end if;
4311       end Process_Extended_Import_Export_Subprogram_Pragma;
4312
4313       --------------------------
4314       -- Process_Generic_List --
4315       --------------------------
4316
4317       procedure Process_Generic_List is
4318          Arg : Node_Id;
4319          Exp : Node_Id;
4320
4321       begin
4322          Check_No_Identifiers;
4323          Check_At_Least_N_Arguments (1);
4324
4325          Arg := Arg1;
4326          while Present (Arg) loop
4327             Exp := Get_Pragma_Arg (Arg);
4328             Analyze (Exp);
4329
4330             if not Is_Entity_Name (Exp)
4331               or else
4332                 (not Is_Generic_Instance (Entity (Exp))
4333                   and then
4334                  not Is_Generic_Unit (Entity (Exp)))
4335             then
4336                Error_Pragma_Arg
4337                  ("pragma% argument must be name of generic unit/instance",
4338                   Arg);
4339             end if;
4340
4341             Next (Arg);
4342          end loop;
4343       end Process_Generic_List;
4344
4345       ------------------------------------
4346       -- Process_Import_Predefined_Type --
4347       ------------------------------------
4348
4349       procedure Process_Import_Predefined_Type is
4350          Loc  : constant Source_Ptr := Sloc (N);
4351          Elmt : Elmt_Id;
4352          Ftyp : Node_Id := Empty;
4353          Decl : Node_Id;
4354          Def  : Node_Id;
4355          Nam  : Name_Id;
4356
4357       begin
4358          String_To_Name_Buffer (Strval (Expression (Arg3)));
4359          Nam := Name_Find;
4360
4361          Elmt := First_Elmt (Predefined_Float_Types);
4362          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4363             Next_Elmt (Elmt);
4364          end loop;
4365
4366          Ftyp := Node (Elmt);
4367
4368          if Present (Ftyp) then
4369
4370             --  Don't build a derived type declaration, because predefined C
4371             --  types have no declaration anywhere, so cannot really be named.
4372             --  Instead build a full type declaration, starting with an
4373             --  appropriate type definition is built
4374
4375             if Is_Floating_Point_Type (Ftyp) then
4376                Def := Make_Floating_Point_Definition (Loc,
4377                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4378                  Make_Real_Range_Specification (Loc,
4379                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4380                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4381
4382             --  Should never have a predefined type we cannot handle
4383
4384             else
4385                raise Program_Error;
4386             end if;
4387
4388             --  Build and insert a Full_Type_Declaration, which will be
4389             --  analyzed as soon as this list entry has been analyzed.
4390
4391             Decl := Make_Full_Type_Declaration (Loc,
4392               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4393               Type_Definition => Def);
4394
4395             Insert_After (N, Decl);
4396             Mark_Rewrite_Insertion (Decl);
4397
4398          else
4399             Error_Pragma_Arg ("no matching type found for pragma%",
4400             Arg2);
4401          end if;
4402       end Process_Import_Predefined_Type;
4403
4404       ---------------------------------
4405       -- Process_Import_Or_Interface --
4406       ---------------------------------
4407
4408       procedure Process_Import_Or_Interface is
4409          C      : Convention_Id;
4410          Def_Id : Entity_Id;
4411          Hom_Id : Entity_Id;
4412
4413       begin
4414          Process_Convention (C, Def_Id);
4415          Kill_Size_Check_Code (Def_Id);
4416          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4417
4418          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4419
4420             --  We do not permit Import to apply to a renaming declaration
4421
4422             if Present (Renamed_Object (Def_Id)) then
4423                Error_Pragma_Arg
4424                  ("pragma% not allowed for object renaming", Arg2);
4425
4426             --  User initialization is not allowed for imported object, but
4427             --  the object declaration may contain a default initialization,
4428             --  that will be discarded. Note that an explicit initialization
4429             --  only counts if it comes from source, otherwise it is simply
4430             --  the code generator making an implicit initialization explicit.
4431
4432             elsif Present (Expression (Parent (Def_Id)))
4433               and then Comes_From_Source (Expression (Parent (Def_Id)))
4434             then
4435                Error_Msg_Sloc := Sloc (Def_Id);
4436                Error_Pragma_Arg
4437                  ("no initialization allowed for declaration of& #",
4438                   "\imported entities cannot be initialized (RM B.1(24))",
4439                   Arg2);
4440
4441             else
4442                Set_Imported (Def_Id);
4443                Process_Interface_Name (Def_Id, Arg3, Arg4);
4444
4445                --  Note that we do not set Is_Public here. That's because we
4446                --  only want to set it if there is no address clause, and we
4447                --  don't know that yet, so we delay that processing till
4448                --  freeze time.
4449
4450                --  pragma Import completes deferred constants
4451
4452                if Ekind (Def_Id) = E_Constant then
4453                   Set_Has_Completion (Def_Id);
4454                end if;
4455
4456                --  It is not possible to import a constant of an unconstrained
4457                --  array type (e.g. string) because there is no simple way to
4458                --  write a meaningful subtype for it.
4459
4460                if Is_Array_Type (Etype (Def_Id))
4461                  and then not Is_Constrained (Etype (Def_Id))
4462                then
4463                   Error_Msg_NE
4464                     ("imported constant& must have a constrained subtype",
4465                       N, Def_Id);
4466                end if;
4467             end if;
4468
4469          elsif Is_Subprogram (Def_Id)
4470            or else Is_Generic_Subprogram (Def_Id)
4471          then
4472             --  If the name is overloaded, pragma applies to all of the denoted
4473             --  entities in the same declarative part.
4474
4475             Hom_Id := Def_Id;
4476             while Present (Hom_Id) loop
4477                Def_Id := Get_Base_Subprogram (Hom_Id);
4478
4479                --  Ignore inherited subprograms because the pragma will apply
4480                --  to the parent operation, which is the one called.
4481
4482                if Is_Overloadable (Def_Id)
4483                  and then Present (Alias (Def_Id))
4484                then
4485                   null;
4486
4487                --  If it is not a subprogram, it must be in an outer scope and
4488                --  pragma does not apply.
4489
4490                elsif not Is_Subprogram (Def_Id)
4491                  and then not Is_Generic_Subprogram (Def_Id)
4492                then
4493                   null;
4494
4495                --  The pragma does not apply to primitives of interfaces
4496
4497                elsif Is_Dispatching_Operation (Def_Id)
4498                  and then Present (Find_Dispatching_Type (Def_Id))
4499                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4500                then
4501                   null;
4502
4503                --  Verify that the homonym is in the same declarative part (not
4504                --  just the same scope).
4505
4506                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4507                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4508                then
4509                   exit;
4510
4511                else
4512                   Set_Imported (Def_Id);
4513
4514                   --  Reject an Import applied to an abstract subprogram
4515
4516                   if Is_Subprogram (Def_Id)
4517                     and then Is_Abstract_Subprogram (Def_Id)
4518                   then
4519                      Error_Msg_Sloc := Sloc (Def_Id);
4520                      Error_Msg_NE
4521                        ("cannot import abstract subprogram& declared#",
4522                         Arg2, Def_Id);
4523                   end if;
4524
4525                   --  Special processing for Convention_Intrinsic
4526
4527                   if C = Convention_Intrinsic then
4528
4529                      --  Link_Name argument not allowed for intrinsic
4530
4531                      Check_No_Link_Name;
4532
4533                      Set_Is_Intrinsic_Subprogram (Def_Id);
4534
4535                      --  If no external name is present, then check that this
4536                      --  is a valid intrinsic subprogram. If an external name
4537                      --  is present, then this is handled by the back end.
4538
4539                      if No (Arg3) then
4540                         Check_Intrinsic_Subprogram
4541                           (Def_Id, Get_Pragma_Arg (Arg2));
4542                      end if;
4543                   end if;
4544
4545                   --  All interfaced procedures need an external symbol created
4546                   --  for them since they are always referenced from another
4547                   --  object file.
4548
4549                   Set_Is_Public (Def_Id);
4550
4551                   --  Verify that the subprogram does not have a completion
4552                   --  through a renaming declaration. For other completions the
4553                   --  pragma appears as a too late representation.
4554
4555                   declare
4556                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4557
4558                   begin
4559                      if Present (Decl)
4560                        and then Nkind (Decl) = N_Subprogram_Declaration
4561                        and then Present (Corresponding_Body (Decl))
4562                        and then Nkind (Unit_Declaration_Node
4563                                         (Corresponding_Body (Decl))) =
4564                                              N_Subprogram_Renaming_Declaration
4565                      then
4566                         Error_Msg_Sloc := Sloc (Def_Id);
4567                         Error_Msg_NE
4568                           ("cannot import&, renaming already provided for " &
4569                            "declaration #", N, Def_Id);
4570                      end if;
4571                   end;
4572
4573                   Set_Has_Completion (Def_Id);
4574                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4575                end if;
4576
4577                if Is_Compilation_Unit (Hom_Id) then
4578
4579                   --  Its possible homonyms are not affected by the pragma.
4580                   --  Such homonyms might be present in the context of other
4581                   --  units being compiled.
4582
4583                   exit;
4584
4585                else
4586                   Hom_Id := Homonym (Hom_Id);
4587                end if;
4588             end loop;
4589
4590          --  When the convention is Java or CIL, we also allow Import to be
4591          --  given for packages, generic packages, exceptions, record
4592          --  components, and access to subprograms.
4593
4594          elsif (C = Convention_Java or else C = Convention_CIL)
4595            and then
4596              (Is_Package_Or_Generic_Package (Def_Id)
4597                or else Ekind (Def_Id) = E_Exception
4598                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4599                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4600          then
4601             Set_Imported (Def_Id);
4602             Set_Is_Public (Def_Id);
4603             Process_Interface_Name (Def_Id, Arg3, Arg4);
4604
4605          --  Import a CPP class
4606
4607          elsif Is_Record_Type (Def_Id)
4608            and then C = Convention_CPP
4609          then
4610             --  Types treated as CPP classes must be declared limited (note:
4611             --  this used to be a warning but there is no real benefit to it
4612             --  since we did effectively intend to treat the type as limited
4613             --  anyway).
4614
4615             if not Is_Limited_Type (Def_Id) then
4616                Error_Msg_N
4617                  ("imported 'C'P'P type must be limited",
4618                   Get_Pragma_Arg (Arg2));
4619             end if;
4620
4621             Set_Is_CPP_Class (Def_Id);
4622
4623             --  Imported CPP types must not have discriminants (because C++
4624             --  classes do not have discriminants).
4625
4626             if Has_Discriminants (Def_Id) then
4627                Error_Msg_N
4628                  ("imported 'C'P'P type cannot have discriminants",
4629                   First (Discriminant_Specifications
4630                           (Declaration_Node (Def_Id))));
4631             end if;
4632
4633             --  Components of imported CPP types must not have default
4634             --  expressions because the constructor (if any) is on the
4635             --  C++ side.
4636
4637             declare
4638                Tdef  : constant Node_Id :=
4639                          Type_Definition (Declaration_Node (Def_Id));
4640                Clist : Node_Id;
4641                Comp  : Node_Id;
4642
4643             begin
4644                if Nkind (Tdef) = N_Record_Definition then
4645                   Clist := Component_List (Tdef);
4646
4647                else
4648                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4649                   Clist := Component_List (Record_Extension_Part (Tdef));
4650                end if;
4651
4652                if Present (Clist) then
4653                   Comp := First (Component_Items (Clist));
4654                   while Present (Comp) loop
4655                      if Present (Expression (Comp)) then
4656                         Error_Msg_N
4657                           ("component of imported 'C'P'P type cannot have" &
4658                            " default expression", Expression (Comp));
4659                      end if;
4660
4661                      Next (Comp);
4662                   end loop;
4663                end if;
4664             end;
4665
4666          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4667             Check_No_Link_Name;
4668             Check_Arg_Count (3);
4669             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4670
4671             Process_Import_Predefined_Type;
4672
4673          else
4674             Error_Pragma_Arg
4675               ("second argument of pragma% must be object, subprogram" &
4676                " or incomplete type",
4677                Arg2);
4678          end if;
4679
4680          --  If this pragma applies to a compilation unit, then the unit, which
4681          --  is a subprogram, does not require (or allow) a body. We also do
4682          --  not need to elaborate imported procedures.
4683
4684          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4685             declare
4686                Cunit : constant Node_Id := Parent (Parent (N));
4687             begin
4688                Set_Body_Required (Cunit, False);
4689             end;
4690          end if;
4691       end Process_Import_Or_Interface;
4692
4693       --------------------
4694       -- Process_Inline --
4695       --------------------
4696
4697       procedure Process_Inline (Active : Boolean) is
4698          Assoc     : Node_Id;
4699          Decl      : Node_Id;
4700          Subp_Id   : Node_Id;
4701          Subp      : Entity_Id;
4702          Applies   : Boolean;
4703
4704          Effective : Boolean := False;
4705          --  Set True if inline has some effect, i.e. if there is at least one
4706          --  subprogram set as inlined as a result of the use of the pragma.
4707
4708          procedure Make_Inline (Subp : Entity_Id);
4709          --  Subp is the defining unit name of the subprogram declaration. Set
4710          --  the flag, as well as the flag in the corresponding body, if there
4711          --  is one present.
4712
4713          procedure Set_Inline_Flags (Subp : Entity_Id);
4714          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4715          --  Has_Pragma_Inline_Always for the Inline_Always case.
4716
4717          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4718          --  Returns True if it can be determined at this stage that inlining
4719          --  is not possible, for example if the body is available and contains
4720          --  exception handlers, we prevent inlining, since otherwise we can
4721          --  get undefined symbols at link time. This function also emits a
4722          --  warning if front-end inlining is enabled and the pragma appears
4723          --  too late.
4724          --
4725          --  ??? is business with link symbols still valid, or does it relate
4726          --  to front end ZCX which is being phased out ???
4727
4728          ---------------------------
4729          -- Inlining_Not_Possible --
4730          ---------------------------
4731
4732          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4733             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4734             Stats : Node_Id;
4735
4736          begin
4737             if Nkind (Decl) = N_Subprogram_Body then
4738                Stats := Handled_Statement_Sequence (Decl);
4739                return Present (Exception_Handlers (Stats))
4740                  or else Present (At_End_Proc (Stats));
4741
4742             elsif Nkind (Decl) = N_Subprogram_Declaration
4743               and then Present (Corresponding_Body (Decl))
4744             then
4745                if Front_End_Inlining
4746                  and then Analyzed (Corresponding_Body (Decl))
4747                then
4748                   Error_Msg_N ("pragma appears too late, ignored?", N);
4749                   return True;
4750
4751                --  If the subprogram is a renaming as body, the body is just a
4752                --  call to the renamed subprogram, and inlining is trivially
4753                --  possible.
4754
4755                elsif
4756                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4757                                              N_Subprogram_Renaming_Declaration
4758                then
4759                   return False;
4760
4761                else
4762                   Stats :=
4763                     Handled_Statement_Sequence
4764                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4765
4766                   return
4767                     Present (Exception_Handlers (Stats))
4768                       or else Present (At_End_Proc (Stats));
4769                end if;
4770
4771             else
4772                --  If body is not available, assume the best, the check is
4773                --  performed again when compiling enclosing package bodies.
4774
4775                return False;
4776             end if;
4777          end Inlining_Not_Possible;
4778
4779          -----------------
4780          -- Make_Inline --
4781          -----------------
4782
4783          procedure Make_Inline (Subp : Entity_Id) is
4784             Kind       : constant Entity_Kind := Ekind (Subp);
4785             Inner_Subp : Entity_Id   := Subp;
4786
4787          begin
4788             --  Ignore if bad type, avoid cascaded error
4789
4790             if Etype (Subp) = Any_Type then
4791                Applies := True;
4792                return;
4793
4794             --  Ignore if all inlining is suppressed
4795
4796             elsif Suppress_All_Inlining then
4797                Applies := True;
4798                return;
4799
4800             --  If inlining is not possible, for now do not treat as an error
4801
4802             elsif Inlining_Not_Possible (Subp) then
4803                Applies := True;
4804                return;
4805
4806             --  Here we have a candidate for inlining, but we must exclude
4807             --  derived operations. Otherwise we would end up trying to inline
4808             --  a phantom declaration, and the result would be to drag in a
4809             --  body which has no direct inlining associated with it. That
4810             --  would not only be inefficient but would also result in the
4811             --  backend doing cross-unit inlining in cases where it was
4812             --  definitely inappropriate to do so.
4813
4814             --  However, a simple Comes_From_Source test is insufficient, since
4815             --  we do want to allow inlining of generic instances which also do
4816             --  not come from source. We also need to recognize specs generated
4817             --  by the front-end for bodies that carry the pragma. Finally,
4818             --  predefined operators do not come from source but are not
4819             --  inlineable either.
4820
4821             elsif Is_Generic_Instance (Subp)
4822               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4823             then
4824                null;
4825
4826             elsif not Comes_From_Source (Subp)
4827               and then Scope (Subp) /= Standard_Standard
4828             then
4829                Applies := True;
4830                return;
4831             end if;
4832
4833             --  The referenced entity must either be the enclosing entity, or
4834             --  an entity declared within the current open scope.
4835
4836             if Present (Scope (Subp))
4837               and then Scope (Subp) /= Current_Scope
4838               and then Subp /= Current_Scope
4839             then
4840                Error_Pragma_Arg
4841                  ("argument of% must be entity in current scope", Assoc);
4842                return;
4843             end if;
4844
4845             --  Processing for procedure, operator or function. If subprogram
4846             --  is aliased (as for an instance) indicate that the renamed
4847             --  entity (if declared in the same unit) is inlined.
4848
4849             if Is_Subprogram (Subp) then
4850                Inner_Subp := Ultimate_Alias (Inner_Subp);
4851
4852                if In_Same_Source_Unit (Subp, Inner_Subp) then
4853                   Set_Inline_Flags (Inner_Subp);
4854
4855                   Decl := Parent (Parent (Inner_Subp));
4856
4857                   if Nkind (Decl) = N_Subprogram_Declaration
4858                     and then Present (Corresponding_Body (Decl))
4859                   then
4860                      Set_Inline_Flags (Corresponding_Body (Decl));
4861
4862                   elsif Is_Generic_Instance (Subp) then
4863
4864                      --  Indicate that the body needs to be created for
4865                      --  inlining subsequent calls. The instantiation node
4866                      --  follows the declaration of the wrapper package
4867                      --  created for it.
4868
4869                      if Scope (Subp) /= Standard_Standard
4870                        and then
4871                          Need_Subprogram_Instance_Body
4872                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4873                               Subp)
4874                      then
4875                         null;
4876                      end if;
4877
4878                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
4879                   --  appear in a formal part to apply to a formal subprogram.
4880                   --  Do not apply check within an instance or a formal package
4881                   --  the test will have been applied to the original generic.
4882
4883                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4884                     and then List_Containing (Decl) = List_Containing (N)
4885                     and then not In_Instance
4886                   then
4887                      Error_Msg_N
4888                        ("Inline cannot apply to a formal subprogram", N);
4889                   end if;
4890                end if;
4891
4892                Applies := True;
4893
4894             --  For a generic subprogram set flag as well, for use at the point
4895             --  of instantiation, to determine whether the body should be
4896             --  generated.
4897
4898             elsif Is_Generic_Subprogram (Subp) then
4899                Set_Inline_Flags (Subp);
4900                Applies := True;
4901
4902             --  Literals are by definition inlined
4903
4904             elsif Kind = E_Enumeration_Literal then
4905                null;
4906
4907             --  Anything else is an error
4908
4909             else
4910                Error_Pragma_Arg
4911                  ("expect subprogram name for pragma%", Assoc);
4912             end if;
4913          end Make_Inline;
4914
4915          ----------------------
4916          -- Set_Inline_Flags --
4917          ----------------------
4918
4919          procedure Set_Inline_Flags (Subp : Entity_Id) is
4920          begin
4921             if Active then
4922                Set_Is_Inlined (Subp);
4923             end if;
4924
4925             if not Has_Pragma_Inline (Subp) then
4926                Set_Has_Pragma_Inline (Subp);
4927                Effective := True;
4928             end if;
4929
4930             if Prag_Id = Pragma_Inline_Always then
4931                Set_Has_Pragma_Inline_Always (Subp);
4932             end if;
4933          end Set_Inline_Flags;
4934
4935       --  Start of processing for Process_Inline
4936
4937       begin
4938          Check_No_Identifiers;
4939          Check_At_Least_N_Arguments (1);
4940
4941          if Active then
4942             Inline_Processing_Required := True;
4943          end if;
4944
4945          Assoc := Arg1;
4946          while Present (Assoc) loop
4947             Subp_Id := Get_Pragma_Arg (Assoc);
4948             Analyze (Subp_Id);
4949             Applies := False;
4950
4951             if Is_Entity_Name (Subp_Id) then
4952                Subp := Entity (Subp_Id);
4953
4954                if Subp = Any_Id then
4955
4956                   --  If previous error, avoid cascaded errors
4957
4958                   Applies := True;
4959                   Effective := True;
4960
4961                else
4962                   Make_Inline (Subp);
4963
4964                   --  For the pragma case, climb homonym chain. This is
4965                   --  what implements allowing the pragma in the renaming
4966                   --  case, with the result applying to the ancestors, and
4967                   --  also allows Inline to apply to all previous homonyms.
4968
4969                   if not From_Aspect_Specification (N) then
4970                      while Present (Homonym (Subp))
4971                        and then Scope (Homonym (Subp)) = Current_Scope
4972                      loop
4973                         Make_Inline (Homonym (Subp));
4974                         Subp := Homonym (Subp);
4975                      end loop;
4976                   end if;
4977                end if;
4978             end if;
4979
4980             if not Applies then
4981                Error_Pragma_Arg
4982                  ("inappropriate argument for pragma%", Assoc);
4983
4984             elsif not Effective
4985               and then Warn_On_Redundant_Constructs
4986               and then not Suppress_All_Inlining
4987             then
4988                if Inlining_Not_Possible (Subp) then
4989                   Error_Msg_NE
4990                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4991                else
4992                   Error_Msg_NE
4993                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4994                end if;
4995             end if;
4996
4997             Next (Assoc);
4998          end loop;
4999       end Process_Inline;
5000
5001       ----------------------------
5002       -- Process_Interface_Name --
5003       ----------------------------
5004
5005       procedure Process_Interface_Name
5006         (Subprogram_Def : Entity_Id;
5007          Ext_Arg        : Node_Id;
5008          Link_Arg       : Node_Id)
5009       is
5010          Ext_Nam    : Node_Id;
5011          Link_Nam   : Node_Id;
5012          String_Val : String_Id;
5013
5014          procedure Check_Form_Of_Interface_Name
5015            (SN            : Node_Id;
5016             Ext_Name_Case : Boolean);
5017          --  SN is a string literal node for an interface name. This routine
5018          --  performs some minimal checks that the name is reasonable. In
5019          --  particular that no spaces or other obviously incorrect characters
5020          --  appear. This is only a warning, since any characters are allowed.
5021          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
5022
5023          ----------------------------------
5024          -- Check_Form_Of_Interface_Name --
5025          ----------------------------------
5026
5027          procedure Check_Form_Of_Interface_Name
5028            (SN            : Node_Id;
5029             Ext_Name_Case : Boolean)
5030          is
5031             S  : constant String_Id := Strval (Expr_Value_S (SN));
5032             SL : constant Nat       := String_Length (S);
5033             C  : Char_Code;
5034
5035          begin
5036             if SL = 0 then
5037                Error_Msg_N ("interface name cannot be null string", SN);
5038             end if;
5039
5040             for J in 1 .. SL loop
5041                C := Get_String_Char (S, J);
5042
5043                --  Look for dubious character and issue unconditional warning.
5044                --  Definitely dubious if not in character range.
5045
5046                if not In_Character_Range (C)
5047
5048                   --  For all cases except CLI target,
5049                   --  commas, spaces and slashes are dubious (in CLI, we use
5050                   --  commas and backslashes in external names to specify
5051                   --  assembly version and public key, while slashes and spaces
5052                   --  can be used in names to mark nested classes and
5053                   --  valuetypes).
5054
5055                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5056                              and then (Get_Character (C) = ','
5057                                          or else
5058                                        Get_Character (C) = '\'))
5059                  or else (VM_Target /= CLI_Target
5060                             and then (Get_Character (C) = ' '
5061                                         or else
5062                                       Get_Character (C) = '/'))
5063                then
5064                   Error_Msg
5065                     ("?interface name contains illegal character",
5066                      Sloc (SN) + Source_Ptr (J));
5067                end if;
5068             end loop;
5069          end Check_Form_Of_Interface_Name;
5070
5071       --  Start of processing for Process_Interface_Name
5072
5073       begin
5074          if No (Link_Arg) then
5075             if No (Ext_Arg) then
5076                if VM_Target = CLI_Target
5077                  and then Ekind (Subprogram_Def) = E_Package
5078                  and then Nkind (Parent (Subprogram_Def)) =
5079                                                  N_Package_Specification
5080                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
5081                then
5082                   Set_Interface_Name
5083                      (Subprogram_Def,
5084                       Interface_Name
5085                         (Generic_Parent (Parent (Subprogram_Def))));
5086                end if;
5087
5088                return;
5089
5090             elsif Chars (Ext_Arg) = Name_Link_Name then
5091                Ext_Nam  := Empty;
5092                Link_Nam := Expression (Ext_Arg);
5093
5094             else
5095                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5096                Ext_Nam  := Expression (Ext_Arg);
5097                Link_Nam := Empty;
5098             end if;
5099
5100          else
5101             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
5102             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5103             Ext_Nam  := Expression (Ext_Arg);
5104             Link_Nam := Expression (Link_Arg);
5105          end if;
5106
5107          --  Check expressions for external name and link name are static
5108
5109          if Present (Ext_Nam) then
5110             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5111             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5112
5113             --  Verify that external name is not the name of a local entity,
5114             --  which would hide the imported one and could lead to run-time
5115             --  surprises. The problem can only arise for entities declared in
5116             --  a package body (otherwise the external name is fully qualified
5117             --  and will not conflict).
5118
5119             declare
5120                Nam : Name_Id;
5121                E   : Entity_Id;
5122                Par : Node_Id;
5123
5124             begin
5125                if Prag_Id = Pragma_Import then
5126                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5127                   Nam := Name_Find;
5128                   E   := Entity_Id (Get_Name_Table_Info (Nam));
5129
5130                   if Nam /= Chars (Subprogram_Def)
5131                     and then Present (E)
5132                     and then not Is_Overloadable (E)
5133                     and then Is_Immediately_Visible (E)
5134                     and then not Is_Imported (E)
5135                     and then Ekind (Scope (E)) = E_Package
5136                   then
5137                      Par := Parent (E);
5138                      while Present (Par) loop
5139                         if Nkind (Par) = N_Package_Body then
5140                            Error_Msg_Sloc := Sloc (E);
5141                            Error_Msg_NE
5142                              ("imported entity is hidden by & declared#",
5143                               Ext_Arg, E);
5144                            exit;
5145                         end if;
5146
5147                         Par := Parent (Par);
5148                      end loop;
5149                   end if;
5150                end if;
5151             end;
5152          end if;
5153
5154          if Present (Link_Nam) then
5155             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5156             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5157          end if;
5158
5159          --  If there is no link name, just set the external name
5160
5161          if No (Link_Nam) then
5162             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5163
5164          --  For the Link_Name case, the given literal is preceded by an
5165          --  asterisk, which indicates to GCC that the given name should be
5166          --  taken literally, and in particular that no prepending of
5167          --  underlines should occur, even in systems where this is the
5168          --  normal default.
5169
5170          else
5171             Start_String;
5172
5173             if VM_Target = No_VM then
5174                Store_String_Char (Get_Char_Code ('*'));
5175             end if;
5176
5177             String_Val := Strval (Expr_Value_S (Link_Nam));
5178             Store_String_Chars (String_Val);
5179             Link_Nam :=
5180               Make_String_Literal (Sloc (Link_Nam),
5181                 Strval => End_String);
5182          end if;
5183
5184          --  Set the interface name. If the entity is a generic instance, use
5185          --  its alias, which is the callable entity.
5186
5187          if Is_Generic_Instance (Subprogram_Def) then
5188             Set_Encoded_Interface_Name
5189               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5190          else
5191             Set_Encoded_Interface_Name
5192               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5193          end if;
5194
5195          --  We allow duplicated export names in CIL/Java, as they are always
5196          --  enclosed in a namespace that differentiates them, and overloaded
5197          --  entities are supported by the VM.
5198
5199          if Convention (Subprogram_Def) /= Convention_CIL
5200               and then
5201             Convention (Subprogram_Def) /= Convention_Java
5202          then
5203             Check_Duplicated_Export_Name (Link_Nam);
5204          end if;
5205       end Process_Interface_Name;
5206
5207       -----------------------------------------
5208       -- Process_Interrupt_Or_Attach_Handler --
5209       -----------------------------------------
5210
5211       procedure Process_Interrupt_Or_Attach_Handler is
5212          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5213          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5214          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5215
5216       begin
5217          Set_Is_Interrupt_Handler (Handler_Proc);
5218
5219          --  If the pragma is not associated with a handler procedure within a
5220          --  protected type, then it must be for a nonprotected procedure for
5221          --  the AAMP target, in which case we don't associate a representation
5222          --  item with the procedure's scope.
5223
5224          if Ekind (Proc_Scope) = E_Protected_Type then
5225             if Prag_Id = Pragma_Interrupt_Handler
5226                  or else
5227                Prag_Id = Pragma_Attach_Handler
5228             then
5229                Record_Rep_Item (Proc_Scope, N);
5230             end if;
5231          end if;
5232       end Process_Interrupt_Or_Attach_Handler;
5233
5234       --------------------------------------------------
5235       -- Process_Restrictions_Or_Restriction_Warnings --
5236       --------------------------------------------------
5237
5238       --  Note: some of the simple identifier cases were handled in par-prag,
5239       --  but it is harmless (and more straightforward) to simply handle all
5240       --  cases here, even if it means we repeat a bit of work in some cases.
5241
5242       procedure Process_Restrictions_Or_Restriction_Warnings
5243         (Warn : Boolean)
5244       is
5245          Arg   : Node_Id;
5246          R_Id  : Restriction_Id;
5247          Id    : Name_Id;
5248          Expr  : Node_Id;
5249          Val   : Uint;
5250
5251          procedure Check_Unit_Name (N : Node_Id);
5252          --  Checks unit name parameter for No_Dependence. Returns if it has
5253          --  an appropriate form, otherwise raises pragma argument error.
5254
5255          ---------------------
5256          -- Check_Unit_Name --
5257          ---------------------
5258
5259          procedure Check_Unit_Name (N : Node_Id) is
5260          begin
5261             if Nkind (N) = N_Selected_Component then
5262                Check_Unit_Name (Prefix (N));
5263                Check_Unit_Name (Selector_Name (N));
5264
5265             elsif Nkind (N) = N_Identifier then
5266                return;
5267
5268             else
5269                Error_Pragma_Arg
5270                  ("wrong form for unit name for No_Dependence", N);
5271             end if;
5272          end Check_Unit_Name;
5273
5274       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5275
5276       begin
5277          --  Ignore all Restrictions pragma in CodePeer mode
5278
5279          if CodePeer_Mode then
5280             return;
5281          end if;
5282
5283          Check_Ada_83_Warning;
5284          Check_At_Least_N_Arguments (1);
5285          Check_Valid_Configuration_Pragma;
5286
5287          Arg := Arg1;
5288          while Present (Arg) loop
5289             Id := Chars (Arg);
5290             Expr := Get_Pragma_Arg (Arg);
5291
5292             --  Case of no restriction identifier present
5293
5294             if Id = No_Name then
5295                if Nkind (Expr) /= N_Identifier then
5296                   Error_Pragma_Arg
5297                     ("invalid form for restriction", Arg);
5298                end if;
5299
5300                R_Id :=
5301                  Get_Restriction_Id
5302                    (Process_Restriction_Synonyms (Expr));
5303
5304                if R_Id not in All_Boolean_Restrictions then
5305                   Error_Msg_Name_1 := Pname;
5306                   Error_Msg_N
5307                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5308
5309                   --  Check for possible misspelling
5310
5311                   for J in Restriction_Id loop
5312                      declare
5313                         Rnm : constant String := Restriction_Id'Image (J);
5314
5315                      begin
5316                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5317                         Name_Len := Rnm'Length;
5318                         Set_Casing (All_Lower_Case);
5319
5320                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5321                            Set_Casing
5322                              (Identifier_Casing (Current_Source_File));
5323                            Error_Msg_String (1 .. Rnm'Length) :=
5324                              Name_Buffer (1 .. Name_Len);
5325                            Error_Msg_Strlen := Rnm'Length;
5326                            Error_Msg_N -- CODEFIX
5327                              ("\possible misspelling of ""~""",
5328                               Get_Pragma_Arg (Arg));
5329                            exit;
5330                         end if;
5331                      end;
5332                   end loop;
5333
5334                   raise Pragma_Exit;
5335                end if;
5336
5337                if Implementation_Restriction (R_Id) then
5338                   Check_Restriction (No_Implementation_Restrictions, Arg);
5339                end if;
5340
5341                --  If this is a warning, then set the warning unless we already
5342                --  have a real restriction active (we never want a warning to
5343                --  override a real restriction).
5344
5345                if Warn then
5346                   if not Restriction_Active (R_Id) then
5347                      Set_Restriction (R_Id, N);
5348                      Restriction_Warnings (R_Id) := True;
5349                   end if;
5350
5351                --  If real restriction case, then set it and make sure that the
5352                --  restriction warning flag is off, since a real restriction
5353                --  always overrides a warning.
5354
5355                else
5356                   Set_Restriction (R_Id, N);
5357                   Restriction_Warnings (R_Id) := False;
5358                end if;
5359
5360                --  Check for obsolescent restrictions in Ada 2005 mode
5361
5362                if not Warn
5363                  and then Ada_Version >= Ada_2005
5364                  and then (R_Id = No_Asynchronous_Control
5365                             or else
5366                            R_Id = No_Unchecked_Deallocation
5367                             or else
5368                            R_Id = No_Unchecked_Conversion)
5369                then
5370                   Check_Restriction (No_Obsolescent_Features, N);
5371                end if;
5372
5373                --  A very special case that must be processed here: pragma
5374                --  Restrictions (No_Exceptions) turns off all run-time
5375                --  checking. This is a bit dubious in terms of the formal
5376                --  language definition, but it is what is intended by RM
5377                --  H.4(12). Restriction_Warnings never affects generated code
5378                --  so this is done only in the real restriction case.
5379
5380                --  Atomic_Synchronization is not a real check, so it is not
5381                --  affected by this processing).
5382
5383                if R_Id = No_Exceptions and then not Warn then
5384                   for J in Scope_Suppress'Range loop
5385                      if J /= Atomic_Synchronization then
5386                         Scope_Suppress (J) := True;
5387                      end if;
5388                   end loop;
5389                end if;
5390
5391             --  Case of No_Dependence => unit-name. Note that the parser
5392             --  already made the necessary entry in the No_Dependence table.
5393
5394             elsif Id = Name_No_Dependence then
5395                Check_Unit_Name (Expr);
5396
5397             --  Case of No_Specification_Of_Aspect => Identifier.
5398
5399             elsif Id = Name_No_Specification_Of_Aspect then
5400                declare
5401                   A_Id : Aspect_Id;
5402
5403                begin
5404                   if Nkind (Expr) /= N_Identifier then
5405                      A_Id := No_Aspect;
5406                   else
5407                      A_Id := Get_Aspect_Id (Chars (Expr));
5408                   end if;
5409
5410                   if A_Id = No_Aspect then
5411                      Error_Pragma_Arg ("invalid restriction name", Arg);
5412                   else
5413                      Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5414                   end if;
5415                end;
5416
5417             --  All other cases of restriction identifier present
5418
5419             else
5420                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5421                Analyze_And_Resolve (Expr, Any_Integer);
5422
5423                if R_Id not in All_Parameter_Restrictions then
5424                   Error_Pragma_Arg
5425                     ("invalid restriction parameter identifier", Arg);
5426
5427                elsif not Is_OK_Static_Expression (Expr) then
5428                   Flag_Non_Static_Expr
5429                     ("value must be static expression!", Expr);
5430                   raise Pragma_Exit;
5431
5432                elsif not Is_Integer_Type (Etype (Expr))
5433                  or else Expr_Value (Expr) < 0
5434                then
5435                   Error_Pragma_Arg
5436                     ("value must be non-negative integer", Arg);
5437                end if;
5438
5439                --  Restriction pragma is active
5440
5441                Val := Expr_Value (Expr);
5442
5443                if not UI_Is_In_Int_Range (Val) then
5444                   Error_Pragma_Arg
5445                     ("pragma ignored, value too large?", Arg);
5446                end if;
5447
5448                --  Warning case. If the real restriction is active, then we
5449                --  ignore the request, since warning never overrides a real
5450                --  restriction. Otherwise we set the proper warning. Note that
5451                --  this circuit sets the warning again if it is already set,
5452                --  which is what we want, since the constant may have changed.
5453
5454                if Warn then
5455                   if not Restriction_Active (R_Id) then
5456                      Set_Restriction
5457                        (R_Id, N, Integer (UI_To_Int (Val)));
5458                      Restriction_Warnings (R_Id) := True;
5459                   end if;
5460
5461                --  Real restriction case, set restriction and make sure warning
5462                --  flag is off since real restriction always overrides warning.
5463
5464                else
5465                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5466                   Restriction_Warnings (R_Id) := False;
5467                end if;
5468             end if;
5469
5470             Next (Arg);
5471          end loop;
5472       end Process_Restrictions_Or_Restriction_Warnings;
5473
5474       ---------------------------------
5475       -- Process_Suppress_Unsuppress --
5476       ---------------------------------
5477
5478       --  Note: this procedure makes entries in the check suppress data
5479       --  structures managed by Sem. See spec of package Sem for full
5480       --  details on how we handle recording of check suppression.
5481
5482       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5483          C    : Check_Id;
5484          E_Id : Node_Id;
5485          E    : Entity_Id;
5486
5487          In_Package_Spec : constant Boolean :=
5488                              Is_Package_Or_Generic_Package (Current_Scope)
5489                                and then not In_Package_Body (Current_Scope);
5490
5491          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5492          --  Used to suppress a single check on the given entity
5493
5494          --------------------------------
5495          -- Suppress_Unsuppress_Echeck --
5496          --------------------------------
5497
5498          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5499          begin
5500             --  Check for error of trying to set atomic synchronization for
5501             --  a non-atomic variable.
5502
5503             if C = Atomic_Synchronization
5504               and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5505             then
5506                Error_Msg_N
5507                  ("pragma & requires atomic type or variable",
5508                   Pragma_Identifier (Original_Node (N)));
5509             end if;
5510
5511             Set_Checks_May_Be_Suppressed (E);
5512
5513             if In_Package_Spec then
5514                Push_Global_Suppress_Stack_Entry
5515                  (Entity   => E,
5516                   Check    => C,
5517                   Suppress => Suppress_Case);
5518             else
5519                Push_Local_Suppress_Stack_Entry
5520                  (Entity   => E,
5521                   Check    => C,
5522                   Suppress => Suppress_Case);
5523             end if;
5524
5525             --  If this is a first subtype, and the base type is distinct,
5526             --  then also set the suppress flags on the base type.
5527
5528             if Is_First_Subtype (E)
5529               and then Etype (E) /= E
5530             then
5531                Suppress_Unsuppress_Echeck (Etype (E), C);
5532             end if;
5533          end Suppress_Unsuppress_Echeck;
5534
5535       --  Start of processing for Process_Suppress_Unsuppress
5536
5537       begin
5538          --  Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5539          --  user code: we want to generate checks for analysis purposes, as
5540          --  set respectively by -gnatC and -gnatd.F
5541
5542          if (CodePeer_Mode or Alfa_Mode)
5543            and then Comes_From_Source (N)
5544          then
5545             return;
5546          end if;
5547
5548          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5549          --  declarative part or a package spec (RM 11.5(5)).
5550
5551          if not Is_Configuration_Pragma then
5552             Check_Is_In_Decl_Part_Or_Package_Spec;
5553          end if;
5554
5555          Check_At_Least_N_Arguments (1);
5556          Check_At_Most_N_Arguments (2);
5557          Check_No_Identifier (Arg1);
5558          Check_Arg_Is_Identifier (Arg1);
5559
5560          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5561
5562          if C = No_Check_Id then
5563             Error_Pragma_Arg
5564               ("argument of pragma% is not valid check name", Arg1);
5565          end if;
5566
5567          if not Suppress_Case
5568            and then (C = All_Checks or else C = Overflow_Check)
5569          then
5570             Opt.Overflow_Checks_Unsuppressed := True;
5571          end if;
5572
5573          if Arg_Count = 1 then
5574
5575             --  Make an entry in the local scope suppress table. This is the
5576             --  table that directly shows the current value of the scope
5577             --  suppress check for any check id value.
5578
5579             if C = All_Checks then
5580
5581                --  For All_Checks, we set all specific predefined checks with
5582                --  the exception of Elaboration_Check, which is handled
5583                --  specially because of not wanting All_Checks to have the
5584                --  effect of deactivating static elaboration order processing.
5585                --  Atomic_Synchronization is also not affected, since this is
5586                --  not a real check.
5587
5588                for J in Scope_Suppress'Range loop
5589                   if J /= Elaboration_Check
5590                     and then J /= Atomic_Synchronization
5591                   then
5592                      Scope_Suppress (J) := Suppress_Case;
5593                   end if;
5594                end loop;
5595
5596             --  If not All_Checks, and predefined check, then set appropriate
5597             --  scope entry. Note that we will set Elaboration_Check if this
5598             --  is explicitly specified. Atomic_Synchronization is allowed
5599             --  only if internally generated and entity is atomic.
5600
5601             elsif C in Predefined_Check_Id
5602               and then (not Comes_From_Source (N)
5603                          or else C /= Atomic_Synchronization)
5604             then
5605                Scope_Suppress (C) := Suppress_Case;
5606             end if;
5607
5608             --  Also make an entry in the Local_Entity_Suppress table
5609
5610             Push_Local_Suppress_Stack_Entry
5611               (Entity   => Empty,
5612                Check    => C,
5613                Suppress => Suppress_Case);
5614
5615          --  Case of two arguments present, where the check is suppressed for
5616          --  a specified entity (given as the second argument of the pragma)
5617
5618          else
5619             --  This is obsolescent in Ada 2005 mode
5620
5621             if Ada_Version >= Ada_2005 then
5622                Check_Restriction (No_Obsolescent_Features, Arg2);
5623             end if;
5624
5625             Check_Optional_Identifier (Arg2, Name_On);
5626             E_Id := Get_Pragma_Arg (Arg2);
5627             Analyze (E_Id);
5628
5629             if not Is_Entity_Name (E_Id) then
5630                Error_Pragma_Arg
5631                  ("second argument of pragma% must be entity name", Arg2);
5632             end if;
5633
5634             E := Entity (E_Id);
5635
5636             if E = Any_Id then
5637                return;
5638             end if;
5639
5640             --  Enforce RM 11.5(7) which requires that for a pragma that
5641             --  appears within a package spec, the named entity must be
5642             --  within the package spec. We allow the package name itself
5643             --  to be mentioned since that makes sense, although it is not
5644             --  strictly allowed by 11.5(7).
5645
5646             if In_Package_Spec
5647               and then E /= Current_Scope
5648               and then Scope (E) /= Current_Scope
5649             then
5650                Error_Pragma_Arg
5651                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5652                   Arg2);
5653             end if;
5654
5655             --  Loop through homonyms. As noted below, in the case of a package
5656             --  spec, only homonyms within the package spec are considered.
5657
5658             loop
5659                Suppress_Unsuppress_Echeck (E, C);
5660
5661                if Is_Generic_Instance (E)
5662                  and then Is_Subprogram (E)
5663                  and then Present (Alias (E))
5664                then
5665                   Suppress_Unsuppress_Echeck (Alias (E), C);
5666                end if;
5667
5668                --  Move to next homonym if not aspect spec case
5669
5670                exit when From_Aspect_Specification (N);
5671                E := Homonym (E);
5672                exit when No (E);
5673
5674                --  If we are within a package specification, the pragma only
5675                --  applies to homonyms in the same scope.
5676
5677                exit when In_Package_Spec
5678                  and then Scope (E) /= Current_Scope;
5679             end loop;
5680          end if;
5681       end Process_Suppress_Unsuppress;
5682
5683       ------------------
5684       -- Set_Exported --
5685       ------------------
5686
5687       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5688       begin
5689          if Is_Imported (E) then
5690             Error_Pragma_Arg
5691               ("cannot export entity& that was previously imported", Arg);
5692
5693          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5694             Error_Pragma_Arg
5695               ("cannot export entity& that has an address clause", Arg);
5696          end if;
5697
5698          Set_Is_Exported (E);
5699
5700          --  Generate a reference for entity explicitly, because the
5701          --  identifier may be overloaded and name resolution will not
5702          --  generate one.
5703
5704          Generate_Reference (E, Arg);
5705
5706          --  Deal with exporting non-library level entity
5707
5708          if not Is_Library_Level_Entity (E) then
5709
5710             --  Not allowed at all for subprograms
5711
5712             if Is_Subprogram (E) then
5713                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5714
5715             --  Otherwise set public and statically allocated
5716
5717             else
5718                Set_Is_Public (E);
5719                Set_Is_Statically_Allocated (E);
5720
5721                --  Warn if the corresponding W flag is set and the pragma comes
5722                --  from source. The latter may not be true e.g. on VMS where we
5723                --  expand export pragmas for exception codes associated with
5724                --  imported or exported exceptions. We do not want to generate
5725                --  a warning for something that the user did not write.
5726
5727                if Warn_On_Export_Import
5728                  and then Comes_From_Source (Arg)
5729                then
5730                   Error_Msg_NE
5731                     ("?& has been made static as a result of Export", Arg, E);
5732                   Error_Msg_N
5733                     ("\this usage is non-standard and non-portable", Arg);
5734                end if;
5735             end if;
5736          end if;
5737
5738          if Warn_On_Export_Import and then Is_Type (E) then
5739             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5740          end if;
5741
5742          if Warn_On_Export_Import and Inside_A_Generic then
5743             Error_Msg_NE
5744               ("all instances of& will have the same external name?", Arg, E);
5745          end if;
5746       end Set_Exported;
5747
5748       ----------------------------------------------
5749       -- Set_Extended_Import_Export_External_Name --
5750       ----------------------------------------------
5751
5752       procedure Set_Extended_Import_Export_External_Name
5753         (Internal_Ent : Entity_Id;
5754          Arg_External : Node_Id)
5755       is
5756          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5757          New_Name : Node_Id;
5758
5759       begin
5760          if No (Arg_External) then
5761             return;
5762          end if;
5763
5764          Check_Arg_Is_External_Name (Arg_External);
5765
5766          if Nkind (Arg_External) = N_String_Literal then
5767             if String_Length (Strval (Arg_External)) = 0 then
5768                return;
5769             else
5770                New_Name := Adjust_External_Name_Case (Arg_External);
5771             end if;
5772
5773          elsif Nkind (Arg_External) = N_Identifier then
5774             New_Name := Get_Default_External_Name (Arg_External);
5775
5776          --  Check_Arg_Is_External_Name should let through only identifiers and
5777          --  string literals or static string expressions (which are folded to
5778          --  string literals).
5779
5780          else
5781             raise Program_Error;
5782          end if;
5783
5784          --  If we already have an external name set (by a prior normal Import
5785          --  or Export pragma), then the external names must match
5786
5787          if Present (Interface_Name (Internal_Ent)) then
5788             Check_Matching_Internal_Names : declare
5789                S1 : constant String_Id := Strval (Old_Name);
5790                S2 : constant String_Id := Strval (New_Name);
5791
5792                procedure Mismatch;
5793                --  Called if names do not match
5794
5795                --------------
5796                -- Mismatch --
5797                --------------
5798
5799                procedure Mismatch is
5800                begin
5801                   Error_Msg_Sloc := Sloc (Old_Name);
5802                   Error_Pragma_Arg
5803                     ("external name does not match that given #",
5804                      Arg_External);
5805                end Mismatch;
5806
5807             --  Start of processing for Check_Matching_Internal_Names
5808
5809             begin
5810                if String_Length (S1) /= String_Length (S2) then
5811                   Mismatch;
5812
5813                else
5814                   for J in 1 .. String_Length (S1) loop
5815                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5816                         Mismatch;
5817                      end if;
5818                   end loop;
5819                end if;
5820             end Check_Matching_Internal_Names;
5821
5822          --  Otherwise set the given name
5823
5824          else
5825             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5826             Check_Duplicated_Export_Name (New_Name);
5827          end if;
5828       end Set_Extended_Import_Export_External_Name;
5829
5830       ------------------
5831       -- Set_Imported --
5832       ------------------
5833
5834       procedure Set_Imported (E : Entity_Id) is
5835       begin
5836          --  Error message if already imported or exported
5837
5838          if Is_Exported (E) or else Is_Imported (E) then
5839
5840             --  Error if being set Exported twice
5841
5842             if Is_Exported (E) then
5843                Error_Msg_NE ("entity& was previously exported", N, E);
5844
5845             --  OK if Import/Interface case
5846
5847             elsif Import_Interface_Present (N) then
5848                goto OK;
5849
5850             --  Error if being set Imported twice
5851
5852             else
5853                Error_Msg_NE ("entity& was previously imported", N, E);
5854             end if;
5855
5856             Error_Msg_Name_1 := Pname;
5857             Error_Msg_N
5858               ("\(pragma% applies to all previous entities)", N);
5859
5860             Error_Msg_Sloc  := Sloc (E);
5861             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5862
5863          --  Here if not previously imported or exported, OK to import
5864
5865          else
5866             Set_Is_Imported (E);
5867
5868             --  If the entity is an object that is not at the library level,
5869             --  then it is statically allocated. We do not worry about objects
5870             --  with address clauses in this context since they are not really
5871             --  imported in the linker sense.
5872
5873             if Is_Object (E)
5874               and then not Is_Library_Level_Entity (E)
5875               and then No (Address_Clause (E))
5876             then
5877                Set_Is_Statically_Allocated (E);
5878             end if;
5879          end if;
5880
5881          <<OK>> null;
5882       end Set_Imported;
5883
5884       -------------------------
5885       -- Set_Mechanism_Value --
5886       -------------------------
5887
5888       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5889       --  analyzed, since it is semantic nonsense), so we get it in the exact
5890       --  form created by the parser.
5891
5892       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5893          Class        : Node_Id;
5894          Param        : Node_Id;
5895          Mech_Name_Id : Name_Id;
5896
5897          procedure Bad_Class;
5898          --  Signal bad descriptor class name
5899
5900          procedure Bad_Mechanism;
5901          --  Signal bad mechanism name
5902
5903          ---------------
5904          -- Bad_Class --
5905          ---------------
5906
5907          procedure Bad_Class is
5908          begin
5909             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5910          end Bad_Class;
5911
5912          -------------------------
5913          -- Bad_Mechanism_Value --
5914          -------------------------
5915
5916          procedure Bad_Mechanism is
5917          begin
5918             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5919          end Bad_Mechanism;
5920
5921       --  Start of processing for Set_Mechanism_Value
5922
5923       begin
5924          if Mechanism (Ent) /= Default_Mechanism then
5925             Error_Msg_NE
5926               ("mechanism for & has already been set", Mech_Name, Ent);
5927          end if;
5928
5929          --  MECHANISM_NAME ::= value | reference | descriptor |
5930          --                     short_descriptor
5931
5932          if Nkind (Mech_Name) = N_Identifier then
5933             if Chars (Mech_Name) = Name_Value then
5934                Set_Mechanism (Ent, By_Copy);
5935                return;
5936
5937             elsif Chars (Mech_Name) = Name_Reference then
5938                Set_Mechanism (Ent, By_Reference);
5939                return;
5940
5941             elsif Chars (Mech_Name) = Name_Descriptor then
5942                Check_VMS (Mech_Name);
5943
5944                --  Descriptor => Short_Descriptor if pragma was given
5945
5946                if Short_Descriptors then
5947                   Set_Mechanism (Ent, By_Short_Descriptor);
5948                else
5949                   Set_Mechanism (Ent, By_Descriptor);
5950                end if;
5951
5952                return;
5953
5954             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5955                Check_VMS (Mech_Name);
5956                Set_Mechanism (Ent, By_Short_Descriptor);
5957                return;
5958
5959             elsif Chars (Mech_Name) = Name_Copy then
5960                Error_Pragma_Arg
5961                  ("bad mechanism name, Value assumed", Mech_Name);
5962
5963             else
5964                Bad_Mechanism;
5965             end if;
5966
5967          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5968          --                     short_descriptor (CLASS_NAME)
5969          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5970
5971          --  Note: this form is parsed as an indexed component
5972
5973          elsif Nkind (Mech_Name) = N_Indexed_Component then
5974             Class := First (Expressions (Mech_Name));
5975
5976             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5977              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5978                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5979              or else Present (Next (Class))
5980             then
5981                Bad_Mechanism;
5982             else
5983                Mech_Name_Id := Chars (Prefix (Mech_Name));
5984
5985                --  Change Descriptor => Short_Descriptor if pragma was given
5986
5987                if Mech_Name_Id = Name_Descriptor
5988                  and then Short_Descriptors
5989                then
5990                   Mech_Name_Id := Name_Short_Descriptor;
5991                end if;
5992             end if;
5993
5994          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5995          --                     short_descriptor (Class => CLASS_NAME)
5996          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5997
5998          --  Note: this form is parsed as a function call
5999
6000          elsif Nkind (Mech_Name) = N_Function_Call then
6001             Param := First (Parameter_Associations (Mech_Name));
6002
6003             if Nkind (Name (Mech_Name)) /= N_Identifier
6004               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6005                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6006               or else Present (Next (Param))
6007               or else No (Selector_Name (Param))
6008               or else Chars (Selector_Name (Param)) /= Name_Class
6009             then
6010                Bad_Mechanism;
6011             else
6012                Class := Explicit_Actual_Parameter (Param);
6013                Mech_Name_Id := Chars (Name (Mech_Name));
6014             end if;
6015
6016          else
6017             Bad_Mechanism;
6018          end if;
6019
6020          --  Fall through here with Class set to descriptor class name
6021
6022          Check_VMS (Mech_Name);
6023
6024          if Nkind (Class) /= N_Identifier then
6025             Bad_Class;
6026
6027          elsif Mech_Name_Id = Name_Descriptor
6028            and then Chars (Class) = Name_UBS
6029          then
6030             Set_Mechanism (Ent, By_Descriptor_UBS);
6031
6032          elsif Mech_Name_Id = Name_Descriptor
6033            and then Chars (Class) = Name_UBSB
6034          then
6035             Set_Mechanism (Ent, By_Descriptor_UBSB);
6036
6037          elsif Mech_Name_Id = Name_Descriptor
6038            and then Chars (Class) = Name_UBA
6039          then
6040             Set_Mechanism (Ent, By_Descriptor_UBA);
6041
6042          elsif Mech_Name_Id = Name_Descriptor
6043            and then Chars (Class) = Name_S
6044          then
6045             Set_Mechanism (Ent, By_Descriptor_S);
6046
6047          elsif Mech_Name_Id = Name_Descriptor
6048            and then Chars (Class) = Name_SB
6049          then
6050             Set_Mechanism (Ent, By_Descriptor_SB);
6051
6052          elsif Mech_Name_Id = Name_Descriptor
6053            and then Chars (Class) = Name_A
6054          then
6055             Set_Mechanism (Ent, By_Descriptor_A);
6056
6057          elsif Mech_Name_Id = Name_Descriptor
6058            and then Chars (Class) = Name_NCA
6059          then
6060             Set_Mechanism (Ent, By_Descriptor_NCA);
6061
6062          elsif Mech_Name_Id = Name_Short_Descriptor
6063            and then Chars (Class) = Name_UBS
6064          then
6065             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6066
6067          elsif Mech_Name_Id = Name_Short_Descriptor
6068            and then Chars (Class) = Name_UBSB
6069          then
6070             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6071
6072          elsif Mech_Name_Id = Name_Short_Descriptor
6073            and then Chars (Class) = Name_UBA
6074          then
6075             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6076
6077          elsif Mech_Name_Id = Name_Short_Descriptor
6078            and then Chars (Class) = Name_S
6079          then
6080             Set_Mechanism (Ent, By_Short_Descriptor_S);
6081
6082          elsif Mech_Name_Id = Name_Short_Descriptor
6083            and then Chars (Class) = Name_SB
6084          then
6085             Set_Mechanism (Ent, By_Short_Descriptor_SB);
6086
6087          elsif Mech_Name_Id = Name_Short_Descriptor
6088            and then Chars (Class) = Name_A
6089          then
6090             Set_Mechanism (Ent, By_Short_Descriptor_A);
6091
6092          elsif Mech_Name_Id = Name_Short_Descriptor
6093            and then Chars (Class) = Name_NCA
6094          then
6095             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6096
6097          else
6098             Bad_Class;
6099          end if;
6100       end Set_Mechanism_Value;
6101
6102       ---------------------------
6103       -- Set_Ravenscar_Profile --
6104       ---------------------------
6105
6106       --  The tasks to be done here are
6107
6108       --    Set required policies
6109
6110       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6111       --      pragma Locking_Policy (Ceiling_Locking)
6112
6113       --    Set Detect_Blocking mode
6114
6115       --    Set required restrictions (see System.Rident for detailed list)
6116
6117       --    Set the No_Dependence rules
6118       --      No_Dependence => Ada.Asynchronous_Task_Control
6119       --      No_Dependence => Ada.Calendar
6120       --      No_Dependence => Ada.Execution_Time.Group_Budget
6121       --      No_Dependence => Ada.Execution_Time.Timers
6122       --      No_Dependence => Ada.Task_Attributes
6123       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
6124
6125       procedure Set_Ravenscar_Profile (N : Node_Id) is
6126          Prefix_Entity   : Entity_Id;
6127          Selector_Entity : Entity_Id;
6128          Prefix_Node     : Node_Id;
6129          Node            : Node_Id;
6130
6131       begin
6132          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6133
6134          if Task_Dispatching_Policy /= ' '
6135            and then Task_Dispatching_Policy /= 'F'
6136          then
6137             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6138             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6139
6140          --  Set the FIFO_Within_Priorities policy, but always preserve
6141          --  System_Location since we like the error message with the run time
6142          --  name.
6143
6144          else
6145             Task_Dispatching_Policy := 'F';
6146
6147             if Task_Dispatching_Policy_Sloc /= System_Location then
6148                Task_Dispatching_Policy_Sloc := Loc;
6149             end if;
6150          end if;
6151
6152          --  pragma Locking_Policy (Ceiling_Locking)
6153
6154          if Locking_Policy /= ' '
6155            and then Locking_Policy /= 'C'
6156          then
6157             Error_Msg_Sloc := Locking_Policy_Sloc;
6158             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6159
6160          --  Set the Ceiling_Locking policy, but preserve System_Location since
6161          --  we like the error message with the run time name.
6162
6163          else
6164             Locking_Policy := 'C';
6165
6166             if Locking_Policy_Sloc /= System_Location then
6167                Locking_Policy_Sloc := Loc;
6168             end if;
6169          end if;
6170
6171          --  pragma Detect_Blocking
6172
6173          Detect_Blocking := True;
6174
6175          --  Set the corresponding restrictions
6176
6177          Set_Profile_Restrictions
6178            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6179
6180          --  Set the No_Dependence restrictions
6181
6182          --  The following No_Dependence restrictions:
6183          --    No_Dependence => Ada.Asynchronous_Task_Control
6184          --    No_Dependence => Ada.Calendar
6185          --    No_Dependence => Ada.Task_Attributes
6186          --  are already set by previous call to Set_Profile_Restrictions.
6187
6188          --  Set the following restrictions which were added to Ada 2005:
6189          --    No_Dependence => Ada.Execution_Time.Group_Budget
6190          --    No_Dependence => Ada.Execution_Time.Timers
6191
6192          if Ada_Version >= Ada_2005 then
6193             Name_Buffer (1 .. 3) := "ada";
6194             Name_Len := 3;
6195
6196             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6197
6198             Name_Buffer (1 .. 14) := "execution_time";
6199             Name_Len := 14;
6200
6201             Selector_Entity := Make_Identifier (Loc, Name_Find);
6202
6203             Prefix_Node :=
6204               Make_Selected_Component
6205                 (Sloc          => Loc,
6206                  Prefix        => Prefix_Entity,
6207                  Selector_Name => Selector_Entity);
6208
6209             Name_Buffer (1 .. 13) := "group_budgets";
6210             Name_Len := 13;
6211
6212             Selector_Entity := Make_Identifier (Loc, Name_Find);
6213
6214             Node :=
6215               Make_Selected_Component
6216                 (Sloc          => Loc,
6217                  Prefix        => Prefix_Node,
6218                  Selector_Name => Selector_Entity);
6219
6220             Set_Restriction_No_Dependence
6221               (Unit    => Node,
6222                Warn    => Treat_Restrictions_As_Warnings,
6223                Profile => Ravenscar);
6224
6225             Name_Buffer (1 .. 6) := "timers";
6226             Name_Len := 6;
6227
6228             Selector_Entity := Make_Identifier (Loc, Name_Find);
6229
6230             Node :=
6231               Make_Selected_Component
6232                 (Sloc          => Loc,
6233                  Prefix        => Prefix_Node,
6234                  Selector_Name => Selector_Entity);
6235
6236             Set_Restriction_No_Dependence
6237               (Unit    => Node,
6238                Warn    => Treat_Restrictions_As_Warnings,
6239                Profile => Ravenscar);
6240          end if;
6241
6242          --  Set the following restrictions which was added to Ada 2012 (see
6243          --  AI-0171):
6244          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
6245
6246          if Ada_Version >= Ada_2012 then
6247             Name_Buffer (1 .. 6) := "system";
6248             Name_Len := 6;
6249
6250             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6251
6252             Name_Buffer (1 .. 15) := "multiprocessors";
6253             Name_Len := 15;
6254
6255             Selector_Entity := Make_Identifier (Loc, Name_Find);
6256
6257             Prefix_Node :=
6258               Make_Selected_Component
6259                 (Sloc          => Loc,
6260                  Prefix        => Prefix_Entity,
6261                  Selector_Name => Selector_Entity);
6262
6263             Name_Buffer (1 .. 19) := "dispatching_domains";
6264             Name_Len := 19;
6265
6266             Selector_Entity := Make_Identifier (Loc, Name_Find);
6267
6268             Node :=
6269               Make_Selected_Component
6270                 (Sloc          => Loc,
6271                  Prefix        => Prefix_Node,
6272                  Selector_Name => Selector_Entity);
6273
6274             Set_Restriction_No_Dependence
6275               (Unit    => Node,
6276                Warn    => Treat_Restrictions_As_Warnings,
6277                Profile => Ravenscar);
6278          end if;
6279       end Set_Ravenscar_Profile;
6280
6281    --  Start of processing for Analyze_Pragma
6282
6283    begin
6284       --  The following code is a defense against recursion. Not clear that
6285       --  this can happen legitimately, but perhaps some error situations
6286       --  can cause it, and we did see this recursion during testing.
6287
6288       if Analyzed (N) then
6289          return;
6290       else
6291          Set_Analyzed (N, True);
6292       end if;
6293
6294       --  Deal with unrecognized pragma
6295
6296       Pname := Pragma_Name (N);
6297
6298       if not Is_Pragma_Name (Pname) then
6299          if Warn_On_Unrecognized_Pragma then
6300             Error_Msg_Name_1 := Pname;
6301             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6302
6303             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6304                if Is_Bad_Spelling_Of (Pname, PN) then
6305                   Error_Msg_Name_1 := PN;
6306                   Error_Msg_N -- CODEFIX
6307                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6308                   exit;
6309                end if;
6310             end loop;
6311          end if;
6312
6313          return;
6314       end if;
6315
6316       --  Here to start processing for recognized pragma
6317
6318       Prag_Id := Get_Pragma_Id (Pname);
6319
6320       if Present (Corresponding_Aspect (N)) then
6321          Pname := Chars (Identifier (Corresponding_Aspect (N)));
6322       end if;
6323
6324       --  Preset arguments
6325
6326       Arg_Count := 0;
6327       Arg1      := Empty;
6328       Arg2      := Empty;
6329       Arg3      := Empty;
6330       Arg4      := Empty;
6331
6332       if Present (Pragma_Argument_Associations (N)) then
6333          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6334          Arg1 := First (Pragma_Argument_Associations (N));
6335
6336          if Present (Arg1) then
6337             Arg2 := Next (Arg1);
6338
6339             if Present (Arg2) then
6340                Arg3 := Next (Arg2);
6341
6342                if Present (Arg3) then
6343                   Arg4 := Next (Arg3);
6344                end if;
6345             end if;
6346          end if;
6347       end if;
6348
6349       --  An enumeration type defines the pragmas that are supported by the
6350       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6351       --  into the corresponding enumeration value for the following case.
6352
6353       case Prag_Id is
6354
6355          -----------------
6356          -- Abort_Defer --
6357          -----------------
6358
6359          --  pragma Abort_Defer;
6360
6361          when Pragma_Abort_Defer =>
6362             GNAT_Pragma;
6363             Check_Arg_Count (0);
6364
6365             --  The only required semantic processing is to check the
6366             --  placement. This pragma must appear at the start of the
6367             --  statement sequence of a handled sequence of statements.
6368
6369             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6370               or else N /= First (Statements (Parent (N)))
6371             then
6372                Pragma_Misplaced;
6373             end if;
6374
6375          ------------
6376          -- Ada_83 --
6377          ------------
6378
6379          --  pragma Ada_83;
6380
6381          --  Note: this pragma also has some specific processing in Par.Prag
6382          --  because we want to set the Ada version mode during parsing.
6383
6384          when Pragma_Ada_83 =>
6385             GNAT_Pragma;
6386             Check_Arg_Count (0);
6387
6388             --  We really should check unconditionally for proper configuration
6389             --  pragma placement, since we really don't want mixed Ada modes
6390             --  within a single unit, and the GNAT reference manual has always
6391             --  said this was a configuration pragma, but we did not check and
6392             --  are hesitant to add the check now.
6393
6394             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6395             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6396             --  or Ada 2012 mode.
6397
6398             if Ada_Version >= Ada_2005 then
6399                Check_Valid_Configuration_Pragma;
6400             end if;
6401
6402             --  Now set Ada 83 mode
6403
6404             Ada_Version := Ada_83;
6405             Ada_Version_Explicit := Ada_Version;
6406
6407          ------------
6408          -- Ada_95 --
6409          ------------
6410
6411          --  pragma Ada_95;
6412
6413          --  Note: this pragma also has some specific processing in Par.Prag
6414          --  because we want to set the Ada 83 version mode during parsing.
6415
6416          when Pragma_Ada_95 =>
6417             GNAT_Pragma;
6418             Check_Arg_Count (0);
6419
6420             --  We really should check unconditionally for proper configuration
6421             --  pragma placement, since we really don't want mixed Ada modes
6422             --  within a single unit, and the GNAT reference manual has always
6423             --  said this was a configuration pragma, but we did not check and
6424             --  are hesitant to add the check now.
6425
6426             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6427             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6428
6429             if Ada_Version >= Ada_2005 then
6430                Check_Valid_Configuration_Pragma;
6431             end if;
6432
6433             --  Now set Ada 95 mode
6434
6435             Ada_Version := Ada_95;
6436             Ada_Version_Explicit := Ada_Version;
6437
6438          ---------------------
6439          -- Ada_05/Ada_2005 --
6440          ---------------------
6441
6442          --  pragma Ada_05;
6443          --  pragma Ada_05 (LOCAL_NAME);
6444
6445          --  pragma Ada_2005;
6446          --  pragma Ada_2005 (LOCAL_NAME):
6447
6448          --  Note: these pragmas also have some specific processing in Par.Prag
6449          --  because we want to set the Ada 2005 version mode during parsing.
6450
6451          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6452             E_Id : Node_Id;
6453
6454          begin
6455             GNAT_Pragma;
6456
6457             if Arg_Count = 1 then
6458                Check_Arg_Is_Local_Name (Arg1);
6459                E_Id := Get_Pragma_Arg (Arg1);
6460
6461                if Etype (E_Id) = Any_Type then
6462                   return;
6463                end if;
6464
6465                Set_Is_Ada_2005_Only (Entity (E_Id));
6466
6467             else
6468                Check_Arg_Count (0);
6469
6470                --  For Ada_2005 we unconditionally enforce the documented
6471                --  configuration pragma placement, since we do not want to
6472                --  tolerate mixed modes in a unit involving Ada 2005. That
6473                --  would cause real difficulties for those cases where there
6474                --  are incompatibilities between Ada 95 and Ada 2005.
6475
6476                Check_Valid_Configuration_Pragma;
6477
6478                --  Now set appropriate Ada mode
6479
6480                Ada_Version          := Ada_2005;
6481                Ada_Version_Explicit := Ada_2005;
6482             end if;
6483          end;
6484
6485          ---------------------
6486          -- Ada_12/Ada_2012 --
6487          ---------------------
6488
6489          --  pragma Ada_12;
6490          --  pragma Ada_12 (LOCAL_NAME);
6491
6492          --  pragma Ada_2012;
6493          --  pragma Ada_2012 (LOCAL_NAME):
6494
6495          --  Note: these pragmas also have some specific processing in Par.Prag
6496          --  because we want to set the Ada 2012 version mode during parsing.
6497
6498          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6499             E_Id : Node_Id;
6500
6501          begin
6502             GNAT_Pragma;
6503
6504             if Arg_Count = 1 then
6505                Check_Arg_Is_Local_Name (Arg1);
6506                E_Id := Get_Pragma_Arg (Arg1);
6507
6508                if Etype (E_Id) = Any_Type then
6509                   return;
6510                end if;
6511
6512                Set_Is_Ada_2012_Only (Entity (E_Id));
6513
6514             else
6515                Check_Arg_Count (0);
6516
6517                --  For Ada_2012 we unconditionally enforce the documented
6518                --  configuration pragma placement, since we do not want to
6519                --  tolerate mixed modes in a unit involving Ada 2012. That
6520                --  would cause real difficulties for those cases where there
6521                --  are incompatibilities between Ada 95 and Ada 2012. We could
6522                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6523
6524                Check_Valid_Configuration_Pragma;
6525
6526                --  Now set appropriate Ada mode
6527
6528                Ada_Version          := Ada_2012;
6529                Ada_Version_Explicit := Ada_2012;
6530             end if;
6531          end;
6532
6533          ----------------------
6534          -- All_Calls_Remote --
6535          ----------------------
6536
6537          --  pragma All_Calls_Remote [(library_package_NAME)];
6538
6539          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6540             Lib_Entity : Entity_Id;
6541
6542          begin
6543             Check_Ada_83_Warning;
6544             Check_Valid_Library_Unit_Pragma;
6545
6546             if Nkind (N) = N_Null_Statement then
6547                return;
6548             end if;
6549
6550             Lib_Entity := Find_Lib_Unit_Name;
6551
6552             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6553
6554             if Present (Lib_Entity)
6555               and then not Debug_Flag_U
6556             then
6557                if not Is_Remote_Call_Interface (Lib_Entity) then
6558                   Error_Pragma ("pragma% only apply to rci unit");
6559
6560                --  Set flag for entity of the library unit
6561
6562                else
6563                   Set_Has_All_Calls_Remote (Lib_Entity);
6564                end if;
6565
6566             end if;
6567          end All_Calls_Remote;
6568
6569          --------------
6570          -- Annotate --
6571          --------------
6572
6573          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6574          --  ARG ::= NAME | EXPRESSION
6575
6576          --  The first two arguments are by convention intended to refer to an
6577          --  external tool and a tool-specific function. These arguments are
6578          --  not analyzed.
6579
6580          when Pragma_Annotate => Annotate : declare
6581             Arg : Node_Id;
6582             Exp : Node_Id;
6583
6584          begin
6585             GNAT_Pragma;
6586             Check_At_Least_N_Arguments (1);
6587             Check_Arg_Is_Identifier (Arg1);
6588             Check_No_Identifiers;
6589             Store_Note (N);
6590
6591             --  Second parameter is optional, it is never analyzed
6592
6593             if No (Arg2) then
6594                null;
6595
6596             --  Here if we have a second parameter
6597
6598             else
6599                --  Second parameter must be identifier
6600
6601                Check_Arg_Is_Identifier (Arg2);
6602
6603                --  Process remaining parameters if any
6604
6605                Arg := Next (Arg2);
6606                while Present (Arg) loop
6607                   Exp := Get_Pragma_Arg (Arg);
6608                   Analyze (Exp);
6609
6610                   if Is_Entity_Name (Exp) then
6611                      null;
6612
6613                   --  For string literals, we assume Standard_String as the
6614                   --  type, unless the string contains wide or wide_wide
6615                   --  characters.
6616
6617                   elsif Nkind (Exp) = N_String_Literal then
6618                      if Has_Wide_Wide_Character (Exp) then
6619                         Resolve (Exp, Standard_Wide_Wide_String);
6620                      elsif Has_Wide_Character (Exp) then
6621                         Resolve (Exp, Standard_Wide_String);
6622                      else
6623                         Resolve (Exp, Standard_String);
6624                      end if;
6625
6626                   elsif Is_Overloaded (Exp) then
6627                         Error_Pragma_Arg
6628                           ("ambiguous argument for pragma%", Exp);
6629
6630                   else
6631                      Resolve (Exp);
6632                   end if;
6633
6634                   Next (Arg);
6635                end loop;
6636             end if;
6637          end Annotate;
6638
6639          ------------
6640          -- Assert --
6641          ------------
6642
6643          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6644          --                 [, [Message =>] Static_String_EXPRESSION]);
6645
6646          when Pragma_Assert => Assert : declare
6647             Expr : Node_Id;
6648             Newa : List_Id;
6649
6650          begin
6651             Ada_2005_Pragma;
6652             Check_At_Least_N_Arguments (1);
6653             Check_At_Most_N_Arguments (2);
6654             Check_Arg_Order ((Name_Check, Name_Message));
6655             Check_Optional_Identifier (Arg1, Name_Check);
6656
6657             --  We treat pragma Assert as equivalent to:
6658
6659             --    pragma Check (Assertion, condition [, msg]);
6660
6661             --  So rewrite pragma in this manner, and analyze the result
6662
6663             Expr := Get_Pragma_Arg (Arg1);
6664             Newa := New_List (
6665               Make_Pragma_Argument_Association (Loc,
6666                 Expression => Make_Identifier (Loc, Name_Assertion)),
6667
6668               Make_Pragma_Argument_Association (Sloc (Expr),
6669                 Expression => Expr));
6670
6671             if Arg_Count > 1 then
6672                Check_Optional_Identifier (Arg2, Name_Message);
6673                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6674                Append_To (Newa, Relocate_Node (Arg2));
6675             end if;
6676
6677             Rewrite (N,
6678               Make_Pragma (Loc,
6679                 Chars                        => Name_Check,
6680                 Pragma_Argument_Associations => Newa));
6681             Analyze (N);
6682          end Assert;
6683
6684          ----------------------
6685          -- Assertion_Policy --
6686          ----------------------
6687
6688          --  pragma Assertion_Policy (Check | Disable |Ignore)
6689
6690          when Pragma_Assertion_Policy => Assertion_Policy : declare
6691             Policy : Node_Id;
6692
6693          begin
6694             Ada_2005_Pragma;
6695             Check_Valid_Configuration_Pragma;
6696             Check_Arg_Count (1);
6697             Check_No_Identifiers;
6698             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6699
6700             --  We treat pragma Assertion_Policy as equivalent to:
6701
6702             --    pragma Check_Policy (Assertion, policy)
6703
6704             --  So rewrite the pragma in that manner and link on to the chain
6705             --  of Check_Policy pragmas, marking the pragma as analyzed.
6706
6707             Policy := Get_Pragma_Arg (Arg1);
6708
6709             Rewrite (N,
6710               Make_Pragma (Loc,
6711                 Chars => Name_Check_Policy,
6712
6713                 Pragma_Argument_Associations => New_List (
6714                   Make_Pragma_Argument_Association (Loc,
6715                     Expression => Make_Identifier (Loc, Name_Assertion)),
6716
6717                   Make_Pragma_Argument_Association (Loc,
6718                     Expression =>
6719                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6720
6721             Set_Analyzed (N);
6722             Set_Next_Pragma (N, Opt.Check_Policy_List);
6723             Opt.Check_Policy_List := N;
6724          end Assertion_Policy;
6725
6726          ------------------------------
6727          -- Assume_No_Invalid_Values --
6728          ------------------------------
6729
6730          --  pragma Assume_No_Invalid_Values (On | Off);
6731
6732          when Pragma_Assume_No_Invalid_Values =>
6733             GNAT_Pragma;
6734             Check_Valid_Configuration_Pragma;
6735             Check_Arg_Count (1);
6736             Check_No_Identifiers;
6737             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6738
6739             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6740                Assume_No_Invalid_Values := True;
6741             else
6742                Assume_No_Invalid_Values := False;
6743             end if;
6744
6745          ---------------
6746          -- AST_Entry --
6747          ---------------
6748
6749          --  pragma AST_Entry (entry_IDENTIFIER);
6750
6751          when Pragma_AST_Entry => AST_Entry : declare
6752             Ent : Node_Id;
6753
6754          begin
6755             GNAT_Pragma;
6756             Check_VMS (N);
6757             Check_Arg_Count (1);
6758             Check_No_Identifiers;
6759             Check_Arg_Is_Local_Name (Arg1);
6760             Ent := Entity (Get_Pragma_Arg (Arg1));
6761
6762             --  Note: the implementation of the AST_Entry pragma could handle
6763             --  the entry family case fine, but for now we are consistent with
6764             --  the DEC rules, and do not allow the pragma, which of course
6765             --  has the effect of also forbidding the attribute.
6766
6767             if Ekind (Ent) /= E_Entry then
6768                Error_Pragma_Arg
6769                  ("pragma% argument must be simple entry name", Arg1);
6770
6771             elsif Is_AST_Entry (Ent) then
6772                Error_Pragma_Arg
6773                  ("duplicate % pragma for entry", Arg1);
6774
6775             elsif Has_Homonym (Ent) then
6776                Error_Pragma_Arg
6777                  ("pragma% argument cannot specify overloaded entry", Arg1);
6778
6779             else
6780                declare
6781                   FF : constant Entity_Id := First_Formal (Ent);
6782
6783                begin
6784                   if Present (FF) then
6785                      if Present (Next_Formal (FF)) then
6786                         Error_Pragma_Arg
6787                           ("entry for pragma% can have only one argument",
6788                            Arg1);
6789
6790                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6791                         Error_Pragma_Arg
6792                           ("entry parameter for pragma% must have mode IN",
6793                            Arg1);
6794                      end if;
6795                   end if;
6796                end;
6797
6798                Set_Is_AST_Entry (Ent);
6799             end if;
6800          end AST_Entry;
6801
6802          ------------------
6803          -- Asynchronous --
6804          ------------------
6805
6806          --  pragma Asynchronous (LOCAL_NAME);
6807
6808          when Pragma_Asynchronous => Asynchronous : declare
6809             Nm     : Entity_Id;
6810             C_Ent  : Entity_Id;
6811             L      : List_Id;
6812             S      : Node_Id;
6813             N      : Node_Id;
6814             Formal : Entity_Id;
6815
6816             procedure Process_Async_Pragma;
6817             --  Common processing for procedure and access-to-procedure case
6818
6819             --------------------------
6820             -- Process_Async_Pragma --
6821             --------------------------
6822
6823             procedure Process_Async_Pragma is
6824             begin
6825                if No (L) then
6826                   Set_Is_Asynchronous (Nm);
6827                   return;
6828                end if;
6829
6830                --  The formals should be of mode IN (RM E.4.1(6))
6831
6832                S := First (L);
6833                while Present (S) loop
6834                   Formal := Defining_Identifier (S);
6835
6836                   if Nkind (Formal) = N_Defining_Identifier
6837                     and then Ekind (Formal) /= E_In_Parameter
6838                   then
6839                      Error_Pragma_Arg
6840                        ("pragma% procedure can only have IN parameter",
6841                         Arg1);
6842                   end if;
6843
6844                   Next (S);
6845                end loop;
6846
6847                Set_Is_Asynchronous (Nm);
6848             end Process_Async_Pragma;
6849
6850          --  Start of processing for pragma Asynchronous
6851
6852          begin
6853             Check_Ada_83_Warning;
6854             Check_No_Identifiers;
6855             Check_Arg_Count (1);
6856             Check_Arg_Is_Local_Name (Arg1);
6857
6858             if Debug_Flag_U then
6859                return;
6860             end if;
6861
6862             C_Ent := Cunit_Entity (Current_Sem_Unit);
6863             Analyze (Get_Pragma_Arg (Arg1));
6864             Nm := Entity (Get_Pragma_Arg (Arg1));
6865
6866             if not Is_Remote_Call_Interface (C_Ent)
6867               and then not Is_Remote_Types (C_Ent)
6868             then
6869                --  This pragma should only appear in an RCI or Remote Types
6870                --  unit (RM E.4.1(4)).
6871
6872                Error_Pragma
6873                  ("pragma% not in Remote_Call_Interface or " &
6874                   "Remote_Types unit");
6875             end if;
6876
6877             if Ekind (Nm) = E_Procedure
6878               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6879             then
6880                if not Is_Remote_Call_Interface (Nm) then
6881                   Error_Pragma_Arg
6882                     ("pragma% cannot be applied on non-remote procedure",
6883                      Arg1);
6884                end if;
6885
6886                L := Parameter_Specifications (Parent (Nm));
6887                Process_Async_Pragma;
6888                return;
6889
6890             elsif Ekind (Nm) = E_Function then
6891                Error_Pragma_Arg
6892                  ("pragma% cannot be applied to function", Arg1);
6893
6894             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6895                   if Is_Record_Type (Nm) then
6896
6897                   --  A record type that is the Equivalent_Type for a remote
6898                   --  access-to-subprogram type.
6899
6900                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6901
6902                   else
6903                      --  A non-expanded RAS type (distribution is not enabled)
6904
6905                      N := Declaration_Node (Nm);
6906                   end if;
6907
6908                if Nkind (N) = N_Full_Type_Declaration
6909                  and then Nkind (Type_Definition (N)) =
6910                                      N_Access_Procedure_Definition
6911                then
6912                   L := Parameter_Specifications (Type_Definition (N));
6913                   Process_Async_Pragma;
6914
6915                   if Is_Asynchronous (Nm)
6916                     and then Expander_Active
6917                     and then Get_PCS_Name /= Name_No_DSA
6918                   then
6919                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6920                   end if;
6921
6922                else
6923                   Error_Pragma_Arg
6924                     ("pragma% cannot reference access-to-function type",
6925                     Arg1);
6926                end if;
6927
6928             --  Only other possibility is Access-to-class-wide type
6929
6930             elsif Is_Access_Type (Nm)
6931               and then Is_Class_Wide_Type (Designated_Type (Nm))
6932             then
6933                Check_First_Subtype (Arg1);
6934                Set_Is_Asynchronous (Nm);
6935                if Expander_Active then
6936                   RACW_Type_Is_Asynchronous (Nm);
6937                end if;
6938
6939             else
6940                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6941             end if;
6942          end Asynchronous;
6943
6944          ------------
6945          -- Atomic --
6946          ------------
6947
6948          --  pragma Atomic (LOCAL_NAME);
6949
6950          when Pragma_Atomic =>
6951             Process_Atomic_Shared_Volatile;
6952
6953          -----------------------
6954          -- Atomic_Components --
6955          -----------------------
6956
6957          --  pragma Atomic_Components (array_LOCAL_NAME);
6958
6959          --  This processing is shared by Volatile_Components
6960
6961          when Pragma_Atomic_Components   |
6962               Pragma_Volatile_Components =>
6963
6964          Atomic_Components : declare
6965             E_Id : Node_Id;
6966             E    : Entity_Id;
6967             D    : Node_Id;
6968             K    : Node_Kind;
6969
6970          begin
6971             Check_Ada_83_Warning;
6972             Check_No_Identifiers;
6973             Check_Arg_Count (1);
6974             Check_Arg_Is_Local_Name (Arg1);
6975             E_Id := Get_Pragma_Arg (Arg1);
6976
6977             if Etype (E_Id) = Any_Type then
6978                return;
6979             end if;
6980
6981             E := Entity (E_Id);
6982
6983             Check_Duplicate_Pragma (E);
6984
6985             if Rep_Item_Too_Early (E, N)
6986                  or else
6987                Rep_Item_Too_Late (E, N)
6988             then
6989                return;
6990             end if;
6991
6992             D := Declaration_Node (E);
6993             K := Nkind (D);
6994
6995             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6996               or else
6997                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6998                    and then Nkind (D) = N_Object_Declaration
6999                    and then Nkind (Object_Definition (D)) =
7000                                        N_Constrained_Array_Definition)
7001             then
7002                --  The flag is set on the object, or on the base type
7003
7004                if Nkind (D) /= N_Object_Declaration then
7005                   E := Base_Type (E);
7006                end if;
7007
7008                Set_Has_Volatile_Components (E);
7009
7010                if Prag_Id = Pragma_Atomic_Components then
7011                   Set_Has_Atomic_Components (E);
7012                end if;
7013
7014             else
7015                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7016             end if;
7017          end Atomic_Components;
7018          --------------------
7019          -- Attach_Handler --
7020          --------------------
7021
7022          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
7023
7024          when Pragma_Attach_Handler =>
7025             Check_Ada_83_Warning;
7026             Check_No_Identifiers;
7027             Check_Arg_Count (2);
7028
7029             if No_Run_Time_Mode then
7030                Error_Msg_CRT ("Attach_Handler pragma", N);
7031             else
7032                Check_Interrupt_Or_Attach_Handler;
7033
7034                --  The expression that designates the attribute may depend on a
7035                --  discriminant, and is therefore a per- object expression, to
7036                --  be expanded in the init proc. If expansion is enabled, then
7037                --  perform semantic checks on a copy only.
7038
7039                if Expander_Active then
7040                   declare
7041                      Temp : constant Node_Id :=
7042                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
7043                   begin
7044                      Set_Parent (Temp, N);
7045                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7046                   end;
7047
7048                else
7049                   Analyze (Get_Pragma_Arg (Arg2));
7050                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7051                end if;
7052
7053                Process_Interrupt_Or_Attach_Handler;
7054             end if;
7055
7056          --------------------
7057          -- C_Pass_By_Copy --
7058          --------------------
7059
7060          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7061
7062          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7063             Arg : Node_Id;
7064             Val : Uint;
7065
7066          begin
7067             GNAT_Pragma;
7068             Check_Valid_Configuration_Pragma;
7069             Check_Arg_Count (1);
7070             Check_Optional_Identifier (Arg1, "max_size");
7071
7072             Arg := Get_Pragma_Arg (Arg1);
7073             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7074
7075             Val := Expr_Value (Arg);
7076
7077             if Val <= 0 then
7078                Error_Pragma_Arg
7079                  ("maximum size for pragma% must be positive", Arg1);
7080
7081             elsif UI_Is_In_Int_Range (Val) then
7082                Default_C_Record_Mechanism := UI_To_Int (Val);
7083
7084             --  If a giant value is given, Int'Last will do well enough.
7085             --  If sometime someone complains that a record larger than
7086             --  two gigabytes is not copied, we will worry about it then!
7087
7088             else
7089                Default_C_Record_Mechanism := Mechanism_Type'Last;
7090             end if;
7091          end C_Pass_By_Copy;
7092
7093          -----------
7094          -- Check --
7095          -----------
7096
7097          --  pragma Check ([Name    =>] IDENTIFIER,
7098          --                [Check   =>] Boolean_EXPRESSION
7099          --              [,[Message =>] String_EXPRESSION]);
7100
7101          when Pragma_Check => Check : declare
7102             Expr : Node_Id;
7103             Eloc : Source_Ptr;
7104
7105             Check_On : Boolean;
7106             --  Set True if category of assertions referenced by Name enabled
7107
7108          begin
7109             GNAT_Pragma;
7110             Check_At_Least_N_Arguments (2);
7111             Check_At_Most_N_Arguments (3);
7112             Check_Optional_Identifier (Arg1, Name_Name);
7113             Check_Optional_Identifier (Arg2, Name_Check);
7114
7115             if Arg_Count = 3 then
7116                Check_Optional_Identifier (Arg3, Name_Message);
7117                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7118             end if;
7119
7120             Check_Arg_Is_Identifier (Arg1);
7121
7122             --  Completely ignore if disabled
7123
7124             if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7125                Rewrite (N, Make_Null_Statement (Loc));
7126                Analyze (N);
7127                return;
7128             end if;
7129
7130             --  Indicate if pragma is enabled. The Original_Node reference here
7131             --  is to deal with pragma Assert rewritten as a Check pragma.
7132
7133             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7134
7135             if Check_On then
7136                Set_SCO_Pragma_Enabled (Loc);
7137             end if;
7138
7139             --  If expansion is active and the check is not enabled then we
7140             --  rewrite the Check as:
7141
7142             --    if False and then condition then
7143             --       null;
7144             --    end if;
7145
7146             --  The reason we do this rewriting during semantic analysis rather
7147             --  than as part of normal expansion is that we cannot analyze and
7148             --  expand the code for the boolean expression directly, or it may
7149             --  cause insertion of actions that would escape the attempt to
7150             --  suppress the check code.
7151
7152             --  Note that the Sloc for the if statement corresponds to the
7153             --  argument condition, not the pragma itself. The reason for this
7154             --  is that we may generate a warning if the condition is False at
7155             --  compile time, and we do not want to delete this warning when we
7156             --  delete the if statement.
7157
7158             Expr := Get_Pragma_Arg (Arg2);
7159
7160             if Expander_Active and then not Check_On then
7161                Eloc := Sloc (Expr);
7162
7163                Rewrite (N,
7164                  Make_If_Statement (Eloc,
7165                    Condition =>
7166                      Make_And_Then (Eloc,
7167                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
7168                        Right_Opnd => Expr),
7169                    Then_Statements => New_List (
7170                      Make_Null_Statement (Eloc))));
7171
7172                Analyze (N);
7173
7174             --  Check is active
7175
7176             else
7177                Analyze_And_Resolve (Expr, Any_Boolean);
7178             end if;
7179          end Check;
7180
7181          ----------------
7182          -- Check_Name --
7183          ----------------
7184
7185          --  pragma Check_Name (check_IDENTIFIER);
7186
7187          when Pragma_Check_Name =>
7188             Check_No_Identifiers;
7189             GNAT_Pragma;
7190             Check_Valid_Configuration_Pragma;
7191             Check_Arg_Count (1);
7192             Check_Arg_Is_Identifier (Arg1);
7193
7194             declare
7195                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7196
7197             begin
7198                for J in Check_Names.First .. Check_Names.Last loop
7199                   if Check_Names.Table (J) = Nam then
7200                      return;
7201                   end if;
7202                end loop;
7203
7204                Check_Names.Append (Nam);
7205             end;
7206
7207          ------------------
7208          -- Check_Policy --
7209          ------------------
7210
7211          --  pragma Check_Policy (
7212          --    [Name   =>] IDENTIFIER,
7213          --    [Policy =>] POLICY_IDENTIFIER);
7214
7215          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7216
7217          --  Note: this is a configuration pragma, but it is allowed to appear
7218          --  anywhere else.
7219
7220          when Pragma_Check_Policy =>
7221             GNAT_Pragma;
7222             Check_Arg_Count (2);
7223             Check_Optional_Identifier (Arg1, Name_Name);
7224             Check_Optional_Identifier (Arg2, Name_Policy);
7225             Check_Arg_Is_One_Of
7226               (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7227
7228             --  A Check_Policy pragma can appear either as a configuration
7229             --  pragma, or in a declarative part or a package spec (see RM
7230             --  11.5(5) for rules for Suppress/Unsuppress which are also
7231             --  followed for Check_Policy).
7232
7233             if not Is_Configuration_Pragma then
7234                Check_Is_In_Decl_Part_Or_Package_Spec;
7235             end if;
7236
7237             Set_Next_Pragma (N, Opt.Check_Policy_List);
7238             Opt.Check_Policy_List := N;
7239
7240          ---------------------
7241          -- CIL_Constructor --
7242          ---------------------
7243
7244          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7245
7246          --  Processing for this pragma is shared with Java_Constructor
7247
7248          -------------
7249          -- Comment --
7250          -------------
7251
7252          --  pragma Comment (static_string_EXPRESSION)
7253
7254          --  Processing for pragma Comment shares the circuitry for pragma
7255          --  Ident. The only differences are that Ident enforces a limit of 31
7256          --  characters on its argument, and also enforces limitations on
7257          --  placement for DEC compatibility. Pragma Comment shares neither of
7258          --  these restrictions.
7259
7260          -------------------
7261          -- Common_Object --
7262          -------------------
7263
7264          --  pragma Common_Object (
7265          --        [Internal =>] LOCAL_NAME
7266          --     [, [External =>] EXTERNAL_SYMBOL]
7267          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7268
7269          --  Processing for this pragma is shared with Psect_Object
7270
7271          ------------------------
7272          -- Compile_Time_Error --
7273          ------------------------
7274
7275          --  pragma Compile_Time_Error
7276          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7277
7278          when Pragma_Compile_Time_Error =>
7279             GNAT_Pragma;
7280             Process_Compile_Time_Warning_Or_Error;
7281
7282          --------------------------
7283          -- Compile_Time_Warning --
7284          --------------------------
7285
7286          --  pragma Compile_Time_Warning
7287          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7288
7289          when Pragma_Compile_Time_Warning =>
7290             GNAT_Pragma;
7291             Process_Compile_Time_Warning_Or_Error;
7292
7293          -------------------
7294          -- Compiler_Unit --
7295          -------------------
7296
7297          when Pragma_Compiler_Unit =>
7298             GNAT_Pragma;
7299             Check_Arg_Count (0);
7300             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7301
7302          -----------------------------
7303          -- Complete_Representation --
7304          -----------------------------
7305
7306          --  pragma Complete_Representation;
7307
7308          when Pragma_Complete_Representation =>
7309             GNAT_Pragma;
7310             Check_Arg_Count (0);
7311
7312             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7313                Error_Pragma
7314                  ("pragma & must appear within record representation clause");
7315             end if;
7316
7317          ----------------------------
7318          -- Complex_Representation --
7319          ----------------------------
7320
7321          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7322
7323          when Pragma_Complex_Representation => Complex_Representation : declare
7324             E_Id : Entity_Id;
7325             E    : Entity_Id;
7326             Ent  : Entity_Id;
7327
7328          begin
7329             GNAT_Pragma;
7330             Check_Arg_Count (1);
7331             Check_Optional_Identifier (Arg1, Name_Entity);
7332             Check_Arg_Is_Local_Name (Arg1);
7333             E_Id := Get_Pragma_Arg (Arg1);
7334
7335             if Etype (E_Id) = Any_Type then
7336                return;
7337             end if;
7338
7339             E := Entity (E_Id);
7340
7341             if not Is_Record_Type (E) then
7342                Error_Pragma_Arg
7343                  ("argument for pragma% must be record type", Arg1);
7344             end if;
7345
7346             Ent := First_Entity (E);
7347
7348             if No (Ent)
7349               or else No (Next_Entity (Ent))
7350               or else Present (Next_Entity (Next_Entity (Ent)))
7351               or else not Is_Floating_Point_Type (Etype (Ent))
7352               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7353             then
7354                Error_Pragma_Arg
7355                  ("record for pragma% must have two fields of the same "
7356                   & "floating-point type", Arg1);
7357
7358             else
7359                Set_Has_Complex_Representation (Base_Type (E));
7360
7361                --  We need to treat the type has having a non-standard
7362                --  representation, for back-end purposes, even though in
7363                --  general a complex will have the default representation
7364                --  of a record with two real components.
7365
7366                Set_Has_Non_Standard_Rep (Base_Type (E));
7367             end if;
7368          end Complex_Representation;
7369
7370          -------------------------
7371          -- Component_Alignment --
7372          -------------------------
7373
7374          --  pragma Component_Alignment (
7375          --        [Form =>] ALIGNMENT_CHOICE
7376          --     [, [Name =>] type_LOCAL_NAME]);
7377          --
7378          --   ALIGNMENT_CHOICE ::=
7379          --     Component_Size
7380          --   | Component_Size_4
7381          --   | Storage_Unit
7382          --   | Default
7383
7384          when Pragma_Component_Alignment => Component_AlignmentP : declare
7385             Args  : Args_List (1 .. 2);
7386             Names : constant Name_List (1 .. 2) := (
7387                       Name_Form,
7388                       Name_Name);
7389
7390             Form  : Node_Id renames Args (1);
7391             Name  : Node_Id renames Args (2);
7392
7393             Atype : Component_Alignment_Kind;
7394             Typ   : Entity_Id;
7395
7396          begin
7397             GNAT_Pragma;
7398             Gather_Associations (Names, Args);
7399
7400             if No (Form) then
7401                Error_Pragma ("missing Form argument for pragma%");
7402             end if;
7403
7404             Check_Arg_Is_Identifier (Form);
7405
7406             --  Get proper alignment, note that Default = Component_Size on all
7407             --  machines we have so far, and we want to set this value rather
7408             --  than the default value to indicate that it has been explicitly
7409             --  set (and thus will not get overridden by the default component
7410             --  alignment for the current scope)
7411
7412             if Chars (Form) = Name_Component_Size then
7413                Atype := Calign_Component_Size;
7414
7415             elsif Chars (Form) = Name_Component_Size_4 then
7416                Atype := Calign_Component_Size_4;
7417
7418             elsif Chars (Form) = Name_Default then
7419                Atype := Calign_Component_Size;
7420
7421             elsif Chars (Form) = Name_Storage_Unit then
7422                Atype := Calign_Storage_Unit;
7423
7424             else
7425                Error_Pragma_Arg
7426                  ("invalid Form parameter for pragma%", Form);
7427             end if;
7428
7429             --  Case with no name, supplied, affects scope table entry
7430
7431             if No (Name) then
7432                Scope_Stack.Table
7433                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7434
7435             --  Case of name supplied
7436
7437             else
7438                Check_Arg_Is_Local_Name (Name);
7439                Find_Type (Name);
7440                Typ := Entity (Name);
7441
7442                if Typ = Any_Type
7443                  or else Rep_Item_Too_Early (Typ, N)
7444                then
7445                   return;
7446                else
7447                   Typ := Underlying_Type (Typ);
7448                end if;
7449
7450                if not Is_Record_Type (Typ)
7451                  and then not Is_Array_Type (Typ)
7452                then
7453                   Error_Pragma_Arg
7454                     ("Name parameter of pragma% must identify record or " &
7455                      "array type", Name);
7456                end if;
7457
7458                --  An explicit Component_Alignment pragma overrides an
7459                --  implicit pragma Pack, but not an explicit one.
7460
7461                if not Has_Pragma_Pack (Base_Type (Typ)) then
7462                   Set_Is_Packed (Base_Type (Typ), False);
7463                   Set_Component_Alignment (Base_Type (Typ), Atype);
7464                end if;
7465             end if;
7466          end Component_AlignmentP;
7467
7468          ----------------
7469          -- Controlled --
7470          ----------------
7471
7472          --  pragma Controlled (first_subtype_LOCAL_NAME);
7473
7474          when Pragma_Controlled => Controlled : declare
7475             Arg : Node_Id;
7476
7477          begin
7478             Check_No_Identifiers;
7479             Check_Arg_Count (1);
7480             Check_Arg_Is_Local_Name (Arg1);
7481             Arg := Get_Pragma_Arg (Arg1);
7482
7483             if not Is_Entity_Name (Arg)
7484               or else not Is_Access_Type (Entity (Arg))
7485             then
7486                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7487             else
7488                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7489             end if;
7490          end Controlled;
7491
7492          ----------------
7493          -- Convention --
7494          ----------------
7495
7496          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7497          --    [Entity =>] LOCAL_NAME);
7498
7499          when Pragma_Convention => Convention : declare
7500             C : Convention_Id;
7501             E : Entity_Id;
7502             pragma Warnings (Off, C);
7503             pragma Warnings (Off, E);
7504          begin
7505             Check_Arg_Order ((Name_Convention, Name_Entity));
7506             Check_Ada_83_Warning;
7507             Check_Arg_Count (2);
7508             Process_Convention (C, E);
7509          end Convention;
7510
7511          ---------------------------
7512          -- Convention_Identifier --
7513          ---------------------------
7514
7515          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7516          --    [Convention =>] convention_IDENTIFIER);
7517
7518          when Pragma_Convention_Identifier => Convention_Identifier : declare
7519             Idnam : Name_Id;
7520             Cname : Name_Id;
7521
7522          begin
7523             GNAT_Pragma;
7524             Check_Arg_Order ((Name_Name, Name_Convention));
7525             Check_Arg_Count (2);
7526             Check_Optional_Identifier (Arg1, Name_Name);
7527             Check_Optional_Identifier (Arg2, Name_Convention);
7528             Check_Arg_Is_Identifier (Arg1);
7529             Check_Arg_Is_Identifier (Arg2);
7530             Idnam := Chars (Get_Pragma_Arg (Arg1));
7531             Cname := Chars (Get_Pragma_Arg (Arg2));
7532
7533             if Is_Convention_Name (Cname) then
7534                Record_Convention_Identifier
7535                  (Idnam, Get_Convention_Id (Cname));
7536             else
7537                Error_Pragma_Arg
7538                  ("second arg for % pragma must be convention", Arg2);
7539             end if;
7540          end Convention_Identifier;
7541
7542          ---------------
7543          -- CPP_Class --
7544          ---------------
7545
7546          --  pragma CPP_Class ([Entity =>] local_NAME)
7547
7548          when Pragma_CPP_Class => CPP_Class : declare
7549             Arg : Node_Id;
7550             Typ : Entity_Id;
7551
7552          begin
7553             if Warn_On_Obsolescent_Feature then
7554                Error_Msg_N
7555                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7556                   " by pragma import?", N);
7557             end if;
7558
7559             GNAT_Pragma;
7560             Check_Arg_Count (1);
7561             Check_Optional_Identifier (Arg1, Name_Entity);
7562             Check_Arg_Is_Local_Name (Arg1);
7563
7564             Arg := Get_Pragma_Arg (Arg1);
7565             Analyze (Arg);
7566
7567             if Etype (Arg) = Any_Type then
7568                return;
7569             end if;
7570
7571             if not Is_Entity_Name (Arg)
7572               or else not Is_Type (Entity (Arg))
7573             then
7574                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7575             end if;
7576
7577             Typ := Entity (Arg);
7578
7579             if not Is_Tagged_Type (Typ) then
7580                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7581             end if;
7582
7583             --  Types treated as CPP classes must be declared limited (note:
7584             --  this used to be a warning but there is no real benefit to it
7585             --  since we did effectively intend to treat the type as limited
7586             --  anyway).
7587
7588             if not Is_Limited_Type (Typ) then
7589                Error_Msg_N
7590                  ("imported 'C'P'P type must be limited",
7591                   Get_Pragma_Arg (Arg1));
7592             end if;
7593
7594             Set_Is_CPP_Class      (Typ);
7595             Set_Convention        (Typ, Convention_CPP);
7596
7597             --  Imported CPP types must not have discriminants (because C++
7598             --  classes do not have discriminants).
7599
7600             if Has_Discriminants (Typ) then
7601                Error_Msg_N
7602                  ("imported 'C'P'P type cannot have discriminants",
7603                   First (Discriminant_Specifications
7604                           (Declaration_Node (Typ))));
7605             end if;
7606
7607             --  Components of imported CPP types must not have default
7608             --  expressions because the constructor (if any) is in the
7609             --  C++ side.
7610
7611             if Is_Incomplete_Or_Private_Type (Typ)
7612               and then No (Underlying_Type (Typ))
7613             then
7614                --  It should be an error to apply pragma CPP to a private
7615                --  type if the underlying type is not visible (as it is
7616                --  for any representation item). For now, for backward
7617                --  compatibility we do nothing but we cannot check components
7618                --  because they are not available at this stage. All this code
7619                --  will be removed when we cleanup this obsolete GNAT pragma???
7620
7621                null;
7622
7623             else
7624                declare
7625                   Tdef  : constant Node_Id :=
7626                             Type_Definition (Declaration_Node (Typ));
7627                   Clist : Node_Id;
7628                   Comp  : Node_Id;
7629
7630                begin
7631                   if Nkind (Tdef) = N_Record_Definition then
7632                      Clist := Component_List (Tdef);
7633                   else
7634                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7635                      Clist := Component_List (Record_Extension_Part (Tdef));
7636                   end if;
7637
7638                   if Present (Clist) then
7639                      Comp := First (Component_Items (Clist));
7640                      while Present (Comp) loop
7641                         if Present (Expression (Comp)) then
7642                            Error_Msg_N
7643                              ("component of imported 'C'P'P type cannot have" &
7644                               " default expression", Expression (Comp));
7645                         end if;
7646
7647                         Next (Comp);
7648                      end loop;
7649                   end if;
7650                end;
7651             end if;
7652          end CPP_Class;
7653
7654          ---------------------
7655          -- CPP_Constructor --
7656          ---------------------
7657
7658          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7659          --    [, [External_Name =>] static_string_EXPRESSION ]
7660          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7661
7662          when Pragma_CPP_Constructor => CPP_Constructor : declare
7663             Elmt    : Elmt_Id;
7664             Id      : Entity_Id;
7665             Def_Id  : Entity_Id;
7666             Tag_Typ : Entity_Id;
7667
7668          begin
7669             GNAT_Pragma;
7670             Check_At_Least_N_Arguments (1);
7671             Check_At_Most_N_Arguments (3);
7672             Check_Optional_Identifier (Arg1, Name_Entity);
7673             Check_Arg_Is_Local_Name (Arg1);
7674
7675             Id := Get_Pragma_Arg (Arg1);
7676             Find_Program_Unit_Name (Id);
7677
7678             --  If we did not find the name, we are done
7679
7680             if Etype (Id) = Any_Type then
7681                return;
7682             end if;
7683
7684             Def_Id := Entity (Id);
7685
7686             --  Check if already defined as constructor
7687
7688             if Is_Constructor (Def_Id) then
7689                Error_Msg_N
7690                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7691                return;
7692             end if;
7693
7694             if Ekind (Def_Id) = E_Function
7695               and then (Is_CPP_Class (Etype (Def_Id))
7696                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7697                                    and then
7698                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7699             then
7700                if Arg_Count >= 2 then
7701                   Set_Imported (Def_Id);
7702                   Set_Is_Public (Def_Id);
7703                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7704                end if;
7705
7706                Set_Has_Completion (Def_Id);
7707                Set_Is_Constructor (Def_Id);
7708
7709                --  Imported C++ constructors are not dispatching primitives
7710                --  because in C++ they don't have a dispatch table slot.
7711                --  However, in Ada the constructor has the profile of a
7712                --  function that returns a tagged type and therefore it has
7713                --  been treated as a primitive operation during semantic
7714                --  analysis. We now remove it from the list of primitive
7715                --  operations of the type.
7716
7717                if Is_Tagged_Type (Etype (Def_Id))
7718                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7719                then
7720                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7721                   Tag_Typ := Etype (Def_Id);
7722
7723                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7724                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7725                      Next_Elmt (Elmt);
7726                   end loop;
7727
7728                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7729                   Set_Is_Dispatching_Operation (Def_Id, False);
7730                end if;
7731
7732                --  For backward compatibility, if the constructor returns a
7733                --  class wide type, and we internally change the return type to
7734                --  the corresponding root type.
7735
7736                if Is_Class_Wide_Type (Etype (Def_Id)) then
7737                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7738                end if;
7739             else
7740                Error_Pragma_Arg
7741                  ("pragma% requires function returning a 'C'P'P_Class type",
7742                    Arg1);
7743             end if;
7744          end CPP_Constructor;
7745
7746          -----------------
7747          -- CPP_Virtual --
7748          -----------------
7749
7750          when Pragma_CPP_Virtual => CPP_Virtual : declare
7751          begin
7752             GNAT_Pragma;
7753
7754             if Warn_On_Obsolescent_Feature then
7755                Error_Msg_N
7756                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7757                   "no effect?", N);
7758             end if;
7759          end CPP_Virtual;
7760
7761          ----------------
7762          -- CPP_Vtable --
7763          ----------------
7764
7765          when Pragma_CPP_Vtable => CPP_Vtable : declare
7766          begin
7767             GNAT_Pragma;
7768
7769             if Warn_On_Obsolescent_Feature then
7770                Error_Msg_N
7771                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7772                   "no effect?", N);
7773             end if;
7774          end CPP_Vtable;
7775
7776          ---------
7777          -- CPU --
7778          ---------
7779
7780          --  pragma CPU (EXPRESSION);
7781
7782          when Pragma_CPU => CPU : declare
7783             P   : constant Node_Id := Parent (N);
7784             Arg : Node_Id;
7785
7786          begin
7787             Ada_2012_Pragma;
7788             Check_No_Identifiers;
7789             Check_Arg_Count (1);
7790
7791             --  Subprogram case
7792
7793             if Nkind (P) = N_Subprogram_Body then
7794                Check_In_Main_Program;
7795
7796                Arg := Get_Pragma_Arg (Arg1);
7797                Analyze_And_Resolve (Arg, Any_Integer);
7798
7799                --  Must be static
7800
7801                if not Is_Static_Expression (Arg) then
7802                   Flag_Non_Static_Expr
7803                     ("main subprogram affinity is not static!", Arg);
7804                   raise Pragma_Exit;
7805
7806                --  If constraint error, then we already signalled an error
7807
7808                elsif Raises_Constraint_Error (Arg) then
7809                   null;
7810
7811                --  Otherwise check in range
7812
7813                else
7814                   declare
7815                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7816                      --  This is the entity System.Multiprocessors.CPU_Range;
7817
7818                      Val : constant Uint := Expr_Value (Arg);
7819
7820                   begin
7821                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7822                           or else
7823                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7824                      then
7825                         Error_Pragma_Arg
7826                           ("main subprogram CPU is out of range", Arg1);
7827                      end if;
7828                   end;
7829                end if;
7830
7831                Set_Main_CPU
7832                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7833
7834             --  Task case
7835
7836             elsif Nkind (P) = N_Task_Definition then
7837                Arg := Get_Pragma_Arg (Arg1);
7838
7839                --  The expression must be analyzed in the special manner
7840                --  described in "Handling of Default and Per-Object
7841                --  Expressions" in sem.ads.
7842
7843                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7844
7845             --  Anything else is incorrect
7846
7847             else
7848                Pragma_Misplaced;
7849             end if;
7850
7851             if Has_Pragma_CPU (P) then
7852                Error_Pragma ("duplicate pragma% not allowed");
7853             else
7854                Set_Has_Pragma_CPU (P, True);
7855
7856                if Nkind (P) = N_Task_Definition then
7857                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7858                end if;
7859             end if;
7860          end CPU;
7861
7862          -----------
7863          -- Debug --
7864          -----------
7865
7866          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7867
7868          when Pragma_Debug => Debug : declare
7869             Cond : Node_Id;
7870             Call : Node_Id;
7871
7872          begin
7873             GNAT_Pragma;
7874
7875             --  Skip analysis if disabled
7876
7877             if Debug_Pragmas_Disabled then
7878                Rewrite (N, Make_Null_Statement (Loc));
7879                Analyze (N);
7880                return;
7881             end if;
7882
7883             Cond :=
7884               New_Occurrence_Of
7885                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7886                  Loc);
7887
7888             if Debug_Pragmas_Enabled then
7889                Set_SCO_Pragma_Enabled (Loc);
7890             end if;
7891
7892             if Arg_Count = 2 then
7893                Cond :=
7894                  Make_And_Then (Loc,
7895                    Left_Opnd  => Relocate_Node (Cond),
7896                    Right_Opnd => Get_Pragma_Arg (Arg1));
7897                Call := Get_Pragma_Arg (Arg2);
7898             else
7899                Call := Get_Pragma_Arg (Arg1);
7900             end if;
7901
7902             if Nkind_In (Call,
7903                  N_Indexed_Component,
7904                  N_Function_Call,
7905                  N_Identifier,
7906                  N_Expanded_Name,
7907                  N_Selected_Component)
7908             then
7909                --  If this pragma Debug comes from source, its argument was
7910                --  parsed as a name form (which is syntactically identical).
7911                --  In a generic context a parameterless call will be left as
7912                --  an expanded name (if global) or selected_component if local.
7913                --  Change it to a procedure call statement now.
7914
7915                Change_Name_To_Procedure_Call_Statement (Call);
7916
7917             elsif Nkind (Call) = N_Procedure_Call_Statement then
7918
7919                --  Already in the form of a procedure call statement: nothing
7920                --  to do (could happen in case of an internally generated
7921                --  pragma Debug).
7922
7923                null;
7924
7925             else
7926                --  All other cases: diagnose error
7927
7928                Error_Msg
7929                  ("argument of pragma ""Debug"" is not procedure call",
7930                   Sloc (Call));
7931                return;
7932             end if;
7933
7934             --  Rewrite into a conditional with an appropriate condition. We
7935             --  wrap the procedure call in a block so that overhead from e.g.
7936             --  use of the secondary stack does not generate execution overhead
7937             --  for suppressed conditions.
7938
7939             Rewrite (N, Make_Implicit_If_Statement (N,
7940               Condition => Cond,
7941                  Then_Statements => New_List (
7942                    Make_Block_Statement (Loc,
7943                      Handled_Statement_Sequence =>
7944                        Make_Handled_Sequence_Of_Statements (Loc,
7945                          Statements => New_List (Relocate_Node (Call)))))));
7946             Analyze (N);
7947          end Debug;
7948
7949          ------------------
7950          -- Debug_Policy --
7951          ------------------
7952
7953          --  pragma Debug_Policy (Check | Ignore)
7954
7955          when Pragma_Debug_Policy =>
7956             GNAT_Pragma;
7957             Check_Arg_Count (1);
7958             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7959             Debug_Pragmas_Enabled :=
7960               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7961             Debug_Pragmas_Disabled :=
7962               Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7963
7964          ---------------------
7965          -- Detect_Blocking --
7966          ---------------------
7967
7968          --  pragma Detect_Blocking;
7969
7970          when Pragma_Detect_Blocking =>
7971             Ada_2005_Pragma;
7972             Check_Arg_Count (0);
7973             Check_Valid_Configuration_Pragma;
7974             Detect_Blocking := True;
7975
7976          --------------------------
7977          -- Default_Storage_Pool --
7978          --------------------------
7979
7980          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7981
7982          when Pragma_Default_Storage_Pool =>
7983             Ada_2012_Pragma;
7984             Check_Arg_Count (1);
7985
7986             --  Default_Storage_Pool can appear as a configuration pragma, or
7987             --  in a declarative part or a package spec.
7988
7989             if not Is_Configuration_Pragma then
7990                Check_Is_In_Decl_Part_Or_Package_Spec;
7991             end if;
7992
7993             --  Case of Default_Storage_Pool (null);
7994
7995             if Nkind (Expression (Arg1)) = N_Null then
7996                Analyze (Expression (Arg1));
7997
7998                --  This is an odd case, this is not really an expression, so
7999                --  we don't have a type for it. So just set the type to Empty.
8000
8001                Set_Etype (Expression (Arg1), Empty);
8002
8003             --  Case of Default_Storage_Pool (storage_pool_NAME);
8004
8005             else
8006                --  If it's a configuration pragma, then the only allowed
8007                --  argument is "null".
8008
8009                if Is_Configuration_Pragma then
8010                   Error_Pragma_Arg ("NULL expected", Arg1);
8011                end if;
8012
8013                --  The expected type for a non-"null" argument is
8014                --  Root_Storage_Pool'Class.
8015
8016                Analyze_And_Resolve
8017                  (Get_Pragma_Arg (Arg1),
8018                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8019             end if;
8020
8021             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
8022             --  for an access type will use this information to set the
8023             --  appropriate attributes of the access type.
8024
8025             Default_Pool := Expression (Arg1);
8026
8027          ---------------
8028          -- Dimension --
8029          ---------------
8030
8031          when Pragma_Dimension =>
8032             GNAT_Pragma;
8033             Check_Arg_Count (4);
8034             Check_No_Identifiers;
8035             Check_Arg_Is_Local_Name (Arg1);
8036
8037             if not Is_Type (Arg1) then
8038                Error_Pragma ("first argument for pragma% must be subtype");
8039             end if;
8040
8041             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
8042             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
8043             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
8044
8045          ------------------------------------
8046          -- Disable_Atomic_Synchronization --
8047          ------------------------------------
8048
8049          --  pragma Disable_Atomic_Synchronization [(Entity)];
8050
8051          when Pragma_Disable_Atomic_Synchronization =>
8052             Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8053
8054          -------------------
8055          -- Discard_Names --
8056          -------------------
8057
8058          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
8059
8060          when Pragma_Discard_Names => Discard_Names : declare
8061             E    : Entity_Id;
8062             E_Id : Entity_Id;
8063
8064          begin
8065             Check_Ada_83_Warning;
8066
8067             --  Deal with configuration pragma case
8068
8069             if Arg_Count = 0 and then Is_Configuration_Pragma then
8070                Global_Discard_Names := True;
8071                return;
8072
8073             --  Otherwise, check correct appropriate context
8074
8075             else
8076                Check_Is_In_Decl_Part_Or_Package_Spec;
8077
8078                if Arg_Count = 0 then
8079
8080                   --  If there is no parameter, then from now on this pragma
8081                   --  applies to any enumeration, exception or tagged type
8082                   --  defined in the current declarative part, and recursively
8083                   --  to any nested scope.
8084
8085                   Set_Discard_Names (Current_Scope);
8086                   return;
8087
8088                else
8089                   Check_Arg_Count (1);
8090                   Check_Optional_Identifier (Arg1, Name_On);
8091                   Check_Arg_Is_Local_Name (Arg1);
8092
8093                   E_Id := Get_Pragma_Arg (Arg1);
8094
8095                   if Etype (E_Id) = Any_Type then
8096                      return;
8097                   else
8098                      E := Entity (E_Id);
8099                   end if;
8100
8101                   if (Is_First_Subtype (E)
8102                       and then
8103                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8104                     or else Ekind (E) = E_Exception
8105                   then
8106                      Set_Discard_Names (E);
8107                   else
8108                      Error_Pragma_Arg
8109                        ("inappropriate entity for pragma%", Arg1);
8110                   end if;
8111
8112                end if;
8113             end if;
8114          end Discard_Names;
8115
8116          ------------------------
8117          -- Dispatching_Domain --
8118          ------------------------
8119
8120          --  pragma Dispatching_Domain (EXPRESSION);
8121
8122          when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8123             P   : constant Node_Id := Parent (N);
8124             Arg : Node_Id;
8125
8126          begin
8127             Ada_2012_Pragma;
8128             Check_No_Identifiers;
8129             Check_Arg_Count (1);
8130
8131             --  This pragma is born obsolete, but not the aspect
8132
8133             if not From_Aspect_Specification (N) then
8134                Check_Restriction
8135                  (No_Obsolescent_Features, Pragma_Identifier (N));
8136             end if;
8137
8138             if Nkind (P) = N_Task_Definition then
8139                Arg := Get_Pragma_Arg (Arg1);
8140
8141                --  The expression must be analyzed in the special manner
8142                --  described in "Handling of Default and Per-Object
8143                --  Expressions" in sem.ads.
8144
8145                Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8146
8147             --  Anything else is incorrect
8148
8149             else
8150                Pragma_Misplaced;
8151             end if;
8152
8153             if Has_Pragma_Dispatching_Domain (P) then
8154                Error_Pragma ("duplicate pragma% not allowed");
8155             else
8156                Set_Has_Pragma_Dispatching_Domain (P, True);
8157
8158                if Nkind (P) = N_Task_Definition then
8159                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8160                end if;
8161             end if;
8162          end Dispatching_Domain;
8163
8164          ---------------
8165          -- Elaborate --
8166          ---------------
8167
8168          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8169
8170          when Pragma_Elaborate => Elaborate : declare
8171             Arg   : Node_Id;
8172             Citem : Node_Id;
8173
8174          begin
8175             --  Pragma must be in context items list of a compilation unit
8176
8177             if not Is_In_Context_Clause then
8178                Pragma_Misplaced;
8179             end if;
8180
8181             --  Must be at least one argument
8182
8183             if Arg_Count = 0 then
8184                Error_Pragma ("pragma% requires at least one argument");
8185             end if;
8186
8187             --  In Ada 83 mode, there can be no items following it in the
8188             --  context list except other pragmas and implicit with clauses
8189             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8190             --  placement rule does not apply.
8191
8192             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8193                Citem := Next (N);
8194                while Present (Citem) loop
8195                   if Nkind (Citem) = N_Pragma
8196                     or else (Nkind (Citem) = N_With_Clause
8197                               and then Implicit_With (Citem))
8198                   then
8199                      null;
8200                   else
8201                      Error_Pragma
8202                        ("(Ada 83) pragma% must be at end of context clause");
8203                   end if;
8204
8205                   Next (Citem);
8206                end loop;
8207             end if;
8208
8209             --  Finally, the arguments must all be units mentioned in a with
8210             --  clause in the same context clause. Note we already checked (in
8211             --  Par.Prag) that the arguments are all identifiers or selected
8212             --  components.
8213
8214             Arg := Arg1;
8215             Outer : while Present (Arg) loop
8216                Citem := First (List_Containing (N));
8217                Inner : while Citem /= N loop
8218                   if Nkind (Citem) = N_With_Clause
8219                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8220                   then
8221                      Set_Elaborate_Present (Citem, True);
8222                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8223                      Generate_Reference (Entity (Name (Citem)), Citem);
8224
8225                      --  With the pragma present, elaboration calls on
8226                      --  subprograms from the named unit need no further
8227                      --  checks, as long as the pragma appears in the current
8228                      --  compilation unit. If the pragma appears in some unit
8229                      --  in the context, there might still be a need for an
8230                      --  Elaborate_All_Desirable from the current compilation
8231                      --  to the named unit, so we keep the check enabled.
8232
8233                      if In_Extended_Main_Source_Unit (N) then
8234                         Set_Suppress_Elaboration_Warnings
8235                           (Entity (Name (Citem)));
8236                      end if;
8237
8238                      exit Inner;
8239                   end if;
8240
8241                   Next (Citem);
8242                end loop Inner;
8243
8244                if Citem = N then
8245                   Error_Pragma_Arg
8246                     ("argument of pragma% is not with'ed unit", Arg);
8247                end if;
8248
8249                Next (Arg);
8250             end loop Outer;
8251
8252             --  Give a warning if operating in static mode with -gnatwl
8253             --  (elaboration warnings enabled) switch set.
8254
8255             if Elab_Warnings and not Dynamic_Elaboration_Checks then
8256                Error_Msg_N
8257                  ("?use of pragma Elaborate may not be safe", N);
8258                Error_Msg_N
8259                  ("?use pragma Elaborate_All instead if possible", N);
8260             end if;
8261          end Elaborate;
8262
8263          -------------------
8264          -- Elaborate_All --
8265          -------------------
8266
8267          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8268
8269          when Pragma_Elaborate_All => Elaborate_All : declare
8270             Arg   : Node_Id;
8271             Citem : Node_Id;
8272
8273          begin
8274             Check_Ada_83_Warning;
8275
8276             --  Pragma must be in context items list of a compilation unit
8277
8278             if not Is_In_Context_Clause then
8279                Pragma_Misplaced;
8280             end if;
8281
8282             --  Must be at least one argument
8283
8284             if Arg_Count = 0 then
8285                Error_Pragma ("pragma% requires at least one argument");
8286             end if;
8287
8288             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
8289             --  have to appear at the end of the context clause, but may
8290             --  appear mixed in with other items, even in Ada 83 mode.
8291
8292             --  Final check: the arguments must all be units mentioned in
8293             --  a with clause in the same context clause. Note that we
8294             --  already checked (in Par.Prag) that all the arguments are
8295             --  either identifiers or selected components.
8296
8297             Arg := Arg1;
8298             Outr : while Present (Arg) loop
8299                Citem := First (List_Containing (N));
8300                Innr : while Citem /= N loop
8301                   if Nkind (Citem) = N_With_Clause
8302                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8303                   then
8304                      Set_Elaborate_All_Present (Citem, True);
8305                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8306
8307                      --  Suppress warnings and elaboration checks on the named
8308                      --  unit if the pragma is in the current compilation, as
8309                      --  for pragma Elaborate.
8310
8311                      if In_Extended_Main_Source_Unit (N) then
8312                         Set_Suppress_Elaboration_Warnings
8313                           (Entity (Name (Citem)));
8314                      end if;
8315                      exit Innr;
8316                   end if;
8317
8318                   Next (Citem);
8319                end loop Innr;
8320
8321                if Citem = N then
8322                   Set_Error_Posted (N);
8323                   Error_Pragma_Arg
8324                     ("argument of pragma% is not with'ed unit", Arg);
8325                end if;
8326
8327                Next (Arg);
8328             end loop Outr;
8329          end Elaborate_All;
8330
8331          --------------------
8332          -- Elaborate_Body --
8333          --------------------
8334
8335          --  pragma Elaborate_Body [( library_unit_NAME )];
8336
8337          when Pragma_Elaborate_Body => Elaborate_Body : declare
8338             Cunit_Node : Node_Id;
8339             Cunit_Ent  : Entity_Id;
8340
8341          begin
8342             Check_Ada_83_Warning;
8343             Check_Valid_Library_Unit_Pragma;
8344
8345             if Nkind (N) = N_Null_Statement then
8346                return;
8347             end if;
8348
8349             Cunit_Node := Cunit (Current_Sem_Unit);
8350             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8351
8352             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8353                                             N_Subprogram_Body)
8354             then
8355                Error_Pragma ("pragma% must refer to a spec, not a body");
8356             else
8357                Set_Body_Required (Cunit_Node, True);
8358                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8359
8360                --  If we are in dynamic elaboration mode, then we suppress
8361                --  elaboration warnings for the unit, since it is definitely
8362                --  fine NOT to do dynamic checks at the first level (and such
8363                --  checks will be suppressed because no elaboration boolean
8364                --  is created for Elaborate_Body packages).
8365
8366                --  But in the static model of elaboration, Elaborate_Body is
8367                --  definitely NOT good enough to ensure elaboration safety on
8368                --  its own, since the body may WITH other units that are not
8369                --  safe from an elaboration point of view, so a client must
8370                --  still do an Elaborate_All on such units.
8371
8372                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8373                --  Elaborate_Body always suppressed elab warnings.
8374
8375                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8376                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8377                end if;
8378             end if;
8379          end Elaborate_Body;
8380
8381          ------------------------
8382          -- Elaboration_Checks --
8383          ------------------------
8384
8385          --  pragma Elaboration_Checks (Static | Dynamic);
8386
8387          when Pragma_Elaboration_Checks =>
8388             GNAT_Pragma;
8389             Check_Arg_Count (1);
8390             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8391             Dynamic_Elaboration_Checks :=
8392               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8393
8394          ---------------
8395          -- Eliminate --
8396          ---------------
8397
8398          --  pragma Eliminate (
8399          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8400          --    [,[Entity     =>] IDENTIFIER |
8401          --                      SELECTED_COMPONENT |
8402          --                      STRING_LITERAL]
8403          --    [,                OVERLOADING_RESOLUTION]);
8404
8405          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8406          --                             SOURCE_LOCATION
8407
8408          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8409          --                                        FUNCTION_PROFILE
8410
8411          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8412
8413          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8414          --                       Result_Type => result_SUBTYPE_NAME]
8415
8416          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8417          --  SUBTYPE_NAME    ::= STRING_LITERAL
8418
8419          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8420          --  SOURCE_TRACE    ::= STRING_LITERAL
8421
8422          when Pragma_Eliminate => Eliminate : declare
8423             Args  : Args_List (1 .. 5);
8424             Names : constant Name_List (1 .. 5) := (
8425                       Name_Unit_Name,
8426                       Name_Entity,
8427                       Name_Parameter_Types,
8428                       Name_Result_Type,
8429                       Name_Source_Location);
8430
8431             Unit_Name       : Node_Id renames Args (1);
8432             Entity          : Node_Id renames Args (2);
8433             Parameter_Types : Node_Id renames Args (3);
8434             Result_Type     : Node_Id renames Args (4);
8435             Source_Location : Node_Id renames Args (5);
8436
8437          begin
8438             GNAT_Pragma;
8439             Check_Valid_Configuration_Pragma;
8440             Gather_Associations (Names, Args);
8441
8442             if No (Unit_Name) then
8443                Error_Pragma ("missing Unit_Name argument for pragma%");
8444             end if;
8445
8446             if No (Entity)
8447               and then (Present (Parameter_Types)
8448                           or else
8449                         Present (Result_Type)
8450                           or else
8451                         Present (Source_Location))
8452             then
8453                Error_Pragma ("missing Entity argument for pragma%");
8454             end if;
8455
8456             if (Present (Parameter_Types)
8457                   or else
8458                 Present (Result_Type))
8459               and then
8460                 Present (Source_Location)
8461             then
8462                Error_Pragma
8463                  ("parameter profile and source location cannot " &
8464                   "be used together in pragma%");
8465             end if;
8466
8467             Process_Eliminate_Pragma
8468               (N,
8469                Unit_Name,
8470                Entity,
8471                Parameter_Types,
8472                Result_Type,
8473                Source_Location);
8474          end Eliminate;
8475
8476          -----------------------------------
8477          -- Enable_Atomic_Synchronization --
8478          -----------------------------------
8479
8480          --  pragma Enable_Atomic_Synchronization [(Entity)];
8481
8482          when Pragma_Enable_Atomic_Synchronization =>
8483             Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8484
8485          ------------
8486          -- Export --
8487          ------------
8488
8489          --  pragma Export (
8490          --    [   Convention    =>] convention_IDENTIFIER,
8491          --    [   Entity        =>] local_NAME
8492          --    [, [External_Name =>] static_string_EXPRESSION ]
8493          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8494
8495          when Pragma_Export => Export : declare
8496             C      : Convention_Id;
8497             Def_Id : Entity_Id;
8498
8499             pragma Warnings (Off, C);
8500
8501          begin
8502             Check_Ada_83_Warning;
8503             Check_Arg_Order
8504               ((Name_Convention,
8505                 Name_Entity,
8506                 Name_External_Name,
8507                 Name_Link_Name));
8508             Check_At_Least_N_Arguments (2);
8509             Check_At_Most_N_Arguments  (4);
8510             Process_Convention (C, Def_Id);
8511
8512             if Ekind (Def_Id) /= E_Constant then
8513                Note_Possible_Modification
8514                  (Get_Pragma_Arg (Arg2), Sure => False);
8515             end if;
8516
8517             Process_Interface_Name (Def_Id, Arg3, Arg4);
8518             Set_Exported (Def_Id, Arg2);
8519
8520             --  If the entity is a deferred constant, propagate the information
8521             --  to the full view, because gigi elaborates the full view only.
8522
8523             if Ekind (Def_Id) = E_Constant
8524               and then Present (Full_View (Def_Id))
8525             then
8526                declare
8527                   Id2 : constant Entity_Id := Full_View (Def_Id);
8528                begin
8529                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8530                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8531                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8532                end;
8533             end if;
8534          end Export;
8535
8536          ----------------------
8537          -- Export_Exception --
8538          ----------------------
8539
8540          --  pragma Export_Exception (
8541          --        [Internal         =>] LOCAL_NAME
8542          --     [, [External         =>] EXTERNAL_SYMBOL]
8543          --     [, [Form     =>] Ada | VMS]
8544          --     [, [Code     =>] static_integer_EXPRESSION]);
8545
8546          when Pragma_Export_Exception => Export_Exception : declare
8547             Args  : Args_List (1 .. 4);
8548             Names : constant Name_List (1 .. 4) := (
8549                       Name_Internal,
8550                       Name_External,
8551                       Name_Form,
8552                       Name_Code);
8553
8554             Internal : Node_Id renames Args (1);
8555             External : Node_Id renames Args (2);
8556             Form     : Node_Id renames Args (3);
8557             Code     : Node_Id renames Args (4);
8558
8559          begin
8560             GNAT_Pragma;
8561
8562             if Inside_A_Generic then
8563                Error_Pragma ("pragma% cannot be used for generic entities");
8564             end if;
8565
8566             Gather_Associations (Names, Args);
8567             Process_Extended_Import_Export_Exception_Pragma (
8568               Arg_Internal => Internal,
8569               Arg_External => External,
8570               Arg_Form     => Form,
8571               Arg_Code     => Code);
8572
8573             if not Is_VMS_Exception (Entity (Internal)) then
8574                Set_Exported (Entity (Internal), Internal);
8575             end if;
8576          end Export_Exception;
8577
8578          ---------------------
8579          -- Export_Function --
8580          ---------------------
8581
8582          --  pragma Export_Function (
8583          --        [Internal         =>] LOCAL_NAME
8584          --     [, [External         =>] EXTERNAL_SYMBOL]
8585          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8586          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8587          --     [, [Mechanism        =>] MECHANISM]
8588          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8589
8590          --  EXTERNAL_SYMBOL ::=
8591          --    IDENTIFIER
8592          --  | static_string_EXPRESSION
8593
8594          --  PARAMETER_TYPES ::=
8595          --    null
8596          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8597
8598          --  TYPE_DESIGNATOR ::=
8599          --    subtype_NAME
8600          --  | subtype_Name ' Access
8601
8602          --  MECHANISM ::=
8603          --    MECHANISM_NAME
8604          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8605
8606          --  MECHANISM_ASSOCIATION ::=
8607          --    [formal_parameter_NAME =>] MECHANISM_NAME
8608
8609          --  MECHANISM_NAME ::=
8610          --    Value
8611          --  | Reference
8612          --  | Descriptor [([Class =>] CLASS_NAME)]
8613
8614          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8615
8616          when Pragma_Export_Function => Export_Function : declare
8617             Args  : Args_List (1 .. 6);
8618             Names : constant Name_List (1 .. 6) := (
8619                       Name_Internal,
8620                       Name_External,
8621                       Name_Parameter_Types,
8622                       Name_Result_Type,
8623                       Name_Mechanism,
8624                       Name_Result_Mechanism);
8625
8626             Internal         : Node_Id renames Args (1);
8627             External         : Node_Id renames Args (2);
8628             Parameter_Types  : Node_Id renames Args (3);
8629             Result_Type      : Node_Id renames Args (4);
8630             Mechanism        : Node_Id renames Args (5);
8631             Result_Mechanism : Node_Id renames Args (6);
8632
8633          begin
8634             GNAT_Pragma;
8635             Gather_Associations (Names, Args);
8636             Process_Extended_Import_Export_Subprogram_Pragma (
8637               Arg_Internal         => Internal,
8638               Arg_External         => External,
8639               Arg_Parameter_Types  => Parameter_Types,
8640               Arg_Result_Type      => Result_Type,
8641               Arg_Mechanism        => Mechanism,
8642               Arg_Result_Mechanism => Result_Mechanism);
8643          end Export_Function;
8644
8645          -------------------
8646          -- Export_Object --
8647          -------------------
8648
8649          --  pragma Export_Object (
8650          --        [Internal =>] LOCAL_NAME
8651          --     [, [External =>] EXTERNAL_SYMBOL]
8652          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8653
8654          --  EXTERNAL_SYMBOL ::=
8655          --    IDENTIFIER
8656          --  | static_string_EXPRESSION
8657
8658          --  PARAMETER_TYPES ::=
8659          --    null
8660          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8661
8662          --  TYPE_DESIGNATOR ::=
8663          --    subtype_NAME
8664          --  | subtype_Name ' Access
8665
8666          --  MECHANISM ::=
8667          --    MECHANISM_NAME
8668          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8669
8670          --  MECHANISM_ASSOCIATION ::=
8671          --    [formal_parameter_NAME =>] MECHANISM_NAME
8672
8673          --  MECHANISM_NAME ::=
8674          --    Value
8675          --  | Reference
8676          --  | Descriptor [([Class =>] CLASS_NAME)]
8677
8678          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8679
8680          when Pragma_Export_Object => Export_Object : declare
8681             Args  : Args_List (1 .. 3);
8682             Names : constant Name_List (1 .. 3) := (
8683                       Name_Internal,
8684                       Name_External,
8685                       Name_Size);
8686
8687             Internal : Node_Id renames Args (1);
8688             External : Node_Id renames Args (2);
8689             Size     : Node_Id renames Args (3);
8690
8691          begin
8692             GNAT_Pragma;
8693             Gather_Associations (Names, Args);
8694             Process_Extended_Import_Export_Object_Pragma (
8695               Arg_Internal => Internal,
8696               Arg_External => External,
8697               Arg_Size     => Size);
8698          end Export_Object;
8699
8700          ----------------------
8701          -- Export_Procedure --
8702          ----------------------
8703
8704          --  pragma Export_Procedure (
8705          --        [Internal         =>] LOCAL_NAME
8706          --     [, [External         =>] EXTERNAL_SYMBOL]
8707          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8708          --     [, [Mechanism        =>] MECHANISM]);
8709
8710          --  EXTERNAL_SYMBOL ::=
8711          --    IDENTIFIER
8712          --  | static_string_EXPRESSION
8713
8714          --  PARAMETER_TYPES ::=
8715          --    null
8716          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8717
8718          --  TYPE_DESIGNATOR ::=
8719          --    subtype_NAME
8720          --  | subtype_Name ' Access
8721
8722          --  MECHANISM ::=
8723          --    MECHANISM_NAME
8724          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8725
8726          --  MECHANISM_ASSOCIATION ::=
8727          --    [formal_parameter_NAME =>] MECHANISM_NAME
8728
8729          --  MECHANISM_NAME ::=
8730          --    Value
8731          --  | Reference
8732          --  | Descriptor [([Class =>] CLASS_NAME)]
8733
8734          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8735
8736          when Pragma_Export_Procedure => Export_Procedure : declare
8737             Args  : Args_List (1 .. 4);
8738             Names : constant Name_List (1 .. 4) := (
8739                       Name_Internal,
8740                       Name_External,
8741                       Name_Parameter_Types,
8742                       Name_Mechanism);
8743
8744             Internal        : Node_Id renames Args (1);
8745             External        : Node_Id renames Args (2);
8746             Parameter_Types : Node_Id renames Args (3);
8747             Mechanism       : Node_Id renames Args (4);
8748
8749          begin
8750             GNAT_Pragma;
8751             Gather_Associations (Names, Args);
8752             Process_Extended_Import_Export_Subprogram_Pragma (
8753               Arg_Internal        => Internal,
8754               Arg_External        => External,
8755               Arg_Parameter_Types => Parameter_Types,
8756               Arg_Mechanism       => Mechanism);
8757          end Export_Procedure;
8758
8759          ------------------
8760          -- Export_Value --
8761          ------------------
8762
8763          --  pragma Export_Value (
8764          --     [Value     =>] static_integer_EXPRESSION,
8765          --     [Link_Name =>] static_string_EXPRESSION);
8766
8767          when Pragma_Export_Value =>
8768             GNAT_Pragma;
8769             Check_Arg_Order ((Name_Value, Name_Link_Name));
8770             Check_Arg_Count (2);
8771
8772             Check_Optional_Identifier (Arg1, Name_Value);
8773             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8774
8775             Check_Optional_Identifier (Arg2, Name_Link_Name);
8776             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8777
8778          -----------------------------
8779          -- Export_Valued_Procedure --
8780          -----------------------------
8781
8782          --  pragma Export_Valued_Procedure (
8783          --        [Internal         =>] LOCAL_NAME
8784          --     [, [External         =>] EXTERNAL_SYMBOL,]
8785          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8786          --     [, [Mechanism        =>] MECHANISM]);
8787
8788          --  EXTERNAL_SYMBOL ::=
8789          --    IDENTIFIER
8790          --  | static_string_EXPRESSION
8791
8792          --  PARAMETER_TYPES ::=
8793          --    null
8794          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8795
8796          --  TYPE_DESIGNATOR ::=
8797          --    subtype_NAME
8798          --  | subtype_Name ' Access
8799
8800          --  MECHANISM ::=
8801          --    MECHANISM_NAME
8802          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8803
8804          --  MECHANISM_ASSOCIATION ::=
8805          --    [formal_parameter_NAME =>] MECHANISM_NAME
8806
8807          --  MECHANISM_NAME ::=
8808          --    Value
8809          --  | Reference
8810          --  | Descriptor [([Class =>] CLASS_NAME)]
8811
8812          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8813
8814          when Pragma_Export_Valued_Procedure =>
8815          Export_Valued_Procedure : declare
8816             Args  : Args_List (1 .. 4);
8817             Names : constant Name_List (1 .. 4) := (
8818                       Name_Internal,
8819                       Name_External,
8820                       Name_Parameter_Types,
8821                       Name_Mechanism);
8822
8823             Internal        : Node_Id renames Args (1);
8824             External        : Node_Id renames Args (2);
8825             Parameter_Types : Node_Id renames Args (3);
8826             Mechanism       : Node_Id renames Args (4);
8827
8828          begin
8829             GNAT_Pragma;
8830             Gather_Associations (Names, Args);
8831             Process_Extended_Import_Export_Subprogram_Pragma (
8832               Arg_Internal        => Internal,
8833               Arg_External        => External,
8834               Arg_Parameter_Types => Parameter_Types,
8835               Arg_Mechanism       => Mechanism);
8836          end Export_Valued_Procedure;
8837
8838          -------------------
8839          -- Extend_System --
8840          -------------------
8841
8842          --  pragma Extend_System ([Name =>] Identifier);
8843
8844          when Pragma_Extend_System => Extend_System : declare
8845          begin
8846             GNAT_Pragma;
8847             Check_Valid_Configuration_Pragma;
8848             Check_Arg_Count (1);
8849             Check_Optional_Identifier (Arg1, Name_Name);
8850             Check_Arg_Is_Identifier (Arg1);
8851
8852             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8853
8854             if Name_Len > 4
8855               and then Name_Buffer (1 .. 4) = "aux_"
8856             then
8857                if Present (System_Extend_Pragma_Arg) then
8858                   if Chars (Get_Pragma_Arg (Arg1)) =
8859                      Chars (Expression (System_Extend_Pragma_Arg))
8860                   then
8861                      null;
8862                   else
8863                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8864                      Error_Pragma ("pragma% conflicts with that #");
8865                   end if;
8866
8867                else
8868                   System_Extend_Pragma_Arg := Arg1;
8869
8870                   if not GNAT_Mode then
8871                      System_Extend_Unit := Arg1;
8872                   end if;
8873                end if;
8874             else
8875                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8876             end if;
8877          end Extend_System;
8878
8879          ------------------------
8880          -- Extensions_Allowed --
8881          ------------------------
8882
8883          --  pragma Extensions_Allowed (ON | OFF);
8884
8885          when Pragma_Extensions_Allowed =>
8886             GNAT_Pragma;
8887             Check_Arg_Count (1);
8888             Check_No_Identifiers;
8889             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8890
8891             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8892                Extensions_Allowed := True;
8893                Ada_Version := Ada_Version_Type'Last;
8894
8895             else
8896                Extensions_Allowed := False;
8897                Ada_Version := Ada_Version_Explicit;
8898             end if;
8899
8900          --------------
8901          -- External --
8902          --------------
8903
8904          --  pragma External (
8905          --    [   Convention    =>] convention_IDENTIFIER,
8906          --    [   Entity        =>] local_NAME
8907          --    [, [External_Name =>] static_string_EXPRESSION ]
8908          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8909
8910          when Pragma_External => External : declare
8911                Def_Id : Entity_Id;
8912
8913                C : Convention_Id;
8914                pragma Warnings (Off, C);
8915
8916          begin
8917             GNAT_Pragma;
8918             Check_Arg_Order
8919               ((Name_Convention,
8920                 Name_Entity,
8921                 Name_External_Name,
8922                 Name_Link_Name));
8923             Check_At_Least_N_Arguments (2);
8924             Check_At_Most_N_Arguments  (4);
8925             Process_Convention (C, Def_Id);
8926             Note_Possible_Modification
8927               (Get_Pragma_Arg (Arg2), Sure => False);
8928             Process_Interface_Name (Def_Id, Arg3, Arg4);
8929             Set_Exported (Def_Id, Arg2);
8930          end External;
8931
8932          --------------------------
8933          -- External_Name_Casing --
8934          --------------------------
8935
8936          --  pragma External_Name_Casing (
8937          --    UPPERCASE | LOWERCASE
8938          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8939
8940          when Pragma_External_Name_Casing => External_Name_Casing : declare
8941          begin
8942             GNAT_Pragma;
8943             Check_No_Identifiers;
8944
8945             if Arg_Count = 2 then
8946                Check_Arg_Is_One_Of
8947                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8948
8949                case Chars (Get_Pragma_Arg (Arg2)) is
8950                   when Name_As_Is     =>
8951                      Opt.External_Name_Exp_Casing := As_Is;
8952
8953                   when Name_Uppercase =>
8954                      Opt.External_Name_Exp_Casing := Uppercase;
8955
8956                   when Name_Lowercase =>
8957                      Opt.External_Name_Exp_Casing := Lowercase;
8958
8959                   when others =>
8960                      null;
8961                end case;
8962
8963             else
8964                Check_Arg_Count (1);
8965             end if;
8966
8967             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8968
8969             case Chars (Get_Pragma_Arg (Arg1)) is
8970                when Name_Uppercase =>
8971                   Opt.External_Name_Imp_Casing := Uppercase;
8972
8973                when Name_Lowercase =>
8974                   Opt.External_Name_Imp_Casing := Lowercase;
8975
8976                when others =>
8977                   null;
8978             end case;
8979          end External_Name_Casing;
8980
8981          --------------------------
8982          -- Favor_Top_Level --
8983          --------------------------
8984
8985          --  pragma Favor_Top_Level (type_NAME);
8986
8987          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8988                Named_Entity : Entity_Id;
8989
8990          begin
8991             GNAT_Pragma;
8992             Check_No_Identifiers;
8993             Check_Arg_Count (1);
8994             Check_Arg_Is_Local_Name (Arg1);
8995             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8996
8997             --  If it's an access-to-subprogram type (in particular, not a
8998             --  subtype), set the flag on that type.
8999
9000             if Is_Access_Subprogram_Type (Named_Entity) then
9001                Set_Can_Use_Internal_Rep (Named_Entity, False);
9002
9003             --  Otherwise it's an error (name denotes the wrong sort of entity)
9004
9005             else
9006                Error_Pragma_Arg
9007                  ("access-to-subprogram type expected",
9008                   Get_Pragma_Arg (Arg1));
9009             end if;
9010          end Favor_Top_Level;
9011
9012          ---------------
9013          -- Fast_Math --
9014          ---------------
9015
9016          --  pragma Fast_Math;
9017
9018          when Pragma_Fast_Math =>
9019             GNAT_Pragma;
9020             Check_No_Identifiers;
9021             Check_Valid_Configuration_Pragma;
9022             Fast_Math := True;
9023
9024          ---------------------------
9025          -- Finalize_Storage_Only --
9026          ---------------------------
9027
9028          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9029
9030          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9031             Assoc   : constant Node_Id := Arg1;
9032             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9033             Typ     : Entity_Id;
9034
9035          begin
9036             GNAT_Pragma;
9037             Check_No_Identifiers;
9038             Check_Arg_Count (1);
9039             Check_Arg_Is_Local_Name (Arg1);
9040
9041             Find_Type (Type_Id);
9042             Typ := Entity (Type_Id);
9043
9044             if Typ = Any_Type
9045               or else Rep_Item_Too_Early (Typ, N)
9046             then
9047                return;
9048             else
9049                Typ := Underlying_Type (Typ);
9050             end if;
9051
9052             if not Is_Controlled (Typ) then
9053                Error_Pragma ("pragma% must specify controlled type");
9054             end if;
9055
9056             Check_First_Subtype (Arg1);
9057
9058             if Finalize_Storage_Only (Typ) then
9059                Error_Pragma ("duplicate pragma%, only one allowed");
9060
9061             elsif not Rep_Item_Too_Late (Typ, N) then
9062                Set_Finalize_Storage_Only (Base_Type (Typ), True);
9063             end if;
9064          end Finalize_Storage;
9065
9066          --------------------------
9067          -- Float_Representation --
9068          --------------------------
9069
9070          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9071
9072          --  FLOAT_REP ::= VAX_Float | IEEE_Float
9073
9074          when Pragma_Float_Representation => Float_Representation : declare
9075             Argx : Node_Id;
9076             Digs : Nat;
9077             Ent  : Entity_Id;
9078
9079          begin
9080             GNAT_Pragma;
9081
9082             if Arg_Count = 1 then
9083                Check_Valid_Configuration_Pragma;
9084             else
9085                Check_Arg_Count (2);
9086                Check_Optional_Identifier (Arg2, Name_Entity);
9087                Check_Arg_Is_Local_Name (Arg2);
9088             end if;
9089
9090             Check_No_Identifier (Arg1);
9091             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9092
9093             if not OpenVMS_On_Target then
9094                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9095                   Error_Pragma
9096                     ("?pragma% ignored (applies only to Open'V'M'S)");
9097                end if;
9098
9099                return;
9100             end if;
9101
9102             --  One argument case
9103
9104             if Arg_Count = 1 then
9105                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9106                   if Opt.Float_Format = 'I' then
9107                      Error_Pragma ("'I'E'E'E format previously specified");
9108                   end if;
9109
9110                   Opt.Float_Format := 'V';
9111
9112                else
9113                   if Opt.Float_Format = 'V' then
9114                      Error_Pragma ("'V'A'X format previously specified");
9115                   end if;
9116
9117                   Opt.Float_Format := 'I';
9118                end if;
9119
9120                Set_Standard_Fpt_Formats;
9121
9122             --  Two argument case
9123
9124             else
9125                Argx := Get_Pragma_Arg (Arg2);
9126
9127                if not Is_Entity_Name (Argx)
9128                  or else not Is_Floating_Point_Type (Entity (Argx))
9129                then
9130                   Error_Pragma_Arg
9131                     ("second argument of% pragma must be floating-point type",
9132                      Arg2);
9133                end if;
9134
9135                Ent  := Entity (Argx);
9136                Digs := UI_To_Int (Digits_Value (Ent));
9137
9138                --  Two arguments, VAX_Float case
9139
9140                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9141                   case Digs is
9142                      when  6 => Set_F_Float (Ent);
9143                      when  9 => Set_D_Float (Ent);
9144                      when 15 => Set_G_Float (Ent);
9145
9146                      when others =>
9147                         Error_Pragma_Arg
9148                           ("wrong digits value, must be 6,9 or 15", Arg2);
9149                   end case;
9150
9151                --  Two arguments, IEEE_Float case
9152
9153                else
9154                   case Digs is
9155                      when  6 => Set_IEEE_Short (Ent);
9156                      when 15 => Set_IEEE_Long  (Ent);
9157
9158                      when others =>
9159                         Error_Pragma_Arg
9160                           ("wrong digits value, must be 6 or 15", Arg2);
9161                   end case;
9162                end if;
9163             end if;
9164          end Float_Representation;
9165
9166          -----------
9167          -- Ident --
9168          -----------
9169
9170          --  pragma Ident (static_string_EXPRESSION)
9171
9172          --  Note: pragma Comment shares this processing. Pragma Comment is
9173          --  identical to Ident, except that the restriction of the argument to
9174          --  31 characters and the placement restrictions are not enforced for
9175          --  pragma Comment.
9176
9177          when Pragma_Ident | Pragma_Comment => Ident : declare
9178             Str : Node_Id;
9179
9180          begin
9181             GNAT_Pragma;
9182             Check_Arg_Count (1);
9183             Check_No_Identifiers;
9184             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9185             Store_Note (N);
9186
9187             --  For pragma Ident, preserve DEC compatibility by requiring the
9188             --  pragma to appear in a declarative part or package spec.
9189
9190             if Prag_Id = Pragma_Ident then
9191                Check_Is_In_Decl_Part_Or_Package_Spec;
9192             end if;
9193
9194             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9195
9196             declare
9197                CS : Node_Id;
9198                GP : Node_Id;
9199
9200             begin
9201                GP := Parent (Parent (N));
9202
9203                if Nkind_In (GP, N_Package_Declaration,
9204                                 N_Generic_Package_Declaration)
9205                then
9206                   GP := Parent (GP);
9207                end if;
9208
9209                --  If we have a compilation unit, then record the ident value,
9210                --  checking for improper duplication.
9211
9212                if Nkind (GP) = N_Compilation_Unit then
9213                   CS := Ident_String (Current_Sem_Unit);
9214
9215                   if Present (CS) then
9216
9217                      --  For Ident, we do not permit multiple instances
9218
9219                      if Prag_Id = Pragma_Ident then
9220                         Error_Pragma ("duplicate% pragma not permitted");
9221
9222                      --  For Comment, we concatenate the string, unless we want
9223                      --  to preserve the tree structure for ASIS.
9224
9225                      elsif not ASIS_Mode then
9226                         Start_String (Strval (CS));
9227                         Store_String_Char (' ');
9228                         Store_String_Chars (Strval (Str));
9229                         Set_Strval (CS, End_String);
9230                      end if;
9231
9232                   else
9233                      --  In VMS, the effect of IDENT is achieved by passing
9234                      --  --identification=name as a --for-linker switch.
9235
9236                      if OpenVMS_On_Target then
9237                         Start_String;
9238                         Store_String_Chars
9239                           ("--for-linker=--identification=");
9240                         String_To_Name_Buffer (Strval (Str));
9241                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
9242
9243                         --  Only the last processed IDENT is saved. The main
9244                         --  purpose is so an IDENT associated with a main
9245                         --  procedure will be used in preference to an IDENT
9246                         --  associated with a with'd package.
9247
9248                         Replace_Linker_Option_String
9249                           (End_String, "--for-linker=--identification=");
9250                      end if;
9251
9252                      Set_Ident_String (Current_Sem_Unit, Str);
9253                   end if;
9254
9255                --  For subunits, we just ignore the Ident, since in GNAT these
9256                --  are not separate object files, and hence not separate units
9257                --  in the unit table.
9258
9259                elsif Nkind (GP) = N_Subunit then
9260                   null;
9261
9262                --  Otherwise we have a misplaced pragma Ident, but we ignore
9263                --  this if we are in an instantiation, since it comes from
9264                --  a generic, and has no relevance to the instantiation.
9265
9266                elsif Prag_Id = Pragma_Ident then
9267                   if Instantiation_Location (Loc) = No_Location then
9268                      Error_Pragma ("pragma% only allowed at outer level");
9269                   end if;
9270                end if;
9271             end;
9272          end Ident;
9273
9274          ----------------------------
9275          -- Implementation_Defined --
9276          ----------------------------
9277
9278          --  pragma Implementation_Defined (local_NAME);
9279
9280          --  Marks previously declared entity as implementation defined. For
9281          --  an overloaded entity, applies to the most recent homonym.
9282
9283          --  pragma Implementation_Defined;
9284
9285          --  The form with no arguments appears anywhere within a scope, most
9286          --  typically a package spec, and indicates that all entities that are
9287          --  defined within the package spec are Implementation_Defined.
9288
9289          when Pragma_Implementation_Defined => Implementation_Defined : declare
9290             Ent : Entity_Id;
9291
9292          begin
9293             Check_No_Identifiers;
9294
9295             --  Form with no arguments
9296
9297             if Arg_Count = 0 then
9298                Set_Is_Implementation_Defined (Current_Scope);
9299
9300             --  Form with one argument
9301
9302             else
9303                Check_Arg_Count (1);
9304                Check_Arg_Is_Local_Name (Arg1);
9305                Ent := Entity (Get_Pragma_Arg (Arg1));
9306                Set_Is_Implementation_Defined (Ent);
9307             end if;
9308          end Implementation_Defined;
9309
9310          -----------------
9311          -- Implemented --
9312          -----------------
9313
9314          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9315          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9316
9317          when Pragma_Implemented => Implemented : declare
9318             Proc_Id : Entity_Id;
9319             Typ     : Entity_Id;
9320
9321          begin
9322             Ada_2012_Pragma;
9323             Check_Arg_Count (2);
9324             Check_No_Identifiers;
9325             Check_Arg_Is_Identifier (Arg1);
9326             Check_Arg_Is_Local_Name (Arg1);
9327             Check_Arg_Is_One_Of
9328               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9329
9330             --  Extract the name of the local procedure
9331
9332             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9333
9334             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9335             --  primitive procedure of a synchronized tagged type.
9336
9337             if Ekind (Proc_Id) = E_Procedure
9338               and then Is_Primitive (Proc_Id)
9339               and then Present (First_Formal (Proc_Id))
9340             then
9341                Typ := Etype (First_Formal (Proc_Id));
9342
9343                if Is_Tagged_Type (Typ)
9344                  and then
9345
9346                   --  Check for a protected, a synchronized or a task interface
9347
9348                    ((Is_Interface (Typ)
9349                        and then Is_Synchronized_Interface (Typ))
9350
9351                   --  Check for a protected type or a task type that implements
9352                   --  an interface.
9353
9354                    or else
9355                     (Is_Concurrent_Record_Type (Typ)
9356                        and then Present (Interfaces (Typ)))
9357
9358                   --  Check for a private record extension with keyword
9359                   --  "synchronized".
9360
9361                    or else
9362                     (Ekind_In (Typ, E_Record_Type_With_Private,
9363                                     E_Record_Subtype_With_Private)
9364                        and then Synchronized_Present (Parent (Typ))))
9365                then
9366                   null;
9367                else
9368                   Error_Pragma_Arg
9369                     ("controlling formal must be of synchronized " &
9370                      "tagged type", Arg1);
9371                   return;
9372                end if;
9373
9374             --  Procedures declared inside a protected type must be accepted
9375
9376             elsif Ekind (Proc_Id) = E_Procedure
9377               and then Is_Protected_Type (Scope (Proc_Id))
9378             then
9379                null;
9380
9381             --  The first argument is not a primitive procedure
9382
9383             else
9384                Error_Pragma_Arg
9385                  ("pragma % must be applied to a primitive procedure", Arg1);
9386                return;
9387             end if;
9388
9389             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9390             --  By_Protected_Procedure to the primitive procedure of a task
9391             --  interface.
9392
9393             if Chars (Arg2) = Name_By_Protected_Procedure
9394               and then Is_Interface (Typ)
9395               and then Is_Task_Interface (Typ)
9396             then
9397                Error_Pragma_Arg
9398                  ("implementation kind By_Protected_Procedure cannot be " &
9399                   "applied to a task interface primitive", Arg2);
9400                return;
9401             end if;
9402
9403             Record_Rep_Item (Proc_Id, N);
9404          end Implemented;
9405
9406          ----------------------
9407          -- Implicit_Packing --
9408          ----------------------
9409
9410          --  pragma Implicit_Packing;
9411
9412          when Pragma_Implicit_Packing =>
9413             GNAT_Pragma;
9414             Check_Arg_Count (0);
9415             Implicit_Packing := True;
9416
9417          ------------
9418          -- Import --
9419          ------------
9420
9421          --  pragma Import (
9422          --       [Convention    =>] convention_IDENTIFIER,
9423          --       [Entity        =>] local_NAME
9424          --    [, [External_Name =>] static_string_EXPRESSION ]
9425          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9426
9427          when Pragma_Import =>
9428             Check_Ada_83_Warning;
9429             Check_Arg_Order
9430               ((Name_Convention,
9431                 Name_Entity,
9432                 Name_External_Name,
9433                 Name_Link_Name));
9434             Check_At_Least_N_Arguments (2);
9435             Check_At_Most_N_Arguments  (4);
9436             Process_Import_Or_Interface;
9437
9438          ----------------------
9439          -- Import_Exception --
9440          ----------------------
9441
9442          --  pragma Import_Exception (
9443          --        [Internal         =>] LOCAL_NAME
9444          --     [, [External         =>] EXTERNAL_SYMBOL]
9445          --     [, [Form     =>] Ada | VMS]
9446          --     [, [Code     =>] static_integer_EXPRESSION]);
9447
9448          when Pragma_Import_Exception => Import_Exception : declare
9449             Args  : Args_List (1 .. 4);
9450             Names : constant Name_List (1 .. 4) := (
9451                       Name_Internal,
9452                       Name_External,
9453                       Name_Form,
9454                       Name_Code);
9455
9456             Internal : Node_Id renames Args (1);
9457             External : Node_Id renames Args (2);
9458             Form     : Node_Id renames Args (3);
9459             Code     : Node_Id renames Args (4);
9460
9461          begin
9462             GNAT_Pragma;
9463             Gather_Associations (Names, Args);
9464
9465             if Present (External) and then Present (Code) then
9466                Error_Pragma
9467                  ("cannot give both External and Code options for pragma%");
9468             end if;
9469
9470             Process_Extended_Import_Export_Exception_Pragma (
9471               Arg_Internal => Internal,
9472               Arg_External => External,
9473               Arg_Form     => Form,
9474               Arg_Code     => Code);
9475
9476             if not Is_VMS_Exception (Entity (Internal)) then
9477                Set_Imported (Entity (Internal));
9478             end if;
9479          end Import_Exception;
9480
9481          ---------------------
9482          -- Import_Function --
9483          ---------------------
9484
9485          --  pragma Import_Function (
9486          --        [Internal                 =>] LOCAL_NAME,
9487          --     [, [External                 =>] EXTERNAL_SYMBOL]
9488          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9489          --     [, [Result_Type              =>] SUBTYPE_MARK]
9490          --     [, [Mechanism                =>] MECHANISM]
9491          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9492          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9493
9494          --  EXTERNAL_SYMBOL ::=
9495          --    IDENTIFIER
9496          --  | static_string_EXPRESSION
9497
9498          --  PARAMETER_TYPES ::=
9499          --    null
9500          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9501
9502          --  TYPE_DESIGNATOR ::=
9503          --    subtype_NAME
9504          --  | subtype_Name ' Access
9505
9506          --  MECHANISM ::=
9507          --    MECHANISM_NAME
9508          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9509
9510          --  MECHANISM_ASSOCIATION ::=
9511          --    [formal_parameter_NAME =>] MECHANISM_NAME
9512
9513          --  MECHANISM_NAME ::=
9514          --    Value
9515          --  | Reference
9516          --  | Descriptor [([Class =>] CLASS_NAME)]
9517
9518          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9519
9520          when Pragma_Import_Function => Import_Function : declare
9521             Args  : Args_List (1 .. 7);
9522             Names : constant Name_List (1 .. 7) := (
9523                       Name_Internal,
9524                       Name_External,
9525                       Name_Parameter_Types,
9526                       Name_Result_Type,
9527                       Name_Mechanism,
9528                       Name_Result_Mechanism,
9529                       Name_First_Optional_Parameter);
9530
9531             Internal                 : Node_Id renames Args (1);
9532             External                 : Node_Id renames Args (2);
9533             Parameter_Types          : Node_Id renames Args (3);
9534             Result_Type              : Node_Id renames Args (4);
9535             Mechanism                : Node_Id renames Args (5);
9536             Result_Mechanism         : Node_Id renames Args (6);
9537             First_Optional_Parameter : Node_Id renames Args (7);
9538
9539          begin
9540             GNAT_Pragma;
9541             Gather_Associations (Names, Args);
9542             Process_Extended_Import_Export_Subprogram_Pragma (
9543               Arg_Internal                 => Internal,
9544               Arg_External                 => External,
9545               Arg_Parameter_Types          => Parameter_Types,
9546               Arg_Result_Type              => Result_Type,
9547               Arg_Mechanism                => Mechanism,
9548               Arg_Result_Mechanism         => Result_Mechanism,
9549               Arg_First_Optional_Parameter => First_Optional_Parameter);
9550          end Import_Function;
9551
9552          -------------------
9553          -- Import_Object --
9554          -------------------
9555
9556          --  pragma Import_Object (
9557          --        [Internal =>] LOCAL_NAME
9558          --     [, [External =>] EXTERNAL_SYMBOL]
9559          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9560
9561          --  EXTERNAL_SYMBOL ::=
9562          --    IDENTIFIER
9563          --  | static_string_EXPRESSION
9564
9565          when Pragma_Import_Object => Import_Object : declare
9566             Args  : Args_List (1 .. 3);
9567             Names : constant Name_List (1 .. 3) := (
9568                       Name_Internal,
9569                       Name_External,
9570                       Name_Size);
9571
9572             Internal : Node_Id renames Args (1);
9573             External : Node_Id renames Args (2);
9574             Size     : Node_Id renames Args (3);
9575
9576          begin
9577             GNAT_Pragma;
9578             Gather_Associations (Names, Args);
9579             Process_Extended_Import_Export_Object_Pragma (
9580               Arg_Internal => Internal,
9581               Arg_External => External,
9582               Arg_Size     => Size);
9583          end Import_Object;
9584
9585          ----------------------
9586          -- Import_Procedure --
9587          ----------------------
9588
9589          --  pragma Import_Procedure (
9590          --        [Internal                 =>] LOCAL_NAME
9591          --     [, [External                 =>] EXTERNAL_SYMBOL]
9592          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9593          --     [, [Mechanism                =>] MECHANISM]
9594          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9595
9596          --  EXTERNAL_SYMBOL ::=
9597          --    IDENTIFIER
9598          --  | static_string_EXPRESSION
9599
9600          --  PARAMETER_TYPES ::=
9601          --    null
9602          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9603
9604          --  TYPE_DESIGNATOR ::=
9605          --    subtype_NAME
9606          --  | subtype_Name ' Access
9607
9608          --  MECHANISM ::=
9609          --    MECHANISM_NAME
9610          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9611
9612          --  MECHANISM_ASSOCIATION ::=
9613          --    [formal_parameter_NAME =>] MECHANISM_NAME
9614
9615          --  MECHANISM_NAME ::=
9616          --    Value
9617          --  | Reference
9618          --  | Descriptor [([Class =>] CLASS_NAME)]
9619
9620          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9621
9622          when Pragma_Import_Procedure => Import_Procedure : declare
9623             Args  : Args_List (1 .. 5);
9624             Names : constant Name_List (1 .. 5) := (
9625                       Name_Internal,
9626                       Name_External,
9627                       Name_Parameter_Types,
9628                       Name_Mechanism,
9629                       Name_First_Optional_Parameter);
9630
9631             Internal                 : Node_Id renames Args (1);
9632             External                 : Node_Id renames Args (2);
9633             Parameter_Types          : Node_Id renames Args (3);
9634             Mechanism                : Node_Id renames Args (4);
9635             First_Optional_Parameter : Node_Id renames Args (5);
9636
9637          begin
9638             GNAT_Pragma;
9639             Gather_Associations (Names, Args);
9640             Process_Extended_Import_Export_Subprogram_Pragma (
9641               Arg_Internal                 => Internal,
9642               Arg_External                 => External,
9643               Arg_Parameter_Types          => Parameter_Types,
9644               Arg_Mechanism                => Mechanism,
9645               Arg_First_Optional_Parameter => First_Optional_Parameter);
9646          end Import_Procedure;
9647
9648          -----------------------------
9649          -- Import_Valued_Procedure --
9650          -----------------------------
9651
9652          --  pragma Import_Valued_Procedure (
9653          --        [Internal                 =>] LOCAL_NAME
9654          --     [, [External                 =>] EXTERNAL_SYMBOL]
9655          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9656          --     [, [Mechanism                =>] MECHANISM]
9657          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9658
9659          --  EXTERNAL_SYMBOL ::=
9660          --    IDENTIFIER
9661          --  | static_string_EXPRESSION
9662
9663          --  PARAMETER_TYPES ::=
9664          --    null
9665          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9666
9667          --  TYPE_DESIGNATOR ::=
9668          --    subtype_NAME
9669          --  | subtype_Name ' Access
9670
9671          --  MECHANISM ::=
9672          --    MECHANISM_NAME
9673          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9674
9675          --  MECHANISM_ASSOCIATION ::=
9676          --    [formal_parameter_NAME =>] MECHANISM_NAME
9677
9678          --  MECHANISM_NAME ::=
9679          --    Value
9680          --  | Reference
9681          --  | Descriptor [([Class =>] CLASS_NAME)]
9682
9683          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9684
9685          when Pragma_Import_Valued_Procedure =>
9686          Import_Valued_Procedure : declare
9687             Args  : Args_List (1 .. 5);
9688             Names : constant Name_List (1 .. 5) := (
9689                       Name_Internal,
9690                       Name_External,
9691                       Name_Parameter_Types,
9692                       Name_Mechanism,
9693                       Name_First_Optional_Parameter);
9694
9695             Internal                 : Node_Id renames Args (1);
9696             External                 : Node_Id renames Args (2);
9697             Parameter_Types          : Node_Id renames Args (3);
9698             Mechanism                : Node_Id renames Args (4);
9699             First_Optional_Parameter : Node_Id renames Args (5);
9700
9701          begin
9702             GNAT_Pragma;
9703             Gather_Associations (Names, Args);
9704             Process_Extended_Import_Export_Subprogram_Pragma (
9705               Arg_Internal                 => Internal,
9706               Arg_External                 => External,
9707               Arg_Parameter_Types          => Parameter_Types,
9708               Arg_Mechanism                => Mechanism,
9709               Arg_First_Optional_Parameter => First_Optional_Parameter);
9710          end Import_Valued_Procedure;
9711
9712          -----------------
9713          -- Independent --
9714          -----------------
9715
9716          --  pragma Independent (LOCAL_NAME);
9717
9718          when Pragma_Independent => Independent : declare
9719             E_Id : Node_Id;
9720             E    : Entity_Id;
9721             D    : Node_Id;
9722             K    : Node_Kind;
9723
9724          begin
9725             Check_Ada_83_Warning;
9726             Ada_2012_Pragma;
9727             Check_No_Identifiers;
9728             Check_Arg_Count (1);
9729             Check_Arg_Is_Local_Name (Arg1);
9730             E_Id := Get_Pragma_Arg (Arg1);
9731
9732             if Etype (E_Id) = Any_Type then
9733                return;
9734             end if;
9735
9736             E := Entity (E_Id);
9737             D := Declaration_Node (E);
9738             K := Nkind (D);
9739
9740             --  Check duplicate before we chain ourselves!
9741
9742             Check_Duplicate_Pragma (E);
9743
9744             --  Check appropriate entity
9745
9746             if Is_Type (E) then
9747                if Rep_Item_Too_Early (E, N)
9748                     or else
9749                   Rep_Item_Too_Late (E, N)
9750                then
9751                   return;
9752                else
9753                   Check_First_Subtype (Arg1);
9754                end if;
9755
9756             elsif K = N_Object_Declaration
9757               or else (K = N_Component_Declaration
9758                        and then Original_Record_Component (E) = E)
9759             then
9760                if Rep_Item_Too_Late (E, N) then
9761                   return;
9762                end if;
9763
9764             else
9765                Error_Pragma_Arg
9766                  ("inappropriate entity for pragma%", Arg1);
9767             end if;
9768
9769             Independence_Checks.Append ((N, E));
9770          end Independent;
9771
9772          ----------------------------
9773          -- Independent_Components --
9774          ----------------------------
9775
9776          --  pragma Atomic_Components (array_LOCAL_NAME);
9777
9778          --  This processing is shared by Volatile_Components
9779
9780          when Pragma_Independent_Components => Independent_Components : declare
9781             E_Id : Node_Id;
9782             E    : Entity_Id;
9783             D    : Node_Id;
9784             K    : Node_Kind;
9785
9786          begin
9787             Check_Ada_83_Warning;
9788             Ada_2012_Pragma;
9789             Check_No_Identifiers;
9790             Check_Arg_Count (1);
9791             Check_Arg_Is_Local_Name (Arg1);
9792             E_Id := Get_Pragma_Arg (Arg1);
9793
9794             if Etype (E_Id) = Any_Type then
9795                return;
9796             end if;
9797
9798             E := Entity (E_Id);
9799
9800             --  Check duplicate before we chain ourselves!
9801
9802             Check_Duplicate_Pragma (E);
9803
9804             --  Check appropriate entity
9805
9806             if Rep_Item_Too_Early (E, N)
9807                  or else
9808                Rep_Item_Too_Late (E, N)
9809             then
9810                return;
9811             end if;
9812
9813             D := Declaration_Node (E);
9814             K := Nkind (D);
9815
9816             if (K = N_Full_Type_Declaration
9817                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9818               or else
9819                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9820                    and then Nkind (D) = N_Object_Declaration
9821                    and then Nkind (Object_Definition (D)) =
9822                                        N_Constrained_Array_Definition)
9823             then
9824                Independence_Checks.Append ((N, E));
9825
9826             else
9827                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9828             end if;
9829          end Independent_Components;
9830
9831          ------------------------
9832          -- Initialize_Scalars --
9833          ------------------------
9834
9835          --  pragma Initialize_Scalars;
9836
9837          when Pragma_Initialize_Scalars =>
9838             GNAT_Pragma;
9839             Check_Arg_Count (0);
9840             Check_Valid_Configuration_Pragma;
9841             Check_Restriction (No_Initialize_Scalars, N);
9842
9843             --  Initialize_Scalars creates false positives in CodePeer, and
9844             --  incorrect negative results in Alfa mode, so ignore this pragma
9845             --  in these modes.
9846
9847             if not Restriction_Active (No_Initialize_Scalars)
9848               and then not (CodePeer_Mode or Alfa_Mode)
9849             then
9850                Init_Or_Norm_Scalars := True;
9851                Initialize_Scalars := True;
9852             end if;
9853
9854          ------------
9855          -- Inline --
9856          ------------
9857
9858          --  pragma Inline ( NAME {, NAME} );
9859
9860          when Pragma_Inline =>
9861
9862             --  Pragma is active if inlining option is active
9863
9864             Process_Inline (Inline_Active);
9865
9866          -------------------
9867          -- Inline_Always --
9868          -------------------
9869
9870          --  pragma Inline_Always ( NAME {, NAME} );
9871
9872          when Pragma_Inline_Always =>
9873             GNAT_Pragma;
9874
9875             --  Pragma always active unless in CodePeer or Alfa mode, since
9876             --  this causes walk order issues.
9877
9878             if not (CodePeer_Mode or Alfa_Mode) then
9879                Process_Inline (True);
9880             end if;
9881
9882          --------------------
9883          -- Inline_Generic --
9884          --------------------
9885
9886          --  pragma Inline_Generic (NAME {, NAME});
9887
9888          when Pragma_Inline_Generic =>
9889             GNAT_Pragma;
9890             Process_Generic_List;
9891
9892          ----------------------
9893          -- Inspection_Point --
9894          ----------------------
9895
9896          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9897
9898          when Pragma_Inspection_Point => Inspection_Point : declare
9899             Arg : Node_Id;
9900             Exp : Node_Id;
9901
9902          begin
9903             if Arg_Count > 0 then
9904                Arg := Arg1;
9905                loop
9906                   Exp := Get_Pragma_Arg (Arg);
9907                   Analyze (Exp);
9908
9909                   if not Is_Entity_Name (Exp)
9910                     or else not Is_Object (Entity (Exp))
9911                   then
9912                      Error_Pragma_Arg ("object name required", Arg);
9913                   end if;
9914
9915                   Next (Arg);
9916                   exit when No (Arg);
9917                end loop;
9918             end if;
9919          end Inspection_Point;
9920
9921          ---------------
9922          -- Interface --
9923          ---------------
9924
9925          --  pragma Interface (
9926          --    [   Convention    =>] convention_IDENTIFIER,
9927          --    [   Entity        =>] local_NAME
9928          --    [, [External_Name =>] static_string_EXPRESSION ]
9929          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9930
9931          when Pragma_Interface =>
9932             GNAT_Pragma;
9933             Check_Arg_Order
9934               ((Name_Convention,
9935                 Name_Entity,
9936                 Name_External_Name,
9937                 Name_Link_Name));
9938             Check_At_Least_N_Arguments (2);
9939             Check_At_Most_N_Arguments  (4);
9940             Process_Import_Or_Interface;
9941
9942             --  In Ada 2005, the permission to use Interface (a reserved word)
9943             --  as a pragma name is considered an obsolescent feature.
9944
9945             if Ada_Version >= Ada_2005 then
9946                Check_Restriction
9947                  (No_Obsolescent_Features, Pragma_Identifier (N));
9948             end if;
9949
9950          --------------------
9951          -- Interface_Name --
9952          --------------------
9953
9954          --  pragma Interface_Name (
9955          --    [  Entity        =>] local_NAME
9956          --    [,[External_Name =>] static_string_EXPRESSION ]
9957          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9958
9959          when Pragma_Interface_Name => Interface_Name : declare
9960             Id     : Node_Id;
9961             Def_Id : Entity_Id;
9962             Hom_Id : Entity_Id;
9963             Found  : Boolean;
9964
9965          begin
9966             GNAT_Pragma;
9967             Check_Arg_Order
9968               ((Name_Entity, Name_External_Name, Name_Link_Name));
9969             Check_At_Least_N_Arguments (2);
9970             Check_At_Most_N_Arguments  (3);
9971             Id := Get_Pragma_Arg (Arg1);
9972             Analyze (Id);
9973
9974             if not Is_Entity_Name (Id) then
9975                Error_Pragma_Arg
9976                  ("first argument for pragma% must be entity name", Arg1);
9977             elsif Etype (Id) = Any_Type then
9978                return;
9979             else
9980                Def_Id := Entity (Id);
9981             end if;
9982
9983             --  Special DEC-compatible processing for the object case, forces
9984             --  object to be imported.
9985
9986             if Ekind (Def_Id) = E_Variable then
9987                Kill_Size_Check_Code (Def_Id);
9988                Note_Possible_Modification (Id, Sure => False);
9989
9990                --  Initialization is not allowed for imported variable
9991
9992                if Present (Expression (Parent (Def_Id)))
9993                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9994                then
9995                   Error_Msg_Sloc := Sloc (Def_Id);
9996                   Error_Pragma_Arg
9997                     ("no initialization allowed for declaration of& #",
9998                      Arg2);
9999
10000                else
10001                   --  For compatibility, support VADS usage of providing both
10002                   --  pragmas Interface and Interface_Name to obtain the effect
10003                   --  of a single Import pragma.
10004
10005                   if Is_Imported (Def_Id)
10006                     and then Present (First_Rep_Item (Def_Id))
10007                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10008                     and then
10009                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10010                   then
10011                      null;
10012                   else
10013                      Set_Imported (Def_Id);
10014                   end if;
10015
10016                   Set_Is_Public (Def_Id);
10017                   Process_Interface_Name (Def_Id, Arg2, Arg3);
10018                end if;
10019
10020             --  Otherwise must be subprogram
10021
10022             elsif not Is_Subprogram (Def_Id) then
10023                Error_Pragma_Arg
10024                  ("argument of pragma% is not subprogram", Arg1);
10025
10026             else
10027                Check_At_Most_N_Arguments (3);
10028                Hom_Id := Def_Id;
10029                Found := False;
10030
10031                --  Loop through homonyms
10032
10033                loop
10034                   Def_Id := Get_Base_Subprogram (Hom_Id);
10035
10036                   if Is_Imported (Def_Id) then
10037                      Process_Interface_Name (Def_Id, Arg2, Arg3);
10038                      Found := True;
10039                   end if;
10040
10041                   exit when From_Aspect_Specification (N);
10042                   Hom_Id := Homonym (Hom_Id);
10043
10044                   exit when No (Hom_Id)
10045                     or else Scope (Hom_Id) /= Current_Scope;
10046                end loop;
10047
10048                if not Found then
10049                   Error_Pragma_Arg
10050                     ("argument of pragma% is not imported subprogram",
10051                      Arg1);
10052                end if;
10053             end if;
10054          end Interface_Name;
10055
10056          -----------------------
10057          -- Interrupt_Handler --
10058          -----------------------
10059
10060          --  pragma Interrupt_Handler (handler_NAME);
10061
10062          when Pragma_Interrupt_Handler =>
10063             Check_Ada_83_Warning;
10064             Check_Arg_Count (1);
10065             Check_No_Identifiers;
10066
10067             if No_Run_Time_Mode then
10068                Error_Msg_CRT ("Interrupt_Handler pragma", N);
10069             else
10070                Check_Interrupt_Or_Attach_Handler;
10071                Process_Interrupt_Or_Attach_Handler;
10072             end if;
10073
10074          ------------------------
10075          -- Interrupt_Priority --
10076          ------------------------
10077
10078          --  pragma Interrupt_Priority [(EXPRESSION)];
10079
10080          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10081             P   : constant Node_Id := Parent (N);
10082             Arg : Node_Id;
10083
10084          begin
10085             Check_Ada_83_Warning;
10086
10087             if Arg_Count /= 0 then
10088                Arg := Get_Pragma_Arg (Arg1);
10089                Check_Arg_Count (1);
10090                Check_No_Identifiers;
10091
10092                --  The expression must be analyzed in the special manner
10093                --  described in "Handling of Default and Per-Object
10094                --  Expressions" in sem.ads.
10095
10096                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10097             end if;
10098
10099             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10100                Pragma_Misplaced;
10101                return;
10102
10103             elsif Has_Pragma_Priority (P) then
10104                Error_Pragma ("duplicate pragma% not allowed");
10105
10106             else
10107                Set_Has_Pragma_Priority (P, True);
10108                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10109             end if;
10110          end Interrupt_Priority;
10111
10112          ---------------------
10113          -- Interrupt_State --
10114          ---------------------
10115
10116          --  pragma Interrupt_State (
10117          --    [Name  =>] INTERRUPT_ID,
10118          --    [State =>] INTERRUPT_STATE);
10119
10120          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10121          --  INTERRUPT_STATE => System | Runtime | User
10122
10123          --  Note: if the interrupt id is given as an identifier, then it must
10124          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10125          --  given as a static integer expression which must be in the range of
10126          --  Ada.Interrupts.Interrupt_ID.
10127
10128          when Pragma_Interrupt_State => Interrupt_State : declare
10129
10130             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10131             --  This is the entity Ada.Interrupts.Interrupt_ID;
10132
10133             State_Type : Character;
10134             --  Set to 's'/'r'/'u' for System/Runtime/User
10135
10136             IST_Num : Pos;
10137             --  Index to entry in Interrupt_States table
10138
10139             Int_Val : Uint;
10140             --  Value of interrupt
10141
10142             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10143             --  The first argument to the pragma
10144
10145             Int_Ent : Entity_Id;
10146             --  Interrupt entity in Ada.Interrupts.Names
10147
10148          begin
10149             GNAT_Pragma;
10150             Check_Arg_Order ((Name_Name, Name_State));
10151             Check_Arg_Count (2);
10152
10153             Check_Optional_Identifier (Arg1, Name_Name);
10154             Check_Optional_Identifier (Arg2, Name_State);
10155             Check_Arg_Is_Identifier (Arg2);
10156
10157             --  First argument is identifier
10158
10159             if Nkind (Arg1X) = N_Identifier then
10160
10161                --  Search list of names in Ada.Interrupts.Names
10162
10163                Int_Ent := First_Entity (RTE (RE_Names));
10164                loop
10165                   if No (Int_Ent) then
10166                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
10167
10168                   elsif Chars (Int_Ent) = Chars (Arg1X) then
10169                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
10170                      exit;
10171                   end if;
10172
10173                   Next_Entity (Int_Ent);
10174                end loop;
10175
10176             --  First argument is not an identifier, so it must be a static
10177             --  expression of type Ada.Interrupts.Interrupt_ID.
10178
10179             else
10180                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10181                Int_Val := Expr_Value (Arg1X);
10182
10183                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10184                     or else
10185                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10186                then
10187                   Error_Pragma_Arg
10188                     ("value not in range of type " &
10189                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10190                end if;
10191             end if;
10192
10193             --  Check OK state
10194
10195             case Chars (Get_Pragma_Arg (Arg2)) is
10196                when Name_Runtime => State_Type := 'r';
10197                when Name_System  => State_Type := 's';
10198                when Name_User    => State_Type := 'u';
10199
10200                when others =>
10201                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
10202             end case;
10203
10204             --  Check if entry is already stored
10205
10206             IST_Num := Interrupt_States.First;
10207             loop
10208                --  If entry not found, add it
10209
10210                if IST_Num > Interrupt_States.Last then
10211                   Interrupt_States.Append
10212                     ((Interrupt_Number => UI_To_Int (Int_Val),
10213                       Interrupt_State  => State_Type,
10214                       Pragma_Loc       => Loc));
10215                   exit;
10216
10217                --  Case of entry for the same entry
10218
10219                elsif Int_Val = Interrupt_States.Table (IST_Num).
10220                                                            Interrupt_Number
10221                then
10222                   --  If state matches, done, no need to make redundant entry
10223
10224                   exit when
10225                     State_Type = Interrupt_States.Table (IST_Num).
10226                                                            Interrupt_State;
10227
10228                   --  Otherwise if state does not match, error
10229
10230                   Error_Msg_Sloc :=
10231                     Interrupt_States.Table (IST_Num).Pragma_Loc;
10232                   Error_Pragma_Arg
10233                     ("state conflicts with that given #", Arg2);
10234                   exit;
10235                end if;
10236
10237                IST_Num := IST_Num + 1;
10238             end loop;
10239          end Interrupt_State;
10240
10241          ---------------
10242          -- Invariant --
10243          ---------------
10244
10245          --  pragma Invariant
10246          --    ([Entity =>]    type_LOCAL_NAME,
10247          --     [Check  =>]    EXPRESSION
10248          --     [,[Message =>] String_Expression]);
10249
10250          when Pragma_Invariant => Invariant : declare
10251             Type_Id : Node_Id;
10252             Typ     : Entity_Id;
10253
10254             Discard : Boolean;
10255             pragma Unreferenced (Discard);
10256
10257          begin
10258             GNAT_Pragma;
10259             Check_At_Least_N_Arguments (2);
10260             Check_At_Most_N_Arguments (3);
10261             Check_Optional_Identifier (Arg1, Name_Entity);
10262             Check_Optional_Identifier (Arg2, Name_Check);
10263
10264             if Arg_Count = 3 then
10265                Check_Optional_Identifier (Arg3, Name_Message);
10266                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10267             end if;
10268
10269             Check_Arg_Is_Local_Name (Arg1);
10270
10271             Type_Id := Get_Pragma_Arg (Arg1);
10272             Find_Type (Type_Id);
10273             Typ := Entity (Type_Id);
10274
10275             if Typ = Any_Type then
10276                return;
10277
10278             --  An invariant must apply to a private type, or appear in the
10279             --  private part of a package spec and apply to a completion.
10280
10281             elsif Ekind_In (Typ, E_Private_Type,
10282                                  E_Record_Type_With_Private,
10283                                  E_Limited_Private_Type)
10284             then
10285                null;
10286
10287             elsif In_Private_Part (Current_Scope)
10288               and then Has_Private_Declaration (Typ)
10289             then
10290                null;
10291
10292             elsif In_Private_Part (Current_Scope) then
10293                Error_Pragma_Arg
10294                  ("pragma% only allowed for private type " &
10295                   "declared in visible part", Arg1);
10296
10297             else
10298                Error_Pragma_Arg
10299                  ("pragma% only allowed for private type", Arg1);
10300             end if;
10301
10302             --  Note that the type has at least one invariant, and also that
10303             --  it has inheritable invariants if we have Invariant'Class.
10304
10305             Set_Has_Invariants (Typ);
10306
10307             if Class_Present (N) then
10308                Set_Has_Inheritable_Invariants (Typ);
10309             end if;
10310
10311             --  The remaining processing is simply to link the pragma on to
10312             --  the rep item chain, for processing when the type is frozen.
10313             --  This is accomplished by a call to Rep_Item_Too_Late.
10314
10315             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10316          end Invariant;
10317
10318          ----------------------
10319          -- Java_Constructor --
10320          ----------------------
10321
10322          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10323
10324          --  Also handles pragma CIL_Constructor
10325
10326          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10327          Java_Constructor : declare
10328             Convention  : Convention_Id;
10329             Def_Id      : Entity_Id;
10330             Hom_Id      : Entity_Id;
10331             Id          : Entity_Id;
10332             This_Formal : Entity_Id;
10333
10334          begin
10335             GNAT_Pragma;
10336             Check_Arg_Count (1);
10337             Check_Optional_Identifier (Arg1, Name_Entity);
10338             Check_Arg_Is_Local_Name (Arg1);
10339
10340             Id := Get_Pragma_Arg (Arg1);
10341             Find_Program_Unit_Name (Id);
10342
10343             --  If we did not find the name, we are done
10344
10345             if Etype (Id) = Any_Type then
10346                return;
10347             end if;
10348
10349             --  Check wrong use of pragma in wrong VM target
10350
10351             if VM_Target = No_VM then
10352                return;
10353
10354             elsif VM_Target = CLI_Target
10355               and then Prag_Id = Pragma_Java_Constructor
10356             then
10357                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10358
10359             elsif VM_Target = JVM_Target
10360               and then Prag_Id = Pragma_CIL_Constructor
10361             then
10362                Error_Pragma ("must use pragma 'Java_'Constructor");
10363             end if;
10364
10365             case Prag_Id is
10366                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
10367                when Pragma_Java_Constructor => Convention := Convention_Java;
10368                when others                  => null;
10369             end case;
10370
10371             Hom_Id := Entity (Id);
10372
10373             --  Loop through homonyms
10374
10375             loop
10376                Def_Id := Get_Base_Subprogram (Hom_Id);
10377
10378                --  The constructor is required to be a function
10379
10380                if Ekind (Def_Id) /= E_Function then
10381                   if VM_Target = JVM_Target then
10382                      Error_Pragma_Arg
10383                        ("pragma% requires function returning a " &
10384                         "'Java access type", Def_Id);
10385                   else
10386                      Error_Pragma_Arg
10387                        ("pragma% requires function returning a " &
10388                         "'C'I'L access type", Def_Id);
10389                   end if;
10390                end if;
10391
10392                --  Check arguments: For tagged type the first formal must be
10393                --  named "this" and its type must be a named access type
10394                --  designating a class-wide tagged type that has convention
10395                --  CIL/Java. The first formal must also have a null default
10396                --  value. For example:
10397
10398                --      type Typ is tagged ...
10399                --      type Ref is access all Typ;
10400                --      pragma Convention (CIL, Typ);
10401
10402                --      function New_Typ (This : Ref) return Ref;
10403                --      function New_Typ (This : Ref; I : Integer) return Ref;
10404                --      pragma Cil_Constructor (New_Typ);
10405
10406                --  Reason: The first formal must NOT be a primitive of the
10407                --  tagged type.
10408
10409                --  This rule also applies to constructors of delegates used
10410                --  to interface with standard target libraries. For example:
10411
10412                --      type Delegate is access procedure ...
10413                --      pragma Import (CIL, Delegate, ...);
10414
10415                --      function new_Delegate
10416                --        (This : Delegate := null; ... ) return Delegate;
10417
10418                --  For value-types this rule does not apply.
10419
10420                if not Is_Value_Type (Etype (Def_Id)) then
10421                   if No (First_Formal (Def_Id)) then
10422                      Error_Msg_Name_1 := Pname;
10423                      Error_Msg_N ("% function must have parameters", Def_Id);
10424                      return;
10425                   end if;
10426
10427                   --  In the JRE library we have several occurrences in which
10428                   --  the "this" parameter is not the first formal.
10429
10430                   This_Formal := First_Formal (Def_Id);
10431
10432                   --  In the JRE library we have several occurrences in which
10433                   --  the "this" parameter is not the first formal. Search for
10434                   --  it.
10435
10436                   if VM_Target = JVM_Target then
10437                      while Present (This_Formal)
10438                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10439                      loop
10440                         Next_Formal (This_Formal);
10441                      end loop;
10442
10443                      if No (This_Formal) then
10444                         This_Formal := First_Formal (Def_Id);
10445                      end if;
10446                   end if;
10447
10448                   --  Warning: The first parameter should be named "this".
10449                   --  We temporarily allow it because we have the following
10450                   --  case in the Java runtime (file s-osinte.ads) ???
10451
10452                   --    function new_Thread
10453                   --      (Self_Id : System.Address) return Thread_Id;
10454                   --    pragma Java_Constructor (new_Thread);
10455
10456                   if VM_Target = JVM_Target
10457                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10458                                = "self_id"
10459                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10460                   then
10461                      null;
10462
10463                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10464                      Error_Msg_Name_1 := Pname;
10465                      Error_Msg_N
10466                        ("first formal of % function must be named `this`",
10467                         Parent (This_Formal));
10468
10469                   elsif not Is_Access_Type (Etype (This_Formal)) then
10470                      Error_Msg_Name_1 := Pname;
10471                      Error_Msg_N
10472                        ("first formal of % function must be an access type",
10473                         Parameter_Type (Parent (This_Formal)));
10474
10475                   --  For delegates the type of the first formal must be a
10476                   --  named access-to-subprogram type (see previous example)
10477
10478                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10479                     and then Ekind (Etype (This_Formal))
10480                                /= E_Access_Subprogram_Type
10481                   then
10482                      Error_Msg_Name_1 := Pname;
10483                      Error_Msg_N
10484                        ("first formal of % function must be a named access" &
10485                         " to subprogram type",
10486                         Parameter_Type (Parent (This_Formal)));
10487
10488                   --  Warning: We should reject anonymous access types because
10489                   --  the constructor must not be handled as a primitive of the
10490                   --  tagged type. We temporarily allow it because this profile
10491                   --  is currently generated by cil2ada???
10492
10493                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10494                     and then not Ekind_In (Etype (This_Formal),
10495                                              E_Access_Type,
10496                                              E_General_Access_Type,
10497                                              E_Anonymous_Access_Type)
10498                   then
10499                      Error_Msg_Name_1 := Pname;
10500                      Error_Msg_N
10501                        ("first formal of % function must be a named access" &
10502                         " type",
10503                         Parameter_Type (Parent (This_Formal)));
10504
10505                   elsif Atree.Convention
10506                          (Designated_Type (Etype (This_Formal))) /= Convention
10507                   then
10508                      Error_Msg_Name_1 := Pname;
10509
10510                      if Convention = Convention_Java then
10511                         Error_Msg_N
10512                           ("pragma% requires convention 'Cil in designated" &
10513                            " type",
10514                            Parameter_Type (Parent (This_Formal)));
10515                      else
10516                         Error_Msg_N
10517                           ("pragma% requires convention 'Java in designated" &
10518                            " type",
10519                            Parameter_Type (Parent (This_Formal)));
10520                      end if;
10521
10522                   elsif No (Expression (Parent (This_Formal)))
10523                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10524                   then
10525                      Error_Msg_Name_1 := Pname;
10526                      Error_Msg_N
10527                        ("pragma% requires first formal with default `null`",
10528                         Parameter_Type (Parent (This_Formal)));
10529                   end if;
10530                end if;
10531
10532                --  Check result type: the constructor must be a function
10533                --  returning:
10534                --   * a value type (only allowed in the CIL compiler)
10535                --   * an access-to-subprogram type with convention Java/CIL
10536                --   * an access-type designating a type that has convention
10537                --     Java/CIL.
10538
10539                if Is_Value_Type (Etype (Def_Id)) then
10540                   null;
10541
10542                --  Access-to-subprogram type with convention Java/CIL
10543
10544                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10545                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10546                      if Convention = Convention_Java then
10547                         Error_Pragma_Arg
10548                           ("pragma% requires function returning a " &
10549                            "'Java access type", Arg1);
10550                      else
10551                         pragma Assert (Convention = Convention_CIL);
10552                         Error_Pragma_Arg
10553                           ("pragma% requires function returning a " &
10554                            "'C'I'L access type", Arg1);
10555                      end if;
10556                   end if;
10557
10558                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10559                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10560                                                    E_General_Access_Type)
10561                     or else
10562                       Atree.Convention
10563                         (Designated_Type (Etype (Def_Id))) /= Convention
10564                   then
10565                      Error_Msg_Name_1 := Pname;
10566
10567                      if Convention = Convention_Java then
10568                         Error_Pragma_Arg
10569                           ("pragma% requires function returning a named" &
10570                            "'Java access type", Arg1);
10571                      else
10572                         Error_Pragma_Arg
10573                           ("pragma% requires function returning a named" &
10574                            "'C'I'L access type", Arg1);
10575                      end if;
10576                   end if;
10577                end if;
10578
10579                Set_Is_Constructor (Def_Id);
10580                Set_Convention     (Def_Id, Convention);
10581                Set_Is_Imported    (Def_Id);
10582
10583                exit when From_Aspect_Specification (N);
10584                Hom_Id := Homonym (Hom_Id);
10585
10586                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10587             end loop;
10588          end Java_Constructor;
10589
10590          ----------------------
10591          -- Java_Interface --
10592          ----------------------
10593
10594          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10595
10596          when Pragma_Java_Interface => Java_Interface : declare
10597             Arg : Node_Id;
10598             Typ : Entity_Id;
10599
10600          begin
10601             GNAT_Pragma;
10602             Check_Arg_Count (1);
10603             Check_Optional_Identifier (Arg1, Name_Entity);
10604             Check_Arg_Is_Local_Name (Arg1);
10605
10606             Arg := Get_Pragma_Arg (Arg1);
10607             Analyze (Arg);
10608
10609             if Etype (Arg) = Any_Type then
10610                return;
10611             end if;
10612
10613             if not Is_Entity_Name (Arg)
10614               or else not Is_Type (Entity (Arg))
10615             then
10616                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10617             end if;
10618
10619             Typ := Underlying_Type (Entity (Arg));
10620
10621             --  For now simply check some of the semantic constraints on the
10622             --  type. This currently leaves out some restrictions on interface
10623             --  types, namely that the parent type must be java.lang.Object.Typ
10624             --  and that all primitives of the type should be declared
10625             --  abstract. ???
10626
10627             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10628                Error_Pragma_Arg ("pragma% requires an abstract "
10629                  & "tagged type", Arg1);
10630
10631             elsif not Has_Discriminants (Typ)
10632               or else Ekind (Etype (First_Discriminant (Typ)))
10633                         /= E_Anonymous_Access_Type
10634               or else
10635                 not Is_Class_Wide_Type
10636                       (Designated_Type (Etype (First_Discriminant (Typ))))
10637             then
10638                Error_Pragma_Arg
10639                  ("type must have a class-wide access discriminant", Arg1);
10640             end if;
10641          end Java_Interface;
10642
10643          ----------------
10644          -- Keep_Names --
10645          ----------------
10646
10647          --  pragma Keep_Names ([On => ] local_NAME);
10648
10649          when Pragma_Keep_Names => Keep_Names : declare
10650             Arg : Node_Id;
10651
10652          begin
10653             GNAT_Pragma;
10654             Check_Arg_Count (1);
10655             Check_Optional_Identifier (Arg1, Name_On);
10656             Check_Arg_Is_Local_Name (Arg1);
10657
10658             Arg := Get_Pragma_Arg (Arg1);
10659             Analyze (Arg);
10660
10661             if Etype (Arg) = Any_Type then
10662                return;
10663             end if;
10664
10665             if not Is_Entity_Name (Arg)
10666               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10667             then
10668                Error_Pragma_Arg
10669                  ("pragma% requires a local enumeration type", Arg1);
10670             end if;
10671
10672             Set_Discard_Names (Entity (Arg), False);
10673          end Keep_Names;
10674
10675          -------------
10676          -- License --
10677          -------------
10678
10679          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10680
10681          when Pragma_License =>
10682             GNAT_Pragma;
10683             Check_Arg_Count (1);
10684             Check_No_Identifiers;
10685             Check_Valid_Configuration_Pragma;
10686             Check_Arg_Is_Identifier (Arg1);
10687
10688             declare
10689                Sind : constant Source_File_Index :=
10690                         Source_Index (Current_Sem_Unit);
10691
10692             begin
10693                case Chars (Get_Pragma_Arg (Arg1)) is
10694                   when Name_GPL =>
10695                      Set_License (Sind, GPL);
10696
10697                   when Name_Modified_GPL =>
10698                      Set_License (Sind, Modified_GPL);
10699
10700                   when Name_Restricted =>
10701                      Set_License (Sind, Restricted);
10702
10703                   when Name_Unrestricted =>
10704                      Set_License (Sind, Unrestricted);
10705
10706                   when others =>
10707                      Error_Pragma_Arg ("invalid license name", Arg1);
10708                end case;
10709             end;
10710
10711          ---------------
10712          -- Link_With --
10713          ---------------
10714
10715          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10716
10717          when Pragma_Link_With => Link_With : declare
10718             Arg : Node_Id;
10719
10720          begin
10721             GNAT_Pragma;
10722
10723             if Operating_Mode = Generate_Code
10724               and then In_Extended_Main_Source_Unit (N)
10725             then
10726                Check_At_Least_N_Arguments (1);
10727                Check_No_Identifiers;
10728                Check_Is_In_Decl_Part_Or_Package_Spec;
10729                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10730                Start_String;
10731
10732                Arg := Arg1;
10733                while Present (Arg) loop
10734                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10735
10736                   --  Store argument, converting sequences of spaces to a
10737                   --  single null character (this is one of the differences
10738                   --  in processing between Link_With and Linker_Options).
10739
10740                   Arg_Store : declare
10741                      C : constant Char_Code := Get_Char_Code (' ');
10742                      S : constant String_Id :=
10743                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10744                      L : constant Nat := String_Length (S);
10745                      F : Nat := 1;
10746
10747                      procedure Skip_Spaces;
10748                      --  Advance F past any spaces
10749
10750                      -----------------
10751                      -- Skip_Spaces --
10752                      -----------------
10753
10754                      procedure Skip_Spaces is
10755                      begin
10756                         while F <= L and then Get_String_Char (S, F) = C loop
10757                            F := F + 1;
10758                         end loop;
10759                      end Skip_Spaces;
10760
10761                   --  Start of processing for Arg_Store
10762
10763                   begin
10764                      Skip_Spaces; -- skip leading spaces
10765
10766                      --  Loop through characters, changing any embedded
10767                      --  sequence of spaces to a single null character (this
10768                      --  is how Link_With/Linker_Options differ)
10769
10770                      while F <= L loop
10771                         if Get_String_Char (S, F) = C then
10772                            Skip_Spaces;
10773                            exit when F > L;
10774                            Store_String_Char (ASCII.NUL);
10775
10776                         else
10777                            Store_String_Char (Get_String_Char (S, F));
10778                            F := F + 1;
10779                         end if;
10780                      end loop;
10781                   end Arg_Store;
10782
10783                   Arg := Next (Arg);
10784
10785                   if Present (Arg) then
10786                      Store_String_Char (ASCII.NUL);
10787                   end if;
10788                end loop;
10789
10790                Store_Linker_Option_String (End_String);
10791             end if;
10792          end Link_With;
10793
10794          ------------------
10795          -- Linker_Alias --
10796          ------------------
10797
10798          --  pragma Linker_Alias (
10799          --      [Entity =>]  LOCAL_NAME
10800          --      [Target =>]  static_string_EXPRESSION);
10801
10802          when Pragma_Linker_Alias =>
10803             GNAT_Pragma;
10804             Check_Arg_Order ((Name_Entity, Name_Target));
10805             Check_Arg_Count (2);
10806             Check_Optional_Identifier (Arg1, Name_Entity);
10807             Check_Optional_Identifier (Arg2, Name_Target);
10808             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10809             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10810
10811             --  The only processing required is to link this item on to the
10812             --  list of rep items for the given entity. This is accomplished
10813             --  by the call to Rep_Item_Too_Late (when no error is detected
10814             --  and False is returned).
10815
10816             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10817                return;
10818             else
10819                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10820             end if;
10821
10822          ------------------------
10823          -- Linker_Constructor --
10824          ------------------------
10825
10826          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10827
10828          --  Code is shared with Linker_Destructor
10829
10830          -----------------------
10831          -- Linker_Destructor --
10832          -----------------------
10833
10834          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10835
10836          when Pragma_Linker_Constructor |
10837               Pragma_Linker_Destructor =>
10838          Linker_Constructor : declare
10839             Arg1_X : Node_Id;
10840             Proc   : Entity_Id;
10841
10842          begin
10843             GNAT_Pragma;
10844             Check_Arg_Count (1);
10845             Check_No_Identifiers;
10846             Check_Arg_Is_Local_Name (Arg1);
10847             Arg1_X := Get_Pragma_Arg (Arg1);
10848             Analyze (Arg1_X);
10849             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10850
10851             if not Is_Library_Level_Entity (Proc) then
10852                Error_Pragma_Arg
10853                 ("argument for pragma% must be library level entity", Arg1);
10854             end if;
10855
10856             --  The only processing required is to link this item on to the
10857             --  list of rep items for the given entity. This is accomplished
10858             --  by the call to Rep_Item_Too_Late (when no error is detected
10859             --  and False is returned).
10860
10861             if Rep_Item_Too_Late (Proc, N) then
10862                return;
10863             else
10864                Set_Has_Gigi_Rep_Item (Proc);
10865             end if;
10866          end Linker_Constructor;
10867
10868          --------------------
10869          -- Linker_Options --
10870          --------------------
10871
10872          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10873
10874          when Pragma_Linker_Options => Linker_Options : declare
10875             Arg : Node_Id;
10876
10877          begin
10878             Check_Ada_83_Warning;
10879             Check_No_Identifiers;
10880             Check_Arg_Count (1);
10881             Check_Is_In_Decl_Part_Or_Package_Spec;
10882             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10883             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10884
10885             Arg := Arg2;
10886             while Present (Arg) loop
10887                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10888                Store_String_Char (ASCII.NUL);
10889                Store_String_Chars
10890                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10891                Arg := Next (Arg);
10892             end loop;
10893
10894             if Operating_Mode = Generate_Code
10895               and then In_Extended_Main_Source_Unit (N)
10896             then
10897                Store_Linker_Option_String (End_String);
10898             end if;
10899          end Linker_Options;
10900
10901          --------------------
10902          -- Linker_Section --
10903          --------------------
10904
10905          --  pragma Linker_Section (
10906          --      [Entity  =>]  LOCAL_NAME
10907          --      [Section =>]  static_string_EXPRESSION);
10908
10909          when Pragma_Linker_Section =>
10910             GNAT_Pragma;
10911             Check_Arg_Order ((Name_Entity, Name_Section));
10912             Check_Arg_Count (2);
10913             Check_Optional_Identifier (Arg1, Name_Entity);
10914             Check_Optional_Identifier (Arg2, Name_Section);
10915             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10916             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10917
10918             --  This pragma applies only to objects
10919
10920             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10921                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10922             end if;
10923
10924             --  The only processing required is to link this item on to the
10925             --  list of rep items for the given entity. This is accomplished
10926             --  by the call to Rep_Item_Too_Late (when no error is detected
10927             --  and False is returned).
10928
10929             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10930                return;
10931             else
10932                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10933             end if;
10934
10935          ----------
10936          -- List --
10937          ----------
10938
10939          --  pragma List (On | Off)
10940
10941          --  There is nothing to do here, since we did all the processing for
10942          --  this pragma in Par.Prag (so that it works properly even in syntax
10943          --  only mode).
10944
10945          when Pragma_List =>
10946             null;
10947
10948          --------------------
10949          -- Locking_Policy --
10950          --------------------
10951
10952          --  pragma Locking_Policy (policy_IDENTIFIER);
10953
10954          when Pragma_Locking_Policy => declare
10955             subtype LP_Range is Name_Id
10956               range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10957             LP_Val : LP_Range;
10958             LP     : Character;
10959          begin
10960             Check_Ada_83_Warning;
10961             Check_Arg_Count (1);
10962             Check_No_Identifiers;
10963             Check_Arg_Is_Locking_Policy (Arg1);
10964             Check_Valid_Configuration_Pragma;
10965             LP_Val := Chars (Get_Pragma_Arg (Arg1));
10966
10967             case LP_Val is
10968                when Name_Ceiling_Locking            => LP := 'C';
10969                when Name_Inheritance_Locking        => LP := 'I';
10970                when Name_Concurrent_Readers_Locking => LP := 'R';
10971             end case;
10972
10973             if Locking_Policy /= ' '
10974               and then Locking_Policy /= LP
10975             then
10976                Error_Msg_Sloc := Locking_Policy_Sloc;
10977                Error_Pragma ("locking policy incompatible with policy#");
10978
10979             --  Set new policy, but always preserve System_Location since we
10980             --  like the error message with the run time name.
10981
10982             else
10983                Locking_Policy := LP;
10984
10985                if Locking_Policy_Sloc /= System_Location then
10986                   Locking_Policy_Sloc := Loc;
10987                end if;
10988             end if;
10989          end;
10990
10991          ----------------
10992          -- Long_Float --
10993          ----------------
10994
10995          --  pragma Long_Float (D_Float | G_Float);
10996
10997          when Pragma_Long_Float => Long_Float : declare
10998          begin
10999             GNAT_Pragma;
11000             Check_Valid_Configuration_Pragma;
11001             Check_Arg_Count (1);
11002             Check_No_Identifier (Arg1);
11003             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11004
11005             if not OpenVMS_On_Target then
11006                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11007             end if;
11008
11009             --  D_Float case
11010
11011             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11012                if Opt.Float_Format_Long = 'G' then
11013                   Error_Pragma_Arg
11014                     ("G_Float previously specified", Arg1);
11015
11016                elsif Current_Sem_Unit /= Main_Unit
11017                  and then Opt.Float_Format_Long /= 'D'
11018                then
11019                   Error_Pragma_Arg
11020                     ("main unit not compiled with pragma Long_Float (D_Float)",
11021                      "\pragma% must be used consistently for whole partition",
11022                      Arg1);
11023
11024                else
11025                   Opt.Float_Format_Long := 'D';
11026                end if;
11027
11028             --  G_Float case (this is the default, does not need overriding)
11029
11030             else
11031                if Opt.Float_Format_Long = 'D' then
11032                   Error_Pragma ("D_Float previously specified");
11033
11034                elsif Current_Sem_Unit /= Main_Unit
11035                  and then Opt.Float_Format_Long /= 'G'
11036                then
11037                   Error_Pragma_Arg
11038                     ("main unit not compiled with pragma Long_Float (G_Float)",
11039                      "\pragma% must be used consistently for whole partition",
11040                      Arg1);
11041
11042                else
11043                   Opt.Float_Format_Long := 'G';
11044                end if;
11045             end if;
11046
11047             Set_Standard_Fpt_Formats;
11048          end Long_Float;
11049
11050          -----------------------
11051          -- Machine_Attribute --
11052          -----------------------
11053
11054          --  pragma Machine_Attribute (
11055          --       [Entity         =>] LOCAL_NAME,
11056          --       [Attribute_Name =>] static_string_EXPRESSION
11057          --    [, [Info           =>] static_EXPRESSION] );
11058
11059          when Pragma_Machine_Attribute => Machine_Attribute : declare
11060             Def_Id : Entity_Id;
11061
11062          begin
11063             GNAT_Pragma;
11064             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11065
11066             if Arg_Count = 3 then
11067                Check_Optional_Identifier (Arg3, Name_Info);
11068                Check_Arg_Is_Static_Expression (Arg3);
11069             else
11070                Check_Arg_Count (2);
11071             end if;
11072
11073             Check_Optional_Identifier (Arg1, Name_Entity);
11074             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11075             Check_Arg_Is_Local_Name (Arg1);
11076             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11077             Def_Id := Entity (Get_Pragma_Arg (Arg1));
11078
11079             if Is_Access_Type (Def_Id) then
11080                Def_Id := Designated_Type (Def_Id);
11081             end if;
11082
11083             if Rep_Item_Too_Early (Def_Id, N) then
11084                return;
11085             end if;
11086
11087             Def_Id := Underlying_Type (Def_Id);
11088
11089             --  The only processing required is to link this item on to the
11090             --  list of rep items for the given entity. This is accomplished
11091             --  by the call to Rep_Item_Too_Late (when no error is detected
11092             --  and False is returned).
11093
11094             if Rep_Item_Too_Late (Def_Id, N) then
11095                return;
11096             else
11097                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11098             end if;
11099          end Machine_Attribute;
11100
11101          ----------
11102          -- Main --
11103          ----------
11104
11105          --  pragma Main
11106          --   (MAIN_OPTION [, MAIN_OPTION]);
11107
11108          --  MAIN_OPTION ::=
11109          --    [STACK_SIZE              =>] static_integer_EXPRESSION
11110          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11111          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
11112
11113          when Pragma_Main => Main : declare
11114             Args  : Args_List (1 .. 3);
11115             Names : constant Name_List (1 .. 3) := (
11116                       Name_Stack_Size,
11117                       Name_Task_Stack_Size_Default,
11118                       Name_Time_Slicing_Enabled);
11119
11120             Nod : Node_Id;
11121
11122          begin
11123             GNAT_Pragma;
11124             Gather_Associations (Names, Args);
11125
11126             for J in 1 .. 2 loop
11127                if Present (Args (J)) then
11128                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11129                end if;
11130             end loop;
11131
11132             if Present (Args (3)) then
11133                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11134             end if;
11135
11136             Nod := Next (N);
11137             while Present (Nod) loop
11138                if Nkind (Nod) = N_Pragma
11139                  and then Pragma_Name (Nod) = Name_Main
11140                then
11141                   Error_Msg_Name_1 := Pname;
11142                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11143                end if;
11144
11145                Next (Nod);
11146             end loop;
11147          end Main;
11148
11149          ------------------
11150          -- Main_Storage --
11151          ------------------
11152
11153          --  pragma Main_Storage
11154          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11155
11156          --  MAIN_STORAGE_OPTION ::=
11157          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11158          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11159
11160          when Pragma_Main_Storage => Main_Storage : declare
11161             Args  : Args_List (1 .. 2);
11162             Names : constant Name_List (1 .. 2) := (
11163                       Name_Working_Storage,
11164                       Name_Top_Guard);
11165
11166             Nod : Node_Id;
11167
11168          begin
11169             GNAT_Pragma;
11170             Gather_Associations (Names, Args);
11171
11172             for J in 1 .. 2 loop
11173                if Present (Args (J)) then
11174                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11175                end if;
11176             end loop;
11177
11178             Check_In_Main_Program;
11179
11180             Nod := Next (N);
11181             while Present (Nod) loop
11182                if Nkind (Nod) = N_Pragma
11183                  and then Pragma_Name (Nod) = Name_Main_Storage
11184                then
11185                   Error_Msg_Name_1 := Pname;
11186                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11187                end if;
11188
11189                Next (Nod);
11190             end loop;
11191          end Main_Storage;
11192
11193          -----------------
11194          -- Memory_Size --
11195          -----------------
11196
11197          --  pragma Memory_Size (NUMERIC_LITERAL)
11198
11199          when Pragma_Memory_Size =>
11200             GNAT_Pragma;
11201
11202             --  Memory size is simply ignored
11203
11204             Check_No_Identifiers;
11205             Check_Arg_Count (1);
11206             Check_Arg_Is_Integer_Literal (Arg1);
11207
11208          -------------
11209          -- No_Body --
11210          -------------
11211
11212          --  pragma No_Body;
11213
11214          --  The only correct use of this pragma is on its own in a file, in
11215          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
11216          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11217          --  check for a file containing nothing but a No_Body pragma). If we
11218          --  attempt to process it during normal semantics processing, it means
11219          --  it was misplaced.
11220
11221          when Pragma_No_Body =>
11222             GNAT_Pragma;
11223             Pragma_Misplaced;
11224
11225          ---------------
11226          -- No_Return --
11227          ---------------
11228
11229          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11230
11231          when Pragma_No_Return => No_Return : declare
11232             Id    : Node_Id;
11233             E     : Entity_Id;
11234             Found : Boolean;
11235             Arg   : Node_Id;
11236
11237          begin
11238             Ada_2005_Pragma;
11239             Check_At_Least_N_Arguments (1);
11240
11241             --  Loop through arguments of pragma
11242
11243             Arg := Arg1;
11244             while Present (Arg) loop
11245                Check_Arg_Is_Local_Name (Arg);
11246                Id := Get_Pragma_Arg (Arg);
11247                Analyze (Id);
11248
11249                if not Is_Entity_Name (Id) then
11250                   Error_Pragma_Arg ("entity name required", Arg);
11251                end if;
11252
11253                if Etype (Id) = Any_Type then
11254                   raise Pragma_Exit;
11255                end if;
11256
11257                --  Loop to find matching procedures
11258
11259                E := Entity (Id);
11260                Found := False;
11261                while Present (E)
11262                  and then Scope (E) = Current_Scope
11263                loop
11264                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11265                      Set_No_Return (E);
11266
11267                      --  Set flag on any alias as well
11268
11269                      if Is_Overloadable (E) and then Present (Alias (E)) then
11270                         Set_No_Return (Alias (E));
11271                      end if;
11272
11273                      Found := True;
11274                   end if;
11275
11276                   exit when From_Aspect_Specification (N);
11277                   E := Homonym (E);
11278                end loop;
11279
11280                if not Found then
11281                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11282                end if;
11283
11284                Next (Arg);
11285             end loop;
11286          end No_Return;
11287
11288          -----------------
11289          -- No_Run_Time --
11290          -----------------
11291
11292          --  pragma No_Run_Time;
11293
11294          --  Note: this pragma is retained for backwards compatibility. See
11295          --  body of Rtsfind for full details on its handling.
11296
11297          when Pragma_No_Run_Time =>
11298             GNAT_Pragma;
11299             Check_Valid_Configuration_Pragma;
11300             Check_Arg_Count (0);
11301
11302             No_Run_Time_Mode           := True;
11303             Configurable_Run_Time_Mode := True;
11304
11305             --  Set Duration to 32 bits if word size is 32
11306
11307             if Ttypes.System_Word_Size = 32 then
11308                Duration_32_Bits_On_Target := True;
11309             end if;
11310
11311             --  Set appropriate restrictions
11312
11313             Set_Restriction (No_Finalization, N);
11314             Set_Restriction (No_Exception_Handlers, N);
11315             Set_Restriction (Max_Tasks, N, 0);
11316             Set_Restriction (No_Tasking, N);
11317
11318          ------------------------
11319          -- No_Strict_Aliasing --
11320          ------------------------
11321
11322          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11323
11324          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11325             E_Id : Entity_Id;
11326
11327          begin
11328             GNAT_Pragma;
11329             Check_At_Most_N_Arguments (1);
11330
11331             if Arg_Count = 0 then
11332                Check_Valid_Configuration_Pragma;
11333                Opt.No_Strict_Aliasing := True;
11334
11335             else
11336                Check_Optional_Identifier (Arg2, Name_Entity);
11337                Check_Arg_Is_Local_Name (Arg1);
11338                E_Id := Entity (Get_Pragma_Arg (Arg1));
11339
11340                if E_Id = Any_Type then
11341                   return;
11342                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11343                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
11344                end if;
11345
11346                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11347             end if;
11348          end No_Strict_Aliasing;
11349
11350          -----------------------
11351          -- Normalize_Scalars --
11352          -----------------------
11353
11354          --  pragma Normalize_Scalars;
11355
11356          when Pragma_Normalize_Scalars =>
11357             Check_Ada_83_Warning;
11358             Check_Arg_Count (0);
11359             Check_Valid_Configuration_Pragma;
11360
11361             --  Normalize_Scalars creates false positives in CodePeer, and
11362             --  incorrect negative results in Alfa mode, so ignore this pragma
11363             --  in these modes.
11364
11365             if not (CodePeer_Mode or Alfa_Mode) then
11366                Normalize_Scalars := True;
11367                Init_Or_Norm_Scalars := True;
11368             end if;
11369
11370          -----------------
11371          -- Obsolescent --
11372          -----------------
11373
11374          --  pragma Obsolescent;
11375
11376          --  pragma Obsolescent (
11377          --    [Message =>] static_string_EXPRESSION
11378          --  [,[Version =>] Ada_05]]);
11379
11380          --  pragma Obsolescent (
11381          --    [Entity  =>] NAME
11382          --  [,[Message =>] static_string_EXPRESSION
11383          --  [,[Version =>] Ada_05]] );
11384
11385          when Pragma_Obsolescent => Obsolescent : declare
11386             Ename : Node_Id;
11387             Decl  : Node_Id;
11388
11389             procedure Set_Obsolescent (E : Entity_Id);
11390             --  Given an entity Ent, mark it as obsolescent if appropriate
11391
11392             ---------------------
11393             -- Set_Obsolescent --
11394             ---------------------
11395
11396             procedure Set_Obsolescent (E : Entity_Id) is
11397                Active : Boolean;
11398                Ent    : Entity_Id;
11399                S      : String_Id;
11400
11401             begin
11402                Active := True;
11403                Ent    := E;
11404
11405                --  Entity name was given
11406
11407                if Present (Ename) then
11408
11409                   --  If entity name matches, we are fine. Save entity in
11410                   --  pragma argument, for ASIS use.
11411
11412                   if Chars (Ename) = Chars (Ent) then
11413                      Set_Entity (Ename, Ent);
11414                      Generate_Reference (Ent, Ename);
11415
11416                   --  If entity name does not match, only possibility is an
11417                   --  enumeration literal from an enumeration type declaration.
11418
11419                   elsif Ekind (Ent) /= E_Enumeration_Type then
11420                      Error_Pragma
11421                        ("pragma % entity name does not match declaration");
11422
11423                   else
11424                      Ent := First_Literal (E);
11425                      loop
11426                         if No (Ent) then
11427                            Error_Pragma
11428                              ("pragma % entity name does not match any " &
11429                               "enumeration literal");
11430
11431                         elsif Chars (Ent) = Chars (Ename) then
11432                            Set_Entity (Ename, Ent);
11433                            Generate_Reference (Ent, Ename);
11434                            exit;
11435
11436                         else
11437                            Ent := Next_Literal (Ent);
11438                         end if;
11439                      end loop;
11440                   end if;
11441                end if;
11442
11443                --  Ent points to entity to be marked
11444
11445                if Arg_Count >= 1 then
11446
11447                   --  Deal with static string argument
11448
11449                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11450                   S := Strval (Get_Pragma_Arg (Arg1));
11451
11452                   for J in 1 .. String_Length (S) loop
11453                      if not In_Character_Range (Get_String_Char (S, J)) then
11454                         Error_Pragma_Arg
11455                           ("pragma% argument does not allow wide characters",
11456                            Arg1);
11457                      end if;
11458                   end loop;
11459
11460                   Obsolescent_Warnings.Append
11461                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11462
11463                   --  Check for Ada_05 parameter
11464
11465                   if Arg_Count /= 1 then
11466                      Check_Arg_Count (2);
11467
11468                      declare
11469                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11470
11471                      begin
11472                         Check_Arg_Is_Identifier (Argx);
11473
11474                         if Chars (Argx) /= Name_Ada_05 then
11475                            Error_Msg_Name_2 := Name_Ada_05;
11476                            Error_Pragma_Arg
11477                              ("only allowed argument for pragma% is %", Argx);
11478                         end if;
11479
11480                         if Ada_Version_Explicit < Ada_2005
11481                           or else not Warn_On_Ada_2005_Compatibility
11482                         then
11483                            Active := False;
11484                         end if;
11485                      end;
11486                   end if;
11487                end if;
11488
11489                --  Set flag if pragma active
11490
11491                if Active then
11492                   Set_Is_Obsolescent (Ent);
11493                end if;
11494
11495                return;
11496             end Set_Obsolescent;
11497
11498          --  Start of processing for pragma Obsolescent
11499
11500          begin
11501             GNAT_Pragma;
11502
11503             Check_At_Most_N_Arguments (3);
11504
11505             --  See if first argument specifies an entity name
11506
11507             if Arg_Count >= 1
11508               and then
11509                 (Chars (Arg1) = Name_Entity
11510                    or else
11511                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11512                                                       N_Identifier,
11513                                                       N_Operator_Symbol))
11514             then
11515                Ename := Get_Pragma_Arg (Arg1);
11516
11517                --  Eliminate first argument, so we can share processing
11518
11519                Arg1 := Arg2;
11520                Arg2 := Arg3;
11521                Arg_Count := Arg_Count - 1;
11522
11523             --  No Entity name argument given
11524
11525             else
11526                Ename := Empty;
11527             end if;
11528
11529             if Arg_Count >= 1 then
11530                Check_Optional_Identifier (Arg1, Name_Message);
11531
11532                if Arg_Count = 2 then
11533                   Check_Optional_Identifier (Arg2, Name_Version);
11534                end if;
11535             end if;
11536
11537             --  Get immediately preceding declaration
11538
11539             Decl := Prev (N);
11540             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11541                Prev (Decl);
11542             end loop;
11543
11544             --  Cases where we do not follow anything other than another pragma
11545
11546             if No (Decl) then
11547
11548                --  First case: library level compilation unit declaration with
11549                --  the pragma immediately following the declaration.
11550
11551                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11552                   Set_Obsolescent
11553                     (Defining_Entity (Unit (Parent (Parent (N)))));
11554                   return;
11555
11556                --  Case 2: library unit placement for package
11557
11558                else
11559                   declare
11560                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11561                   begin
11562                      if Is_Package_Or_Generic_Package (Ent) then
11563                         Set_Obsolescent (Ent);
11564                         return;
11565                      end if;
11566                   end;
11567                end if;
11568
11569             --  Cases where we must follow a declaration
11570
11571             else
11572                if         Nkind (Decl) not in N_Declaration
11573                  and then Nkind (Decl) not in N_Later_Decl_Item
11574                  and then Nkind (Decl) not in N_Generic_Declaration
11575                  and then Nkind (Decl) not in N_Renaming_Declaration
11576                then
11577                   Error_Pragma
11578                     ("pragma% misplaced, "
11579                      & "must immediately follow a declaration");
11580
11581                else
11582                   Set_Obsolescent (Defining_Entity (Decl));
11583                   return;
11584                end if;
11585             end if;
11586          end Obsolescent;
11587
11588          --------------
11589          -- Optimize --
11590          --------------
11591
11592          --  pragma Optimize (Time | Space | Off);
11593
11594          --  The actual check for optimize is done in Gigi. Note that this
11595          --  pragma does not actually change the optimization setting, it
11596          --  simply checks that it is consistent with the pragma.
11597
11598          when Pragma_Optimize =>
11599             Check_No_Identifiers;
11600             Check_Arg_Count (1);
11601             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11602
11603          ------------------------
11604          -- Optimize_Alignment --
11605          ------------------------
11606
11607          --  pragma Optimize_Alignment (Time | Space | Off);
11608
11609          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11610             GNAT_Pragma;
11611             Check_No_Identifiers;
11612             Check_Arg_Count (1);
11613             Check_Valid_Configuration_Pragma;
11614
11615             declare
11616                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11617             begin
11618                case Nam is
11619                   when Name_Time =>
11620                      Opt.Optimize_Alignment := 'T';
11621                   when Name_Space =>
11622                      Opt.Optimize_Alignment := 'S';
11623                   when Name_Off =>
11624                      Opt.Optimize_Alignment := 'O';
11625                   when others =>
11626                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11627                end case;
11628             end;
11629
11630             --  Set indication that mode is set locally. If we are in fact in a
11631             --  configuration pragma file, this setting is harmless since the
11632             --  switch will get reset anyway at the start of each unit.
11633
11634             Optimize_Alignment_Local := True;
11635          end Optimize_Alignment;
11636
11637          -------------
11638          -- Ordered --
11639          -------------
11640
11641          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11642
11643          when Pragma_Ordered => Ordered : declare
11644             Assoc   : constant Node_Id := Arg1;
11645             Type_Id : Node_Id;
11646             Typ     : Entity_Id;
11647
11648          begin
11649             GNAT_Pragma;
11650             Check_No_Identifiers;
11651             Check_Arg_Count (1);
11652             Check_Arg_Is_Local_Name (Arg1);
11653
11654             Type_Id := Get_Pragma_Arg (Assoc);
11655             Find_Type (Type_Id);
11656             Typ := Entity (Type_Id);
11657
11658             if Typ = Any_Type then
11659                return;
11660             else
11661                Typ := Underlying_Type (Typ);
11662             end if;
11663
11664             if not Is_Enumeration_Type (Typ) then
11665                Error_Pragma ("pragma% must specify enumeration type");
11666             end if;
11667
11668             Check_First_Subtype (Arg1);
11669             Set_Has_Pragma_Ordered (Base_Type (Typ));
11670          end Ordered;
11671
11672          ----------
11673          -- Pack --
11674          ----------
11675
11676          --  pragma Pack (first_subtype_LOCAL_NAME);
11677
11678          when Pragma_Pack => Pack : declare
11679             Assoc   : constant Node_Id := Arg1;
11680             Type_Id : Node_Id;
11681             Typ     : Entity_Id;
11682             Ctyp    : Entity_Id;
11683             Ignore  : Boolean := False;
11684
11685          begin
11686             Check_No_Identifiers;
11687             Check_Arg_Count (1);
11688             Check_Arg_Is_Local_Name (Arg1);
11689
11690             Type_Id := Get_Pragma_Arg (Assoc);
11691             Find_Type (Type_Id);
11692             Typ := Entity (Type_Id);
11693
11694             if Typ = Any_Type
11695               or else Rep_Item_Too_Early (Typ, N)
11696             then
11697                return;
11698             else
11699                Typ := Underlying_Type (Typ);
11700             end if;
11701
11702             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11703                Error_Pragma ("pragma% must specify array or record type");
11704             end if;
11705
11706             Check_First_Subtype (Arg1);
11707             Check_Duplicate_Pragma (Typ);
11708
11709             --  Array type
11710
11711             if Is_Array_Type (Typ) then
11712                Ctyp := Component_Type (Typ);
11713
11714                --  Ignore pack that does nothing
11715
11716                if Known_Static_Esize (Ctyp)
11717                  and then Known_Static_RM_Size (Ctyp)
11718                  and then Esize (Ctyp) = RM_Size (Ctyp)
11719                  and then Addressable (Esize (Ctyp))
11720                then
11721                   Ignore := True;
11722                end if;
11723
11724                --  Process OK pragma Pack. Note that if there is a separate
11725                --  component clause present, the Pack will be cancelled. This
11726                --  processing is in Freeze.
11727
11728                if not Rep_Item_Too_Late (Typ, N) then
11729
11730                   --  In the context of static code analysis, we do not need
11731                   --  complex front-end expansions related to pragma Pack,
11732                   --  so disable handling of pragma Pack in these cases.
11733
11734                   if CodePeer_Mode or Alfa_Mode then
11735                      null;
11736
11737                   --  Don't attempt any packing for VM targets. We possibly
11738                   --  could deal with some cases of array bit-packing, but we
11739                   --  don't bother, since this is not a typical kind of
11740                   --  representation in the VM context anyway (and would not
11741                   --  for example work nicely with the debugger).
11742
11743                   elsif VM_Target /= No_VM then
11744                      if not GNAT_Mode then
11745                         Error_Pragma
11746                           ("?pragma% ignored in this configuration");
11747                      end if;
11748
11749                   --  Normal case where we do the pack action
11750
11751                   else
11752                      if not Ignore then
11753                         Set_Is_Packed            (Base_Type (Typ));
11754                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11755                      end if;
11756
11757                      Set_Has_Pragma_Pack (Base_Type (Typ));
11758                   end if;
11759                end if;
11760
11761             --  For record types, the pack is always effective
11762
11763             else pragma Assert (Is_Record_Type (Typ));
11764                if not Rep_Item_Too_Late (Typ, N) then
11765
11766                   --  Ignore pack request with warning in VM mode (skip warning
11767                   --  if we are compiling GNAT run time library).
11768
11769                   if VM_Target /= No_VM then
11770                      if not GNAT_Mode then
11771                         Error_Pragma
11772                           ("?pragma% ignored in this configuration");
11773                      end if;
11774
11775                   --  Normal case of pack request active
11776
11777                   else
11778                      Set_Is_Packed            (Base_Type (Typ));
11779                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11780                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11781                   end if;
11782                end if;
11783             end if;
11784          end Pack;
11785
11786          ----------
11787          -- Page --
11788          ----------
11789
11790          --  pragma Page;
11791
11792          --  There is nothing to do here, since we did all the processing for
11793          --  this pragma in Par.Prag (so that it works properly even in syntax
11794          --  only mode).
11795
11796          when Pragma_Page =>
11797             null;
11798
11799          -------------
11800          -- Passive --
11801          -------------
11802
11803          --  pragma Passive [(PASSIVE_FORM)];
11804
11805          --  PASSIVE_FORM ::= Semaphore | No
11806
11807          when Pragma_Passive =>
11808             GNAT_Pragma;
11809
11810             if Nkind (Parent (N)) /= N_Task_Definition then
11811                Error_Pragma ("pragma% must be within task definition");
11812             end if;
11813
11814             if Arg_Count /= 0 then
11815                Check_Arg_Count (1);
11816                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11817             end if;
11818
11819          ----------------------------------
11820          -- Preelaborable_Initialization --
11821          ----------------------------------
11822
11823          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11824
11825          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11826             Ent : Entity_Id;
11827
11828          begin
11829             Ada_2005_Pragma;
11830             Check_Arg_Count (1);
11831             Check_No_Identifiers;
11832             Check_Arg_Is_Identifier (Arg1);
11833             Check_Arg_Is_Local_Name (Arg1);
11834             Check_First_Subtype (Arg1);
11835             Ent := Entity (Get_Pragma_Arg (Arg1));
11836
11837             if not (Is_Private_Type (Ent)
11838                       or else
11839                     Is_Protected_Type (Ent)
11840                       or else
11841                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11842             then
11843                Error_Pragma_Arg
11844                  ("pragma % can only be applied to private, formal derived or "
11845                   & "protected type",
11846                   Arg1);
11847             end if;
11848
11849             --  Give an error if the pragma is applied to a protected type that
11850             --  does not qualify (due to having entries, or due to components
11851             --  that do not qualify).
11852
11853             if Is_Protected_Type (Ent)
11854               and then not Has_Preelaborable_Initialization (Ent)
11855             then
11856                Error_Msg_N
11857                  ("protected type & does not have preelaborable " &
11858                   "initialization", Ent);
11859
11860             --  Otherwise mark the type as definitely having preelaborable
11861             --  initialization.
11862
11863             else
11864                Set_Known_To_Have_Preelab_Init (Ent);
11865             end if;
11866
11867             if Has_Pragma_Preelab_Init (Ent)
11868               and then Warn_On_Redundant_Constructs
11869             then
11870                Error_Pragma ("?duplicate pragma%!");
11871             else
11872                Set_Has_Pragma_Preelab_Init (Ent);
11873             end if;
11874          end Preelab_Init;
11875
11876          --------------------
11877          -- Persistent_BSS --
11878          --------------------
11879
11880          --  pragma Persistent_BSS [(object_NAME)];
11881
11882          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11883             Decl : Node_Id;
11884             Ent  : Entity_Id;
11885             Prag : Node_Id;
11886
11887          begin
11888             GNAT_Pragma;
11889             Check_At_Most_N_Arguments (1);
11890
11891             --  Case of application to specific object (one argument)
11892
11893             if Arg_Count = 1 then
11894                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11895
11896                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11897                  or else not
11898                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11899                                                             E_Constant)
11900                then
11901                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11902                end if;
11903
11904                Ent := Entity (Get_Pragma_Arg (Arg1));
11905                Decl := Parent (Ent);
11906
11907                if Rep_Item_Too_Late (Ent, N) then
11908                   return;
11909                end if;
11910
11911                if Present (Expression (Decl)) then
11912                   Error_Pragma_Arg
11913                     ("object for pragma% cannot have initialization", Arg1);
11914                end if;
11915
11916                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11917                   Error_Pragma_Arg
11918                     ("object type for pragma% is not potentially persistent",
11919                      Arg1);
11920                end if;
11921
11922                Check_Duplicate_Pragma (Ent);
11923
11924                Prag :=
11925                  Make_Linker_Section_Pragma
11926                    (Ent, Sloc (N), ".persistent.bss");
11927                Insert_After (N, Prag);
11928                Analyze (Prag);
11929
11930             --  Case of use as configuration pragma with no arguments
11931
11932             else
11933                Check_Valid_Configuration_Pragma;
11934                Persistent_BSS_Mode := True;
11935             end if;
11936          end Persistent_BSS;
11937
11938          -------------
11939          -- Polling --
11940          -------------
11941
11942          --  pragma Polling (ON | OFF);
11943
11944          when Pragma_Polling =>
11945             GNAT_Pragma;
11946             Check_Arg_Count (1);
11947             Check_No_Identifiers;
11948             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11949             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11950
11951          -------------------
11952          -- Postcondition --
11953          -------------------
11954
11955          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11956          --                      [,[Message =>] String_EXPRESSION]);
11957
11958          when Pragma_Postcondition => Postcondition : declare
11959             In_Body : Boolean;
11960             pragma Warnings (Off, In_Body);
11961
11962          begin
11963             GNAT_Pragma;
11964             Check_At_Least_N_Arguments (1);
11965             Check_At_Most_N_Arguments (2);
11966             Check_Optional_Identifier (Arg1, Name_Check);
11967
11968             --  All we need to do here is call the common check procedure,
11969             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11970
11971             Check_Precondition_Postcondition (In_Body);
11972          end Postcondition;
11973
11974          ------------------
11975          -- Precondition --
11976          ------------------
11977
11978          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11979          --                     [,[Message =>] String_EXPRESSION]);
11980
11981          when Pragma_Precondition => Precondition : declare
11982             In_Body : Boolean;
11983
11984          begin
11985             GNAT_Pragma;
11986             Check_At_Least_N_Arguments (1);
11987             Check_At_Most_N_Arguments (2);
11988             Check_Optional_Identifier (Arg1, Name_Check);
11989             Check_Precondition_Postcondition (In_Body);
11990
11991             --  If in spec, nothing more to do. If in body, then we convert the
11992             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11993             --  this whether or not precondition checks are enabled. That works
11994             --  fine since pragma Check will do this check, and will also
11995             --  analyze the condition itself in the proper context.
11996
11997             if In_Body then
11998                Rewrite (N,
11999                  Make_Pragma (Loc,
12000                    Chars => Name_Check,
12001                    Pragma_Argument_Associations => New_List (
12002                      Make_Pragma_Argument_Association (Loc,
12003                        Expression => Make_Identifier (Loc, Name_Precondition)),
12004
12005                      Make_Pragma_Argument_Association (Sloc (Arg1),
12006                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12007
12008                if Arg_Count = 2 then
12009                   Append_To (Pragma_Argument_Associations (N),
12010                     Make_Pragma_Argument_Association (Sloc (Arg2),
12011                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12012                end if;
12013
12014                Analyze (N);
12015             end if;
12016          end Precondition;
12017
12018          ---------------
12019          -- Predicate --
12020          ---------------
12021
12022          --  pragma Predicate
12023          --    ([Entity =>] type_LOCAL_NAME,
12024          --     [Check  =>] EXPRESSION);
12025
12026          when Pragma_Predicate => Predicate : declare
12027             Type_Id : Node_Id;
12028             Typ     : Entity_Id;
12029
12030             Discard : Boolean;
12031             pragma Unreferenced (Discard);
12032
12033          begin
12034             GNAT_Pragma;
12035             Check_Arg_Count (2);
12036             Check_Optional_Identifier (Arg1, Name_Entity);
12037             Check_Optional_Identifier (Arg2, Name_Check);
12038
12039             Check_Arg_Is_Local_Name (Arg1);
12040
12041             Type_Id := Get_Pragma_Arg (Arg1);
12042             Find_Type (Type_Id);
12043             Typ := Entity (Type_Id);
12044
12045             if Typ = Any_Type then
12046                return;
12047             end if;
12048
12049             --  The remaining processing is simply to link the pragma on to
12050             --  the rep item chain, for processing when the type is frozen.
12051             --  This is accomplished by a call to Rep_Item_Too_Late. We also
12052             --  mark the type as having predicates.
12053
12054             Set_Has_Predicates (Typ);
12055             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12056          end Predicate;
12057
12058          ------------------
12059          -- Preelaborate --
12060          ------------------
12061
12062          --  pragma Preelaborate [(library_unit_NAME)];
12063
12064          --  Set the flag Is_Preelaborated of program unit name entity
12065
12066          when Pragma_Preelaborate => Preelaborate : declare
12067             Pa  : constant Node_Id   := Parent (N);
12068             Pk  : constant Node_Kind := Nkind (Pa);
12069             Ent : Entity_Id;
12070
12071          begin
12072             Check_Ada_83_Warning;
12073             Check_Valid_Library_Unit_Pragma;
12074
12075             if Nkind (N) = N_Null_Statement then
12076                return;
12077             end if;
12078
12079             Ent := Find_Lib_Unit_Name;
12080             Check_Duplicate_Pragma (Ent);
12081
12082             --  This filters out pragmas inside generic parent then
12083             --  show up inside instantiation
12084
12085             if Present (Ent)
12086               and then not (Pk = N_Package_Specification
12087                              and then Present (Generic_Parent (Pa)))
12088             then
12089                if not Debug_Flag_U then
12090                   Set_Is_Preelaborated (Ent);
12091                   Set_Suppress_Elaboration_Warnings (Ent);
12092                end if;
12093             end if;
12094          end Preelaborate;
12095
12096          ---------------------
12097          -- Preelaborate_05 --
12098          ---------------------
12099
12100          --  pragma Preelaborate_05 [(library_unit_NAME)];
12101
12102          --  This pragma is useable only in GNAT_Mode, where it is used like
12103          --  pragma Preelaborate but it is only effective in Ada 2005 mode
12104          --  (otherwise it is ignored). This is used to implement AI-362 which
12105          --  recategorizes some run-time packages in Ada 2005 mode.
12106
12107          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12108             Ent : Entity_Id;
12109
12110          begin
12111             GNAT_Pragma;
12112             Check_Valid_Library_Unit_Pragma;
12113
12114             if not GNAT_Mode then
12115                Error_Pragma ("pragma% only available in GNAT mode");
12116             end if;
12117
12118             if Nkind (N) = N_Null_Statement then
12119                return;
12120             end if;
12121
12122             --  This is one of the few cases where we need to test the value of
12123             --  Ada_Version_Explicit rather than Ada_Version (which is always
12124             --  set to Ada_2012 in a predefined unit), we need to know the
12125             --  explicit version set to know if this pragma is active.
12126
12127             if Ada_Version_Explicit >= Ada_2005 then
12128                Ent := Find_Lib_Unit_Name;
12129                Set_Is_Preelaborated (Ent);
12130                Set_Suppress_Elaboration_Warnings (Ent);
12131             end if;
12132          end Preelaborate_05;
12133
12134          --------------
12135          -- Priority --
12136          --------------
12137
12138          --  pragma Priority (EXPRESSION);
12139
12140          when Pragma_Priority => Priority : declare
12141             P   : constant Node_Id := Parent (N);
12142             Arg : Node_Id;
12143
12144          begin
12145             Check_No_Identifiers;
12146             Check_Arg_Count (1);
12147
12148             --  Subprogram case
12149
12150             if Nkind (P) = N_Subprogram_Body then
12151                Check_In_Main_Program;
12152
12153                Arg := Get_Pragma_Arg (Arg1);
12154                Analyze_And_Resolve (Arg, Standard_Integer);
12155
12156                --  Must be static
12157
12158                if not Is_Static_Expression (Arg) then
12159                   Flag_Non_Static_Expr
12160                     ("main subprogram priority is not static!", Arg);
12161                   raise Pragma_Exit;
12162
12163                --  If constraint error, then we already signalled an error
12164
12165                elsif Raises_Constraint_Error (Arg) then
12166                   null;
12167
12168                --  Otherwise check in range
12169
12170                else
12171                   declare
12172                      Val : constant Uint := Expr_Value (Arg);
12173
12174                   begin
12175                      if Val < 0
12176                        or else Val > Expr_Value (Expression
12177                                        (Parent (RTE (RE_Max_Priority))))
12178                      then
12179                         Error_Pragma_Arg
12180                           ("main subprogram priority is out of range", Arg1);
12181                      end if;
12182                   end;
12183                end if;
12184
12185                Set_Main_Priority
12186                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12187
12188                --  Load an arbitrary entity from System.Tasking to make sure
12189                --  this package is implicitly with'ed, since we need to have
12190                --  the tasking run-time active for the pragma Priority to have
12191                --  any effect.
12192
12193                declare
12194                   Discard : Entity_Id;
12195                   pragma Warnings (Off, Discard);
12196                begin
12197                   Discard := RTE (RE_Task_List);
12198                end;
12199
12200             --  Task or Protected, must be of type Integer
12201
12202             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12203                Arg := Get_Pragma_Arg (Arg1);
12204
12205                --  The expression must be analyzed in the special manner
12206                --  described in "Handling of Default and Per-Object
12207                --  Expressions" in sem.ads.
12208
12209                Preanalyze_Spec_Expression (Arg, Standard_Integer);
12210
12211                if not Is_Static_Expression (Arg) then
12212                   Check_Restriction (Static_Priorities, Arg);
12213                end if;
12214
12215             --  Anything else is incorrect
12216
12217             else
12218                Pragma_Misplaced;
12219             end if;
12220
12221             if Has_Pragma_Priority (P) then
12222                Error_Pragma ("duplicate pragma% not allowed");
12223             else
12224                Set_Has_Pragma_Priority (P, True);
12225
12226                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12227                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12228                   --  exp_ch9 should use this ???
12229                end if;
12230             end if;
12231          end Priority;
12232
12233          -----------------------------------
12234          -- Priority_Specific_Dispatching --
12235          -----------------------------------
12236
12237          --  pragma Priority_Specific_Dispatching (
12238          --    policy_IDENTIFIER,
12239          --    first_priority_EXPRESSION,
12240          --    last_priority_EXPRESSION);
12241
12242          when Pragma_Priority_Specific_Dispatching =>
12243          Priority_Specific_Dispatching : declare
12244             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12245             --  This is the entity System.Any_Priority;
12246
12247             DP          : Character;
12248             Lower_Bound : Node_Id;
12249             Upper_Bound : Node_Id;
12250             Lower_Val   : Uint;
12251             Upper_Val   : Uint;
12252
12253          begin
12254             Ada_2005_Pragma;
12255             Check_Arg_Count (3);
12256             Check_No_Identifiers;
12257             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12258             Check_Valid_Configuration_Pragma;
12259             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12260             DP := Fold_Upper (Name_Buffer (1));
12261
12262             Lower_Bound := Get_Pragma_Arg (Arg2);
12263             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12264             Lower_Val := Expr_Value (Lower_Bound);
12265
12266             Upper_Bound := Get_Pragma_Arg (Arg3);
12267             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12268             Upper_Val := Expr_Value (Upper_Bound);
12269
12270             --  It is not allowed to use Task_Dispatching_Policy and
12271             --  Priority_Specific_Dispatching in the same partition.
12272
12273             if Task_Dispatching_Policy /= ' ' then
12274                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12275                Error_Pragma
12276                  ("pragma% incompatible with Task_Dispatching_Policy#");
12277
12278             --  Check lower bound in range
12279
12280             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12281                     or else
12282                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12283             then
12284                Error_Pragma_Arg
12285                  ("first_priority is out of range", Arg2);
12286
12287             --  Check upper bound in range
12288
12289             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12290                     or else
12291                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12292             then
12293                Error_Pragma_Arg
12294                  ("last_priority is out of range", Arg3);
12295
12296             --  Check that the priority range is valid
12297
12298             elsif Lower_Val > Upper_Val then
12299                Error_Pragma
12300                  ("last_priority_expression must be greater than" &
12301                   " or equal to first_priority_expression");
12302
12303             --  Store the new policy, but always preserve System_Location since
12304             --  we like the error message with the run-time name.
12305
12306             else
12307                --  Check overlapping in the priority ranges specified in other
12308                --  Priority_Specific_Dispatching pragmas within the same
12309                --  partition. We can only check those we know about!
12310
12311                for J in
12312                   Specific_Dispatching.First .. Specific_Dispatching.Last
12313                loop
12314                   if Specific_Dispatching.Table (J).First_Priority in
12315                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12316                   or else Specific_Dispatching.Table (J).Last_Priority in
12317                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12318                   then
12319                      Error_Msg_Sloc :=
12320                        Specific_Dispatching.Table (J).Pragma_Loc;
12321                         Error_Pragma
12322                           ("priority range overlaps with "
12323                            & "Priority_Specific_Dispatching#");
12324                   end if;
12325                end loop;
12326
12327                --  The use of Priority_Specific_Dispatching is incompatible
12328                --  with Task_Dispatching_Policy.
12329
12330                if Task_Dispatching_Policy /= ' ' then
12331                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12332                      Error_Pragma
12333                        ("Priority_Specific_Dispatching incompatible "
12334                         & "with Task_Dispatching_Policy#");
12335                end if;
12336
12337                --  The use of Priority_Specific_Dispatching forces ceiling
12338                --  locking policy.
12339
12340                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12341                   Error_Msg_Sloc := Locking_Policy_Sloc;
12342                      Error_Pragma
12343                        ("Priority_Specific_Dispatching incompatible "
12344                         & "with Locking_Policy#");
12345
12346                --  Set the Ceiling_Locking policy, but preserve System_Location
12347                --  since we like the error message with the run time name.
12348
12349                else
12350                   Locking_Policy := 'C';
12351
12352                   if Locking_Policy_Sloc /= System_Location then
12353                      Locking_Policy_Sloc := Loc;
12354                   end if;
12355                end if;
12356
12357                --  Add entry in the table
12358
12359                Specific_Dispatching.Append
12360                     ((Dispatching_Policy => DP,
12361                       First_Priority     => UI_To_Int (Lower_Val),
12362                       Last_Priority      => UI_To_Int (Upper_Val),
12363                       Pragma_Loc         => Loc));
12364             end if;
12365          end Priority_Specific_Dispatching;
12366
12367          -------------
12368          -- Profile --
12369          -------------
12370
12371          --  pragma Profile (profile_IDENTIFIER);
12372
12373          --  profile_IDENTIFIER => Restricted | Ravenscar
12374
12375          when Pragma_Profile =>
12376             Ada_2005_Pragma;
12377             Check_Arg_Count (1);
12378             Check_Valid_Configuration_Pragma;
12379             Check_No_Identifiers;
12380
12381             declare
12382                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12383
12384             begin
12385                if Chars (Argx) = Name_Ravenscar then
12386                   Set_Ravenscar_Profile (N);
12387
12388                elsif Chars (Argx) = Name_Restricted then
12389                   Set_Profile_Restrictions
12390                     (Restricted,
12391                      N, Warn => Treat_Restrictions_As_Warnings);
12392
12393                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12394                   Set_Profile_Restrictions
12395                     (No_Implementation_Extensions,
12396                      N, Warn => Treat_Restrictions_As_Warnings);
12397
12398                else
12399                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12400                end if;
12401             end;
12402
12403          ----------------------
12404          -- Profile_Warnings --
12405          ----------------------
12406
12407          --  pragma Profile_Warnings (profile_IDENTIFIER);
12408
12409          --  profile_IDENTIFIER => Restricted | Ravenscar
12410
12411          when Pragma_Profile_Warnings =>
12412             GNAT_Pragma;
12413             Check_Arg_Count (1);
12414             Check_Valid_Configuration_Pragma;
12415             Check_No_Identifiers;
12416
12417             declare
12418                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12419
12420             begin
12421                if Chars (Argx) = Name_Ravenscar then
12422                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12423
12424                elsif Chars (Argx) = Name_Restricted then
12425                   Set_Profile_Restrictions (Restricted, N, Warn => True);
12426
12427                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12428                   Set_Profile_Restrictions
12429                     (No_Implementation_Extensions, N, Warn => True);
12430
12431                else
12432                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12433                end if;
12434             end;
12435
12436          --------------------------
12437          -- Propagate_Exceptions --
12438          --------------------------
12439
12440          --  pragma Propagate_Exceptions;
12441
12442          --  Note: this pragma is obsolete and has no effect
12443
12444          when Pragma_Propagate_Exceptions =>
12445             GNAT_Pragma;
12446             Check_Arg_Count (0);
12447
12448             if In_Extended_Main_Source_Unit (N) then
12449                Propagate_Exceptions := True;
12450             end if;
12451
12452          ------------------
12453          -- Psect_Object --
12454          ------------------
12455
12456          --  pragma Psect_Object (
12457          --        [Internal =>] LOCAL_NAME,
12458          --     [, [External =>] EXTERNAL_SYMBOL]
12459          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12460
12461          when Pragma_Psect_Object | Pragma_Common_Object =>
12462          Psect_Object : declare
12463             Args  : Args_List (1 .. 3);
12464             Names : constant Name_List (1 .. 3) := (
12465                       Name_Internal,
12466                       Name_External,
12467                       Name_Size);
12468
12469             Internal : Node_Id renames Args (1);
12470             External : Node_Id renames Args (2);
12471             Size     : Node_Id renames Args (3);
12472
12473             Def_Id : Entity_Id;
12474
12475             procedure Check_Too_Long (Arg : Node_Id);
12476             --  Posts message if the argument is an identifier with more
12477             --  than 31 characters, or a string literal with more than
12478             --  31 characters, and we are operating under VMS
12479
12480             --------------------
12481             -- Check_Too_Long --
12482             --------------------
12483
12484             procedure Check_Too_Long (Arg : Node_Id) is
12485                X : constant Node_Id := Original_Node (Arg);
12486
12487             begin
12488                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12489                   Error_Pragma_Arg
12490                     ("inappropriate argument for pragma %", Arg);
12491                end if;
12492
12493                if OpenVMS_On_Target then
12494                   if (Nkind (X) = N_String_Literal
12495                        and then String_Length (Strval (X)) > 31)
12496                     or else
12497                      (Nkind (X) = N_Identifier
12498                        and then Length_Of_Name (Chars (X)) > 31)
12499                   then
12500                      Error_Pragma_Arg
12501                        ("argument for pragma % is longer than 31 characters",
12502                         Arg);
12503                   end if;
12504                end if;
12505             end Check_Too_Long;
12506
12507          --  Start of processing for Common_Object/Psect_Object
12508
12509          begin
12510             GNAT_Pragma;
12511             Gather_Associations (Names, Args);
12512             Process_Extended_Import_Export_Internal_Arg (Internal);
12513
12514             Def_Id := Entity (Internal);
12515
12516             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12517                Error_Pragma_Arg
12518                  ("pragma% must designate an object", Internal);
12519             end if;
12520
12521             Check_Too_Long (Internal);
12522
12523             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12524                Error_Pragma_Arg
12525                  ("cannot use pragma% for imported/exported object",
12526                   Internal);
12527             end if;
12528
12529             if Is_Concurrent_Type (Etype (Internal)) then
12530                Error_Pragma_Arg
12531                  ("cannot specify pragma % for task/protected object",
12532                   Internal);
12533             end if;
12534
12535             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12536                  or else
12537                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12538             then
12539                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12540             end if;
12541
12542             if Ekind (Def_Id) = E_Constant then
12543                Error_Pragma_Arg
12544                  ("cannot specify pragma % for a constant", Internal);
12545             end if;
12546
12547             if Is_Record_Type (Etype (Internal)) then
12548                declare
12549                   Ent  : Entity_Id;
12550                   Decl : Entity_Id;
12551
12552                begin
12553                   Ent := First_Entity (Etype (Internal));
12554                   while Present (Ent) loop
12555                      Decl := Declaration_Node (Ent);
12556
12557                      if Ekind (Ent) = E_Component
12558                        and then Nkind (Decl) = N_Component_Declaration
12559                        and then Present (Expression (Decl))
12560                        and then Warn_On_Export_Import
12561                      then
12562                         Error_Msg_N
12563                           ("?object for pragma % has defaults", Internal);
12564                         exit;
12565
12566                      else
12567                         Next_Entity (Ent);
12568                      end if;
12569                   end loop;
12570                end;
12571             end if;
12572
12573             if Present (Size) then
12574                Check_Too_Long (Size);
12575             end if;
12576
12577             if Present (External) then
12578                Check_Arg_Is_External_Name (External);
12579                Check_Too_Long (External);
12580             end if;
12581
12582             --  If all error tests pass, link pragma on to the rep item chain
12583
12584             Record_Rep_Item (Def_Id, N);
12585          end Psect_Object;
12586
12587          ----------
12588          -- Pure --
12589          ----------
12590
12591          --  pragma Pure [(library_unit_NAME)];
12592
12593          when Pragma_Pure => Pure : declare
12594             Ent : Entity_Id;
12595
12596          begin
12597             Check_Ada_83_Warning;
12598             Check_Valid_Library_Unit_Pragma;
12599
12600             if Nkind (N) = N_Null_Statement then
12601                return;
12602             end if;
12603
12604             Ent := Find_Lib_Unit_Name;
12605             Set_Is_Pure (Ent);
12606             Set_Has_Pragma_Pure (Ent);
12607             Set_Suppress_Elaboration_Warnings (Ent);
12608          end Pure;
12609
12610          -------------
12611          -- Pure_05 --
12612          -------------
12613
12614          --  pragma Pure_05 [(library_unit_NAME)];
12615
12616          --  This pragma is useable only in GNAT_Mode, where it is used like
12617          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12618          --  it is ignored). It may be used after a pragma Preelaborate, in
12619          --  which case it overrides the effect of the pragma Preelaborate.
12620          --  This is used to implement AI-362 which recategorizes some run-time
12621          --  packages in Ada 2005 mode.
12622
12623          when Pragma_Pure_05 => Pure_05 : declare
12624             Ent : Entity_Id;
12625
12626          begin
12627             GNAT_Pragma;
12628             Check_Valid_Library_Unit_Pragma;
12629
12630             if not GNAT_Mode then
12631                Error_Pragma ("pragma% only available in GNAT mode");
12632             end if;
12633
12634             if Nkind (N) = N_Null_Statement then
12635                return;
12636             end if;
12637
12638             --  This is one of the few cases where we need to test the value of
12639             --  Ada_Version_Explicit rather than Ada_Version (which is always
12640             --  set to Ada_2012 in a predefined unit), we need to know the
12641             --  explicit version set to know if this pragma is active.
12642
12643             if Ada_Version_Explicit >= Ada_2005 then
12644                Ent := Find_Lib_Unit_Name;
12645                Set_Is_Preelaborated (Ent, False);
12646                Set_Is_Pure (Ent);
12647                Set_Suppress_Elaboration_Warnings (Ent);
12648             end if;
12649          end Pure_05;
12650
12651          -------------
12652          -- Pure_12 --
12653          -------------
12654
12655          --  pragma Pure_12 [(library_unit_NAME)];
12656
12657          --  This pragma is useable only in GNAT_Mode, where it is used like
12658          --  pragma Pure but it is only effective in Ada 2012 mode (otherwise
12659          --  it is ignored). It may be used after a pragma Preelaborate, in
12660          --  which case it overrides the effect of the pragma Preelaborate.
12661          --  This is used to implement AI05-0212 which recategorizes some
12662          --  run-time packages in Ada 2012 mode.
12663
12664          when Pragma_Pure_12 => Pure_12 : declare
12665             Ent : Entity_Id;
12666
12667          begin
12668             GNAT_Pragma;
12669             Check_Valid_Library_Unit_Pragma;
12670
12671             if not GNAT_Mode then
12672                Error_Pragma ("pragma% only available in GNAT mode");
12673             end if;
12674
12675             if Nkind (N) = N_Null_Statement then
12676                return;
12677             end if;
12678
12679             --  This is one of the few cases where we need to test the value of
12680             --  Ada_Version_Explicit rather than Ada_Version (which is always
12681             --  set to Ada_2012 in a predefined unit), we need to know the
12682             --  explicit version set to know if this pragma is active.
12683
12684             if Ada_Version_Explicit >= Ada_2012 then
12685                Ent := Find_Lib_Unit_Name;
12686                Set_Is_Preelaborated (Ent, False);
12687                Set_Is_Pure (Ent);
12688                Set_Suppress_Elaboration_Warnings (Ent);
12689             end if;
12690          end Pure_12;
12691
12692          -------------------
12693          -- Pure_Function --
12694          -------------------
12695
12696          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12697
12698          when Pragma_Pure_Function => Pure_Function : declare
12699             E_Id      : Node_Id;
12700             E         : Entity_Id;
12701             Def_Id    : Entity_Id;
12702             Effective : Boolean := False;
12703
12704          begin
12705             GNAT_Pragma;
12706             Check_Arg_Count (1);
12707             Check_Optional_Identifier (Arg1, Name_Entity);
12708             Check_Arg_Is_Local_Name (Arg1);
12709             E_Id := Get_Pragma_Arg (Arg1);
12710
12711             if Error_Posted (E_Id) then
12712                return;
12713             end if;
12714
12715             --  Loop through homonyms (overloadings) of referenced entity
12716
12717             E := Entity (E_Id);
12718
12719             if Present (E) then
12720                loop
12721                   Def_Id := Get_Base_Subprogram (E);
12722
12723                   if not Ekind_In (Def_Id, E_Function,
12724                                            E_Generic_Function,
12725                                            E_Operator)
12726                   then
12727                      Error_Pragma_Arg
12728                        ("pragma% requires a function name", Arg1);
12729                   end if;
12730
12731                   Set_Is_Pure (Def_Id);
12732
12733                   if not Has_Pragma_Pure_Function (Def_Id) then
12734                      Set_Has_Pragma_Pure_Function (Def_Id);
12735                      Effective := True;
12736                   end if;
12737
12738                   exit when From_Aspect_Specification (N);
12739                   E := Homonym (E);
12740                   exit when No (E) or else Scope (E) /= Current_Scope;
12741                end loop;
12742
12743                if not Effective
12744                  and then Warn_On_Redundant_Constructs
12745                then
12746                   Error_Msg_NE
12747                     ("pragma Pure_Function on& is redundant?",
12748                      N, Entity (E_Id));
12749                end if;
12750             end if;
12751          end Pure_Function;
12752
12753          --------------------
12754          -- Queuing_Policy --
12755          --------------------
12756
12757          --  pragma Queuing_Policy (policy_IDENTIFIER);
12758
12759          when Pragma_Queuing_Policy => declare
12760             QP : Character;
12761
12762          begin
12763             Check_Ada_83_Warning;
12764             Check_Arg_Count (1);
12765             Check_No_Identifiers;
12766             Check_Arg_Is_Queuing_Policy (Arg1);
12767             Check_Valid_Configuration_Pragma;
12768             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12769             QP := Fold_Upper (Name_Buffer (1));
12770
12771             if Queuing_Policy /= ' '
12772               and then Queuing_Policy /= QP
12773             then
12774                Error_Msg_Sloc := Queuing_Policy_Sloc;
12775                Error_Pragma ("queuing policy incompatible with policy#");
12776
12777             --  Set new policy, but always preserve System_Location since we
12778             --  like the error message with the run time name.
12779
12780             else
12781                Queuing_Policy := QP;
12782
12783                if Queuing_Policy_Sloc /= System_Location then
12784                   Queuing_Policy_Sloc := Loc;
12785                end if;
12786             end if;
12787          end;
12788
12789          -----------------------
12790          -- Relative_Deadline --
12791          -----------------------
12792
12793          --  pragma Relative_Deadline (time_span_EXPRESSION);
12794
12795          when Pragma_Relative_Deadline => Relative_Deadline : declare
12796             P   : constant Node_Id := Parent (N);
12797             Arg : Node_Id;
12798
12799          begin
12800             Ada_2005_Pragma;
12801             Check_No_Identifiers;
12802             Check_Arg_Count (1);
12803
12804             Arg := Get_Pragma_Arg (Arg1);
12805
12806             --  The expression must be analyzed in the special manner described
12807             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12808
12809             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12810
12811             --  Subprogram case
12812
12813             if Nkind (P) = N_Subprogram_Body then
12814                Check_In_Main_Program;
12815
12816             --  Tasks
12817
12818             elsif Nkind (P) = N_Task_Definition then
12819                null;
12820
12821             --  Anything else is incorrect
12822
12823             else
12824                Pragma_Misplaced;
12825             end if;
12826
12827             if Has_Relative_Deadline_Pragma (P) then
12828                Error_Pragma ("duplicate pragma% not allowed");
12829             else
12830                Set_Has_Relative_Deadline_Pragma (P, True);
12831
12832                if Nkind (P) = N_Task_Definition then
12833                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12834                end if;
12835             end if;
12836          end Relative_Deadline;
12837
12838          ---------------------------
12839          -- Remote_Call_Interface --
12840          ---------------------------
12841
12842          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12843
12844          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12845             Cunit_Node : Node_Id;
12846             Cunit_Ent  : Entity_Id;
12847             K          : Node_Kind;
12848
12849          begin
12850             Check_Ada_83_Warning;
12851             Check_Valid_Library_Unit_Pragma;
12852
12853             if Nkind (N) = N_Null_Statement then
12854                return;
12855             end if;
12856
12857             Cunit_Node := Cunit (Current_Sem_Unit);
12858             K          := Nkind (Unit (Cunit_Node));
12859             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12860
12861             if K = N_Package_Declaration
12862               or else K = N_Generic_Package_Declaration
12863               or else K = N_Subprogram_Declaration
12864               or else K = N_Generic_Subprogram_Declaration
12865               or else (K = N_Subprogram_Body
12866                          and then Acts_As_Spec (Unit (Cunit_Node)))
12867             then
12868                null;
12869             else
12870                Error_Pragma (
12871                  "pragma% must apply to package or subprogram declaration");
12872             end if;
12873
12874             Set_Is_Remote_Call_Interface (Cunit_Ent);
12875          end Remote_Call_Interface;
12876
12877          ------------------
12878          -- Remote_Types --
12879          ------------------
12880
12881          --  pragma Remote_Types [(library_unit_NAME)];
12882
12883          when Pragma_Remote_Types => Remote_Types : declare
12884             Cunit_Node : Node_Id;
12885             Cunit_Ent  : Entity_Id;
12886
12887          begin
12888             Check_Ada_83_Warning;
12889             Check_Valid_Library_Unit_Pragma;
12890
12891             if Nkind (N) = N_Null_Statement then
12892                return;
12893             end if;
12894
12895             Cunit_Node := Cunit (Current_Sem_Unit);
12896             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12897
12898             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12899                                                 N_Generic_Package_Declaration)
12900             then
12901                Error_Pragma
12902                  ("pragma% can only apply to a package declaration");
12903             end if;
12904
12905             Set_Is_Remote_Types (Cunit_Ent);
12906          end Remote_Types;
12907
12908          ---------------
12909          -- Ravenscar --
12910          ---------------
12911
12912          --  pragma Ravenscar;
12913
12914          when Pragma_Ravenscar =>
12915             GNAT_Pragma;
12916             Check_Arg_Count (0);
12917             Check_Valid_Configuration_Pragma;
12918             Set_Ravenscar_Profile (N);
12919
12920             if Warn_On_Obsolescent_Feature then
12921                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12922                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12923             end if;
12924
12925          -------------------------
12926          -- Restricted_Run_Time --
12927          -------------------------
12928
12929          --  pragma Restricted_Run_Time;
12930
12931          when Pragma_Restricted_Run_Time =>
12932             GNAT_Pragma;
12933             Check_Arg_Count (0);
12934             Check_Valid_Configuration_Pragma;
12935             Set_Profile_Restrictions
12936               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12937
12938             if Warn_On_Obsolescent_Feature then
12939                Error_Msg_N
12940                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12941                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12942             end if;
12943
12944          ------------------
12945          -- Restrictions --
12946          ------------------
12947
12948          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12949
12950          --  RESTRICTION ::=
12951          --    restriction_IDENTIFIER
12952          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12953
12954          when Pragma_Restrictions =>
12955             Process_Restrictions_Or_Restriction_Warnings
12956               (Warn => Treat_Restrictions_As_Warnings);
12957
12958          --------------------------
12959          -- Restriction_Warnings --
12960          --------------------------
12961
12962          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12963
12964          --  RESTRICTION ::=
12965          --    restriction_IDENTIFIER
12966          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12967
12968          when Pragma_Restriction_Warnings =>
12969             GNAT_Pragma;
12970             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12971
12972          ----------------
12973          -- Reviewable --
12974          ----------------
12975
12976          --  pragma Reviewable;
12977
12978          when Pragma_Reviewable =>
12979             Check_Ada_83_Warning;
12980             Check_Arg_Count (0);
12981
12982             --  Call dummy debugging function rv. This is done to assist front
12983             --  end debugging. By placing a Reviewable pragma in the source
12984             --  program, a breakpoint on rv catches this place in the source,
12985             --  allowing convenient stepping to the point of interest.
12986
12987             rv;
12988
12989          --------------------------
12990          -- Short_Circuit_And_Or --
12991          --------------------------
12992
12993          when Pragma_Short_Circuit_And_Or =>
12994             GNAT_Pragma;
12995             Check_Arg_Count (0);
12996             Check_Valid_Configuration_Pragma;
12997             Short_Circuit_And_Or := True;
12998
12999          -------------------
13000          -- Share_Generic --
13001          -------------------
13002
13003          --  pragma Share_Generic (NAME {, NAME});
13004
13005          when Pragma_Share_Generic =>
13006             GNAT_Pragma;
13007             Process_Generic_List;
13008
13009          ------------
13010          -- Shared --
13011          ------------
13012
13013          --  pragma Shared (LOCAL_NAME);
13014
13015          when Pragma_Shared =>
13016             GNAT_Pragma;
13017             Process_Atomic_Shared_Volatile;
13018
13019          --------------------
13020          -- Shared_Passive --
13021          --------------------
13022
13023          --  pragma Shared_Passive [(library_unit_NAME)];
13024
13025          --  Set the flag Is_Shared_Passive of program unit name entity
13026
13027          when Pragma_Shared_Passive => Shared_Passive : declare
13028             Cunit_Node : Node_Id;
13029             Cunit_Ent  : Entity_Id;
13030
13031          begin
13032             Check_Ada_83_Warning;
13033             Check_Valid_Library_Unit_Pragma;
13034
13035             if Nkind (N) = N_Null_Statement then
13036                return;
13037             end if;
13038
13039             Cunit_Node := Cunit (Current_Sem_Unit);
13040             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
13041
13042             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13043                                                 N_Generic_Package_Declaration)
13044             then
13045                Error_Pragma
13046                  ("pragma% can only apply to a package declaration");
13047             end if;
13048
13049             Set_Is_Shared_Passive (Cunit_Ent);
13050          end Shared_Passive;
13051
13052          -----------------------
13053          -- Short_Descriptors --
13054          -----------------------
13055
13056          --  pragma Short_Descriptors;
13057
13058          when Pragma_Short_Descriptors =>
13059             GNAT_Pragma;
13060             Check_Arg_Count (0);
13061             Check_Valid_Configuration_Pragma;
13062             Short_Descriptors := True;
13063
13064          ----------------------
13065          -- Source_File_Name --
13066          ----------------------
13067
13068          --  There are five forms for this pragma:
13069
13070          --  pragma Source_File_Name (
13071          --    [UNIT_NAME      =>] unit_NAME,
13072          --     BODY_FILE_NAME =>  STRING_LITERAL
13073          --    [, [INDEX =>] INTEGER_LITERAL]);
13074
13075          --  pragma Source_File_Name (
13076          --    [UNIT_NAME      =>] unit_NAME,
13077          --     SPEC_FILE_NAME =>  STRING_LITERAL
13078          --    [, [INDEX =>] INTEGER_LITERAL]);
13079
13080          --  pragma Source_File_Name (
13081          --     BODY_FILE_NAME  => STRING_LITERAL
13082          --  [, DOT_REPLACEMENT => STRING_LITERAL]
13083          --  [, CASING          => CASING_SPEC]);
13084
13085          --  pragma Source_File_Name (
13086          --     SPEC_FILE_NAME  => STRING_LITERAL
13087          --  [, DOT_REPLACEMENT => STRING_LITERAL]
13088          --  [, CASING          => CASING_SPEC]);
13089
13090          --  pragma Source_File_Name (
13091          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
13092          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
13093          --  [, CASING             => CASING_SPEC]);
13094
13095          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13096
13097          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13098          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
13099          --  only be used when no project file is used, while SFNP can only be
13100          --  used when a project file is used.
13101
13102          --  No processing here. Processing was completed during parsing, since
13103          --  we need to have file names set as early as possible. Units are
13104          --  loaded well before semantic processing starts.
13105
13106          --  The only processing we defer to this point is the check for
13107          --  correct placement.
13108
13109          when Pragma_Source_File_Name =>
13110             GNAT_Pragma;
13111             Check_Valid_Configuration_Pragma;
13112
13113          ------------------------------
13114          -- Source_File_Name_Project --
13115          ------------------------------
13116
13117          --  See Source_File_Name for syntax
13118
13119          --  No processing here. Processing was completed during parsing, since
13120          --  we need to have file names set as early as possible. Units are
13121          --  loaded well before semantic processing starts.
13122
13123          --  The only processing we defer to this point is the check for
13124          --  correct placement.
13125
13126          when Pragma_Source_File_Name_Project =>
13127             GNAT_Pragma;
13128             Check_Valid_Configuration_Pragma;
13129
13130             --  Check that a pragma Source_File_Name_Project is used only in a
13131             --  configuration pragmas file.
13132
13133             --  Pragmas Source_File_Name_Project should only be generated by
13134             --  the Project Manager in configuration pragmas files.
13135
13136             --  This is really an ugly test. It seems to depend on some
13137             --  accidental and undocumented property. At the very least it
13138             --  needs to be documented, but it would be better to have a
13139             --  clean way of testing if we are in a configuration file???
13140
13141             if Present (Parent (N)) then
13142                Error_Pragma
13143                  ("pragma% can only appear in a configuration pragmas file");
13144             end if;
13145
13146          ----------------------
13147          -- Source_Reference --
13148          ----------------------
13149
13150          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13151
13152          --  Nothing to do, all processing completed in Par.Prag, since we need
13153          --  the information for possible parser messages that are output.
13154
13155          when Pragma_Source_Reference =>
13156             GNAT_Pragma;
13157
13158          --------------------------------
13159          -- Static_Elaboration_Desired --
13160          --------------------------------
13161
13162          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
13163
13164          when Pragma_Static_Elaboration_Desired =>
13165             GNAT_Pragma;
13166             Check_At_Most_N_Arguments (1);
13167
13168             if Is_Compilation_Unit (Current_Scope)
13169               and then Ekind (Current_Scope) = E_Package
13170             then
13171                Set_Static_Elaboration_Desired (Current_Scope, True);
13172             else
13173                Error_Pragma ("pragma% must apply to a library-level package");
13174             end if;
13175
13176          ------------------
13177          -- Storage_Size --
13178          ------------------
13179
13180          --  pragma Storage_Size (EXPRESSION);
13181
13182          when Pragma_Storage_Size => Storage_Size : declare
13183             P   : constant Node_Id := Parent (N);
13184             Arg : Node_Id;
13185
13186          begin
13187             Check_No_Identifiers;
13188             Check_Arg_Count (1);
13189
13190             --  The expression must be analyzed in the special manner described
13191             --  in "Handling of Default Expressions" in sem.ads.
13192
13193             Arg := Get_Pragma_Arg (Arg1);
13194             Preanalyze_Spec_Expression (Arg, Any_Integer);
13195
13196             if not Is_Static_Expression (Arg) then
13197                Check_Restriction (Static_Storage_Size, Arg);
13198             end if;
13199
13200             if Nkind (P) /= N_Task_Definition then
13201                Pragma_Misplaced;
13202                return;
13203
13204             else
13205                if Has_Storage_Size_Pragma (P) then
13206                   Error_Pragma ("duplicate pragma% not allowed");
13207                else
13208                   Set_Has_Storage_Size_Pragma (P, True);
13209                end if;
13210
13211                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13212                --  ???  exp_ch9 should use this!
13213             end if;
13214          end Storage_Size;
13215
13216          ------------------
13217          -- Storage_Unit --
13218          ------------------
13219
13220          --  pragma Storage_Unit (NUMERIC_LITERAL);
13221
13222          --  Only permitted argument is System'Storage_Unit value
13223
13224          when Pragma_Storage_Unit =>
13225             Check_No_Identifiers;
13226             Check_Arg_Count (1);
13227             Check_Arg_Is_Integer_Literal (Arg1);
13228
13229             if Intval (Get_Pragma_Arg (Arg1)) /=
13230               UI_From_Int (Ttypes.System_Storage_Unit)
13231             then
13232                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13233                Error_Pragma_Arg
13234                  ("the only allowed argument for pragma% is ^", Arg1);
13235             end if;
13236
13237          --------------------
13238          -- Stream_Convert --
13239          --------------------
13240
13241          --  pragma Stream_Convert (
13242          --    [Entity =>] type_LOCAL_NAME,
13243          --    [Read   =>] function_NAME,
13244          --    [Write  =>] function NAME);
13245
13246          when Pragma_Stream_Convert => Stream_Convert : declare
13247
13248             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13249             --  Check that the given argument is the name of a local function
13250             --  of one argument that is not overloaded earlier in the current
13251             --  local scope. A check is also made that the argument is a
13252             --  function with one parameter.
13253
13254             --------------------------------------
13255             -- Check_OK_Stream_Convert_Function --
13256             --------------------------------------
13257
13258             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13259                Ent : Entity_Id;
13260
13261             begin
13262                Check_Arg_Is_Local_Name (Arg);
13263                Ent := Entity (Get_Pragma_Arg (Arg));
13264
13265                if Has_Homonym (Ent) then
13266                   Error_Pragma_Arg
13267                     ("argument for pragma% may not be overloaded", Arg);
13268                end if;
13269
13270                if Ekind (Ent) /= E_Function
13271                  or else No (First_Formal (Ent))
13272                  or else Present (Next_Formal (First_Formal (Ent)))
13273                then
13274                   Error_Pragma_Arg
13275                     ("argument for pragma% must be" &
13276                      " function of one argument", Arg);
13277                end if;
13278             end Check_OK_Stream_Convert_Function;
13279
13280          --  Start of processing for Stream_Convert
13281
13282          begin
13283             GNAT_Pragma;
13284             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13285             Check_Arg_Count (3);
13286             Check_Optional_Identifier (Arg1, Name_Entity);
13287             Check_Optional_Identifier (Arg2, Name_Read);
13288             Check_Optional_Identifier (Arg3, Name_Write);
13289             Check_Arg_Is_Local_Name (Arg1);
13290             Check_OK_Stream_Convert_Function (Arg2);
13291             Check_OK_Stream_Convert_Function (Arg3);
13292
13293             declare
13294                Typ   : constant Entity_Id :=
13295                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13296                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13297                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13298
13299             begin
13300                Check_First_Subtype (Arg1);
13301
13302                --  Check for too early or too late. Note that we don't enforce
13303                --  the rule about primitive operations in this case, since, as
13304                --  is the case for explicit stream attributes themselves, these
13305                --  restrictions are not appropriate. Note that the chaining of
13306                --  the pragma by Rep_Item_Too_Late is actually the critical
13307                --  processing done for this pragma.
13308
13309                if Rep_Item_Too_Early (Typ, N)
13310                     or else
13311                   Rep_Item_Too_Late (Typ, N, FOnly => True)
13312                then
13313                   return;
13314                end if;
13315
13316                --  Return if previous error
13317
13318                if Etype (Typ) = Any_Type
13319                     or else
13320                   Etype (Read) = Any_Type
13321                     or else
13322                   Etype (Write) = Any_Type
13323                then
13324                   return;
13325                end if;
13326
13327                --  Error checks
13328
13329                if Underlying_Type (Etype (Read)) /= Typ then
13330                   Error_Pragma_Arg
13331                     ("incorrect return type for function&", Arg2);
13332                end if;
13333
13334                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13335                   Error_Pragma_Arg
13336                     ("incorrect parameter type for function&", Arg3);
13337                end if;
13338
13339                if Underlying_Type (Etype (First_Formal (Read))) /=
13340                   Underlying_Type (Etype (Write))
13341                then
13342                   Error_Pragma_Arg
13343                     ("result type of & does not match Read parameter type",
13344                      Arg3);
13345                end if;
13346             end;
13347          end Stream_Convert;
13348
13349          -------------------------
13350          -- Style_Checks (GNAT) --
13351          -------------------------
13352
13353          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13354
13355          --  This is processed by the parser since some of the style checks
13356          --  take place during source scanning and parsing. This means that
13357          --  we don't need to issue error messages here.
13358
13359          when Pragma_Style_Checks => Style_Checks : declare
13360             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13361             S  : String_Id;
13362             C  : Char_Code;
13363
13364          begin
13365             GNAT_Pragma;
13366             Check_No_Identifiers;
13367
13368             --  Two argument form
13369
13370             if Arg_Count = 2 then
13371                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13372
13373                declare
13374                   E_Id : Node_Id;
13375                   E    : Entity_Id;
13376
13377                begin
13378                   E_Id := Get_Pragma_Arg (Arg2);
13379                   Analyze (E_Id);
13380
13381                   if not Is_Entity_Name (E_Id) then
13382                      Error_Pragma_Arg
13383                        ("second argument of pragma% must be entity name",
13384                         Arg2);
13385                   end if;
13386
13387                   E := Entity (E_Id);
13388
13389                   if E = Any_Id then
13390                      return;
13391                   else
13392                      loop
13393                         Set_Suppress_Style_Checks (E,
13394                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13395                         exit when No (Homonym (E));
13396                         E := Homonym (E);
13397                      end loop;
13398                   end if;
13399                end;
13400
13401             --  One argument form
13402
13403             else
13404                Check_Arg_Count (1);
13405
13406                if Nkind (A) = N_String_Literal then
13407                   S   := Strval (A);
13408
13409                   declare
13410                      Slen    : constant Natural := Natural (String_Length (S));
13411                      Options : String (1 .. Slen);
13412                      J       : Natural;
13413
13414                   begin
13415                      J := 1;
13416                      loop
13417                         C := Get_String_Char (S, Int (J));
13418                         exit when not In_Character_Range (C);
13419                         Options (J) := Get_Character (C);
13420
13421                         --  If at end of string, set options. As per discussion
13422                         --  above, no need to check for errors, since we issued
13423                         --  them in the parser.
13424
13425                         if J = Slen then
13426                            Set_Style_Check_Options (Options);
13427                            exit;
13428                         end if;
13429
13430                         J := J + 1;
13431                      end loop;
13432                   end;
13433
13434                elsif Nkind (A) = N_Identifier then
13435                   if Chars (A) = Name_All_Checks then
13436                      if GNAT_Mode then
13437                         Set_GNAT_Style_Check_Options;
13438                      else
13439                         Set_Default_Style_Check_Options;
13440                      end if;
13441
13442                   elsif Chars (A) = Name_On then
13443                      Style_Check := True;
13444
13445                   elsif Chars (A) = Name_Off then
13446                      Style_Check := False;
13447                   end if;
13448                end if;
13449             end if;
13450          end Style_Checks;
13451
13452          --------------
13453          -- Subtitle --
13454          --------------
13455
13456          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13457
13458          when Pragma_Subtitle =>
13459             GNAT_Pragma;
13460             Check_Arg_Count (1);
13461             Check_Optional_Identifier (Arg1, Name_Subtitle);
13462             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13463             Store_Note (N);
13464
13465          --------------
13466          -- Suppress --
13467          --------------
13468
13469          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13470
13471          when Pragma_Suppress =>
13472             Process_Suppress_Unsuppress (True);
13473
13474          ------------------
13475          -- Suppress_All --
13476          ------------------
13477
13478          --  pragma Suppress_All;
13479
13480          --  The only check made here is that the pragma has no arguments.
13481          --  There are no placement rules, and the processing required (setting
13482          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
13483          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
13484          --  then creates and inserts a pragma Suppress (All_Checks).
13485
13486          when Pragma_Suppress_All =>
13487             GNAT_Pragma;
13488             Check_Arg_Count (0);
13489
13490          -------------------------
13491          -- Suppress_Debug_Info --
13492          -------------------------
13493
13494          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13495
13496          when Pragma_Suppress_Debug_Info =>
13497             GNAT_Pragma;
13498             Check_Arg_Count (1);
13499             Check_Optional_Identifier (Arg1, Name_Entity);
13500             Check_Arg_Is_Local_Name (Arg1);
13501             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13502
13503          ----------------------------------
13504          -- Suppress_Exception_Locations --
13505          ----------------------------------
13506
13507          --  pragma Suppress_Exception_Locations;
13508
13509          when Pragma_Suppress_Exception_Locations =>
13510             GNAT_Pragma;
13511             Check_Arg_Count (0);
13512             Check_Valid_Configuration_Pragma;
13513             Exception_Locations_Suppressed := True;
13514
13515          -----------------------------
13516          -- Suppress_Initialization --
13517          -----------------------------
13518
13519          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13520
13521          when Pragma_Suppress_Initialization => Suppress_Init : declare
13522             E_Id : Node_Id;
13523             E    : Entity_Id;
13524
13525          begin
13526             GNAT_Pragma;
13527             Check_Arg_Count (1);
13528             Check_Optional_Identifier (Arg1, Name_Entity);
13529             Check_Arg_Is_Local_Name (Arg1);
13530
13531             E_Id := Get_Pragma_Arg (Arg1);
13532
13533             if Etype (E_Id) = Any_Type then
13534                return;
13535             end if;
13536
13537             E := Entity (E_Id);
13538
13539             if not Is_Type (E) then
13540                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13541             end if;
13542
13543             if Rep_Item_Too_Early (E, N)
13544                  or else
13545                Rep_Item_Too_Late (E, N, FOnly => True)
13546             then
13547                return;
13548             end if;
13549
13550             --  For incomplete/private type, set flag on full view
13551
13552             if Is_Incomplete_Or_Private_Type (E) then
13553                if No (Full_View (Base_Type (E))) then
13554                   Error_Pragma_Arg
13555                     ("argument of pragma% cannot be an incomplete type", Arg1);
13556                else
13557                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13558                end if;
13559
13560             --  For first subtype, set flag on base type
13561
13562             elsif Is_First_Subtype (E) then
13563                Set_Suppress_Initialization (Base_Type (E));
13564
13565             --  For other than first subtype, set flag on subtype itself
13566
13567             else
13568                Set_Suppress_Initialization (E);
13569             end if;
13570          end Suppress_Init;
13571
13572          -----------------
13573          -- System_Name --
13574          -----------------
13575
13576          --  pragma System_Name (DIRECT_NAME);
13577
13578          --  Syntax check: one argument, which must be the identifier GNAT or
13579          --  the identifier GCC, no other identifiers are acceptable.
13580
13581          when Pragma_System_Name =>
13582             GNAT_Pragma;
13583             Check_No_Identifiers;
13584             Check_Arg_Count (1);
13585             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13586
13587          -----------------------------
13588          -- Task_Dispatching_Policy --
13589          -----------------------------
13590
13591          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13592
13593          when Pragma_Task_Dispatching_Policy => declare
13594             DP : Character;
13595
13596          begin
13597             Check_Ada_83_Warning;
13598             Check_Arg_Count (1);
13599             Check_No_Identifiers;
13600             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13601             Check_Valid_Configuration_Pragma;
13602             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13603             DP := Fold_Upper (Name_Buffer (1));
13604
13605             if Task_Dispatching_Policy /= ' '
13606               and then Task_Dispatching_Policy /= DP
13607             then
13608                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13609                Error_Pragma
13610                  ("task dispatching policy incompatible with policy#");
13611
13612             --  Set new policy, but always preserve System_Location since we
13613             --  like the error message with the run time name.
13614
13615             else
13616                Task_Dispatching_Policy := DP;
13617
13618                if Task_Dispatching_Policy_Sloc /= System_Location then
13619                   Task_Dispatching_Policy_Sloc := Loc;
13620                end if;
13621             end if;
13622          end;
13623
13624          ---------------
13625          -- Task_Info --
13626          ---------------
13627
13628          --  pragma Task_Info (EXPRESSION);
13629
13630          when Pragma_Task_Info => Task_Info : declare
13631             P : constant Node_Id := Parent (N);
13632
13633          begin
13634             GNAT_Pragma;
13635
13636             if Nkind (P) /= N_Task_Definition then
13637                Error_Pragma ("pragma% must appear in task definition");
13638             end if;
13639
13640             Check_No_Identifiers;
13641             Check_Arg_Count (1);
13642
13643             Analyze_And_Resolve
13644               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13645
13646             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13647                return;
13648             end if;
13649
13650             if Has_Task_Info_Pragma (P) then
13651                Error_Pragma ("duplicate pragma% not allowed");
13652             else
13653                Set_Has_Task_Info_Pragma (P, True);
13654             end if;
13655          end Task_Info;
13656
13657          ---------------
13658          -- Task_Name --
13659          ---------------
13660
13661          --  pragma Task_Name (string_EXPRESSION);
13662
13663          when Pragma_Task_Name => Task_Name : declare
13664             P   : constant Node_Id := Parent (N);
13665             Arg : Node_Id;
13666
13667          begin
13668             Check_No_Identifiers;
13669             Check_Arg_Count (1);
13670
13671             Arg := Get_Pragma_Arg (Arg1);
13672
13673             --  The expression is used in the call to Create_Task, and must be
13674             --  expanded there, not in the context of the current spec. It must
13675             --  however be analyzed to capture global references, in case it
13676             --  appears in a generic context.
13677
13678             Preanalyze_And_Resolve (Arg, Standard_String);
13679
13680             if Nkind (P) /= N_Task_Definition then
13681                Pragma_Misplaced;
13682             end if;
13683
13684             if Has_Task_Name_Pragma (P) then
13685                Error_Pragma ("duplicate pragma% not allowed");
13686             else
13687                Set_Has_Task_Name_Pragma (P, True);
13688                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13689             end if;
13690          end Task_Name;
13691
13692          ------------------
13693          -- Task_Storage --
13694          ------------------
13695
13696          --  pragma Task_Storage (
13697          --     [Task_Type =>] LOCAL_NAME,
13698          --     [Top_Guard =>] static_integer_EXPRESSION);
13699
13700          when Pragma_Task_Storage => Task_Storage : declare
13701             Args  : Args_List (1 .. 2);
13702             Names : constant Name_List (1 .. 2) := (
13703                       Name_Task_Type,
13704                       Name_Top_Guard);
13705
13706             Task_Type : Node_Id renames Args (1);
13707             Top_Guard : Node_Id renames Args (2);
13708
13709             Ent : Entity_Id;
13710
13711          begin
13712             GNAT_Pragma;
13713             Gather_Associations (Names, Args);
13714
13715             if No (Task_Type) then
13716                Error_Pragma
13717                  ("missing task_type argument for pragma%");
13718             end if;
13719
13720             Check_Arg_Is_Local_Name (Task_Type);
13721
13722             Ent := Entity (Task_Type);
13723
13724             if not Is_Task_Type (Ent) then
13725                Error_Pragma_Arg
13726                  ("argument for pragma% must be task type", Task_Type);
13727             end if;
13728
13729             if No (Top_Guard) then
13730                Error_Pragma_Arg
13731                  ("pragma% takes two arguments", Task_Type);
13732             else
13733                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13734             end if;
13735
13736             Check_First_Subtype (Task_Type);
13737
13738             if Rep_Item_Too_Late (Ent, N) then
13739                raise Pragma_Exit;
13740             end if;
13741          end Task_Storage;
13742
13743          ---------------
13744          -- Test_Case --
13745          ---------------
13746
13747          --  pragma Test_Case ([Name     =>] Static_String_EXPRESSION
13748          --                   ,[Mode     =>] MODE_TYPE
13749          --                  [, Requires =>  Boolean_EXPRESSION]
13750          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13751
13752          --  MODE_TYPE ::= Nominal | Robustness
13753
13754          when Pragma_Test_Case => Test_Case : declare
13755          begin
13756             GNAT_Pragma;
13757             Check_At_Least_N_Arguments (2);
13758             Check_At_Most_N_Arguments (4);
13759             Check_Arg_Order
13760                  ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13761
13762             Check_Optional_Identifier (Arg1, Name_Name);
13763             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13764
13765             --  In ASIS mode, for a pragma generated from a source aspect, also
13766             --  analyze the original aspect expression.
13767
13768             if ASIS_Mode
13769               and then Present (Corresponding_Aspect (N))
13770             then
13771                Check_Expr_Is_Static_Expression
13772                  (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13773             end if;
13774
13775             Check_Optional_Identifier (Arg2, Name_Mode);
13776             Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13777
13778             if Arg_Count = 4 then
13779                Check_Identifier (Arg3, Name_Requires);
13780                Check_Identifier (Arg4, Name_Ensures);
13781
13782             elsif Arg_Count = 3 then
13783                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13784             end if;
13785
13786             Check_Test_Case;
13787          end Test_Case;
13788
13789          --------------------------
13790          -- Thread_Local_Storage --
13791          --------------------------
13792
13793          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13794
13795          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13796             Id : Node_Id;
13797             E  : Entity_Id;
13798
13799          begin
13800             GNAT_Pragma;
13801             Check_Arg_Count (1);
13802             Check_Optional_Identifier (Arg1, Name_Entity);
13803             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13804
13805             Id := Get_Pragma_Arg (Arg1);
13806             Analyze (Id);
13807
13808             if not Is_Entity_Name (Id)
13809               or else Ekind (Entity (Id)) /= E_Variable
13810             then
13811                Error_Pragma_Arg ("local variable name required", Arg1);
13812             end if;
13813
13814             E := Entity (Id);
13815
13816             if Rep_Item_Too_Early (E, N)
13817               or else Rep_Item_Too_Late (E, N)
13818             then
13819                raise Pragma_Exit;
13820             end if;
13821
13822             Set_Has_Pragma_Thread_Local_Storage (E);
13823             Set_Has_Gigi_Rep_Item (E);
13824          end Thread_Local_Storage;
13825
13826          ----------------
13827          -- Time_Slice --
13828          ----------------
13829
13830          --  pragma Time_Slice (static_duration_EXPRESSION);
13831
13832          when Pragma_Time_Slice => Time_Slice : declare
13833             Val : Ureal;
13834             Nod : Node_Id;
13835
13836          begin
13837             GNAT_Pragma;
13838             Check_Arg_Count (1);
13839             Check_No_Identifiers;
13840             Check_In_Main_Program;
13841             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13842
13843             if not Error_Posted (Arg1) then
13844                Nod := Next (N);
13845                while Present (Nod) loop
13846                   if Nkind (Nod) = N_Pragma
13847                     and then Pragma_Name (Nod) = Name_Time_Slice
13848                   then
13849                      Error_Msg_Name_1 := Pname;
13850                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13851                   end if;
13852
13853                   Next (Nod);
13854                end loop;
13855             end if;
13856
13857             --  Process only if in main unit
13858
13859             if Get_Source_Unit (Loc) = Main_Unit then
13860                Opt.Time_Slice_Set := True;
13861                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13862
13863                if Val <= Ureal_0 then
13864                   Opt.Time_Slice_Value := 0;
13865
13866                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13867                   Opt.Time_Slice_Value := 1_000_000_000;
13868
13869                else
13870                   Opt.Time_Slice_Value :=
13871                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13872                end if;
13873             end if;
13874          end Time_Slice;
13875
13876          -----------
13877          -- Title --
13878          -----------
13879
13880          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13881
13882          --   TITLING_OPTION ::=
13883          --     [Title =>] STRING_LITERAL
13884          --   | [Subtitle =>] STRING_LITERAL
13885
13886          when Pragma_Title => Title : declare
13887             Args  : Args_List (1 .. 2);
13888             Names : constant Name_List (1 .. 2) := (
13889                       Name_Title,
13890                       Name_Subtitle);
13891
13892          begin
13893             GNAT_Pragma;
13894             Gather_Associations (Names, Args);
13895             Store_Note (N);
13896
13897             for J in 1 .. 2 loop
13898                if Present (Args (J)) then
13899                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13900                end if;
13901             end loop;
13902          end Title;
13903
13904          ---------------------
13905          -- Unchecked_Union --
13906          ---------------------
13907
13908          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13909
13910          when Pragma_Unchecked_Union => Unchecked_Union : declare
13911             Assoc   : constant Node_Id := Arg1;
13912             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13913             Typ     : Entity_Id;
13914             Discr   : Entity_Id;
13915             Tdef    : Node_Id;
13916             Clist   : Node_Id;
13917             Vpart   : Node_Id;
13918             Comp    : Node_Id;
13919             Variant : Node_Id;
13920
13921          begin
13922             Ada_2005_Pragma;
13923             Check_No_Identifiers;
13924             Check_Arg_Count (1);
13925             Check_Arg_Is_Local_Name (Arg1);
13926
13927             Find_Type (Type_Id);
13928             Typ := Entity (Type_Id);
13929
13930             if Typ = Any_Type
13931               or else Rep_Item_Too_Early (Typ, N)
13932             then
13933                return;
13934             else
13935                Typ := Underlying_Type (Typ);
13936             end if;
13937
13938             if Rep_Item_Too_Late (Typ, N) then
13939                return;
13940             end if;
13941
13942             Check_First_Subtype (Arg1);
13943
13944             --  Note remaining cases are references to a type in the current
13945             --  declarative part. If we find an error, we post the error on
13946             --  the relevant type declaration at an appropriate point.
13947
13948             if not Is_Record_Type (Typ) then
13949                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13950                return;
13951
13952             elsif Is_Tagged_Type (Typ) then
13953                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13954                return;
13955
13956             elsif not Has_Discriminants (Typ) then
13957                Error_Msg_N
13958                 ("Unchecked_Union must have one discriminant", Typ);
13959                return;
13960
13961             --  Note: in previous versions of GNAT we used to check for limited
13962             --  types and give an error, but in fact the standard does allow
13963             --  Unchecked_Union on limited types, so this check was removed.
13964
13965             --  Proceed with basic error checks completed
13966
13967             else
13968                Discr := First_Discriminant (Typ);
13969                while Present (Discr) loop
13970                   if No (Discriminant_Default_Value (Discr)) then
13971                      Error_Msg_N
13972                        ("Unchecked_Union discriminant must have default value",
13973                         Discr);
13974                   end if;
13975
13976                   Next_Discriminant (Discr);
13977                end loop;
13978
13979                Tdef  := Type_Definition (Declaration_Node (Typ));
13980                Clist := Component_List (Tdef);
13981
13982                Comp := First (Component_Items (Clist));
13983                while Present (Comp) loop
13984                   Check_Component (Comp, Typ);
13985                   Next (Comp);
13986                end loop;
13987
13988                if No (Clist) or else No (Variant_Part (Clist)) then
13989                   Error_Msg_N
13990                     ("Unchecked_Union must have variant part",
13991                      Tdef);
13992                   return;
13993                end if;
13994
13995                Vpart := Variant_Part (Clist);
13996
13997                Variant := First (Variants (Vpart));
13998                while Present (Variant) loop
13999                   Check_Variant (Variant, Typ);
14000                   Next (Variant);
14001                end loop;
14002             end if;
14003
14004             Set_Is_Unchecked_Union  (Typ);
14005             Set_Convention (Typ, Convention_C);
14006             Set_Has_Unchecked_Union (Base_Type (Typ));
14007             Set_Is_Unchecked_Union  (Base_Type (Typ));
14008          end Unchecked_Union;
14009
14010          ------------------------
14011          -- Unimplemented_Unit --
14012          ------------------------
14013
14014          --  pragma Unimplemented_Unit;
14015
14016          --  Note: this only gives an error if we are generating code, or if
14017          --  we are in a generic library unit (where the pragma appears in the
14018          --  body, not in the spec).
14019
14020          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14021             Cunitent : constant Entity_Id :=
14022                          Cunit_Entity (Get_Source_Unit (Loc));
14023             Ent_Kind : constant Entity_Kind :=
14024                          Ekind (Cunitent);
14025
14026          begin
14027             GNAT_Pragma;
14028             Check_Arg_Count (0);
14029
14030             if Operating_Mode = Generate_Code
14031               or else Ent_Kind = E_Generic_Function
14032               or else Ent_Kind = E_Generic_Procedure
14033               or else Ent_Kind = E_Generic_Package
14034             then
14035                Get_Name_String (Chars (Cunitent));
14036                Set_Casing (Mixed_Case);
14037                Write_Str (Name_Buffer (1 .. Name_Len));
14038                Write_Str (" is not supported in this configuration");
14039                Write_Eol;
14040                raise Unrecoverable_Error;
14041             end if;
14042          end Unimplemented_Unit;
14043
14044          ------------------------
14045          -- Universal_Aliasing --
14046          ------------------------
14047
14048          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14049
14050          when Pragma_Universal_Aliasing => Universal_Alias : declare
14051             E_Id : Entity_Id;
14052
14053          begin
14054             GNAT_Pragma;
14055             Check_Arg_Count (1);
14056             Check_Optional_Identifier (Arg2, Name_Entity);
14057             Check_Arg_Is_Local_Name (Arg1);
14058             E_Id := Entity (Get_Pragma_Arg (Arg1));
14059
14060             if E_Id = Any_Type then
14061                return;
14062             elsif No (E_Id) or else not Is_Type (E_Id) then
14063                Error_Pragma_Arg ("pragma% requires type", Arg1);
14064             end if;
14065
14066             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14067          end Universal_Alias;
14068
14069          --------------------
14070          -- Universal_Data --
14071          --------------------
14072
14073          --  pragma Universal_Data [(library_unit_NAME)];
14074
14075          when Pragma_Universal_Data =>
14076             GNAT_Pragma;
14077
14078             --  If this is a configuration pragma, then set the universal
14079             --  addressing option, otherwise confirm that the pragma satisfies
14080             --  the requirements of library unit pragma placement and leave it
14081             --  to the GNAAMP back end to detect the pragma (avoids transitive
14082             --  setting of the option due to withed units).
14083
14084             if Is_Configuration_Pragma then
14085                Universal_Addressing_On_AAMP := True;
14086             else
14087                Check_Valid_Library_Unit_Pragma;
14088             end if;
14089
14090             if not AAMP_On_Target then
14091                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14092             end if;
14093
14094          ----------------
14095          -- Unmodified --
14096          ----------------
14097
14098          --  pragma Unmodified (local_Name {, local_Name});
14099
14100          when Pragma_Unmodified => Unmodified : declare
14101             Arg_Node : Node_Id;
14102             Arg_Expr : Node_Id;
14103             Arg_Ent  : Entity_Id;
14104
14105          begin
14106             GNAT_Pragma;
14107             Check_At_Least_N_Arguments (1);
14108
14109             --  Loop through arguments
14110
14111             Arg_Node := Arg1;
14112             while Present (Arg_Node) loop
14113                Check_No_Identifier (Arg_Node);
14114
14115                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
14116                --  in fact generate reference, so that the entity will have a
14117                --  reference, which will inhibit any warnings about it not
14118                --  being referenced, and also properly show up in the ali file
14119                --  as a reference. But this reference is recorded before the
14120                --  Has_Pragma_Unreferenced flag is set, so that no warning is
14121                --  generated for this reference.
14122
14123                Check_Arg_Is_Local_Name (Arg_Node);
14124                Arg_Expr := Get_Pragma_Arg (Arg_Node);
14125
14126                if Is_Entity_Name (Arg_Expr) then
14127                   Arg_Ent := Entity (Arg_Expr);
14128
14129                   if not Is_Assignable (Arg_Ent) then
14130                      Error_Pragma_Arg
14131                        ("pragma% can only be applied to a variable",
14132                         Arg_Expr);
14133                   else
14134                      Set_Has_Pragma_Unmodified (Arg_Ent);
14135                   end if;
14136                end if;
14137
14138                Next (Arg_Node);
14139             end loop;
14140          end Unmodified;
14141
14142          ------------------
14143          -- Unreferenced --
14144          ------------------
14145
14146          --  pragma Unreferenced (local_Name {, local_Name});
14147
14148          --    or when used in a context clause:
14149
14150          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14151
14152          when Pragma_Unreferenced => Unreferenced : declare
14153             Arg_Node : Node_Id;
14154             Arg_Expr : Node_Id;
14155             Arg_Ent  : Entity_Id;
14156             Citem    : Node_Id;
14157
14158          begin
14159             GNAT_Pragma;
14160             Check_At_Least_N_Arguments (1);
14161
14162             --  Check case of appearing within context clause
14163
14164             if Is_In_Context_Clause then
14165
14166                --  The arguments must all be units mentioned in a with clause
14167                --  in the same context clause. Note we already checked (in
14168                --  Par.Prag) that the arguments are either identifiers or
14169                --  selected components.
14170
14171                Arg_Node := Arg1;
14172                while Present (Arg_Node) loop
14173                   Citem := First (List_Containing (N));
14174                   while Citem /= N loop
14175                      if Nkind (Citem) = N_With_Clause
14176                        and then
14177                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14178                      then
14179                         Set_Has_Pragma_Unreferenced
14180                           (Cunit_Entity
14181                              (Get_Source_Unit
14182                                 (Library_Unit (Citem))));
14183                         Set_Unit_Name
14184                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
14185                         exit;
14186                      end if;
14187
14188                      Next (Citem);
14189                   end loop;
14190
14191                   if Citem = N then
14192                      Error_Pragma_Arg
14193                        ("argument of pragma% is not with'ed unit", Arg_Node);
14194                   end if;
14195
14196                   Next (Arg_Node);
14197                end loop;
14198
14199             --  Case of not in list of context items
14200
14201             else
14202                Arg_Node := Arg1;
14203                while Present (Arg_Node) loop
14204                   Check_No_Identifier (Arg_Node);
14205
14206                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
14207                   --  will in fact generate reference, so that the entity will
14208                   --  have a reference, which will inhibit any warnings about
14209                   --  it not being referenced, and also properly show up in the
14210                   --  ali file as a reference. But this reference is recorded
14211                   --  before the Has_Pragma_Unreferenced flag is set, so that
14212                   --  no warning is generated for this reference.
14213
14214                   Check_Arg_Is_Local_Name (Arg_Node);
14215                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
14216
14217                   if Is_Entity_Name (Arg_Expr) then
14218                      Arg_Ent := Entity (Arg_Expr);
14219
14220                      --  If the entity is overloaded, the pragma applies to the
14221                      --  most recent overloading, as documented. In this case,
14222                      --  name resolution does not generate a reference, so it
14223                      --  must be done here explicitly.
14224
14225                      if Is_Overloaded (Arg_Expr) then
14226                         Generate_Reference (Arg_Ent, N);
14227                      end if;
14228
14229                      Set_Has_Pragma_Unreferenced (Arg_Ent);
14230                   end if;
14231
14232                   Next (Arg_Node);
14233                end loop;
14234             end if;
14235          end Unreferenced;
14236
14237          --------------------------
14238          -- Unreferenced_Objects --
14239          --------------------------
14240
14241          --  pragma Unreferenced_Objects (local_Name {, local_Name});
14242
14243          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14244             Arg_Node : Node_Id;
14245             Arg_Expr : Node_Id;
14246
14247          begin
14248             GNAT_Pragma;
14249             Check_At_Least_N_Arguments (1);
14250
14251             Arg_Node := Arg1;
14252             while Present (Arg_Node) loop
14253                Check_No_Identifier (Arg_Node);
14254                Check_Arg_Is_Local_Name (Arg_Node);
14255                Arg_Expr := Get_Pragma_Arg (Arg_Node);
14256
14257                if not Is_Entity_Name (Arg_Expr)
14258                  or else not Is_Type (Entity (Arg_Expr))
14259                then
14260                   Error_Pragma_Arg
14261                     ("argument for pragma% must be type or subtype", Arg_Node);
14262                end if;
14263
14264                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14265                Next (Arg_Node);
14266             end loop;
14267          end Unreferenced_Objects;
14268
14269          ------------------------------
14270          -- Unreserve_All_Interrupts --
14271          ------------------------------
14272
14273          --  pragma Unreserve_All_Interrupts;
14274
14275          when Pragma_Unreserve_All_Interrupts =>
14276             GNAT_Pragma;
14277             Check_Arg_Count (0);
14278
14279             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14280                Unreserve_All_Interrupts := True;
14281             end if;
14282
14283          ----------------
14284          -- Unsuppress --
14285          ----------------
14286
14287          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14288
14289          when Pragma_Unsuppress =>
14290             Ada_2005_Pragma;
14291             Process_Suppress_Unsuppress (False);
14292
14293          -------------------
14294          -- Use_VADS_Size --
14295          -------------------
14296
14297          --  pragma Use_VADS_Size;
14298
14299          when Pragma_Use_VADS_Size =>
14300             GNAT_Pragma;
14301             Check_Arg_Count (0);
14302             Check_Valid_Configuration_Pragma;
14303             Use_VADS_Size := True;
14304
14305          ---------------------
14306          -- Validity_Checks --
14307          ---------------------
14308
14309          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14310
14311          when Pragma_Validity_Checks => Validity_Checks : declare
14312             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
14313             S  : String_Id;
14314             C  : Char_Code;
14315
14316          begin
14317             GNAT_Pragma;
14318             Check_Arg_Count (1);
14319             Check_No_Identifiers;
14320
14321             if Nkind (A) = N_String_Literal then
14322                S   := Strval (A);
14323
14324                declare
14325                   Slen    : constant Natural := Natural (String_Length (S));
14326                   Options : String (1 .. Slen);
14327                   J       : Natural;
14328
14329                begin
14330                   J := 1;
14331                   loop
14332                      C := Get_String_Char (S, Int (J));
14333                      exit when not In_Character_Range (C);
14334                      Options (J) := Get_Character (C);
14335
14336                      if J = Slen then
14337                         Set_Validity_Check_Options (Options);
14338                         exit;
14339                      else
14340                         J := J + 1;
14341                      end if;
14342                   end loop;
14343                end;
14344
14345             elsif Nkind (A) = N_Identifier then
14346                if Chars (A) = Name_All_Checks then
14347                   Set_Validity_Check_Options ("a");
14348                elsif Chars (A) = Name_On then
14349                   Validity_Checks_On := True;
14350                elsif Chars (A) = Name_Off then
14351                   Validity_Checks_On := False;
14352                end if;
14353             end if;
14354          end Validity_Checks;
14355
14356          --------------
14357          -- Volatile --
14358          --------------
14359
14360          --  pragma Volatile (LOCAL_NAME);
14361
14362          when Pragma_Volatile =>
14363             Process_Atomic_Shared_Volatile;
14364
14365          -------------------------
14366          -- Volatile_Components --
14367          -------------------------
14368
14369          --  pragma Volatile_Components (array_LOCAL_NAME);
14370
14371          --  Volatile is handled by the same circuit as Atomic_Components
14372
14373          --------------
14374          -- Warnings --
14375          --------------
14376
14377          --  pragma Warnings (On | Off);
14378          --  pragma Warnings (On | Off, LOCAL_NAME);
14379          --  pragma Warnings (static_string_EXPRESSION);
14380          --  pragma Warnings (On | Off, STRING_LITERAL);
14381
14382          when Pragma_Warnings => Warnings : begin
14383             GNAT_Pragma;
14384             Check_At_Least_N_Arguments (1);
14385             Check_No_Identifiers;
14386
14387             --  If debug flag -gnatd.i is set, pragma is ignored
14388
14389             if Debug_Flag_Dot_I then
14390                return;
14391             end if;
14392
14393             --  Process various forms of the pragma
14394
14395             declare
14396                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14397
14398             begin
14399                --  One argument case
14400
14401                if Arg_Count = 1 then
14402
14403                   --  On/Off one argument case was processed by parser
14404
14405                   if Nkind (Argx) = N_Identifier
14406                     and then
14407                       (Chars (Argx) = Name_On
14408                          or else
14409                        Chars (Argx) = Name_Off)
14410                   then
14411                      null;
14412
14413                   --  One argument case must be ON/OFF or static string expr
14414
14415                   elsif not Is_Static_String_Expression (Arg1) then
14416                      Error_Pragma_Arg
14417                        ("argument of pragma% must be On/Off or " &
14418                         "static string expression", Arg1);
14419
14420                   --  One argument string expression case
14421
14422                   else
14423                      declare
14424                         Lit : constant Node_Id   := Expr_Value_S (Argx);
14425                         Str : constant String_Id := Strval (Lit);
14426                         Len : constant Nat       := String_Length (Str);
14427                         C   : Char_Code;
14428                         J   : Nat;
14429                         OK  : Boolean;
14430                         Chr : Character;
14431
14432                      begin
14433                         J := 1;
14434                         while J <= Len loop
14435                            C := Get_String_Char (Str, J);
14436                            OK := In_Character_Range (C);
14437
14438                            if OK then
14439                               Chr := Get_Character (C);
14440
14441                               --  Dot case
14442
14443                               if J < Len and then Chr = '.' then
14444                                  J := J + 1;
14445                                  C := Get_String_Char (Str, J);
14446                                  Chr := Get_Character (C);
14447
14448                                  if not Set_Dot_Warning_Switch (Chr) then
14449                                     Error_Pragma_Arg
14450                                       ("invalid warning switch character " &
14451                                        '.' & Chr, Arg1);
14452                                  end if;
14453
14454                               --  Non-Dot case
14455
14456                               else
14457                                  OK := Set_Warning_Switch (Chr);
14458                               end if;
14459                            end if;
14460
14461                            if not OK then
14462                               Error_Pragma_Arg
14463                                 ("invalid warning switch character " & Chr,
14464                                  Arg1);
14465                            end if;
14466
14467                            J := J + 1;
14468                         end loop;
14469                      end;
14470                   end if;
14471
14472                   --  Two or more arguments (must be two)
14473
14474                else
14475                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14476                   Check_At_Most_N_Arguments (2);
14477
14478                   declare
14479                      E_Id : Node_Id;
14480                      E    : Entity_Id;
14481                      Err  : Boolean;
14482
14483                   begin
14484                      E_Id := Get_Pragma_Arg (Arg2);
14485                      Analyze (E_Id);
14486
14487                      --  In the expansion of an inlined body, a reference to
14488                      --  the formal may be wrapped in a conversion if the
14489                      --  actual is a conversion. Retrieve the real entity name.
14490
14491                      if (In_Instance_Body
14492                           or else In_Inlined_Body)
14493                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14494                      then
14495                         E_Id := Expression (E_Id);
14496                      end if;
14497
14498                      --  Entity name case
14499
14500                      if Is_Entity_Name (E_Id) then
14501                         E := Entity (E_Id);
14502
14503                         if E = Any_Id then
14504                            return;
14505                         else
14506                            loop
14507                               Set_Warnings_Off
14508                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14509                                                               Name_Off));
14510
14511                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14512                                 and then Warn_On_Warnings_Off
14513                               then
14514                                  Warnings_Off_Pragmas.Append ((N, E));
14515                               end if;
14516
14517                               if Is_Enumeration_Type (E) then
14518                                  declare
14519                                     Lit : Entity_Id;
14520                                  begin
14521                                     Lit := First_Literal (E);
14522                                     while Present (Lit) loop
14523                                        Set_Warnings_Off (Lit);
14524                                        Next_Literal (Lit);
14525                                     end loop;
14526                                  end;
14527                               end if;
14528
14529                               exit when No (Homonym (E));
14530                               E := Homonym (E);
14531                            end loop;
14532                         end if;
14533
14534                      --  Error if not entity or static string literal case
14535
14536                      elsif not Is_Static_String_Expression (Arg2) then
14537                         Error_Pragma_Arg
14538                           ("second argument of pragma% must be entity " &
14539                            "name or static string expression", Arg2);
14540
14541                      --  String literal case
14542
14543                      else
14544                         String_To_Name_Buffer
14545                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14546
14547                         --  Note on configuration pragma case: If this is a
14548                         --  configuration pragma, then for an OFF pragma, we
14549                         --  just set Config True in the call, which is all
14550                         --  that needs to be done. For the case of ON, this
14551                         --  is normally an error, unless it is canceling the
14552                         --  effect of a previous OFF pragma in the same file.
14553                         --  In any other case, an error will be signalled (ON
14554                         --  with no matching OFF).
14555
14556                         if Chars (Argx) = Name_Off then
14557                            Set_Specific_Warning_Off
14558                              (Loc, Name_Buffer (1 .. Name_Len),
14559                               Config => Is_Configuration_Pragma);
14560
14561                         elsif Chars (Argx) = Name_On then
14562                            Set_Specific_Warning_On
14563                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14564
14565                            if Err then
14566                               Error_Msg
14567                                 ("?pragma Warnings On with no " &
14568                                  "matching Warnings Off",
14569                                  Loc);
14570                            end if;
14571                         end if;
14572                      end if;
14573                   end;
14574                end if;
14575             end;
14576          end Warnings;
14577
14578          -------------------
14579          -- Weak_External --
14580          -------------------
14581
14582          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14583
14584          when Pragma_Weak_External => Weak_External : declare
14585             Ent : Entity_Id;
14586
14587          begin
14588             GNAT_Pragma;
14589             Check_Arg_Count (1);
14590             Check_Optional_Identifier (Arg1, Name_Entity);
14591             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14592             Ent := Entity (Get_Pragma_Arg (Arg1));
14593
14594             if Rep_Item_Too_Early (Ent, N) then
14595                return;
14596             else
14597                Ent := Underlying_Type (Ent);
14598             end if;
14599
14600             --  The only processing required is to link this item on to the
14601             --  list of rep items for the given entity. This is accomplished
14602             --  by the call to Rep_Item_Too_Late (when no error is detected
14603             --  and False is returned).
14604
14605             if Rep_Item_Too_Late (Ent, N) then
14606                return;
14607             else
14608                Set_Has_Gigi_Rep_Item (Ent);
14609             end if;
14610          end Weak_External;
14611
14612          -----------------------------
14613          -- Wide_Character_Encoding --
14614          -----------------------------
14615
14616          --  pragma Wide_Character_Encoding (IDENTIFIER);
14617
14618          when Pragma_Wide_Character_Encoding =>
14619             GNAT_Pragma;
14620
14621             --  Nothing to do, handled in parser. Note that we do not enforce
14622             --  configuration pragma placement, this pragma can appear at any
14623             --  place in the source, allowing mixed encodings within a single
14624             --  source program.
14625
14626             null;
14627
14628          --------------------
14629          -- Unknown_Pragma --
14630          --------------------
14631
14632          --  Should be impossible, since the case of an unknown pragma is
14633          --  separately processed before the case statement is entered.
14634
14635          when Unknown_Pragma =>
14636             raise Program_Error;
14637       end case;
14638
14639       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14640       --  until AI is formally approved.
14641
14642       --  Check_Order_Dependence;
14643
14644    exception
14645       when Pragma_Exit => null;
14646    end Analyze_Pragma;
14647
14648    -----------------------------
14649    -- Analyze_TC_In_Decl_Part --
14650    -----------------------------
14651
14652    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14653    begin
14654       --  Install formals and push subprogram spec onto scope stack so that we
14655       --  can see the formals from the pragma.
14656
14657       Install_Formals (S);
14658       Push_Scope (S);
14659
14660       --  Preanalyze the boolean expressions, we treat these as spec
14661       --  expressions (i.e. similar to a default expression).
14662
14663       Preanalyze_TC_Args (N,
14664                           Get_Requires_From_Test_Case_Pragma (N),
14665                           Get_Ensures_From_Test_Case_Pragma (N));
14666
14667       --  Remove the subprogram from the scope stack now that the pre-analysis
14668       --  of the expressions in the test-case is done.
14669
14670       End_Scope;
14671    end Analyze_TC_In_Decl_Part;
14672
14673    --------------------
14674    -- Check_Disabled --
14675    --------------------
14676
14677    function Check_Disabled (Nam : Name_Id) return Boolean is
14678       PP : Node_Id;
14679
14680    begin
14681       --  Loop through entries in check policy list
14682
14683       PP := Opt.Check_Policy_List;
14684       loop
14685          --  If there are no specific entries that matched, then nothing is
14686          --  disabled, so return False.
14687
14688          if No (PP) then
14689             return False;
14690
14691          --  Here we have an entry see if it matches
14692
14693          else
14694             declare
14695                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14696             begin
14697                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14698                   return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14699                else
14700                   PP := Next_Pragma (PP);
14701                end if;
14702             end;
14703          end if;
14704       end loop;
14705    end Check_Disabled;
14706
14707    -------------------
14708    -- Check_Enabled --
14709    -------------------
14710
14711    function Check_Enabled (Nam : Name_Id) return Boolean is
14712       PP : Node_Id;
14713
14714    begin
14715       --  Loop through entries in check policy list
14716
14717       PP := Opt.Check_Policy_List;
14718       loop
14719          --  If there are no specific entries that matched, then we let the
14720          --  setting of assertions govern. Note that this provides the needed
14721          --  compatibility with the RM for the cases of assertion, invariant,
14722          --  precondition, predicate, and postcondition.
14723
14724          if No (PP) then
14725             return Assertions_Enabled;
14726
14727          --  Here we have an entry see if it matches
14728
14729          else
14730             declare
14731                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14732
14733             begin
14734                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14735                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14736                      when Name_On | Name_Check =>
14737                         return True;
14738                      when Name_Off | Name_Ignore =>
14739                         return False;
14740                      when others =>
14741                         raise Program_Error;
14742                   end case;
14743
14744                else
14745                   PP := Next_Pragma (PP);
14746                end if;
14747             end;
14748          end if;
14749       end loop;
14750    end Check_Enabled;
14751
14752    ---------------------------------
14753    -- Delay_Config_Pragma_Analyze --
14754    ---------------------------------
14755
14756    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14757    begin
14758       return Pragma_Name (N) = Name_Interrupt_State
14759                or else
14760              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14761    end Delay_Config_Pragma_Analyze;
14762
14763    -------------------------
14764    -- Get_Base_Subprogram --
14765    -------------------------
14766
14767    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14768       Result : Entity_Id;
14769
14770    begin
14771       --  Follow subprogram renaming chain
14772
14773       Result := Def_Id;
14774       while Is_Subprogram (Result)
14775         and then
14776           Nkind (Parent (Declaration_Node (Result))) =
14777                                          N_Subprogram_Renaming_Declaration
14778         and then Present (Alias (Result))
14779       loop
14780          Result := Alias (Result);
14781       end loop;
14782
14783       return Result;
14784    end Get_Base_Subprogram;
14785
14786    ----------------
14787    -- Initialize --
14788    ----------------
14789
14790    procedure Initialize is
14791    begin
14792       Externals.Init;
14793    end Initialize;
14794
14795    -----------------------------
14796    -- Is_Config_Static_String --
14797    -----------------------------
14798
14799    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14800
14801       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14802       --  This is an internal recursive function that is just like the outer
14803       --  function except that it adds the string to the name buffer rather
14804       --  than placing the string in the name buffer.
14805
14806       ------------------------------
14807       -- Add_Config_Static_String --
14808       ------------------------------
14809
14810       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14811          N : Node_Id;
14812          C : Char_Code;
14813
14814       begin
14815          N := Arg;
14816
14817          if Nkind (N) = N_Op_Concat then
14818             if Add_Config_Static_String (Left_Opnd (N)) then
14819                N := Right_Opnd (N);
14820             else
14821                return False;
14822             end if;
14823          end if;
14824
14825          if Nkind (N) /= N_String_Literal then
14826             Error_Msg_N ("string literal expected for pragma argument", N);
14827             return False;
14828
14829          else
14830             for J in 1 .. String_Length (Strval (N)) loop
14831                C := Get_String_Char (Strval (N), J);
14832
14833                if not In_Character_Range (C) then
14834                   Error_Msg
14835                     ("string literal contains invalid wide character",
14836                      Sloc (N) + 1 + Source_Ptr (J));
14837                   return False;
14838                end if;
14839
14840                Add_Char_To_Name_Buffer (Get_Character (C));
14841             end loop;
14842          end if;
14843
14844          return True;
14845       end Add_Config_Static_String;
14846
14847    --  Start of processing for Is_Config_Static_String
14848
14849    begin
14850
14851       Name_Len := 0;
14852       return Add_Config_Static_String (Arg);
14853    end Is_Config_Static_String;
14854
14855    -----------------------------------------
14856    -- Is_Non_Significant_Pragma_Reference --
14857    -----------------------------------------
14858
14859    --  This function makes use of the following static table which indicates
14860    --  whether a given pragma is significant.
14861
14862    --  -1  indicates that references in any argument position are significant
14863    --  0   indicates that appearance in any argument is not significant
14864    --  +n  indicates that appearance as argument n is significant, but all
14865    --      other arguments are not significant
14866    --  99  special processing required (e.g. for pragma Check)
14867
14868    Sig_Flags : constant array (Pragma_Id) of Int :=
14869      (Pragma_AST_Entry                      => -1,
14870       Pragma_Abort_Defer                    => -1,
14871       Pragma_Ada_83                         => -1,
14872       Pragma_Ada_95                         => -1,
14873       Pragma_Ada_05                         => -1,
14874       Pragma_Ada_2005                       => -1,
14875       Pragma_Ada_12                         => -1,
14876       Pragma_Ada_2012                       => -1,
14877       Pragma_All_Calls_Remote               => -1,
14878       Pragma_Annotate                       => -1,
14879       Pragma_Assert                         => -1,
14880       Pragma_Assertion_Policy               =>  0,
14881       Pragma_Assume_No_Invalid_Values       =>  0,
14882       Pragma_Asynchronous                   => -1,
14883       Pragma_Atomic                         =>  0,
14884       Pragma_Atomic_Components              =>  0,
14885       Pragma_Attach_Handler                 => -1,
14886       Pragma_Check                          => 99,
14887       Pragma_Check_Name                     =>  0,
14888       Pragma_Check_Policy                   =>  0,
14889       Pragma_CIL_Constructor                => -1,
14890       Pragma_CPP_Class                      =>  0,
14891       Pragma_CPP_Constructor                =>  0,
14892       Pragma_CPP_Virtual                    =>  0,
14893       Pragma_CPP_Vtable                     =>  0,
14894       Pragma_CPU                            => -1,
14895       Pragma_C_Pass_By_Copy                 =>  0,
14896       Pragma_Comment                        =>  0,
14897       Pragma_Common_Object                  => -1,
14898       Pragma_Compile_Time_Error             => -1,
14899       Pragma_Compile_Time_Warning           => -1,
14900       Pragma_Compiler_Unit                  =>  0,
14901       Pragma_Complete_Representation        =>  0,
14902       Pragma_Complex_Representation         =>  0,
14903       Pragma_Component_Alignment            => -1,
14904       Pragma_Controlled                     =>  0,
14905       Pragma_Convention                     =>  0,
14906       Pragma_Convention_Identifier          =>  0,
14907       Pragma_Debug                          => -1,
14908       Pragma_Debug_Policy                   =>  0,
14909       Pragma_Detect_Blocking                => -1,
14910       Pragma_Default_Storage_Pool           => -1,
14911       Pragma_Dimension                      => -1,
14912       Pragma_Disable_Atomic_Synchronization => -1,
14913       Pragma_Discard_Names                  =>  0,
14914       Pragma_Dispatching_Domain             => -1,
14915       Pragma_Elaborate                      => -1,
14916       Pragma_Elaborate_All                  => -1,
14917       Pragma_Elaborate_Body                 => -1,
14918       Pragma_Elaboration_Checks             => -1,
14919       Pragma_Eliminate                      => -1,
14920       Pragma_Enable_Atomic_Synchronization  => -1,
14921       Pragma_Export                         => -1,
14922       Pragma_Export_Exception               => -1,
14923       Pragma_Export_Function                => -1,
14924       Pragma_Export_Object                  => -1,
14925       Pragma_Export_Procedure               => -1,
14926       Pragma_Export_Value                   => -1,
14927       Pragma_Export_Valued_Procedure        => -1,
14928       Pragma_Extend_System                  => -1,
14929       Pragma_Extensions_Allowed             => -1,
14930       Pragma_External                       => -1,
14931       Pragma_Favor_Top_Level                => -1,
14932       Pragma_External_Name_Casing           => -1,
14933       Pragma_Fast_Math                      => -1,
14934       Pragma_Finalize_Storage_Only          =>  0,
14935       Pragma_Float_Representation           =>  0,
14936       Pragma_Ident                          => -1,
14937       Pragma_Implementation_Defined         => -1,
14938       Pragma_Implemented                    => -1,
14939       Pragma_Implicit_Packing               =>  0,
14940       Pragma_Import                         => +2,
14941       Pragma_Import_Exception               =>  0,
14942       Pragma_Import_Function                =>  0,
14943       Pragma_Import_Object                  =>  0,
14944       Pragma_Import_Procedure               =>  0,
14945       Pragma_Import_Valued_Procedure        =>  0,
14946       Pragma_Independent                    =>  0,
14947       Pragma_Independent_Components         =>  0,
14948       Pragma_Initialize_Scalars             => -1,
14949       Pragma_Inline                         =>  0,
14950       Pragma_Inline_Always                  =>  0,
14951       Pragma_Inline_Generic                 =>  0,
14952       Pragma_Inspection_Point               => -1,
14953       Pragma_Interface                      => +2,
14954       Pragma_Interface_Name                 => +2,
14955       Pragma_Interrupt_Handler              => -1,
14956       Pragma_Interrupt_Priority             => -1,
14957       Pragma_Interrupt_State                => -1,
14958       Pragma_Invariant                      => -1,
14959       Pragma_Java_Constructor               => -1,
14960       Pragma_Java_Interface                 => -1,
14961       Pragma_Keep_Names                     =>  0,
14962       Pragma_License                        => -1,
14963       Pragma_Link_With                      => -1,
14964       Pragma_Linker_Alias                   => -1,
14965       Pragma_Linker_Constructor             => -1,
14966       Pragma_Linker_Destructor              => -1,
14967       Pragma_Linker_Options                 => -1,
14968       Pragma_Linker_Section                 => -1,
14969       Pragma_List                           => -1,
14970       Pragma_Locking_Policy                 => -1,
14971       Pragma_Long_Float                     => -1,
14972       Pragma_Machine_Attribute              => -1,
14973       Pragma_Main                           => -1,
14974       Pragma_Main_Storage                   => -1,
14975       Pragma_Memory_Size                    => -1,
14976       Pragma_No_Return                      =>  0,
14977       Pragma_No_Body                        =>  0,
14978       Pragma_No_Run_Time                    => -1,
14979       Pragma_No_Strict_Aliasing             => -1,
14980       Pragma_Normalize_Scalars              => -1,
14981       Pragma_Obsolescent                    =>  0,
14982       Pragma_Optimize                       => -1,
14983       Pragma_Optimize_Alignment             => -1,
14984       Pragma_Ordered                        =>  0,
14985       Pragma_Pack                           =>  0,
14986       Pragma_Page                           => -1,
14987       Pragma_Passive                        => -1,
14988       Pragma_Preelaborable_Initialization   => -1,
14989       Pragma_Polling                        => -1,
14990       Pragma_Persistent_BSS                 =>  0,
14991       Pragma_Postcondition                  => -1,
14992       Pragma_Precondition                   => -1,
14993       Pragma_Predicate                      => -1,
14994       Pragma_Preelaborate                   => -1,
14995       Pragma_Preelaborate_05                => -1,
14996       Pragma_Priority                       => -1,
14997       Pragma_Priority_Specific_Dispatching  => -1,
14998       Pragma_Profile                        =>  0,
14999       Pragma_Profile_Warnings               =>  0,
15000       Pragma_Propagate_Exceptions           => -1,
15001       Pragma_Psect_Object                   => -1,
15002       Pragma_Pure                           => -1,
15003       Pragma_Pure_05                        => -1,
15004       Pragma_Pure_12                        => -1,
15005       Pragma_Pure_Function                  => -1,
15006       Pragma_Queuing_Policy                 => -1,
15007       Pragma_Ravenscar                      => -1,
15008       Pragma_Relative_Deadline              => -1,
15009       Pragma_Remote_Call_Interface          => -1,
15010       Pragma_Remote_Types                   => -1,
15011       Pragma_Restricted_Run_Time            => -1,
15012       Pragma_Restriction_Warnings           => -1,
15013       Pragma_Restrictions                   => -1,
15014       Pragma_Reviewable                     => -1,
15015       Pragma_Short_Circuit_And_Or           => -1,
15016       Pragma_Share_Generic                  => -1,
15017       Pragma_Shared                         => -1,
15018       Pragma_Shared_Passive                 => -1,
15019       Pragma_Short_Descriptors              =>  0,
15020       Pragma_Source_File_Name               => -1,
15021       Pragma_Source_File_Name_Project       => -1,
15022       Pragma_Source_Reference               => -1,
15023       Pragma_Storage_Size                   => -1,
15024       Pragma_Storage_Unit                   => -1,
15025       Pragma_Static_Elaboration_Desired     => -1,
15026       Pragma_Stream_Convert                 => -1,
15027       Pragma_Style_Checks                   => -1,
15028       Pragma_Subtitle                       => -1,
15029       Pragma_Suppress                       =>  0,
15030       Pragma_Suppress_Exception_Locations   =>  0,
15031       Pragma_Suppress_All                   => -1,
15032       Pragma_Suppress_Debug_Info            =>  0,
15033       Pragma_Suppress_Initialization        =>  0,
15034       Pragma_System_Name                    => -1,
15035       Pragma_Task_Dispatching_Policy        => -1,
15036       Pragma_Task_Info                      => -1,
15037       Pragma_Task_Name                      => -1,
15038       Pragma_Task_Storage                   =>  0,
15039       Pragma_Test_Case                      => -1,
15040       Pragma_Thread_Local_Storage           =>  0,
15041       Pragma_Time_Slice                     => -1,
15042       Pragma_Title                          => -1,
15043       Pragma_Unchecked_Union                =>  0,
15044       Pragma_Unimplemented_Unit             => -1,
15045       Pragma_Universal_Aliasing             => -1,
15046       Pragma_Universal_Data                 => -1,
15047       Pragma_Unmodified                     => -1,
15048       Pragma_Unreferenced                   => -1,
15049       Pragma_Unreferenced_Objects           => -1,
15050       Pragma_Unreserve_All_Interrupts       => -1,
15051       Pragma_Unsuppress                     =>  0,
15052       Pragma_Use_VADS_Size                  => -1,
15053       Pragma_Validity_Checks                => -1,
15054       Pragma_Volatile                       =>  0,
15055       Pragma_Volatile_Components            =>  0,
15056       Pragma_Warnings                       => -1,
15057       Pragma_Weak_External                  => -1,
15058       Pragma_Wide_Character_Encoding        =>  0,
15059       Unknown_Pragma                        =>  0);
15060
15061    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15062       Id : Pragma_Id;
15063       P  : Node_Id;
15064       C  : Int;
15065       A  : Node_Id;
15066
15067    begin
15068       P := Parent (N);
15069
15070       if Nkind (P) /= N_Pragma_Argument_Association then
15071          return False;
15072
15073       else
15074          Id := Get_Pragma_Id (Parent (P));
15075          C := Sig_Flags (Id);
15076
15077          case C is
15078             when -1 =>
15079                return False;
15080
15081             when 0 =>
15082                return True;
15083
15084             when 99 =>
15085                case Id is
15086
15087                   --  For pragma Check, the first argument is not significant,
15088                   --  the second and the third (if present) arguments are
15089                   --  significant.
15090
15091                   when Pragma_Check =>
15092                      return
15093                        P = First (Pragma_Argument_Associations (Parent (P)));
15094
15095                   when others =>
15096                      raise Program_Error;
15097                end case;
15098
15099             when others =>
15100                A := First (Pragma_Argument_Associations (Parent (P)));
15101                for J in 1 .. C - 1 loop
15102                   if No (A) then
15103                      return False;
15104                   end if;
15105
15106                   Next (A);
15107                end loop;
15108
15109                return A = P; -- is this wrong way round ???
15110          end case;
15111       end if;
15112    end Is_Non_Significant_Pragma_Reference;
15113
15114    ------------------------------
15115    -- Is_Pragma_String_Literal --
15116    ------------------------------
15117
15118    --  This function returns true if the corresponding pragma argument is a
15119    --  static string expression. These are the only cases in which string
15120    --  literals can appear as pragma arguments. We also allow a string literal
15121    --  as the first argument to pragma Assert (although it will of course
15122    --  always generate a type error).
15123
15124    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15125       Pragn : constant Node_Id := Parent (Par);
15126       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15127       Pname : constant Name_Id := Pragma_Name (Pragn);
15128       Argn  : Natural;
15129       N     : Node_Id;
15130
15131    begin
15132       Argn := 1;
15133       N := First (Assoc);
15134       loop
15135          exit when N = Par;
15136          Argn := Argn + 1;
15137          Next (N);
15138       end loop;
15139
15140       if Pname = Name_Assert then
15141          return True;
15142
15143       elsif Pname = Name_Export then
15144          return Argn > 2;
15145
15146       elsif Pname = Name_Ident then
15147          return Argn = 1;
15148
15149       elsif Pname = Name_Import then
15150          return Argn > 2;
15151
15152       elsif Pname = Name_Interface_Name then
15153          return Argn > 1;
15154
15155       elsif Pname = Name_Linker_Alias then
15156          return Argn = 2;
15157
15158       elsif Pname = Name_Linker_Section then
15159          return Argn = 2;
15160
15161       elsif Pname = Name_Machine_Attribute then
15162          return Argn = 2;
15163
15164       elsif Pname = Name_Source_File_Name then
15165          return True;
15166
15167       elsif Pname = Name_Source_Reference then
15168          return Argn = 2;
15169
15170       elsif Pname = Name_Title then
15171          return True;
15172
15173       elsif Pname = Name_Subtitle then
15174          return True;
15175
15176       else
15177          return False;
15178       end if;
15179    end Is_Pragma_String_Literal;
15180
15181    ------------------------
15182    -- Preanalyze_TC_Args --
15183    ------------------------
15184
15185    procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15186    begin
15187       --  Preanalyze the boolean expressions, we treat these as spec
15188       --  expressions (i.e. similar to a default expression).
15189
15190       if Present (Arg_Req) then
15191          Preanalyze_Spec_Expression
15192            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15193
15194          --  In ASIS mode, for a pragma generated from a source aspect, also
15195          --  analyze the original aspect expression.
15196
15197          if ASIS_Mode
15198            and then Present (Corresponding_Aspect (N))
15199          then
15200             Preanalyze_Spec_Expression
15201               (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15202          end if;
15203       end if;
15204
15205       if Present (Arg_Ens) then
15206          Preanalyze_Spec_Expression
15207            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15208
15209          --  In ASIS mode, for a pragma generated from a source aspect, also
15210          --  analyze the original aspect expression.
15211
15212          if ASIS_Mode
15213            and then Present (Corresponding_Aspect (N))
15214          then
15215             Preanalyze_Spec_Expression
15216               (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15217          end if;
15218       end if;
15219    end Preanalyze_TC_Args;
15220
15221    --------------------------------------
15222    -- Process_Compilation_Unit_Pragmas --
15223    --------------------------------------
15224
15225    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15226    begin
15227       --  A special check for pragma Suppress_All, a very strange DEC pragma,
15228       --  strange because it comes at the end of the unit. Rational has the
15229       --  same name for a pragma, but treats it as a program unit pragma, In
15230       --  GNAT we just decide to allow it anywhere at all. If it appeared then
15231       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
15232       --  node, and we insert a pragma Suppress (All_Checks) at the start of
15233       --  the context clause to ensure the correct processing.
15234
15235       if Has_Pragma_Suppress_All (N) then
15236          Prepend_To (Context_Items (N),
15237            Make_Pragma (Sloc (N),
15238              Chars                        => Name_Suppress,
15239              Pragma_Argument_Associations => New_List (
15240                Make_Pragma_Argument_Association (Sloc (N),
15241                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15242       end if;
15243
15244       --  Nothing else to do at the current time!
15245
15246    end Process_Compilation_Unit_Pragmas;
15247
15248    --------
15249    -- rv --
15250    --------
15251
15252    procedure rv is
15253    begin
15254       null;
15255    end rv;
15256
15257    --------------------------------
15258    -- Set_Encoded_Interface_Name --
15259    --------------------------------
15260
15261    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15262       Str : constant String_Id := Strval (S);
15263       Len : constant Int       := String_Length (Str);
15264       CC  : Char_Code;
15265       C   : Character;
15266       J   : Int;
15267
15268       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15269
15270       procedure Encode;
15271       --  Stores encoded value of character code CC. The encoding we use an
15272       --  underscore followed by four lower case hex digits.
15273
15274       ------------
15275       -- Encode --
15276       ------------
15277
15278       procedure Encode is
15279       begin
15280          Store_String_Char (Get_Char_Code ('_'));
15281          Store_String_Char
15282            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15283          Store_String_Char
15284            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15285          Store_String_Char
15286            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15287          Store_String_Char
15288            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15289       end Encode;
15290
15291    --  Start of processing for Set_Encoded_Interface_Name
15292
15293    begin
15294       --  If first character is asterisk, this is a link name, and we leave it
15295       --  completely unmodified. We also ignore null strings (the latter case
15296       --  happens only in error cases) and no encoding should occur for Java or
15297       --  AAMP interface names.
15298
15299       if Len = 0
15300         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15301         or else VM_Target /= No_VM
15302         or else AAMP_On_Target
15303       then
15304          Set_Interface_Name (E, S);
15305
15306       else
15307          J := 1;
15308          loop
15309             CC := Get_String_Char (Str, J);
15310
15311             exit when not In_Character_Range (CC);
15312
15313             C := Get_Character (CC);
15314
15315             exit when C /= '_' and then C /= '$'
15316               and then C not in '0' .. '9'
15317               and then C not in 'a' .. 'z'
15318               and then C not in 'A' .. 'Z';
15319
15320             if J = Len then
15321                Set_Interface_Name (E, S);
15322                return;
15323
15324             else
15325                J := J + 1;
15326             end if;
15327          end loop;
15328
15329          --  Here we need to encode. The encoding we use as follows:
15330          --     three underscores  + four hex digits (lower case)
15331
15332          Start_String;
15333
15334          for J in 1 .. String_Length (Str) loop
15335             CC := Get_String_Char (Str, J);
15336
15337             if not In_Character_Range (CC) then
15338                Encode;
15339             else
15340                C := Get_Character (CC);
15341
15342                if C = '_' or else C = '$'
15343                  or else C in '0' .. '9'
15344                  or else C in 'a' .. 'z'
15345                  or else C in 'A' .. 'Z'
15346                then
15347                   Store_String_Char (CC);
15348                else
15349                   Encode;
15350                end if;
15351             end if;
15352          end loop;
15353
15354          Set_Interface_Name (E,
15355            Make_String_Literal (Sloc (S),
15356              Strval => End_String));
15357       end if;
15358    end Set_Encoded_Interface_Name;
15359
15360    -------------------
15361    -- Set_Unit_Name --
15362    -------------------
15363
15364    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15365       Pref : Node_Id;
15366       Scop : Entity_Id;
15367
15368    begin
15369       if Nkind (N) = N_Identifier
15370         and then Nkind (With_Item) = N_Identifier
15371       then
15372          Set_Entity (N, Entity (With_Item));
15373
15374       elsif Nkind (N) = N_Selected_Component then
15375          Change_Selected_Component_To_Expanded_Name (N);
15376          Set_Entity (N, Entity (With_Item));
15377          Set_Entity (Selector_Name (N), Entity (N));
15378
15379          Pref := Prefix (N);
15380          Scop := Scope (Entity (N));
15381          while Nkind (Pref) = N_Selected_Component loop
15382             Change_Selected_Component_To_Expanded_Name (Pref);
15383             Set_Entity (Selector_Name (Pref), Scop);
15384             Set_Entity (Pref, Scop);
15385             Pref := Prefix (Pref);
15386             Scop := Scope (Scop);
15387          end loop;
15388
15389          Set_Entity (Pref, Scop);
15390       end if;
15391    end Set_Unit_Name;
15392
15393 end Sem_Prag;