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          --  Stdcall case
3528
3529          if C = Convention_Stdcall
3530
3531             --  Subprogram is allowed, but not a generic subprogram, and not a
3532             --  dispatching operation. A dispatching subprogram cannot be used
3533             --  to interface to the Win32 API, so in fact this check does not
3534             --  impose any effective restriction.
3535
3536            and then
3537              ((not Is_Subprogram (E) and then not Is_Generic_Subprogram (E))
3538                 or else Is_Dispatching_Operation (E))
3539
3540             --  A variable is OK
3541
3542            and then Ekind (E) /= E_Variable
3543
3544            --  An access to subprogram is also allowed
3545
3546            and then not
3547              (Is_Access_Type (E)
3548                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3549          then
3550             Error_Pragma_Arg
3551               ("second argument of pragma% must be subprogram (type)",
3552                Arg2);
3553          end if;
3554
3555          if not Is_Subprogram (E)
3556            and then not Is_Generic_Subprogram (E)
3557          then
3558             Set_Convention_From_Pragma (E);
3559
3560             if Is_Type (E) then
3561                Check_First_Subtype (Arg2);
3562                Set_Convention_From_Pragma (Base_Type (E));
3563
3564                --  For subprograms, we must set the convention on the
3565                --  internally generated directly designated type as well.
3566
3567                if Ekind (E) = E_Access_Subprogram_Type then
3568                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3569                end if;
3570             end if;
3571
3572          --  For the subprogram case, set proper convention for all homonyms
3573          --  in same scope and the same declarative part, i.e. the same
3574          --  compilation unit.
3575
3576          else
3577             Comp_Unit := Get_Source_Unit (E);
3578             Set_Convention_From_Pragma (E);
3579
3580             --  Treat a pragma Import as an implicit body, for GPS use
3581
3582             if Prag_Id = Pragma_Import then
3583                Generate_Reference (E, Id, 'b');
3584             end if;
3585
3586             --  Loop through the homonyms of the pragma argument's entity
3587
3588             E1 := Ent;
3589             loop
3590                E1 := Homonym (E1);
3591                exit when No (E1) or else Scope (E1) /= Current_Scope;
3592
3593                --  Do not set the pragma on inherited operations or on formal
3594                --  subprograms.
3595
3596                if Comes_From_Source (E1)
3597                  and then Comp_Unit = Get_Source_Unit (E1)
3598                  and then not Is_Formal_Subprogram (E1)
3599                  and then Nkind (Original_Node (Parent (E1))) /=
3600                                                     N_Full_Type_Declaration
3601                then
3602                   if Present (Alias (E1))
3603                     and then Scope (E1) /= Scope (Alias (E1))
3604                   then
3605                      Error_Pragma_Ref
3606                        ("cannot apply pragma% to non-local entity& declared#",
3607                         E1);
3608                   end if;
3609
3610                   Set_Convention_From_Pragma (E1);
3611
3612                   if Prag_Id = Pragma_Import then
3613                      Generate_Reference (E1, Id, 'b');
3614                   end if;
3615                end if;
3616
3617                --  For aspect case, do NOT apply to homonyms
3618
3619                exit when From_Aspect_Specification (N);
3620             end loop;
3621          end if;
3622       end Process_Convention;
3623
3624       ----------------------------------------
3625       -- Process_Disable_Enable_Atomic_Sync --
3626       ----------------------------------------
3627
3628       procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3629       begin
3630          GNAT_Pragma;
3631          Check_No_Identifiers;
3632          Check_At_Most_N_Arguments (1);
3633
3634          --  Modeled internally as
3635          --    pragma Unsuppress (Atomic_Synchronization [,Entity])
3636
3637          Rewrite (N,
3638            Make_Pragma (Loc,
3639              Pragma_Identifier            =>
3640                Make_Identifier (Loc, Nam),
3641              Pragma_Argument_Associations => New_List (
3642                Make_Pragma_Argument_Association (Loc,
3643                  Expression =>
3644                    Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3645
3646          if Present (Arg1) then
3647             Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3648          end if;
3649
3650          Analyze (N);
3651       end Process_Disable_Enable_Atomic_Sync;
3652
3653       -----------------------------------------------------
3654       -- Process_Extended_Import_Export_Exception_Pragma --
3655       -----------------------------------------------------
3656
3657       procedure Process_Extended_Import_Export_Exception_Pragma
3658         (Arg_Internal : Node_Id;
3659          Arg_External : Node_Id;
3660          Arg_Form     : Node_Id;
3661          Arg_Code     : Node_Id)
3662       is
3663          Def_Id   : Entity_Id;
3664          Code_Val : Uint;
3665
3666       begin
3667          if not OpenVMS_On_Target then
3668             Error_Pragma
3669               ("?pragma% ignored (applies only to Open'V'M'S)");
3670          end if;
3671
3672          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3673          Def_Id := Entity (Arg_Internal);
3674
3675          if Ekind (Def_Id) /= E_Exception then
3676             Error_Pragma_Arg
3677               ("pragma% must refer to declared exception", Arg_Internal);
3678          end if;
3679
3680          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3681
3682          if Present (Arg_Form) then
3683             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3684          end if;
3685
3686          if Present (Arg_Form)
3687            and then Chars (Arg_Form) = Name_Ada
3688          then
3689             null;
3690          else
3691             Set_Is_VMS_Exception (Def_Id);
3692             Set_Exception_Code (Def_Id, No_Uint);
3693          end if;
3694
3695          if Present (Arg_Code) then
3696             if not Is_VMS_Exception (Def_Id) then
3697                Error_Pragma_Arg
3698                  ("Code option for pragma% not allowed for Ada case",
3699                   Arg_Code);
3700             end if;
3701
3702             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3703             Code_Val := Expr_Value (Arg_Code);
3704
3705             if not UI_Is_In_Int_Range (Code_Val) then
3706                Error_Pragma_Arg
3707                  ("Code option for pragma% must be in 32-bit range",
3708                   Arg_Code);
3709
3710             else
3711                Set_Exception_Code (Def_Id, Code_Val);
3712             end if;
3713          end if;
3714       end Process_Extended_Import_Export_Exception_Pragma;
3715
3716       -------------------------------------------------
3717       -- Process_Extended_Import_Export_Internal_Arg --
3718       -------------------------------------------------
3719
3720       procedure Process_Extended_Import_Export_Internal_Arg
3721         (Arg_Internal : Node_Id := Empty)
3722       is
3723       begin
3724          if No (Arg_Internal) then
3725             Error_Pragma ("Internal parameter required for pragma%");
3726          end if;
3727
3728          if Nkind (Arg_Internal) = N_Identifier then
3729             null;
3730
3731          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3732            and then (Prag_Id = Pragma_Import_Function
3733                        or else
3734                      Prag_Id = Pragma_Export_Function)
3735          then
3736             null;
3737
3738          else
3739             Error_Pragma_Arg
3740               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3741          end if;
3742
3743          Check_Arg_Is_Local_Name (Arg_Internal);
3744       end Process_Extended_Import_Export_Internal_Arg;
3745
3746       --------------------------------------------------
3747       -- Process_Extended_Import_Export_Object_Pragma --
3748       --------------------------------------------------
3749
3750       procedure Process_Extended_Import_Export_Object_Pragma
3751         (Arg_Internal : Node_Id;
3752          Arg_External : Node_Id;
3753          Arg_Size     : Node_Id)
3754       is
3755          Def_Id : Entity_Id;
3756
3757       begin
3758          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3759          Def_Id := Entity (Arg_Internal);
3760
3761          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3762             Error_Pragma_Arg
3763               ("pragma% must designate an object", Arg_Internal);
3764          end if;
3765
3766          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3767               or else
3768             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3769          then
3770             Error_Pragma_Arg
3771               ("previous Common/Psect_Object applies, pragma % not permitted",
3772                Arg_Internal);
3773          end if;
3774
3775          if Rep_Item_Too_Late (Def_Id, N) then
3776             raise Pragma_Exit;
3777          end if;
3778
3779          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3780
3781          if Present (Arg_Size) then
3782             Check_Arg_Is_External_Name (Arg_Size);
3783          end if;
3784
3785          --  Export_Object case
3786
3787          if Prag_Id = Pragma_Export_Object then
3788             if not Is_Library_Level_Entity (Def_Id) then
3789                Error_Pragma_Arg
3790                  ("argument for pragma% must be library level entity",
3791                   Arg_Internal);
3792             end if;
3793
3794             if Ekind (Current_Scope) = E_Generic_Package then
3795                Error_Pragma ("pragma& cannot appear in a generic unit");
3796             end if;
3797
3798             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3799                Error_Pragma_Arg
3800                  ("exported object must have compile time known size",
3801                   Arg_Internal);
3802             end if;
3803
3804             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3805                Error_Msg_N ("?duplicate Export_Object pragma", N);
3806             else
3807                Set_Exported (Def_Id, Arg_Internal);
3808             end if;
3809
3810          --  Import_Object case
3811
3812          else
3813             if Is_Concurrent_Type (Etype (Def_Id)) then
3814                Error_Pragma_Arg
3815                  ("cannot use pragma% for task/protected object",
3816                   Arg_Internal);
3817             end if;
3818
3819             if Ekind (Def_Id) = E_Constant then
3820                Error_Pragma_Arg
3821                  ("cannot import a constant", Arg_Internal);
3822             end if;
3823
3824             if Warn_On_Export_Import
3825               and then Has_Discriminants (Etype (Def_Id))
3826             then
3827                Error_Msg_N
3828                  ("imported value must be initialized?", Arg_Internal);
3829             end if;
3830
3831             if Warn_On_Export_Import
3832               and then Is_Access_Type (Etype (Def_Id))
3833             then
3834                Error_Pragma_Arg
3835                  ("cannot import object of an access type?", Arg_Internal);
3836             end if;
3837
3838             if Warn_On_Export_Import
3839               and then Is_Imported (Def_Id)
3840             then
3841                Error_Msg_N
3842                  ("?duplicate Import_Object pragma", N);
3843
3844             --  Check for explicit initialization present. Note that an
3845             --  initialization generated by the code generator, e.g. for an
3846             --  access type, does not count here.
3847
3848             elsif Present (Expression (Parent (Def_Id)))
3849                and then
3850                  Comes_From_Source
3851                    (Original_Node (Expression (Parent (Def_Id))))
3852             then
3853                Error_Msg_Sloc := Sloc (Def_Id);
3854                Error_Pragma_Arg
3855                  ("imported entities cannot be initialized (RM B.1(24))",
3856                   "\no initialization allowed for & declared#", Arg1);
3857             else
3858                Set_Imported (Def_Id);
3859                Note_Possible_Modification (Arg_Internal, Sure => False);
3860             end if;
3861          end if;
3862       end Process_Extended_Import_Export_Object_Pragma;
3863
3864       ------------------------------------------------------
3865       -- Process_Extended_Import_Export_Subprogram_Pragma --
3866       ------------------------------------------------------
3867
3868       procedure Process_Extended_Import_Export_Subprogram_Pragma
3869         (Arg_Internal                 : Node_Id;
3870          Arg_External                 : Node_Id;
3871          Arg_Parameter_Types          : Node_Id;
3872          Arg_Result_Type              : Node_Id := Empty;
3873          Arg_Mechanism                : Node_Id;
3874          Arg_Result_Mechanism         : Node_Id := Empty;
3875          Arg_First_Optional_Parameter : Node_Id := Empty)
3876       is
3877          Ent       : Entity_Id;
3878          Def_Id    : Entity_Id;
3879          Hom_Id    : Entity_Id;
3880          Formal    : Entity_Id;
3881          Ambiguous : Boolean;
3882          Match     : Boolean;
3883          Dval      : Node_Id;
3884
3885          function Same_Base_Type
3886           (Ptype  : Node_Id;
3887            Formal : Entity_Id) return Boolean;
3888          --  Determines if Ptype references the type of Formal. Note that only
3889          --  the base types need to match according to the spec. Ptype here is
3890          --  the argument from the pragma, which is either a type name, or an
3891          --  access attribute.
3892
3893          --------------------
3894          -- Same_Base_Type --
3895          --------------------
3896
3897          function Same_Base_Type
3898            (Ptype  : Node_Id;
3899             Formal : Entity_Id) return Boolean
3900          is
3901             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3902             Pref : Node_Id;
3903
3904          begin
3905             --  Case where pragma argument is typ'Access
3906
3907             if Nkind (Ptype) = N_Attribute_Reference
3908               and then Attribute_Name (Ptype) = Name_Access
3909             then
3910                Pref := Prefix (Ptype);
3911                Find_Type (Pref);
3912
3913                if not Is_Entity_Name (Pref)
3914                  or else Entity (Pref) = Any_Type
3915                then
3916                   raise Pragma_Exit;
3917                end if;
3918
3919                --  We have a match if the corresponding argument is of an
3920                --  anonymous access type, and its designated type matches the
3921                --  type of the prefix of the access attribute
3922
3923                return Ekind (Ftyp) = E_Anonymous_Access_Type
3924                  and then Base_Type (Entity (Pref)) =
3925                             Base_Type (Etype (Designated_Type (Ftyp)));
3926
3927             --  Case where pragma argument is a type name
3928
3929             else
3930                Find_Type (Ptype);
3931
3932                if not Is_Entity_Name (Ptype)
3933                  or else Entity (Ptype) = Any_Type
3934                then
3935                   raise Pragma_Exit;
3936                end if;
3937
3938                --  We have a match if the corresponding argument is of the type
3939                --  given in the pragma (comparing base types)
3940
3941                return Base_Type (Entity (Ptype)) = Ftyp;
3942             end if;
3943          end Same_Base_Type;
3944
3945       --  Start of processing for
3946       --  Process_Extended_Import_Export_Subprogram_Pragma
3947
3948       begin
3949          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3950          Ent := Empty;
3951          Ambiguous := False;
3952
3953          --  Loop through homonyms (overloadings) of the entity
3954
3955          Hom_Id := Entity (Arg_Internal);
3956          while Present (Hom_Id) loop
3957             Def_Id := Get_Base_Subprogram (Hom_Id);
3958
3959             --  We need a subprogram in the current scope
3960
3961             if not Is_Subprogram (Def_Id)
3962               or else Scope (Def_Id) /= Current_Scope
3963             then
3964                null;
3965
3966             else
3967                Match := True;
3968
3969                --  Pragma cannot apply to subprogram body
3970
3971                if Is_Subprogram (Def_Id)
3972                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3973                                                              N_Subprogram_Body
3974                then
3975                   Error_Pragma
3976                     ("pragma% requires separate spec"
3977                       & " and must come before body");
3978                end if;
3979
3980                --  Test result type if given, note that the result type
3981                --  parameter can only be present for the function cases.
3982
3983                if Present (Arg_Result_Type)
3984                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3985                then
3986                   Match := False;
3987
3988                elsif Etype (Def_Id) /= Standard_Void_Type
3989                  and then
3990                    (Pname = Name_Export_Procedure
3991                       or else
3992                     Pname = Name_Import_Procedure)
3993                then
3994                   Match := False;
3995
3996                --  Test parameter types if given. Note that this parameter
3997                --  has not been analyzed (and must not be, since it is
3998                --  semantic nonsense), so we get it as the parser left it.
3999
4000                elsif Present (Arg_Parameter_Types) then
4001                   Check_Matching_Types : declare
4002                      Formal : Entity_Id;
4003                      Ptype  : Node_Id;
4004
4005                   begin
4006                      Formal := First_Formal (Def_Id);
4007
4008                      if Nkind (Arg_Parameter_Types) = N_Null then
4009                         if Present (Formal) then
4010                            Match := False;
4011                         end if;
4012
4013                      --  A list of one type, e.g. (List) is parsed as
4014                      --  a parenthesized expression.
4015
4016                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4017                        and then Paren_Count (Arg_Parameter_Types) = 1
4018                      then
4019                         if No (Formal)
4020                           or else Present (Next_Formal (Formal))
4021                         then
4022                            Match := False;
4023                         else
4024                            Match :=
4025                              Same_Base_Type (Arg_Parameter_Types, Formal);
4026                         end if;
4027
4028                      --  A list of more than one type is parsed as a aggregate
4029
4030                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4031                        and then Paren_Count (Arg_Parameter_Types) = 0
4032                      then
4033                         Ptype := First (Expressions (Arg_Parameter_Types));
4034                         while Present (Ptype) or else Present (Formal) loop
4035                            if No (Ptype)
4036                              or else No (Formal)
4037                              or else not Same_Base_Type (Ptype, Formal)
4038                            then
4039                               Match := False;
4040                               exit;
4041                            else
4042                               Next_Formal (Formal);
4043                               Next (Ptype);
4044                            end if;
4045                         end loop;
4046
4047                      --  Anything else is of the wrong form
4048
4049                      else
4050                         Error_Pragma_Arg
4051                           ("wrong form for Parameter_Types parameter",
4052                            Arg_Parameter_Types);
4053                      end if;
4054                   end Check_Matching_Types;
4055                end if;
4056
4057                --  Match is now False if the entry we found did not match
4058                --  either a supplied Parameter_Types or Result_Types argument
4059
4060                if Match then
4061                   if No (Ent) then
4062                      Ent := Def_Id;
4063
4064                   --  Ambiguous case, the flag Ambiguous shows if we already
4065                   --  detected this and output the initial messages.
4066
4067                   else
4068                      if not Ambiguous then
4069                         Ambiguous := True;
4070                         Error_Msg_Name_1 := Pname;
4071                         Error_Msg_N
4072                           ("pragma% does not uniquely identify subprogram!",
4073                            N);
4074                         Error_Msg_Sloc := Sloc (Ent);
4075                         Error_Msg_N ("matching subprogram #!", N);
4076                         Ent := Empty;
4077                      end if;
4078
4079                      Error_Msg_Sloc := Sloc (Def_Id);
4080                      Error_Msg_N ("matching subprogram #!", N);
4081                   end if;
4082                end if;
4083             end if;
4084
4085             Hom_Id := Homonym (Hom_Id);
4086          end loop;
4087
4088          --  See if we found an entry
4089
4090          if No (Ent) then
4091             if not Ambiguous then
4092                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4093                   Error_Pragma
4094                     ("pragma% cannot be given for generic subprogram");
4095                else
4096                   Error_Pragma
4097                     ("pragma% does not identify local subprogram");
4098                end if;
4099             end if;
4100
4101             return;
4102          end if;
4103
4104          --  Import pragmas must be for imported entities
4105
4106          if Prag_Id = Pragma_Import_Function
4107               or else
4108             Prag_Id = Pragma_Import_Procedure
4109               or else
4110             Prag_Id = Pragma_Import_Valued_Procedure
4111          then
4112             if not Is_Imported (Ent) then
4113                Error_Pragma
4114                  ("pragma Import or Interface must precede pragma%");
4115             end if;
4116
4117          --  Here we have the Export case which can set the entity as exported
4118
4119          --  But does not do so if the specified external name is null, since
4120          --  that is taken as a signal in DEC Ada 83 (with which we want to be
4121          --  compatible) to request no external name.
4122
4123          elsif Nkind (Arg_External) = N_String_Literal
4124            and then String_Length (Strval (Arg_External)) = 0
4125          then
4126             null;
4127
4128          --  In all other cases, set entity as exported
4129
4130          else
4131             Set_Exported (Ent, Arg_Internal);
4132          end if;
4133
4134          --  Special processing for Valued_Procedure cases
4135
4136          if Prag_Id = Pragma_Import_Valued_Procedure
4137            or else
4138             Prag_Id = Pragma_Export_Valued_Procedure
4139          then
4140             Formal := First_Formal (Ent);
4141
4142             if No (Formal) then
4143                Error_Pragma ("at least one parameter required for pragma%");
4144
4145             elsif Ekind (Formal) /= E_Out_Parameter then
4146                Error_Pragma ("first parameter must have mode out for pragma%");
4147
4148             else
4149                Set_Is_Valued_Procedure (Ent);
4150             end if;
4151          end if;
4152
4153          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4154
4155          --  Process Result_Mechanism argument if present. We have already
4156          --  checked that this is only allowed for the function case.
4157
4158          if Present (Arg_Result_Mechanism) then
4159             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4160          end if;
4161
4162          --  Process Mechanism parameter if present. Note that this parameter
4163          --  is not analyzed, and must not be analyzed since it is semantic
4164          --  nonsense, so we get it in exactly as the parser left it.
4165
4166          if Present (Arg_Mechanism) then
4167             declare
4168                Formal : Entity_Id;
4169                Massoc : Node_Id;
4170                Mname  : Node_Id;
4171                Choice : Node_Id;
4172
4173             begin
4174                --  A single mechanism association without a formal parameter
4175                --  name is parsed as a parenthesized expression. All other
4176                --  cases are parsed as aggregates, so we rewrite the single
4177                --  parameter case as an aggregate for consistency.
4178
4179                if Nkind (Arg_Mechanism) /= N_Aggregate
4180                  and then Paren_Count (Arg_Mechanism) = 1
4181                then
4182                   Rewrite (Arg_Mechanism,
4183                     Make_Aggregate (Sloc (Arg_Mechanism),
4184                       Expressions => New_List (
4185                         Relocate_Node (Arg_Mechanism))));
4186                end if;
4187
4188                --  Case of only mechanism name given, applies to all formals
4189
4190                if Nkind (Arg_Mechanism) /= N_Aggregate then
4191                   Formal := First_Formal (Ent);
4192                   while Present (Formal) loop
4193                      Set_Mechanism_Value (Formal, Arg_Mechanism);
4194                      Next_Formal (Formal);
4195                   end loop;
4196
4197                --  Case of list of mechanism associations given
4198
4199                else
4200                   if Null_Record_Present (Arg_Mechanism) then
4201                      Error_Pragma_Arg
4202                        ("inappropriate form for Mechanism parameter",
4203                         Arg_Mechanism);
4204                   end if;
4205
4206                   --  Deal with positional ones first
4207
4208                   Formal := First_Formal (Ent);
4209
4210                   if Present (Expressions (Arg_Mechanism)) then
4211                      Mname := First (Expressions (Arg_Mechanism));
4212                      while Present (Mname) loop
4213                         if No (Formal) then
4214                            Error_Pragma_Arg
4215                              ("too many mechanism associations", Mname);
4216                         end if;
4217
4218                         Set_Mechanism_Value (Formal, Mname);
4219                         Next_Formal (Formal);
4220                         Next (Mname);
4221                      end loop;
4222                   end if;
4223
4224                   --  Deal with named entries
4225
4226                   if Present (Component_Associations (Arg_Mechanism)) then
4227                      Massoc := First (Component_Associations (Arg_Mechanism));
4228                      while Present (Massoc) loop
4229                         Choice := First (Choices (Massoc));
4230
4231                         if Nkind (Choice) /= N_Identifier
4232                           or else Present (Next (Choice))
4233                         then
4234                            Error_Pragma_Arg
4235                              ("incorrect form for mechanism association",
4236                               Massoc);
4237                         end if;
4238
4239                         Formal := First_Formal (Ent);
4240                         loop
4241                            if No (Formal) then
4242                               Error_Pragma_Arg
4243                                 ("parameter name & not present", Choice);
4244                            end if;
4245
4246                            if Chars (Choice) = Chars (Formal) then
4247                               Set_Mechanism_Value
4248                                 (Formal, Expression (Massoc));
4249
4250                               --  Set entity on identifier (needed by ASIS)
4251
4252                               Set_Entity (Choice, Formal);
4253
4254                               exit;
4255                            end if;
4256
4257                            Next_Formal (Formal);
4258                         end loop;
4259
4260                         Next (Massoc);
4261                      end loop;
4262                   end if;
4263                end if;
4264             end;
4265          end if;
4266
4267          --  Process First_Optional_Parameter argument if present. We have
4268          --  already checked that this is only allowed for the Import case.
4269
4270          if Present (Arg_First_Optional_Parameter) then
4271             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4272                Error_Pragma_Arg
4273                  ("first optional parameter must be formal parameter name",
4274                   Arg_First_Optional_Parameter);
4275             end if;
4276
4277             Formal := First_Formal (Ent);
4278             loop
4279                if No (Formal) then
4280                   Error_Pragma_Arg
4281                     ("specified formal parameter& not found",
4282                      Arg_First_Optional_Parameter);
4283                end if;
4284
4285                exit when Chars (Formal) =
4286                          Chars (Arg_First_Optional_Parameter);
4287
4288                Next_Formal (Formal);
4289             end loop;
4290
4291             Set_First_Optional_Parameter (Ent, Formal);
4292
4293             --  Check specified and all remaining formals have right form
4294
4295             while Present (Formal) loop
4296                if Ekind (Formal) /= E_In_Parameter then
4297                   Error_Msg_NE
4298                     ("optional formal& is not of mode in!",
4299                      Arg_First_Optional_Parameter, Formal);
4300
4301                else
4302                   Dval := Default_Value (Formal);
4303
4304                   if No (Dval) then
4305                      Error_Msg_NE
4306                        ("optional formal& does not have default value!",
4307                         Arg_First_Optional_Parameter, Formal);
4308
4309                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4310                      null;
4311
4312                   else
4313                      Error_Msg_FE
4314                        ("default value for optional formal& is non-static!",
4315                         Arg_First_Optional_Parameter, Formal);
4316                   end if;
4317                end if;
4318
4319                Set_Is_Optional_Parameter (Formal);
4320                Next_Formal (Formal);
4321             end loop;
4322          end if;
4323       end Process_Extended_Import_Export_Subprogram_Pragma;
4324
4325       --------------------------
4326       -- Process_Generic_List --
4327       --------------------------
4328
4329       procedure Process_Generic_List is
4330          Arg : Node_Id;
4331          Exp : Node_Id;
4332
4333       begin
4334          Check_No_Identifiers;
4335          Check_At_Least_N_Arguments (1);
4336
4337          Arg := Arg1;
4338          while Present (Arg) loop
4339             Exp := Get_Pragma_Arg (Arg);
4340             Analyze (Exp);
4341
4342             if not Is_Entity_Name (Exp)
4343               or else
4344                 (not Is_Generic_Instance (Entity (Exp))
4345                   and then
4346                  not Is_Generic_Unit (Entity (Exp)))
4347             then
4348                Error_Pragma_Arg
4349                  ("pragma% argument must be name of generic unit/instance",
4350                   Arg);
4351             end if;
4352
4353             Next (Arg);
4354          end loop;
4355       end Process_Generic_List;
4356
4357       ------------------------------------
4358       -- Process_Import_Predefined_Type --
4359       ------------------------------------
4360
4361       procedure Process_Import_Predefined_Type is
4362          Loc  : constant Source_Ptr := Sloc (N);
4363          Elmt : Elmt_Id;
4364          Ftyp : Node_Id := Empty;
4365          Decl : Node_Id;
4366          Def  : Node_Id;
4367          Nam  : Name_Id;
4368
4369       begin
4370          String_To_Name_Buffer (Strval (Expression (Arg3)));
4371          Nam := Name_Find;
4372
4373          Elmt := First_Elmt (Predefined_Float_Types);
4374          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4375             Next_Elmt (Elmt);
4376          end loop;
4377
4378          Ftyp := Node (Elmt);
4379
4380          if Present (Ftyp) then
4381
4382             --  Don't build a derived type declaration, because predefined C
4383             --  types have no declaration anywhere, so cannot really be named.
4384             --  Instead build a full type declaration, starting with an
4385             --  appropriate type definition is built
4386
4387             if Is_Floating_Point_Type (Ftyp) then
4388                Def := Make_Floating_Point_Definition (Loc,
4389                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4390                  Make_Real_Range_Specification (Loc,
4391                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4392                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4393
4394             --  Should never have a predefined type we cannot handle
4395
4396             else
4397                raise Program_Error;
4398             end if;
4399
4400             --  Build and insert a Full_Type_Declaration, which will be
4401             --  analyzed as soon as this list entry has been analyzed.
4402
4403             Decl := Make_Full_Type_Declaration (Loc,
4404               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4405               Type_Definition => Def);
4406
4407             Insert_After (N, Decl);
4408             Mark_Rewrite_Insertion (Decl);
4409
4410          else
4411             Error_Pragma_Arg ("no matching type found for pragma%",
4412             Arg2);
4413          end if;
4414       end Process_Import_Predefined_Type;
4415
4416       ---------------------------------
4417       -- Process_Import_Or_Interface --
4418       ---------------------------------
4419
4420       procedure Process_Import_Or_Interface is
4421          C      : Convention_Id;
4422          Def_Id : Entity_Id;
4423          Hom_Id : Entity_Id;
4424
4425       begin
4426          Process_Convention (C, Def_Id);
4427          Kill_Size_Check_Code (Def_Id);
4428          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4429
4430          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4431
4432             --  We do not permit Import to apply to a renaming declaration
4433
4434             if Present (Renamed_Object (Def_Id)) then
4435                Error_Pragma_Arg
4436                  ("pragma% not allowed for object renaming", Arg2);
4437
4438             --  User initialization is not allowed for imported object, but
4439             --  the object declaration may contain a default initialization,
4440             --  that will be discarded. Note that an explicit initialization
4441             --  only counts if it comes from source, otherwise it is simply
4442             --  the code generator making an implicit initialization explicit.
4443
4444             elsif Present (Expression (Parent (Def_Id)))
4445               and then Comes_From_Source (Expression (Parent (Def_Id)))
4446             then
4447                Error_Msg_Sloc := Sloc (Def_Id);
4448                Error_Pragma_Arg
4449                  ("no initialization allowed for declaration of& #",
4450                   "\imported entities cannot be initialized (RM B.1(24))",
4451                   Arg2);
4452
4453             else
4454                Set_Imported (Def_Id);
4455                Process_Interface_Name (Def_Id, Arg3, Arg4);
4456
4457                --  Note that we do not set Is_Public here. That's because we
4458                --  only want to set it if there is no address clause, and we
4459                --  don't know that yet, so we delay that processing till
4460                --  freeze time.
4461
4462                --  pragma Import completes deferred constants
4463
4464                if Ekind (Def_Id) = E_Constant then
4465                   Set_Has_Completion (Def_Id);
4466                end if;
4467
4468                --  It is not possible to import a constant of an unconstrained
4469                --  array type (e.g. string) because there is no simple way to
4470                --  write a meaningful subtype for it.
4471
4472                if Is_Array_Type (Etype (Def_Id))
4473                  and then not Is_Constrained (Etype (Def_Id))
4474                then
4475                   Error_Msg_NE
4476                     ("imported constant& must have a constrained subtype",
4477                       N, Def_Id);
4478                end if;
4479             end if;
4480
4481          elsif Is_Subprogram (Def_Id)
4482            or else Is_Generic_Subprogram (Def_Id)
4483          then
4484             --  If the name is overloaded, pragma applies to all of the denoted
4485             --  entities in the same declarative part.
4486
4487             Hom_Id := Def_Id;
4488             while Present (Hom_Id) loop
4489                Def_Id := Get_Base_Subprogram (Hom_Id);
4490
4491                --  Ignore inherited subprograms because the pragma will apply
4492                --  to the parent operation, which is the one called.
4493
4494                if Is_Overloadable (Def_Id)
4495                  and then Present (Alias (Def_Id))
4496                then
4497                   null;
4498
4499                --  If it is not a subprogram, it must be in an outer scope and
4500                --  pragma does not apply.
4501
4502                elsif not Is_Subprogram (Def_Id)
4503                  and then not Is_Generic_Subprogram (Def_Id)
4504                then
4505                   null;
4506
4507                --  The pragma does not apply to primitives of interfaces
4508
4509                elsif Is_Dispatching_Operation (Def_Id)
4510                  and then Present (Find_Dispatching_Type (Def_Id))
4511                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4512                then
4513                   null;
4514
4515                --  Verify that the homonym is in the same declarative part (not
4516                --  just the same scope).
4517
4518                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4519                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4520                then
4521                   exit;
4522
4523                else
4524                   Set_Imported (Def_Id);
4525
4526                   --  Reject an Import applied to an abstract subprogram
4527
4528                   if Is_Subprogram (Def_Id)
4529                     and then Is_Abstract_Subprogram (Def_Id)
4530                   then
4531                      Error_Msg_Sloc := Sloc (Def_Id);
4532                      Error_Msg_NE
4533                        ("cannot import abstract subprogram& declared#",
4534                         Arg2, Def_Id);
4535                   end if;
4536
4537                   --  Special processing for Convention_Intrinsic
4538
4539                   if C = Convention_Intrinsic then
4540
4541                      --  Link_Name argument not allowed for intrinsic
4542
4543                      Check_No_Link_Name;
4544
4545                      Set_Is_Intrinsic_Subprogram (Def_Id);
4546
4547                      --  If no external name is present, then check that this
4548                      --  is a valid intrinsic subprogram. If an external name
4549                      --  is present, then this is handled by the back end.
4550
4551                      if No (Arg3) then
4552                         Check_Intrinsic_Subprogram
4553                           (Def_Id, Get_Pragma_Arg (Arg2));
4554                      end if;
4555                   end if;
4556
4557                   --  All interfaced procedures need an external symbol created
4558                   --  for them since they are always referenced from another
4559                   --  object file.
4560
4561                   Set_Is_Public (Def_Id);
4562
4563                   --  Verify that the subprogram does not have a completion
4564                   --  through a renaming declaration. For other completions the
4565                   --  pragma appears as a too late representation.
4566
4567                   declare
4568                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4569
4570                   begin
4571                      if Present (Decl)
4572                        and then Nkind (Decl) = N_Subprogram_Declaration
4573                        and then Present (Corresponding_Body (Decl))
4574                        and then Nkind (Unit_Declaration_Node
4575                                         (Corresponding_Body (Decl))) =
4576                                              N_Subprogram_Renaming_Declaration
4577                      then
4578                         Error_Msg_Sloc := Sloc (Def_Id);
4579                         Error_Msg_NE
4580                           ("cannot import&, renaming already provided for " &
4581                            "declaration #", N, Def_Id);
4582                      end if;
4583                   end;
4584
4585                   Set_Has_Completion (Def_Id);
4586                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4587                end if;
4588
4589                if Is_Compilation_Unit (Hom_Id) then
4590
4591                   --  Its possible homonyms are not affected by the pragma.
4592                   --  Such homonyms might be present in the context of other
4593                   --  units being compiled.
4594
4595                   exit;
4596
4597                else
4598                   Hom_Id := Homonym (Hom_Id);
4599                end if;
4600             end loop;
4601
4602          --  When the convention is Java or CIL, we also allow Import to be
4603          --  given for packages, generic packages, exceptions, record
4604          --  components, and access to subprograms.
4605
4606          elsif (C = Convention_Java or else C = Convention_CIL)
4607            and then
4608              (Is_Package_Or_Generic_Package (Def_Id)
4609                or else Ekind (Def_Id) = E_Exception
4610                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4611                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4612          then
4613             Set_Imported (Def_Id);
4614             Set_Is_Public (Def_Id);
4615             Process_Interface_Name (Def_Id, Arg3, Arg4);
4616
4617          --  Import a CPP class
4618
4619          elsif Is_Record_Type (Def_Id)
4620            and then C = Convention_CPP
4621          then
4622             --  Types treated as CPP classes must be declared limited (note:
4623             --  this used to be a warning but there is no real benefit to it
4624             --  since we did effectively intend to treat the type as limited
4625             --  anyway).
4626
4627             if not Is_Limited_Type (Def_Id) then
4628                Error_Msg_N
4629                  ("imported 'C'P'P type must be limited",
4630                   Get_Pragma_Arg (Arg2));
4631             end if;
4632
4633             Set_Is_CPP_Class (Def_Id);
4634
4635             --  Imported CPP types must not have discriminants (because C++
4636             --  classes do not have discriminants).
4637
4638             if Has_Discriminants (Def_Id) then
4639                Error_Msg_N
4640                  ("imported 'C'P'P type cannot have discriminants",
4641                   First (Discriminant_Specifications
4642                           (Declaration_Node (Def_Id))));
4643             end if;
4644
4645             --  Components of imported CPP types must not have default
4646             --  expressions because the constructor (if any) is on the
4647             --  C++ side.
4648
4649             declare
4650                Tdef  : constant Node_Id :=
4651                          Type_Definition (Declaration_Node (Def_Id));
4652                Clist : Node_Id;
4653                Comp  : Node_Id;
4654
4655             begin
4656                if Nkind (Tdef) = N_Record_Definition then
4657                   Clist := Component_List (Tdef);
4658
4659                else
4660                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4661                   Clist := Component_List (Record_Extension_Part (Tdef));
4662                end if;
4663
4664                if Present (Clist) then
4665                   Comp := First (Component_Items (Clist));
4666                   while Present (Comp) loop
4667                      if Present (Expression (Comp)) then
4668                         Error_Msg_N
4669                           ("component of imported 'C'P'P type cannot have" &
4670                            " default expression", Expression (Comp));
4671                      end if;
4672
4673                      Next (Comp);
4674                   end loop;
4675                end if;
4676             end;
4677
4678          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4679             Check_No_Link_Name;
4680             Check_Arg_Count (3);
4681             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4682
4683             Process_Import_Predefined_Type;
4684
4685          else
4686             Error_Pragma_Arg
4687               ("second argument of pragma% must be object, subprogram" &
4688                " or incomplete type",
4689                Arg2);
4690          end if;
4691
4692          --  If this pragma applies to a compilation unit, then the unit, which
4693          --  is a subprogram, does not require (or allow) a body. We also do
4694          --  not need to elaborate imported procedures.
4695
4696          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4697             declare
4698                Cunit : constant Node_Id := Parent (Parent (N));
4699             begin
4700                Set_Body_Required (Cunit, False);
4701             end;
4702          end if;
4703       end Process_Import_Or_Interface;
4704
4705       --------------------
4706       -- Process_Inline --
4707       --------------------
4708
4709       procedure Process_Inline (Active : Boolean) is
4710          Assoc     : Node_Id;
4711          Decl      : Node_Id;
4712          Subp_Id   : Node_Id;
4713          Subp      : Entity_Id;
4714          Applies   : Boolean;
4715
4716          Effective : Boolean := False;
4717          --  Set True if inline has some effect, i.e. if there is at least one
4718          --  subprogram set as inlined as a result of the use of the pragma.
4719
4720          procedure Make_Inline (Subp : Entity_Id);
4721          --  Subp is the defining unit name of the subprogram declaration. Set
4722          --  the flag, as well as the flag in the corresponding body, if there
4723          --  is one present.
4724
4725          procedure Set_Inline_Flags (Subp : Entity_Id);
4726          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4727          --  Has_Pragma_Inline_Always for the Inline_Always case.
4728
4729          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4730          --  Returns True if it can be determined at this stage that inlining
4731          --  is not possible, for example if the body is available and contains
4732          --  exception handlers, we prevent inlining, since otherwise we can
4733          --  get undefined symbols at link time. This function also emits a
4734          --  warning if front-end inlining is enabled and the pragma appears
4735          --  too late.
4736          --
4737          --  ??? is business with link symbols still valid, or does it relate
4738          --  to front end ZCX which is being phased out ???
4739
4740          ---------------------------
4741          -- Inlining_Not_Possible --
4742          ---------------------------
4743
4744          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4745             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4746             Stats : Node_Id;
4747
4748          begin
4749             if Nkind (Decl) = N_Subprogram_Body then
4750                Stats := Handled_Statement_Sequence (Decl);
4751                return Present (Exception_Handlers (Stats))
4752                  or else Present (At_End_Proc (Stats));
4753
4754             elsif Nkind (Decl) = N_Subprogram_Declaration
4755               and then Present (Corresponding_Body (Decl))
4756             then
4757                if Front_End_Inlining
4758                  and then Analyzed (Corresponding_Body (Decl))
4759                then
4760                   Error_Msg_N ("pragma appears too late, ignored?", N);
4761                   return True;
4762
4763                --  If the subprogram is a renaming as body, the body is just a
4764                --  call to the renamed subprogram, and inlining is trivially
4765                --  possible.
4766
4767                elsif
4768                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4769                                              N_Subprogram_Renaming_Declaration
4770                then
4771                   return False;
4772
4773                else
4774                   Stats :=
4775                     Handled_Statement_Sequence
4776                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4777
4778                   return
4779                     Present (Exception_Handlers (Stats))
4780                       or else Present (At_End_Proc (Stats));
4781                end if;
4782
4783             else
4784                --  If body is not available, assume the best, the check is
4785                --  performed again when compiling enclosing package bodies.
4786
4787                return False;
4788             end if;
4789          end Inlining_Not_Possible;
4790
4791          -----------------
4792          -- Make_Inline --
4793          -----------------
4794
4795          procedure Make_Inline (Subp : Entity_Id) is
4796             Kind       : constant Entity_Kind := Ekind (Subp);
4797             Inner_Subp : Entity_Id   := Subp;
4798
4799          begin
4800             --  Ignore if bad type, avoid cascaded error
4801
4802             if Etype (Subp) = Any_Type then
4803                Applies := True;
4804                return;
4805
4806             --  Ignore if all inlining is suppressed
4807
4808             elsif Suppress_All_Inlining then
4809                Applies := True;
4810                return;
4811
4812             --  If inlining is not possible, for now do not treat as an error
4813
4814             elsif Inlining_Not_Possible (Subp) then
4815                Applies := True;
4816                return;
4817
4818             --  Here we have a candidate for inlining, but we must exclude
4819             --  derived operations. Otherwise we would end up trying to inline
4820             --  a phantom declaration, and the result would be to drag in a
4821             --  body which has no direct inlining associated with it. That
4822             --  would not only be inefficient but would also result in the
4823             --  backend doing cross-unit inlining in cases where it was
4824             --  definitely inappropriate to do so.
4825
4826             --  However, a simple Comes_From_Source test is insufficient, since
4827             --  we do want to allow inlining of generic instances which also do
4828             --  not come from source. We also need to recognize specs generated
4829             --  by the front-end for bodies that carry the pragma. Finally,
4830             --  predefined operators do not come from source but are not
4831             --  inlineable either.
4832
4833             elsif Is_Generic_Instance (Subp)
4834               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4835             then
4836                null;
4837
4838             elsif not Comes_From_Source (Subp)
4839               and then Scope (Subp) /= Standard_Standard
4840             then
4841                Applies := True;
4842                return;
4843             end if;
4844
4845             --  The referenced entity must either be the enclosing entity, or
4846             --  an entity declared within the current open scope.
4847
4848             if Present (Scope (Subp))
4849               and then Scope (Subp) /= Current_Scope
4850               and then Subp /= Current_Scope
4851             then
4852                Error_Pragma_Arg
4853                  ("argument of% must be entity in current scope", Assoc);
4854                return;
4855             end if;
4856
4857             --  Processing for procedure, operator or function. If subprogram
4858             --  is aliased (as for an instance) indicate that the renamed
4859             --  entity (if declared in the same unit) is inlined.
4860
4861             if Is_Subprogram (Subp) then
4862                Inner_Subp := Ultimate_Alias (Inner_Subp);
4863
4864                if In_Same_Source_Unit (Subp, Inner_Subp) then
4865                   Set_Inline_Flags (Inner_Subp);
4866
4867                   Decl := Parent (Parent (Inner_Subp));
4868
4869                   if Nkind (Decl) = N_Subprogram_Declaration
4870                     and then Present (Corresponding_Body (Decl))
4871                   then
4872                      Set_Inline_Flags (Corresponding_Body (Decl));
4873
4874                   elsif Is_Generic_Instance (Subp) then
4875
4876                      --  Indicate that the body needs to be created for
4877                      --  inlining subsequent calls. The instantiation node
4878                      --  follows the declaration of the wrapper package
4879                      --  created for it.
4880
4881                      if Scope (Subp) /= Standard_Standard
4882                        and then
4883                          Need_Subprogram_Instance_Body
4884                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4885                               Subp)
4886                      then
4887                         null;
4888                      end if;
4889
4890                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
4891                   --  appear in a formal part to apply to a formal subprogram.
4892                   --  Do not apply check within an instance or a formal package
4893                   --  the test will have been applied to the original generic.
4894
4895                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4896                     and then List_Containing (Decl) = List_Containing (N)
4897                     and then not In_Instance
4898                   then
4899                      Error_Msg_N
4900                        ("Inline cannot apply to a formal subprogram", N);
4901                   end if;
4902                end if;
4903
4904                Applies := True;
4905
4906             --  For a generic subprogram set flag as well, for use at the point
4907             --  of instantiation, to determine whether the body should be
4908             --  generated.
4909
4910             elsif Is_Generic_Subprogram (Subp) then
4911                Set_Inline_Flags (Subp);
4912                Applies := True;
4913
4914             --  Literals are by definition inlined
4915
4916             elsif Kind = E_Enumeration_Literal then
4917                null;
4918
4919             --  Anything else is an error
4920
4921             else
4922                Error_Pragma_Arg
4923                  ("expect subprogram name for pragma%", Assoc);
4924             end if;
4925          end Make_Inline;
4926
4927          ----------------------
4928          -- Set_Inline_Flags --
4929          ----------------------
4930
4931          procedure Set_Inline_Flags (Subp : Entity_Id) is
4932          begin
4933             if Active then
4934                Set_Is_Inlined (Subp);
4935             end if;
4936
4937             if not Has_Pragma_Inline (Subp) then
4938                Set_Has_Pragma_Inline (Subp);
4939                Effective := True;
4940             end if;
4941
4942             if Prag_Id = Pragma_Inline_Always then
4943                Set_Has_Pragma_Inline_Always (Subp);
4944             end if;
4945          end Set_Inline_Flags;
4946
4947       --  Start of processing for Process_Inline
4948
4949       begin
4950          Check_No_Identifiers;
4951          Check_At_Least_N_Arguments (1);
4952
4953          if Active then
4954             Inline_Processing_Required := True;
4955          end if;
4956
4957          Assoc := Arg1;
4958          while Present (Assoc) loop
4959             Subp_Id := Get_Pragma_Arg (Assoc);
4960             Analyze (Subp_Id);
4961             Applies := False;
4962
4963             if Is_Entity_Name (Subp_Id) then
4964                Subp := Entity (Subp_Id);
4965
4966                if Subp = Any_Id then
4967
4968                   --  If previous error, avoid cascaded errors
4969
4970                   Applies := True;
4971                   Effective := True;
4972
4973                else
4974                   Make_Inline (Subp);
4975
4976                   --  For the pragma case, climb homonym chain. This is
4977                   --  what implements allowing the pragma in the renaming
4978                   --  case, with the result applying to the ancestors, and
4979                   --  also allows Inline to apply to all previous homonyms.
4980
4981                   if not From_Aspect_Specification (N) then
4982                      while Present (Homonym (Subp))
4983                        and then Scope (Homonym (Subp)) = Current_Scope
4984                      loop
4985                         Make_Inline (Homonym (Subp));
4986                         Subp := Homonym (Subp);
4987                      end loop;
4988                   end if;
4989                end if;
4990             end if;
4991
4992             if not Applies then
4993                Error_Pragma_Arg
4994                  ("inappropriate argument for pragma%", Assoc);
4995
4996             elsif not Effective
4997               and then Warn_On_Redundant_Constructs
4998               and then not Suppress_All_Inlining
4999             then
5000                if Inlining_Not_Possible (Subp) then
5001                   Error_Msg_NE
5002                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
5003                else
5004                   Error_Msg_NE
5005                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
5006                end if;
5007             end if;
5008
5009             Next (Assoc);
5010          end loop;
5011       end Process_Inline;
5012
5013       ----------------------------
5014       -- Process_Interface_Name --
5015       ----------------------------
5016
5017       procedure Process_Interface_Name
5018         (Subprogram_Def : Entity_Id;
5019          Ext_Arg        : Node_Id;
5020          Link_Arg       : Node_Id)
5021       is
5022          Ext_Nam    : Node_Id;
5023          Link_Nam   : Node_Id;
5024          String_Val : String_Id;
5025
5026          procedure Check_Form_Of_Interface_Name
5027            (SN            : Node_Id;
5028             Ext_Name_Case : Boolean);
5029          --  SN is a string literal node for an interface name. This routine
5030          --  performs some minimal checks that the name is reasonable. In
5031          --  particular that no spaces or other obviously incorrect characters
5032          --  appear. This is only a warning, since any characters are allowed.
5033          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
5034
5035          ----------------------------------
5036          -- Check_Form_Of_Interface_Name --
5037          ----------------------------------
5038
5039          procedure Check_Form_Of_Interface_Name
5040            (SN            : Node_Id;
5041             Ext_Name_Case : Boolean)
5042          is
5043             S  : constant String_Id := Strval (Expr_Value_S (SN));
5044             SL : constant Nat       := String_Length (S);
5045             C  : Char_Code;
5046
5047          begin
5048             if SL = 0 then
5049                Error_Msg_N ("interface name cannot be null string", SN);
5050             end if;
5051
5052             for J in 1 .. SL loop
5053                C := Get_String_Char (S, J);
5054
5055                --  Look for dubious character and issue unconditional warning.
5056                --  Definitely dubious if not in character range.
5057
5058                if not In_Character_Range (C)
5059
5060                   --  For all cases except CLI target,
5061                   --  commas, spaces and slashes are dubious (in CLI, we use
5062                   --  commas and backslashes in external names to specify
5063                   --  assembly version and public key, while slashes and spaces
5064                   --  can be used in names to mark nested classes and
5065                   --  valuetypes).
5066
5067                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5068                              and then (Get_Character (C) = ','
5069                                          or else
5070                                        Get_Character (C) = '\'))
5071                  or else (VM_Target /= CLI_Target
5072                             and then (Get_Character (C) = ' '
5073                                         or else
5074                                       Get_Character (C) = '/'))
5075                then
5076                   Error_Msg
5077                     ("?interface name contains illegal character",
5078                      Sloc (SN) + Source_Ptr (J));
5079                end if;
5080             end loop;
5081          end Check_Form_Of_Interface_Name;
5082
5083       --  Start of processing for Process_Interface_Name
5084
5085       begin
5086          if No (Link_Arg) then
5087             if No (Ext_Arg) then
5088                if VM_Target = CLI_Target
5089                  and then Ekind (Subprogram_Def) = E_Package
5090                  and then Nkind (Parent (Subprogram_Def)) =
5091                                                  N_Package_Specification
5092                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
5093                then
5094                   Set_Interface_Name
5095                      (Subprogram_Def,
5096                       Interface_Name
5097                         (Generic_Parent (Parent (Subprogram_Def))));
5098                end if;
5099
5100                return;
5101
5102             elsif Chars (Ext_Arg) = Name_Link_Name then
5103                Ext_Nam  := Empty;
5104                Link_Nam := Expression (Ext_Arg);
5105
5106             else
5107                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5108                Ext_Nam  := Expression (Ext_Arg);
5109                Link_Nam := Empty;
5110             end if;
5111
5112          else
5113             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
5114             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5115             Ext_Nam  := Expression (Ext_Arg);
5116             Link_Nam := Expression (Link_Arg);
5117          end if;
5118
5119          --  Check expressions for external name and link name are static
5120
5121          if Present (Ext_Nam) then
5122             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5123             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5124
5125             --  Verify that external name is not the name of a local entity,
5126             --  which would hide the imported one and could lead to run-time
5127             --  surprises. The problem can only arise for entities declared in
5128             --  a package body (otherwise the external name is fully qualified
5129             --  and will not conflict).
5130
5131             declare
5132                Nam : Name_Id;
5133                E   : Entity_Id;
5134                Par : Node_Id;
5135
5136             begin
5137                if Prag_Id = Pragma_Import then
5138                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5139                   Nam := Name_Find;
5140                   E   := Entity_Id (Get_Name_Table_Info (Nam));
5141
5142                   if Nam /= Chars (Subprogram_Def)
5143                     and then Present (E)
5144                     and then not Is_Overloadable (E)
5145                     and then Is_Immediately_Visible (E)
5146                     and then not Is_Imported (E)
5147                     and then Ekind (Scope (E)) = E_Package
5148                   then
5149                      Par := Parent (E);
5150                      while Present (Par) loop
5151                         if Nkind (Par) = N_Package_Body then
5152                            Error_Msg_Sloc := Sloc (E);
5153                            Error_Msg_NE
5154                              ("imported entity is hidden by & declared#",
5155                               Ext_Arg, E);
5156                            exit;
5157                         end if;
5158
5159                         Par := Parent (Par);
5160                      end loop;
5161                   end if;
5162                end if;
5163             end;
5164          end if;
5165
5166          if Present (Link_Nam) then
5167             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5168             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5169          end if;
5170
5171          --  If there is no link name, just set the external name
5172
5173          if No (Link_Nam) then
5174             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5175
5176          --  For the Link_Name case, the given literal is preceded by an
5177          --  asterisk, which indicates to GCC that the given name should be
5178          --  taken literally, and in particular that no prepending of
5179          --  underlines should occur, even in systems where this is the
5180          --  normal default.
5181
5182          else
5183             Start_String;
5184
5185             if VM_Target = No_VM then
5186                Store_String_Char (Get_Char_Code ('*'));
5187             end if;
5188
5189             String_Val := Strval (Expr_Value_S (Link_Nam));
5190             Store_String_Chars (String_Val);
5191             Link_Nam :=
5192               Make_String_Literal (Sloc (Link_Nam),
5193                 Strval => End_String);
5194          end if;
5195
5196          --  Set the interface name. If the entity is a generic instance, use
5197          --  its alias, which is the callable entity.
5198
5199          if Is_Generic_Instance (Subprogram_Def) then
5200             Set_Encoded_Interface_Name
5201               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5202          else
5203             Set_Encoded_Interface_Name
5204               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5205          end if;
5206
5207          --  We allow duplicated export names in CIL/Java, as they are always
5208          --  enclosed in a namespace that differentiates them, and overloaded
5209          --  entities are supported by the VM.
5210
5211          if Convention (Subprogram_Def) /= Convention_CIL
5212               and then
5213             Convention (Subprogram_Def) /= Convention_Java
5214          then
5215             Check_Duplicated_Export_Name (Link_Nam);
5216          end if;
5217       end Process_Interface_Name;
5218
5219       -----------------------------------------
5220       -- Process_Interrupt_Or_Attach_Handler --
5221       -----------------------------------------
5222
5223       procedure Process_Interrupt_Or_Attach_Handler is
5224          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5225          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5226          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5227
5228       begin
5229          Set_Is_Interrupt_Handler (Handler_Proc);
5230
5231          --  If the pragma is not associated with a handler procedure within a
5232          --  protected type, then it must be for a nonprotected procedure for
5233          --  the AAMP target, in which case we don't associate a representation
5234          --  item with the procedure's scope.
5235
5236          if Ekind (Proc_Scope) = E_Protected_Type then
5237             if Prag_Id = Pragma_Interrupt_Handler
5238                  or else
5239                Prag_Id = Pragma_Attach_Handler
5240             then
5241                Record_Rep_Item (Proc_Scope, N);
5242             end if;
5243          end if;
5244       end Process_Interrupt_Or_Attach_Handler;
5245
5246       --------------------------------------------------
5247       -- Process_Restrictions_Or_Restriction_Warnings --
5248       --------------------------------------------------
5249
5250       --  Note: some of the simple identifier cases were handled in par-prag,
5251       --  but it is harmless (and more straightforward) to simply handle all
5252       --  cases here, even if it means we repeat a bit of work in some cases.
5253
5254       procedure Process_Restrictions_Or_Restriction_Warnings
5255         (Warn : Boolean)
5256       is
5257          Arg   : Node_Id;
5258          R_Id  : Restriction_Id;
5259          Id    : Name_Id;
5260          Expr  : Node_Id;
5261          Val   : Uint;
5262
5263          procedure Check_Unit_Name (N : Node_Id);
5264          --  Checks unit name parameter for No_Dependence. Returns if it has
5265          --  an appropriate form, otherwise raises pragma argument error.
5266
5267          ---------------------
5268          -- Check_Unit_Name --
5269          ---------------------
5270
5271          procedure Check_Unit_Name (N : Node_Id) is
5272          begin
5273             if Nkind (N) = N_Selected_Component then
5274                Check_Unit_Name (Prefix (N));
5275                Check_Unit_Name (Selector_Name (N));
5276
5277             elsif Nkind (N) = N_Identifier then
5278                return;
5279
5280             else
5281                Error_Pragma_Arg
5282                  ("wrong form for unit name for No_Dependence", N);
5283             end if;
5284          end Check_Unit_Name;
5285
5286       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5287
5288       begin
5289          --  Ignore all Restrictions pragma in CodePeer mode
5290
5291          if CodePeer_Mode then
5292             return;
5293          end if;
5294
5295          Check_Ada_83_Warning;
5296          Check_At_Least_N_Arguments (1);
5297          Check_Valid_Configuration_Pragma;
5298
5299          Arg := Arg1;
5300          while Present (Arg) loop
5301             Id := Chars (Arg);
5302             Expr := Get_Pragma_Arg (Arg);
5303
5304             --  Case of no restriction identifier present
5305
5306             if Id = No_Name then
5307                if Nkind (Expr) /= N_Identifier then
5308                   Error_Pragma_Arg
5309                     ("invalid form for restriction", Arg);
5310                end if;
5311
5312                R_Id :=
5313                  Get_Restriction_Id
5314                    (Process_Restriction_Synonyms (Expr));
5315
5316                if R_Id not in All_Boolean_Restrictions then
5317                   Error_Msg_Name_1 := Pname;
5318                   Error_Msg_N
5319                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5320
5321                   --  Check for possible misspelling
5322
5323                   for J in Restriction_Id loop
5324                      declare
5325                         Rnm : constant String := Restriction_Id'Image (J);
5326
5327                      begin
5328                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5329                         Name_Len := Rnm'Length;
5330                         Set_Casing (All_Lower_Case);
5331
5332                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5333                            Set_Casing
5334                              (Identifier_Casing (Current_Source_File));
5335                            Error_Msg_String (1 .. Rnm'Length) :=
5336                              Name_Buffer (1 .. Name_Len);
5337                            Error_Msg_Strlen := Rnm'Length;
5338                            Error_Msg_N -- CODEFIX
5339                              ("\possible misspelling of ""~""",
5340                               Get_Pragma_Arg (Arg));
5341                            exit;
5342                         end if;
5343                      end;
5344                   end loop;
5345
5346                   raise Pragma_Exit;
5347                end if;
5348
5349                if Implementation_Restriction (R_Id) then
5350                   Check_Restriction (No_Implementation_Restrictions, Arg);
5351                end if;
5352
5353                --  If this is a warning, then set the warning unless we already
5354                --  have a real restriction active (we never want a warning to
5355                --  override a real restriction).
5356
5357                if Warn then
5358                   if not Restriction_Active (R_Id) then
5359                      Set_Restriction (R_Id, N);
5360                      Restriction_Warnings (R_Id) := True;
5361                   end if;
5362
5363                --  If real restriction case, then set it and make sure that the
5364                --  restriction warning flag is off, since a real restriction
5365                --  always overrides a warning.
5366
5367                else
5368                   Set_Restriction (R_Id, N);
5369                   Restriction_Warnings (R_Id) := False;
5370                end if;
5371
5372                --  Check for obsolescent restrictions in Ada 2005 mode
5373
5374                if not Warn
5375                  and then Ada_Version >= Ada_2005
5376                  and then (R_Id = No_Asynchronous_Control
5377                             or else
5378                            R_Id = No_Unchecked_Deallocation
5379                             or else
5380                            R_Id = No_Unchecked_Conversion)
5381                then
5382                   Check_Restriction (No_Obsolescent_Features, N);
5383                end if;
5384
5385                --  A very special case that must be processed here: pragma
5386                --  Restrictions (No_Exceptions) turns off all run-time
5387                --  checking. This is a bit dubious in terms of the formal
5388                --  language definition, but it is what is intended by RM
5389                --  H.4(12). Restriction_Warnings never affects generated code
5390                --  so this is done only in the real restriction case.
5391
5392                --  Atomic_Synchronization is not a real check, so it is not
5393                --  affected by this processing).
5394
5395                if R_Id = No_Exceptions and then not Warn then
5396                   for J in Scope_Suppress'Range loop
5397                      if J /= Atomic_Synchronization then
5398                         Scope_Suppress (J) := True;
5399                      end if;
5400                   end loop;
5401                end if;
5402
5403             --  Case of No_Dependence => unit-name. Note that the parser
5404             --  already made the necessary entry in the No_Dependence table.
5405
5406             elsif Id = Name_No_Dependence then
5407                Check_Unit_Name (Expr);
5408
5409             --  Case of No_Specification_Of_Aspect => Identifier.
5410
5411             elsif Id = Name_No_Specification_Of_Aspect then
5412                declare
5413                   A_Id : Aspect_Id;
5414
5415                begin
5416                   if Nkind (Expr) /= N_Identifier then
5417                      A_Id := No_Aspect;
5418                   else
5419                      A_Id := Get_Aspect_Id (Chars (Expr));
5420                   end if;
5421
5422                   if A_Id = No_Aspect then
5423                      Error_Pragma_Arg ("invalid restriction name", Arg);
5424                   else
5425                      Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5426                   end if;
5427                end;
5428
5429             --  All other cases of restriction identifier present
5430
5431             else
5432                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5433                Analyze_And_Resolve (Expr, Any_Integer);
5434
5435                if R_Id not in All_Parameter_Restrictions then
5436                   Error_Pragma_Arg
5437                     ("invalid restriction parameter identifier", Arg);
5438
5439                elsif not Is_OK_Static_Expression (Expr) then
5440                   Flag_Non_Static_Expr
5441                     ("value must be static expression!", Expr);
5442                   raise Pragma_Exit;
5443
5444                elsif not Is_Integer_Type (Etype (Expr))
5445                  or else Expr_Value (Expr) < 0
5446                then
5447                   Error_Pragma_Arg
5448                     ("value must be non-negative integer", Arg);
5449                end if;
5450
5451                --  Restriction pragma is active
5452
5453                Val := Expr_Value (Expr);
5454
5455                if not UI_Is_In_Int_Range (Val) then
5456                   Error_Pragma_Arg
5457                     ("pragma ignored, value too large?", Arg);
5458                end if;
5459
5460                --  Warning case. If the real restriction is active, then we
5461                --  ignore the request, since warning never overrides a real
5462                --  restriction. Otherwise we set the proper warning. Note that
5463                --  this circuit sets the warning again if it is already set,
5464                --  which is what we want, since the constant may have changed.
5465
5466                if Warn then
5467                   if not Restriction_Active (R_Id) then
5468                      Set_Restriction
5469                        (R_Id, N, Integer (UI_To_Int (Val)));
5470                      Restriction_Warnings (R_Id) := True;
5471                   end if;
5472
5473                --  Real restriction case, set restriction and make sure warning
5474                --  flag is off since real restriction always overrides warning.
5475
5476                else
5477                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5478                   Restriction_Warnings (R_Id) := False;
5479                end if;
5480             end if;
5481
5482             Next (Arg);
5483          end loop;
5484       end Process_Restrictions_Or_Restriction_Warnings;
5485
5486       ---------------------------------
5487       -- Process_Suppress_Unsuppress --
5488       ---------------------------------
5489
5490       --  Note: this procedure makes entries in the check suppress data
5491       --  structures managed by Sem. See spec of package Sem for full
5492       --  details on how we handle recording of check suppression.
5493
5494       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5495          C    : Check_Id;
5496          E_Id : Node_Id;
5497          E    : Entity_Id;
5498
5499          In_Package_Spec : constant Boolean :=
5500                              Is_Package_Or_Generic_Package (Current_Scope)
5501                                and then not In_Package_Body (Current_Scope);
5502
5503          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5504          --  Used to suppress a single check on the given entity
5505
5506          --------------------------------
5507          -- Suppress_Unsuppress_Echeck --
5508          --------------------------------
5509
5510          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5511          begin
5512             --  Check for error of trying to set atomic synchronization for
5513             --  a non-atomic variable.
5514
5515             if C = Atomic_Synchronization
5516               and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5517             then
5518                Error_Msg_N
5519                  ("pragma & requires atomic type or variable",
5520                   Pragma_Identifier (Original_Node (N)));
5521             end if;
5522
5523             Set_Checks_May_Be_Suppressed (E);
5524
5525             if In_Package_Spec then
5526                Push_Global_Suppress_Stack_Entry
5527                  (Entity   => E,
5528                   Check    => C,
5529                   Suppress => Suppress_Case);
5530             else
5531                Push_Local_Suppress_Stack_Entry
5532                  (Entity   => E,
5533                   Check    => C,
5534                   Suppress => Suppress_Case);
5535             end if;
5536
5537             --  If this is a first subtype, and the base type is distinct,
5538             --  then also set the suppress flags on the base type.
5539
5540             if Is_First_Subtype (E)
5541               and then Etype (E) /= E
5542             then
5543                Suppress_Unsuppress_Echeck (Etype (E), C);
5544             end if;
5545          end Suppress_Unsuppress_Echeck;
5546
5547       --  Start of processing for Process_Suppress_Unsuppress
5548
5549       begin
5550          --  Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5551          --  user code: we want to generate checks for analysis purposes, as
5552          --  set respectively by -gnatC and -gnatd.F
5553
5554          if (CodePeer_Mode or Alfa_Mode)
5555            and then Comes_From_Source (N)
5556          then
5557             return;
5558          end if;
5559
5560          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5561          --  declarative part or a package spec (RM 11.5(5)).
5562
5563          if not Is_Configuration_Pragma then
5564             Check_Is_In_Decl_Part_Or_Package_Spec;
5565          end if;
5566
5567          Check_At_Least_N_Arguments (1);
5568          Check_At_Most_N_Arguments (2);
5569          Check_No_Identifier (Arg1);
5570          Check_Arg_Is_Identifier (Arg1);
5571
5572          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5573
5574          if C = No_Check_Id then
5575             Error_Pragma_Arg
5576               ("argument of pragma% is not valid check name", Arg1);
5577          end if;
5578
5579          if not Suppress_Case
5580            and then (C = All_Checks or else C = Overflow_Check)
5581          then
5582             Opt.Overflow_Checks_Unsuppressed := True;
5583          end if;
5584
5585          if Arg_Count = 1 then
5586
5587             --  Make an entry in the local scope suppress table. This is the
5588             --  table that directly shows the current value of the scope
5589             --  suppress check for any check id value.
5590
5591             if C = All_Checks then
5592
5593                --  For All_Checks, we set all specific predefined checks with
5594                --  the exception of Elaboration_Check, which is handled
5595                --  specially because of not wanting All_Checks to have the
5596                --  effect of deactivating static elaboration order processing.
5597                --  Atomic_Synchronization is also not affected, since this is
5598                --  not a real check.
5599
5600                for J in Scope_Suppress'Range loop
5601                   if J /= Elaboration_Check
5602                     and then J /= Atomic_Synchronization
5603                   then
5604                      Scope_Suppress (J) := Suppress_Case;
5605                   end if;
5606                end loop;
5607
5608             --  If not All_Checks, and predefined check, then set appropriate
5609             --  scope entry. Note that we will set Elaboration_Check if this
5610             --  is explicitly specified. Atomic_Synchronization is allowed
5611             --  only if internally generated and entity is atomic.
5612
5613             elsif C in Predefined_Check_Id
5614               and then (not Comes_From_Source (N)
5615                          or else C /= Atomic_Synchronization)
5616             then
5617                Scope_Suppress (C) := Suppress_Case;
5618             end if;
5619
5620             --  Also make an entry in the Local_Entity_Suppress table
5621
5622             Push_Local_Suppress_Stack_Entry
5623               (Entity   => Empty,
5624                Check    => C,
5625                Suppress => Suppress_Case);
5626
5627          --  Case of two arguments present, where the check is suppressed for
5628          --  a specified entity (given as the second argument of the pragma)
5629
5630          else
5631             --  This is obsolescent in Ada 2005 mode
5632
5633             if Ada_Version >= Ada_2005 then
5634                Check_Restriction (No_Obsolescent_Features, Arg2);
5635             end if;
5636
5637             Check_Optional_Identifier (Arg2, Name_On);
5638             E_Id := Get_Pragma_Arg (Arg2);
5639             Analyze (E_Id);
5640
5641             if not Is_Entity_Name (E_Id) then
5642                Error_Pragma_Arg
5643                  ("second argument of pragma% must be entity name", Arg2);
5644             end if;
5645
5646             E := Entity (E_Id);
5647
5648             if E = Any_Id then
5649                return;
5650             end if;
5651
5652             --  Enforce RM 11.5(7) which requires that for a pragma that
5653             --  appears within a package spec, the named entity must be
5654             --  within the package spec. We allow the package name itself
5655             --  to be mentioned since that makes sense, although it is not
5656             --  strictly allowed by 11.5(7).
5657
5658             if In_Package_Spec
5659               and then E /= Current_Scope
5660               and then Scope (E) /= Current_Scope
5661             then
5662                Error_Pragma_Arg
5663                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5664                   Arg2);
5665             end if;
5666
5667             --  Loop through homonyms. As noted below, in the case of a package
5668             --  spec, only homonyms within the package spec are considered.
5669
5670             loop
5671                Suppress_Unsuppress_Echeck (E, C);
5672
5673                if Is_Generic_Instance (E)
5674                  and then Is_Subprogram (E)
5675                  and then Present (Alias (E))
5676                then
5677                   Suppress_Unsuppress_Echeck (Alias (E), C);
5678                end if;
5679
5680                --  Move to next homonym if not aspect spec case
5681
5682                exit when From_Aspect_Specification (N);
5683                E := Homonym (E);
5684                exit when No (E);
5685
5686                --  If we are within a package specification, the pragma only
5687                --  applies to homonyms in the same scope.
5688
5689                exit when In_Package_Spec
5690                  and then Scope (E) /= Current_Scope;
5691             end loop;
5692          end if;
5693       end Process_Suppress_Unsuppress;
5694
5695       ------------------
5696       -- Set_Exported --
5697       ------------------
5698
5699       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5700       begin
5701          if Is_Imported (E) then
5702             Error_Pragma_Arg
5703               ("cannot export entity& that was previously imported", Arg);
5704
5705          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5706             Error_Pragma_Arg
5707               ("cannot export entity& that has an address clause", Arg);
5708          end if;
5709
5710          Set_Is_Exported (E);
5711
5712          --  Generate a reference for entity explicitly, because the
5713          --  identifier may be overloaded and name resolution will not
5714          --  generate one.
5715
5716          Generate_Reference (E, Arg);
5717
5718          --  Deal with exporting non-library level entity
5719
5720          if not Is_Library_Level_Entity (E) then
5721
5722             --  Not allowed at all for subprograms
5723
5724             if Is_Subprogram (E) then
5725                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5726
5727             --  Otherwise set public and statically allocated
5728
5729             else
5730                Set_Is_Public (E);
5731                Set_Is_Statically_Allocated (E);
5732
5733                --  Warn if the corresponding W flag is set and the pragma comes
5734                --  from source. The latter may not be true e.g. on VMS where we
5735                --  expand export pragmas for exception codes associated with
5736                --  imported or exported exceptions. We do not want to generate
5737                --  a warning for something that the user did not write.
5738
5739                if Warn_On_Export_Import
5740                  and then Comes_From_Source (Arg)
5741                then
5742                   Error_Msg_NE
5743                     ("?& has been made static as a result of Export", Arg, E);
5744                   Error_Msg_N
5745                     ("\this usage is non-standard and non-portable", Arg);
5746                end if;
5747             end if;
5748          end if;
5749
5750          if Warn_On_Export_Import and then Is_Type (E) then
5751             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5752          end if;
5753
5754          if Warn_On_Export_Import and Inside_A_Generic then
5755             Error_Msg_NE
5756               ("all instances of& will have the same external name?", Arg, E);
5757          end if;
5758       end Set_Exported;
5759
5760       ----------------------------------------------
5761       -- Set_Extended_Import_Export_External_Name --
5762       ----------------------------------------------
5763
5764       procedure Set_Extended_Import_Export_External_Name
5765         (Internal_Ent : Entity_Id;
5766          Arg_External : Node_Id)
5767       is
5768          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5769          New_Name : Node_Id;
5770
5771       begin
5772          if No (Arg_External) then
5773             return;
5774          end if;
5775
5776          Check_Arg_Is_External_Name (Arg_External);
5777
5778          if Nkind (Arg_External) = N_String_Literal then
5779             if String_Length (Strval (Arg_External)) = 0 then
5780                return;
5781             else
5782                New_Name := Adjust_External_Name_Case (Arg_External);
5783             end if;
5784
5785          elsif Nkind (Arg_External) = N_Identifier then
5786             New_Name := Get_Default_External_Name (Arg_External);
5787
5788          --  Check_Arg_Is_External_Name should let through only identifiers and
5789          --  string literals or static string expressions (which are folded to
5790          --  string literals).
5791
5792          else
5793             raise Program_Error;
5794          end if;
5795
5796          --  If we already have an external name set (by a prior normal Import
5797          --  or Export pragma), then the external names must match
5798
5799          if Present (Interface_Name (Internal_Ent)) then
5800             Check_Matching_Internal_Names : declare
5801                S1 : constant String_Id := Strval (Old_Name);
5802                S2 : constant String_Id := Strval (New_Name);
5803
5804                procedure Mismatch;
5805                --  Called if names do not match
5806
5807                --------------
5808                -- Mismatch --
5809                --------------
5810
5811                procedure Mismatch is
5812                begin
5813                   Error_Msg_Sloc := Sloc (Old_Name);
5814                   Error_Pragma_Arg
5815                     ("external name does not match that given #",
5816                      Arg_External);
5817                end Mismatch;
5818
5819             --  Start of processing for Check_Matching_Internal_Names
5820
5821             begin
5822                if String_Length (S1) /= String_Length (S2) then
5823                   Mismatch;
5824
5825                else
5826                   for J in 1 .. String_Length (S1) loop
5827                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5828                         Mismatch;
5829                      end if;
5830                   end loop;
5831                end if;
5832             end Check_Matching_Internal_Names;
5833
5834          --  Otherwise set the given name
5835
5836          else
5837             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5838             Check_Duplicated_Export_Name (New_Name);
5839          end if;
5840       end Set_Extended_Import_Export_External_Name;
5841
5842       ------------------
5843       -- Set_Imported --
5844       ------------------
5845
5846       procedure Set_Imported (E : Entity_Id) is
5847       begin
5848          --  Error message if already imported or exported
5849
5850          if Is_Exported (E) or else Is_Imported (E) then
5851
5852             --  Error if being set Exported twice
5853
5854             if Is_Exported (E) then
5855                Error_Msg_NE ("entity& was previously exported", N, E);
5856
5857             --  OK if Import/Interface case
5858
5859             elsif Import_Interface_Present (N) then
5860                goto OK;
5861
5862             --  Error if being set Imported twice
5863
5864             else
5865                Error_Msg_NE ("entity& was previously imported", N, E);
5866             end if;
5867
5868             Error_Msg_Name_1 := Pname;
5869             Error_Msg_N
5870               ("\(pragma% applies to all previous entities)", N);
5871
5872             Error_Msg_Sloc  := Sloc (E);
5873             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5874
5875          --  Here if not previously imported or exported, OK to import
5876
5877          else
5878             Set_Is_Imported (E);
5879
5880             --  If the entity is an object that is not at the library level,
5881             --  then it is statically allocated. We do not worry about objects
5882             --  with address clauses in this context since they are not really
5883             --  imported in the linker sense.
5884
5885             if Is_Object (E)
5886               and then not Is_Library_Level_Entity (E)
5887               and then No (Address_Clause (E))
5888             then
5889                Set_Is_Statically_Allocated (E);
5890             end if;
5891          end if;
5892
5893          <<OK>> null;
5894       end Set_Imported;
5895
5896       -------------------------
5897       -- Set_Mechanism_Value --
5898       -------------------------
5899
5900       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5901       --  analyzed, since it is semantic nonsense), so we get it in the exact
5902       --  form created by the parser.
5903
5904       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5905          Class        : Node_Id;
5906          Param        : Node_Id;
5907          Mech_Name_Id : Name_Id;
5908
5909          procedure Bad_Class;
5910          --  Signal bad descriptor class name
5911
5912          procedure Bad_Mechanism;
5913          --  Signal bad mechanism name
5914
5915          ---------------
5916          -- Bad_Class --
5917          ---------------
5918
5919          procedure Bad_Class is
5920          begin
5921             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5922          end Bad_Class;
5923
5924          -------------------------
5925          -- Bad_Mechanism_Value --
5926          -------------------------
5927
5928          procedure Bad_Mechanism is
5929          begin
5930             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5931          end Bad_Mechanism;
5932
5933       --  Start of processing for Set_Mechanism_Value
5934
5935       begin
5936          if Mechanism (Ent) /= Default_Mechanism then
5937             Error_Msg_NE
5938               ("mechanism for & has already been set", Mech_Name, Ent);
5939          end if;
5940
5941          --  MECHANISM_NAME ::= value | reference | descriptor |
5942          --                     short_descriptor
5943
5944          if Nkind (Mech_Name) = N_Identifier then
5945             if Chars (Mech_Name) = Name_Value then
5946                Set_Mechanism (Ent, By_Copy);
5947                return;
5948
5949             elsif Chars (Mech_Name) = Name_Reference then
5950                Set_Mechanism (Ent, By_Reference);
5951                return;
5952
5953             elsif Chars (Mech_Name) = Name_Descriptor then
5954                Check_VMS (Mech_Name);
5955
5956                --  Descriptor => Short_Descriptor if pragma was given
5957
5958                if Short_Descriptors then
5959                   Set_Mechanism (Ent, By_Short_Descriptor);
5960                else
5961                   Set_Mechanism (Ent, By_Descriptor);
5962                end if;
5963
5964                return;
5965
5966             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5967                Check_VMS (Mech_Name);
5968                Set_Mechanism (Ent, By_Short_Descriptor);
5969                return;
5970
5971             elsif Chars (Mech_Name) = Name_Copy then
5972                Error_Pragma_Arg
5973                  ("bad mechanism name, Value assumed", Mech_Name);
5974
5975             else
5976                Bad_Mechanism;
5977             end if;
5978
5979          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5980          --                     short_descriptor (CLASS_NAME)
5981          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5982
5983          --  Note: this form is parsed as an indexed component
5984
5985          elsif Nkind (Mech_Name) = N_Indexed_Component then
5986             Class := First (Expressions (Mech_Name));
5987
5988             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5989              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5990                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5991              or else Present (Next (Class))
5992             then
5993                Bad_Mechanism;
5994             else
5995                Mech_Name_Id := Chars (Prefix (Mech_Name));
5996
5997                --  Change Descriptor => Short_Descriptor if pragma was given
5998
5999                if Mech_Name_Id = Name_Descriptor
6000                  and then Short_Descriptors
6001                then
6002                   Mech_Name_Id := Name_Short_Descriptor;
6003                end if;
6004             end if;
6005
6006          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
6007          --                     short_descriptor (Class => CLASS_NAME)
6008          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
6009
6010          --  Note: this form is parsed as a function call
6011
6012          elsif Nkind (Mech_Name) = N_Function_Call then
6013             Param := First (Parameter_Associations (Mech_Name));
6014
6015             if Nkind (Name (Mech_Name)) /= N_Identifier
6016               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6017                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6018               or else Present (Next (Param))
6019               or else No (Selector_Name (Param))
6020               or else Chars (Selector_Name (Param)) /= Name_Class
6021             then
6022                Bad_Mechanism;
6023             else
6024                Class := Explicit_Actual_Parameter (Param);
6025                Mech_Name_Id := Chars (Name (Mech_Name));
6026             end if;
6027
6028          else
6029             Bad_Mechanism;
6030          end if;
6031
6032          --  Fall through here with Class set to descriptor class name
6033
6034          Check_VMS (Mech_Name);
6035
6036          if Nkind (Class) /= N_Identifier then
6037             Bad_Class;
6038
6039          elsif Mech_Name_Id = Name_Descriptor
6040            and then Chars (Class) = Name_UBS
6041          then
6042             Set_Mechanism (Ent, By_Descriptor_UBS);
6043
6044          elsif Mech_Name_Id = Name_Descriptor
6045            and then Chars (Class) = Name_UBSB
6046          then
6047             Set_Mechanism (Ent, By_Descriptor_UBSB);
6048
6049          elsif Mech_Name_Id = Name_Descriptor
6050            and then Chars (Class) = Name_UBA
6051          then
6052             Set_Mechanism (Ent, By_Descriptor_UBA);
6053
6054          elsif Mech_Name_Id = Name_Descriptor
6055            and then Chars (Class) = Name_S
6056          then
6057             Set_Mechanism (Ent, By_Descriptor_S);
6058
6059          elsif Mech_Name_Id = Name_Descriptor
6060            and then Chars (Class) = Name_SB
6061          then
6062             Set_Mechanism (Ent, By_Descriptor_SB);
6063
6064          elsif Mech_Name_Id = Name_Descriptor
6065            and then Chars (Class) = Name_A
6066          then
6067             Set_Mechanism (Ent, By_Descriptor_A);
6068
6069          elsif Mech_Name_Id = Name_Descriptor
6070            and then Chars (Class) = Name_NCA
6071          then
6072             Set_Mechanism (Ent, By_Descriptor_NCA);
6073
6074          elsif Mech_Name_Id = Name_Short_Descriptor
6075            and then Chars (Class) = Name_UBS
6076          then
6077             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6078
6079          elsif Mech_Name_Id = Name_Short_Descriptor
6080            and then Chars (Class) = Name_UBSB
6081          then
6082             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6083
6084          elsif Mech_Name_Id = Name_Short_Descriptor
6085            and then Chars (Class) = Name_UBA
6086          then
6087             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6088
6089          elsif Mech_Name_Id = Name_Short_Descriptor
6090            and then Chars (Class) = Name_S
6091          then
6092             Set_Mechanism (Ent, By_Short_Descriptor_S);
6093
6094          elsif Mech_Name_Id = Name_Short_Descriptor
6095            and then Chars (Class) = Name_SB
6096          then
6097             Set_Mechanism (Ent, By_Short_Descriptor_SB);
6098
6099          elsif Mech_Name_Id = Name_Short_Descriptor
6100            and then Chars (Class) = Name_A
6101          then
6102             Set_Mechanism (Ent, By_Short_Descriptor_A);
6103
6104          elsif Mech_Name_Id = Name_Short_Descriptor
6105            and then Chars (Class) = Name_NCA
6106          then
6107             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6108
6109          else
6110             Bad_Class;
6111          end if;
6112       end Set_Mechanism_Value;
6113
6114       ---------------------------
6115       -- Set_Ravenscar_Profile --
6116       ---------------------------
6117
6118       --  The tasks to be done here are
6119
6120       --    Set required policies
6121
6122       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6123       --      pragma Locking_Policy (Ceiling_Locking)
6124
6125       --    Set Detect_Blocking mode
6126
6127       --    Set required restrictions (see System.Rident for detailed list)
6128
6129       --    Set the No_Dependence rules
6130       --      No_Dependence => Ada.Asynchronous_Task_Control
6131       --      No_Dependence => Ada.Calendar
6132       --      No_Dependence => Ada.Execution_Time.Group_Budget
6133       --      No_Dependence => Ada.Execution_Time.Timers
6134       --      No_Dependence => Ada.Task_Attributes
6135       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
6136
6137       procedure Set_Ravenscar_Profile (N : Node_Id) is
6138          Prefix_Entity   : Entity_Id;
6139          Selector_Entity : Entity_Id;
6140          Prefix_Node     : Node_Id;
6141          Node            : Node_Id;
6142
6143       begin
6144          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6145
6146          if Task_Dispatching_Policy /= ' '
6147            and then Task_Dispatching_Policy /= 'F'
6148          then
6149             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6150             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6151
6152          --  Set the FIFO_Within_Priorities policy, but always preserve
6153          --  System_Location since we like the error message with the run time
6154          --  name.
6155
6156          else
6157             Task_Dispatching_Policy := 'F';
6158
6159             if Task_Dispatching_Policy_Sloc /= System_Location then
6160                Task_Dispatching_Policy_Sloc := Loc;
6161             end if;
6162          end if;
6163
6164          --  pragma Locking_Policy (Ceiling_Locking)
6165
6166          if Locking_Policy /= ' '
6167            and then Locking_Policy /= 'C'
6168          then
6169             Error_Msg_Sloc := Locking_Policy_Sloc;
6170             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6171
6172          --  Set the Ceiling_Locking policy, but preserve System_Location since
6173          --  we like the error message with the run time name.
6174
6175          else
6176             Locking_Policy := 'C';
6177
6178             if Locking_Policy_Sloc /= System_Location then
6179                Locking_Policy_Sloc := Loc;
6180             end if;
6181          end if;
6182
6183          --  pragma Detect_Blocking
6184
6185          Detect_Blocking := True;
6186
6187          --  Set the corresponding restrictions
6188
6189          Set_Profile_Restrictions
6190            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6191
6192          --  Set the No_Dependence restrictions
6193
6194          --  The following No_Dependence restrictions:
6195          --    No_Dependence => Ada.Asynchronous_Task_Control
6196          --    No_Dependence => Ada.Calendar
6197          --    No_Dependence => Ada.Task_Attributes
6198          --  are already set by previous call to Set_Profile_Restrictions.
6199
6200          --  Set the following restrictions which were added to Ada 2005:
6201          --    No_Dependence => Ada.Execution_Time.Group_Budget
6202          --    No_Dependence => Ada.Execution_Time.Timers
6203
6204          if Ada_Version >= Ada_2005 then
6205             Name_Buffer (1 .. 3) := "ada";
6206             Name_Len := 3;
6207
6208             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6209
6210             Name_Buffer (1 .. 14) := "execution_time";
6211             Name_Len := 14;
6212
6213             Selector_Entity := Make_Identifier (Loc, Name_Find);
6214
6215             Prefix_Node :=
6216               Make_Selected_Component
6217                 (Sloc          => Loc,
6218                  Prefix        => Prefix_Entity,
6219                  Selector_Name => Selector_Entity);
6220
6221             Name_Buffer (1 .. 13) := "group_budgets";
6222             Name_Len := 13;
6223
6224             Selector_Entity := Make_Identifier (Loc, Name_Find);
6225
6226             Node :=
6227               Make_Selected_Component
6228                 (Sloc          => Loc,
6229                  Prefix        => Prefix_Node,
6230                  Selector_Name => Selector_Entity);
6231
6232             Set_Restriction_No_Dependence
6233               (Unit    => Node,
6234                Warn    => Treat_Restrictions_As_Warnings,
6235                Profile => Ravenscar);
6236
6237             Name_Buffer (1 .. 6) := "timers";
6238             Name_Len := 6;
6239
6240             Selector_Entity := Make_Identifier (Loc, Name_Find);
6241
6242             Node :=
6243               Make_Selected_Component
6244                 (Sloc          => Loc,
6245                  Prefix        => Prefix_Node,
6246                  Selector_Name => Selector_Entity);
6247
6248             Set_Restriction_No_Dependence
6249               (Unit    => Node,
6250                Warn    => Treat_Restrictions_As_Warnings,
6251                Profile => Ravenscar);
6252          end if;
6253
6254          --  Set the following restrictions which was added to Ada 2012 (see
6255          --  AI-0171):
6256          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
6257
6258          if Ada_Version >= Ada_2012 then
6259             Name_Buffer (1 .. 6) := "system";
6260             Name_Len := 6;
6261
6262             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6263
6264             Name_Buffer (1 .. 15) := "multiprocessors";
6265             Name_Len := 15;
6266
6267             Selector_Entity := Make_Identifier (Loc, Name_Find);
6268
6269             Prefix_Node :=
6270               Make_Selected_Component
6271                 (Sloc          => Loc,
6272                  Prefix        => Prefix_Entity,
6273                  Selector_Name => Selector_Entity);
6274
6275             Name_Buffer (1 .. 19) := "dispatching_domains";
6276             Name_Len := 19;
6277
6278             Selector_Entity := Make_Identifier (Loc, Name_Find);
6279
6280             Node :=
6281               Make_Selected_Component
6282                 (Sloc          => Loc,
6283                  Prefix        => Prefix_Node,
6284                  Selector_Name => Selector_Entity);
6285
6286             Set_Restriction_No_Dependence
6287               (Unit    => Node,
6288                Warn    => Treat_Restrictions_As_Warnings,
6289                Profile => Ravenscar);
6290          end if;
6291       end Set_Ravenscar_Profile;
6292
6293    --  Start of processing for Analyze_Pragma
6294
6295    begin
6296       --  The following code is a defense against recursion. Not clear that
6297       --  this can happen legitimately, but perhaps some error situations
6298       --  can cause it, and we did see this recursion during testing.
6299
6300       if Analyzed (N) then
6301          return;
6302       else
6303          Set_Analyzed (N, True);
6304       end if;
6305
6306       --  Deal with unrecognized pragma
6307
6308       Pname := Pragma_Name (N);
6309
6310       if not Is_Pragma_Name (Pname) then
6311          if Warn_On_Unrecognized_Pragma then
6312             Error_Msg_Name_1 := Pname;
6313             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6314
6315             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6316                if Is_Bad_Spelling_Of (Pname, PN) then
6317                   Error_Msg_Name_1 := PN;
6318                   Error_Msg_N -- CODEFIX
6319                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6320                   exit;
6321                end if;
6322             end loop;
6323          end if;
6324
6325          return;
6326       end if;
6327
6328       --  Here to start processing for recognized pragma
6329
6330       Prag_Id := Get_Pragma_Id (Pname);
6331
6332       if Present (Corresponding_Aspect (N)) then
6333          Pname := Chars (Identifier (Corresponding_Aspect (N)));
6334       end if;
6335
6336       --  Preset arguments
6337
6338       Arg_Count := 0;
6339       Arg1      := Empty;
6340       Arg2      := Empty;
6341       Arg3      := Empty;
6342       Arg4      := Empty;
6343
6344       if Present (Pragma_Argument_Associations (N)) then
6345          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6346          Arg1 := First (Pragma_Argument_Associations (N));
6347
6348          if Present (Arg1) then
6349             Arg2 := Next (Arg1);
6350
6351             if Present (Arg2) then
6352                Arg3 := Next (Arg2);
6353
6354                if Present (Arg3) then
6355                   Arg4 := Next (Arg3);
6356                end if;
6357             end if;
6358          end if;
6359       end if;
6360
6361       --  An enumeration type defines the pragmas that are supported by the
6362       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6363       --  into the corresponding enumeration value for the following case.
6364
6365       case Prag_Id is
6366
6367          -----------------
6368          -- Abort_Defer --
6369          -----------------
6370
6371          --  pragma Abort_Defer;
6372
6373          when Pragma_Abort_Defer =>
6374             GNAT_Pragma;
6375             Check_Arg_Count (0);
6376
6377             --  The only required semantic processing is to check the
6378             --  placement. This pragma must appear at the start of the
6379             --  statement sequence of a handled sequence of statements.
6380
6381             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6382               or else N /= First (Statements (Parent (N)))
6383             then
6384                Pragma_Misplaced;
6385             end if;
6386
6387          ------------
6388          -- Ada_83 --
6389          ------------
6390
6391          --  pragma Ada_83;
6392
6393          --  Note: this pragma also has some specific processing in Par.Prag
6394          --  because we want to set the Ada version mode during parsing.
6395
6396          when Pragma_Ada_83 =>
6397             GNAT_Pragma;
6398             Check_Arg_Count (0);
6399
6400             --  We really should check unconditionally for proper configuration
6401             --  pragma placement, since we really don't want mixed Ada modes
6402             --  within a single unit, and the GNAT reference manual has always
6403             --  said this was a configuration pragma, but we did not check and
6404             --  are hesitant to add the check now.
6405
6406             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6407             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6408             --  or Ada 2012 mode.
6409
6410             if Ada_Version >= Ada_2005 then
6411                Check_Valid_Configuration_Pragma;
6412             end if;
6413
6414             --  Now set Ada 83 mode
6415
6416             Ada_Version := Ada_83;
6417             Ada_Version_Explicit := Ada_Version;
6418
6419          ------------
6420          -- Ada_95 --
6421          ------------
6422
6423          --  pragma Ada_95;
6424
6425          --  Note: this pragma also has some specific processing in Par.Prag
6426          --  because we want to set the Ada 83 version mode during parsing.
6427
6428          when Pragma_Ada_95 =>
6429             GNAT_Pragma;
6430             Check_Arg_Count (0);
6431
6432             --  We really should check unconditionally for proper configuration
6433             --  pragma placement, since we really don't want mixed Ada modes
6434             --  within a single unit, and the GNAT reference manual has always
6435             --  said this was a configuration pragma, but we did not check and
6436             --  are hesitant to add the check now.
6437
6438             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6439             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6440
6441             if Ada_Version >= Ada_2005 then
6442                Check_Valid_Configuration_Pragma;
6443             end if;
6444
6445             --  Now set Ada 95 mode
6446
6447             Ada_Version := Ada_95;
6448             Ada_Version_Explicit := Ada_Version;
6449
6450          ---------------------
6451          -- Ada_05/Ada_2005 --
6452          ---------------------
6453
6454          --  pragma Ada_05;
6455          --  pragma Ada_05 (LOCAL_NAME);
6456
6457          --  pragma Ada_2005;
6458          --  pragma Ada_2005 (LOCAL_NAME):
6459
6460          --  Note: these pragmas also have some specific processing in Par.Prag
6461          --  because we want to set the Ada 2005 version mode during parsing.
6462
6463          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6464             E_Id : Node_Id;
6465
6466          begin
6467             GNAT_Pragma;
6468
6469             if Arg_Count = 1 then
6470                Check_Arg_Is_Local_Name (Arg1);
6471                E_Id := Get_Pragma_Arg (Arg1);
6472
6473                if Etype (E_Id) = Any_Type then
6474                   return;
6475                end if;
6476
6477                Set_Is_Ada_2005_Only (Entity (E_Id));
6478
6479             else
6480                Check_Arg_Count (0);
6481
6482                --  For Ada_2005 we unconditionally enforce the documented
6483                --  configuration pragma placement, since we do not want to
6484                --  tolerate mixed modes in a unit involving Ada 2005. That
6485                --  would cause real difficulties for those cases where there
6486                --  are incompatibilities between Ada 95 and Ada 2005.
6487
6488                Check_Valid_Configuration_Pragma;
6489
6490                --  Now set appropriate Ada mode
6491
6492                Ada_Version          := Ada_2005;
6493                Ada_Version_Explicit := Ada_2005;
6494             end if;
6495          end;
6496
6497          ---------------------
6498          -- Ada_12/Ada_2012 --
6499          ---------------------
6500
6501          --  pragma Ada_12;
6502          --  pragma Ada_12 (LOCAL_NAME);
6503
6504          --  pragma Ada_2012;
6505          --  pragma Ada_2012 (LOCAL_NAME):
6506
6507          --  Note: these pragmas also have some specific processing in Par.Prag
6508          --  because we want to set the Ada 2012 version mode during parsing.
6509
6510          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6511             E_Id : Node_Id;
6512
6513          begin
6514             GNAT_Pragma;
6515
6516             if Arg_Count = 1 then
6517                Check_Arg_Is_Local_Name (Arg1);
6518                E_Id := Get_Pragma_Arg (Arg1);
6519
6520                if Etype (E_Id) = Any_Type then
6521                   return;
6522                end if;
6523
6524                Set_Is_Ada_2012_Only (Entity (E_Id));
6525
6526             else
6527                Check_Arg_Count (0);
6528
6529                --  For Ada_2012 we unconditionally enforce the documented
6530                --  configuration pragma placement, since we do not want to
6531                --  tolerate mixed modes in a unit involving Ada 2012. That
6532                --  would cause real difficulties for those cases where there
6533                --  are incompatibilities between Ada 95 and Ada 2012. We could
6534                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6535
6536                Check_Valid_Configuration_Pragma;
6537
6538                --  Now set appropriate Ada mode
6539
6540                Ada_Version          := Ada_2012;
6541                Ada_Version_Explicit := Ada_2012;
6542             end if;
6543          end;
6544
6545          ----------------------
6546          -- All_Calls_Remote --
6547          ----------------------
6548
6549          --  pragma All_Calls_Remote [(library_package_NAME)];
6550
6551          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6552             Lib_Entity : Entity_Id;
6553
6554          begin
6555             Check_Ada_83_Warning;
6556             Check_Valid_Library_Unit_Pragma;
6557
6558             if Nkind (N) = N_Null_Statement then
6559                return;
6560             end if;
6561
6562             Lib_Entity := Find_Lib_Unit_Name;
6563
6564             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6565
6566             if Present (Lib_Entity)
6567               and then not Debug_Flag_U
6568             then
6569                if not Is_Remote_Call_Interface (Lib_Entity) then
6570                   Error_Pragma ("pragma% only apply to rci unit");
6571
6572                --  Set flag for entity of the library unit
6573
6574                else
6575                   Set_Has_All_Calls_Remote (Lib_Entity);
6576                end if;
6577
6578             end if;
6579          end All_Calls_Remote;
6580
6581          --------------
6582          -- Annotate --
6583          --------------
6584
6585          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6586          --  ARG ::= NAME | EXPRESSION
6587
6588          --  The first two arguments are by convention intended to refer to an
6589          --  external tool and a tool-specific function. These arguments are
6590          --  not analyzed.
6591
6592          when Pragma_Annotate => Annotate : declare
6593             Arg : Node_Id;
6594             Exp : Node_Id;
6595
6596          begin
6597             GNAT_Pragma;
6598             Check_At_Least_N_Arguments (1);
6599             Check_Arg_Is_Identifier (Arg1);
6600             Check_No_Identifiers;
6601             Store_Note (N);
6602
6603             --  Second parameter is optional, it is never analyzed
6604
6605             if No (Arg2) then
6606                null;
6607
6608             --  Here if we have a second parameter
6609
6610             else
6611                --  Second parameter must be identifier
6612
6613                Check_Arg_Is_Identifier (Arg2);
6614
6615                --  Process remaining parameters if any
6616
6617                Arg := Next (Arg2);
6618                while Present (Arg) loop
6619                   Exp := Get_Pragma_Arg (Arg);
6620                   Analyze (Exp);
6621
6622                   if Is_Entity_Name (Exp) then
6623                      null;
6624
6625                   --  For string literals, we assume Standard_String as the
6626                   --  type, unless the string contains wide or wide_wide
6627                   --  characters.
6628
6629                   elsif Nkind (Exp) = N_String_Literal then
6630                      if Has_Wide_Wide_Character (Exp) then
6631                         Resolve (Exp, Standard_Wide_Wide_String);
6632                      elsif Has_Wide_Character (Exp) then
6633                         Resolve (Exp, Standard_Wide_String);
6634                      else
6635                         Resolve (Exp, Standard_String);
6636                      end if;
6637
6638                   elsif Is_Overloaded (Exp) then
6639                         Error_Pragma_Arg
6640                           ("ambiguous argument for pragma%", Exp);
6641
6642                   else
6643                      Resolve (Exp);
6644                   end if;
6645
6646                   Next (Arg);
6647                end loop;
6648             end if;
6649          end Annotate;
6650
6651          ------------
6652          -- Assert --
6653          ------------
6654
6655          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6656          --                 [, [Message =>] Static_String_EXPRESSION]);
6657
6658          when Pragma_Assert => Assert : declare
6659             Expr : Node_Id;
6660             Newa : List_Id;
6661
6662          begin
6663             Ada_2005_Pragma;
6664             Check_At_Least_N_Arguments (1);
6665             Check_At_Most_N_Arguments (2);
6666             Check_Arg_Order ((Name_Check, Name_Message));
6667             Check_Optional_Identifier (Arg1, Name_Check);
6668
6669             --  We treat pragma Assert as equivalent to:
6670
6671             --    pragma Check (Assertion, condition [, msg]);
6672
6673             --  So rewrite pragma in this manner, and analyze the result
6674
6675             Expr := Get_Pragma_Arg (Arg1);
6676             Newa := New_List (
6677               Make_Pragma_Argument_Association (Loc,
6678                 Expression => Make_Identifier (Loc, Name_Assertion)),
6679
6680               Make_Pragma_Argument_Association (Sloc (Expr),
6681                 Expression => Expr));
6682
6683             if Arg_Count > 1 then
6684                Check_Optional_Identifier (Arg2, Name_Message);
6685                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6686                Append_To (Newa, Relocate_Node (Arg2));
6687             end if;
6688
6689             Rewrite (N,
6690               Make_Pragma (Loc,
6691                 Chars                        => Name_Check,
6692                 Pragma_Argument_Associations => Newa));
6693             Analyze (N);
6694          end Assert;
6695
6696          ----------------------
6697          -- Assertion_Policy --
6698          ----------------------
6699
6700          --  pragma Assertion_Policy (Check | Disable |Ignore)
6701
6702          when Pragma_Assertion_Policy => Assertion_Policy : declare
6703             Policy : Node_Id;
6704
6705          begin
6706             Ada_2005_Pragma;
6707             Check_Valid_Configuration_Pragma;
6708             Check_Arg_Count (1);
6709             Check_No_Identifiers;
6710             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6711
6712             --  We treat pragma Assertion_Policy as equivalent to:
6713
6714             --    pragma Check_Policy (Assertion, policy)
6715
6716             --  So rewrite the pragma in that manner and link on to the chain
6717             --  of Check_Policy pragmas, marking the pragma as analyzed.
6718
6719             Policy := Get_Pragma_Arg (Arg1);
6720
6721             Rewrite (N,
6722               Make_Pragma (Loc,
6723                 Chars => Name_Check_Policy,
6724
6725                 Pragma_Argument_Associations => New_List (
6726                   Make_Pragma_Argument_Association (Loc,
6727                     Expression => Make_Identifier (Loc, Name_Assertion)),
6728
6729                   Make_Pragma_Argument_Association (Loc,
6730                     Expression =>
6731                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6732
6733             Set_Analyzed (N);
6734             Set_Next_Pragma (N, Opt.Check_Policy_List);
6735             Opt.Check_Policy_List := N;
6736          end Assertion_Policy;
6737
6738          ------------------------------
6739          -- Assume_No_Invalid_Values --
6740          ------------------------------
6741
6742          --  pragma Assume_No_Invalid_Values (On | Off);
6743
6744          when Pragma_Assume_No_Invalid_Values =>
6745             GNAT_Pragma;
6746             Check_Valid_Configuration_Pragma;
6747             Check_Arg_Count (1);
6748             Check_No_Identifiers;
6749             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6750
6751             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6752                Assume_No_Invalid_Values := True;
6753             else
6754                Assume_No_Invalid_Values := False;
6755             end if;
6756
6757          ---------------
6758          -- AST_Entry --
6759          ---------------
6760
6761          --  pragma AST_Entry (entry_IDENTIFIER);
6762
6763          when Pragma_AST_Entry => AST_Entry : declare
6764             Ent : Node_Id;
6765
6766          begin
6767             GNAT_Pragma;
6768             Check_VMS (N);
6769             Check_Arg_Count (1);
6770             Check_No_Identifiers;
6771             Check_Arg_Is_Local_Name (Arg1);
6772             Ent := Entity (Get_Pragma_Arg (Arg1));
6773
6774             --  Note: the implementation of the AST_Entry pragma could handle
6775             --  the entry family case fine, but for now we are consistent with
6776             --  the DEC rules, and do not allow the pragma, which of course
6777             --  has the effect of also forbidding the attribute.
6778
6779             if Ekind (Ent) /= E_Entry then
6780                Error_Pragma_Arg
6781                  ("pragma% argument must be simple entry name", Arg1);
6782
6783             elsif Is_AST_Entry (Ent) then
6784                Error_Pragma_Arg
6785                  ("duplicate % pragma for entry", Arg1);
6786
6787             elsif Has_Homonym (Ent) then
6788                Error_Pragma_Arg
6789                  ("pragma% argument cannot specify overloaded entry", Arg1);
6790
6791             else
6792                declare
6793                   FF : constant Entity_Id := First_Formal (Ent);
6794
6795                begin
6796                   if Present (FF) then
6797                      if Present (Next_Formal (FF)) then
6798                         Error_Pragma_Arg
6799                           ("entry for pragma% can have only one argument",
6800                            Arg1);
6801
6802                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6803                         Error_Pragma_Arg
6804                           ("entry parameter for pragma% must have mode IN",
6805                            Arg1);
6806                      end if;
6807                   end if;
6808                end;
6809
6810                Set_Is_AST_Entry (Ent);
6811             end if;
6812          end AST_Entry;
6813
6814          ------------------
6815          -- Asynchronous --
6816          ------------------
6817
6818          --  pragma Asynchronous (LOCAL_NAME);
6819
6820          when Pragma_Asynchronous => Asynchronous : declare
6821             Nm     : Entity_Id;
6822             C_Ent  : Entity_Id;
6823             L      : List_Id;
6824             S      : Node_Id;
6825             N      : Node_Id;
6826             Formal : Entity_Id;
6827
6828             procedure Process_Async_Pragma;
6829             --  Common processing for procedure and access-to-procedure case
6830
6831             --------------------------
6832             -- Process_Async_Pragma --
6833             --------------------------
6834
6835             procedure Process_Async_Pragma is
6836             begin
6837                if No (L) then
6838                   Set_Is_Asynchronous (Nm);
6839                   return;
6840                end if;
6841
6842                --  The formals should be of mode IN (RM E.4.1(6))
6843
6844                S := First (L);
6845                while Present (S) loop
6846                   Formal := Defining_Identifier (S);
6847
6848                   if Nkind (Formal) = N_Defining_Identifier
6849                     and then Ekind (Formal) /= E_In_Parameter
6850                   then
6851                      Error_Pragma_Arg
6852                        ("pragma% procedure can only have IN parameter",
6853                         Arg1);
6854                   end if;
6855
6856                   Next (S);
6857                end loop;
6858
6859                Set_Is_Asynchronous (Nm);
6860             end Process_Async_Pragma;
6861
6862          --  Start of processing for pragma Asynchronous
6863
6864          begin
6865             Check_Ada_83_Warning;
6866             Check_No_Identifiers;
6867             Check_Arg_Count (1);
6868             Check_Arg_Is_Local_Name (Arg1);
6869
6870             if Debug_Flag_U then
6871                return;
6872             end if;
6873
6874             C_Ent := Cunit_Entity (Current_Sem_Unit);
6875             Analyze (Get_Pragma_Arg (Arg1));
6876             Nm := Entity (Get_Pragma_Arg (Arg1));
6877
6878             if not Is_Remote_Call_Interface (C_Ent)
6879               and then not Is_Remote_Types (C_Ent)
6880             then
6881                --  This pragma should only appear in an RCI or Remote Types
6882                --  unit (RM E.4.1(4)).
6883
6884                Error_Pragma
6885                  ("pragma% not in Remote_Call_Interface or " &
6886                   "Remote_Types unit");
6887             end if;
6888
6889             if Ekind (Nm) = E_Procedure
6890               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6891             then
6892                if not Is_Remote_Call_Interface (Nm) then
6893                   Error_Pragma_Arg
6894                     ("pragma% cannot be applied on non-remote procedure",
6895                      Arg1);
6896                end if;
6897
6898                L := Parameter_Specifications (Parent (Nm));
6899                Process_Async_Pragma;
6900                return;
6901
6902             elsif Ekind (Nm) = E_Function then
6903                Error_Pragma_Arg
6904                  ("pragma% cannot be applied to function", Arg1);
6905
6906             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6907                   if Is_Record_Type (Nm) then
6908
6909                   --  A record type that is the Equivalent_Type for a remote
6910                   --  access-to-subprogram type.
6911
6912                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6913
6914                   else
6915                      --  A non-expanded RAS type (distribution is not enabled)
6916
6917                      N := Declaration_Node (Nm);
6918                   end if;
6919
6920                if Nkind (N) = N_Full_Type_Declaration
6921                  and then Nkind (Type_Definition (N)) =
6922                                      N_Access_Procedure_Definition
6923                then
6924                   L := Parameter_Specifications (Type_Definition (N));
6925                   Process_Async_Pragma;
6926
6927                   if Is_Asynchronous (Nm)
6928                     and then Expander_Active
6929                     and then Get_PCS_Name /= Name_No_DSA
6930                   then
6931                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6932                   end if;
6933
6934                else
6935                   Error_Pragma_Arg
6936                     ("pragma% cannot reference access-to-function type",
6937                     Arg1);
6938                end if;
6939
6940             --  Only other possibility is Access-to-class-wide type
6941
6942             elsif Is_Access_Type (Nm)
6943               and then Is_Class_Wide_Type (Designated_Type (Nm))
6944             then
6945                Check_First_Subtype (Arg1);
6946                Set_Is_Asynchronous (Nm);
6947                if Expander_Active then
6948                   RACW_Type_Is_Asynchronous (Nm);
6949                end if;
6950
6951             else
6952                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6953             end if;
6954          end Asynchronous;
6955
6956          ------------
6957          -- Atomic --
6958          ------------
6959
6960          --  pragma Atomic (LOCAL_NAME);
6961
6962          when Pragma_Atomic =>
6963             Process_Atomic_Shared_Volatile;
6964
6965          -----------------------
6966          -- Atomic_Components --
6967          -----------------------
6968
6969          --  pragma Atomic_Components (array_LOCAL_NAME);
6970
6971          --  This processing is shared by Volatile_Components
6972
6973          when Pragma_Atomic_Components   |
6974               Pragma_Volatile_Components =>
6975
6976          Atomic_Components : declare
6977             E_Id : Node_Id;
6978             E    : Entity_Id;
6979             D    : Node_Id;
6980             K    : Node_Kind;
6981
6982          begin
6983             Check_Ada_83_Warning;
6984             Check_No_Identifiers;
6985             Check_Arg_Count (1);
6986             Check_Arg_Is_Local_Name (Arg1);
6987             E_Id := Get_Pragma_Arg (Arg1);
6988
6989             if Etype (E_Id) = Any_Type then
6990                return;
6991             end if;
6992
6993             E := Entity (E_Id);
6994
6995             Check_Duplicate_Pragma (E);
6996
6997             if Rep_Item_Too_Early (E, N)
6998                  or else
6999                Rep_Item_Too_Late (E, N)
7000             then
7001                return;
7002             end if;
7003
7004             D := Declaration_Node (E);
7005             K := Nkind (D);
7006
7007             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
7008               or else
7009                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
7010                    and then Nkind (D) = N_Object_Declaration
7011                    and then Nkind (Object_Definition (D)) =
7012                                        N_Constrained_Array_Definition)
7013             then
7014                --  The flag is set on the object, or on the base type
7015
7016                if Nkind (D) /= N_Object_Declaration then
7017                   E := Base_Type (E);
7018                end if;
7019
7020                Set_Has_Volatile_Components (E);
7021
7022                if Prag_Id = Pragma_Atomic_Components then
7023                   Set_Has_Atomic_Components (E);
7024                end if;
7025
7026             else
7027                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7028             end if;
7029          end Atomic_Components;
7030          --------------------
7031          -- Attach_Handler --
7032          --------------------
7033
7034          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
7035
7036          when Pragma_Attach_Handler =>
7037             Check_Ada_83_Warning;
7038             Check_No_Identifiers;
7039             Check_Arg_Count (2);
7040
7041             if No_Run_Time_Mode then
7042                Error_Msg_CRT ("Attach_Handler pragma", N);
7043             else
7044                Check_Interrupt_Or_Attach_Handler;
7045
7046                --  The expression that designates the attribute may depend on a
7047                --  discriminant, and is therefore a per- object expression, to
7048                --  be expanded in the init proc. If expansion is enabled, then
7049                --  perform semantic checks on a copy only.
7050
7051                if Expander_Active then
7052                   declare
7053                      Temp : constant Node_Id :=
7054                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
7055                   begin
7056                      Set_Parent (Temp, N);
7057                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7058                   end;
7059
7060                else
7061                   Analyze (Get_Pragma_Arg (Arg2));
7062                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7063                end if;
7064
7065                Process_Interrupt_Or_Attach_Handler;
7066             end if;
7067
7068          --------------------
7069          -- C_Pass_By_Copy --
7070          --------------------
7071
7072          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7073
7074          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7075             Arg : Node_Id;
7076             Val : Uint;
7077
7078          begin
7079             GNAT_Pragma;
7080             Check_Valid_Configuration_Pragma;
7081             Check_Arg_Count (1);
7082             Check_Optional_Identifier (Arg1, "max_size");
7083
7084             Arg := Get_Pragma_Arg (Arg1);
7085             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7086
7087             Val := Expr_Value (Arg);
7088
7089             if Val <= 0 then
7090                Error_Pragma_Arg
7091                  ("maximum size for pragma% must be positive", Arg1);
7092
7093             elsif UI_Is_In_Int_Range (Val) then
7094                Default_C_Record_Mechanism := UI_To_Int (Val);
7095
7096             --  If a giant value is given, Int'Last will do well enough.
7097             --  If sometime someone complains that a record larger than
7098             --  two gigabytes is not copied, we will worry about it then!
7099
7100             else
7101                Default_C_Record_Mechanism := Mechanism_Type'Last;
7102             end if;
7103          end C_Pass_By_Copy;
7104
7105          -----------
7106          -- Check --
7107          -----------
7108
7109          --  pragma Check ([Name    =>] IDENTIFIER,
7110          --                [Check   =>] Boolean_EXPRESSION
7111          --              [,[Message =>] String_EXPRESSION]);
7112
7113          when Pragma_Check => Check : declare
7114             Expr : Node_Id;
7115             Eloc : Source_Ptr;
7116
7117             Check_On : Boolean;
7118             --  Set True if category of assertions referenced by Name enabled
7119
7120          begin
7121             GNAT_Pragma;
7122             Check_At_Least_N_Arguments (2);
7123             Check_At_Most_N_Arguments (3);
7124             Check_Optional_Identifier (Arg1, Name_Name);
7125             Check_Optional_Identifier (Arg2, Name_Check);
7126
7127             if Arg_Count = 3 then
7128                Check_Optional_Identifier (Arg3, Name_Message);
7129                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7130             end if;
7131
7132             Check_Arg_Is_Identifier (Arg1);
7133
7134             --  Completely ignore if disabled
7135
7136             if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7137                Rewrite (N, Make_Null_Statement (Loc));
7138                Analyze (N);
7139                return;
7140             end if;
7141
7142             --  Indicate if pragma is enabled. The Original_Node reference here
7143             --  is to deal with pragma Assert rewritten as a Check pragma.
7144
7145             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7146
7147             if Check_On then
7148                Set_SCO_Pragma_Enabled (Loc);
7149             end if;
7150
7151             --  If expansion is active and the check is not enabled then we
7152             --  rewrite the Check as:
7153
7154             --    if False and then condition then
7155             --       null;
7156             --    end if;
7157
7158             --  The reason we do this rewriting during semantic analysis rather
7159             --  than as part of normal expansion is that we cannot analyze and
7160             --  expand the code for the boolean expression directly, or it may
7161             --  cause insertion of actions that would escape the attempt to
7162             --  suppress the check code.
7163
7164             --  Note that the Sloc for the if statement corresponds to the
7165             --  argument condition, not the pragma itself. The reason for this
7166             --  is that we may generate a warning if the condition is False at
7167             --  compile time, and we do not want to delete this warning when we
7168             --  delete the if statement.
7169
7170             Expr := Get_Pragma_Arg (Arg2);
7171
7172             if Expander_Active and then not Check_On then
7173                Eloc := Sloc (Expr);
7174
7175                Rewrite (N,
7176                  Make_If_Statement (Eloc,
7177                    Condition =>
7178                      Make_And_Then (Eloc,
7179                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
7180                        Right_Opnd => Expr),
7181                    Then_Statements => New_List (
7182                      Make_Null_Statement (Eloc))));
7183
7184                Analyze (N);
7185
7186             --  Check is active
7187
7188             else
7189                Analyze_And_Resolve (Expr, Any_Boolean);
7190             end if;
7191          end Check;
7192
7193          ----------------
7194          -- Check_Name --
7195          ----------------
7196
7197          --  pragma Check_Name (check_IDENTIFIER);
7198
7199          when Pragma_Check_Name =>
7200             Check_No_Identifiers;
7201             GNAT_Pragma;
7202             Check_Valid_Configuration_Pragma;
7203             Check_Arg_Count (1);
7204             Check_Arg_Is_Identifier (Arg1);
7205
7206             declare
7207                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7208
7209             begin
7210                for J in Check_Names.First .. Check_Names.Last loop
7211                   if Check_Names.Table (J) = Nam then
7212                      return;
7213                   end if;
7214                end loop;
7215
7216                Check_Names.Append (Nam);
7217             end;
7218
7219          ------------------
7220          -- Check_Policy --
7221          ------------------
7222
7223          --  pragma Check_Policy (
7224          --    [Name   =>] IDENTIFIER,
7225          --    [Policy =>] POLICY_IDENTIFIER);
7226
7227          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7228
7229          --  Note: this is a configuration pragma, but it is allowed to appear
7230          --  anywhere else.
7231
7232          when Pragma_Check_Policy =>
7233             GNAT_Pragma;
7234             Check_Arg_Count (2);
7235             Check_Optional_Identifier (Arg1, Name_Name);
7236             Check_Optional_Identifier (Arg2, Name_Policy);
7237             Check_Arg_Is_One_Of
7238               (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7239
7240             --  A Check_Policy pragma can appear either as a configuration
7241             --  pragma, or in a declarative part or a package spec (see RM
7242             --  11.5(5) for rules for Suppress/Unsuppress which are also
7243             --  followed for Check_Policy).
7244
7245             if not Is_Configuration_Pragma then
7246                Check_Is_In_Decl_Part_Or_Package_Spec;
7247             end if;
7248
7249             Set_Next_Pragma (N, Opt.Check_Policy_List);
7250             Opt.Check_Policy_List := N;
7251
7252          ---------------------
7253          -- CIL_Constructor --
7254          ---------------------
7255
7256          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7257
7258          --  Processing for this pragma is shared with Java_Constructor
7259
7260          -------------
7261          -- Comment --
7262          -------------
7263
7264          --  pragma Comment (static_string_EXPRESSION)
7265
7266          --  Processing for pragma Comment shares the circuitry for pragma
7267          --  Ident. The only differences are that Ident enforces a limit of 31
7268          --  characters on its argument, and also enforces limitations on
7269          --  placement for DEC compatibility. Pragma Comment shares neither of
7270          --  these restrictions.
7271
7272          -------------------
7273          -- Common_Object --
7274          -------------------
7275
7276          --  pragma Common_Object (
7277          --        [Internal =>] LOCAL_NAME
7278          --     [, [External =>] EXTERNAL_SYMBOL]
7279          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7280
7281          --  Processing for this pragma is shared with Psect_Object
7282
7283          ------------------------
7284          -- Compile_Time_Error --
7285          ------------------------
7286
7287          --  pragma Compile_Time_Error
7288          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7289
7290          when Pragma_Compile_Time_Error =>
7291             GNAT_Pragma;
7292             Process_Compile_Time_Warning_Or_Error;
7293
7294          --------------------------
7295          -- Compile_Time_Warning --
7296          --------------------------
7297
7298          --  pragma Compile_Time_Warning
7299          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7300
7301          when Pragma_Compile_Time_Warning =>
7302             GNAT_Pragma;
7303             Process_Compile_Time_Warning_Or_Error;
7304
7305          -------------------
7306          -- Compiler_Unit --
7307          -------------------
7308
7309          when Pragma_Compiler_Unit =>
7310             GNAT_Pragma;
7311             Check_Arg_Count (0);
7312             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7313
7314          -----------------------------
7315          -- Complete_Representation --
7316          -----------------------------
7317
7318          --  pragma Complete_Representation;
7319
7320          when Pragma_Complete_Representation =>
7321             GNAT_Pragma;
7322             Check_Arg_Count (0);
7323
7324             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7325                Error_Pragma
7326                  ("pragma & must appear within record representation clause");
7327             end if;
7328
7329          ----------------------------
7330          -- Complex_Representation --
7331          ----------------------------
7332
7333          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7334
7335          when Pragma_Complex_Representation => Complex_Representation : declare
7336             E_Id : Entity_Id;
7337             E    : Entity_Id;
7338             Ent  : Entity_Id;
7339
7340          begin
7341             GNAT_Pragma;
7342             Check_Arg_Count (1);
7343             Check_Optional_Identifier (Arg1, Name_Entity);
7344             Check_Arg_Is_Local_Name (Arg1);
7345             E_Id := Get_Pragma_Arg (Arg1);
7346
7347             if Etype (E_Id) = Any_Type then
7348                return;
7349             end if;
7350
7351             E := Entity (E_Id);
7352
7353             if not Is_Record_Type (E) then
7354                Error_Pragma_Arg
7355                  ("argument for pragma% must be record type", Arg1);
7356             end if;
7357
7358             Ent := First_Entity (E);
7359
7360             if No (Ent)
7361               or else No (Next_Entity (Ent))
7362               or else Present (Next_Entity (Next_Entity (Ent)))
7363               or else not Is_Floating_Point_Type (Etype (Ent))
7364               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7365             then
7366                Error_Pragma_Arg
7367                  ("record for pragma% must have two fields of the same "
7368                   & "floating-point type", Arg1);
7369
7370             else
7371                Set_Has_Complex_Representation (Base_Type (E));
7372
7373                --  We need to treat the type has having a non-standard
7374                --  representation, for back-end purposes, even though in
7375                --  general a complex will have the default representation
7376                --  of a record with two real components.
7377
7378                Set_Has_Non_Standard_Rep (Base_Type (E));
7379             end if;
7380          end Complex_Representation;
7381
7382          -------------------------
7383          -- Component_Alignment --
7384          -------------------------
7385
7386          --  pragma Component_Alignment (
7387          --        [Form =>] ALIGNMENT_CHOICE
7388          --     [, [Name =>] type_LOCAL_NAME]);
7389          --
7390          --   ALIGNMENT_CHOICE ::=
7391          --     Component_Size
7392          --   | Component_Size_4
7393          --   | Storage_Unit
7394          --   | Default
7395
7396          when Pragma_Component_Alignment => Component_AlignmentP : declare
7397             Args  : Args_List (1 .. 2);
7398             Names : constant Name_List (1 .. 2) := (
7399                       Name_Form,
7400                       Name_Name);
7401
7402             Form  : Node_Id renames Args (1);
7403             Name  : Node_Id renames Args (2);
7404
7405             Atype : Component_Alignment_Kind;
7406             Typ   : Entity_Id;
7407
7408          begin
7409             GNAT_Pragma;
7410             Gather_Associations (Names, Args);
7411
7412             if No (Form) then
7413                Error_Pragma ("missing Form argument for pragma%");
7414             end if;
7415
7416             Check_Arg_Is_Identifier (Form);
7417
7418             --  Get proper alignment, note that Default = Component_Size on all
7419             --  machines we have so far, and we want to set this value rather
7420             --  than the default value to indicate that it has been explicitly
7421             --  set (and thus will not get overridden by the default component
7422             --  alignment for the current scope)
7423
7424             if Chars (Form) = Name_Component_Size then
7425                Atype := Calign_Component_Size;
7426
7427             elsif Chars (Form) = Name_Component_Size_4 then
7428                Atype := Calign_Component_Size_4;
7429
7430             elsif Chars (Form) = Name_Default then
7431                Atype := Calign_Component_Size;
7432
7433             elsif Chars (Form) = Name_Storage_Unit then
7434                Atype := Calign_Storage_Unit;
7435
7436             else
7437                Error_Pragma_Arg
7438                  ("invalid Form parameter for pragma%", Form);
7439             end if;
7440
7441             --  Case with no name, supplied, affects scope table entry
7442
7443             if No (Name) then
7444                Scope_Stack.Table
7445                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7446
7447             --  Case of name supplied
7448
7449             else
7450                Check_Arg_Is_Local_Name (Name);
7451                Find_Type (Name);
7452                Typ := Entity (Name);
7453
7454                if Typ = Any_Type
7455                  or else Rep_Item_Too_Early (Typ, N)
7456                then
7457                   return;
7458                else
7459                   Typ := Underlying_Type (Typ);
7460                end if;
7461
7462                if not Is_Record_Type (Typ)
7463                  and then not Is_Array_Type (Typ)
7464                then
7465                   Error_Pragma_Arg
7466                     ("Name parameter of pragma% must identify record or " &
7467                      "array type", Name);
7468                end if;
7469
7470                --  An explicit Component_Alignment pragma overrides an
7471                --  implicit pragma Pack, but not an explicit one.
7472
7473                if not Has_Pragma_Pack (Base_Type (Typ)) then
7474                   Set_Is_Packed (Base_Type (Typ), False);
7475                   Set_Component_Alignment (Base_Type (Typ), Atype);
7476                end if;
7477             end if;
7478          end Component_AlignmentP;
7479
7480          ----------------
7481          -- Controlled --
7482          ----------------
7483
7484          --  pragma Controlled (first_subtype_LOCAL_NAME);
7485
7486          when Pragma_Controlled => Controlled : declare
7487             Arg : Node_Id;
7488
7489          begin
7490             Check_No_Identifiers;
7491             Check_Arg_Count (1);
7492             Check_Arg_Is_Local_Name (Arg1);
7493             Arg := Get_Pragma_Arg (Arg1);
7494
7495             if not Is_Entity_Name (Arg)
7496               or else not Is_Access_Type (Entity (Arg))
7497             then
7498                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7499             else
7500                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7501             end if;
7502          end Controlled;
7503
7504          ----------------
7505          -- Convention --
7506          ----------------
7507
7508          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7509          --    [Entity =>] LOCAL_NAME);
7510
7511          when Pragma_Convention => Convention : declare
7512             C : Convention_Id;
7513             E : Entity_Id;
7514             pragma Warnings (Off, C);
7515             pragma Warnings (Off, E);
7516          begin
7517             Check_Arg_Order ((Name_Convention, Name_Entity));
7518             Check_Ada_83_Warning;
7519             Check_Arg_Count (2);
7520             Process_Convention (C, E);
7521          end Convention;
7522
7523          ---------------------------
7524          -- Convention_Identifier --
7525          ---------------------------
7526
7527          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7528          --    [Convention =>] convention_IDENTIFIER);
7529
7530          when Pragma_Convention_Identifier => Convention_Identifier : declare
7531             Idnam : Name_Id;
7532             Cname : Name_Id;
7533
7534          begin
7535             GNAT_Pragma;
7536             Check_Arg_Order ((Name_Name, Name_Convention));
7537             Check_Arg_Count (2);
7538             Check_Optional_Identifier (Arg1, Name_Name);
7539             Check_Optional_Identifier (Arg2, Name_Convention);
7540             Check_Arg_Is_Identifier (Arg1);
7541             Check_Arg_Is_Identifier (Arg2);
7542             Idnam := Chars (Get_Pragma_Arg (Arg1));
7543             Cname := Chars (Get_Pragma_Arg (Arg2));
7544
7545             if Is_Convention_Name (Cname) then
7546                Record_Convention_Identifier
7547                  (Idnam, Get_Convention_Id (Cname));
7548             else
7549                Error_Pragma_Arg
7550                  ("second arg for % pragma must be convention", Arg2);
7551             end if;
7552          end Convention_Identifier;
7553
7554          ---------------
7555          -- CPP_Class --
7556          ---------------
7557
7558          --  pragma CPP_Class ([Entity =>] local_NAME)
7559
7560          when Pragma_CPP_Class => CPP_Class : declare
7561             Arg : Node_Id;
7562             Typ : Entity_Id;
7563
7564          begin
7565             if Warn_On_Obsolescent_Feature then
7566                Error_Msg_N
7567                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7568                   " by pragma import?", N);
7569             end if;
7570
7571             GNAT_Pragma;
7572             Check_Arg_Count (1);
7573             Check_Optional_Identifier (Arg1, Name_Entity);
7574             Check_Arg_Is_Local_Name (Arg1);
7575
7576             Arg := Get_Pragma_Arg (Arg1);
7577             Analyze (Arg);
7578
7579             if Etype (Arg) = Any_Type then
7580                return;
7581             end if;
7582
7583             if not Is_Entity_Name (Arg)
7584               or else not Is_Type (Entity (Arg))
7585             then
7586                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7587             end if;
7588
7589             Typ := Entity (Arg);
7590
7591             if not Is_Tagged_Type (Typ) then
7592                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7593             end if;
7594
7595             --  Types treated as CPP classes must be declared limited (note:
7596             --  this used to be a warning but there is no real benefit to it
7597             --  since we did effectively intend to treat the type as limited
7598             --  anyway).
7599
7600             if not Is_Limited_Type (Typ) then
7601                Error_Msg_N
7602                  ("imported 'C'P'P type must be limited",
7603                   Get_Pragma_Arg (Arg1));
7604             end if;
7605
7606             Set_Is_CPP_Class      (Typ);
7607             Set_Convention        (Typ, Convention_CPP);
7608
7609             --  Imported CPP types must not have discriminants (because C++
7610             --  classes do not have discriminants).
7611
7612             if Has_Discriminants (Typ) then
7613                Error_Msg_N
7614                  ("imported 'C'P'P type cannot have discriminants",
7615                   First (Discriminant_Specifications
7616                           (Declaration_Node (Typ))));
7617             end if;
7618
7619             --  Components of imported CPP types must not have default
7620             --  expressions because the constructor (if any) is in the
7621             --  C++ side.
7622
7623             if Is_Incomplete_Or_Private_Type (Typ)
7624               and then No (Underlying_Type (Typ))
7625             then
7626                --  It should be an error to apply pragma CPP to a private
7627                --  type if the underlying type is not visible (as it is
7628                --  for any representation item). For now, for backward
7629                --  compatibility we do nothing but we cannot check components
7630                --  because they are not available at this stage. All this code
7631                --  will be removed when we cleanup this obsolete GNAT pragma???
7632
7633                null;
7634
7635             else
7636                declare
7637                   Tdef  : constant Node_Id :=
7638                             Type_Definition (Declaration_Node (Typ));
7639                   Clist : Node_Id;
7640                   Comp  : Node_Id;
7641
7642                begin
7643                   if Nkind (Tdef) = N_Record_Definition then
7644                      Clist := Component_List (Tdef);
7645                   else
7646                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7647                      Clist := Component_List (Record_Extension_Part (Tdef));
7648                   end if;
7649
7650                   if Present (Clist) then
7651                      Comp := First (Component_Items (Clist));
7652                      while Present (Comp) loop
7653                         if Present (Expression (Comp)) then
7654                            Error_Msg_N
7655                              ("component of imported 'C'P'P type cannot have" &
7656                               " default expression", Expression (Comp));
7657                         end if;
7658
7659                         Next (Comp);
7660                      end loop;
7661                   end if;
7662                end;
7663             end if;
7664          end CPP_Class;
7665
7666          ---------------------
7667          -- CPP_Constructor --
7668          ---------------------
7669
7670          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7671          --    [, [External_Name =>] static_string_EXPRESSION ]
7672          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7673
7674          when Pragma_CPP_Constructor => CPP_Constructor : declare
7675             Elmt    : Elmt_Id;
7676             Id      : Entity_Id;
7677             Def_Id  : Entity_Id;
7678             Tag_Typ : Entity_Id;
7679
7680          begin
7681             GNAT_Pragma;
7682             Check_At_Least_N_Arguments (1);
7683             Check_At_Most_N_Arguments (3);
7684             Check_Optional_Identifier (Arg1, Name_Entity);
7685             Check_Arg_Is_Local_Name (Arg1);
7686
7687             Id := Get_Pragma_Arg (Arg1);
7688             Find_Program_Unit_Name (Id);
7689
7690             --  If we did not find the name, we are done
7691
7692             if Etype (Id) = Any_Type then
7693                return;
7694             end if;
7695
7696             Def_Id := Entity (Id);
7697
7698             --  Check if already defined as constructor
7699
7700             if Is_Constructor (Def_Id) then
7701                Error_Msg_N
7702                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7703                return;
7704             end if;
7705
7706             if Ekind (Def_Id) = E_Function
7707               and then (Is_CPP_Class (Etype (Def_Id))
7708                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7709                                    and then
7710                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7711             then
7712                if Arg_Count >= 2 then
7713                   Set_Imported (Def_Id);
7714                   Set_Is_Public (Def_Id);
7715                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7716                end if;
7717
7718                Set_Has_Completion (Def_Id);
7719                Set_Is_Constructor (Def_Id);
7720
7721                --  Imported C++ constructors are not dispatching primitives
7722                --  because in C++ they don't have a dispatch table slot.
7723                --  However, in Ada the constructor has the profile of a
7724                --  function that returns a tagged type and therefore it has
7725                --  been treated as a primitive operation during semantic
7726                --  analysis. We now remove it from the list of primitive
7727                --  operations of the type.
7728
7729                if Is_Tagged_Type (Etype (Def_Id))
7730                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7731                then
7732                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7733                   Tag_Typ := Etype (Def_Id);
7734
7735                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7736                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7737                      Next_Elmt (Elmt);
7738                   end loop;
7739
7740                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7741                   Set_Is_Dispatching_Operation (Def_Id, False);
7742                end if;
7743
7744                --  For backward compatibility, if the constructor returns a
7745                --  class wide type, and we internally change the return type to
7746                --  the corresponding root type.
7747
7748                if Is_Class_Wide_Type (Etype (Def_Id)) then
7749                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7750                end if;
7751             else
7752                Error_Pragma_Arg
7753                  ("pragma% requires function returning a 'C'P'P_Class type",
7754                    Arg1);
7755             end if;
7756          end CPP_Constructor;
7757
7758          -----------------
7759          -- CPP_Virtual --
7760          -----------------
7761
7762          when Pragma_CPP_Virtual => CPP_Virtual : declare
7763          begin
7764             GNAT_Pragma;
7765
7766             if Warn_On_Obsolescent_Feature then
7767                Error_Msg_N
7768                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7769                   "no effect?", N);
7770             end if;
7771          end CPP_Virtual;
7772
7773          ----------------
7774          -- CPP_Vtable --
7775          ----------------
7776
7777          when Pragma_CPP_Vtable => CPP_Vtable : declare
7778          begin
7779             GNAT_Pragma;
7780
7781             if Warn_On_Obsolescent_Feature then
7782                Error_Msg_N
7783                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7784                   "no effect?", N);
7785             end if;
7786          end CPP_Vtable;
7787
7788          ---------
7789          -- CPU --
7790          ---------
7791
7792          --  pragma CPU (EXPRESSION);
7793
7794          when Pragma_CPU => CPU : declare
7795             P   : constant Node_Id := Parent (N);
7796             Arg : Node_Id;
7797
7798          begin
7799             Ada_2012_Pragma;
7800             Check_No_Identifiers;
7801             Check_Arg_Count (1);
7802
7803             --  Subprogram case
7804
7805             if Nkind (P) = N_Subprogram_Body then
7806                Check_In_Main_Program;
7807
7808                Arg := Get_Pragma_Arg (Arg1);
7809                Analyze_And_Resolve (Arg, Any_Integer);
7810
7811                --  Must be static
7812
7813                if not Is_Static_Expression (Arg) then
7814                   Flag_Non_Static_Expr
7815                     ("main subprogram affinity is not static!", Arg);
7816                   raise Pragma_Exit;
7817
7818                --  If constraint error, then we already signalled an error
7819
7820                elsif Raises_Constraint_Error (Arg) then
7821                   null;
7822
7823                --  Otherwise check in range
7824
7825                else
7826                   declare
7827                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7828                      --  This is the entity System.Multiprocessors.CPU_Range;
7829
7830                      Val : constant Uint := Expr_Value (Arg);
7831
7832                   begin
7833                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7834                           or else
7835                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7836                      then
7837                         Error_Pragma_Arg
7838                           ("main subprogram CPU is out of range", Arg1);
7839                      end if;
7840                   end;
7841                end if;
7842
7843                Set_Main_CPU
7844                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7845
7846             --  Task case
7847
7848             elsif Nkind (P) = N_Task_Definition then
7849                Arg := Get_Pragma_Arg (Arg1);
7850
7851                --  The expression must be analyzed in the special manner
7852                --  described in "Handling of Default and Per-Object
7853                --  Expressions" in sem.ads.
7854
7855                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7856
7857             --  Anything else is incorrect
7858
7859             else
7860                Pragma_Misplaced;
7861             end if;
7862
7863             if Has_Pragma_CPU (P) then
7864                Error_Pragma ("duplicate pragma% not allowed");
7865             else
7866                Set_Has_Pragma_CPU (P, True);
7867
7868                if Nkind (P) = N_Task_Definition then
7869                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7870                end if;
7871             end if;
7872          end CPU;
7873
7874          -----------
7875          -- Debug --
7876          -----------
7877
7878          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7879
7880          when Pragma_Debug => Debug : declare
7881             Cond : Node_Id;
7882             Call : Node_Id;
7883
7884          begin
7885             GNAT_Pragma;
7886
7887             --  Skip analysis if disabled
7888
7889             if Debug_Pragmas_Disabled then
7890                Rewrite (N, Make_Null_Statement (Loc));
7891                Analyze (N);
7892                return;
7893             end if;
7894
7895             Cond :=
7896               New_Occurrence_Of
7897                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7898                  Loc);
7899
7900             if Debug_Pragmas_Enabled then
7901                Set_SCO_Pragma_Enabled (Loc);
7902             end if;
7903
7904             if Arg_Count = 2 then
7905                Cond :=
7906                  Make_And_Then (Loc,
7907                    Left_Opnd  => Relocate_Node (Cond),
7908                    Right_Opnd => Get_Pragma_Arg (Arg1));
7909                Call := Get_Pragma_Arg (Arg2);
7910             else
7911                Call := Get_Pragma_Arg (Arg1);
7912             end if;
7913
7914             if Nkind_In (Call,
7915                  N_Indexed_Component,
7916                  N_Function_Call,
7917                  N_Identifier,
7918                  N_Expanded_Name,
7919                  N_Selected_Component)
7920             then
7921                --  If this pragma Debug comes from source, its argument was
7922                --  parsed as a name form (which is syntactically identical).
7923                --  In a generic context a parameterless call will be left as
7924                --  an expanded name (if global) or selected_component if local.
7925                --  Change it to a procedure call statement now.
7926
7927                Change_Name_To_Procedure_Call_Statement (Call);
7928
7929             elsif Nkind (Call) = N_Procedure_Call_Statement then
7930
7931                --  Already in the form of a procedure call statement: nothing
7932                --  to do (could happen in case of an internally generated
7933                --  pragma Debug).
7934
7935                null;
7936
7937             else
7938                --  All other cases: diagnose error
7939
7940                Error_Msg
7941                  ("argument of pragma ""Debug"" is not procedure call",
7942                   Sloc (Call));
7943                return;
7944             end if;
7945
7946             --  Rewrite into a conditional with an appropriate condition. We
7947             --  wrap the procedure call in a block so that overhead from e.g.
7948             --  use of the secondary stack does not generate execution overhead
7949             --  for suppressed conditions.
7950
7951             Rewrite (N, Make_Implicit_If_Statement (N,
7952               Condition => Cond,
7953                  Then_Statements => New_List (
7954                    Make_Block_Statement (Loc,
7955                      Handled_Statement_Sequence =>
7956                        Make_Handled_Sequence_Of_Statements (Loc,
7957                          Statements => New_List (Relocate_Node (Call)))))));
7958             Analyze (N);
7959          end Debug;
7960
7961          ------------------
7962          -- Debug_Policy --
7963          ------------------
7964
7965          --  pragma Debug_Policy (Check | Ignore)
7966
7967          when Pragma_Debug_Policy =>
7968             GNAT_Pragma;
7969             Check_Arg_Count (1);
7970             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7971             Debug_Pragmas_Enabled :=
7972               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7973             Debug_Pragmas_Disabled :=
7974               Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7975
7976          ---------------------
7977          -- Detect_Blocking --
7978          ---------------------
7979
7980          --  pragma Detect_Blocking;
7981
7982          when Pragma_Detect_Blocking =>
7983             Ada_2005_Pragma;
7984             Check_Arg_Count (0);
7985             Check_Valid_Configuration_Pragma;
7986             Detect_Blocking := True;
7987
7988          --------------------------
7989          -- Default_Storage_Pool --
7990          --------------------------
7991
7992          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7993
7994          when Pragma_Default_Storage_Pool =>
7995             Ada_2012_Pragma;
7996             Check_Arg_Count (1);
7997
7998             --  Default_Storage_Pool can appear as a configuration pragma, or
7999             --  in a declarative part or a package spec.
8000
8001             if not Is_Configuration_Pragma then
8002                Check_Is_In_Decl_Part_Or_Package_Spec;
8003             end if;
8004
8005             --  Case of Default_Storage_Pool (null);
8006
8007             if Nkind (Expression (Arg1)) = N_Null then
8008                Analyze (Expression (Arg1));
8009
8010                --  This is an odd case, this is not really an expression, so
8011                --  we don't have a type for it. So just set the type to Empty.
8012
8013                Set_Etype (Expression (Arg1), Empty);
8014
8015             --  Case of Default_Storage_Pool (storage_pool_NAME);
8016
8017             else
8018                --  If it's a configuration pragma, then the only allowed
8019                --  argument is "null".
8020
8021                if Is_Configuration_Pragma then
8022                   Error_Pragma_Arg ("NULL expected", Arg1);
8023                end if;
8024
8025                --  The expected type for a non-"null" argument is
8026                --  Root_Storage_Pool'Class.
8027
8028                Analyze_And_Resolve
8029                  (Get_Pragma_Arg (Arg1),
8030                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8031             end if;
8032
8033             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
8034             --  for an access type will use this information to set the
8035             --  appropriate attributes of the access type.
8036
8037             Default_Pool := Expression (Arg1);
8038
8039          ---------------
8040          -- Dimension --
8041          ---------------
8042
8043          when Pragma_Dimension =>
8044             GNAT_Pragma;
8045             Check_Arg_Count (4);
8046             Check_No_Identifiers;
8047             Check_Arg_Is_Local_Name (Arg1);
8048
8049             if not Is_Type (Arg1) then
8050                Error_Pragma ("first argument for pragma% must be subtype");
8051             end if;
8052
8053             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
8054             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
8055             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
8056
8057          ------------------------------------
8058          -- Disable_Atomic_Synchronization --
8059          ------------------------------------
8060
8061          --  pragma Disable_Atomic_Synchronization [(Entity)];
8062
8063          when Pragma_Disable_Atomic_Synchronization =>
8064             Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8065
8066          -------------------
8067          -- Discard_Names --
8068          -------------------
8069
8070          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
8071
8072          when Pragma_Discard_Names => Discard_Names : declare
8073             E    : Entity_Id;
8074             E_Id : Entity_Id;
8075
8076          begin
8077             Check_Ada_83_Warning;
8078
8079             --  Deal with configuration pragma case
8080
8081             if Arg_Count = 0 and then Is_Configuration_Pragma then
8082                Global_Discard_Names := True;
8083                return;
8084
8085             --  Otherwise, check correct appropriate context
8086
8087             else
8088                Check_Is_In_Decl_Part_Or_Package_Spec;
8089
8090                if Arg_Count = 0 then
8091
8092                   --  If there is no parameter, then from now on this pragma
8093                   --  applies to any enumeration, exception or tagged type
8094                   --  defined in the current declarative part, and recursively
8095                   --  to any nested scope.
8096
8097                   Set_Discard_Names (Current_Scope);
8098                   return;
8099
8100                else
8101                   Check_Arg_Count (1);
8102                   Check_Optional_Identifier (Arg1, Name_On);
8103                   Check_Arg_Is_Local_Name (Arg1);
8104
8105                   E_Id := Get_Pragma_Arg (Arg1);
8106
8107                   if Etype (E_Id) = Any_Type then
8108                      return;
8109                   else
8110                      E := Entity (E_Id);
8111                   end if;
8112
8113                   if (Is_First_Subtype (E)
8114                       and then
8115                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8116                     or else Ekind (E) = E_Exception
8117                   then
8118                      Set_Discard_Names (E);
8119                   else
8120                      Error_Pragma_Arg
8121                        ("inappropriate entity for pragma%", Arg1);
8122                   end if;
8123
8124                end if;
8125             end if;
8126          end Discard_Names;
8127
8128          ------------------------
8129          -- Dispatching_Domain --
8130          ------------------------
8131
8132          --  pragma Dispatching_Domain (EXPRESSION);
8133
8134          when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8135             P   : constant Node_Id := Parent (N);
8136             Arg : Node_Id;
8137
8138          begin
8139             Ada_2012_Pragma;
8140             Check_No_Identifiers;
8141             Check_Arg_Count (1);
8142
8143             --  This pragma is born obsolete, but not the aspect
8144
8145             if not From_Aspect_Specification (N) then
8146                Check_Restriction
8147                  (No_Obsolescent_Features, Pragma_Identifier (N));
8148             end if;
8149
8150             if Nkind (P) = N_Task_Definition then
8151                Arg := Get_Pragma_Arg (Arg1);
8152
8153                --  The expression must be analyzed in the special manner
8154                --  described in "Handling of Default and Per-Object
8155                --  Expressions" in sem.ads.
8156
8157                Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8158
8159             --  Anything else is incorrect
8160
8161             else
8162                Pragma_Misplaced;
8163             end if;
8164
8165             if Has_Pragma_Dispatching_Domain (P) then
8166                Error_Pragma ("duplicate pragma% not allowed");
8167             else
8168                Set_Has_Pragma_Dispatching_Domain (P, True);
8169
8170                if Nkind (P) = N_Task_Definition then
8171                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8172                end if;
8173             end if;
8174          end Dispatching_Domain;
8175
8176          ---------------
8177          -- Elaborate --
8178          ---------------
8179
8180          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8181
8182          when Pragma_Elaborate => Elaborate : declare
8183             Arg   : Node_Id;
8184             Citem : Node_Id;
8185
8186          begin
8187             --  Pragma must be in context items list of a compilation unit
8188
8189             if not Is_In_Context_Clause then
8190                Pragma_Misplaced;
8191             end if;
8192
8193             --  Must be at least one argument
8194
8195             if Arg_Count = 0 then
8196                Error_Pragma ("pragma% requires at least one argument");
8197             end if;
8198
8199             --  In Ada 83 mode, there can be no items following it in the
8200             --  context list except other pragmas and implicit with clauses
8201             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8202             --  placement rule does not apply.
8203
8204             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8205                Citem := Next (N);
8206                while Present (Citem) loop
8207                   if Nkind (Citem) = N_Pragma
8208                     or else (Nkind (Citem) = N_With_Clause
8209                               and then Implicit_With (Citem))
8210                   then
8211                      null;
8212                   else
8213                      Error_Pragma
8214                        ("(Ada 83) pragma% must be at end of context clause");
8215                   end if;
8216
8217                   Next (Citem);
8218                end loop;
8219             end if;
8220
8221             --  Finally, the arguments must all be units mentioned in a with
8222             --  clause in the same context clause. Note we already checked (in
8223             --  Par.Prag) that the arguments are all identifiers or selected
8224             --  components.
8225
8226             Arg := Arg1;
8227             Outer : while Present (Arg) loop
8228                Citem := First (List_Containing (N));
8229                Inner : while Citem /= N loop
8230                   if Nkind (Citem) = N_With_Clause
8231                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8232                   then
8233                      Set_Elaborate_Present (Citem, True);
8234                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8235                      Generate_Reference (Entity (Name (Citem)), Citem);
8236
8237                      --  With the pragma present, elaboration calls on
8238                      --  subprograms from the named unit need no further
8239                      --  checks, as long as the pragma appears in the current
8240                      --  compilation unit. If the pragma appears in some unit
8241                      --  in the context, there might still be a need for an
8242                      --  Elaborate_All_Desirable from the current compilation
8243                      --  to the named unit, so we keep the check enabled.
8244
8245                      if In_Extended_Main_Source_Unit (N) then
8246                         Set_Suppress_Elaboration_Warnings
8247                           (Entity (Name (Citem)));
8248                      end if;
8249
8250                      exit Inner;
8251                   end if;
8252
8253                   Next (Citem);
8254                end loop Inner;
8255
8256                if Citem = N then
8257                   Error_Pragma_Arg
8258                     ("argument of pragma% is not with'ed unit", Arg);
8259                end if;
8260
8261                Next (Arg);
8262             end loop Outer;
8263
8264             --  Give a warning if operating in static mode with -gnatwl
8265             --  (elaboration warnings enabled) switch set.
8266
8267             if Elab_Warnings and not Dynamic_Elaboration_Checks then
8268                Error_Msg_N
8269                  ("?use of pragma Elaborate may not be safe", N);
8270                Error_Msg_N
8271                  ("?use pragma Elaborate_All instead if possible", N);
8272             end if;
8273          end Elaborate;
8274
8275          -------------------
8276          -- Elaborate_All --
8277          -------------------
8278
8279          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8280
8281          when Pragma_Elaborate_All => Elaborate_All : declare
8282             Arg   : Node_Id;
8283             Citem : Node_Id;
8284
8285          begin
8286             Check_Ada_83_Warning;
8287
8288             --  Pragma must be in context items list of a compilation unit
8289
8290             if not Is_In_Context_Clause then
8291                Pragma_Misplaced;
8292             end if;
8293
8294             --  Must be at least one argument
8295
8296             if Arg_Count = 0 then
8297                Error_Pragma ("pragma% requires at least one argument");
8298             end if;
8299
8300             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
8301             --  have to appear at the end of the context clause, but may
8302             --  appear mixed in with other items, even in Ada 83 mode.
8303
8304             --  Final check: the arguments must all be units mentioned in
8305             --  a with clause in the same context clause. Note that we
8306             --  already checked (in Par.Prag) that all the arguments are
8307             --  either identifiers or selected components.
8308
8309             Arg := Arg1;
8310             Outr : while Present (Arg) loop
8311                Citem := First (List_Containing (N));
8312                Innr : while Citem /= N loop
8313                   if Nkind (Citem) = N_With_Clause
8314                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8315                   then
8316                      Set_Elaborate_All_Present (Citem, True);
8317                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8318
8319                      --  Suppress warnings and elaboration checks on the named
8320                      --  unit if the pragma is in the current compilation, as
8321                      --  for pragma Elaborate.
8322
8323                      if In_Extended_Main_Source_Unit (N) then
8324                         Set_Suppress_Elaboration_Warnings
8325                           (Entity (Name (Citem)));
8326                      end if;
8327                      exit Innr;
8328                   end if;
8329
8330                   Next (Citem);
8331                end loop Innr;
8332
8333                if Citem = N then
8334                   Set_Error_Posted (N);
8335                   Error_Pragma_Arg
8336                     ("argument of pragma% is not with'ed unit", Arg);
8337                end if;
8338
8339                Next (Arg);
8340             end loop Outr;
8341          end Elaborate_All;
8342
8343          --------------------
8344          -- Elaborate_Body --
8345          --------------------
8346
8347          --  pragma Elaborate_Body [( library_unit_NAME )];
8348
8349          when Pragma_Elaborate_Body => Elaborate_Body : declare
8350             Cunit_Node : Node_Id;
8351             Cunit_Ent  : Entity_Id;
8352
8353          begin
8354             Check_Ada_83_Warning;
8355             Check_Valid_Library_Unit_Pragma;
8356
8357             if Nkind (N) = N_Null_Statement then
8358                return;
8359             end if;
8360
8361             Cunit_Node := Cunit (Current_Sem_Unit);
8362             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8363
8364             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8365                                             N_Subprogram_Body)
8366             then
8367                Error_Pragma ("pragma% must refer to a spec, not a body");
8368             else
8369                Set_Body_Required (Cunit_Node, True);
8370                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8371
8372                --  If we are in dynamic elaboration mode, then we suppress
8373                --  elaboration warnings for the unit, since it is definitely
8374                --  fine NOT to do dynamic checks at the first level (and such
8375                --  checks will be suppressed because no elaboration boolean
8376                --  is created for Elaborate_Body packages).
8377
8378                --  But in the static model of elaboration, Elaborate_Body is
8379                --  definitely NOT good enough to ensure elaboration safety on
8380                --  its own, since the body may WITH other units that are not
8381                --  safe from an elaboration point of view, so a client must
8382                --  still do an Elaborate_All on such units.
8383
8384                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8385                --  Elaborate_Body always suppressed elab warnings.
8386
8387                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8388                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8389                end if;
8390             end if;
8391          end Elaborate_Body;
8392
8393          ------------------------
8394          -- Elaboration_Checks --
8395          ------------------------
8396
8397          --  pragma Elaboration_Checks (Static | Dynamic);
8398
8399          when Pragma_Elaboration_Checks =>
8400             GNAT_Pragma;
8401             Check_Arg_Count (1);
8402             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8403             Dynamic_Elaboration_Checks :=
8404               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8405
8406          ---------------
8407          -- Eliminate --
8408          ---------------
8409
8410          --  pragma Eliminate (
8411          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8412          --    [,[Entity     =>] IDENTIFIER |
8413          --                      SELECTED_COMPONENT |
8414          --                      STRING_LITERAL]
8415          --    [,                OVERLOADING_RESOLUTION]);
8416
8417          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8418          --                             SOURCE_LOCATION
8419
8420          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8421          --                                        FUNCTION_PROFILE
8422
8423          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8424
8425          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8426          --                       Result_Type => result_SUBTYPE_NAME]
8427
8428          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8429          --  SUBTYPE_NAME    ::= STRING_LITERAL
8430
8431          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8432          --  SOURCE_TRACE    ::= STRING_LITERAL
8433
8434          when Pragma_Eliminate => Eliminate : declare
8435             Args  : Args_List (1 .. 5);
8436             Names : constant Name_List (1 .. 5) := (
8437                       Name_Unit_Name,
8438                       Name_Entity,
8439                       Name_Parameter_Types,
8440                       Name_Result_Type,
8441                       Name_Source_Location);
8442
8443             Unit_Name       : Node_Id renames Args (1);
8444             Entity          : Node_Id renames Args (2);
8445             Parameter_Types : Node_Id renames Args (3);
8446             Result_Type     : Node_Id renames Args (4);
8447             Source_Location : Node_Id renames Args (5);
8448
8449          begin
8450             GNAT_Pragma;
8451             Check_Valid_Configuration_Pragma;
8452             Gather_Associations (Names, Args);
8453
8454             if No (Unit_Name) then
8455                Error_Pragma ("missing Unit_Name argument for pragma%");
8456             end if;
8457
8458             if No (Entity)
8459               and then (Present (Parameter_Types)
8460                           or else
8461                         Present (Result_Type)
8462                           or else
8463                         Present (Source_Location))
8464             then
8465                Error_Pragma ("missing Entity argument for pragma%");
8466             end if;
8467
8468             if (Present (Parameter_Types)
8469                   or else
8470                 Present (Result_Type))
8471               and then
8472                 Present (Source_Location)
8473             then
8474                Error_Pragma
8475                  ("parameter profile and source location cannot " &
8476                   "be used together in pragma%");
8477             end if;
8478
8479             Process_Eliminate_Pragma
8480               (N,
8481                Unit_Name,
8482                Entity,
8483                Parameter_Types,
8484                Result_Type,
8485                Source_Location);
8486          end Eliminate;
8487
8488          -----------------------------------
8489          -- Enable_Atomic_Synchronization --
8490          -----------------------------------
8491
8492          --  pragma Enable_Atomic_Synchronization [(Entity)];
8493
8494          when Pragma_Enable_Atomic_Synchronization =>
8495             Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8496
8497          ------------
8498          -- Export --
8499          ------------
8500
8501          --  pragma Export (
8502          --    [   Convention    =>] convention_IDENTIFIER,
8503          --    [   Entity        =>] local_NAME
8504          --    [, [External_Name =>] static_string_EXPRESSION ]
8505          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8506
8507          when Pragma_Export => Export : declare
8508             C      : Convention_Id;
8509             Def_Id : Entity_Id;
8510
8511             pragma Warnings (Off, C);
8512
8513          begin
8514             Check_Ada_83_Warning;
8515             Check_Arg_Order
8516               ((Name_Convention,
8517                 Name_Entity,
8518                 Name_External_Name,
8519                 Name_Link_Name));
8520             Check_At_Least_N_Arguments (2);
8521             Check_At_Most_N_Arguments  (4);
8522             Process_Convention (C, Def_Id);
8523
8524             if Ekind (Def_Id) /= E_Constant then
8525                Note_Possible_Modification
8526                  (Get_Pragma_Arg (Arg2), Sure => False);
8527             end if;
8528
8529             Process_Interface_Name (Def_Id, Arg3, Arg4);
8530             Set_Exported (Def_Id, Arg2);
8531
8532             --  If the entity is a deferred constant, propagate the information
8533             --  to the full view, because gigi elaborates the full view only.
8534
8535             if Ekind (Def_Id) = E_Constant
8536               and then Present (Full_View (Def_Id))
8537             then
8538                declare
8539                   Id2 : constant Entity_Id := Full_View (Def_Id);
8540                begin
8541                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8542                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8543                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8544                end;
8545             end if;
8546          end Export;
8547
8548          ----------------------
8549          -- Export_Exception --
8550          ----------------------
8551
8552          --  pragma Export_Exception (
8553          --        [Internal         =>] LOCAL_NAME
8554          --     [, [External         =>] EXTERNAL_SYMBOL]
8555          --     [, [Form     =>] Ada | VMS]
8556          --     [, [Code     =>] static_integer_EXPRESSION]);
8557
8558          when Pragma_Export_Exception => Export_Exception : declare
8559             Args  : Args_List (1 .. 4);
8560             Names : constant Name_List (1 .. 4) := (
8561                       Name_Internal,
8562                       Name_External,
8563                       Name_Form,
8564                       Name_Code);
8565
8566             Internal : Node_Id renames Args (1);
8567             External : Node_Id renames Args (2);
8568             Form     : Node_Id renames Args (3);
8569             Code     : Node_Id renames Args (4);
8570
8571          begin
8572             GNAT_Pragma;
8573
8574             if Inside_A_Generic then
8575                Error_Pragma ("pragma% cannot be used for generic entities");
8576             end if;
8577
8578             Gather_Associations (Names, Args);
8579             Process_Extended_Import_Export_Exception_Pragma (
8580               Arg_Internal => Internal,
8581               Arg_External => External,
8582               Arg_Form     => Form,
8583               Arg_Code     => Code);
8584
8585             if not Is_VMS_Exception (Entity (Internal)) then
8586                Set_Exported (Entity (Internal), Internal);
8587             end if;
8588          end Export_Exception;
8589
8590          ---------------------
8591          -- Export_Function --
8592          ---------------------
8593
8594          --  pragma Export_Function (
8595          --        [Internal         =>] LOCAL_NAME
8596          --     [, [External         =>] EXTERNAL_SYMBOL]
8597          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8598          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8599          --     [, [Mechanism        =>] MECHANISM]
8600          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8601
8602          --  EXTERNAL_SYMBOL ::=
8603          --    IDENTIFIER
8604          --  | static_string_EXPRESSION
8605
8606          --  PARAMETER_TYPES ::=
8607          --    null
8608          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8609
8610          --  TYPE_DESIGNATOR ::=
8611          --    subtype_NAME
8612          --  | subtype_Name ' Access
8613
8614          --  MECHANISM ::=
8615          --    MECHANISM_NAME
8616          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8617
8618          --  MECHANISM_ASSOCIATION ::=
8619          --    [formal_parameter_NAME =>] MECHANISM_NAME
8620
8621          --  MECHANISM_NAME ::=
8622          --    Value
8623          --  | Reference
8624          --  | Descriptor [([Class =>] CLASS_NAME)]
8625
8626          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8627
8628          when Pragma_Export_Function => Export_Function : declare
8629             Args  : Args_List (1 .. 6);
8630             Names : constant Name_List (1 .. 6) := (
8631                       Name_Internal,
8632                       Name_External,
8633                       Name_Parameter_Types,
8634                       Name_Result_Type,
8635                       Name_Mechanism,
8636                       Name_Result_Mechanism);
8637
8638             Internal         : Node_Id renames Args (1);
8639             External         : Node_Id renames Args (2);
8640             Parameter_Types  : Node_Id renames Args (3);
8641             Result_Type      : Node_Id renames Args (4);
8642             Mechanism        : Node_Id renames Args (5);
8643             Result_Mechanism : Node_Id renames Args (6);
8644
8645          begin
8646             GNAT_Pragma;
8647             Gather_Associations (Names, Args);
8648             Process_Extended_Import_Export_Subprogram_Pragma (
8649               Arg_Internal         => Internal,
8650               Arg_External         => External,
8651               Arg_Parameter_Types  => Parameter_Types,
8652               Arg_Result_Type      => Result_Type,
8653               Arg_Mechanism        => Mechanism,
8654               Arg_Result_Mechanism => Result_Mechanism);
8655          end Export_Function;
8656
8657          -------------------
8658          -- Export_Object --
8659          -------------------
8660
8661          --  pragma Export_Object (
8662          --        [Internal =>] LOCAL_NAME
8663          --     [, [External =>] EXTERNAL_SYMBOL]
8664          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8665
8666          --  EXTERNAL_SYMBOL ::=
8667          --    IDENTIFIER
8668          --  | static_string_EXPRESSION
8669
8670          --  PARAMETER_TYPES ::=
8671          --    null
8672          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8673
8674          --  TYPE_DESIGNATOR ::=
8675          --    subtype_NAME
8676          --  | subtype_Name ' Access
8677
8678          --  MECHANISM ::=
8679          --    MECHANISM_NAME
8680          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8681
8682          --  MECHANISM_ASSOCIATION ::=
8683          --    [formal_parameter_NAME =>] MECHANISM_NAME
8684
8685          --  MECHANISM_NAME ::=
8686          --    Value
8687          --  | Reference
8688          --  | Descriptor [([Class =>] CLASS_NAME)]
8689
8690          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8691
8692          when Pragma_Export_Object => Export_Object : declare
8693             Args  : Args_List (1 .. 3);
8694             Names : constant Name_List (1 .. 3) := (
8695                       Name_Internal,
8696                       Name_External,
8697                       Name_Size);
8698
8699             Internal : Node_Id renames Args (1);
8700             External : Node_Id renames Args (2);
8701             Size     : Node_Id renames Args (3);
8702
8703          begin
8704             GNAT_Pragma;
8705             Gather_Associations (Names, Args);
8706             Process_Extended_Import_Export_Object_Pragma (
8707               Arg_Internal => Internal,
8708               Arg_External => External,
8709               Arg_Size     => Size);
8710          end Export_Object;
8711
8712          ----------------------
8713          -- Export_Procedure --
8714          ----------------------
8715
8716          --  pragma Export_Procedure (
8717          --        [Internal         =>] LOCAL_NAME
8718          --     [, [External         =>] EXTERNAL_SYMBOL]
8719          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8720          --     [, [Mechanism        =>] MECHANISM]);
8721
8722          --  EXTERNAL_SYMBOL ::=
8723          --    IDENTIFIER
8724          --  | static_string_EXPRESSION
8725
8726          --  PARAMETER_TYPES ::=
8727          --    null
8728          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8729
8730          --  TYPE_DESIGNATOR ::=
8731          --    subtype_NAME
8732          --  | subtype_Name ' Access
8733
8734          --  MECHANISM ::=
8735          --    MECHANISM_NAME
8736          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8737
8738          --  MECHANISM_ASSOCIATION ::=
8739          --    [formal_parameter_NAME =>] MECHANISM_NAME
8740
8741          --  MECHANISM_NAME ::=
8742          --    Value
8743          --  | Reference
8744          --  | Descriptor [([Class =>] CLASS_NAME)]
8745
8746          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8747
8748          when Pragma_Export_Procedure => Export_Procedure : declare
8749             Args  : Args_List (1 .. 4);
8750             Names : constant Name_List (1 .. 4) := (
8751                       Name_Internal,
8752                       Name_External,
8753                       Name_Parameter_Types,
8754                       Name_Mechanism);
8755
8756             Internal        : Node_Id renames Args (1);
8757             External        : Node_Id renames Args (2);
8758             Parameter_Types : Node_Id renames Args (3);
8759             Mechanism       : Node_Id renames Args (4);
8760
8761          begin
8762             GNAT_Pragma;
8763             Gather_Associations (Names, Args);
8764             Process_Extended_Import_Export_Subprogram_Pragma (
8765               Arg_Internal        => Internal,
8766               Arg_External        => External,
8767               Arg_Parameter_Types => Parameter_Types,
8768               Arg_Mechanism       => Mechanism);
8769          end Export_Procedure;
8770
8771          ------------------
8772          -- Export_Value --
8773          ------------------
8774
8775          --  pragma Export_Value (
8776          --     [Value     =>] static_integer_EXPRESSION,
8777          --     [Link_Name =>] static_string_EXPRESSION);
8778
8779          when Pragma_Export_Value =>
8780             GNAT_Pragma;
8781             Check_Arg_Order ((Name_Value, Name_Link_Name));
8782             Check_Arg_Count (2);
8783
8784             Check_Optional_Identifier (Arg1, Name_Value);
8785             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8786
8787             Check_Optional_Identifier (Arg2, Name_Link_Name);
8788             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8789
8790          -----------------------------
8791          -- Export_Valued_Procedure --
8792          -----------------------------
8793
8794          --  pragma Export_Valued_Procedure (
8795          --        [Internal         =>] LOCAL_NAME
8796          --     [, [External         =>] EXTERNAL_SYMBOL,]
8797          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8798          --     [, [Mechanism        =>] MECHANISM]);
8799
8800          --  EXTERNAL_SYMBOL ::=
8801          --    IDENTIFIER
8802          --  | static_string_EXPRESSION
8803
8804          --  PARAMETER_TYPES ::=
8805          --    null
8806          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8807
8808          --  TYPE_DESIGNATOR ::=
8809          --    subtype_NAME
8810          --  | subtype_Name ' Access
8811
8812          --  MECHANISM ::=
8813          --    MECHANISM_NAME
8814          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8815
8816          --  MECHANISM_ASSOCIATION ::=
8817          --    [formal_parameter_NAME =>] MECHANISM_NAME
8818
8819          --  MECHANISM_NAME ::=
8820          --    Value
8821          --  | Reference
8822          --  | Descriptor [([Class =>] CLASS_NAME)]
8823
8824          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8825
8826          when Pragma_Export_Valued_Procedure =>
8827          Export_Valued_Procedure : declare
8828             Args  : Args_List (1 .. 4);
8829             Names : constant Name_List (1 .. 4) := (
8830                       Name_Internal,
8831                       Name_External,
8832                       Name_Parameter_Types,
8833                       Name_Mechanism);
8834
8835             Internal        : Node_Id renames Args (1);
8836             External        : Node_Id renames Args (2);
8837             Parameter_Types : Node_Id renames Args (3);
8838             Mechanism       : Node_Id renames Args (4);
8839
8840          begin
8841             GNAT_Pragma;
8842             Gather_Associations (Names, Args);
8843             Process_Extended_Import_Export_Subprogram_Pragma (
8844               Arg_Internal        => Internal,
8845               Arg_External        => External,
8846               Arg_Parameter_Types => Parameter_Types,
8847               Arg_Mechanism       => Mechanism);
8848          end Export_Valued_Procedure;
8849
8850          -------------------
8851          -- Extend_System --
8852          -------------------
8853
8854          --  pragma Extend_System ([Name =>] Identifier);
8855
8856          when Pragma_Extend_System => Extend_System : declare
8857          begin
8858             GNAT_Pragma;
8859             Check_Valid_Configuration_Pragma;
8860             Check_Arg_Count (1);
8861             Check_Optional_Identifier (Arg1, Name_Name);
8862             Check_Arg_Is_Identifier (Arg1);
8863
8864             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8865
8866             if Name_Len > 4
8867               and then Name_Buffer (1 .. 4) = "aux_"
8868             then
8869                if Present (System_Extend_Pragma_Arg) then
8870                   if Chars (Get_Pragma_Arg (Arg1)) =
8871                      Chars (Expression (System_Extend_Pragma_Arg))
8872                   then
8873                      null;
8874                   else
8875                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8876                      Error_Pragma ("pragma% conflicts with that #");
8877                   end if;
8878
8879                else
8880                   System_Extend_Pragma_Arg := Arg1;
8881
8882                   if not GNAT_Mode then
8883                      System_Extend_Unit := Arg1;
8884                   end if;
8885                end if;
8886             else
8887                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8888             end if;
8889          end Extend_System;
8890
8891          ------------------------
8892          -- Extensions_Allowed --
8893          ------------------------
8894
8895          --  pragma Extensions_Allowed (ON | OFF);
8896
8897          when Pragma_Extensions_Allowed =>
8898             GNAT_Pragma;
8899             Check_Arg_Count (1);
8900             Check_No_Identifiers;
8901             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8902
8903             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8904                Extensions_Allowed := True;
8905                Ada_Version := Ada_Version_Type'Last;
8906
8907             else
8908                Extensions_Allowed := False;
8909                Ada_Version := Ada_Version_Explicit;
8910             end if;
8911
8912          --------------
8913          -- External --
8914          --------------
8915
8916          --  pragma External (
8917          --    [   Convention    =>] convention_IDENTIFIER,
8918          --    [   Entity        =>] local_NAME
8919          --    [, [External_Name =>] static_string_EXPRESSION ]
8920          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8921
8922          when Pragma_External => External : declare
8923                Def_Id : Entity_Id;
8924
8925                C : Convention_Id;
8926                pragma Warnings (Off, C);
8927
8928          begin
8929             GNAT_Pragma;
8930             Check_Arg_Order
8931               ((Name_Convention,
8932                 Name_Entity,
8933                 Name_External_Name,
8934                 Name_Link_Name));
8935             Check_At_Least_N_Arguments (2);
8936             Check_At_Most_N_Arguments  (4);
8937             Process_Convention (C, Def_Id);
8938             Note_Possible_Modification
8939               (Get_Pragma_Arg (Arg2), Sure => False);
8940             Process_Interface_Name (Def_Id, Arg3, Arg4);
8941             Set_Exported (Def_Id, Arg2);
8942          end External;
8943
8944          --------------------------
8945          -- External_Name_Casing --
8946          --------------------------
8947
8948          --  pragma External_Name_Casing (
8949          --    UPPERCASE | LOWERCASE
8950          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8951
8952          when Pragma_External_Name_Casing => External_Name_Casing : declare
8953          begin
8954             GNAT_Pragma;
8955             Check_No_Identifiers;
8956
8957             if Arg_Count = 2 then
8958                Check_Arg_Is_One_Of
8959                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8960
8961                case Chars (Get_Pragma_Arg (Arg2)) is
8962                   when Name_As_Is     =>
8963                      Opt.External_Name_Exp_Casing := As_Is;
8964
8965                   when Name_Uppercase =>
8966                      Opt.External_Name_Exp_Casing := Uppercase;
8967
8968                   when Name_Lowercase =>
8969                      Opt.External_Name_Exp_Casing := Lowercase;
8970
8971                   when others =>
8972                      null;
8973                end case;
8974
8975             else
8976                Check_Arg_Count (1);
8977             end if;
8978
8979             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8980
8981             case Chars (Get_Pragma_Arg (Arg1)) is
8982                when Name_Uppercase =>
8983                   Opt.External_Name_Imp_Casing := Uppercase;
8984
8985                when Name_Lowercase =>
8986                   Opt.External_Name_Imp_Casing := Lowercase;
8987
8988                when others =>
8989                   null;
8990             end case;
8991          end External_Name_Casing;
8992
8993          --------------------------
8994          -- Favor_Top_Level --
8995          --------------------------
8996
8997          --  pragma Favor_Top_Level (type_NAME);
8998
8999          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
9000                Named_Entity : Entity_Id;
9001
9002          begin
9003             GNAT_Pragma;
9004             Check_No_Identifiers;
9005             Check_Arg_Count (1);
9006             Check_Arg_Is_Local_Name (Arg1);
9007             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
9008
9009             --  If it's an access-to-subprogram type (in particular, not a
9010             --  subtype), set the flag on that type.
9011
9012             if Is_Access_Subprogram_Type (Named_Entity) then
9013                Set_Can_Use_Internal_Rep (Named_Entity, False);
9014
9015             --  Otherwise it's an error (name denotes the wrong sort of entity)
9016
9017             else
9018                Error_Pragma_Arg
9019                  ("access-to-subprogram type expected",
9020                   Get_Pragma_Arg (Arg1));
9021             end if;
9022          end Favor_Top_Level;
9023
9024          ---------------
9025          -- Fast_Math --
9026          ---------------
9027
9028          --  pragma Fast_Math;
9029
9030          when Pragma_Fast_Math =>
9031             GNAT_Pragma;
9032             Check_No_Identifiers;
9033             Check_Valid_Configuration_Pragma;
9034             Fast_Math := True;
9035
9036          ---------------------------
9037          -- Finalize_Storage_Only --
9038          ---------------------------
9039
9040          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9041
9042          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9043             Assoc   : constant Node_Id := Arg1;
9044             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9045             Typ     : Entity_Id;
9046
9047          begin
9048             GNAT_Pragma;
9049             Check_No_Identifiers;
9050             Check_Arg_Count (1);
9051             Check_Arg_Is_Local_Name (Arg1);
9052
9053             Find_Type (Type_Id);
9054             Typ := Entity (Type_Id);
9055
9056             if Typ = Any_Type
9057               or else Rep_Item_Too_Early (Typ, N)
9058             then
9059                return;
9060             else
9061                Typ := Underlying_Type (Typ);
9062             end if;
9063
9064             if not Is_Controlled (Typ) then
9065                Error_Pragma ("pragma% must specify controlled type");
9066             end if;
9067
9068             Check_First_Subtype (Arg1);
9069
9070             if Finalize_Storage_Only (Typ) then
9071                Error_Pragma ("duplicate pragma%, only one allowed");
9072
9073             elsif not Rep_Item_Too_Late (Typ, N) then
9074                Set_Finalize_Storage_Only (Base_Type (Typ), True);
9075             end if;
9076          end Finalize_Storage;
9077
9078          --------------------------
9079          -- Float_Representation --
9080          --------------------------
9081
9082          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9083
9084          --  FLOAT_REP ::= VAX_Float | IEEE_Float
9085
9086          when Pragma_Float_Representation => Float_Representation : declare
9087             Argx : Node_Id;
9088             Digs : Nat;
9089             Ent  : Entity_Id;
9090
9091          begin
9092             GNAT_Pragma;
9093
9094             if Arg_Count = 1 then
9095                Check_Valid_Configuration_Pragma;
9096             else
9097                Check_Arg_Count (2);
9098                Check_Optional_Identifier (Arg2, Name_Entity);
9099                Check_Arg_Is_Local_Name (Arg2);
9100             end if;
9101
9102             Check_No_Identifier (Arg1);
9103             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9104
9105             if not OpenVMS_On_Target then
9106                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9107                   Error_Pragma
9108                     ("?pragma% ignored (applies only to Open'V'M'S)");
9109                end if;
9110
9111                return;
9112             end if;
9113
9114             --  One argument case
9115
9116             if Arg_Count = 1 then
9117                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9118                   if Opt.Float_Format = 'I' then
9119                      Error_Pragma ("'I'E'E'E format previously specified");
9120                   end if;
9121
9122                   Opt.Float_Format := 'V';
9123
9124                else
9125                   if Opt.Float_Format = 'V' then
9126                      Error_Pragma ("'V'A'X format previously specified");
9127                   end if;
9128
9129                   Opt.Float_Format := 'I';
9130                end if;
9131
9132                Set_Standard_Fpt_Formats;
9133
9134             --  Two argument case
9135
9136             else
9137                Argx := Get_Pragma_Arg (Arg2);
9138
9139                if not Is_Entity_Name (Argx)
9140                  or else not Is_Floating_Point_Type (Entity (Argx))
9141                then
9142                   Error_Pragma_Arg
9143                     ("second argument of% pragma must be floating-point type",
9144                      Arg2);
9145                end if;
9146
9147                Ent  := Entity (Argx);
9148                Digs := UI_To_Int (Digits_Value (Ent));
9149
9150                --  Two arguments, VAX_Float case
9151
9152                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9153                   case Digs is
9154                      when  6 => Set_F_Float (Ent);
9155                      when  9 => Set_D_Float (Ent);
9156                      when 15 => Set_G_Float (Ent);
9157
9158                      when others =>
9159                         Error_Pragma_Arg
9160                           ("wrong digits value, must be 6,9 or 15", Arg2);
9161                   end case;
9162
9163                --  Two arguments, IEEE_Float case
9164
9165                else
9166                   case Digs is
9167                      when  6 => Set_IEEE_Short (Ent);
9168                      when 15 => Set_IEEE_Long  (Ent);
9169
9170                      when others =>
9171                         Error_Pragma_Arg
9172                           ("wrong digits value, must be 6 or 15", Arg2);
9173                   end case;
9174                end if;
9175             end if;
9176          end Float_Representation;
9177
9178          -----------
9179          -- Ident --
9180          -----------
9181
9182          --  pragma Ident (static_string_EXPRESSION)
9183
9184          --  Note: pragma Comment shares this processing. Pragma Comment is
9185          --  identical to Ident, except that the restriction of the argument to
9186          --  31 characters and the placement restrictions are not enforced for
9187          --  pragma Comment.
9188
9189          when Pragma_Ident | Pragma_Comment => Ident : declare
9190             Str : Node_Id;
9191
9192          begin
9193             GNAT_Pragma;
9194             Check_Arg_Count (1);
9195             Check_No_Identifiers;
9196             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9197             Store_Note (N);
9198
9199             --  For pragma Ident, preserve DEC compatibility by requiring the
9200             --  pragma to appear in a declarative part or package spec.
9201
9202             if Prag_Id = Pragma_Ident then
9203                Check_Is_In_Decl_Part_Or_Package_Spec;
9204             end if;
9205
9206             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9207
9208             declare
9209                CS : Node_Id;
9210                GP : Node_Id;
9211
9212             begin
9213                GP := Parent (Parent (N));
9214
9215                if Nkind_In (GP, N_Package_Declaration,
9216                                 N_Generic_Package_Declaration)
9217                then
9218                   GP := Parent (GP);
9219                end if;
9220
9221                --  If we have a compilation unit, then record the ident value,
9222                --  checking for improper duplication.
9223
9224                if Nkind (GP) = N_Compilation_Unit then
9225                   CS := Ident_String (Current_Sem_Unit);
9226
9227                   if Present (CS) then
9228
9229                      --  For Ident, we do not permit multiple instances
9230
9231                      if Prag_Id = Pragma_Ident then
9232                         Error_Pragma ("duplicate% pragma not permitted");
9233
9234                      --  For Comment, we concatenate the string, unless we want
9235                      --  to preserve the tree structure for ASIS.
9236
9237                      elsif not ASIS_Mode then
9238                         Start_String (Strval (CS));
9239                         Store_String_Char (' ');
9240                         Store_String_Chars (Strval (Str));
9241                         Set_Strval (CS, End_String);
9242                      end if;
9243
9244                   else
9245                      --  In VMS, the effect of IDENT is achieved by passing
9246                      --  --identification=name as a --for-linker switch.
9247
9248                      if OpenVMS_On_Target then
9249                         Start_String;
9250                         Store_String_Chars
9251                           ("--for-linker=--identification=");
9252                         String_To_Name_Buffer (Strval (Str));
9253                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
9254
9255                         --  Only the last processed IDENT is saved. The main
9256                         --  purpose is so an IDENT associated with a main
9257                         --  procedure will be used in preference to an IDENT
9258                         --  associated with a with'd package.
9259
9260                         Replace_Linker_Option_String
9261                           (End_String, "--for-linker=--identification=");
9262                      end if;
9263
9264                      Set_Ident_String (Current_Sem_Unit, Str);
9265                   end if;
9266
9267                --  For subunits, we just ignore the Ident, since in GNAT these
9268                --  are not separate object files, and hence not separate units
9269                --  in the unit table.
9270
9271                elsif Nkind (GP) = N_Subunit then
9272                   null;
9273
9274                --  Otherwise we have a misplaced pragma Ident, but we ignore
9275                --  this if we are in an instantiation, since it comes from
9276                --  a generic, and has no relevance to the instantiation.
9277
9278                elsif Prag_Id = Pragma_Ident then
9279                   if Instantiation_Location (Loc) = No_Location then
9280                      Error_Pragma ("pragma% only allowed at outer level");
9281                   end if;
9282                end if;
9283             end;
9284          end Ident;
9285
9286          ----------------------------
9287          -- Implementation_Defined --
9288          ----------------------------
9289
9290          --  pragma Implementation_Defined (local_NAME);
9291
9292          --  Marks previously declared entity as implementation defined. For
9293          --  an overloaded entity, applies to the most recent homonym.
9294
9295          --  pragma Implementation_Defined;
9296
9297          --  The form with no arguments appears anywhere within a scope, most
9298          --  typically a package spec, and indicates that all entities that are
9299          --  defined within the package spec are Implementation_Defined.
9300
9301          when Pragma_Implementation_Defined => Implementation_Defined : declare
9302             Ent : Entity_Id;
9303
9304          begin
9305             Check_No_Identifiers;
9306
9307             --  Form with no arguments
9308
9309             if Arg_Count = 0 then
9310                Set_Is_Implementation_Defined (Current_Scope);
9311
9312             --  Form with one argument
9313
9314             else
9315                Check_Arg_Count (1);
9316                Check_Arg_Is_Local_Name (Arg1);
9317                Ent := Entity (Get_Pragma_Arg (Arg1));
9318                Set_Is_Implementation_Defined (Ent);
9319             end if;
9320          end Implementation_Defined;
9321
9322          -----------------
9323          -- Implemented --
9324          -----------------
9325
9326          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9327          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9328
9329          when Pragma_Implemented => Implemented : declare
9330             Proc_Id : Entity_Id;
9331             Typ     : Entity_Id;
9332
9333          begin
9334             Ada_2012_Pragma;
9335             Check_Arg_Count (2);
9336             Check_No_Identifiers;
9337             Check_Arg_Is_Identifier (Arg1);
9338             Check_Arg_Is_Local_Name (Arg1);
9339             Check_Arg_Is_One_Of
9340               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9341
9342             --  Extract the name of the local procedure
9343
9344             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9345
9346             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9347             --  primitive procedure of a synchronized tagged type.
9348
9349             if Ekind (Proc_Id) = E_Procedure
9350               and then Is_Primitive (Proc_Id)
9351               and then Present (First_Formal (Proc_Id))
9352             then
9353                Typ := Etype (First_Formal (Proc_Id));
9354
9355                if Is_Tagged_Type (Typ)
9356                  and then
9357
9358                   --  Check for a protected, a synchronized or a task interface
9359
9360                    ((Is_Interface (Typ)
9361                        and then Is_Synchronized_Interface (Typ))
9362
9363                   --  Check for a protected type or a task type that implements
9364                   --  an interface.
9365
9366                    or else
9367                     (Is_Concurrent_Record_Type (Typ)
9368                        and then Present (Interfaces (Typ)))
9369
9370                   --  Check for a private record extension with keyword
9371                   --  "synchronized".
9372
9373                    or else
9374                     (Ekind_In (Typ, E_Record_Type_With_Private,
9375                                     E_Record_Subtype_With_Private)
9376                        and then Synchronized_Present (Parent (Typ))))
9377                then
9378                   null;
9379                else
9380                   Error_Pragma_Arg
9381                     ("controlling formal must be of synchronized " &
9382                      "tagged type", Arg1);
9383                   return;
9384                end if;
9385
9386             --  Procedures declared inside a protected type must be accepted
9387
9388             elsif Ekind (Proc_Id) = E_Procedure
9389               and then Is_Protected_Type (Scope (Proc_Id))
9390             then
9391                null;
9392
9393             --  The first argument is not a primitive procedure
9394
9395             else
9396                Error_Pragma_Arg
9397                  ("pragma % must be applied to a primitive procedure", Arg1);
9398                return;
9399             end if;
9400
9401             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9402             --  By_Protected_Procedure to the primitive procedure of a task
9403             --  interface.
9404
9405             if Chars (Arg2) = Name_By_Protected_Procedure
9406               and then Is_Interface (Typ)
9407               and then Is_Task_Interface (Typ)
9408             then
9409                Error_Pragma_Arg
9410                  ("implementation kind By_Protected_Procedure cannot be " &
9411                   "applied to a task interface primitive", Arg2);
9412                return;
9413             end if;
9414
9415             Record_Rep_Item (Proc_Id, N);
9416          end Implemented;
9417
9418          ----------------------
9419          -- Implicit_Packing --
9420          ----------------------
9421
9422          --  pragma Implicit_Packing;
9423
9424          when Pragma_Implicit_Packing =>
9425             GNAT_Pragma;
9426             Check_Arg_Count (0);
9427             Implicit_Packing := True;
9428
9429          ------------
9430          -- Import --
9431          ------------
9432
9433          --  pragma Import (
9434          --       [Convention    =>] convention_IDENTIFIER,
9435          --       [Entity        =>] local_NAME
9436          --    [, [External_Name =>] static_string_EXPRESSION ]
9437          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9438
9439          when Pragma_Import =>
9440             Check_Ada_83_Warning;
9441             Check_Arg_Order
9442               ((Name_Convention,
9443                 Name_Entity,
9444                 Name_External_Name,
9445                 Name_Link_Name));
9446             Check_At_Least_N_Arguments (2);
9447             Check_At_Most_N_Arguments  (4);
9448             Process_Import_Or_Interface;
9449
9450          ----------------------
9451          -- Import_Exception --
9452          ----------------------
9453
9454          --  pragma Import_Exception (
9455          --        [Internal         =>] LOCAL_NAME
9456          --     [, [External         =>] EXTERNAL_SYMBOL]
9457          --     [, [Form     =>] Ada | VMS]
9458          --     [, [Code     =>] static_integer_EXPRESSION]);
9459
9460          when Pragma_Import_Exception => Import_Exception : declare
9461             Args  : Args_List (1 .. 4);
9462             Names : constant Name_List (1 .. 4) := (
9463                       Name_Internal,
9464                       Name_External,
9465                       Name_Form,
9466                       Name_Code);
9467
9468             Internal : Node_Id renames Args (1);
9469             External : Node_Id renames Args (2);
9470             Form     : Node_Id renames Args (3);
9471             Code     : Node_Id renames Args (4);
9472
9473          begin
9474             GNAT_Pragma;
9475             Gather_Associations (Names, Args);
9476
9477             if Present (External) and then Present (Code) then
9478                Error_Pragma
9479                  ("cannot give both External and Code options for pragma%");
9480             end if;
9481
9482             Process_Extended_Import_Export_Exception_Pragma (
9483               Arg_Internal => Internal,
9484               Arg_External => External,
9485               Arg_Form     => Form,
9486               Arg_Code     => Code);
9487
9488             if not Is_VMS_Exception (Entity (Internal)) then
9489                Set_Imported (Entity (Internal));
9490             end if;
9491          end Import_Exception;
9492
9493          ---------------------
9494          -- Import_Function --
9495          ---------------------
9496
9497          --  pragma Import_Function (
9498          --        [Internal                 =>] LOCAL_NAME,
9499          --     [, [External                 =>] EXTERNAL_SYMBOL]
9500          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9501          --     [, [Result_Type              =>] SUBTYPE_MARK]
9502          --     [, [Mechanism                =>] MECHANISM]
9503          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9504          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9505
9506          --  EXTERNAL_SYMBOL ::=
9507          --    IDENTIFIER
9508          --  | static_string_EXPRESSION
9509
9510          --  PARAMETER_TYPES ::=
9511          --    null
9512          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9513
9514          --  TYPE_DESIGNATOR ::=
9515          --    subtype_NAME
9516          --  | subtype_Name ' Access
9517
9518          --  MECHANISM ::=
9519          --    MECHANISM_NAME
9520          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9521
9522          --  MECHANISM_ASSOCIATION ::=
9523          --    [formal_parameter_NAME =>] MECHANISM_NAME
9524
9525          --  MECHANISM_NAME ::=
9526          --    Value
9527          --  | Reference
9528          --  | Descriptor [([Class =>] CLASS_NAME)]
9529
9530          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9531
9532          when Pragma_Import_Function => Import_Function : declare
9533             Args  : Args_List (1 .. 7);
9534             Names : constant Name_List (1 .. 7) := (
9535                       Name_Internal,
9536                       Name_External,
9537                       Name_Parameter_Types,
9538                       Name_Result_Type,
9539                       Name_Mechanism,
9540                       Name_Result_Mechanism,
9541                       Name_First_Optional_Parameter);
9542
9543             Internal                 : Node_Id renames Args (1);
9544             External                 : Node_Id renames Args (2);
9545             Parameter_Types          : Node_Id renames Args (3);
9546             Result_Type              : Node_Id renames Args (4);
9547             Mechanism                : Node_Id renames Args (5);
9548             Result_Mechanism         : Node_Id renames Args (6);
9549             First_Optional_Parameter : Node_Id renames Args (7);
9550
9551          begin
9552             GNAT_Pragma;
9553             Gather_Associations (Names, Args);
9554             Process_Extended_Import_Export_Subprogram_Pragma (
9555               Arg_Internal                 => Internal,
9556               Arg_External                 => External,
9557               Arg_Parameter_Types          => Parameter_Types,
9558               Arg_Result_Type              => Result_Type,
9559               Arg_Mechanism                => Mechanism,
9560               Arg_Result_Mechanism         => Result_Mechanism,
9561               Arg_First_Optional_Parameter => First_Optional_Parameter);
9562          end Import_Function;
9563
9564          -------------------
9565          -- Import_Object --
9566          -------------------
9567
9568          --  pragma Import_Object (
9569          --        [Internal =>] LOCAL_NAME
9570          --     [, [External =>] EXTERNAL_SYMBOL]
9571          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9572
9573          --  EXTERNAL_SYMBOL ::=
9574          --    IDENTIFIER
9575          --  | static_string_EXPRESSION
9576
9577          when Pragma_Import_Object => Import_Object : declare
9578             Args  : Args_List (1 .. 3);
9579             Names : constant Name_List (1 .. 3) := (
9580                       Name_Internal,
9581                       Name_External,
9582                       Name_Size);
9583
9584             Internal : Node_Id renames Args (1);
9585             External : Node_Id renames Args (2);
9586             Size     : Node_Id renames Args (3);
9587
9588          begin
9589             GNAT_Pragma;
9590             Gather_Associations (Names, Args);
9591             Process_Extended_Import_Export_Object_Pragma (
9592               Arg_Internal => Internal,
9593               Arg_External => External,
9594               Arg_Size     => Size);
9595          end Import_Object;
9596
9597          ----------------------
9598          -- Import_Procedure --
9599          ----------------------
9600
9601          --  pragma Import_Procedure (
9602          --        [Internal                 =>] LOCAL_NAME
9603          --     [, [External                 =>] EXTERNAL_SYMBOL]
9604          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9605          --     [, [Mechanism                =>] MECHANISM]
9606          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9607
9608          --  EXTERNAL_SYMBOL ::=
9609          --    IDENTIFIER
9610          --  | static_string_EXPRESSION
9611
9612          --  PARAMETER_TYPES ::=
9613          --    null
9614          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9615
9616          --  TYPE_DESIGNATOR ::=
9617          --    subtype_NAME
9618          --  | subtype_Name ' Access
9619
9620          --  MECHANISM ::=
9621          --    MECHANISM_NAME
9622          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9623
9624          --  MECHANISM_ASSOCIATION ::=
9625          --    [formal_parameter_NAME =>] MECHANISM_NAME
9626
9627          --  MECHANISM_NAME ::=
9628          --    Value
9629          --  | Reference
9630          --  | Descriptor [([Class =>] CLASS_NAME)]
9631
9632          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9633
9634          when Pragma_Import_Procedure => Import_Procedure : declare
9635             Args  : Args_List (1 .. 5);
9636             Names : constant Name_List (1 .. 5) := (
9637                       Name_Internal,
9638                       Name_External,
9639                       Name_Parameter_Types,
9640                       Name_Mechanism,
9641                       Name_First_Optional_Parameter);
9642
9643             Internal                 : Node_Id renames Args (1);
9644             External                 : Node_Id renames Args (2);
9645             Parameter_Types          : Node_Id renames Args (3);
9646             Mechanism                : Node_Id renames Args (4);
9647             First_Optional_Parameter : Node_Id renames Args (5);
9648
9649          begin
9650             GNAT_Pragma;
9651             Gather_Associations (Names, Args);
9652             Process_Extended_Import_Export_Subprogram_Pragma (
9653               Arg_Internal                 => Internal,
9654               Arg_External                 => External,
9655               Arg_Parameter_Types          => Parameter_Types,
9656               Arg_Mechanism                => Mechanism,
9657               Arg_First_Optional_Parameter => First_Optional_Parameter);
9658          end Import_Procedure;
9659
9660          -----------------------------
9661          -- Import_Valued_Procedure --
9662          -----------------------------
9663
9664          --  pragma Import_Valued_Procedure (
9665          --        [Internal                 =>] LOCAL_NAME
9666          --     [, [External                 =>] EXTERNAL_SYMBOL]
9667          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9668          --     [, [Mechanism                =>] MECHANISM]
9669          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9670
9671          --  EXTERNAL_SYMBOL ::=
9672          --    IDENTIFIER
9673          --  | static_string_EXPRESSION
9674
9675          --  PARAMETER_TYPES ::=
9676          --    null
9677          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9678
9679          --  TYPE_DESIGNATOR ::=
9680          --    subtype_NAME
9681          --  | subtype_Name ' Access
9682
9683          --  MECHANISM ::=
9684          --    MECHANISM_NAME
9685          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9686
9687          --  MECHANISM_ASSOCIATION ::=
9688          --    [formal_parameter_NAME =>] MECHANISM_NAME
9689
9690          --  MECHANISM_NAME ::=
9691          --    Value
9692          --  | Reference
9693          --  | Descriptor [([Class =>] CLASS_NAME)]
9694
9695          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9696
9697          when Pragma_Import_Valued_Procedure =>
9698          Import_Valued_Procedure : declare
9699             Args  : Args_List (1 .. 5);
9700             Names : constant Name_List (1 .. 5) := (
9701                       Name_Internal,
9702                       Name_External,
9703                       Name_Parameter_Types,
9704                       Name_Mechanism,
9705                       Name_First_Optional_Parameter);
9706
9707             Internal                 : Node_Id renames Args (1);
9708             External                 : Node_Id renames Args (2);
9709             Parameter_Types          : Node_Id renames Args (3);
9710             Mechanism                : Node_Id renames Args (4);
9711             First_Optional_Parameter : Node_Id renames Args (5);
9712
9713          begin
9714             GNAT_Pragma;
9715             Gather_Associations (Names, Args);
9716             Process_Extended_Import_Export_Subprogram_Pragma (
9717               Arg_Internal                 => Internal,
9718               Arg_External                 => External,
9719               Arg_Parameter_Types          => Parameter_Types,
9720               Arg_Mechanism                => Mechanism,
9721               Arg_First_Optional_Parameter => First_Optional_Parameter);
9722          end Import_Valued_Procedure;
9723
9724          -----------------
9725          -- Independent --
9726          -----------------
9727
9728          --  pragma Independent (LOCAL_NAME);
9729
9730          when Pragma_Independent => Independent : declare
9731             E_Id : Node_Id;
9732             E    : Entity_Id;
9733             D    : Node_Id;
9734             K    : Node_Kind;
9735
9736          begin
9737             Check_Ada_83_Warning;
9738             Ada_2012_Pragma;
9739             Check_No_Identifiers;
9740             Check_Arg_Count (1);
9741             Check_Arg_Is_Local_Name (Arg1);
9742             E_Id := Get_Pragma_Arg (Arg1);
9743
9744             if Etype (E_Id) = Any_Type then
9745                return;
9746             end if;
9747
9748             E := Entity (E_Id);
9749             D := Declaration_Node (E);
9750             K := Nkind (D);
9751
9752             --  Check duplicate before we chain ourselves!
9753
9754             Check_Duplicate_Pragma (E);
9755
9756             --  Check appropriate entity
9757
9758             if Is_Type (E) then
9759                if Rep_Item_Too_Early (E, N)
9760                     or else
9761                   Rep_Item_Too_Late (E, N)
9762                then
9763                   return;
9764                else
9765                   Check_First_Subtype (Arg1);
9766                end if;
9767
9768             elsif K = N_Object_Declaration
9769               or else (K = N_Component_Declaration
9770                        and then Original_Record_Component (E) = E)
9771             then
9772                if Rep_Item_Too_Late (E, N) then
9773                   return;
9774                end if;
9775
9776             else
9777                Error_Pragma_Arg
9778                  ("inappropriate entity for pragma%", Arg1);
9779             end if;
9780
9781             Independence_Checks.Append ((N, E));
9782          end Independent;
9783
9784          ----------------------------
9785          -- Independent_Components --
9786          ----------------------------
9787
9788          --  pragma Atomic_Components (array_LOCAL_NAME);
9789
9790          --  This processing is shared by Volatile_Components
9791
9792          when Pragma_Independent_Components => Independent_Components : declare
9793             E_Id : Node_Id;
9794             E    : Entity_Id;
9795             D    : Node_Id;
9796             K    : Node_Kind;
9797
9798          begin
9799             Check_Ada_83_Warning;
9800             Ada_2012_Pragma;
9801             Check_No_Identifiers;
9802             Check_Arg_Count (1);
9803             Check_Arg_Is_Local_Name (Arg1);
9804             E_Id := Get_Pragma_Arg (Arg1);
9805
9806             if Etype (E_Id) = Any_Type then
9807                return;
9808             end if;
9809
9810             E := Entity (E_Id);
9811
9812             --  Check duplicate before we chain ourselves!
9813
9814             Check_Duplicate_Pragma (E);
9815
9816             --  Check appropriate entity
9817
9818             if Rep_Item_Too_Early (E, N)
9819                  or else
9820                Rep_Item_Too_Late (E, N)
9821             then
9822                return;
9823             end if;
9824
9825             D := Declaration_Node (E);
9826             K := Nkind (D);
9827
9828             if (K = N_Full_Type_Declaration
9829                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9830               or else
9831                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9832                    and then Nkind (D) = N_Object_Declaration
9833                    and then Nkind (Object_Definition (D)) =
9834                                        N_Constrained_Array_Definition)
9835             then
9836                Independence_Checks.Append ((N, E));
9837
9838             else
9839                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9840             end if;
9841          end Independent_Components;
9842
9843          ------------------------
9844          -- Initialize_Scalars --
9845          ------------------------
9846
9847          --  pragma Initialize_Scalars;
9848
9849          when Pragma_Initialize_Scalars =>
9850             GNAT_Pragma;
9851             Check_Arg_Count (0);
9852             Check_Valid_Configuration_Pragma;
9853             Check_Restriction (No_Initialize_Scalars, N);
9854
9855             --  Initialize_Scalars creates false positives in CodePeer, and
9856             --  incorrect negative results in Alfa mode, so ignore this pragma
9857             --  in these modes.
9858
9859             if not Restriction_Active (No_Initialize_Scalars)
9860               and then not (CodePeer_Mode or Alfa_Mode)
9861             then
9862                Init_Or_Norm_Scalars := True;
9863                Initialize_Scalars := True;
9864             end if;
9865
9866          ------------
9867          -- Inline --
9868          ------------
9869
9870          --  pragma Inline ( NAME {, NAME} );
9871
9872          when Pragma_Inline =>
9873
9874             --  Pragma is active if inlining option is active
9875
9876             Process_Inline (Inline_Active);
9877
9878          -------------------
9879          -- Inline_Always --
9880          -------------------
9881
9882          --  pragma Inline_Always ( NAME {, NAME} );
9883
9884          when Pragma_Inline_Always =>
9885             GNAT_Pragma;
9886
9887             --  Pragma always active unless in CodePeer or Alfa mode, since
9888             --  this causes walk order issues.
9889
9890             if not (CodePeer_Mode or Alfa_Mode) then
9891                Process_Inline (True);
9892             end if;
9893
9894          --------------------
9895          -- Inline_Generic --
9896          --------------------
9897
9898          --  pragma Inline_Generic (NAME {, NAME});
9899
9900          when Pragma_Inline_Generic =>
9901             GNAT_Pragma;
9902             Process_Generic_List;
9903
9904          ----------------------
9905          -- Inspection_Point --
9906          ----------------------
9907
9908          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9909
9910          when Pragma_Inspection_Point => Inspection_Point : declare
9911             Arg : Node_Id;
9912             Exp : Node_Id;
9913
9914          begin
9915             if Arg_Count > 0 then
9916                Arg := Arg1;
9917                loop
9918                   Exp := Get_Pragma_Arg (Arg);
9919                   Analyze (Exp);
9920
9921                   if not Is_Entity_Name (Exp)
9922                     or else not Is_Object (Entity (Exp))
9923                   then
9924                      Error_Pragma_Arg ("object name required", Arg);
9925                   end if;
9926
9927                   Next (Arg);
9928                   exit when No (Arg);
9929                end loop;
9930             end if;
9931          end Inspection_Point;
9932
9933          ---------------
9934          -- Interface --
9935          ---------------
9936
9937          --  pragma Interface (
9938          --    [   Convention    =>] convention_IDENTIFIER,
9939          --    [   Entity        =>] local_NAME
9940          --    [, [External_Name =>] static_string_EXPRESSION ]
9941          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9942
9943          when Pragma_Interface =>
9944             GNAT_Pragma;
9945             Check_Arg_Order
9946               ((Name_Convention,
9947                 Name_Entity,
9948                 Name_External_Name,
9949                 Name_Link_Name));
9950             Check_At_Least_N_Arguments (2);
9951             Check_At_Most_N_Arguments  (4);
9952             Process_Import_Or_Interface;
9953
9954             --  In Ada 2005, the permission to use Interface (a reserved word)
9955             --  as a pragma name is considered an obsolescent feature.
9956
9957             if Ada_Version >= Ada_2005 then
9958                Check_Restriction
9959                  (No_Obsolescent_Features, Pragma_Identifier (N));
9960             end if;
9961
9962          --------------------
9963          -- Interface_Name --
9964          --------------------
9965
9966          --  pragma Interface_Name (
9967          --    [  Entity        =>] local_NAME
9968          --    [,[External_Name =>] static_string_EXPRESSION ]
9969          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9970
9971          when Pragma_Interface_Name => Interface_Name : declare
9972             Id     : Node_Id;
9973             Def_Id : Entity_Id;
9974             Hom_Id : Entity_Id;
9975             Found  : Boolean;
9976
9977          begin
9978             GNAT_Pragma;
9979             Check_Arg_Order
9980               ((Name_Entity, Name_External_Name, Name_Link_Name));
9981             Check_At_Least_N_Arguments (2);
9982             Check_At_Most_N_Arguments  (3);
9983             Id := Get_Pragma_Arg (Arg1);
9984             Analyze (Id);
9985
9986             if not Is_Entity_Name (Id) then
9987                Error_Pragma_Arg
9988                  ("first argument for pragma% must be entity name", Arg1);
9989             elsif Etype (Id) = Any_Type then
9990                return;
9991             else
9992                Def_Id := Entity (Id);
9993             end if;
9994
9995             --  Special DEC-compatible processing for the object case, forces
9996             --  object to be imported.
9997
9998             if Ekind (Def_Id) = E_Variable then
9999                Kill_Size_Check_Code (Def_Id);
10000                Note_Possible_Modification (Id, Sure => False);
10001
10002                --  Initialization is not allowed for imported variable
10003
10004                if Present (Expression (Parent (Def_Id)))
10005                  and then Comes_From_Source (Expression (Parent (Def_Id)))
10006                then
10007                   Error_Msg_Sloc := Sloc (Def_Id);
10008                   Error_Pragma_Arg
10009                     ("no initialization allowed for declaration of& #",
10010                      Arg2);
10011
10012                else
10013                   --  For compatibility, support VADS usage of providing both
10014                   --  pragmas Interface and Interface_Name to obtain the effect
10015                   --  of a single Import pragma.
10016
10017                   if Is_Imported (Def_Id)
10018                     and then Present (First_Rep_Item (Def_Id))
10019                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10020                     and then
10021                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10022                   then
10023                      null;
10024                   else
10025                      Set_Imported (Def_Id);
10026                   end if;
10027
10028                   Set_Is_Public (Def_Id);
10029                   Process_Interface_Name (Def_Id, Arg2, Arg3);
10030                end if;
10031
10032             --  Otherwise must be subprogram
10033
10034             elsif not Is_Subprogram (Def_Id) then
10035                Error_Pragma_Arg
10036                  ("argument of pragma% is not subprogram", Arg1);
10037
10038             else
10039                Check_At_Most_N_Arguments (3);
10040                Hom_Id := Def_Id;
10041                Found := False;
10042
10043                --  Loop through homonyms
10044
10045                loop
10046                   Def_Id := Get_Base_Subprogram (Hom_Id);
10047
10048                   if Is_Imported (Def_Id) then
10049                      Process_Interface_Name (Def_Id, Arg2, Arg3);
10050                      Found := True;
10051                   end if;
10052
10053                   exit when From_Aspect_Specification (N);
10054                   Hom_Id := Homonym (Hom_Id);
10055
10056                   exit when No (Hom_Id)
10057                     or else Scope (Hom_Id) /= Current_Scope;
10058                end loop;
10059
10060                if not Found then
10061                   Error_Pragma_Arg
10062                     ("argument of pragma% is not imported subprogram",
10063                      Arg1);
10064                end if;
10065             end if;
10066          end Interface_Name;
10067
10068          -----------------------
10069          -- Interrupt_Handler --
10070          -----------------------
10071
10072          --  pragma Interrupt_Handler (handler_NAME);
10073
10074          when Pragma_Interrupt_Handler =>
10075             Check_Ada_83_Warning;
10076             Check_Arg_Count (1);
10077             Check_No_Identifiers;
10078
10079             if No_Run_Time_Mode then
10080                Error_Msg_CRT ("Interrupt_Handler pragma", N);
10081             else
10082                Check_Interrupt_Or_Attach_Handler;
10083                Process_Interrupt_Or_Attach_Handler;
10084             end if;
10085
10086          ------------------------
10087          -- Interrupt_Priority --
10088          ------------------------
10089
10090          --  pragma Interrupt_Priority [(EXPRESSION)];
10091
10092          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10093             P   : constant Node_Id := Parent (N);
10094             Arg : Node_Id;
10095
10096          begin
10097             Check_Ada_83_Warning;
10098
10099             if Arg_Count /= 0 then
10100                Arg := Get_Pragma_Arg (Arg1);
10101                Check_Arg_Count (1);
10102                Check_No_Identifiers;
10103
10104                --  The expression must be analyzed in the special manner
10105                --  described in "Handling of Default and Per-Object
10106                --  Expressions" in sem.ads.
10107
10108                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10109             end if;
10110
10111             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10112                Pragma_Misplaced;
10113                return;
10114
10115             elsif Has_Pragma_Priority (P) then
10116                Error_Pragma ("duplicate pragma% not allowed");
10117
10118             else
10119                Set_Has_Pragma_Priority (P, True);
10120                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10121             end if;
10122          end Interrupt_Priority;
10123
10124          ---------------------
10125          -- Interrupt_State --
10126          ---------------------
10127
10128          --  pragma Interrupt_State (
10129          --    [Name  =>] INTERRUPT_ID,
10130          --    [State =>] INTERRUPT_STATE);
10131
10132          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10133          --  INTERRUPT_STATE => System | Runtime | User
10134
10135          --  Note: if the interrupt id is given as an identifier, then it must
10136          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10137          --  given as a static integer expression which must be in the range of
10138          --  Ada.Interrupts.Interrupt_ID.
10139
10140          when Pragma_Interrupt_State => Interrupt_State : declare
10141
10142             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10143             --  This is the entity Ada.Interrupts.Interrupt_ID;
10144
10145             State_Type : Character;
10146             --  Set to 's'/'r'/'u' for System/Runtime/User
10147
10148             IST_Num : Pos;
10149             --  Index to entry in Interrupt_States table
10150
10151             Int_Val : Uint;
10152             --  Value of interrupt
10153
10154             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10155             --  The first argument to the pragma
10156
10157             Int_Ent : Entity_Id;
10158             --  Interrupt entity in Ada.Interrupts.Names
10159
10160          begin
10161             GNAT_Pragma;
10162             Check_Arg_Order ((Name_Name, Name_State));
10163             Check_Arg_Count (2);
10164
10165             Check_Optional_Identifier (Arg1, Name_Name);
10166             Check_Optional_Identifier (Arg2, Name_State);
10167             Check_Arg_Is_Identifier (Arg2);
10168
10169             --  First argument is identifier
10170
10171             if Nkind (Arg1X) = N_Identifier then
10172
10173                --  Search list of names in Ada.Interrupts.Names
10174
10175                Int_Ent := First_Entity (RTE (RE_Names));
10176                loop
10177                   if No (Int_Ent) then
10178                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
10179
10180                   elsif Chars (Int_Ent) = Chars (Arg1X) then
10181                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
10182                      exit;
10183                   end if;
10184
10185                   Next_Entity (Int_Ent);
10186                end loop;
10187
10188             --  First argument is not an identifier, so it must be a static
10189             --  expression of type Ada.Interrupts.Interrupt_ID.
10190
10191             else
10192                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10193                Int_Val := Expr_Value (Arg1X);
10194
10195                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10196                     or else
10197                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10198                then
10199                   Error_Pragma_Arg
10200                     ("value not in range of type " &
10201                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10202                end if;
10203             end if;
10204
10205             --  Check OK state
10206
10207             case Chars (Get_Pragma_Arg (Arg2)) is
10208                when Name_Runtime => State_Type := 'r';
10209                when Name_System  => State_Type := 's';
10210                when Name_User    => State_Type := 'u';
10211
10212                when others =>
10213                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
10214             end case;
10215
10216             --  Check if entry is already stored
10217
10218             IST_Num := Interrupt_States.First;
10219             loop
10220                --  If entry not found, add it
10221
10222                if IST_Num > Interrupt_States.Last then
10223                   Interrupt_States.Append
10224                     ((Interrupt_Number => UI_To_Int (Int_Val),
10225                       Interrupt_State  => State_Type,
10226                       Pragma_Loc       => Loc));
10227                   exit;
10228
10229                --  Case of entry for the same entry
10230
10231                elsif Int_Val = Interrupt_States.Table (IST_Num).
10232                                                            Interrupt_Number
10233                then
10234                   --  If state matches, done, no need to make redundant entry
10235
10236                   exit when
10237                     State_Type = Interrupt_States.Table (IST_Num).
10238                                                            Interrupt_State;
10239
10240                   --  Otherwise if state does not match, error
10241
10242                   Error_Msg_Sloc :=
10243                     Interrupt_States.Table (IST_Num).Pragma_Loc;
10244                   Error_Pragma_Arg
10245                     ("state conflicts with that given #", Arg2);
10246                   exit;
10247                end if;
10248
10249                IST_Num := IST_Num + 1;
10250             end loop;
10251          end Interrupt_State;
10252
10253          ---------------
10254          -- Invariant --
10255          ---------------
10256
10257          --  pragma Invariant
10258          --    ([Entity =>]    type_LOCAL_NAME,
10259          --     [Check  =>]    EXPRESSION
10260          --     [,[Message =>] String_Expression]);
10261
10262          when Pragma_Invariant => Invariant : declare
10263             Type_Id : Node_Id;
10264             Typ     : Entity_Id;
10265
10266             Discard : Boolean;
10267             pragma Unreferenced (Discard);
10268
10269          begin
10270             GNAT_Pragma;
10271             Check_At_Least_N_Arguments (2);
10272             Check_At_Most_N_Arguments (3);
10273             Check_Optional_Identifier (Arg1, Name_Entity);
10274             Check_Optional_Identifier (Arg2, Name_Check);
10275
10276             if Arg_Count = 3 then
10277                Check_Optional_Identifier (Arg3, Name_Message);
10278                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10279             end if;
10280
10281             Check_Arg_Is_Local_Name (Arg1);
10282
10283             Type_Id := Get_Pragma_Arg (Arg1);
10284             Find_Type (Type_Id);
10285             Typ := Entity (Type_Id);
10286
10287             if Typ = Any_Type then
10288                return;
10289
10290             --  An invariant must apply to a private type, or appear in the
10291             --  private part of a package spec and apply to a completion.
10292
10293             elsif Ekind_In (Typ, E_Private_Type,
10294                                  E_Record_Type_With_Private,
10295                                  E_Limited_Private_Type)
10296             then
10297                null;
10298
10299             elsif In_Private_Part (Current_Scope)
10300               and then Has_Private_Declaration (Typ)
10301             then
10302                null;
10303
10304             elsif In_Private_Part (Current_Scope) then
10305                Error_Pragma_Arg
10306                  ("pragma% only allowed for private type " &
10307                   "declared in visible part", Arg1);
10308
10309             else
10310                Error_Pragma_Arg
10311                  ("pragma% only allowed for private type", Arg1);
10312             end if;
10313
10314             --  Note that the type has at least one invariant, and also that
10315             --  it has inheritable invariants if we have Invariant'Class.
10316
10317             Set_Has_Invariants (Typ);
10318
10319             if Class_Present (N) then
10320                Set_Has_Inheritable_Invariants (Typ);
10321             end if;
10322
10323             --  The remaining processing is simply to link the pragma on to
10324             --  the rep item chain, for processing when the type is frozen.
10325             --  This is accomplished by a call to Rep_Item_Too_Late.
10326
10327             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10328          end Invariant;
10329
10330          ----------------------
10331          -- Java_Constructor --
10332          ----------------------
10333
10334          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10335
10336          --  Also handles pragma CIL_Constructor
10337
10338          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10339          Java_Constructor : declare
10340             Convention  : Convention_Id;
10341             Def_Id      : Entity_Id;
10342             Hom_Id      : Entity_Id;
10343             Id          : Entity_Id;
10344             This_Formal : Entity_Id;
10345
10346          begin
10347             GNAT_Pragma;
10348             Check_Arg_Count (1);
10349             Check_Optional_Identifier (Arg1, Name_Entity);
10350             Check_Arg_Is_Local_Name (Arg1);
10351
10352             Id := Get_Pragma_Arg (Arg1);
10353             Find_Program_Unit_Name (Id);
10354
10355             --  If we did not find the name, we are done
10356
10357             if Etype (Id) = Any_Type then
10358                return;
10359             end if;
10360
10361             --  Check wrong use of pragma in wrong VM target
10362
10363             if VM_Target = No_VM then
10364                return;
10365
10366             elsif VM_Target = CLI_Target
10367               and then Prag_Id = Pragma_Java_Constructor
10368             then
10369                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10370
10371             elsif VM_Target = JVM_Target
10372               and then Prag_Id = Pragma_CIL_Constructor
10373             then
10374                Error_Pragma ("must use pragma 'Java_'Constructor");
10375             end if;
10376
10377             case Prag_Id is
10378                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
10379                when Pragma_Java_Constructor => Convention := Convention_Java;
10380                when others                  => null;
10381             end case;
10382
10383             Hom_Id := Entity (Id);
10384
10385             --  Loop through homonyms
10386
10387             loop
10388                Def_Id := Get_Base_Subprogram (Hom_Id);
10389
10390                --  The constructor is required to be a function
10391
10392                if Ekind (Def_Id) /= E_Function then
10393                   if VM_Target = JVM_Target then
10394                      Error_Pragma_Arg
10395                        ("pragma% requires function returning a " &
10396                         "'Java access type", Def_Id);
10397                   else
10398                      Error_Pragma_Arg
10399                        ("pragma% requires function returning a " &
10400                         "'C'I'L access type", Def_Id);
10401                   end if;
10402                end if;
10403
10404                --  Check arguments: For tagged type the first formal must be
10405                --  named "this" and its type must be a named access type
10406                --  designating a class-wide tagged type that has convention
10407                --  CIL/Java. The first formal must also have a null default
10408                --  value. For example:
10409
10410                --      type Typ is tagged ...
10411                --      type Ref is access all Typ;
10412                --      pragma Convention (CIL, Typ);
10413
10414                --      function New_Typ (This : Ref) return Ref;
10415                --      function New_Typ (This : Ref; I : Integer) return Ref;
10416                --      pragma Cil_Constructor (New_Typ);
10417
10418                --  Reason: The first formal must NOT be a primitive of the
10419                --  tagged type.
10420
10421                --  This rule also applies to constructors of delegates used
10422                --  to interface with standard target libraries. For example:
10423
10424                --      type Delegate is access procedure ...
10425                --      pragma Import (CIL, Delegate, ...);
10426
10427                --      function new_Delegate
10428                --        (This : Delegate := null; ... ) return Delegate;
10429
10430                --  For value-types this rule does not apply.
10431
10432                if not Is_Value_Type (Etype (Def_Id)) then
10433                   if No (First_Formal (Def_Id)) then
10434                      Error_Msg_Name_1 := Pname;
10435                      Error_Msg_N ("% function must have parameters", Def_Id);
10436                      return;
10437                   end if;
10438
10439                   --  In the JRE library we have several occurrences in which
10440                   --  the "this" parameter is not the first formal.
10441
10442                   This_Formal := First_Formal (Def_Id);
10443
10444                   --  In the JRE library we have several occurrences in which
10445                   --  the "this" parameter is not the first formal. Search for
10446                   --  it.
10447
10448                   if VM_Target = JVM_Target then
10449                      while Present (This_Formal)
10450                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10451                      loop
10452                         Next_Formal (This_Formal);
10453                      end loop;
10454
10455                      if No (This_Formal) then
10456                         This_Formal := First_Formal (Def_Id);
10457                      end if;
10458                   end if;
10459
10460                   --  Warning: The first parameter should be named "this".
10461                   --  We temporarily allow it because we have the following
10462                   --  case in the Java runtime (file s-osinte.ads) ???
10463
10464                   --    function new_Thread
10465                   --      (Self_Id : System.Address) return Thread_Id;
10466                   --    pragma Java_Constructor (new_Thread);
10467
10468                   if VM_Target = JVM_Target
10469                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10470                                = "self_id"
10471                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10472                   then
10473                      null;
10474
10475                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10476                      Error_Msg_Name_1 := Pname;
10477                      Error_Msg_N
10478                        ("first formal of % function must be named `this`",
10479                         Parent (This_Formal));
10480
10481                   elsif not Is_Access_Type (Etype (This_Formal)) then
10482                      Error_Msg_Name_1 := Pname;
10483                      Error_Msg_N
10484                        ("first formal of % function must be an access type",
10485                         Parameter_Type (Parent (This_Formal)));
10486
10487                   --  For delegates the type of the first formal must be a
10488                   --  named access-to-subprogram type (see previous example)
10489
10490                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10491                     and then Ekind (Etype (This_Formal))
10492                                /= E_Access_Subprogram_Type
10493                   then
10494                      Error_Msg_Name_1 := Pname;
10495                      Error_Msg_N
10496                        ("first formal of % function must be a named access" &
10497                         " to subprogram type",
10498                         Parameter_Type (Parent (This_Formal)));
10499
10500                   --  Warning: We should reject anonymous access types because
10501                   --  the constructor must not be handled as a primitive of the
10502                   --  tagged type. We temporarily allow it because this profile
10503                   --  is currently generated by cil2ada???
10504
10505                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10506                     and then not Ekind_In (Etype (This_Formal),
10507                                              E_Access_Type,
10508                                              E_General_Access_Type,
10509                                              E_Anonymous_Access_Type)
10510                   then
10511                      Error_Msg_Name_1 := Pname;
10512                      Error_Msg_N
10513                        ("first formal of % function must be a named access" &
10514                         " type",
10515                         Parameter_Type (Parent (This_Formal)));
10516
10517                   elsif Atree.Convention
10518                          (Designated_Type (Etype (This_Formal))) /= Convention
10519                   then
10520                      Error_Msg_Name_1 := Pname;
10521
10522                      if Convention = Convention_Java then
10523                         Error_Msg_N
10524                           ("pragma% requires convention 'Cil in designated" &
10525                            " type",
10526                            Parameter_Type (Parent (This_Formal)));
10527                      else
10528                         Error_Msg_N
10529                           ("pragma% requires convention 'Java in designated" &
10530                            " type",
10531                            Parameter_Type (Parent (This_Formal)));
10532                      end if;
10533
10534                   elsif No (Expression (Parent (This_Formal)))
10535                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10536                   then
10537                      Error_Msg_Name_1 := Pname;
10538                      Error_Msg_N
10539                        ("pragma% requires first formal with default `null`",
10540                         Parameter_Type (Parent (This_Formal)));
10541                   end if;
10542                end if;
10543
10544                --  Check result type: the constructor must be a function
10545                --  returning:
10546                --   * a value type (only allowed in the CIL compiler)
10547                --   * an access-to-subprogram type with convention Java/CIL
10548                --   * an access-type designating a type that has convention
10549                --     Java/CIL.
10550
10551                if Is_Value_Type (Etype (Def_Id)) then
10552                   null;
10553
10554                --  Access-to-subprogram type with convention Java/CIL
10555
10556                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10557                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10558                      if Convention = Convention_Java then
10559                         Error_Pragma_Arg
10560                           ("pragma% requires function returning a " &
10561                            "'Java access type", Arg1);
10562                      else
10563                         pragma Assert (Convention = Convention_CIL);
10564                         Error_Pragma_Arg
10565                           ("pragma% requires function returning a " &
10566                            "'C'I'L access type", Arg1);
10567                      end if;
10568                   end if;
10569
10570                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10571                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10572                                                    E_General_Access_Type)
10573                     or else
10574                       Atree.Convention
10575                         (Designated_Type (Etype (Def_Id))) /= Convention
10576                   then
10577                      Error_Msg_Name_1 := Pname;
10578
10579                      if Convention = Convention_Java then
10580                         Error_Pragma_Arg
10581                           ("pragma% requires function returning a named" &
10582                            "'Java access type", Arg1);
10583                      else
10584                         Error_Pragma_Arg
10585                           ("pragma% requires function returning a named" &
10586                            "'C'I'L access type", Arg1);
10587                      end if;
10588                   end if;
10589                end if;
10590
10591                Set_Is_Constructor (Def_Id);
10592                Set_Convention     (Def_Id, Convention);
10593                Set_Is_Imported    (Def_Id);
10594
10595                exit when From_Aspect_Specification (N);
10596                Hom_Id := Homonym (Hom_Id);
10597
10598                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10599             end loop;
10600          end Java_Constructor;
10601
10602          ----------------------
10603          -- Java_Interface --
10604          ----------------------
10605
10606          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10607
10608          when Pragma_Java_Interface => Java_Interface : declare
10609             Arg : Node_Id;
10610             Typ : Entity_Id;
10611
10612          begin
10613             GNAT_Pragma;
10614             Check_Arg_Count (1);
10615             Check_Optional_Identifier (Arg1, Name_Entity);
10616             Check_Arg_Is_Local_Name (Arg1);
10617
10618             Arg := Get_Pragma_Arg (Arg1);
10619             Analyze (Arg);
10620
10621             if Etype (Arg) = Any_Type then
10622                return;
10623             end if;
10624
10625             if not Is_Entity_Name (Arg)
10626               or else not Is_Type (Entity (Arg))
10627             then
10628                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10629             end if;
10630
10631             Typ := Underlying_Type (Entity (Arg));
10632
10633             --  For now simply check some of the semantic constraints on the
10634             --  type. This currently leaves out some restrictions on interface
10635             --  types, namely that the parent type must be java.lang.Object.Typ
10636             --  and that all primitives of the type should be declared
10637             --  abstract. ???
10638
10639             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10640                Error_Pragma_Arg ("pragma% requires an abstract "
10641                  & "tagged type", Arg1);
10642
10643             elsif not Has_Discriminants (Typ)
10644               or else Ekind (Etype (First_Discriminant (Typ)))
10645                         /= E_Anonymous_Access_Type
10646               or else
10647                 not Is_Class_Wide_Type
10648                       (Designated_Type (Etype (First_Discriminant (Typ))))
10649             then
10650                Error_Pragma_Arg
10651                  ("type must have a class-wide access discriminant", Arg1);
10652             end if;
10653          end Java_Interface;
10654
10655          ----------------
10656          -- Keep_Names --
10657          ----------------
10658
10659          --  pragma Keep_Names ([On => ] local_NAME);
10660
10661          when Pragma_Keep_Names => Keep_Names : declare
10662             Arg : Node_Id;
10663
10664          begin
10665             GNAT_Pragma;
10666             Check_Arg_Count (1);
10667             Check_Optional_Identifier (Arg1, Name_On);
10668             Check_Arg_Is_Local_Name (Arg1);
10669
10670             Arg := Get_Pragma_Arg (Arg1);
10671             Analyze (Arg);
10672
10673             if Etype (Arg) = Any_Type then
10674                return;
10675             end if;
10676
10677             if not Is_Entity_Name (Arg)
10678               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10679             then
10680                Error_Pragma_Arg
10681                  ("pragma% requires a local enumeration type", Arg1);
10682             end if;
10683
10684             Set_Discard_Names (Entity (Arg), False);
10685          end Keep_Names;
10686
10687          -------------
10688          -- License --
10689          -------------
10690
10691          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10692
10693          when Pragma_License =>
10694             GNAT_Pragma;
10695             Check_Arg_Count (1);
10696             Check_No_Identifiers;
10697             Check_Valid_Configuration_Pragma;
10698             Check_Arg_Is_Identifier (Arg1);
10699
10700             declare
10701                Sind : constant Source_File_Index :=
10702                         Source_Index (Current_Sem_Unit);
10703
10704             begin
10705                case Chars (Get_Pragma_Arg (Arg1)) is
10706                   when Name_GPL =>
10707                      Set_License (Sind, GPL);
10708
10709                   when Name_Modified_GPL =>
10710                      Set_License (Sind, Modified_GPL);
10711
10712                   when Name_Restricted =>
10713                      Set_License (Sind, Restricted);
10714
10715                   when Name_Unrestricted =>
10716                      Set_License (Sind, Unrestricted);
10717
10718                   when others =>
10719                      Error_Pragma_Arg ("invalid license name", Arg1);
10720                end case;
10721             end;
10722
10723          ---------------
10724          -- Link_With --
10725          ---------------
10726
10727          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10728
10729          when Pragma_Link_With => Link_With : declare
10730             Arg : Node_Id;
10731
10732          begin
10733             GNAT_Pragma;
10734
10735             if Operating_Mode = Generate_Code
10736               and then In_Extended_Main_Source_Unit (N)
10737             then
10738                Check_At_Least_N_Arguments (1);
10739                Check_No_Identifiers;
10740                Check_Is_In_Decl_Part_Or_Package_Spec;
10741                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10742                Start_String;
10743
10744                Arg := Arg1;
10745                while Present (Arg) loop
10746                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10747
10748                   --  Store argument, converting sequences of spaces to a
10749                   --  single null character (this is one of the differences
10750                   --  in processing between Link_With and Linker_Options).
10751
10752                   Arg_Store : declare
10753                      C : constant Char_Code := Get_Char_Code (' ');
10754                      S : constant String_Id :=
10755                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10756                      L : constant Nat := String_Length (S);
10757                      F : Nat := 1;
10758
10759                      procedure Skip_Spaces;
10760                      --  Advance F past any spaces
10761
10762                      -----------------
10763                      -- Skip_Spaces --
10764                      -----------------
10765
10766                      procedure Skip_Spaces is
10767                      begin
10768                         while F <= L and then Get_String_Char (S, F) = C loop
10769                            F := F + 1;
10770                         end loop;
10771                      end Skip_Spaces;
10772
10773                   --  Start of processing for Arg_Store
10774
10775                   begin
10776                      Skip_Spaces; -- skip leading spaces
10777
10778                      --  Loop through characters, changing any embedded
10779                      --  sequence of spaces to a single null character (this
10780                      --  is how Link_With/Linker_Options differ)
10781
10782                      while F <= L loop
10783                         if Get_String_Char (S, F) = C then
10784                            Skip_Spaces;
10785                            exit when F > L;
10786                            Store_String_Char (ASCII.NUL);
10787
10788                         else
10789                            Store_String_Char (Get_String_Char (S, F));
10790                            F := F + 1;
10791                         end if;
10792                      end loop;
10793                   end Arg_Store;
10794
10795                   Arg := Next (Arg);
10796
10797                   if Present (Arg) then
10798                      Store_String_Char (ASCII.NUL);
10799                   end if;
10800                end loop;
10801
10802                Store_Linker_Option_String (End_String);
10803             end if;
10804          end Link_With;
10805
10806          ------------------
10807          -- Linker_Alias --
10808          ------------------
10809
10810          --  pragma Linker_Alias (
10811          --      [Entity =>]  LOCAL_NAME
10812          --      [Target =>]  static_string_EXPRESSION);
10813
10814          when Pragma_Linker_Alias =>
10815             GNAT_Pragma;
10816             Check_Arg_Order ((Name_Entity, Name_Target));
10817             Check_Arg_Count (2);
10818             Check_Optional_Identifier (Arg1, Name_Entity);
10819             Check_Optional_Identifier (Arg2, Name_Target);
10820             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10821             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10822
10823             --  The only processing required is to link this item on to the
10824             --  list of rep items for the given entity. This is accomplished
10825             --  by the call to Rep_Item_Too_Late (when no error is detected
10826             --  and False is returned).
10827
10828             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10829                return;
10830             else
10831                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10832             end if;
10833
10834          ------------------------
10835          -- Linker_Constructor --
10836          ------------------------
10837
10838          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10839
10840          --  Code is shared with Linker_Destructor
10841
10842          -----------------------
10843          -- Linker_Destructor --
10844          -----------------------
10845
10846          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10847
10848          when Pragma_Linker_Constructor |
10849               Pragma_Linker_Destructor =>
10850          Linker_Constructor : declare
10851             Arg1_X : Node_Id;
10852             Proc   : Entity_Id;
10853
10854          begin
10855             GNAT_Pragma;
10856             Check_Arg_Count (1);
10857             Check_No_Identifiers;
10858             Check_Arg_Is_Local_Name (Arg1);
10859             Arg1_X := Get_Pragma_Arg (Arg1);
10860             Analyze (Arg1_X);
10861             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10862
10863             if not Is_Library_Level_Entity (Proc) then
10864                Error_Pragma_Arg
10865                 ("argument for pragma% must be library level entity", Arg1);
10866             end if;
10867
10868             --  The only processing required is to link this item on to the
10869             --  list of rep items for the given entity. This is accomplished
10870             --  by the call to Rep_Item_Too_Late (when no error is detected
10871             --  and False is returned).
10872
10873             if Rep_Item_Too_Late (Proc, N) then
10874                return;
10875             else
10876                Set_Has_Gigi_Rep_Item (Proc);
10877             end if;
10878          end Linker_Constructor;
10879
10880          --------------------
10881          -- Linker_Options --
10882          --------------------
10883
10884          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10885
10886          when Pragma_Linker_Options => Linker_Options : declare
10887             Arg : Node_Id;
10888
10889          begin
10890             Check_Ada_83_Warning;
10891             Check_No_Identifiers;
10892             Check_Arg_Count (1);
10893             Check_Is_In_Decl_Part_Or_Package_Spec;
10894             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10895             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10896
10897             Arg := Arg2;
10898             while Present (Arg) loop
10899                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10900                Store_String_Char (ASCII.NUL);
10901                Store_String_Chars
10902                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10903                Arg := Next (Arg);
10904             end loop;
10905
10906             if Operating_Mode = Generate_Code
10907               and then In_Extended_Main_Source_Unit (N)
10908             then
10909                Store_Linker_Option_String (End_String);
10910             end if;
10911          end Linker_Options;
10912
10913          --------------------
10914          -- Linker_Section --
10915          --------------------
10916
10917          --  pragma Linker_Section (
10918          --      [Entity  =>]  LOCAL_NAME
10919          --      [Section =>]  static_string_EXPRESSION);
10920
10921          when Pragma_Linker_Section =>
10922             GNAT_Pragma;
10923             Check_Arg_Order ((Name_Entity, Name_Section));
10924             Check_Arg_Count (2);
10925             Check_Optional_Identifier (Arg1, Name_Entity);
10926             Check_Optional_Identifier (Arg2, Name_Section);
10927             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10928             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10929
10930             --  This pragma applies only to objects
10931
10932             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10933                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10934             end if;
10935
10936             --  The only processing required is to link this item on to the
10937             --  list of rep items for the given entity. This is accomplished
10938             --  by the call to Rep_Item_Too_Late (when no error is detected
10939             --  and False is returned).
10940
10941             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10942                return;
10943             else
10944                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10945             end if;
10946
10947          ----------
10948          -- List --
10949          ----------
10950
10951          --  pragma List (On | Off)
10952
10953          --  There is nothing to do here, since we did all the processing for
10954          --  this pragma in Par.Prag (so that it works properly even in syntax
10955          --  only mode).
10956
10957          when Pragma_List =>
10958             null;
10959
10960          --------------------
10961          -- Locking_Policy --
10962          --------------------
10963
10964          --  pragma Locking_Policy (policy_IDENTIFIER);
10965
10966          when Pragma_Locking_Policy => declare
10967             subtype LP_Range is Name_Id
10968               range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10969             LP_Val : LP_Range;
10970             LP     : Character;
10971          begin
10972             Check_Ada_83_Warning;
10973             Check_Arg_Count (1);
10974             Check_No_Identifiers;
10975             Check_Arg_Is_Locking_Policy (Arg1);
10976             Check_Valid_Configuration_Pragma;
10977             LP_Val := Chars (Get_Pragma_Arg (Arg1));
10978
10979             case LP_Val is
10980                when Name_Ceiling_Locking            => LP := 'C';
10981                when Name_Inheritance_Locking        => LP := 'I';
10982                when Name_Concurrent_Readers_Locking => LP := 'R';
10983             end case;
10984
10985             if Locking_Policy /= ' '
10986               and then Locking_Policy /= LP
10987             then
10988                Error_Msg_Sloc := Locking_Policy_Sloc;
10989                Error_Pragma ("locking policy incompatible with policy#");
10990
10991             --  Set new policy, but always preserve System_Location since we
10992             --  like the error message with the run time name.
10993
10994             else
10995                Locking_Policy := LP;
10996
10997                if Locking_Policy_Sloc /= System_Location then
10998                   Locking_Policy_Sloc := Loc;
10999                end if;
11000             end if;
11001          end;
11002
11003          ----------------
11004          -- Long_Float --
11005          ----------------
11006
11007          --  pragma Long_Float (D_Float | G_Float);
11008
11009          when Pragma_Long_Float => Long_Float : declare
11010          begin
11011             GNAT_Pragma;
11012             Check_Valid_Configuration_Pragma;
11013             Check_Arg_Count (1);
11014             Check_No_Identifier (Arg1);
11015             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11016
11017             if not OpenVMS_On_Target then
11018                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11019             end if;
11020
11021             --  D_Float case
11022
11023             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11024                if Opt.Float_Format_Long = 'G' then
11025                   Error_Pragma_Arg
11026                     ("G_Float previously specified", Arg1);
11027
11028                elsif Current_Sem_Unit /= Main_Unit
11029                  and then Opt.Float_Format_Long /= 'D'
11030                then
11031                   Error_Pragma_Arg
11032                     ("main unit not compiled with pragma Long_Float (D_Float)",
11033                      "\pragma% must be used consistently for whole partition",
11034                      Arg1);
11035
11036                else
11037                   Opt.Float_Format_Long := 'D';
11038                end if;
11039
11040             --  G_Float case (this is the default, does not need overriding)
11041
11042             else
11043                if Opt.Float_Format_Long = 'D' then
11044                   Error_Pragma ("D_Float previously specified");
11045
11046                elsif Current_Sem_Unit /= Main_Unit
11047                  and then Opt.Float_Format_Long /= 'G'
11048                then
11049                   Error_Pragma_Arg
11050                     ("main unit not compiled with pragma Long_Float (G_Float)",
11051                      "\pragma% must be used consistently for whole partition",
11052                      Arg1);
11053
11054                else
11055                   Opt.Float_Format_Long := 'G';
11056                end if;
11057             end if;
11058
11059             Set_Standard_Fpt_Formats;
11060          end Long_Float;
11061
11062          -----------------------
11063          -- Machine_Attribute --
11064          -----------------------
11065
11066          --  pragma Machine_Attribute (
11067          --       [Entity         =>] LOCAL_NAME,
11068          --       [Attribute_Name =>] static_string_EXPRESSION
11069          --    [, [Info           =>] static_EXPRESSION] );
11070
11071          when Pragma_Machine_Attribute => Machine_Attribute : declare
11072             Def_Id : Entity_Id;
11073
11074          begin
11075             GNAT_Pragma;
11076             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11077
11078             if Arg_Count = 3 then
11079                Check_Optional_Identifier (Arg3, Name_Info);
11080                Check_Arg_Is_Static_Expression (Arg3);
11081             else
11082                Check_Arg_Count (2);
11083             end if;
11084
11085             Check_Optional_Identifier (Arg1, Name_Entity);
11086             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11087             Check_Arg_Is_Local_Name (Arg1);
11088             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11089             Def_Id := Entity (Get_Pragma_Arg (Arg1));
11090
11091             if Is_Access_Type (Def_Id) then
11092                Def_Id := Designated_Type (Def_Id);
11093             end if;
11094
11095             if Rep_Item_Too_Early (Def_Id, N) then
11096                return;
11097             end if;
11098
11099             Def_Id := Underlying_Type (Def_Id);
11100
11101             --  The only processing required is to link this item on to the
11102             --  list of rep items for the given entity. This is accomplished
11103             --  by the call to Rep_Item_Too_Late (when no error is detected
11104             --  and False is returned).
11105
11106             if Rep_Item_Too_Late (Def_Id, N) then
11107                return;
11108             else
11109                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11110             end if;
11111          end Machine_Attribute;
11112
11113          ----------
11114          -- Main --
11115          ----------
11116
11117          --  pragma Main
11118          --   (MAIN_OPTION [, MAIN_OPTION]);
11119
11120          --  MAIN_OPTION ::=
11121          --    [STACK_SIZE              =>] static_integer_EXPRESSION
11122          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11123          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
11124
11125          when Pragma_Main => Main : declare
11126             Args  : Args_List (1 .. 3);
11127             Names : constant Name_List (1 .. 3) := (
11128                       Name_Stack_Size,
11129                       Name_Task_Stack_Size_Default,
11130                       Name_Time_Slicing_Enabled);
11131
11132             Nod : Node_Id;
11133
11134          begin
11135             GNAT_Pragma;
11136             Gather_Associations (Names, Args);
11137
11138             for J in 1 .. 2 loop
11139                if Present (Args (J)) then
11140                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11141                end if;
11142             end loop;
11143
11144             if Present (Args (3)) then
11145                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11146             end if;
11147
11148             Nod := Next (N);
11149             while Present (Nod) loop
11150                if Nkind (Nod) = N_Pragma
11151                  and then Pragma_Name (Nod) = Name_Main
11152                then
11153                   Error_Msg_Name_1 := Pname;
11154                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11155                end if;
11156
11157                Next (Nod);
11158             end loop;
11159          end Main;
11160
11161          ------------------
11162          -- Main_Storage --
11163          ------------------
11164
11165          --  pragma Main_Storage
11166          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11167
11168          --  MAIN_STORAGE_OPTION ::=
11169          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11170          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11171
11172          when Pragma_Main_Storage => Main_Storage : declare
11173             Args  : Args_List (1 .. 2);
11174             Names : constant Name_List (1 .. 2) := (
11175                       Name_Working_Storage,
11176                       Name_Top_Guard);
11177
11178             Nod : Node_Id;
11179
11180          begin
11181             GNAT_Pragma;
11182             Gather_Associations (Names, Args);
11183
11184             for J in 1 .. 2 loop
11185                if Present (Args (J)) then
11186                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11187                end if;
11188             end loop;
11189
11190             Check_In_Main_Program;
11191
11192             Nod := Next (N);
11193             while Present (Nod) loop
11194                if Nkind (Nod) = N_Pragma
11195                  and then Pragma_Name (Nod) = Name_Main_Storage
11196                then
11197                   Error_Msg_Name_1 := Pname;
11198                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11199                end if;
11200
11201                Next (Nod);
11202             end loop;
11203          end Main_Storage;
11204
11205          -----------------
11206          -- Memory_Size --
11207          -----------------
11208
11209          --  pragma Memory_Size (NUMERIC_LITERAL)
11210
11211          when Pragma_Memory_Size =>
11212             GNAT_Pragma;
11213
11214             --  Memory size is simply ignored
11215
11216             Check_No_Identifiers;
11217             Check_Arg_Count (1);
11218             Check_Arg_Is_Integer_Literal (Arg1);
11219
11220          -------------
11221          -- No_Body --
11222          -------------
11223
11224          --  pragma No_Body;
11225
11226          --  The only correct use of this pragma is on its own in a file, in
11227          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
11228          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11229          --  check for a file containing nothing but a No_Body pragma). If we
11230          --  attempt to process it during normal semantics processing, it means
11231          --  it was misplaced.
11232
11233          when Pragma_No_Body =>
11234             GNAT_Pragma;
11235             Pragma_Misplaced;
11236
11237          ---------------
11238          -- No_Return --
11239          ---------------
11240
11241          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11242
11243          when Pragma_No_Return => No_Return : declare
11244             Id    : Node_Id;
11245             E     : Entity_Id;
11246             Found : Boolean;
11247             Arg   : Node_Id;
11248
11249          begin
11250             Ada_2005_Pragma;
11251             Check_At_Least_N_Arguments (1);
11252
11253             --  Loop through arguments of pragma
11254
11255             Arg := Arg1;
11256             while Present (Arg) loop
11257                Check_Arg_Is_Local_Name (Arg);
11258                Id := Get_Pragma_Arg (Arg);
11259                Analyze (Id);
11260
11261                if not Is_Entity_Name (Id) then
11262                   Error_Pragma_Arg ("entity name required", Arg);
11263                end if;
11264
11265                if Etype (Id) = Any_Type then
11266                   raise Pragma_Exit;
11267                end if;
11268
11269                --  Loop to find matching procedures
11270
11271                E := Entity (Id);
11272                Found := False;
11273                while Present (E)
11274                  and then Scope (E) = Current_Scope
11275                loop
11276                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11277                      Set_No_Return (E);
11278
11279                      --  Set flag on any alias as well
11280
11281                      if Is_Overloadable (E) and then Present (Alias (E)) then
11282                         Set_No_Return (Alias (E));
11283                      end if;
11284
11285                      Found := True;
11286                   end if;
11287
11288                   exit when From_Aspect_Specification (N);
11289                   E := Homonym (E);
11290                end loop;
11291
11292                if not Found then
11293                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11294                end if;
11295
11296                Next (Arg);
11297             end loop;
11298          end No_Return;
11299
11300          -----------------
11301          -- No_Run_Time --
11302          -----------------
11303
11304          --  pragma No_Run_Time;
11305
11306          --  Note: this pragma is retained for backwards compatibility. See
11307          --  body of Rtsfind for full details on its handling.
11308
11309          when Pragma_No_Run_Time =>
11310             GNAT_Pragma;
11311             Check_Valid_Configuration_Pragma;
11312             Check_Arg_Count (0);
11313
11314             No_Run_Time_Mode           := True;
11315             Configurable_Run_Time_Mode := True;
11316
11317             --  Set Duration to 32 bits if word size is 32
11318
11319             if Ttypes.System_Word_Size = 32 then
11320                Duration_32_Bits_On_Target := True;
11321             end if;
11322
11323             --  Set appropriate restrictions
11324
11325             Set_Restriction (No_Finalization, N);
11326             Set_Restriction (No_Exception_Handlers, N);
11327             Set_Restriction (Max_Tasks, N, 0);
11328             Set_Restriction (No_Tasking, N);
11329
11330          ------------------------
11331          -- No_Strict_Aliasing --
11332          ------------------------
11333
11334          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11335
11336          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11337             E_Id : Entity_Id;
11338
11339          begin
11340             GNAT_Pragma;
11341             Check_At_Most_N_Arguments (1);
11342
11343             if Arg_Count = 0 then
11344                Check_Valid_Configuration_Pragma;
11345                Opt.No_Strict_Aliasing := True;
11346
11347             else
11348                Check_Optional_Identifier (Arg2, Name_Entity);
11349                Check_Arg_Is_Local_Name (Arg1);
11350                E_Id := Entity (Get_Pragma_Arg (Arg1));
11351
11352                if E_Id = Any_Type then
11353                   return;
11354                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11355                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
11356                end if;
11357
11358                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11359             end if;
11360          end No_Strict_Aliasing;
11361
11362          -----------------------
11363          -- Normalize_Scalars --
11364          -----------------------
11365
11366          --  pragma Normalize_Scalars;
11367
11368          when Pragma_Normalize_Scalars =>
11369             Check_Ada_83_Warning;
11370             Check_Arg_Count (0);
11371             Check_Valid_Configuration_Pragma;
11372
11373             --  Normalize_Scalars creates false positives in CodePeer, and
11374             --  incorrect negative results in Alfa mode, so ignore this pragma
11375             --  in these modes.
11376
11377             if not (CodePeer_Mode or Alfa_Mode) then
11378                Normalize_Scalars := True;
11379                Init_Or_Norm_Scalars := True;
11380             end if;
11381
11382          -----------------
11383          -- Obsolescent --
11384          -----------------
11385
11386          --  pragma Obsolescent;
11387
11388          --  pragma Obsolescent (
11389          --    [Message =>] static_string_EXPRESSION
11390          --  [,[Version =>] Ada_05]]);
11391
11392          --  pragma Obsolescent (
11393          --    [Entity  =>] NAME
11394          --  [,[Message =>] static_string_EXPRESSION
11395          --  [,[Version =>] Ada_05]] );
11396
11397          when Pragma_Obsolescent => Obsolescent : declare
11398             Ename : Node_Id;
11399             Decl  : Node_Id;
11400
11401             procedure Set_Obsolescent (E : Entity_Id);
11402             --  Given an entity Ent, mark it as obsolescent if appropriate
11403
11404             ---------------------
11405             -- Set_Obsolescent --
11406             ---------------------
11407
11408             procedure Set_Obsolescent (E : Entity_Id) is
11409                Active : Boolean;
11410                Ent    : Entity_Id;
11411                S      : String_Id;
11412
11413             begin
11414                Active := True;
11415                Ent    := E;
11416
11417                --  Entity name was given
11418
11419                if Present (Ename) then
11420
11421                   --  If entity name matches, we are fine. Save entity in
11422                   --  pragma argument, for ASIS use.
11423
11424                   if Chars (Ename) = Chars (Ent) then
11425                      Set_Entity (Ename, Ent);
11426                      Generate_Reference (Ent, Ename);
11427
11428                   --  If entity name does not match, only possibility is an
11429                   --  enumeration literal from an enumeration type declaration.
11430
11431                   elsif Ekind (Ent) /= E_Enumeration_Type then
11432                      Error_Pragma
11433                        ("pragma % entity name does not match declaration");
11434
11435                   else
11436                      Ent := First_Literal (E);
11437                      loop
11438                         if No (Ent) then
11439                            Error_Pragma
11440                              ("pragma % entity name does not match any " &
11441                               "enumeration literal");
11442
11443                         elsif Chars (Ent) = Chars (Ename) then
11444                            Set_Entity (Ename, Ent);
11445                            Generate_Reference (Ent, Ename);
11446                            exit;
11447
11448                         else
11449                            Ent := Next_Literal (Ent);
11450                         end if;
11451                      end loop;
11452                   end if;
11453                end if;
11454
11455                --  Ent points to entity to be marked
11456
11457                if Arg_Count >= 1 then
11458
11459                   --  Deal with static string argument
11460
11461                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11462                   S := Strval (Get_Pragma_Arg (Arg1));
11463
11464                   for J in 1 .. String_Length (S) loop
11465                      if not In_Character_Range (Get_String_Char (S, J)) then
11466                         Error_Pragma_Arg
11467                           ("pragma% argument does not allow wide characters",
11468                            Arg1);
11469                      end if;
11470                   end loop;
11471
11472                   Obsolescent_Warnings.Append
11473                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11474
11475                   --  Check for Ada_05 parameter
11476
11477                   if Arg_Count /= 1 then
11478                      Check_Arg_Count (2);
11479
11480                      declare
11481                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11482
11483                      begin
11484                         Check_Arg_Is_Identifier (Argx);
11485
11486                         if Chars (Argx) /= Name_Ada_05 then
11487                            Error_Msg_Name_2 := Name_Ada_05;
11488                            Error_Pragma_Arg
11489                              ("only allowed argument for pragma% is %", Argx);
11490                         end if;
11491
11492                         if Ada_Version_Explicit < Ada_2005
11493                           or else not Warn_On_Ada_2005_Compatibility
11494                         then
11495                            Active := False;
11496                         end if;
11497                      end;
11498                   end if;
11499                end if;
11500
11501                --  Set flag if pragma active
11502
11503                if Active then
11504                   Set_Is_Obsolescent (Ent);
11505                end if;
11506
11507                return;
11508             end Set_Obsolescent;
11509
11510          --  Start of processing for pragma Obsolescent
11511
11512          begin
11513             GNAT_Pragma;
11514
11515             Check_At_Most_N_Arguments (3);
11516
11517             --  See if first argument specifies an entity name
11518
11519             if Arg_Count >= 1
11520               and then
11521                 (Chars (Arg1) = Name_Entity
11522                    or else
11523                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11524                                                       N_Identifier,
11525                                                       N_Operator_Symbol))
11526             then
11527                Ename := Get_Pragma_Arg (Arg1);
11528
11529                --  Eliminate first argument, so we can share processing
11530
11531                Arg1 := Arg2;
11532                Arg2 := Arg3;
11533                Arg_Count := Arg_Count - 1;
11534
11535             --  No Entity name argument given
11536
11537             else
11538                Ename := Empty;
11539             end if;
11540
11541             if Arg_Count >= 1 then
11542                Check_Optional_Identifier (Arg1, Name_Message);
11543
11544                if Arg_Count = 2 then
11545                   Check_Optional_Identifier (Arg2, Name_Version);
11546                end if;
11547             end if;
11548
11549             --  Get immediately preceding declaration
11550
11551             Decl := Prev (N);
11552             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11553                Prev (Decl);
11554             end loop;
11555
11556             --  Cases where we do not follow anything other than another pragma
11557
11558             if No (Decl) then
11559
11560                --  First case: library level compilation unit declaration with
11561                --  the pragma immediately following the declaration.
11562
11563                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11564                   Set_Obsolescent
11565                     (Defining_Entity (Unit (Parent (Parent (N)))));
11566                   return;
11567
11568                --  Case 2: library unit placement for package
11569
11570                else
11571                   declare
11572                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11573                   begin
11574                      if Is_Package_Or_Generic_Package (Ent) then
11575                         Set_Obsolescent (Ent);
11576                         return;
11577                      end if;
11578                   end;
11579                end if;
11580
11581             --  Cases where we must follow a declaration
11582
11583             else
11584                if         Nkind (Decl) not in N_Declaration
11585                  and then Nkind (Decl) not in N_Later_Decl_Item
11586                  and then Nkind (Decl) not in N_Generic_Declaration
11587                  and then Nkind (Decl) not in N_Renaming_Declaration
11588                then
11589                   Error_Pragma
11590                     ("pragma% misplaced, "
11591                      & "must immediately follow a declaration");
11592
11593                else
11594                   Set_Obsolescent (Defining_Entity (Decl));
11595                   return;
11596                end if;
11597             end if;
11598          end Obsolescent;
11599
11600          --------------
11601          -- Optimize --
11602          --------------
11603
11604          --  pragma Optimize (Time | Space | Off);
11605
11606          --  The actual check for optimize is done in Gigi. Note that this
11607          --  pragma does not actually change the optimization setting, it
11608          --  simply checks that it is consistent with the pragma.
11609
11610          when Pragma_Optimize =>
11611             Check_No_Identifiers;
11612             Check_Arg_Count (1);
11613             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11614
11615          ------------------------
11616          -- Optimize_Alignment --
11617          ------------------------
11618
11619          --  pragma Optimize_Alignment (Time | Space | Off);
11620
11621          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11622             GNAT_Pragma;
11623             Check_No_Identifiers;
11624             Check_Arg_Count (1);
11625             Check_Valid_Configuration_Pragma;
11626
11627             declare
11628                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11629             begin
11630                case Nam is
11631                   when Name_Time =>
11632                      Opt.Optimize_Alignment := 'T';
11633                   when Name_Space =>
11634                      Opt.Optimize_Alignment := 'S';
11635                   when Name_Off =>
11636                      Opt.Optimize_Alignment := 'O';
11637                   when others =>
11638                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11639                end case;
11640             end;
11641
11642             --  Set indication that mode is set locally. If we are in fact in a
11643             --  configuration pragma file, this setting is harmless since the
11644             --  switch will get reset anyway at the start of each unit.
11645
11646             Optimize_Alignment_Local := True;
11647          end Optimize_Alignment;
11648
11649          -------------
11650          -- Ordered --
11651          -------------
11652
11653          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11654
11655          when Pragma_Ordered => Ordered : declare
11656             Assoc   : constant Node_Id := Arg1;
11657             Type_Id : Node_Id;
11658             Typ     : Entity_Id;
11659
11660          begin
11661             GNAT_Pragma;
11662             Check_No_Identifiers;
11663             Check_Arg_Count (1);
11664             Check_Arg_Is_Local_Name (Arg1);
11665
11666             Type_Id := Get_Pragma_Arg (Assoc);
11667             Find_Type (Type_Id);
11668             Typ := Entity (Type_Id);
11669
11670             if Typ = Any_Type then
11671                return;
11672             else
11673                Typ := Underlying_Type (Typ);
11674             end if;
11675
11676             if not Is_Enumeration_Type (Typ) then
11677                Error_Pragma ("pragma% must specify enumeration type");
11678             end if;
11679
11680             Check_First_Subtype (Arg1);
11681             Set_Has_Pragma_Ordered (Base_Type (Typ));
11682          end Ordered;
11683
11684          ----------
11685          -- Pack --
11686          ----------
11687
11688          --  pragma Pack (first_subtype_LOCAL_NAME);
11689
11690          when Pragma_Pack => Pack : declare
11691             Assoc   : constant Node_Id := Arg1;
11692             Type_Id : Node_Id;
11693             Typ     : Entity_Id;
11694             Ctyp    : Entity_Id;
11695             Ignore  : Boolean := False;
11696
11697          begin
11698             Check_No_Identifiers;
11699             Check_Arg_Count (1);
11700             Check_Arg_Is_Local_Name (Arg1);
11701
11702             Type_Id := Get_Pragma_Arg (Assoc);
11703             Find_Type (Type_Id);
11704             Typ := Entity (Type_Id);
11705
11706             if Typ = Any_Type
11707               or else Rep_Item_Too_Early (Typ, N)
11708             then
11709                return;
11710             else
11711                Typ := Underlying_Type (Typ);
11712             end if;
11713
11714             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11715                Error_Pragma ("pragma% must specify array or record type");
11716             end if;
11717
11718             Check_First_Subtype (Arg1);
11719             Check_Duplicate_Pragma (Typ);
11720
11721             --  Array type
11722
11723             if Is_Array_Type (Typ) then
11724                Ctyp := Component_Type (Typ);
11725
11726                --  Ignore pack that does nothing
11727
11728                if Known_Static_Esize (Ctyp)
11729                  and then Known_Static_RM_Size (Ctyp)
11730                  and then Esize (Ctyp) = RM_Size (Ctyp)
11731                  and then Addressable (Esize (Ctyp))
11732                then
11733                   Ignore := True;
11734                end if;
11735
11736                --  Process OK pragma Pack. Note that if there is a separate
11737                --  component clause present, the Pack will be cancelled. This
11738                --  processing is in Freeze.
11739
11740                if not Rep_Item_Too_Late (Typ, N) then
11741
11742                   --  In the context of static code analysis, we do not need
11743                   --  complex front-end expansions related to pragma Pack,
11744                   --  so disable handling of pragma Pack in these cases.
11745
11746                   if CodePeer_Mode or Alfa_Mode then
11747                      null;
11748
11749                   --  Don't attempt any packing for VM targets. We possibly
11750                   --  could deal with some cases of array bit-packing, but we
11751                   --  don't bother, since this is not a typical kind of
11752                   --  representation in the VM context anyway (and would not
11753                   --  for example work nicely with the debugger).
11754
11755                   elsif VM_Target /= No_VM then
11756                      if not GNAT_Mode then
11757                         Error_Pragma
11758                           ("?pragma% ignored in this configuration");
11759                      end if;
11760
11761                   --  Normal case where we do the pack action
11762
11763                   else
11764                      if not Ignore then
11765                         Set_Is_Packed            (Base_Type (Typ));
11766                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11767                      end if;
11768
11769                      Set_Has_Pragma_Pack (Base_Type (Typ));
11770                   end if;
11771                end if;
11772
11773             --  For record types, the pack is always effective
11774
11775             else pragma Assert (Is_Record_Type (Typ));
11776                if not Rep_Item_Too_Late (Typ, N) then
11777
11778                   --  Ignore pack request with warning in VM mode (skip warning
11779                   --  if we are compiling GNAT run time library).
11780
11781                   if VM_Target /= No_VM then
11782                      if not GNAT_Mode then
11783                         Error_Pragma
11784                           ("?pragma% ignored in this configuration");
11785                      end if;
11786
11787                   --  Normal case of pack request active
11788
11789                   else
11790                      Set_Is_Packed            (Base_Type (Typ));
11791                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11792                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11793                   end if;
11794                end if;
11795             end if;
11796          end Pack;
11797
11798          ----------
11799          -- Page --
11800          ----------
11801
11802          --  pragma Page;
11803
11804          --  There is nothing to do here, since we did all the processing for
11805          --  this pragma in Par.Prag (so that it works properly even in syntax
11806          --  only mode).
11807
11808          when Pragma_Page =>
11809             null;
11810
11811          -------------
11812          -- Passive --
11813          -------------
11814
11815          --  pragma Passive [(PASSIVE_FORM)];
11816
11817          --  PASSIVE_FORM ::= Semaphore | No
11818
11819          when Pragma_Passive =>
11820             GNAT_Pragma;
11821
11822             if Nkind (Parent (N)) /= N_Task_Definition then
11823                Error_Pragma ("pragma% must be within task definition");
11824             end if;
11825
11826             if Arg_Count /= 0 then
11827                Check_Arg_Count (1);
11828                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11829             end if;
11830
11831          ----------------------------------
11832          -- Preelaborable_Initialization --
11833          ----------------------------------
11834
11835          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11836
11837          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11838             Ent : Entity_Id;
11839
11840          begin
11841             Ada_2005_Pragma;
11842             Check_Arg_Count (1);
11843             Check_No_Identifiers;
11844             Check_Arg_Is_Identifier (Arg1);
11845             Check_Arg_Is_Local_Name (Arg1);
11846             Check_First_Subtype (Arg1);
11847             Ent := Entity (Get_Pragma_Arg (Arg1));
11848
11849             if not (Is_Private_Type (Ent)
11850                       or else
11851                     Is_Protected_Type (Ent)
11852                       or else
11853                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11854             then
11855                Error_Pragma_Arg
11856                  ("pragma % can only be applied to private, formal derived or "
11857                   & "protected type",
11858                   Arg1);
11859             end if;
11860
11861             --  Give an error if the pragma is applied to a protected type that
11862             --  does not qualify (due to having entries, or due to components
11863             --  that do not qualify).
11864
11865             if Is_Protected_Type (Ent)
11866               and then not Has_Preelaborable_Initialization (Ent)
11867             then
11868                Error_Msg_N
11869                  ("protected type & does not have preelaborable " &
11870                   "initialization", Ent);
11871
11872             --  Otherwise mark the type as definitely having preelaborable
11873             --  initialization.
11874
11875             else
11876                Set_Known_To_Have_Preelab_Init (Ent);
11877             end if;
11878
11879             if Has_Pragma_Preelab_Init (Ent)
11880               and then Warn_On_Redundant_Constructs
11881             then
11882                Error_Pragma ("?duplicate pragma%!");
11883             else
11884                Set_Has_Pragma_Preelab_Init (Ent);
11885             end if;
11886          end Preelab_Init;
11887
11888          --------------------
11889          -- Persistent_BSS --
11890          --------------------
11891
11892          --  pragma Persistent_BSS [(object_NAME)];
11893
11894          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11895             Decl : Node_Id;
11896             Ent  : Entity_Id;
11897             Prag : Node_Id;
11898
11899          begin
11900             GNAT_Pragma;
11901             Check_At_Most_N_Arguments (1);
11902
11903             --  Case of application to specific object (one argument)
11904
11905             if Arg_Count = 1 then
11906                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11907
11908                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11909                  or else not
11910                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11911                                                             E_Constant)
11912                then
11913                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11914                end if;
11915
11916                Ent := Entity (Get_Pragma_Arg (Arg1));
11917                Decl := Parent (Ent);
11918
11919                if Rep_Item_Too_Late (Ent, N) then
11920                   return;
11921                end if;
11922
11923                if Present (Expression (Decl)) then
11924                   Error_Pragma_Arg
11925                     ("object for pragma% cannot have initialization", Arg1);
11926                end if;
11927
11928                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11929                   Error_Pragma_Arg
11930                     ("object type for pragma% is not potentially persistent",
11931                      Arg1);
11932                end if;
11933
11934                Check_Duplicate_Pragma (Ent);
11935
11936                Prag :=
11937                  Make_Linker_Section_Pragma
11938                    (Ent, Sloc (N), ".persistent.bss");
11939                Insert_After (N, Prag);
11940                Analyze (Prag);
11941
11942             --  Case of use as configuration pragma with no arguments
11943
11944             else
11945                Check_Valid_Configuration_Pragma;
11946                Persistent_BSS_Mode := True;
11947             end if;
11948          end Persistent_BSS;
11949
11950          -------------
11951          -- Polling --
11952          -------------
11953
11954          --  pragma Polling (ON | OFF);
11955
11956          when Pragma_Polling =>
11957             GNAT_Pragma;
11958             Check_Arg_Count (1);
11959             Check_No_Identifiers;
11960             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11961             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11962
11963          -------------------
11964          -- Postcondition --
11965          -------------------
11966
11967          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11968          --                      [,[Message =>] String_EXPRESSION]);
11969
11970          when Pragma_Postcondition => Postcondition : declare
11971             In_Body : Boolean;
11972             pragma Warnings (Off, In_Body);
11973
11974          begin
11975             GNAT_Pragma;
11976             Check_At_Least_N_Arguments (1);
11977             Check_At_Most_N_Arguments (2);
11978             Check_Optional_Identifier (Arg1, Name_Check);
11979
11980             --  All we need to do here is call the common check procedure,
11981             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11982
11983             Check_Precondition_Postcondition (In_Body);
11984          end Postcondition;
11985
11986          ------------------
11987          -- Precondition --
11988          ------------------
11989
11990          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11991          --                     [,[Message =>] String_EXPRESSION]);
11992
11993          when Pragma_Precondition => Precondition : declare
11994             In_Body : Boolean;
11995
11996          begin
11997             GNAT_Pragma;
11998             Check_At_Least_N_Arguments (1);
11999             Check_At_Most_N_Arguments (2);
12000             Check_Optional_Identifier (Arg1, Name_Check);
12001             Check_Precondition_Postcondition (In_Body);
12002
12003             --  If in spec, nothing more to do. If in body, then we convert the
12004             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
12005             --  this whether or not precondition checks are enabled. That works
12006             --  fine since pragma Check will do this check, and will also
12007             --  analyze the condition itself in the proper context.
12008
12009             if In_Body then
12010                Rewrite (N,
12011                  Make_Pragma (Loc,
12012                    Chars => Name_Check,
12013                    Pragma_Argument_Associations => New_List (
12014                      Make_Pragma_Argument_Association (Loc,
12015                        Expression => Make_Identifier (Loc, Name_Precondition)),
12016
12017                      Make_Pragma_Argument_Association (Sloc (Arg1),
12018                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12019
12020                if Arg_Count = 2 then
12021                   Append_To (Pragma_Argument_Associations (N),
12022                     Make_Pragma_Argument_Association (Sloc (Arg2),
12023                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12024                end if;
12025
12026                Analyze (N);
12027             end if;
12028          end Precondition;
12029
12030          ---------------
12031          -- Predicate --
12032          ---------------
12033
12034          --  pragma Predicate
12035          --    ([Entity =>] type_LOCAL_NAME,
12036          --     [Check  =>] EXPRESSION);
12037
12038          when Pragma_Predicate => Predicate : declare
12039             Type_Id : Node_Id;
12040             Typ     : Entity_Id;
12041
12042             Discard : Boolean;
12043             pragma Unreferenced (Discard);
12044
12045          begin
12046             GNAT_Pragma;
12047             Check_Arg_Count (2);
12048             Check_Optional_Identifier (Arg1, Name_Entity);
12049             Check_Optional_Identifier (Arg2, Name_Check);
12050
12051             Check_Arg_Is_Local_Name (Arg1);
12052
12053             Type_Id := Get_Pragma_Arg (Arg1);
12054             Find_Type (Type_Id);
12055             Typ := Entity (Type_Id);
12056
12057             if Typ = Any_Type then
12058                return;
12059             end if;
12060
12061             --  The remaining processing is simply to link the pragma on to
12062             --  the rep item chain, for processing when the type is frozen.
12063             --  This is accomplished by a call to Rep_Item_Too_Late. We also
12064             --  mark the type as having predicates.
12065
12066             Set_Has_Predicates (Typ);
12067             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12068          end Predicate;
12069
12070          ------------------
12071          -- Preelaborate --
12072          ------------------
12073
12074          --  pragma Preelaborate [(library_unit_NAME)];
12075
12076          --  Set the flag Is_Preelaborated of program unit name entity
12077
12078          when Pragma_Preelaborate => Preelaborate : declare
12079             Pa  : constant Node_Id   := Parent (N);
12080             Pk  : constant Node_Kind := Nkind (Pa);
12081             Ent : Entity_Id;
12082
12083          begin
12084             Check_Ada_83_Warning;
12085             Check_Valid_Library_Unit_Pragma;
12086
12087             if Nkind (N) = N_Null_Statement then
12088                return;
12089             end if;
12090
12091             Ent := Find_Lib_Unit_Name;
12092             Check_Duplicate_Pragma (Ent);
12093
12094             --  This filters out pragmas inside generic parent then
12095             --  show up inside instantiation
12096
12097             if Present (Ent)
12098               and then not (Pk = N_Package_Specification
12099                              and then Present (Generic_Parent (Pa)))
12100             then
12101                if not Debug_Flag_U then
12102                   Set_Is_Preelaborated (Ent);
12103                   Set_Suppress_Elaboration_Warnings (Ent);
12104                end if;
12105             end if;
12106          end Preelaborate;
12107
12108          ---------------------
12109          -- Preelaborate_05 --
12110          ---------------------
12111
12112          --  pragma Preelaborate_05 [(library_unit_NAME)];
12113
12114          --  This pragma is useable only in GNAT_Mode, where it is used like
12115          --  pragma Preelaborate but it is only effective in Ada 2005 mode
12116          --  (otherwise it is ignored). This is used to implement AI-362 which
12117          --  recategorizes some run-time packages in Ada 2005 mode.
12118
12119          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12120             Ent : Entity_Id;
12121
12122          begin
12123             GNAT_Pragma;
12124             Check_Valid_Library_Unit_Pragma;
12125
12126             if not GNAT_Mode then
12127                Error_Pragma ("pragma% only available in GNAT mode");
12128             end if;
12129
12130             if Nkind (N) = N_Null_Statement then
12131                return;
12132             end if;
12133
12134             --  This is one of the few cases where we need to test the value of
12135             --  Ada_Version_Explicit rather than Ada_Version (which is always
12136             --  set to Ada_2012 in a predefined unit), we need to know the
12137             --  explicit version set to know if this pragma is active.
12138
12139             if Ada_Version_Explicit >= Ada_2005 then
12140                Ent := Find_Lib_Unit_Name;
12141                Set_Is_Preelaborated (Ent);
12142                Set_Suppress_Elaboration_Warnings (Ent);
12143             end if;
12144          end Preelaborate_05;
12145
12146          --------------
12147          -- Priority --
12148          --------------
12149
12150          --  pragma Priority (EXPRESSION);
12151
12152          when Pragma_Priority => Priority : declare
12153             P   : constant Node_Id := Parent (N);
12154             Arg : Node_Id;
12155
12156          begin
12157             Check_No_Identifiers;
12158             Check_Arg_Count (1);
12159
12160             --  Subprogram case
12161
12162             if Nkind (P) = N_Subprogram_Body then
12163                Check_In_Main_Program;
12164
12165                Arg := Get_Pragma_Arg (Arg1);
12166                Analyze_And_Resolve (Arg, Standard_Integer);
12167
12168                --  Must be static
12169
12170                if not Is_Static_Expression (Arg) then
12171                   Flag_Non_Static_Expr
12172                     ("main subprogram priority is not static!", Arg);
12173                   raise Pragma_Exit;
12174
12175                --  If constraint error, then we already signalled an error
12176
12177                elsif Raises_Constraint_Error (Arg) then
12178                   null;
12179
12180                --  Otherwise check in range
12181
12182                else
12183                   declare
12184                      Val : constant Uint := Expr_Value (Arg);
12185
12186                   begin
12187                      if Val < 0
12188                        or else Val > Expr_Value (Expression
12189                                        (Parent (RTE (RE_Max_Priority))))
12190                      then
12191                         Error_Pragma_Arg
12192                           ("main subprogram priority is out of range", Arg1);
12193                      end if;
12194                   end;
12195                end if;
12196
12197                Set_Main_Priority
12198                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12199
12200                --  Load an arbitrary entity from System.Tasking to make sure
12201                --  this package is implicitly with'ed, since we need to have
12202                --  the tasking run-time active for the pragma Priority to have
12203                --  any effect.
12204
12205                declare
12206                   Discard : Entity_Id;
12207                   pragma Warnings (Off, Discard);
12208                begin
12209                   Discard := RTE (RE_Task_List);
12210                end;
12211
12212             --  Task or Protected, must be of type Integer
12213
12214             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12215                Arg := Get_Pragma_Arg (Arg1);
12216
12217                --  The expression must be analyzed in the special manner
12218                --  described in "Handling of Default and Per-Object
12219                --  Expressions" in sem.ads.
12220
12221                Preanalyze_Spec_Expression (Arg, Standard_Integer);
12222
12223                if not Is_Static_Expression (Arg) then
12224                   Check_Restriction (Static_Priorities, Arg);
12225                end if;
12226
12227             --  Anything else is incorrect
12228
12229             else
12230                Pragma_Misplaced;
12231             end if;
12232
12233             if Has_Pragma_Priority (P) then
12234                Error_Pragma ("duplicate pragma% not allowed");
12235             else
12236                Set_Has_Pragma_Priority (P, True);
12237
12238                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12239                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12240                   --  exp_ch9 should use this ???
12241                end if;
12242             end if;
12243          end Priority;
12244
12245          -----------------------------------
12246          -- Priority_Specific_Dispatching --
12247          -----------------------------------
12248
12249          --  pragma Priority_Specific_Dispatching (
12250          --    policy_IDENTIFIER,
12251          --    first_priority_EXPRESSION,
12252          --    last_priority_EXPRESSION);
12253
12254          when Pragma_Priority_Specific_Dispatching =>
12255          Priority_Specific_Dispatching : declare
12256             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12257             --  This is the entity System.Any_Priority;
12258
12259             DP          : Character;
12260             Lower_Bound : Node_Id;
12261             Upper_Bound : Node_Id;
12262             Lower_Val   : Uint;
12263             Upper_Val   : Uint;
12264
12265          begin
12266             Ada_2005_Pragma;
12267             Check_Arg_Count (3);
12268             Check_No_Identifiers;
12269             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12270             Check_Valid_Configuration_Pragma;
12271             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12272             DP := Fold_Upper (Name_Buffer (1));
12273
12274             Lower_Bound := Get_Pragma_Arg (Arg2);
12275             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12276             Lower_Val := Expr_Value (Lower_Bound);
12277
12278             Upper_Bound := Get_Pragma_Arg (Arg3);
12279             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12280             Upper_Val := Expr_Value (Upper_Bound);
12281
12282             --  It is not allowed to use Task_Dispatching_Policy and
12283             --  Priority_Specific_Dispatching in the same partition.
12284
12285             if Task_Dispatching_Policy /= ' ' then
12286                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12287                Error_Pragma
12288                  ("pragma% incompatible with Task_Dispatching_Policy#");
12289
12290             --  Check lower bound in range
12291
12292             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12293                     or else
12294                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12295             then
12296                Error_Pragma_Arg
12297                  ("first_priority is out of range", Arg2);
12298
12299             --  Check upper bound in range
12300
12301             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12302                     or else
12303                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12304             then
12305                Error_Pragma_Arg
12306                  ("last_priority is out of range", Arg3);
12307
12308             --  Check that the priority range is valid
12309
12310             elsif Lower_Val > Upper_Val then
12311                Error_Pragma
12312                  ("last_priority_expression must be greater than" &
12313                   " or equal to first_priority_expression");
12314
12315             --  Store the new policy, but always preserve System_Location since
12316             --  we like the error message with the run-time name.
12317
12318             else
12319                --  Check overlapping in the priority ranges specified in other
12320                --  Priority_Specific_Dispatching pragmas within the same
12321                --  partition. We can only check those we know about!
12322
12323                for J in
12324                   Specific_Dispatching.First .. Specific_Dispatching.Last
12325                loop
12326                   if Specific_Dispatching.Table (J).First_Priority in
12327                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12328                   or else Specific_Dispatching.Table (J).Last_Priority in
12329                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12330                   then
12331                      Error_Msg_Sloc :=
12332                        Specific_Dispatching.Table (J).Pragma_Loc;
12333                         Error_Pragma
12334                           ("priority range overlaps with "
12335                            & "Priority_Specific_Dispatching#");
12336                   end if;
12337                end loop;
12338
12339                --  The use of Priority_Specific_Dispatching is incompatible
12340                --  with Task_Dispatching_Policy.
12341
12342                if Task_Dispatching_Policy /= ' ' then
12343                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12344                      Error_Pragma
12345                        ("Priority_Specific_Dispatching incompatible "
12346                         & "with Task_Dispatching_Policy#");
12347                end if;
12348
12349                --  The use of Priority_Specific_Dispatching forces ceiling
12350                --  locking policy.
12351
12352                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12353                   Error_Msg_Sloc := Locking_Policy_Sloc;
12354                      Error_Pragma
12355                        ("Priority_Specific_Dispatching incompatible "
12356                         & "with Locking_Policy#");
12357
12358                --  Set the Ceiling_Locking policy, but preserve System_Location
12359                --  since we like the error message with the run time name.
12360
12361                else
12362                   Locking_Policy := 'C';
12363
12364                   if Locking_Policy_Sloc /= System_Location then
12365                      Locking_Policy_Sloc := Loc;
12366                   end if;
12367                end if;
12368
12369                --  Add entry in the table
12370
12371                Specific_Dispatching.Append
12372                     ((Dispatching_Policy => DP,
12373                       First_Priority     => UI_To_Int (Lower_Val),
12374                       Last_Priority      => UI_To_Int (Upper_Val),
12375                       Pragma_Loc         => Loc));
12376             end if;
12377          end Priority_Specific_Dispatching;
12378
12379          -------------
12380          -- Profile --
12381          -------------
12382
12383          --  pragma Profile (profile_IDENTIFIER);
12384
12385          --  profile_IDENTIFIER => Restricted | Ravenscar
12386
12387          when Pragma_Profile =>
12388             Ada_2005_Pragma;
12389             Check_Arg_Count (1);
12390             Check_Valid_Configuration_Pragma;
12391             Check_No_Identifiers;
12392
12393             declare
12394                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12395
12396             begin
12397                if Chars (Argx) = Name_Ravenscar then
12398                   Set_Ravenscar_Profile (N);
12399
12400                elsif Chars (Argx) = Name_Restricted then
12401                   Set_Profile_Restrictions
12402                     (Restricted,
12403                      N, Warn => Treat_Restrictions_As_Warnings);
12404
12405                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12406                   Set_Profile_Restrictions
12407                     (No_Implementation_Extensions,
12408                      N, Warn => Treat_Restrictions_As_Warnings);
12409
12410                else
12411                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12412                end if;
12413             end;
12414
12415          ----------------------
12416          -- Profile_Warnings --
12417          ----------------------
12418
12419          --  pragma Profile_Warnings (profile_IDENTIFIER);
12420
12421          --  profile_IDENTIFIER => Restricted | Ravenscar
12422
12423          when Pragma_Profile_Warnings =>
12424             GNAT_Pragma;
12425             Check_Arg_Count (1);
12426             Check_Valid_Configuration_Pragma;
12427             Check_No_Identifiers;
12428
12429             declare
12430                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12431
12432             begin
12433                if Chars (Argx) = Name_Ravenscar then
12434                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12435
12436                elsif Chars (Argx) = Name_Restricted then
12437                   Set_Profile_Restrictions (Restricted, N, Warn => True);
12438
12439                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12440                   Set_Profile_Restrictions
12441                     (No_Implementation_Extensions, N, Warn => True);
12442
12443                else
12444                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12445                end if;
12446             end;
12447
12448          --------------------------
12449          -- Propagate_Exceptions --
12450          --------------------------
12451
12452          --  pragma Propagate_Exceptions;
12453
12454          --  Note: this pragma is obsolete and has no effect
12455
12456          when Pragma_Propagate_Exceptions =>
12457             GNAT_Pragma;
12458             Check_Arg_Count (0);
12459
12460             if In_Extended_Main_Source_Unit (N) then
12461                Propagate_Exceptions := True;
12462             end if;
12463
12464          ------------------
12465          -- Psect_Object --
12466          ------------------
12467
12468          --  pragma Psect_Object (
12469          --        [Internal =>] LOCAL_NAME,
12470          --     [, [External =>] EXTERNAL_SYMBOL]
12471          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12472
12473          when Pragma_Psect_Object | Pragma_Common_Object =>
12474          Psect_Object : declare
12475             Args  : Args_List (1 .. 3);
12476             Names : constant Name_List (1 .. 3) := (
12477                       Name_Internal,
12478                       Name_External,
12479                       Name_Size);
12480
12481             Internal : Node_Id renames Args (1);
12482             External : Node_Id renames Args (2);
12483             Size     : Node_Id renames Args (3);
12484
12485             Def_Id : Entity_Id;
12486
12487             procedure Check_Too_Long (Arg : Node_Id);
12488             --  Posts message if the argument is an identifier with more
12489             --  than 31 characters, or a string literal with more than
12490             --  31 characters, and we are operating under VMS
12491
12492             --------------------
12493             -- Check_Too_Long --
12494             --------------------
12495
12496             procedure Check_Too_Long (Arg : Node_Id) is
12497                X : constant Node_Id := Original_Node (Arg);
12498
12499             begin
12500                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12501                   Error_Pragma_Arg
12502                     ("inappropriate argument for pragma %", Arg);
12503                end if;
12504
12505                if OpenVMS_On_Target then
12506                   if (Nkind (X) = N_String_Literal
12507                        and then String_Length (Strval (X)) > 31)
12508                     or else
12509                      (Nkind (X) = N_Identifier
12510                        and then Length_Of_Name (Chars (X)) > 31)
12511                   then
12512                      Error_Pragma_Arg
12513                        ("argument for pragma % is longer than 31 characters",
12514                         Arg);
12515                   end if;
12516                end if;
12517             end Check_Too_Long;
12518
12519          --  Start of processing for Common_Object/Psect_Object
12520
12521          begin
12522             GNAT_Pragma;
12523             Gather_Associations (Names, Args);
12524             Process_Extended_Import_Export_Internal_Arg (Internal);
12525
12526             Def_Id := Entity (Internal);
12527
12528             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12529                Error_Pragma_Arg
12530                  ("pragma% must designate an object", Internal);
12531             end if;
12532
12533             Check_Too_Long (Internal);
12534
12535             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12536                Error_Pragma_Arg
12537                  ("cannot use pragma% for imported/exported object",
12538                   Internal);
12539             end if;
12540
12541             if Is_Concurrent_Type (Etype (Internal)) then
12542                Error_Pragma_Arg
12543                  ("cannot specify pragma % for task/protected object",
12544                   Internal);
12545             end if;
12546
12547             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12548                  or else
12549                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12550             then
12551                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12552             end if;
12553
12554             if Ekind (Def_Id) = E_Constant then
12555                Error_Pragma_Arg
12556                  ("cannot specify pragma % for a constant", Internal);
12557             end if;
12558
12559             if Is_Record_Type (Etype (Internal)) then
12560                declare
12561                   Ent  : Entity_Id;
12562                   Decl : Entity_Id;
12563
12564                begin
12565                   Ent := First_Entity (Etype (Internal));
12566                   while Present (Ent) loop
12567                      Decl := Declaration_Node (Ent);
12568
12569                      if Ekind (Ent) = E_Component
12570                        and then Nkind (Decl) = N_Component_Declaration
12571                        and then Present (Expression (Decl))
12572                        and then Warn_On_Export_Import
12573                      then
12574                         Error_Msg_N
12575                           ("?object for pragma % has defaults", Internal);
12576                         exit;
12577
12578                      else
12579                         Next_Entity (Ent);
12580                      end if;
12581                   end loop;
12582                end;
12583             end if;
12584
12585             if Present (Size) then
12586                Check_Too_Long (Size);
12587             end if;
12588
12589             if Present (External) then
12590                Check_Arg_Is_External_Name (External);
12591                Check_Too_Long (External);
12592             end if;
12593
12594             --  If all error tests pass, link pragma on to the rep item chain
12595
12596             Record_Rep_Item (Def_Id, N);
12597          end Psect_Object;
12598
12599          ----------
12600          -- Pure --
12601          ----------
12602
12603          --  pragma Pure [(library_unit_NAME)];
12604
12605          when Pragma_Pure => Pure : declare
12606             Ent : Entity_Id;
12607
12608          begin
12609             Check_Ada_83_Warning;
12610             Check_Valid_Library_Unit_Pragma;
12611
12612             if Nkind (N) = N_Null_Statement then
12613                return;
12614             end if;
12615
12616             Ent := Find_Lib_Unit_Name;
12617             Set_Is_Pure (Ent);
12618             Set_Has_Pragma_Pure (Ent);
12619             Set_Suppress_Elaboration_Warnings (Ent);
12620          end Pure;
12621
12622          -------------
12623          -- Pure_05 --
12624          -------------
12625
12626          --  pragma Pure_05 [(library_unit_NAME)];
12627
12628          --  This pragma is useable only in GNAT_Mode, where it is used like
12629          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12630          --  it is ignored). It may be used after a pragma Preelaborate, in
12631          --  which case it overrides the effect of the pragma Preelaborate.
12632          --  This is used to implement AI-362 which recategorizes some run-time
12633          --  packages in Ada 2005 mode.
12634
12635          when Pragma_Pure_05 => Pure_05 : declare
12636             Ent : Entity_Id;
12637
12638          begin
12639             GNAT_Pragma;
12640             Check_Valid_Library_Unit_Pragma;
12641
12642             if not GNAT_Mode then
12643                Error_Pragma ("pragma% only available in GNAT mode");
12644             end if;
12645
12646             if Nkind (N) = N_Null_Statement then
12647                return;
12648             end if;
12649
12650             --  This is one of the few cases where we need to test the value of
12651             --  Ada_Version_Explicit rather than Ada_Version (which is always
12652             --  set to Ada_2012 in a predefined unit), we need to know the
12653             --  explicit version set to know if this pragma is active.
12654
12655             if Ada_Version_Explicit >= Ada_2005 then
12656                Ent := Find_Lib_Unit_Name;
12657                Set_Is_Preelaborated (Ent, False);
12658                Set_Is_Pure (Ent);
12659                Set_Suppress_Elaboration_Warnings (Ent);
12660             end if;
12661          end Pure_05;
12662
12663          -------------
12664          -- Pure_12 --
12665          -------------
12666
12667          --  pragma Pure_12 [(library_unit_NAME)];
12668
12669          --  This pragma is useable only in GNAT_Mode, where it is used like
12670          --  pragma Pure but it is only effective in Ada 2012 mode (otherwise
12671          --  it is ignored). It may be used after a pragma Preelaborate, in
12672          --  which case it overrides the effect of the pragma Preelaborate.
12673          --  This is used to implement AI05-0212 which recategorizes some
12674          --  run-time packages in Ada 2012 mode.
12675
12676          when Pragma_Pure_12 => Pure_12 : declare
12677             Ent : Entity_Id;
12678
12679          begin
12680             GNAT_Pragma;
12681             Check_Valid_Library_Unit_Pragma;
12682
12683             if not GNAT_Mode then
12684                Error_Pragma ("pragma% only available in GNAT mode");
12685             end if;
12686
12687             if Nkind (N) = N_Null_Statement then
12688                return;
12689             end if;
12690
12691             --  This is one of the few cases where we need to test the value of
12692             --  Ada_Version_Explicit rather than Ada_Version (which is always
12693             --  set to Ada_2012 in a predefined unit), we need to know the
12694             --  explicit version set to know if this pragma is active.
12695
12696             if Ada_Version_Explicit >= Ada_2012 then
12697                Ent := Find_Lib_Unit_Name;
12698                Set_Is_Preelaborated (Ent, False);
12699                Set_Is_Pure (Ent);
12700                Set_Suppress_Elaboration_Warnings (Ent);
12701             end if;
12702          end Pure_12;
12703
12704          -------------------
12705          -- Pure_Function --
12706          -------------------
12707
12708          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12709
12710          when Pragma_Pure_Function => Pure_Function : declare
12711             E_Id      : Node_Id;
12712             E         : Entity_Id;
12713             Def_Id    : Entity_Id;
12714             Effective : Boolean := False;
12715
12716          begin
12717             GNAT_Pragma;
12718             Check_Arg_Count (1);
12719             Check_Optional_Identifier (Arg1, Name_Entity);
12720             Check_Arg_Is_Local_Name (Arg1);
12721             E_Id := Get_Pragma_Arg (Arg1);
12722
12723             if Error_Posted (E_Id) then
12724                return;
12725             end if;
12726
12727             --  Loop through homonyms (overloadings) of referenced entity
12728
12729             E := Entity (E_Id);
12730
12731             if Present (E) then
12732                loop
12733                   Def_Id := Get_Base_Subprogram (E);
12734
12735                   if not Ekind_In (Def_Id, E_Function,
12736                                            E_Generic_Function,
12737                                            E_Operator)
12738                   then
12739                      Error_Pragma_Arg
12740                        ("pragma% requires a function name", Arg1);
12741                   end if;
12742
12743                   Set_Is_Pure (Def_Id);
12744
12745                   if not Has_Pragma_Pure_Function (Def_Id) then
12746                      Set_Has_Pragma_Pure_Function (Def_Id);
12747                      Effective := True;
12748                   end if;
12749
12750                   exit when From_Aspect_Specification (N);
12751                   E := Homonym (E);
12752                   exit when No (E) or else Scope (E) /= Current_Scope;
12753                end loop;
12754
12755                if not Effective
12756                  and then Warn_On_Redundant_Constructs
12757                then
12758                   Error_Msg_NE
12759                     ("pragma Pure_Function on& is redundant?",
12760                      N, Entity (E_Id));
12761                end if;
12762             end if;
12763          end Pure_Function;
12764
12765          --------------------
12766          -- Queuing_Policy --
12767          --------------------
12768
12769          --  pragma Queuing_Policy (policy_IDENTIFIER);
12770
12771          when Pragma_Queuing_Policy => declare
12772             QP : Character;
12773
12774          begin
12775             Check_Ada_83_Warning;
12776             Check_Arg_Count (1);
12777             Check_No_Identifiers;
12778             Check_Arg_Is_Queuing_Policy (Arg1);
12779             Check_Valid_Configuration_Pragma;
12780             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12781             QP := Fold_Upper (Name_Buffer (1));
12782
12783             if Queuing_Policy /= ' '
12784               and then Queuing_Policy /= QP
12785             then
12786                Error_Msg_Sloc := Queuing_Policy_Sloc;
12787                Error_Pragma ("queuing policy incompatible with policy#");
12788
12789             --  Set new policy, but always preserve System_Location since we
12790             --  like the error message with the run time name.
12791
12792             else
12793                Queuing_Policy := QP;
12794
12795                if Queuing_Policy_Sloc /= System_Location then
12796                   Queuing_Policy_Sloc := Loc;
12797                end if;
12798             end if;
12799          end;
12800
12801          -----------------------
12802          -- Relative_Deadline --
12803          -----------------------
12804
12805          --  pragma Relative_Deadline (time_span_EXPRESSION);
12806
12807          when Pragma_Relative_Deadline => Relative_Deadline : declare
12808             P   : constant Node_Id := Parent (N);
12809             Arg : Node_Id;
12810
12811          begin
12812             Ada_2005_Pragma;
12813             Check_No_Identifiers;
12814             Check_Arg_Count (1);
12815
12816             Arg := Get_Pragma_Arg (Arg1);
12817
12818             --  The expression must be analyzed in the special manner described
12819             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12820
12821             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12822
12823             --  Subprogram case
12824
12825             if Nkind (P) = N_Subprogram_Body then
12826                Check_In_Main_Program;
12827
12828             --  Tasks
12829
12830             elsif Nkind (P) = N_Task_Definition then
12831                null;
12832
12833             --  Anything else is incorrect
12834
12835             else
12836                Pragma_Misplaced;
12837             end if;
12838
12839             if Has_Relative_Deadline_Pragma (P) then
12840                Error_Pragma ("duplicate pragma% not allowed");
12841             else
12842                Set_Has_Relative_Deadline_Pragma (P, True);
12843
12844                if Nkind (P) = N_Task_Definition then
12845                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12846                end if;
12847             end if;
12848          end Relative_Deadline;
12849
12850          ---------------------------
12851          -- Remote_Call_Interface --
12852          ---------------------------
12853
12854          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12855
12856          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12857             Cunit_Node : Node_Id;
12858             Cunit_Ent  : Entity_Id;
12859             K          : Node_Kind;
12860
12861          begin
12862             Check_Ada_83_Warning;
12863             Check_Valid_Library_Unit_Pragma;
12864
12865             if Nkind (N) = N_Null_Statement then
12866                return;
12867             end if;
12868
12869             Cunit_Node := Cunit (Current_Sem_Unit);
12870             K          := Nkind (Unit (Cunit_Node));
12871             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12872
12873             if K = N_Package_Declaration
12874               or else K = N_Generic_Package_Declaration
12875               or else K = N_Subprogram_Declaration
12876               or else K = N_Generic_Subprogram_Declaration
12877               or else (K = N_Subprogram_Body
12878                          and then Acts_As_Spec (Unit (Cunit_Node)))
12879             then
12880                null;
12881             else
12882                Error_Pragma (
12883                  "pragma% must apply to package or subprogram declaration");
12884             end if;
12885
12886             Set_Is_Remote_Call_Interface (Cunit_Ent);
12887          end Remote_Call_Interface;
12888
12889          ------------------
12890          -- Remote_Types --
12891          ------------------
12892
12893          --  pragma Remote_Types [(library_unit_NAME)];
12894
12895          when Pragma_Remote_Types => Remote_Types : declare
12896             Cunit_Node : Node_Id;
12897             Cunit_Ent  : Entity_Id;
12898
12899          begin
12900             Check_Ada_83_Warning;
12901             Check_Valid_Library_Unit_Pragma;
12902
12903             if Nkind (N) = N_Null_Statement then
12904                return;
12905             end if;
12906
12907             Cunit_Node := Cunit (Current_Sem_Unit);
12908             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12909
12910             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12911                                                 N_Generic_Package_Declaration)
12912             then
12913                Error_Pragma
12914                  ("pragma% can only apply to a package declaration");
12915             end if;
12916
12917             Set_Is_Remote_Types (Cunit_Ent);
12918          end Remote_Types;
12919
12920          ---------------
12921          -- Ravenscar --
12922          ---------------
12923
12924          --  pragma Ravenscar;
12925
12926          when Pragma_Ravenscar =>
12927             GNAT_Pragma;
12928             Check_Arg_Count (0);
12929             Check_Valid_Configuration_Pragma;
12930             Set_Ravenscar_Profile (N);
12931
12932             if Warn_On_Obsolescent_Feature then
12933                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12934                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12935             end if;
12936
12937          -------------------------
12938          -- Restricted_Run_Time --
12939          -------------------------
12940
12941          --  pragma Restricted_Run_Time;
12942
12943          when Pragma_Restricted_Run_Time =>
12944             GNAT_Pragma;
12945             Check_Arg_Count (0);
12946             Check_Valid_Configuration_Pragma;
12947             Set_Profile_Restrictions
12948               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12949
12950             if Warn_On_Obsolescent_Feature then
12951                Error_Msg_N
12952                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12953                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12954             end if;
12955
12956          ------------------
12957          -- Restrictions --
12958          ------------------
12959
12960          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12961
12962          --  RESTRICTION ::=
12963          --    restriction_IDENTIFIER
12964          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12965
12966          when Pragma_Restrictions =>
12967             Process_Restrictions_Or_Restriction_Warnings
12968               (Warn => Treat_Restrictions_As_Warnings);
12969
12970          --------------------------
12971          -- Restriction_Warnings --
12972          --------------------------
12973
12974          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12975
12976          --  RESTRICTION ::=
12977          --    restriction_IDENTIFIER
12978          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12979
12980          when Pragma_Restriction_Warnings =>
12981             GNAT_Pragma;
12982             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12983
12984          ----------------
12985          -- Reviewable --
12986          ----------------
12987
12988          --  pragma Reviewable;
12989
12990          when Pragma_Reviewable =>
12991             Check_Ada_83_Warning;
12992             Check_Arg_Count (0);
12993
12994             --  Call dummy debugging function rv. This is done to assist front
12995             --  end debugging. By placing a Reviewable pragma in the source
12996             --  program, a breakpoint on rv catches this place in the source,
12997             --  allowing convenient stepping to the point of interest.
12998
12999             rv;
13000
13001          --------------------------
13002          -- Short_Circuit_And_Or --
13003          --------------------------
13004
13005          when Pragma_Short_Circuit_And_Or =>
13006             GNAT_Pragma;
13007             Check_Arg_Count (0);
13008             Check_Valid_Configuration_Pragma;
13009             Short_Circuit_And_Or := True;
13010
13011          -------------------
13012          -- Share_Generic --
13013          -------------------
13014
13015          --  pragma Share_Generic (NAME {, NAME});
13016
13017          when Pragma_Share_Generic =>
13018             GNAT_Pragma;
13019             Process_Generic_List;
13020
13021          ------------
13022          -- Shared --
13023          ------------
13024
13025          --  pragma Shared (LOCAL_NAME);
13026
13027          when Pragma_Shared =>
13028             GNAT_Pragma;
13029             Process_Atomic_Shared_Volatile;
13030
13031          --------------------
13032          -- Shared_Passive --
13033          --------------------
13034
13035          --  pragma Shared_Passive [(library_unit_NAME)];
13036
13037          --  Set the flag Is_Shared_Passive of program unit name entity
13038
13039          when Pragma_Shared_Passive => Shared_Passive : declare
13040             Cunit_Node : Node_Id;
13041             Cunit_Ent  : Entity_Id;
13042
13043          begin
13044             Check_Ada_83_Warning;
13045             Check_Valid_Library_Unit_Pragma;
13046
13047             if Nkind (N) = N_Null_Statement then
13048                return;
13049             end if;
13050
13051             Cunit_Node := Cunit (Current_Sem_Unit);
13052             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
13053
13054             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13055                                                 N_Generic_Package_Declaration)
13056             then
13057                Error_Pragma
13058                  ("pragma% can only apply to a package declaration");
13059             end if;
13060
13061             Set_Is_Shared_Passive (Cunit_Ent);
13062          end Shared_Passive;
13063
13064          -----------------------
13065          -- Short_Descriptors --
13066          -----------------------
13067
13068          --  pragma Short_Descriptors;
13069
13070          when Pragma_Short_Descriptors =>
13071             GNAT_Pragma;
13072             Check_Arg_Count (0);
13073             Check_Valid_Configuration_Pragma;
13074             Short_Descriptors := True;
13075
13076          ----------------------
13077          -- Source_File_Name --
13078          ----------------------
13079
13080          --  There are five forms for this pragma:
13081
13082          --  pragma Source_File_Name (
13083          --    [UNIT_NAME      =>] unit_NAME,
13084          --     BODY_FILE_NAME =>  STRING_LITERAL
13085          --    [, [INDEX =>] INTEGER_LITERAL]);
13086
13087          --  pragma Source_File_Name (
13088          --    [UNIT_NAME      =>] unit_NAME,
13089          --     SPEC_FILE_NAME =>  STRING_LITERAL
13090          --    [, [INDEX =>] INTEGER_LITERAL]);
13091
13092          --  pragma Source_File_Name (
13093          --     BODY_FILE_NAME  => STRING_LITERAL
13094          --  [, DOT_REPLACEMENT => STRING_LITERAL]
13095          --  [, CASING          => CASING_SPEC]);
13096
13097          --  pragma Source_File_Name (
13098          --     SPEC_FILE_NAME  => STRING_LITERAL
13099          --  [, DOT_REPLACEMENT => STRING_LITERAL]
13100          --  [, CASING          => CASING_SPEC]);
13101
13102          --  pragma Source_File_Name (
13103          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
13104          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
13105          --  [, CASING             => CASING_SPEC]);
13106
13107          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13108
13109          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13110          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
13111          --  only be used when no project file is used, while SFNP can only be
13112          --  used when a project file is used.
13113
13114          --  No processing here. Processing was completed during parsing, since
13115          --  we need to have file names set as early as possible. Units are
13116          --  loaded well before semantic processing starts.
13117
13118          --  The only processing we defer to this point is the check for
13119          --  correct placement.
13120
13121          when Pragma_Source_File_Name =>
13122             GNAT_Pragma;
13123             Check_Valid_Configuration_Pragma;
13124
13125          ------------------------------
13126          -- Source_File_Name_Project --
13127          ------------------------------
13128
13129          --  See Source_File_Name for syntax
13130
13131          --  No processing here. Processing was completed during parsing, since
13132          --  we need to have file names set as early as possible. Units are
13133          --  loaded well before semantic processing starts.
13134
13135          --  The only processing we defer to this point is the check for
13136          --  correct placement.
13137
13138          when Pragma_Source_File_Name_Project =>
13139             GNAT_Pragma;
13140             Check_Valid_Configuration_Pragma;
13141
13142             --  Check that a pragma Source_File_Name_Project is used only in a
13143             --  configuration pragmas file.
13144
13145             --  Pragmas Source_File_Name_Project should only be generated by
13146             --  the Project Manager in configuration pragmas files.
13147
13148             --  This is really an ugly test. It seems to depend on some
13149             --  accidental and undocumented property. At the very least it
13150             --  needs to be documented, but it would be better to have a
13151             --  clean way of testing if we are in a configuration file???
13152
13153             if Present (Parent (N)) then
13154                Error_Pragma
13155                  ("pragma% can only appear in a configuration pragmas file");
13156             end if;
13157
13158          ----------------------
13159          -- Source_Reference --
13160          ----------------------
13161
13162          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13163
13164          --  Nothing to do, all processing completed in Par.Prag, since we need
13165          --  the information for possible parser messages that are output.
13166
13167          when Pragma_Source_Reference =>
13168             GNAT_Pragma;
13169
13170          --------------------------------
13171          -- Static_Elaboration_Desired --
13172          --------------------------------
13173
13174          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
13175
13176          when Pragma_Static_Elaboration_Desired =>
13177             GNAT_Pragma;
13178             Check_At_Most_N_Arguments (1);
13179
13180             if Is_Compilation_Unit (Current_Scope)
13181               and then Ekind (Current_Scope) = E_Package
13182             then
13183                Set_Static_Elaboration_Desired (Current_Scope, True);
13184             else
13185                Error_Pragma ("pragma% must apply to a library-level package");
13186             end if;
13187
13188          ------------------
13189          -- Storage_Size --
13190          ------------------
13191
13192          --  pragma Storage_Size (EXPRESSION);
13193
13194          when Pragma_Storage_Size => Storage_Size : declare
13195             P   : constant Node_Id := Parent (N);
13196             Arg : Node_Id;
13197
13198          begin
13199             Check_No_Identifiers;
13200             Check_Arg_Count (1);
13201
13202             --  The expression must be analyzed in the special manner described
13203             --  in "Handling of Default Expressions" in sem.ads.
13204
13205             Arg := Get_Pragma_Arg (Arg1);
13206             Preanalyze_Spec_Expression (Arg, Any_Integer);
13207
13208             if not Is_Static_Expression (Arg) then
13209                Check_Restriction (Static_Storage_Size, Arg);
13210             end if;
13211
13212             if Nkind (P) /= N_Task_Definition then
13213                Pragma_Misplaced;
13214                return;
13215
13216             else
13217                if Has_Storage_Size_Pragma (P) then
13218                   Error_Pragma ("duplicate pragma% not allowed");
13219                else
13220                   Set_Has_Storage_Size_Pragma (P, True);
13221                end if;
13222
13223                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13224                --  ???  exp_ch9 should use this!
13225             end if;
13226          end Storage_Size;
13227
13228          ------------------
13229          -- Storage_Unit --
13230          ------------------
13231
13232          --  pragma Storage_Unit (NUMERIC_LITERAL);
13233
13234          --  Only permitted argument is System'Storage_Unit value
13235
13236          when Pragma_Storage_Unit =>
13237             Check_No_Identifiers;
13238             Check_Arg_Count (1);
13239             Check_Arg_Is_Integer_Literal (Arg1);
13240
13241             if Intval (Get_Pragma_Arg (Arg1)) /=
13242               UI_From_Int (Ttypes.System_Storage_Unit)
13243             then
13244                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13245                Error_Pragma_Arg
13246                  ("the only allowed argument for pragma% is ^", Arg1);
13247             end if;
13248
13249          --------------------
13250          -- Stream_Convert --
13251          --------------------
13252
13253          --  pragma Stream_Convert (
13254          --    [Entity =>] type_LOCAL_NAME,
13255          --    [Read   =>] function_NAME,
13256          --    [Write  =>] function NAME);
13257
13258          when Pragma_Stream_Convert => Stream_Convert : declare
13259
13260             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13261             --  Check that the given argument is the name of a local function
13262             --  of one argument that is not overloaded earlier in the current
13263             --  local scope. A check is also made that the argument is a
13264             --  function with one parameter.
13265
13266             --------------------------------------
13267             -- Check_OK_Stream_Convert_Function --
13268             --------------------------------------
13269
13270             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13271                Ent : Entity_Id;
13272
13273             begin
13274                Check_Arg_Is_Local_Name (Arg);
13275                Ent := Entity (Get_Pragma_Arg (Arg));
13276
13277                if Has_Homonym (Ent) then
13278                   Error_Pragma_Arg
13279                     ("argument for pragma% may not be overloaded", Arg);
13280                end if;
13281
13282                if Ekind (Ent) /= E_Function
13283                  or else No (First_Formal (Ent))
13284                  or else Present (Next_Formal (First_Formal (Ent)))
13285                then
13286                   Error_Pragma_Arg
13287                     ("argument for pragma% must be" &
13288                      " function of one argument", Arg);
13289                end if;
13290             end Check_OK_Stream_Convert_Function;
13291
13292          --  Start of processing for Stream_Convert
13293
13294          begin
13295             GNAT_Pragma;
13296             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13297             Check_Arg_Count (3);
13298             Check_Optional_Identifier (Arg1, Name_Entity);
13299             Check_Optional_Identifier (Arg2, Name_Read);
13300             Check_Optional_Identifier (Arg3, Name_Write);
13301             Check_Arg_Is_Local_Name (Arg1);
13302             Check_OK_Stream_Convert_Function (Arg2);
13303             Check_OK_Stream_Convert_Function (Arg3);
13304
13305             declare
13306                Typ   : constant Entity_Id :=
13307                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13308                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13309                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13310
13311             begin
13312                Check_First_Subtype (Arg1);
13313
13314                --  Check for too early or too late. Note that we don't enforce
13315                --  the rule about primitive operations in this case, since, as
13316                --  is the case for explicit stream attributes themselves, these
13317                --  restrictions are not appropriate. Note that the chaining of
13318                --  the pragma by Rep_Item_Too_Late is actually the critical
13319                --  processing done for this pragma.
13320
13321                if Rep_Item_Too_Early (Typ, N)
13322                     or else
13323                   Rep_Item_Too_Late (Typ, N, FOnly => True)
13324                then
13325                   return;
13326                end if;
13327
13328                --  Return if previous error
13329
13330                if Etype (Typ) = Any_Type
13331                     or else
13332                   Etype (Read) = Any_Type
13333                     or else
13334                   Etype (Write) = Any_Type
13335                then
13336                   return;
13337                end if;
13338
13339                --  Error checks
13340
13341                if Underlying_Type (Etype (Read)) /= Typ then
13342                   Error_Pragma_Arg
13343                     ("incorrect return type for function&", Arg2);
13344                end if;
13345
13346                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13347                   Error_Pragma_Arg
13348                     ("incorrect parameter type for function&", Arg3);
13349                end if;
13350
13351                if Underlying_Type (Etype (First_Formal (Read))) /=
13352                   Underlying_Type (Etype (Write))
13353                then
13354                   Error_Pragma_Arg
13355                     ("result type of & does not match Read parameter type",
13356                      Arg3);
13357                end if;
13358             end;
13359          end Stream_Convert;
13360
13361          -------------------------
13362          -- Style_Checks (GNAT) --
13363          -------------------------
13364
13365          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13366
13367          --  This is processed by the parser since some of the style checks
13368          --  take place during source scanning and parsing. This means that
13369          --  we don't need to issue error messages here.
13370
13371          when Pragma_Style_Checks => Style_Checks : declare
13372             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13373             S  : String_Id;
13374             C  : Char_Code;
13375
13376          begin
13377             GNAT_Pragma;
13378             Check_No_Identifiers;
13379
13380             --  Two argument form
13381
13382             if Arg_Count = 2 then
13383                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13384
13385                declare
13386                   E_Id : Node_Id;
13387                   E    : Entity_Id;
13388
13389                begin
13390                   E_Id := Get_Pragma_Arg (Arg2);
13391                   Analyze (E_Id);
13392
13393                   if not Is_Entity_Name (E_Id) then
13394                      Error_Pragma_Arg
13395                        ("second argument of pragma% must be entity name",
13396                         Arg2);
13397                   end if;
13398
13399                   E := Entity (E_Id);
13400
13401                   if E = Any_Id then
13402                      return;
13403                   else
13404                      loop
13405                         Set_Suppress_Style_Checks (E,
13406                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13407                         exit when No (Homonym (E));
13408                         E := Homonym (E);
13409                      end loop;
13410                   end if;
13411                end;
13412
13413             --  One argument form
13414
13415             else
13416                Check_Arg_Count (1);
13417
13418                if Nkind (A) = N_String_Literal then
13419                   S   := Strval (A);
13420
13421                   declare
13422                      Slen    : constant Natural := Natural (String_Length (S));
13423                      Options : String (1 .. Slen);
13424                      J       : Natural;
13425
13426                   begin
13427                      J := 1;
13428                      loop
13429                         C := Get_String_Char (S, Int (J));
13430                         exit when not In_Character_Range (C);
13431                         Options (J) := Get_Character (C);
13432
13433                         --  If at end of string, set options. As per discussion
13434                         --  above, no need to check for errors, since we issued
13435                         --  them in the parser.
13436
13437                         if J = Slen then
13438                            Set_Style_Check_Options (Options);
13439                            exit;
13440                         end if;
13441
13442                         J := J + 1;
13443                      end loop;
13444                   end;
13445
13446                elsif Nkind (A) = N_Identifier then
13447                   if Chars (A) = Name_All_Checks then
13448                      if GNAT_Mode then
13449                         Set_GNAT_Style_Check_Options;
13450                      else
13451                         Set_Default_Style_Check_Options;
13452                      end if;
13453
13454                   elsif Chars (A) = Name_On then
13455                      Style_Check := True;
13456
13457                   elsif Chars (A) = Name_Off then
13458                      Style_Check := False;
13459                   end if;
13460                end if;
13461             end if;
13462          end Style_Checks;
13463
13464          --------------
13465          -- Subtitle --
13466          --------------
13467
13468          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13469
13470          when Pragma_Subtitle =>
13471             GNAT_Pragma;
13472             Check_Arg_Count (1);
13473             Check_Optional_Identifier (Arg1, Name_Subtitle);
13474             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13475             Store_Note (N);
13476
13477          --------------
13478          -- Suppress --
13479          --------------
13480
13481          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13482
13483          when Pragma_Suppress =>
13484             Process_Suppress_Unsuppress (True);
13485
13486          ------------------
13487          -- Suppress_All --
13488          ------------------
13489
13490          --  pragma Suppress_All;
13491
13492          --  The only check made here is that the pragma has no arguments.
13493          --  There are no placement rules, and the processing required (setting
13494          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
13495          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
13496          --  then creates and inserts a pragma Suppress (All_Checks).
13497
13498          when Pragma_Suppress_All =>
13499             GNAT_Pragma;
13500             Check_Arg_Count (0);
13501
13502          -------------------------
13503          -- Suppress_Debug_Info --
13504          -------------------------
13505
13506          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13507
13508          when Pragma_Suppress_Debug_Info =>
13509             GNAT_Pragma;
13510             Check_Arg_Count (1);
13511             Check_Optional_Identifier (Arg1, Name_Entity);
13512             Check_Arg_Is_Local_Name (Arg1);
13513             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13514
13515          ----------------------------------
13516          -- Suppress_Exception_Locations --
13517          ----------------------------------
13518
13519          --  pragma Suppress_Exception_Locations;
13520
13521          when Pragma_Suppress_Exception_Locations =>
13522             GNAT_Pragma;
13523             Check_Arg_Count (0);
13524             Check_Valid_Configuration_Pragma;
13525             Exception_Locations_Suppressed := True;
13526
13527          -----------------------------
13528          -- Suppress_Initialization --
13529          -----------------------------
13530
13531          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13532
13533          when Pragma_Suppress_Initialization => Suppress_Init : declare
13534             E_Id : Node_Id;
13535             E    : Entity_Id;
13536
13537          begin
13538             GNAT_Pragma;
13539             Check_Arg_Count (1);
13540             Check_Optional_Identifier (Arg1, Name_Entity);
13541             Check_Arg_Is_Local_Name (Arg1);
13542
13543             E_Id := Get_Pragma_Arg (Arg1);
13544
13545             if Etype (E_Id) = Any_Type then
13546                return;
13547             end if;
13548
13549             E := Entity (E_Id);
13550
13551             if not Is_Type (E) then
13552                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13553             end if;
13554
13555             if Rep_Item_Too_Early (E, N)
13556                  or else
13557                Rep_Item_Too_Late (E, N, FOnly => True)
13558             then
13559                return;
13560             end if;
13561
13562             --  For incomplete/private type, set flag on full view
13563
13564             if Is_Incomplete_Or_Private_Type (E) then
13565                if No (Full_View (Base_Type (E))) then
13566                   Error_Pragma_Arg
13567                     ("argument of pragma% cannot be an incomplete type", Arg1);
13568                else
13569                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13570                end if;
13571
13572             --  For first subtype, set flag on base type
13573
13574             elsif Is_First_Subtype (E) then
13575                Set_Suppress_Initialization (Base_Type (E));
13576
13577             --  For other than first subtype, set flag on subtype itself
13578
13579             else
13580                Set_Suppress_Initialization (E);
13581             end if;
13582          end Suppress_Init;
13583
13584          -----------------
13585          -- System_Name --
13586          -----------------
13587
13588          --  pragma System_Name (DIRECT_NAME);
13589
13590          --  Syntax check: one argument, which must be the identifier GNAT or
13591          --  the identifier GCC, no other identifiers are acceptable.
13592
13593          when Pragma_System_Name =>
13594             GNAT_Pragma;
13595             Check_No_Identifiers;
13596             Check_Arg_Count (1);
13597             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13598
13599          -----------------------------
13600          -- Task_Dispatching_Policy --
13601          -----------------------------
13602
13603          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13604
13605          when Pragma_Task_Dispatching_Policy => declare
13606             DP : Character;
13607
13608          begin
13609             Check_Ada_83_Warning;
13610             Check_Arg_Count (1);
13611             Check_No_Identifiers;
13612             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13613             Check_Valid_Configuration_Pragma;
13614             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13615             DP := Fold_Upper (Name_Buffer (1));
13616
13617             if Task_Dispatching_Policy /= ' '
13618               and then Task_Dispatching_Policy /= DP
13619             then
13620                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13621                Error_Pragma
13622                  ("task dispatching policy incompatible with policy#");
13623
13624             --  Set new policy, but always preserve System_Location since we
13625             --  like the error message with the run time name.
13626
13627             else
13628                Task_Dispatching_Policy := DP;
13629
13630                if Task_Dispatching_Policy_Sloc /= System_Location then
13631                   Task_Dispatching_Policy_Sloc := Loc;
13632                end if;
13633             end if;
13634          end;
13635
13636          ---------------
13637          -- Task_Info --
13638          ---------------
13639
13640          --  pragma Task_Info (EXPRESSION);
13641
13642          when Pragma_Task_Info => Task_Info : declare
13643             P : constant Node_Id := Parent (N);
13644
13645          begin
13646             GNAT_Pragma;
13647
13648             if Nkind (P) /= N_Task_Definition then
13649                Error_Pragma ("pragma% must appear in task definition");
13650             end if;
13651
13652             Check_No_Identifiers;
13653             Check_Arg_Count (1);
13654
13655             Analyze_And_Resolve
13656               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13657
13658             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13659                return;
13660             end if;
13661
13662             if Has_Task_Info_Pragma (P) then
13663                Error_Pragma ("duplicate pragma% not allowed");
13664             else
13665                Set_Has_Task_Info_Pragma (P, True);
13666             end if;
13667          end Task_Info;
13668
13669          ---------------
13670          -- Task_Name --
13671          ---------------
13672
13673          --  pragma Task_Name (string_EXPRESSION);
13674
13675          when Pragma_Task_Name => Task_Name : declare
13676             P   : constant Node_Id := Parent (N);
13677             Arg : Node_Id;
13678
13679          begin
13680             Check_No_Identifiers;
13681             Check_Arg_Count (1);
13682
13683             Arg := Get_Pragma_Arg (Arg1);
13684
13685             --  The expression is used in the call to Create_Task, and must be
13686             --  expanded there, not in the context of the current spec. It must
13687             --  however be analyzed to capture global references, in case it
13688             --  appears in a generic context.
13689
13690             Preanalyze_And_Resolve (Arg, Standard_String);
13691
13692             if Nkind (P) /= N_Task_Definition then
13693                Pragma_Misplaced;
13694             end if;
13695
13696             if Has_Task_Name_Pragma (P) then
13697                Error_Pragma ("duplicate pragma% not allowed");
13698             else
13699                Set_Has_Task_Name_Pragma (P, True);
13700                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13701             end if;
13702          end Task_Name;
13703
13704          ------------------
13705          -- Task_Storage --
13706          ------------------
13707
13708          --  pragma Task_Storage (
13709          --     [Task_Type =>] LOCAL_NAME,
13710          --     [Top_Guard =>] static_integer_EXPRESSION);
13711
13712          when Pragma_Task_Storage => Task_Storage : declare
13713             Args  : Args_List (1 .. 2);
13714             Names : constant Name_List (1 .. 2) := (
13715                       Name_Task_Type,
13716                       Name_Top_Guard);
13717
13718             Task_Type : Node_Id renames Args (1);
13719             Top_Guard : Node_Id renames Args (2);
13720
13721             Ent : Entity_Id;
13722
13723          begin
13724             GNAT_Pragma;
13725             Gather_Associations (Names, Args);
13726
13727             if No (Task_Type) then
13728                Error_Pragma
13729                  ("missing task_type argument for pragma%");
13730             end if;
13731
13732             Check_Arg_Is_Local_Name (Task_Type);
13733
13734             Ent := Entity (Task_Type);
13735
13736             if not Is_Task_Type (Ent) then
13737                Error_Pragma_Arg
13738                  ("argument for pragma% must be task type", Task_Type);
13739             end if;
13740
13741             if No (Top_Guard) then
13742                Error_Pragma_Arg
13743                  ("pragma% takes two arguments", Task_Type);
13744             else
13745                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13746             end if;
13747
13748             Check_First_Subtype (Task_Type);
13749
13750             if Rep_Item_Too_Late (Ent, N) then
13751                raise Pragma_Exit;
13752             end if;
13753          end Task_Storage;
13754
13755          ---------------
13756          -- Test_Case --
13757          ---------------
13758
13759          --  pragma Test_Case ([Name     =>] Static_String_EXPRESSION
13760          --                   ,[Mode     =>] MODE_TYPE
13761          --                  [, Requires =>  Boolean_EXPRESSION]
13762          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13763
13764          --  MODE_TYPE ::= Nominal | Robustness
13765
13766          when Pragma_Test_Case => Test_Case : declare
13767          begin
13768             GNAT_Pragma;
13769             Check_At_Least_N_Arguments (2);
13770             Check_At_Most_N_Arguments (4);
13771             Check_Arg_Order
13772                  ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13773
13774             Check_Optional_Identifier (Arg1, Name_Name);
13775             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13776
13777             --  In ASIS mode, for a pragma generated from a source aspect, also
13778             --  analyze the original aspect expression.
13779
13780             if ASIS_Mode
13781               and then Present (Corresponding_Aspect (N))
13782             then
13783                Check_Expr_Is_Static_Expression
13784                  (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13785             end if;
13786
13787             Check_Optional_Identifier (Arg2, Name_Mode);
13788             Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13789
13790             if Arg_Count = 4 then
13791                Check_Identifier (Arg3, Name_Requires);
13792                Check_Identifier (Arg4, Name_Ensures);
13793
13794             elsif Arg_Count = 3 then
13795                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13796             end if;
13797
13798             Check_Test_Case;
13799          end Test_Case;
13800
13801          --------------------------
13802          -- Thread_Local_Storage --
13803          --------------------------
13804
13805          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13806
13807          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13808             Id : Node_Id;
13809             E  : Entity_Id;
13810
13811          begin
13812             GNAT_Pragma;
13813             Check_Arg_Count (1);
13814             Check_Optional_Identifier (Arg1, Name_Entity);
13815             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13816
13817             Id := Get_Pragma_Arg (Arg1);
13818             Analyze (Id);
13819
13820             if not Is_Entity_Name (Id)
13821               or else Ekind (Entity (Id)) /= E_Variable
13822             then
13823                Error_Pragma_Arg ("local variable name required", Arg1);
13824             end if;
13825
13826             E := Entity (Id);
13827
13828             if Rep_Item_Too_Early (E, N)
13829               or else Rep_Item_Too_Late (E, N)
13830             then
13831                raise Pragma_Exit;
13832             end if;
13833
13834             Set_Has_Pragma_Thread_Local_Storage (E);
13835             Set_Has_Gigi_Rep_Item (E);
13836          end Thread_Local_Storage;
13837
13838          ----------------
13839          -- Time_Slice --
13840          ----------------
13841
13842          --  pragma Time_Slice (static_duration_EXPRESSION);
13843
13844          when Pragma_Time_Slice => Time_Slice : declare
13845             Val : Ureal;
13846             Nod : Node_Id;
13847
13848          begin
13849             GNAT_Pragma;
13850             Check_Arg_Count (1);
13851             Check_No_Identifiers;
13852             Check_In_Main_Program;
13853             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13854
13855             if not Error_Posted (Arg1) then
13856                Nod := Next (N);
13857                while Present (Nod) loop
13858                   if Nkind (Nod) = N_Pragma
13859                     and then Pragma_Name (Nod) = Name_Time_Slice
13860                   then
13861                      Error_Msg_Name_1 := Pname;
13862                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13863                   end if;
13864
13865                   Next (Nod);
13866                end loop;
13867             end if;
13868
13869             --  Process only if in main unit
13870
13871             if Get_Source_Unit (Loc) = Main_Unit then
13872                Opt.Time_Slice_Set := True;
13873                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13874
13875                if Val <= Ureal_0 then
13876                   Opt.Time_Slice_Value := 0;
13877
13878                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13879                   Opt.Time_Slice_Value := 1_000_000_000;
13880
13881                else
13882                   Opt.Time_Slice_Value :=
13883                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13884                end if;
13885             end if;
13886          end Time_Slice;
13887
13888          -----------
13889          -- Title --
13890          -----------
13891
13892          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13893
13894          --   TITLING_OPTION ::=
13895          --     [Title =>] STRING_LITERAL
13896          --   | [Subtitle =>] STRING_LITERAL
13897
13898          when Pragma_Title => Title : declare
13899             Args  : Args_List (1 .. 2);
13900             Names : constant Name_List (1 .. 2) := (
13901                       Name_Title,
13902                       Name_Subtitle);
13903
13904          begin
13905             GNAT_Pragma;
13906             Gather_Associations (Names, Args);
13907             Store_Note (N);
13908
13909             for J in 1 .. 2 loop
13910                if Present (Args (J)) then
13911                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13912                end if;
13913             end loop;
13914          end Title;
13915
13916          ---------------------
13917          -- Unchecked_Union --
13918          ---------------------
13919
13920          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13921
13922          when Pragma_Unchecked_Union => Unchecked_Union : declare
13923             Assoc   : constant Node_Id := Arg1;
13924             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13925             Typ     : Entity_Id;
13926             Discr   : Entity_Id;
13927             Tdef    : Node_Id;
13928             Clist   : Node_Id;
13929             Vpart   : Node_Id;
13930             Comp    : Node_Id;
13931             Variant : Node_Id;
13932
13933          begin
13934             Ada_2005_Pragma;
13935             Check_No_Identifiers;
13936             Check_Arg_Count (1);
13937             Check_Arg_Is_Local_Name (Arg1);
13938
13939             Find_Type (Type_Id);
13940             Typ := Entity (Type_Id);
13941
13942             if Typ = Any_Type
13943               or else Rep_Item_Too_Early (Typ, N)
13944             then
13945                return;
13946             else
13947                Typ := Underlying_Type (Typ);
13948             end if;
13949
13950             if Rep_Item_Too_Late (Typ, N) then
13951                return;
13952             end if;
13953
13954             Check_First_Subtype (Arg1);
13955
13956             --  Note remaining cases are references to a type in the current
13957             --  declarative part. If we find an error, we post the error on
13958             --  the relevant type declaration at an appropriate point.
13959
13960             if not Is_Record_Type (Typ) then
13961                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13962                return;
13963
13964             elsif Is_Tagged_Type (Typ) then
13965                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13966                return;
13967
13968             elsif not Has_Discriminants (Typ) then
13969                Error_Msg_N
13970                 ("Unchecked_Union must have one discriminant", Typ);
13971                return;
13972
13973             --  Note: in previous versions of GNAT we used to check for limited
13974             --  types and give an error, but in fact the standard does allow
13975             --  Unchecked_Union on limited types, so this check was removed.
13976
13977             --  Proceed with basic error checks completed
13978
13979             else
13980                Discr := First_Discriminant (Typ);
13981                while Present (Discr) loop
13982                   if No (Discriminant_Default_Value (Discr)) then
13983                      Error_Msg_N
13984                        ("Unchecked_Union discriminant must have default value",
13985                         Discr);
13986                   end if;
13987
13988                   Next_Discriminant (Discr);
13989                end loop;
13990
13991                Tdef  := Type_Definition (Declaration_Node (Typ));
13992                Clist := Component_List (Tdef);
13993
13994                Comp := First (Component_Items (Clist));
13995                while Present (Comp) loop
13996                   Check_Component (Comp, Typ);
13997                   Next (Comp);
13998                end loop;
13999
14000                if No (Clist) or else No (Variant_Part (Clist)) then
14001                   Error_Msg_N
14002                     ("Unchecked_Union must have variant part",
14003                      Tdef);
14004                   return;
14005                end if;
14006
14007                Vpart := Variant_Part (Clist);
14008
14009                Variant := First (Variants (Vpart));
14010                while Present (Variant) loop
14011                   Check_Variant (Variant, Typ);
14012                   Next (Variant);
14013                end loop;
14014             end if;
14015
14016             Set_Is_Unchecked_Union  (Typ);
14017             Set_Convention (Typ, Convention_C);
14018             Set_Has_Unchecked_Union (Base_Type (Typ));
14019             Set_Is_Unchecked_Union  (Base_Type (Typ));
14020          end Unchecked_Union;
14021
14022          ------------------------
14023          -- Unimplemented_Unit --
14024          ------------------------
14025
14026          --  pragma Unimplemented_Unit;
14027
14028          --  Note: this only gives an error if we are generating code, or if
14029          --  we are in a generic library unit (where the pragma appears in the
14030          --  body, not in the spec).
14031
14032          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
14033             Cunitent : constant Entity_Id :=
14034                          Cunit_Entity (Get_Source_Unit (Loc));
14035             Ent_Kind : constant Entity_Kind :=
14036                          Ekind (Cunitent);
14037
14038          begin
14039             GNAT_Pragma;
14040             Check_Arg_Count (0);
14041
14042             if Operating_Mode = Generate_Code
14043               or else Ent_Kind = E_Generic_Function
14044               or else Ent_Kind = E_Generic_Procedure
14045               or else Ent_Kind = E_Generic_Package
14046             then
14047                Get_Name_String (Chars (Cunitent));
14048                Set_Casing (Mixed_Case);
14049                Write_Str (Name_Buffer (1 .. Name_Len));
14050                Write_Str (" is not supported in this configuration");
14051                Write_Eol;
14052                raise Unrecoverable_Error;
14053             end if;
14054          end Unimplemented_Unit;
14055
14056          ------------------------
14057          -- Universal_Aliasing --
14058          ------------------------
14059
14060          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14061
14062          when Pragma_Universal_Aliasing => Universal_Alias : declare
14063             E_Id : Entity_Id;
14064
14065          begin
14066             GNAT_Pragma;
14067             Check_Arg_Count (1);
14068             Check_Optional_Identifier (Arg2, Name_Entity);
14069             Check_Arg_Is_Local_Name (Arg1);
14070             E_Id := Entity (Get_Pragma_Arg (Arg1));
14071
14072             if E_Id = Any_Type then
14073                return;
14074             elsif No (E_Id) or else not Is_Type (E_Id) then
14075                Error_Pragma_Arg ("pragma% requires type", Arg1);
14076             end if;
14077
14078             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14079          end Universal_Alias;
14080
14081          --------------------
14082          -- Universal_Data --
14083          --------------------
14084
14085          --  pragma Universal_Data [(library_unit_NAME)];
14086
14087          when Pragma_Universal_Data =>
14088             GNAT_Pragma;
14089
14090             --  If this is a configuration pragma, then set the universal
14091             --  addressing option, otherwise confirm that the pragma satisfies
14092             --  the requirements of library unit pragma placement and leave it
14093             --  to the GNAAMP back end to detect the pragma (avoids transitive
14094             --  setting of the option due to withed units).
14095
14096             if Is_Configuration_Pragma then
14097                Universal_Addressing_On_AAMP := True;
14098             else
14099                Check_Valid_Library_Unit_Pragma;
14100             end if;
14101
14102             if not AAMP_On_Target then
14103                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14104             end if;
14105
14106          ----------------
14107          -- Unmodified --
14108          ----------------
14109
14110          --  pragma Unmodified (local_Name {, local_Name});
14111
14112          when Pragma_Unmodified => Unmodified : declare
14113             Arg_Node : Node_Id;
14114             Arg_Expr : Node_Id;
14115             Arg_Ent  : Entity_Id;
14116
14117          begin
14118             GNAT_Pragma;
14119             Check_At_Least_N_Arguments (1);
14120
14121             --  Loop through arguments
14122
14123             Arg_Node := Arg1;
14124             while Present (Arg_Node) loop
14125                Check_No_Identifier (Arg_Node);
14126
14127                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
14128                --  in fact generate reference, so that the entity will have a
14129                --  reference, which will inhibit any warnings about it not
14130                --  being referenced, and also properly show up in the ali file
14131                --  as a reference. But this reference is recorded before the
14132                --  Has_Pragma_Unreferenced flag is set, so that no warning is
14133                --  generated for this reference.
14134
14135                Check_Arg_Is_Local_Name (Arg_Node);
14136                Arg_Expr := Get_Pragma_Arg (Arg_Node);
14137
14138                if Is_Entity_Name (Arg_Expr) then
14139                   Arg_Ent := Entity (Arg_Expr);
14140
14141                   if not Is_Assignable (Arg_Ent) then
14142                      Error_Pragma_Arg
14143                        ("pragma% can only be applied to a variable",
14144                         Arg_Expr);
14145                   else
14146                      Set_Has_Pragma_Unmodified (Arg_Ent);
14147                   end if;
14148                end if;
14149
14150                Next (Arg_Node);
14151             end loop;
14152          end Unmodified;
14153
14154          ------------------
14155          -- Unreferenced --
14156          ------------------
14157
14158          --  pragma Unreferenced (local_Name {, local_Name});
14159
14160          --    or when used in a context clause:
14161
14162          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14163
14164          when Pragma_Unreferenced => Unreferenced : declare
14165             Arg_Node : Node_Id;
14166             Arg_Expr : Node_Id;
14167             Arg_Ent  : Entity_Id;
14168             Citem    : Node_Id;
14169
14170          begin
14171             GNAT_Pragma;
14172             Check_At_Least_N_Arguments (1);
14173
14174             --  Check case of appearing within context clause
14175
14176             if Is_In_Context_Clause then
14177
14178                --  The arguments must all be units mentioned in a with clause
14179                --  in the same context clause. Note we already checked (in
14180                --  Par.Prag) that the arguments are either identifiers or
14181                --  selected components.
14182
14183                Arg_Node := Arg1;
14184                while Present (Arg_Node) loop
14185                   Citem := First (List_Containing (N));
14186                   while Citem /= N loop
14187                      if Nkind (Citem) = N_With_Clause
14188                        and then
14189                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14190                      then
14191                         Set_Has_Pragma_Unreferenced
14192                           (Cunit_Entity
14193                              (Get_Source_Unit
14194                                 (Library_Unit (Citem))));
14195                         Set_Unit_Name
14196                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
14197                         exit;
14198                      end if;
14199
14200                      Next (Citem);
14201                   end loop;
14202
14203                   if Citem = N then
14204                      Error_Pragma_Arg
14205                        ("argument of pragma% is not with'ed unit", Arg_Node);
14206                   end if;
14207
14208                   Next (Arg_Node);
14209                end loop;
14210
14211             --  Case of not in list of context items
14212
14213             else
14214                Arg_Node := Arg1;
14215                while Present (Arg_Node) loop
14216                   Check_No_Identifier (Arg_Node);
14217
14218                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
14219                   --  will in fact generate reference, so that the entity will
14220                   --  have a reference, which will inhibit any warnings about
14221                   --  it not being referenced, and also properly show up in the
14222                   --  ali file as a reference. But this reference is recorded
14223                   --  before the Has_Pragma_Unreferenced flag is set, so that
14224                   --  no warning is generated for this reference.
14225
14226                   Check_Arg_Is_Local_Name (Arg_Node);
14227                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
14228
14229                   if Is_Entity_Name (Arg_Expr) then
14230                      Arg_Ent := Entity (Arg_Expr);
14231
14232                      --  If the entity is overloaded, the pragma applies to the
14233                      --  most recent overloading, as documented. In this case,
14234                      --  name resolution does not generate a reference, so it
14235                      --  must be done here explicitly.
14236
14237                      if Is_Overloaded (Arg_Expr) then
14238                         Generate_Reference (Arg_Ent, N);
14239                      end if;
14240
14241                      Set_Has_Pragma_Unreferenced (Arg_Ent);
14242                   end if;
14243
14244                   Next (Arg_Node);
14245                end loop;
14246             end if;
14247          end Unreferenced;
14248
14249          --------------------------
14250          -- Unreferenced_Objects --
14251          --------------------------
14252
14253          --  pragma Unreferenced_Objects (local_Name {, local_Name});
14254
14255          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14256             Arg_Node : Node_Id;
14257             Arg_Expr : Node_Id;
14258
14259          begin
14260             GNAT_Pragma;
14261             Check_At_Least_N_Arguments (1);
14262
14263             Arg_Node := Arg1;
14264             while Present (Arg_Node) loop
14265                Check_No_Identifier (Arg_Node);
14266                Check_Arg_Is_Local_Name (Arg_Node);
14267                Arg_Expr := Get_Pragma_Arg (Arg_Node);
14268
14269                if not Is_Entity_Name (Arg_Expr)
14270                  or else not Is_Type (Entity (Arg_Expr))
14271                then
14272                   Error_Pragma_Arg
14273                     ("argument for pragma% must be type or subtype", Arg_Node);
14274                end if;
14275
14276                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14277                Next (Arg_Node);
14278             end loop;
14279          end Unreferenced_Objects;
14280
14281          ------------------------------
14282          -- Unreserve_All_Interrupts --
14283          ------------------------------
14284
14285          --  pragma Unreserve_All_Interrupts;
14286
14287          when Pragma_Unreserve_All_Interrupts =>
14288             GNAT_Pragma;
14289             Check_Arg_Count (0);
14290
14291             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14292                Unreserve_All_Interrupts := True;
14293             end if;
14294
14295          ----------------
14296          -- Unsuppress --
14297          ----------------
14298
14299          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14300
14301          when Pragma_Unsuppress =>
14302             Ada_2005_Pragma;
14303             Process_Suppress_Unsuppress (False);
14304
14305          -------------------
14306          -- Use_VADS_Size --
14307          -------------------
14308
14309          --  pragma Use_VADS_Size;
14310
14311          when Pragma_Use_VADS_Size =>
14312             GNAT_Pragma;
14313             Check_Arg_Count (0);
14314             Check_Valid_Configuration_Pragma;
14315             Use_VADS_Size := True;
14316
14317          ---------------------
14318          -- Validity_Checks --
14319          ---------------------
14320
14321          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14322
14323          when Pragma_Validity_Checks => Validity_Checks : declare
14324             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
14325             S  : String_Id;
14326             C  : Char_Code;
14327
14328          begin
14329             GNAT_Pragma;
14330             Check_Arg_Count (1);
14331             Check_No_Identifiers;
14332
14333             if Nkind (A) = N_String_Literal then
14334                S   := Strval (A);
14335
14336                declare
14337                   Slen    : constant Natural := Natural (String_Length (S));
14338                   Options : String (1 .. Slen);
14339                   J       : Natural;
14340
14341                begin
14342                   J := 1;
14343                   loop
14344                      C := Get_String_Char (S, Int (J));
14345                      exit when not In_Character_Range (C);
14346                      Options (J) := Get_Character (C);
14347
14348                      if J = Slen then
14349                         Set_Validity_Check_Options (Options);
14350                         exit;
14351                      else
14352                         J := J + 1;
14353                      end if;
14354                   end loop;
14355                end;
14356
14357             elsif Nkind (A) = N_Identifier then
14358                if Chars (A) = Name_All_Checks then
14359                   Set_Validity_Check_Options ("a");
14360                elsif Chars (A) = Name_On then
14361                   Validity_Checks_On := True;
14362                elsif Chars (A) = Name_Off then
14363                   Validity_Checks_On := False;
14364                end if;
14365             end if;
14366          end Validity_Checks;
14367
14368          --------------
14369          -- Volatile --
14370          --------------
14371
14372          --  pragma Volatile (LOCAL_NAME);
14373
14374          when Pragma_Volatile =>
14375             Process_Atomic_Shared_Volatile;
14376
14377          -------------------------
14378          -- Volatile_Components --
14379          -------------------------
14380
14381          --  pragma Volatile_Components (array_LOCAL_NAME);
14382
14383          --  Volatile is handled by the same circuit as Atomic_Components
14384
14385          --------------
14386          -- Warnings --
14387          --------------
14388
14389          --  pragma Warnings (On | Off);
14390          --  pragma Warnings (On | Off, LOCAL_NAME);
14391          --  pragma Warnings (static_string_EXPRESSION);
14392          --  pragma Warnings (On | Off, STRING_LITERAL);
14393
14394          when Pragma_Warnings => Warnings : begin
14395             GNAT_Pragma;
14396             Check_At_Least_N_Arguments (1);
14397             Check_No_Identifiers;
14398
14399             --  If debug flag -gnatd.i is set, pragma is ignored
14400
14401             if Debug_Flag_Dot_I then
14402                return;
14403             end if;
14404
14405             --  Process various forms of the pragma
14406
14407             declare
14408                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14409
14410             begin
14411                --  One argument case
14412
14413                if Arg_Count = 1 then
14414
14415                   --  On/Off one argument case was processed by parser
14416
14417                   if Nkind (Argx) = N_Identifier
14418                     and then
14419                       (Chars (Argx) = Name_On
14420                          or else
14421                        Chars (Argx) = Name_Off)
14422                   then
14423                      null;
14424
14425                   --  One argument case must be ON/OFF or static string expr
14426
14427                   elsif not Is_Static_String_Expression (Arg1) then
14428                      Error_Pragma_Arg
14429                        ("argument of pragma% must be On/Off or " &
14430                         "static string expression", Arg1);
14431
14432                   --  One argument string expression case
14433
14434                   else
14435                      declare
14436                         Lit : constant Node_Id   := Expr_Value_S (Argx);
14437                         Str : constant String_Id := Strval (Lit);
14438                         Len : constant Nat       := String_Length (Str);
14439                         C   : Char_Code;
14440                         J   : Nat;
14441                         OK  : Boolean;
14442                         Chr : Character;
14443
14444                      begin
14445                         J := 1;
14446                         while J <= Len loop
14447                            C := Get_String_Char (Str, J);
14448                            OK := In_Character_Range (C);
14449
14450                            if OK then
14451                               Chr := Get_Character (C);
14452
14453                               --  Dot case
14454
14455                               if J < Len and then Chr = '.' then
14456                                  J := J + 1;
14457                                  C := Get_String_Char (Str, J);
14458                                  Chr := Get_Character (C);
14459
14460                                  if not Set_Dot_Warning_Switch (Chr) then
14461                                     Error_Pragma_Arg
14462                                       ("invalid warning switch character " &
14463                                        '.' & Chr, Arg1);
14464                                  end if;
14465
14466                               --  Non-Dot case
14467
14468                               else
14469                                  OK := Set_Warning_Switch (Chr);
14470                               end if;
14471                            end if;
14472
14473                            if not OK then
14474                               Error_Pragma_Arg
14475                                 ("invalid warning switch character " & Chr,
14476                                  Arg1);
14477                            end if;
14478
14479                            J := J + 1;
14480                         end loop;
14481                      end;
14482                   end if;
14483
14484                   --  Two or more arguments (must be two)
14485
14486                else
14487                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14488                   Check_At_Most_N_Arguments (2);
14489
14490                   declare
14491                      E_Id : Node_Id;
14492                      E    : Entity_Id;
14493                      Err  : Boolean;
14494
14495                   begin
14496                      E_Id := Get_Pragma_Arg (Arg2);
14497                      Analyze (E_Id);
14498
14499                      --  In the expansion of an inlined body, a reference to
14500                      --  the formal may be wrapped in a conversion if the
14501                      --  actual is a conversion. Retrieve the real entity name.
14502
14503                      if (In_Instance_Body
14504                           or else In_Inlined_Body)
14505                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14506                      then
14507                         E_Id := Expression (E_Id);
14508                      end if;
14509
14510                      --  Entity name case
14511
14512                      if Is_Entity_Name (E_Id) then
14513                         E := Entity (E_Id);
14514
14515                         if E = Any_Id then
14516                            return;
14517                         else
14518                            loop
14519                               Set_Warnings_Off
14520                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14521                                                               Name_Off));
14522
14523                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14524                                 and then Warn_On_Warnings_Off
14525                               then
14526                                  Warnings_Off_Pragmas.Append ((N, E));
14527                               end if;
14528
14529                               if Is_Enumeration_Type (E) then
14530                                  declare
14531                                     Lit : Entity_Id;
14532                                  begin
14533                                     Lit := First_Literal (E);
14534                                     while Present (Lit) loop
14535                                        Set_Warnings_Off (Lit);
14536                                        Next_Literal (Lit);
14537                                     end loop;
14538                                  end;
14539                               end if;
14540
14541                               exit when No (Homonym (E));
14542                               E := Homonym (E);
14543                            end loop;
14544                         end if;
14545
14546                      --  Error if not entity or static string literal case
14547
14548                      elsif not Is_Static_String_Expression (Arg2) then
14549                         Error_Pragma_Arg
14550                           ("second argument of pragma% must be entity " &
14551                            "name or static string expression", Arg2);
14552
14553                      --  String literal case
14554
14555                      else
14556                         String_To_Name_Buffer
14557                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14558
14559                         --  Note on configuration pragma case: If this is a
14560                         --  configuration pragma, then for an OFF pragma, we
14561                         --  just set Config True in the call, which is all
14562                         --  that needs to be done. For the case of ON, this
14563                         --  is normally an error, unless it is canceling the
14564                         --  effect of a previous OFF pragma in the same file.
14565                         --  In any other case, an error will be signalled (ON
14566                         --  with no matching OFF).
14567
14568                         if Chars (Argx) = Name_Off then
14569                            Set_Specific_Warning_Off
14570                              (Loc, Name_Buffer (1 .. Name_Len),
14571                               Config => Is_Configuration_Pragma);
14572
14573                         elsif Chars (Argx) = Name_On then
14574                            Set_Specific_Warning_On
14575                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14576
14577                            if Err then
14578                               Error_Msg
14579                                 ("?pragma Warnings On with no " &
14580                                  "matching Warnings Off",
14581                                  Loc);
14582                            end if;
14583                         end if;
14584                      end if;
14585                   end;
14586                end if;
14587             end;
14588          end Warnings;
14589
14590          -------------------
14591          -- Weak_External --
14592          -------------------
14593
14594          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14595
14596          when Pragma_Weak_External => Weak_External : declare
14597             Ent : Entity_Id;
14598
14599          begin
14600             GNAT_Pragma;
14601             Check_Arg_Count (1);
14602             Check_Optional_Identifier (Arg1, Name_Entity);
14603             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14604             Ent := Entity (Get_Pragma_Arg (Arg1));
14605
14606             if Rep_Item_Too_Early (Ent, N) then
14607                return;
14608             else
14609                Ent := Underlying_Type (Ent);
14610             end if;
14611
14612             --  The only processing required is to link this item on to the
14613             --  list of rep items for the given entity. This is accomplished
14614             --  by the call to Rep_Item_Too_Late (when no error is detected
14615             --  and False is returned).
14616
14617             if Rep_Item_Too_Late (Ent, N) then
14618                return;
14619             else
14620                Set_Has_Gigi_Rep_Item (Ent);
14621             end if;
14622          end Weak_External;
14623
14624          -----------------------------
14625          -- Wide_Character_Encoding --
14626          -----------------------------
14627
14628          --  pragma Wide_Character_Encoding (IDENTIFIER);
14629
14630          when Pragma_Wide_Character_Encoding =>
14631             GNAT_Pragma;
14632
14633             --  Nothing to do, handled in parser. Note that we do not enforce
14634             --  configuration pragma placement, this pragma can appear at any
14635             --  place in the source, allowing mixed encodings within a single
14636             --  source program.
14637
14638             null;
14639
14640          --------------------
14641          -- Unknown_Pragma --
14642          --------------------
14643
14644          --  Should be impossible, since the case of an unknown pragma is
14645          --  separately processed before the case statement is entered.
14646
14647          when Unknown_Pragma =>
14648             raise Program_Error;
14649       end case;
14650
14651       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14652       --  until AI is formally approved.
14653
14654       --  Check_Order_Dependence;
14655
14656    exception
14657       when Pragma_Exit => null;
14658    end Analyze_Pragma;
14659
14660    -----------------------------
14661    -- Analyze_TC_In_Decl_Part --
14662    -----------------------------
14663
14664    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14665    begin
14666       --  Install formals and push subprogram spec onto scope stack so that we
14667       --  can see the formals from the pragma.
14668
14669       Install_Formals (S);
14670       Push_Scope (S);
14671
14672       --  Preanalyze the boolean expressions, we treat these as spec
14673       --  expressions (i.e. similar to a default expression).
14674
14675       Preanalyze_TC_Args (N,
14676                           Get_Requires_From_Test_Case_Pragma (N),
14677                           Get_Ensures_From_Test_Case_Pragma (N));
14678
14679       --  Remove the subprogram from the scope stack now that the pre-analysis
14680       --  of the expressions in the test-case is done.
14681
14682       End_Scope;
14683    end Analyze_TC_In_Decl_Part;
14684
14685    --------------------
14686    -- Check_Disabled --
14687    --------------------
14688
14689    function Check_Disabled (Nam : Name_Id) return Boolean is
14690       PP : Node_Id;
14691
14692    begin
14693       --  Loop through entries in check policy list
14694
14695       PP := Opt.Check_Policy_List;
14696       loop
14697          --  If there are no specific entries that matched, then nothing is
14698          --  disabled, so return False.
14699
14700          if No (PP) then
14701             return False;
14702
14703          --  Here we have an entry see if it matches
14704
14705          else
14706             declare
14707                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14708             begin
14709                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14710                   return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14711                else
14712                   PP := Next_Pragma (PP);
14713                end if;
14714             end;
14715          end if;
14716       end loop;
14717    end Check_Disabled;
14718
14719    -------------------
14720    -- Check_Enabled --
14721    -------------------
14722
14723    function Check_Enabled (Nam : Name_Id) return Boolean is
14724       PP : Node_Id;
14725
14726    begin
14727       --  Loop through entries in check policy list
14728
14729       PP := Opt.Check_Policy_List;
14730       loop
14731          --  If there are no specific entries that matched, then we let the
14732          --  setting of assertions govern. Note that this provides the needed
14733          --  compatibility with the RM for the cases of assertion, invariant,
14734          --  precondition, predicate, and postcondition.
14735
14736          if No (PP) then
14737             return Assertions_Enabled;
14738
14739          --  Here we have an entry see if it matches
14740
14741          else
14742             declare
14743                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14744
14745             begin
14746                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14747                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14748                      when Name_On | Name_Check =>
14749                         return True;
14750                      when Name_Off | Name_Ignore =>
14751                         return False;
14752                      when others =>
14753                         raise Program_Error;
14754                   end case;
14755
14756                else
14757                   PP := Next_Pragma (PP);
14758                end if;
14759             end;
14760          end if;
14761       end loop;
14762    end Check_Enabled;
14763
14764    ---------------------------------
14765    -- Delay_Config_Pragma_Analyze --
14766    ---------------------------------
14767
14768    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14769    begin
14770       return Pragma_Name (N) = Name_Interrupt_State
14771                or else
14772              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14773    end Delay_Config_Pragma_Analyze;
14774
14775    -------------------------
14776    -- Get_Base_Subprogram --
14777    -------------------------
14778
14779    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14780       Result : Entity_Id;
14781
14782    begin
14783       --  Follow subprogram renaming chain
14784
14785       Result := Def_Id;
14786       while Is_Subprogram (Result)
14787         and then
14788           Nkind (Parent (Declaration_Node (Result))) =
14789                                          N_Subprogram_Renaming_Declaration
14790         and then Present (Alias (Result))
14791       loop
14792          Result := Alias (Result);
14793       end loop;
14794
14795       return Result;
14796    end Get_Base_Subprogram;
14797
14798    ----------------
14799    -- Initialize --
14800    ----------------
14801
14802    procedure Initialize is
14803    begin
14804       Externals.Init;
14805    end Initialize;
14806
14807    -----------------------------
14808    -- Is_Config_Static_String --
14809    -----------------------------
14810
14811    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14812
14813       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14814       --  This is an internal recursive function that is just like the outer
14815       --  function except that it adds the string to the name buffer rather
14816       --  than placing the string in the name buffer.
14817
14818       ------------------------------
14819       -- Add_Config_Static_String --
14820       ------------------------------
14821
14822       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14823          N : Node_Id;
14824          C : Char_Code;
14825
14826       begin
14827          N := Arg;
14828
14829          if Nkind (N) = N_Op_Concat then
14830             if Add_Config_Static_String (Left_Opnd (N)) then
14831                N := Right_Opnd (N);
14832             else
14833                return False;
14834             end if;
14835          end if;
14836
14837          if Nkind (N) /= N_String_Literal then
14838             Error_Msg_N ("string literal expected for pragma argument", N);
14839             return False;
14840
14841          else
14842             for J in 1 .. String_Length (Strval (N)) loop
14843                C := Get_String_Char (Strval (N), J);
14844
14845                if not In_Character_Range (C) then
14846                   Error_Msg
14847                     ("string literal contains invalid wide character",
14848                      Sloc (N) + 1 + Source_Ptr (J));
14849                   return False;
14850                end if;
14851
14852                Add_Char_To_Name_Buffer (Get_Character (C));
14853             end loop;
14854          end if;
14855
14856          return True;
14857       end Add_Config_Static_String;
14858
14859    --  Start of processing for Is_Config_Static_String
14860
14861    begin
14862
14863       Name_Len := 0;
14864       return Add_Config_Static_String (Arg);
14865    end Is_Config_Static_String;
14866
14867    -----------------------------------------
14868    -- Is_Non_Significant_Pragma_Reference --
14869    -----------------------------------------
14870
14871    --  This function makes use of the following static table which indicates
14872    --  whether a given pragma is significant.
14873
14874    --  -1  indicates that references in any argument position are significant
14875    --  0   indicates that appearance in any argument is not significant
14876    --  +n  indicates that appearance as argument n is significant, but all
14877    --      other arguments are not significant
14878    --  99  special processing required (e.g. for pragma Check)
14879
14880    Sig_Flags : constant array (Pragma_Id) of Int :=
14881      (Pragma_AST_Entry                      => -1,
14882       Pragma_Abort_Defer                    => -1,
14883       Pragma_Ada_83                         => -1,
14884       Pragma_Ada_95                         => -1,
14885       Pragma_Ada_05                         => -1,
14886       Pragma_Ada_2005                       => -1,
14887       Pragma_Ada_12                         => -1,
14888       Pragma_Ada_2012                       => -1,
14889       Pragma_All_Calls_Remote               => -1,
14890       Pragma_Annotate                       => -1,
14891       Pragma_Assert                         => -1,
14892       Pragma_Assertion_Policy               =>  0,
14893       Pragma_Assume_No_Invalid_Values       =>  0,
14894       Pragma_Asynchronous                   => -1,
14895       Pragma_Atomic                         =>  0,
14896       Pragma_Atomic_Components              =>  0,
14897       Pragma_Attach_Handler                 => -1,
14898       Pragma_Check                          => 99,
14899       Pragma_Check_Name                     =>  0,
14900       Pragma_Check_Policy                   =>  0,
14901       Pragma_CIL_Constructor                => -1,
14902       Pragma_CPP_Class                      =>  0,
14903       Pragma_CPP_Constructor                =>  0,
14904       Pragma_CPP_Virtual                    =>  0,
14905       Pragma_CPP_Vtable                     =>  0,
14906       Pragma_CPU                            => -1,
14907       Pragma_C_Pass_By_Copy                 =>  0,
14908       Pragma_Comment                        =>  0,
14909       Pragma_Common_Object                  => -1,
14910       Pragma_Compile_Time_Error             => -1,
14911       Pragma_Compile_Time_Warning           => -1,
14912       Pragma_Compiler_Unit                  =>  0,
14913       Pragma_Complete_Representation        =>  0,
14914       Pragma_Complex_Representation         =>  0,
14915       Pragma_Component_Alignment            => -1,
14916       Pragma_Controlled                     =>  0,
14917       Pragma_Convention                     =>  0,
14918       Pragma_Convention_Identifier          =>  0,
14919       Pragma_Debug                          => -1,
14920       Pragma_Debug_Policy                   =>  0,
14921       Pragma_Detect_Blocking                => -1,
14922       Pragma_Default_Storage_Pool           => -1,
14923       Pragma_Dimension                      => -1,
14924       Pragma_Disable_Atomic_Synchronization => -1,
14925       Pragma_Discard_Names                  =>  0,
14926       Pragma_Dispatching_Domain             => -1,
14927       Pragma_Elaborate                      => -1,
14928       Pragma_Elaborate_All                  => -1,
14929       Pragma_Elaborate_Body                 => -1,
14930       Pragma_Elaboration_Checks             => -1,
14931       Pragma_Eliminate                      => -1,
14932       Pragma_Enable_Atomic_Synchronization  => -1,
14933       Pragma_Export                         => -1,
14934       Pragma_Export_Exception               => -1,
14935       Pragma_Export_Function                => -1,
14936       Pragma_Export_Object                  => -1,
14937       Pragma_Export_Procedure               => -1,
14938       Pragma_Export_Value                   => -1,
14939       Pragma_Export_Valued_Procedure        => -1,
14940       Pragma_Extend_System                  => -1,
14941       Pragma_Extensions_Allowed             => -1,
14942       Pragma_External                       => -1,
14943       Pragma_Favor_Top_Level                => -1,
14944       Pragma_External_Name_Casing           => -1,
14945       Pragma_Fast_Math                      => -1,
14946       Pragma_Finalize_Storage_Only          =>  0,
14947       Pragma_Float_Representation           =>  0,
14948       Pragma_Ident                          => -1,
14949       Pragma_Implementation_Defined         => -1,
14950       Pragma_Implemented                    => -1,
14951       Pragma_Implicit_Packing               =>  0,
14952       Pragma_Import                         => +2,
14953       Pragma_Import_Exception               =>  0,
14954       Pragma_Import_Function                =>  0,
14955       Pragma_Import_Object                  =>  0,
14956       Pragma_Import_Procedure               =>  0,
14957       Pragma_Import_Valued_Procedure        =>  0,
14958       Pragma_Independent                    =>  0,
14959       Pragma_Independent_Components         =>  0,
14960       Pragma_Initialize_Scalars             => -1,
14961       Pragma_Inline                         =>  0,
14962       Pragma_Inline_Always                  =>  0,
14963       Pragma_Inline_Generic                 =>  0,
14964       Pragma_Inspection_Point               => -1,
14965       Pragma_Interface                      => +2,
14966       Pragma_Interface_Name                 => +2,
14967       Pragma_Interrupt_Handler              => -1,
14968       Pragma_Interrupt_Priority             => -1,
14969       Pragma_Interrupt_State                => -1,
14970       Pragma_Invariant                      => -1,
14971       Pragma_Java_Constructor               => -1,
14972       Pragma_Java_Interface                 => -1,
14973       Pragma_Keep_Names                     =>  0,
14974       Pragma_License                        => -1,
14975       Pragma_Link_With                      => -1,
14976       Pragma_Linker_Alias                   => -1,
14977       Pragma_Linker_Constructor             => -1,
14978       Pragma_Linker_Destructor              => -1,
14979       Pragma_Linker_Options                 => -1,
14980       Pragma_Linker_Section                 => -1,
14981       Pragma_List                           => -1,
14982       Pragma_Locking_Policy                 => -1,
14983       Pragma_Long_Float                     => -1,
14984       Pragma_Machine_Attribute              => -1,
14985       Pragma_Main                           => -1,
14986       Pragma_Main_Storage                   => -1,
14987       Pragma_Memory_Size                    => -1,
14988       Pragma_No_Return                      =>  0,
14989       Pragma_No_Body                        =>  0,
14990       Pragma_No_Run_Time                    => -1,
14991       Pragma_No_Strict_Aliasing             => -1,
14992       Pragma_Normalize_Scalars              => -1,
14993       Pragma_Obsolescent                    =>  0,
14994       Pragma_Optimize                       => -1,
14995       Pragma_Optimize_Alignment             => -1,
14996       Pragma_Ordered                        =>  0,
14997       Pragma_Pack                           =>  0,
14998       Pragma_Page                           => -1,
14999       Pragma_Passive                        => -1,
15000       Pragma_Preelaborable_Initialization   => -1,
15001       Pragma_Polling                        => -1,
15002       Pragma_Persistent_BSS                 =>  0,
15003       Pragma_Postcondition                  => -1,
15004       Pragma_Precondition                   => -1,
15005       Pragma_Predicate                      => -1,
15006       Pragma_Preelaborate                   => -1,
15007       Pragma_Preelaborate_05                => -1,
15008       Pragma_Priority                       => -1,
15009       Pragma_Priority_Specific_Dispatching  => -1,
15010       Pragma_Profile                        =>  0,
15011       Pragma_Profile_Warnings               =>  0,
15012       Pragma_Propagate_Exceptions           => -1,
15013       Pragma_Psect_Object                   => -1,
15014       Pragma_Pure                           => -1,
15015       Pragma_Pure_05                        => -1,
15016       Pragma_Pure_12                        => -1,
15017       Pragma_Pure_Function                  => -1,
15018       Pragma_Queuing_Policy                 => -1,
15019       Pragma_Ravenscar                      => -1,
15020       Pragma_Relative_Deadline              => -1,
15021       Pragma_Remote_Call_Interface          => -1,
15022       Pragma_Remote_Types                   => -1,
15023       Pragma_Restricted_Run_Time            => -1,
15024       Pragma_Restriction_Warnings           => -1,
15025       Pragma_Restrictions                   => -1,
15026       Pragma_Reviewable                     => -1,
15027       Pragma_Short_Circuit_And_Or           => -1,
15028       Pragma_Share_Generic                  => -1,
15029       Pragma_Shared                         => -1,
15030       Pragma_Shared_Passive                 => -1,
15031       Pragma_Short_Descriptors              =>  0,
15032       Pragma_Source_File_Name               => -1,
15033       Pragma_Source_File_Name_Project       => -1,
15034       Pragma_Source_Reference               => -1,
15035       Pragma_Storage_Size                   => -1,
15036       Pragma_Storage_Unit                   => -1,
15037       Pragma_Static_Elaboration_Desired     => -1,
15038       Pragma_Stream_Convert                 => -1,
15039       Pragma_Style_Checks                   => -1,
15040       Pragma_Subtitle                       => -1,
15041       Pragma_Suppress                       =>  0,
15042       Pragma_Suppress_Exception_Locations   =>  0,
15043       Pragma_Suppress_All                   => -1,
15044       Pragma_Suppress_Debug_Info            =>  0,
15045       Pragma_Suppress_Initialization        =>  0,
15046       Pragma_System_Name                    => -1,
15047       Pragma_Task_Dispatching_Policy        => -1,
15048       Pragma_Task_Info                      => -1,
15049       Pragma_Task_Name                      => -1,
15050       Pragma_Task_Storage                   =>  0,
15051       Pragma_Test_Case                      => -1,
15052       Pragma_Thread_Local_Storage           =>  0,
15053       Pragma_Time_Slice                     => -1,
15054       Pragma_Title                          => -1,
15055       Pragma_Unchecked_Union                =>  0,
15056       Pragma_Unimplemented_Unit             => -1,
15057       Pragma_Universal_Aliasing             => -1,
15058       Pragma_Universal_Data                 => -1,
15059       Pragma_Unmodified                     => -1,
15060       Pragma_Unreferenced                   => -1,
15061       Pragma_Unreferenced_Objects           => -1,
15062       Pragma_Unreserve_All_Interrupts       => -1,
15063       Pragma_Unsuppress                     =>  0,
15064       Pragma_Use_VADS_Size                  => -1,
15065       Pragma_Validity_Checks                => -1,
15066       Pragma_Volatile                       =>  0,
15067       Pragma_Volatile_Components            =>  0,
15068       Pragma_Warnings                       => -1,
15069       Pragma_Weak_External                  => -1,
15070       Pragma_Wide_Character_Encoding        =>  0,
15071       Unknown_Pragma                        =>  0);
15072
15073    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15074       Id : Pragma_Id;
15075       P  : Node_Id;
15076       C  : Int;
15077       A  : Node_Id;
15078
15079    begin
15080       P := Parent (N);
15081
15082       if Nkind (P) /= N_Pragma_Argument_Association then
15083          return False;
15084
15085       else
15086          Id := Get_Pragma_Id (Parent (P));
15087          C := Sig_Flags (Id);
15088
15089          case C is
15090             when -1 =>
15091                return False;
15092
15093             when 0 =>
15094                return True;
15095
15096             when 99 =>
15097                case Id is
15098
15099                   --  For pragma Check, the first argument is not significant,
15100                   --  the second and the third (if present) arguments are
15101                   --  significant.
15102
15103                   when Pragma_Check =>
15104                      return
15105                        P = First (Pragma_Argument_Associations (Parent (P)));
15106
15107                   when others =>
15108                      raise Program_Error;
15109                end case;
15110
15111             when others =>
15112                A := First (Pragma_Argument_Associations (Parent (P)));
15113                for J in 1 .. C - 1 loop
15114                   if No (A) then
15115                      return False;
15116                   end if;
15117
15118                   Next (A);
15119                end loop;
15120
15121                return A = P; -- is this wrong way round ???
15122          end case;
15123       end if;
15124    end Is_Non_Significant_Pragma_Reference;
15125
15126    ------------------------------
15127    -- Is_Pragma_String_Literal --
15128    ------------------------------
15129
15130    --  This function returns true if the corresponding pragma argument is a
15131    --  static string expression. These are the only cases in which string
15132    --  literals can appear as pragma arguments. We also allow a string literal
15133    --  as the first argument to pragma Assert (although it will of course
15134    --  always generate a type error).
15135
15136    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15137       Pragn : constant Node_Id := Parent (Par);
15138       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15139       Pname : constant Name_Id := Pragma_Name (Pragn);
15140       Argn  : Natural;
15141       N     : Node_Id;
15142
15143    begin
15144       Argn := 1;
15145       N := First (Assoc);
15146       loop
15147          exit when N = Par;
15148          Argn := Argn + 1;
15149          Next (N);
15150       end loop;
15151
15152       if Pname = Name_Assert then
15153          return True;
15154
15155       elsif Pname = Name_Export then
15156          return Argn > 2;
15157
15158       elsif Pname = Name_Ident then
15159          return Argn = 1;
15160
15161       elsif Pname = Name_Import then
15162          return Argn > 2;
15163
15164       elsif Pname = Name_Interface_Name then
15165          return Argn > 1;
15166
15167       elsif Pname = Name_Linker_Alias then
15168          return Argn = 2;
15169
15170       elsif Pname = Name_Linker_Section then
15171          return Argn = 2;
15172
15173       elsif Pname = Name_Machine_Attribute then
15174          return Argn = 2;
15175
15176       elsif Pname = Name_Source_File_Name then
15177          return True;
15178
15179       elsif Pname = Name_Source_Reference then
15180          return Argn = 2;
15181
15182       elsif Pname = Name_Title then
15183          return True;
15184
15185       elsif Pname = Name_Subtitle then
15186          return True;
15187
15188       else
15189          return False;
15190       end if;
15191    end Is_Pragma_String_Literal;
15192
15193    ------------------------
15194    -- Preanalyze_TC_Args --
15195    ------------------------
15196
15197    procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15198    begin
15199       --  Preanalyze the boolean expressions, we treat these as spec
15200       --  expressions (i.e. similar to a default expression).
15201
15202       if Present (Arg_Req) then
15203          Preanalyze_Spec_Expression
15204            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15205
15206          --  In ASIS mode, for a pragma generated from a source aspect, also
15207          --  analyze the original aspect expression.
15208
15209          if ASIS_Mode
15210            and then Present (Corresponding_Aspect (N))
15211          then
15212             Preanalyze_Spec_Expression
15213               (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15214          end if;
15215       end if;
15216
15217       if Present (Arg_Ens) then
15218          Preanalyze_Spec_Expression
15219            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15220
15221          --  In ASIS mode, for a pragma generated from a source aspect, also
15222          --  analyze the original aspect expression.
15223
15224          if ASIS_Mode
15225            and then Present (Corresponding_Aspect (N))
15226          then
15227             Preanalyze_Spec_Expression
15228               (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15229          end if;
15230       end if;
15231    end Preanalyze_TC_Args;
15232
15233    --------------------------------------
15234    -- Process_Compilation_Unit_Pragmas --
15235    --------------------------------------
15236
15237    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15238    begin
15239       --  A special check for pragma Suppress_All, a very strange DEC pragma,
15240       --  strange because it comes at the end of the unit. Rational has the
15241       --  same name for a pragma, but treats it as a program unit pragma, In
15242       --  GNAT we just decide to allow it anywhere at all. If it appeared then
15243       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
15244       --  node, and we insert a pragma Suppress (All_Checks) at the start of
15245       --  the context clause to ensure the correct processing.
15246
15247       if Has_Pragma_Suppress_All (N) then
15248          Prepend_To (Context_Items (N),
15249            Make_Pragma (Sloc (N),
15250              Chars                        => Name_Suppress,
15251              Pragma_Argument_Associations => New_List (
15252                Make_Pragma_Argument_Association (Sloc (N),
15253                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15254       end if;
15255
15256       --  Nothing else to do at the current time!
15257
15258    end Process_Compilation_Unit_Pragmas;
15259
15260    --------
15261    -- rv --
15262    --------
15263
15264    procedure rv is
15265    begin
15266       null;
15267    end rv;
15268
15269    --------------------------------
15270    -- Set_Encoded_Interface_Name --
15271    --------------------------------
15272
15273    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15274       Str : constant String_Id := Strval (S);
15275       Len : constant Int       := String_Length (Str);
15276       CC  : Char_Code;
15277       C   : Character;
15278       J   : Int;
15279
15280       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15281
15282       procedure Encode;
15283       --  Stores encoded value of character code CC. The encoding we use an
15284       --  underscore followed by four lower case hex digits.
15285
15286       ------------
15287       -- Encode --
15288       ------------
15289
15290       procedure Encode is
15291       begin
15292          Store_String_Char (Get_Char_Code ('_'));
15293          Store_String_Char
15294            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15295          Store_String_Char
15296            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15297          Store_String_Char
15298            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15299          Store_String_Char
15300            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15301       end Encode;
15302
15303    --  Start of processing for Set_Encoded_Interface_Name
15304
15305    begin
15306       --  If first character is asterisk, this is a link name, and we leave it
15307       --  completely unmodified. We also ignore null strings (the latter case
15308       --  happens only in error cases) and no encoding should occur for Java or
15309       --  AAMP interface names.
15310
15311       if Len = 0
15312         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15313         or else VM_Target /= No_VM
15314         or else AAMP_On_Target
15315       then
15316          Set_Interface_Name (E, S);
15317
15318       else
15319          J := 1;
15320          loop
15321             CC := Get_String_Char (Str, J);
15322
15323             exit when not In_Character_Range (CC);
15324
15325             C := Get_Character (CC);
15326
15327             exit when C /= '_' and then C /= '$'
15328               and then C not in '0' .. '9'
15329               and then C not in 'a' .. 'z'
15330               and then C not in 'A' .. 'Z';
15331
15332             if J = Len then
15333                Set_Interface_Name (E, S);
15334                return;
15335
15336             else
15337                J := J + 1;
15338             end if;
15339          end loop;
15340
15341          --  Here we need to encode. The encoding we use as follows:
15342          --     three underscores  + four hex digits (lower case)
15343
15344          Start_String;
15345
15346          for J in 1 .. String_Length (Str) loop
15347             CC := Get_String_Char (Str, J);
15348
15349             if not In_Character_Range (CC) then
15350                Encode;
15351             else
15352                C := Get_Character (CC);
15353
15354                if C = '_' or else C = '$'
15355                  or else C in '0' .. '9'
15356                  or else C in 'a' .. 'z'
15357                  or else C in 'A' .. 'Z'
15358                then
15359                   Store_String_Char (CC);
15360                else
15361                   Encode;
15362                end if;
15363             end if;
15364          end loop;
15365
15366          Set_Interface_Name (E,
15367            Make_String_Literal (Sloc (S),
15368              Strval => End_String));
15369       end if;
15370    end Set_Encoded_Interface_Name;
15371
15372    -------------------
15373    -- Set_Unit_Name --
15374    -------------------
15375
15376    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15377       Pref : Node_Id;
15378       Scop : Entity_Id;
15379
15380    begin
15381       if Nkind (N) = N_Identifier
15382         and then Nkind (With_Item) = N_Identifier
15383       then
15384          Set_Entity (N, Entity (With_Item));
15385
15386       elsif Nkind (N) = N_Selected_Component then
15387          Change_Selected_Component_To_Expanded_Name (N);
15388          Set_Entity (N, Entity (With_Item));
15389          Set_Entity (Selector_Name (N), Entity (N));
15390
15391          Pref := Prefix (N);
15392          Scop := Scope (Entity (N));
15393          while Nkind (Pref) = N_Selected_Component loop
15394             Change_Selected_Component_To_Expanded_Name (Pref);
15395             Set_Entity (Selector_Name (Pref), Scop);
15396             Set_Entity (Pref, Scop);
15397             Pref := Prefix (Pref);
15398             Scop := Scope (Scop);
15399          end loop;
15400
15401          Set_Entity (Pref, Scop);
15402       end if;
15403    end Set_Unit_Name;
15404
15405 end Sem_Prag;