OSDN Git Service

2011-11-04 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ P R A G                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with Aspects;  use Aspects;
33 with Atree;    use Atree;
34 with Casing;   use Casing;
35 with Checks;   use Checks;
36 with Csets;    use Csets;
37 with Debug;    use Debug;
38 with Einfo;    use Einfo;
39 with Elists;   use Elists;
40 with Errout;   use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze;   use Freeze;
44 with Lib;      use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists;   use Nlists;
49 with Nmake;    use Nmake;
50 with Opt;      use Opt;
51 with Output;   use Output;
52 with Par_SCO;  use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident;   use Rident;
55 with Rtsfind;  use Rtsfind;
56 with Sem;      use Sem;
57 with Sem_Aux;  use Sem_Aux;
58 with Sem_Ch3;  use Sem_Ch3;
59 with Sem_Ch6;  use Sem_Ch6;
60 with Sem_Ch8;  use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res;  use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand;    use Stand;
75 with Sinfo;    use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput;   use Sinput;
78 with Snames;   use Snames;
79 with Stringt;  use Stringt;
80 with Stylesw;  use Stylesw;
81 with Table;
82 with Targparm; use Targparm;
83 with Tbuild;   use Tbuild;
84 with Ttypes;
85 with Uintp;    use Uintp;
86 with Uname;    use Uname;
87 with Urealp;   use Urealp;
88 with Validsw;  use Validsw;
89 with Warnsw;   use Warnsw;
90
91 package body Sem_Prag is
92
93    ----------------------------------------------
94    -- Common Handling of Import-Export Pragmas --
95    ----------------------------------------------
96
97    --  In the following section, a number of Import_xxx and Export_xxx pragmas
98    --  are defined by GNAT. These are compatible with the DEC pragmas of the
99    --  same name, and all have the following common form and processing:
100
101    --  pragma Export_xxx
102    --        [Internal                 =>] LOCAL_NAME
103    --     [, [External                 =>] EXTERNAL_SYMBOL]
104    --     [, other optional parameters   ]);
105
106    --  pragma Import_xxx
107    --        [Internal                 =>] LOCAL_NAME
108    --     [, [External                 =>] EXTERNAL_SYMBOL]
109    --     [, other optional parameters   ]);
110
111    --   EXTERNAL_SYMBOL ::=
112    --     IDENTIFIER
113    --   | static_string_EXPRESSION
114
115    --  The internal LOCAL_NAME designates the entity that is imported or
116    --  exported, and must refer to an entity in the current declarative
117    --  part (as required by the rules for LOCAL_NAME).
118
119    --  The external linker name is designated by the External parameter if
120    --  given, or the Internal parameter if not (if there is no External
121    --  parameter, the External parameter is a copy of the Internal name).
122
123    --  If the External parameter is given as a string, then this string is
124    --  treated as an external name (exactly as though it had been given as an
125    --  External_Name parameter for a normal Import pragma).
126
127    --  If the External parameter is given as an identifier (or there is no
128    --  External parameter, so that the Internal identifier is used), then
129    --  the external name is the characters of the identifier, translated
130    --  to all upper case letters for OpenVMS versions of GNAT, and to all
131    --  lower case letters for all other versions
132
133    --  Note: the external name specified or implied by any of these special
134    --  Import_xxx or Export_xxx pragmas override an external or link name
135    --  specified in a previous Import or Export pragma.
136
137    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
138    --  named notation, following the standard rules for subprogram calls, i.e.
139    --  parameters can be given in any order if named notation is used, and
140    --  positional and named notation can be mixed, subject to the rule that all
141    --  positional parameters must appear first.
142
143    --  Note: All these pragmas are implemented exactly following the DEC design
144    --  and implementation and are intended to be fully compatible with the use
145    --  of these pragmas in the DEC Ada compiler.
146
147    --------------------------------------------
148    -- Checking for Duplicated External Names --
149    --------------------------------------------
150
151    --  It is suspicious if two separate Export pragmas use the same external
152    --  name. The following table is used to diagnose this situation so that
153    --  an appropriate warning can be issued.
154
155    --  The Node_Id stored is for the N_String_Literal node created to hold
156    --  the value of the external name. The Sloc of this node is used to
157    --  cross-reference the location of the duplication.
158
159    package Externals is new Table.Table (
160      Table_Component_Type => Node_Id,
161      Table_Index_Type     => Int,
162      Table_Low_Bound      => 0,
163      Table_Initial        => 100,
164      Table_Increment      => 100,
165      Table_Name           => "Name_Externals");
166
167    -------------------------------------
168    -- Local Subprograms and Variables --
169    -------------------------------------
170
171    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
172    --  This routine is used for possible casing adjustment of an explicit
173    --  external name supplied as a string literal (the node N), according to
174    --  the casing requirement of Opt.External_Name_Casing. If this is set to
175    --  As_Is, then the string literal is returned unchanged, but if it is set
176    --  to Uppercase or Lowercase, then a new string literal with appropriate
177    --  casing is constructed.
178
179    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
180    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
181    --  original one, following the renaming chain) is returned. Otherwise the
182    --  entity is returned unchanged. Should be in Einfo???
183
184    procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id);
185    --  Preanalyze the boolean expressions in the Requires and Ensures arguments
186    --  of a Test_Case pragma if present (possibly Empty). We treat these as
187    --  spec expressions (i.e. similar to a default expression).
188
189    procedure rv;
190    --  This is a dummy function called by the processing for pragma Reviewable.
191    --  It is there for assisting front end debugging. By placing a Reviewable
192    --  pragma in the source program, a breakpoint on rv catches this place in
193    --  the source, allowing convenient stepping to the point of interest.
194
195    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
196    --  Place semantic information on the argument of an Elaborate/Elaborate_All
197    --  pragma. Entity name for unit and its parents is taken from item in
198    --  previous with_clause that mentions the unit.
199
200    -------------------------------
201    -- Adjust_External_Name_Case --
202    -------------------------------
203
204    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
205       CC : Char_Code;
206
207    begin
208       --  Adjust case of literal if required
209
210       if Opt.External_Name_Exp_Casing = As_Is then
211          return N;
212
213       else
214          --  Copy existing string
215
216          Start_String;
217
218          --  Set proper casing
219
220          for J in 1 .. String_Length (Strval (N)) loop
221             CC := Get_String_Char (Strval (N), J);
222
223             if Opt.External_Name_Exp_Casing = Uppercase
224               and then CC >= Get_Char_Code ('a')
225               and then CC <= Get_Char_Code ('z')
226             then
227                Store_String_Char (CC - 32);
228
229             elsif Opt.External_Name_Exp_Casing = Lowercase
230               and then CC >= Get_Char_Code ('A')
231               and then CC <= Get_Char_Code ('Z')
232             then
233                Store_String_Char (CC + 32);
234
235             else
236                Store_String_Char (CC);
237             end if;
238          end loop;
239
240          return
241            Make_String_Literal (Sloc (N),
242              Strval => End_String);
243       end if;
244    end Adjust_External_Name_Case;
245
246    ------------------------------
247    -- Analyze_PPC_In_Decl_Part --
248    ------------------------------
249
250    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
251       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
252
253    begin
254       --  Install formals and push subprogram spec onto scope stack so that we
255       --  can see the formals from the pragma.
256
257       Install_Formals (S);
258       Push_Scope (S);
259
260       --  Preanalyze the boolean expression, we treat this as a spec expression
261       --  (i.e. similar to a default expression).
262
263       Preanalyze_Spec_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
264
265       --  In ASIS mode, for a pragma generated from a source aspect, also
266       --  analyze the original aspect expression.
267
268       if ASIS_Mode
269         and then Present (Corresponding_Aspect (N))
270       then
271          Preanalyze_Spec_Expression
272            (Expression (Corresponding_Aspect (N)), Standard_Boolean);
273       end if;
274
275       --  For a class-wide condition, a reference to a controlling formal must
276       --  be interpreted as having the class-wide type (or an access to such)
277       --  so that the inherited condition can be properly applied to any
278       --  overriding operation (see ARM12 6.6.1 (7)).
279
280       if Class_Present (N) then
281          declare
282             T   : constant Entity_Id := Find_Dispatching_Type (S);
283
284             ACW : Entity_Id := Empty;
285             --  Access to T'class, created if there is a controlling formal
286             --  that is an access parameter.
287
288             function Get_ACW return Entity_Id;
289             --  If the expression has a reference to an controlling access
290             --  parameter, create an access to T'class for the necessary
291             --  conversions if one does not exist.
292
293             function Process (N : Node_Id) return Traverse_Result;
294             --  ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
295             --  aspect for a primitive subprogram of a tagged type T, a name
296             --  that denotes a formal parameter of type T is interpreted as
297             --  having type T'Class. Similarly, a name that denotes a formal
298             --  accessparameter of type access-to-T is interpreted as having
299             --  type access-to-T'Class. This ensures the expression is well-
300             --  defined for a primitive subprogram of a type descended from T.
301
302             -------------
303             -- Get_ACW --
304             -------------
305
306             function Get_ACW return Entity_Id is
307                Loc  : constant Source_Ptr := Sloc (N);
308                Decl : Node_Id;
309
310             begin
311                if No (ACW) then
312                   Decl := Make_Full_Type_Declaration (Loc,
313                     Defining_Identifier => Make_Temporary (Loc, 'T'),
314                     Type_Definition =>
315                        Make_Access_To_Object_Definition (Loc,
316                        Subtype_Indication =>
317                          New_Occurrence_Of (Class_Wide_Type (T), Loc),
318                        All_Present => True));
319
320                   Insert_Before (Unit_Declaration_Node (S), Decl);
321                   Analyze (Decl);
322                   ACW := Defining_Identifier (Decl);
323                   Freeze_Before (Unit_Declaration_Node (S), ACW);
324                end if;
325
326                return ACW;
327             end Get_ACW;
328
329             -------------
330             -- Process --
331             -------------
332
333             function Process (N : Node_Id) return Traverse_Result is
334                Loc : constant Source_Ptr := Sloc (N);
335                Typ : Entity_Id;
336
337             begin
338                if Is_Entity_Name (N)
339                  and then Is_Formal (Entity (N))
340                  and then Nkind (Parent (N)) /= N_Type_Conversion
341                then
342                   if Etype (Entity (N)) = T then
343                      Typ := Class_Wide_Type (T);
344
345                   elsif Is_Access_Type (Etype (Entity (N)))
346                     and then Designated_Type (Etype (Entity (N))) = T
347                   then
348                      Typ := Get_ACW;
349                   else
350                      Typ := Empty;
351                   end if;
352
353                   if Present (Typ) then
354                      Rewrite (N,
355                        Make_Type_Conversion (Loc,
356                          Subtype_Mark =>
357                            New_Occurrence_Of (Typ, Loc),
358                          Expression  => New_Occurrence_Of (Entity (N), Loc)));
359                      Set_Etype (N, Typ);
360                   end if;
361                end if;
362
363                return OK;
364             end Process;
365
366             procedure Replace_Type is new Traverse_Proc (Process);
367
368          begin
369             Replace_Type (Get_Pragma_Arg (Arg1));
370          end;
371       end if;
372
373       --  Remove the subprogram from the scope stack now that the pre-analysis
374       --  of the precondition/postcondition is done.
375
376       End_Scope;
377    end Analyze_PPC_In_Decl_Part;
378
379    --------------------
380    -- Analyze_Pragma --
381    --------------------
382
383    procedure Analyze_Pragma (N : Node_Id) is
384       Loc     : constant Source_Ptr := Sloc (N);
385       Prag_Id : Pragma_Id;
386
387       Pname : Name_Id;
388       --  Name of the source pragma, or name of the corresponding aspect for
389       --  pragmas which originate in a source aspect. In the latter case, the
390       --  name may be different from the pragma name.
391
392       Pragma_Exit : exception;
393       --  This exception is used to exit pragma processing completely. It is
394       --  used when an error is detected, and no further processing is
395       --  required. It is also used if an earlier error has left the tree in
396       --  a state where the pragma should not be processed.
397
398       Arg_Count : Nat;
399       --  Number of pragma argument associations
400
401       Arg1 : Node_Id;
402       Arg2 : Node_Id;
403       Arg3 : Node_Id;
404       Arg4 : Node_Id;
405       --  First four pragma arguments (pragma argument association nodes, or
406       --  Empty if the corresponding argument does not exist).
407
408       type Name_List is array (Natural range <>) of Name_Id;
409       type Args_List is array (Natural range <>) of Node_Id;
410       --  Types used for arguments to Check_Arg_Order and Gather_Associations
411
412       procedure Ada_2005_Pragma;
413       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
414       --  Ada 95 mode, these are implementation defined pragmas, so should be
415       --  caught by the No_Implementation_Pragmas restriction.
416
417       procedure Ada_2012_Pragma;
418       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
419       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
420       --  should be caught by the No_Implementation_Pragmas restriction.
421
422       procedure Check_Ada_83_Warning;
423       --  Issues a warning message for the current pragma if operating in Ada
424       --  83 mode (used for language pragmas that are not a standard part of
425       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
426       --  of 95 pragma.
427
428       procedure Check_Arg_Count (Required : Nat);
429       --  Check argument count for pragma is equal to given parameter. If not,
430       --  then issue an error message and raise Pragma_Exit.
431
432       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
433       --  Arg which can either be a pragma argument association, in which case
434       --  the check is applied to the expression of the association or an
435       --  expression directly.
436
437       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
438       --  Check that an argument has the right form for an EXTERNAL_NAME
439       --  parameter of an extended import/export pragma. The rule is that the
440       --  name must be an identifier or string literal (in Ada 83 mode) or a
441       --  static string expression (in Ada 95 mode).
442
443       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
444       --  Check the specified argument Arg to make sure that it is an
445       --  identifier. If not give error and raise Pragma_Exit.
446
447       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
448       --  Check the specified argument Arg to make sure that it is an integer
449       --  literal. If not give error and raise Pragma_Exit.
450
451       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
452       --  Check the specified argument Arg to make sure that it has the proper
453       --  syntactic form for a local name and meets the semantic requirements
454       --  for a local name. The local name is analyzed as part of the
455       --  processing for this call. In addition, the local name is required
456       --  to represent an entity at the library level.
457
458       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
459       --  Check the specified argument Arg to make sure that it has the proper
460       --  syntactic form for a local name and meets the semantic requirements
461       --  for a local name. The local name is analyzed as part of the
462       --  processing for this call.
463
464       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
465       --  Check the specified argument Arg to make sure that it is a valid
466       --  locking policy name. If not give error and raise Pragma_Exit.
467
468       procedure Check_Arg_Is_One_Of
469         (Arg                : Node_Id;
470          N1, N2             : Name_Id);
471       procedure Check_Arg_Is_One_Of
472         (Arg                : Node_Id;
473          N1, N2, N3         : Name_Id);
474       procedure Check_Arg_Is_One_Of
475         (Arg                : Node_Id;
476          N1, N2, N3, N4, N5 : Name_Id);
477       --  Check the specified argument Arg to make sure that it is an
478       --  identifier whose name matches either N1 or N2 (or N3, N4, N5 if
479       --  present). If not then give error and raise Pragma_Exit.
480
481       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
482       --  Check the specified argument Arg to make sure that it is a valid
483       --  queuing policy name. If not give error and raise Pragma_Exit.
484
485       procedure Check_Arg_Is_Static_Expression
486         (Arg : Node_Id;
487          Typ : Entity_Id := Empty);
488       --  Check the specified argument Arg to make sure that it is a static
489       --  expression of the given type (i.e. it will be analyzed and resolved
490       --  using this type, which can be any valid argument to Resolve, e.g.
491       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
492       --  Typ is left Empty, then any static expression is allowed.
493
494       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
495       --  Check the specified argument Arg to make sure that it is a valid task
496       --  dispatching policy name. If not give error and raise Pragma_Exit.
497
498       procedure Check_Arg_Order (Names : Name_List);
499       --  Checks for an instance of two arguments with identifiers for the
500       --  current pragma which are not in the sequence indicated by Names,
501       --  and if so, generates a fatal message about bad order of arguments.
502
503       procedure Check_At_Least_N_Arguments (N : Nat);
504       --  Check there are at least N arguments present
505
506       procedure Check_At_Most_N_Arguments (N : Nat);
507       --  Check there are no more than N arguments present
508
509       procedure Check_Component
510         (Comp            : Node_Id;
511          UU_Typ          : Entity_Id;
512          In_Variant_Part : Boolean := False);
513       --  Examine an Unchecked_Union component for correct use of per-object
514       --  constrained subtypes, and for restrictions on finalizable components.
515       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
516       --  should be set when Comp comes from a record variant.
517
518       procedure Check_Duplicate_Pragma (E : Entity_Id);
519       --  Check if a pragma of the same name as the current pragma is already
520       --  chained as a rep pragma to the given entity. If so give a message
521       --  about the duplicate, and then raise Pragma_Exit so does not return.
522       --  Also checks for delayed aspect specification node in the chain.
523
524       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
525       --  Nam is an N_String_Literal node containing the external name set by
526       --  an Import or Export pragma (or extended Import or Export pragma).
527       --  This procedure checks for possible duplications if this is the export
528       --  case, and if found, issues an appropriate error message.
529
530       procedure Check_Expr_Is_Static_Expression
531         (Expr : Node_Id;
532          Typ  : Entity_Id := Empty);
533       --  Check the specified expression Expr to make sure that it is a static
534       --  expression of the given type (i.e. it will be analyzed and resolved
535       --  using this type, which can be any valid argument to Resolve, e.g.
536       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
537       --  Typ is left Empty, then any static expression is allowed.
538
539       procedure Check_First_Subtype (Arg : Node_Id);
540       --  Checks that Arg, whose expression is an entity name, references a
541       --  first subtype.
542
543       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
544       --  Checks that the given argument has an identifier, and if so, requires
545       --  it to match the given identifier name. If there is no identifier, or
546       --  a non-matching identifier, then an error message is given and
547       --  Pragma_Exit is raised.
548
549       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
550       --  Checks that the given argument has an identifier, and if so, requires
551       --  it to match one of the given identifier names. If there is no
552       --  identifier, or a non-matching identifier, then an error message is
553       --  given and Pragma_Exit is raised.
554
555       procedure Check_In_Main_Program;
556       --  Common checks for pragmas that appear within a main program
557       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
558
559       procedure Check_Interrupt_Or_Attach_Handler;
560       --  Common processing for first argument of pragma Interrupt_Handler or
561       --  pragma Attach_Handler.
562
563       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
564       --  Check that pragma appears in a declarative part, or in a package
565       --  specification, i.e. that it does not occur in a statement sequence
566       --  in a body.
567
568       procedure Check_No_Identifier (Arg : Node_Id);
569       --  Checks that the given argument does not have an identifier. If
570       --  an identifier is present, then an error message is issued, and
571       --  Pragma_Exit is raised.
572
573       procedure Check_No_Identifiers;
574       --  Checks that none of the arguments to the pragma has an identifier.
575       --  If any argument has an identifier, then an error message is issued,
576       --  and Pragma_Exit is raised.
577
578       procedure Check_No_Link_Name;
579       --  Checks that no link name is specified
580
581       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
582       --  Checks if the given argument has an identifier, and if so, requires
583       --  it to match the given identifier name. If there is a non-matching
584       --  identifier, then an error message is given and Pragma_Exit is raised.
585
586       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
587       --  Checks if the given argument has an identifier, and if so, requires
588       --  it to match the given identifier name. If there is a non-matching
589       --  identifier, then an error message is given and Pragma_Exit is raised.
590       --  In this version of the procedure, the identifier name is given as
591       --  a string with lower case letters.
592
593       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
594       --  Called to process a precondition or postcondition pragma. There are
595       --  three cases:
596       --
597       --    The pragma appears after a subprogram spec
598       --
599       --      If the corresponding check is not enabled, the pragma is analyzed
600       --      but otherwise ignored and control returns with In_Body set False.
601       --
602       --      If the check is enabled, then the first step is to analyze the
603       --      pragma, but this is skipped if the subprogram spec appears within
604       --      a package specification (because this is the case where we delay
605       --      analysis till the end of the spec). Then (whether or not it was
606       --      analyzed), the pragma is chained to the subprogram in question
607       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
608       --      caller with In_Body set False.
609       --
610       --    The pragma appears at the start of subprogram body declarations
611       --
612       --      In this case an immediate return to the caller is made with
613       --      In_Body set True, and the pragma is NOT analyzed.
614       --
615       --    In all other cases, an error message for bad placement is given
616
617       procedure Check_Static_Constraint (Constr : Node_Id);
618       --  Constr is a constraint from an N_Subtype_Indication node from a
619       --  component constraint in an Unchecked_Union type. This routine checks
620       --  that the constraint is static as required by the restrictions for
621       --  Unchecked_Union.
622
623       procedure Check_Test_Case;
624       --  Called to process a test-case pragma. The treatment is similar to the
625       --  one for pre- and postcondition in Check_Precondition_Postcondition,
626       --  except the placement rules for the test-case pragma are stricter.
627       --  This pragma may only occur after a subprogram spec declared directly
628       --  in a package spec unit. In this case, the pragma is chained to the
629       --  subprogram in question (using Spec_TC_List and Next_Pragma) and
630       --  analysis of the pragma is delayed till the end of the spec. In
631       --  all other cases, an error message for bad placement is given.
632
633       procedure Check_Valid_Configuration_Pragma;
634       --  Legality checks for placement of a configuration pragma
635
636       procedure Check_Valid_Library_Unit_Pragma;
637       --  Legality checks for library unit pragmas. A special case arises for
638       --  pragmas in generic instances that come from copies of the original
639       --  library unit pragmas in the generic templates. In the case of other
640       --  than library level instantiations these can appear in contexts which
641       --  would normally be invalid (they only apply to the original template
642       --  and to library level instantiations), and they are simply ignored,
643       --  which is implemented by rewriting them as null statements.
644
645       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
646       --  Check an Unchecked_Union variant for lack of nested variants and
647       --  presence of at least one component. UU_Typ is the related Unchecked_
648       --  Union type.
649
650       procedure Error_Pragma (Msg : String);
651       pragma No_Return (Error_Pragma);
652       --  Outputs error message for current pragma. The message contains a %
653       --  that will be replaced with the pragma name, and the flag is placed
654       --  on the pragma itself. Pragma_Exit is then raised.
655
656       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
657       pragma No_Return (Error_Pragma_Arg);
658       --  Outputs error message for current pragma. The message may contain
659       --  a % that will be replaced with the pragma name. The parameter Arg
660       --  may either be a pragma argument association, in which case the flag
661       --  is placed on the expression of this association, or an expression,
662       --  in which case the flag is placed directly on the expression. The
663       --  message is placed using Error_Msg_N, so the message may also contain
664       --  an & insertion character which will reference the given Arg value.
665       --  After placing the message, Pragma_Exit is raised.
666
667       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
668       pragma No_Return (Error_Pragma_Arg);
669       --  Similar to above form of Error_Pragma_Arg except that two messages
670       --  are provided, the second is a continuation comment starting with \.
671
672       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
673       pragma No_Return (Error_Pragma_Arg_Ident);
674       --  Outputs error message for current pragma. The message may contain
675       --  a % that will be replaced with the pragma name. The parameter Arg
676       --  must be a pragma argument association with a non-empty identifier
677       --  (i.e. its Chars field must be set), and the error message is placed
678       --  on the identifier. The message is placed using Error_Msg_N so
679       --  the message may also contain an & insertion character which will
680       --  reference the identifier. After placing the message, Pragma_Exit
681       --  is raised.
682
683       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
684       pragma No_Return (Error_Pragma_Ref);
685       --  Outputs error message for current pragma. The message may contain
686       --  a % that will be replaced with the pragma name. The parameter Ref
687       --  must be an entity whose name can be referenced by & and sloc by #.
688       --  After placing the message, Pragma_Exit is raised.
689
690       function Find_Lib_Unit_Name return Entity_Id;
691       --  Used for a library unit pragma to find the entity to which the
692       --  library unit pragma applies, returns the entity found.
693
694       procedure Find_Program_Unit_Name (Id : Node_Id);
695       --  If the pragma is a compilation unit pragma, the id must denote the
696       --  compilation unit in the same compilation, and the pragma must appear
697       --  in the list of preceding or trailing pragmas. If it is a program
698       --  unit pragma that is not a compilation unit pragma, then the
699       --  identifier must be visible.
700
701       function Find_Unique_Parameterless_Procedure
702         (Name : Entity_Id;
703          Arg  : Node_Id) return Entity_Id;
704       --  Used for a procedure pragma to find the unique parameterless
705       --  procedure identified by Name, returns it if it exists, otherwise
706       --  errors out and uses Arg as the pragma argument for the message.
707
708       procedure Fix_Error (Msg : in out String);
709       --  This is called prior to issuing an error message. Msg is a string
710       --  which typically contains the substring pragma. If the current pragma
711       --  comes from an aspect, each such "pragma" substring is replaced with
712       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
713       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
714
715       procedure Gather_Associations
716         (Names : Name_List;
717          Args  : out Args_List);
718       --  This procedure is used to gather the arguments for a pragma that
719       --  permits arbitrary ordering of parameters using the normal rules
720       --  for named and positional parameters. The Names argument is a list
721       --  of Name_Id values that corresponds to the allowed pragma argument
722       --  association identifiers in order. The result returned in Args is
723       --  a list of corresponding expressions that are the pragma arguments.
724       --  Note that this is a list of expressions, not of pragma argument
725       --  associations (Gather_Associations has completely checked all the
726       --  optional identifiers when it returns). An entry in Args is Empty
727       --  on return if the corresponding argument is not present.
728
729       procedure GNAT_Pragma;
730       --  Called for all GNAT defined pragmas to check the relevant restriction
731       --  (No_Implementation_Pragmas).
732
733       function Is_Before_First_Decl
734         (Pragma_Node : Node_Id;
735          Decls       : List_Id) return Boolean;
736       --  Return True if Pragma_Node is before the first declarative item in
737       --  Decls where Decls is the list of declarative items.
738
739       function Is_Configuration_Pragma return Boolean;
740       --  Determines if the placement of the current pragma is appropriate
741       --  for a configuration pragma.
742
743       function Is_In_Context_Clause return Boolean;
744       --  Returns True if pragma appears within the context clause of a unit,
745       --  and False for any other placement (does not generate any messages).
746
747       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
748       --  Analyzes the argument, and determines if it is a static string
749       --  expression, returns True if so, False if non-static or not String.
750
751       procedure Pragma_Misplaced;
752       pragma No_Return (Pragma_Misplaced);
753       --  Issue fatal error message for misplaced pragma
754
755       procedure Process_Atomic_Shared_Volatile;
756       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
757       --  Shared is an obsolete Ada 83 pragma, treated as being identical
758       --  in effect to pragma Atomic.
759
760       procedure Process_Compile_Time_Warning_Or_Error;
761       --  Common processing for Compile_Time_Error and Compile_Time_Warning
762
763       procedure Process_Convention
764         (C   : out Convention_Id;
765          Ent : out Entity_Id);
766       --  Common processing for Convention, Interface, Import and Export.
767       --  Checks first two arguments of pragma, and sets the appropriate
768       --  convention value in the specified entity or entities. On return
769       --  C is the convention, Ent is the referenced entity.
770
771       procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
772       --  Common processing for Disable/Enable_Atomic_Synchronization. Nam is
773       --  Name_Suppress for Disable and Name_Unsuppress for Enable.
774
775       procedure Process_Extended_Import_Export_Exception_Pragma
776         (Arg_Internal : Node_Id;
777          Arg_External : Node_Id;
778          Arg_Form     : Node_Id;
779          Arg_Code     : Node_Id);
780       --  Common processing for the pragmas Import/Export_Exception. The three
781       --  arguments correspond to the three named parameters of the pragma. An
782       --  argument is empty if the corresponding parameter is not present in
783       --  the pragma.
784
785       procedure Process_Extended_Import_Export_Object_Pragma
786         (Arg_Internal : Node_Id;
787          Arg_External : Node_Id;
788          Arg_Size     : Node_Id);
789       --  Common processing for the pragmas Import/Export_Object. The three
790       --  arguments correspond to the three named parameters of the pragmas. An
791       --  argument is empty if the corresponding parameter is not present in
792       --  the pragma.
793
794       procedure Process_Extended_Import_Export_Internal_Arg
795         (Arg_Internal : Node_Id := Empty);
796       --  Common processing for all extended Import and Export pragmas. The
797       --  argument is the pragma parameter for the Internal argument. If
798       --  Arg_Internal is empty or inappropriate, an error message is posted.
799       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
800       --  set to identify the referenced entity.
801
802       procedure Process_Extended_Import_Export_Subprogram_Pragma
803         (Arg_Internal                 : Node_Id;
804          Arg_External                 : Node_Id;
805          Arg_Parameter_Types          : Node_Id;
806          Arg_Result_Type              : Node_Id := Empty;
807          Arg_Mechanism                : Node_Id;
808          Arg_Result_Mechanism         : Node_Id := Empty;
809          Arg_First_Optional_Parameter : Node_Id := Empty);
810       --  Common processing for all extended Import and Export pragmas applying
811       --  to subprograms. The caller omits any arguments that do not apply to
812       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
813       --  only in the Import_Function and Export_Function cases). The argument
814       --  names correspond to the allowed pragma association identifiers.
815
816       procedure Process_Generic_List;
817       --  Common processing for Share_Generic and Inline_Generic
818
819       procedure Process_Import_Or_Interface;
820       --  Common processing for Import of Interface
821
822       procedure Process_Import_Predefined_Type;
823       --  Processing for completing a type with pragma Import. This is used
824       --  to declare types that match predefined C types, especially for cases
825       --  without corresponding Ada predefined type.
826
827       procedure Process_Inline (Active : Boolean);
828       --  Common processing for Inline and Inline_Always. The parameter
829       --  indicates if the inline pragma is active, i.e. if it should actually
830       --  cause inlining to occur.
831
832       procedure Process_Interface_Name
833         (Subprogram_Def : Entity_Id;
834          Ext_Arg        : Node_Id;
835          Link_Arg       : Node_Id);
836       --  Given the last two arguments of pragma Import, pragma Export, or
837       --  pragma Interface_Name, performs validity checks and sets the
838       --  Interface_Name field of the given subprogram entity to the
839       --  appropriate external or link name, depending on the arguments given.
840       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
841       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
842       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
843       --  nor Link_Arg is present, the interface name is set to the default
844       --  from the subprogram name.
845
846       procedure Process_Interrupt_Or_Attach_Handler;
847       --  Common processing for Interrupt and Attach_Handler pragmas
848
849       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
850       --  Common processing for Restrictions and Restriction_Warnings pragmas.
851       --  Warn is True for Restriction_Warnings, or for Restrictions if the
852       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
853       --  is not set in the Restrictions case.
854
855       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
856       --  Common processing for Suppress and Unsuppress. The boolean parameter
857       --  Suppress_Case is True for the Suppress case, and False for the
858       --  Unsuppress case.
859
860       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
861       --  This procedure sets the Is_Exported flag for the given entity,
862       --  checking that the entity was not previously imported. Arg is
863       --  the argument that specified the entity. A check is also made
864       --  for exporting inappropriate entities.
865
866       procedure Set_Extended_Import_Export_External_Name
867         (Internal_Ent : Entity_Id;
868          Arg_External : Node_Id);
869       --  Common processing for all extended import export pragmas. The first
870       --  argument, Internal_Ent, is the internal entity, which has already
871       --  been checked for validity by the caller. Arg_External is from the
872       --  Import or Export pragma, and may be null if no External parameter
873       --  was present. If Arg_External is present and is a non-null string
874       --  (a null string is treated as the default), then the Interface_Name
875       --  field of Internal_Ent is set appropriately.
876
877       procedure Set_Imported (E : Entity_Id);
878       --  This procedure sets the Is_Imported flag for the given entity,
879       --  checking that it is not previously exported or imported.
880
881       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
882       --  Mech is a parameter passing mechanism (see Import_Function syntax
883       --  for MECHANISM_NAME). This routine checks that the mechanism argument
884       --  has the right form, and if not issues an error message. If the
885       --  argument has the right form then the Mechanism field of Ent is
886       --  set appropriately.
887
888       procedure Set_Ravenscar_Profile (N : Node_Id);
889       --  Activate the set of configuration pragmas and restrictions that make
890       --  up the Ravenscar Profile. N is the corresponding pragma node, which
891       --  is used for error messages on any constructs that violate the
892       --  profile.
893
894       ---------------------
895       -- Ada_2005_Pragma --
896       ---------------------
897
898       procedure Ada_2005_Pragma is
899       begin
900          if Ada_Version <= Ada_95 then
901             Check_Restriction (No_Implementation_Pragmas, N);
902          end if;
903       end Ada_2005_Pragma;
904
905       ---------------------
906       -- Ada_2012_Pragma --
907       ---------------------
908
909       procedure Ada_2012_Pragma is
910       begin
911          if Ada_Version <= Ada_2005 then
912             Check_Restriction (No_Implementation_Pragmas, N);
913          end if;
914       end Ada_2012_Pragma;
915
916       --------------------------
917       -- Check_Ada_83_Warning --
918       --------------------------
919
920       procedure Check_Ada_83_Warning is
921       begin
922          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
923             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
924          end if;
925       end Check_Ada_83_Warning;
926
927       ---------------------
928       -- Check_Arg_Count --
929       ---------------------
930
931       procedure Check_Arg_Count (Required : Nat) is
932       begin
933          if Arg_Count /= Required then
934             Error_Pragma ("wrong number of arguments for pragma%");
935          end if;
936       end Check_Arg_Count;
937
938       --------------------------------
939       -- Check_Arg_Is_External_Name --
940       --------------------------------
941
942       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
943          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
944
945       begin
946          if Nkind (Argx) = N_Identifier then
947             return;
948
949          else
950             Analyze_And_Resolve (Argx, Standard_String);
951
952             if Is_OK_Static_Expression (Argx) then
953                return;
954
955             elsif Etype (Argx) = Any_Type then
956                raise Pragma_Exit;
957
958             --  An interesting special case, if we have a string literal and
959             --  we are in Ada 83 mode, then we allow it even though it will
960             --  not be flagged as static. This allows expected Ada 83 mode
961             --  use of external names which are string literals, even though
962             --  technically these are not static in Ada 83.
963
964             elsif Ada_Version = Ada_83
965               and then Nkind (Argx) = N_String_Literal
966             then
967                return;
968
969             --  Static expression that raises Constraint_Error. This has
970             --  already been flagged, so just exit from pragma processing.
971
972             elsif Is_Static_Expression (Argx) then
973                raise Pragma_Exit;
974
975             --  Here we have a real error (non-static expression)
976
977             else
978                Error_Msg_Name_1 := Pname;
979
980                declare
981                   Msg : String :=
982                           "argument for pragma% must be a identifier or "
983                           & "static string expression!";
984                begin
985                   Fix_Error (Msg);
986                   Flag_Non_Static_Expr (Msg, Argx);
987                   raise Pragma_Exit;
988                end;
989             end if;
990          end if;
991       end Check_Arg_Is_External_Name;
992
993       -----------------------------
994       -- Check_Arg_Is_Identifier --
995       -----------------------------
996
997       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
998          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
999       begin
1000          if Nkind (Argx) /= N_Identifier then
1001             Error_Pragma_Arg
1002               ("argument for pragma% must be identifier", Argx);
1003          end if;
1004       end Check_Arg_Is_Identifier;
1005
1006       ----------------------------------
1007       -- Check_Arg_Is_Integer_Literal --
1008       ----------------------------------
1009
1010       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
1011          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1012       begin
1013          if Nkind (Argx) /= N_Integer_Literal then
1014             Error_Pragma_Arg
1015               ("argument for pragma% must be integer literal", Argx);
1016          end if;
1017       end Check_Arg_Is_Integer_Literal;
1018
1019       -------------------------------------------
1020       -- Check_Arg_Is_Library_Level_Local_Name --
1021       -------------------------------------------
1022
1023       --  LOCAL_NAME ::=
1024       --    DIRECT_NAME
1025       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1026       --  | library_unit_NAME
1027
1028       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1029       begin
1030          Check_Arg_Is_Local_Name (Arg);
1031
1032          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1033            and then Comes_From_Source (N)
1034          then
1035             Error_Pragma_Arg
1036               ("argument for pragma% must be library level entity", Arg);
1037          end if;
1038       end Check_Arg_Is_Library_Level_Local_Name;
1039
1040       -----------------------------
1041       -- Check_Arg_Is_Local_Name --
1042       -----------------------------
1043
1044       --  LOCAL_NAME ::=
1045       --    DIRECT_NAME
1046       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1047       --  | library_unit_NAME
1048
1049       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1050          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1051
1052       begin
1053          Analyze (Argx);
1054
1055          if Nkind (Argx) not in N_Direct_Name
1056            and then (Nkind (Argx) /= N_Attribute_Reference
1057                       or else Present (Expressions (Argx))
1058                       or else Nkind (Prefix (Argx)) /= N_Identifier)
1059            and then (not Is_Entity_Name (Argx)
1060                       or else not Is_Compilation_Unit (Entity (Argx)))
1061          then
1062             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1063          end if;
1064
1065          --  No further check required if not an entity name
1066
1067          if not Is_Entity_Name (Argx) then
1068             null;
1069
1070          else
1071             declare
1072                OK   : Boolean;
1073                Ent  : constant Entity_Id := Entity (Argx);
1074                Scop : constant Entity_Id := Scope (Ent);
1075             begin
1076                --  Case of a pragma applied to a compilation unit: pragma must
1077                --  occur immediately after the program unit in the compilation.
1078
1079                if Is_Compilation_Unit (Ent) then
1080                   declare
1081                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1082
1083                   begin
1084                      --  Case of pragma placed immediately after spec
1085
1086                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1087                         OK := True;
1088
1089                      --  Case of pragma placed immediately after body
1090
1091                      elsif Nkind (Decl) = N_Subprogram_Declaration
1092                              and then Present (Corresponding_Body (Decl))
1093                      then
1094                         OK := Parent (N) =
1095                                 Aux_Decls_Node
1096                                   (Parent (Unit_Declaration_Node
1097                                              (Corresponding_Body (Decl))));
1098
1099                      --  All other cases are illegal
1100
1101                      else
1102                         OK := False;
1103                      end if;
1104                   end;
1105
1106                --  Special restricted placement rule from 10.2.1(11.8/2)
1107
1108                elsif Is_Generic_Formal (Ent)
1109                        and then Prag_Id = Pragma_Preelaborable_Initialization
1110                then
1111                   OK := List_Containing (N) =
1112                           Generic_Formal_Declarations
1113                             (Unit_Declaration_Node (Scop));
1114
1115                --  Default case, just check that the pragma occurs in the scope
1116                --  of the entity denoted by the name.
1117
1118                else
1119                   OK := Current_Scope = Scop;
1120                end if;
1121
1122                if not OK then
1123                   Error_Pragma_Arg
1124                     ("pragma% argument must be in same declarative part", Arg);
1125                end if;
1126             end;
1127          end if;
1128       end Check_Arg_Is_Local_Name;
1129
1130       ---------------------------------
1131       -- Check_Arg_Is_Locking_Policy --
1132       ---------------------------------
1133
1134       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1135          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1136
1137       begin
1138          Check_Arg_Is_Identifier (Argx);
1139
1140          if not Is_Locking_Policy_Name (Chars (Argx)) then
1141             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1142          end if;
1143       end Check_Arg_Is_Locking_Policy;
1144
1145       -------------------------
1146       -- Check_Arg_Is_One_Of --
1147       -------------------------
1148
1149       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1150          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1151
1152       begin
1153          Check_Arg_Is_Identifier (Argx);
1154
1155          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1156             Error_Msg_Name_2 := N1;
1157             Error_Msg_Name_3 := N2;
1158             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1159          end if;
1160       end Check_Arg_Is_One_Of;
1161
1162       procedure Check_Arg_Is_One_Of
1163         (Arg        : Node_Id;
1164          N1, N2, N3 : Name_Id)
1165       is
1166          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1167
1168       begin
1169          Check_Arg_Is_Identifier (Argx);
1170
1171          if Chars (Argx) /= N1
1172            and then Chars (Argx) /= N2
1173            and then Chars (Argx) /= N3
1174          then
1175             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1176          end if;
1177       end Check_Arg_Is_One_Of;
1178
1179       procedure Check_Arg_Is_One_Of
1180         (Arg                : Node_Id;
1181          N1, N2, N3, N4, N5 : Name_Id)
1182       is
1183          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1184
1185       begin
1186          Check_Arg_Is_Identifier (Argx);
1187
1188          if Chars (Argx) /= N1
1189            and then Chars (Argx) /= N2
1190            and then Chars (Argx) /= N3
1191            and then Chars (Argx) /= N4
1192            and then Chars (Argx) /= N5
1193          then
1194             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1195          end if;
1196       end Check_Arg_Is_One_Of;
1197       ---------------------------------
1198       -- Check_Arg_Is_Queuing_Policy --
1199       ---------------------------------
1200
1201       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1202          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1203
1204       begin
1205          Check_Arg_Is_Identifier (Argx);
1206
1207          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1208             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1209          end if;
1210       end Check_Arg_Is_Queuing_Policy;
1211
1212       ------------------------------------
1213       -- Check_Arg_Is_Static_Expression --
1214       ------------------------------------
1215
1216       procedure Check_Arg_Is_Static_Expression
1217         (Arg : Node_Id;
1218          Typ : Entity_Id := Empty)
1219       is
1220       begin
1221          Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
1222       end Check_Arg_Is_Static_Expression;
1223
1224       ------------------------------------------
1225       -- Check_Arg_Is_Task_Dispatching_Policy --
1226       ------------------------------------------
1227
1228       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1229          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1230
1231       begin
1232          Check_Arg_Is_Identifier (Argx);
1233
1234          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1235             Error_Pragma_Arg
1236               ("& is not a valid task dispatching policy name", Argx);
1237          end if;
1238       end Check_Arg_Is_Task_Dispatching_Policy;
1239
1240       ---------------------
1241       -- Check_Arg_Order --
1242       ---------------------
1243
1244       procedure Check_Arg_Order (Names : Name_List) is
1245          Arg : Node_Id;
1246
1247          Highest_So_Far : Natural := 0;
1248          --  Highest index in Names seen do far
1249
1250       begin
1251          Arg := Arg1;
1252          for J in 1 .. Arg_Count loop
1253             if Chars (Arg) /= No_Name then
1254                for K in Names'Range loop
1255                   if Chars (Arg) = Names (K) then
1256                      if K < Highest_So_Far then
1257                         Error_Msg_Name_1 := Pname;
1258                         Error_Msg_N
1259                           ("parameters out of order for pragma%", Arg);
1260                         Error_Msg_Name_1 := Names (K);
1261                         Error_Msg_Name_2 := Names (Highest_So_Far);
1262                         Error_Msg_N ("\% must appear before %", Arg);
1263                         raise Pragma_Exit;
1264
1265                      else
1266                         Highest_So_Far := K;
1267                      end if;
1268                   end if;
1269                end loop;
1270             end if;
1271
1272             Arg := Next (Arg);
1273          end loop;
1274       end Check_Arg_Order;
1275
1276       --------------------------------
1277       -- Check_At_Least_N_Arguments --
1278       --------------------------------
1279
1280       procedure Check_At_Least_N_Arguments (N : Nat) is
1281       begin
1282          if Arg_Count < N then
1283             Error_Pragma ("too few arguments for pragma%");
1284          end if;
1285       end Check_At_Least_N_Arguments;
1286
1287       -------------------------------
1288       -- Check_At_Most_N_Arguments --
1289       -------------------------------
1290
1291       procedure Check_At_Most_N_Arguments (N : Nat) is
1292          Arg : Node_Id;
1293       begin
1294          if Arg_Count > N then
1295             Arg := Arg1;
1296             for J in 1 .. N loop
1297                Next (Arg);
1298                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1299             end loop;
1300          end if;
1301       end Check_At_Most_N_Arguments;
1302
1303       ---------------------
1304       -- Check_Component --
1305       ---------------------
1306
1307       procedure Check_Component
1308         (Comp            : Node_Id;
1309          UU_Typ          : Entity_Id;
1310          In_Variant_Part : Boolean := False)
1311       is
1312          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1313          Sindic  : constant Node_Id :=
1314                      Subtype_Indication (Component_Definition (Comp));
1315          Typ     : constant Entity_Id := Etype (Comp_Id);
1316
1317          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1318          --  Determine whether entity Id appears inside a generic body.
1319          --  Shouldn't this be in a more general place ???
1320
1321          -------------------------
1322          -- Inside_Generic_Body --
1323          -------------------------
1324
1325          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1326             S : Entity_Id;
1327
1328          begin
1329             S := Id;
1330             while Present (S) and then S /= Standard_Standard loop
1331                if Ekind (S) = E_Generic_Package
1332                  and then In_Package_Body (S)
1333                then
1334                   return True;
1335                end if;
1336
1337                S := Scope (S);
1338             end loop;
1339
1340             return False;
1341          end Inside_Generic_Body;
1342
1343       --  Start of processing for Check_Component
1344
1345       begin
1346          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1347          --  object constraint, then the component type shall be an Unchecked_
1348          --  Union.
1349
1350          if Nkind (Sindic) = N_Subtype_Indication
1351            and then Has_Per_Object_Constraint (Comp_Id)
1352            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1353          then
1354             Error_Msg_N
1355               ("component subtype subject to per-object constraint " &
1356                "must be an Unchecked_Union", Comp);
1357
1358          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1359          --  the body of a generic unit, or within the body of any of its
1360          --  descendant library units, no part of the type of a component
1361          --  declared in a variant_part of the unchecked union type shall be of
1362          --  a formal private type or formal private extension declared within
1363          --  the formal part of the generic unit.
1364
1365          elsif Ada_Version >= Ada_2012
1366            and then Inside_Generic_Body (UU_Typ)
1367            and then In_Variant_Part
1368            and then Is_Private_Type (Typ)
1369            and then Is_Generic_Type (Typ)
1370          then
1371             Error_Msg_N
1372               ("component of Unchecked_Union cannot be of generic type", Comp);
1373
1374          elsif Needs_Finalization (Typ) then
1375             Error_Msg_N
1376               ("component of Unchecked_Union cannot be controlled", Comp);
1377
1378          elsif Has_Task (Typ) then
1379             Error_Msg_N
1380               ("component of Unchecked_Union cannot have tasks", Comp);
1381          end if;
1382       end Check_Component;
1383
1384       ----------------------------
1385       -- Check_Duplicate_Pragma --
1386       ----------------------------
1387
1388       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1389          P : Node_Id;
1390
1391       begin
1392          --  Nothing to do if this pragma comes from an aspect specification,
1393          --  since we could not be duplicating a pragma, and we dealt with the
1394          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1395
1396          if From_Aspect_Specification (N) then
1397             return;
1398          end if;
1399
1400          --  Otherwise current pragma may duplicate previous pragma or a
1401          --  previously given aspect specification for the same pragma.
1402
1403          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1404
1405          if Present (P) then
1406             Error_Msg_Name_1 := Pragma_Name (N);
1407             Error_Msg_Sloc := Sloc (P);
1408
1409             if Nkind (P) = N_Aspect_Specification
1410               or else From_Aspect_Specification (P)
1411             then
1412                Error_Msg_NE ("aspect% for & previously given#", N, E);
1413             else
1414                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1415             end if;
1416
1417             raise Pragma_Exit;
1418          end if;
1419       end Check_Duplicate_Pragma;
1420
1421       ----------------------------------
1422       -- Check_Duplicated_Export_Name --
1423       ----------------------------------
1424
1425       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1426          String_Val : constant String_Id := Strval (Nam);
1427
1428       begin
1429          --  We are only interested in the export case, and in the case of
1430          --  generics, it is the instance, not the template, that is the
1431          --  problem (the template will generate a warning in any case).
1432
1433          if not Inside_A_Generic
1434            and then (Prag_Id = Pragma_Export
1435                        or else
1436                      Prag_Id = Pragma_Export_Procedure
1437                        or else
1438                      Prag_Id = Pragma_Export_Valued_Procedure
1439                        or else
1440                      Prag_Id = Pragma_Export_Function)
1441          then
1442             for J in Externals.First .. Externals.Last loop
1443                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1444                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1445                   Error_Msg_N ("external name duplicates name given#", Nam);
1446                   exit;
1447                end if;
1448             end loop;
1449
1450             Externals.Append (Nam);
1451          end if;
1452       end Check_Duplicated_Export_Name;
1453
1454       -------------------------------------
1455       -- Check_Expr_Is_Static_Expression --
1456       -------------------------------------
1457
1458       procedure Check_Expr_Is_Static_Expression
1459         (Expr : Node_Id;
1460          Typ  : Entity_Id := Empty)
1461       is
1462       begin
1463          if Present (Typ) then
1464             Analyze_And_Resolve (Expr, Typ);
1465          else
1466             Analyze_And_Resolve (Expr);
1467          end if;
1468
1469          if Is_OK_Static_Expression (Expr) then
1470             return;
1471
1472          elsif Etype (Expr) = Any_Type then
1473             raise Pragma_Exit;
1474
1475          --  An interesting special case, if we have a string literal and we
1476          --  are in Ada 83 mode, then we allow it even though it will not be
1477          --  flagged as static. This allows the use of Ada 95 pragmas like
1478          --  Import in Ada 83 mode. They will of course be flagged with
1479          --  warnings as usual, but will not cause errors.
1480
1481          elsif Ada_Version = Ada_83
1482            and then Nkind (Expr) = N_String_Literal
1483          then
1484             return;
1485
1486          --  Static expression that raises Constraint_Error. This has already
1487          --  been flagged, so just exit from pragma processing.
1488
1489          elsif Is_Static_Expression (Expr) then
1490             raise Pragma_Exit;
1491
1492          --  Finally, we have a real error
1493
1494          else
1495             Error_Msg_Name_1 := Pname;
1496
1497             declare
1498                Msg : String :=
1499                        "argument for pragma% must be a static expression!";
1500             begin
1501                Fix_Error (Msg);
1502                Flag_Non_Static_Expr (Msg, Expr);
1503             end;
1504
1505             raise Pragma_Exit;
1506          end if;
1507       end Check_Expr_Is_Static_Expression;
1508
1509       -------------------------
1510       -- Check_First_Subtype --
1511       -------------------------
1512
1513       procedure Check_First_Subtype (Arg : Node_Id) is
1514          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1515          Ent  : constant Entity_Id := Entity (Argx);
1516
1517       begin
1518          if Is_First_Subtype (Ent) then
1519             null;
1520
1521          elsif Is_Type (Ent) then
1522             Error_Pragma_Arg
1523               ("pragma% cannot apply to subtype", Argx);
1524
1525          elsif Is_Object (Ent) then
1526             Error_Pragma_Arg
1527               ("pragma% cannot apply to object, requires a type", Argx);
1528
1529          else
1530             Error_Pragma_Arg
1531               ("pragma% cannot apply to&, requires a type", Argx);
1532          end if;
1533       end Check_First_Subtype;
1534
1535       ----------------------
1536       -- Check_Identifier --
1537       ----------------------
1538
1539       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1540       begin
1541          if Present (Arg)
1542            and then Nkind (Arg) = N_Pragma_Argument_Association
1543          then
1544             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1545                Error_Msg_Name_1 := Pname;
1546                Error_Msg_Name_2 := Id;
1547                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1548                raise Pragma_Exit;
1549             end if;
1550          end if;
1551       end Check_Identifier;
1552
1553       --------------------------------
1554       -- Check_Identifier_Is_One_Of --
1555       --------------------------------
1556
1557       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1558       begin
1559          if Present (Arg)
1560            and then Nkind (Arg) = N_Pragma_Argument_Association
1561          then
1562             if Chars (Arg) = No_Name then
1563                Error_Msg_Name_1 := Pname;
1564                Error_Msg_N ("pragma% argument expects an identifier", Arg);
1565                raise Pragma_Exit;
1566
1567             elsif Chars (Arg) /= N1
1568               and then Chars (Arg) /= N2
1569             then
1570                Error_Msg_Name_1 := Pname;
1571                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1572                raise Pragma_Exit;
1573             end if;
1574          end if;
1575       end Check_Identifier_Is_One_Of;
1576
1577       ---------------------------
1578       -- Check_In_Main_Program --
1579       ---------------------------
1580
1581       procedure Check_In_Main_Program is
1582          P : constant Node_Id := Parent (N);
1583
1584       begin
1585          --  Must be at in subprogram body
1586
1587          if Nkind (P) /= N_Subprogram_Body then
1588             Error_Pragma ("% pragma allowed only in subprogram");
1589
1590          --  Otherwise warn if obviously not main program
1591
1592          elsif Present (Parameter_Specifications (Specification (P)))
1593            or else not Is_Compilation_Unit (Defining_Entity (P))
1594          then
1595             Error_Msg_Name_1 := Pname;
1596             Error_Msg_N
1597               ("?pragma% is only effective in main program", N);
1598          end if;
1599       end Check_In_Main_Program;
1600
1601       ---------------------------------------
1602       -- Check_Interrupt_Or_Attach_Handler --
1603       ---------------------------------------
1604
1605       procedure Check_Interrupt_Or_Attach_Handler is
1606          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1607          Handler_Proc, Proc_Scope : Entity_Id;
1608
1609       begin
1610          Analyze (Arg1_X);
1611
1612          if Prag_Id = Pragma_Interrupt_Handler then
1613             Check_Restriction (No_Dynamic_Attachment, N);
1614          end if;
1615
1616          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1617          Proc_Scope := Scope (Handler_Proc);
1618
1619          --  On AAMP only, a pragma Interrupt_Handler is supported for
1620          --  nonprotected parameterless procedures.
1621
1622          if not AAMP_On_Target
1623            or else Prag_Id = Pragma_Attach_Handler
1624          then
1625             if Ekind (Proc_Scope) /= E_Protected_Type then
1626                Error_Pragma_Arg
1627                  ("argument of pragma% must be protected procedure", Arg1);
1628             end if;
1629
1630             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1631                Error_Pragma ("pragma% must be in protected definition");
1632             end if;
1633          end if;
1634
1635          if not Is_Library_Level_Entity (Proc_Scope)
1636            or else (AAMP_On_Target
1637                      and then not Is_Library_Level_Entity (Handler_Proc))
1638          then
1639             Error_Pragma_Arg
1640               ("argument for pragma% must be library level entity", Arg1);
1641          end if;
1642
1643          --  AI05-0033: A pragma cannot appear within a generic body, because
1644          --  instance can be in a nested scope. The check that protected type
1645          --  is itself a library-level declaration is done elsewhere.
1646
1647          --  Note: we omit this check in Codepeer mode to properly handle code
1648          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1649
1650          if Inside_A_Generic then
1651             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1652               and then In_Package_Body (Scope (Current_Scope))
1653               and then not CodePeer_Mode
1654             then
1655                Error_Pragma ("pragma% cannot be used inside a generic");
1656             end if;
1657          end if;
1658       end Check_Interrupt_Or_Attach_Handler;
1659
1660       -------------------------------------------
1661       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1662       -------------------------------------------
1663
1664       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1665          P : Node_Id;
1666
1667       begin
1668          P := Parent (N);
1669          loop
1670             if No (P) then
1671                exit;
1672
1673             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1674                exit;
1675
1676             elsif Nkind_In (P, N_Package_Specification,
1677                                N_Block_Statement)
1678             then
1679                return;
1680
1681             --  Note: the following tests seem a little peculiar, because
1682             --  they test for bodies, but if we were in the statement part
1683             --  of the body, we would already have hit the handled statement
1684             --  sequence, so the only way we get here is by being in the
1685             --  declarative part of the body.
1686
1687             elsif Nkind_In (P, N_Subprogram_Body,
1688                                N_Package_Body,
1689                                N_Task_Body,
1690                                N_Entry_Body)
1691             then
1692                return;
1693             end if;
1694
1695             P := Parent (P);
1696          end loop;
1697
1698          Error_Pragma ("pragma% is not in declarative part or package spec");
1699       end Check_Is_In_Decl_Part_Or_Package_Spec;
1700
1701       -------------------------
1702       -- Check_No_Identifier --
1703       -------------------------
1704
1705       procedure Check_No_Identifier (Arg : Node_Id) is
1706       begin
1707          if Nkind (Arg) = N_Pragma_Argument_Association
1708            and then Chars (Arg) /= No_Name
1709          then
1710             Error_Pragma_Arg_Ident
1711               ("pragma% does not permit identifier& here", Arg);
1712          end if;
1713       end Check_No_Identifier;
1714
1715       --------------------------
1716       -- Check_No_Identifiers --
1717       --------------------------
1718
1719       procedure Check_No_Identifiers is
1720          Arg_Node : Node_Id;
1721       begin
1722          if Arg_Count > 0 then
1723             Arg_Node := Arg1;
1724             while Present (Arg_Node) loop
1725                Check_No_Identifier (Arg_Node);
1726                Next (Arg_Node);
1727             end loop;
1728          end if;
1729       end Check_No_Identifiers;
1730
1731       ------------------------
1732       -- Check_No_Link_Name --
1733       ------------------------
1734
1735       procedure Check_No_Link_Name is
1736       begin
1737          if Present (Arg3)
1738            and then Chars (Arg3) = Name_Link_Name
1739          then
1740             Arg4 := Arg3;
1741          end if;
1742
1743          if Present (Arg4) then
1744             Error_Pragma_Arg
1745               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1746          end if;
1747       end Check_No_Link_Name;
1748
1749       -------------------------------
1750       -- Check_Optional_Identifier --
1751       -------------------------------
1752
1753       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1754       begin
1755          if Present (Arg)
1756            and then Nkind (Arg) = N_Pragma_Argument_Association
1757            and then Chars (Arg) /= No_Name
1758          then
1759             if Chars (Arg) /= Id then
1760                Error_Msg_Name_1 := Pname;
1761                Error_Msg_Name_2 := Id;
1762                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1763                raise Pragma_Exit;
1764             end if;
1765          end if;
1766       end Check_Optional_Identifier;
1767
1768       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1769       begin
1770          Name_Buffer (1 .. Id'Length) := Id;
1771          Name_Len := Id'Length;
1772          Check_Optional_Identifier (Arg, Name_Find);
1773       end Check_Optional_Identifier;
1774
1775       --------------------------------------
1776       -- Check_Precondition_Postcondition --
1777       --------------------------------------
1778
1779       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1780          P  : Node_Id;
1781          PO : Node_Id;
1782
1783          procedure Chain_PPC (PO : Node_Id);
1784          --  If PO is an entry or a [generic] subprogram declaration node, then
1785          --  the precondition/postcondition applies to this subprogram and the
1786          --  processing for the pragma is completed. Otherwise the pragma is
1787          --  misplaced.
1788
1789          ---------------
1790          -- Chain_PPC --
1791          ---------------
1792
1793          procedure Chain_PPC (PO : Node_Id) is
1794             S   : Entity_Id;
1795             P   : Node_Id;
1796
1797          begin
1798             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1799                if not From_Aspect_Specification (N) then
1800                   Error_Pragma
1801                     ("pragma% cannot be applied to abstract subprogram");
1802
1803                elsif Class_Present (N) then
1804                   null;
1805
1806                else
1807                   Error_Pragma
1808                     ("aspect % requires ''Class for abstract subprogram");
1809                end if;
1810
1811             --  AI05-0230: The same restriction applies to null procedures. For
1812             --  compatibility with earlier uses of the Ada pragma, apply this
1813             --  rule only to aspect specifications.
1814
1815             --  The above discrpency needs documentation. Robert is dubious
1816             --  about whether it is a good idea ???
1817
1818             elsif Nkind (PO) = N_Subprogram_Declaration
1819               and then Nkind (Specification (PO)) = N_Procedure_Specification
1820               and then Null_Present (Specification (PO))
1821               and then From_Aspect_Specification (N)
1822               and then not Class_Present (N)
1823             then
1824                Error_Pragma
1825                  ("aspect % requires ''Class for null procedure");
1826
1827             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1828                                     N_Generic_Subprogram_Declaration,
1829                                     N_Entry_Declaration)
1830             then
1831                Pragma_Misplaced;
1832             end if;
1833
1834             --  Here if we have [generic] subprogram or entry declaration
1835
1836             if Nkind (PO) = N_Entry_Declaration then
1837                S := Defining_Entity (PO);
1838             else
1839                S := Defining_Unit_Name (Specification (PO));
1840             end if;
1841
1842             --  Make sure we do not have the case of a precondition pragma when
1843             --  the Pre'Class aspect is present.
1844
1845             --  We do this by looking at pragmas already chained to the entity
1846             --  since the aspect derived pragma will be put on this list first.
1847
1848             if Pragma_Name (N) = Name_Precondition then
1849                if not From_Aspect_Specification (N) then
1850                   P := Spec_PPC_List (Contract (S));
1851                   while Present (P) loop
1852                      if Pragma_Name (P) = Name_Precondition
1853                        and then From_Aspect_Specification (P)
1854                        and then Class_Present (P)
1855                      then
1856                         Error_Msg_Sloc := Sloc (P);
1857                         Error_Pragma
1858                           ("pragma% not allowed, `Pre''Class` aspect given#");
1859                      end if;
1860
1861                      P := Next_Pragma (P);
1862                   end loop;
1863                end if;
1864             end if;
1865
1866             --  Similarly check for Pre with inherited Pre'Class. Note that
1867             --  we cover the aspect case as well here.
1868
1869             if Pragma_Name (N) = Name_Precondition
1870               and then not Class_Present (N)
1871             then
1872                declare
1873                   Inherited : constant Subprogram_List :=
1874                                 Inherited_Subprograms (S);
1875                   P         : Node_Id;
1876
1877                begin
1878                   for J in Inherited'Range loop
1879                      P := Spec_PPC_List (Contract (Inherited (J)));
1880                      while Present (P) loop
1881                         if Pragma_Name (P) = Name_Precondition
1882                           and then Class_Present (P)
1883                         then
1884                            Error_Msg_Sloc := Sloc (P);
1885                            Error_Pragma
1886                              ("pragma% not allowed, `Pre''Class` "
1887                               & "aspect inherited from#");
1888                         end if;
1889
1890                         P := Next_Pragma (P);
1891                      end loop;
1892                   end loop;
1893                end;
1894             end if;
1895
1896             --  Note: we do not analyze the pragma at this point. Instead we
1897             --  delay this analysis until the end of the declarative part in
1898             --  which the pragma appears. This implements the required delay
1899             --  in this analysis, allowing forward references. The analysis
1900             --  happens at the end of Analyze_Declarations.
1901
1902             --  Chain spec PPC pragma to list for subprogram
1903
1904             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1905             Set_Spec_PPC_List (Contract (S), N);
1906
1907             --  Return indicating spec case
1908
1909             In_Body := False;
1910             return;
1911          end Chain_PPC;
1912
1913       --  Start of processing for Check_Precondition_Postcondition
1914
1915       begin
1916          if not Is_List_Member (N) then
1917             Pragma_Misplaced;
1918          end if;
1919
1920          --  Preanalyze message argument if present. Visibility in this
1921          --  argument is established at the point of pragma occurrence.
1922
1923          if Arg_Count = 2 then
1924             Check_Optional_Identifier (Arg2, Name_Message);
1925             Preanalyze_Spec_Expression
1926               (Get_Pragma_Arg (Arg2), Standard_String);
1927          end if;
1928
1929          --  Record if pragma is disabled
1930
1931          if Check_Enabled (Pname) then
1932             Set_SCO_Pragma_Enabled (Loc);
1933          end if;
1934
1935          --  If we are within an inlined body, the legality of the pragma
1936          --  has been checked already.
1937
1938          if In_Inlined_Body then
1939             In_Body := True;
1940             return;
1941          end if;
1942
1943          --  Search prior declarations
1944
1945          P := N;
1946          while Present (Prev (P)) loop
1947             P := Prev (P);
1948
1949             --  If the previous node is a generic subprogram, do not go to to
1950             --  the original node, which is the unanalyzed tree: we need to
1951             --  attach the pre/postconditions to the analyzed version at this
1952             --  point. They get propagated to the original tree when analyzing
1953             --  the corresponding body.
1954
1955             if Nkind (P) not in N_Generic_Declaration then
1956                PO := Original_Node (P);
1957             else
1958                PO := P;
1959             end if;
1960
1961             --  Skip past prior pragma
1962
1963             if Nkind (PO) = N_Pragma then
1964                null;
1965
1966             --  Skip stuff not coming from source
1967
1968             elsif not Comes_From_Source (PO) then
1969
1970                --  The condition may apply to a subprogram instantiation
1971
1972                if Nkind (PO) = N_Subprogram_Declaration
1973                  and then Present (Generic_Parent (Specification (PO)))
1974                then
1975                   Chain_PPC (PO);
1976                   return;
1977
1978                elsif Nkind (PO) = N_Subprogram_Declaration
1979                  and then In_Instance
1980                then
1981                   Chain_PPC (PO);
1982                   return;
1983
1984                --  For all other cases of non source code, do nothing
1985
1986                else
1987                   null;
1988                end if;
1989
1990             --  Only remaining possibility is subprogram declaration
1991
1992             else
1993                Chain_PPC (PO);
1994                return;
1995             end if;
1996          end loop;
1997
1998          --  If we fall through loop, pragma is at start of list, so see if it
1999          --  is at the start of declarations of a subprogram body.
2000
2001          if Nkind (Parent (N)) = N_Subprogram_Body
2002            and then List_Containing (N) = Declarations (Parent (N))
2003          then
2004             if Operating_Mode /= Generate_Code
2005               or else Inside_A_Generic
2006             then
2007                --  Analyze pragma expression for correctness and for ASIS use
2008
2009                Preanalyze_Spec_Expression
2010                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
2011
2012                --  In ASIS mode, for a pragma generated from a source aspect,
2013                --  also analyze the original aspect expression.
2014
2015                if ASIS_Mode
2016                  and then Present (Corresponding_Aspect (N))
2017                then
2018                   Preanalyze_Spec_Expression
2019                     (Expression (Corresponding_Aspect (N)), Standard_Boolean);
2020                end if;
2021             end if;
2022
2023             In_Body := True;
2024             return;
2025
2026          --  See if it is in the pragmas after a library level subprogram
2027
2028          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2029
2030             --  In formal verification mode, analyze pragma expression for
2031             --  correctness, as it is not expanded later.
2032
2033             if Alfa_Mode then
2034                Analyze_PPC_In_Decl_Part
2035                  (N, Defining_Entity (Unit (Parent (Parent (N)))));
2036             end if;
2037
2038             Chain_PPC (Unit (Parent (Parent (N))));
2039             return;
2040          end if;
2041
2042          --  If we fall through, pragma was misplaced
2043
2044          Pragma_Misplaced;
2045       end Check_Precondition_Postcondition;
2046
2047       -----------------------------
2048       -- Check_Static_Constraint --
2049       -----------------------------
2050
2051       --  Note: for convenience in writing this procedure, in addition to
2052       --  the officially (i.e. by spec) allowed argument which is always a
2053       --  constraint, it also allows ranges and discriminant associations.
2054       --  Above is not clear ???
2055
2056       procedure Check_Static_Constraint (Constr : Node_Id) is
2057
2058          procedure Require_Static (E : Node_Id);
2059          --  Require given expression to be static expression
2060
2061          --------------------
2062          -- Require_Static --
2063          --------------------
2064
2065          procedure Require_Static (E : Node_Id) is
2066          begin
2067             if not Is_OK_Static_Expression (E) then
2068                Flag_Non_Static_Expr
2069                  ("non-static constraint not allowed in Unchecked_Union!", E);
2070                raise Pragma_Exit;
2071             end if;
2072          end Require_Static;
2073
2074       --  Start of processing for Check_Static_Constraint
2075
2076       begin
2077          case Nkind (Constr) is
2078             when N_Discriminant_Association =>
2079                Require_Static (Expression (Constr));
2080
2081             when N_Range =>
2082                Require_Static (Low_Bound (Constr));
2083                Require_Static (High_Bound (Constr));
2084
2085             when N_Attribute_Reference =>
2086                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
2087                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2088
2089             when N_Range_Constraint =>
2090                Check_Static_Constraint (Range_Expression (Constr));
2091
2092             when N_Index_Or_Discriminant_Constraint =>
2093                declare
2094                   IDC : Entity_Id;
2095                begin
2096                   IDC := First (Constraints (Constr));
2097                   while Present (IDC) loop
2098                      Check_Static_Constraint (IDC);
2099                      Next (IDC);
2100                   end loop;
2101                end;
2102
2103             when others =>
2104                null;
2105          end case;
2106       end Check_Static_Constraint;
2107
2108       ---------------------
2109       -- Check_Test_Case --
2110       ---------------------
2111
2112       procedure Check_Test_Case is
2113          P  : Node_Id;
2114          PO : Node_Id;
2115
2116          procedure Chain_TC (PO : Node_Id);
2117          --  If PO is a [generic] subprogram declaration node, then the
2118          --  test-case applies to this subprogram and the processing for the
2119          --  pragma is completed. Otherwise the pragma is misplaced.
2120
2121          --------------
2122          -- Chain_TC --
2123          --------------
2124
2125          procedure Chain_TC (PO : Node_Id) is
2126             S   : Entity_Id;
2127
2128          begin
2129             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2130                if From_Aspect_Specification (N) then
2131                   Error_Pragma
2132                     ("aspect% cannot be applied to abstract subprogram");
2133                else
2134                   Error_Pragma
2135                     ("pragma% cannot be applied to abstract subprogram");
2136                end if;
2137
2138             elsif Nkind (PO) = N_Entry_Declaration then
2139                if From_Aspect_Specification (N) then
2140                   Error_Pragma ("aspect% cannot be applied to entry");
2141                else
2142                   Error_Pragma ("pragma% cannot be applied to entry");
2143                end if;
2144
2145             elsif not Nkind_In (PO, N_Subprogram_Declaration,
2146                                     N_Generic_Subprogram_Declaration)
2147             then
2148                Pragma_Misplaced;
2149             end if;
2150
2151             --  Here if we have [generic] subprogram declaration
2152
2153             S := Defining_Unit_Name (Specification (PO));
2154
2155             --  Note: we do not analyze the pragma at this point. Instead we
2156             --  delay this analysis until the end of the declarative part in
2157             --  which the pragma appears. This implements the required delay
2158             --  in this analysis, allowing forward references. The analysis
2159             --  happens at the end of Analyze_Declarations.
2160
2161             --  There should not be another test case with the same name
2162             --  associated to this subprogram.
2163
2164             declare
2165                Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2166                TC   : Node_Id;
2167
2168             begin
2169                TC := Spec_TC_List (Contract (S));
2170                while Present (TC) loop
2171
2172                   if String_Equal
2173                     (Name, Get_Name_From_Test_Case_Pragma (TC))
2174                   then
2175                      Error_Msg_Sloc := Sloc (TC);
2176
2177                      if From_Aspect_Specification (N) then
2178                         Error_Pragma ("name for aspect% is already used#");
2179                      else
2180                         Error_Pragma ("name for pragma% is already used#");
2181                      end if;
2182                   end if;
2183
2184                   TC := Next_Pragma (TC);
2185                end loop;
2186             end;
2187
2188             --  Chain spec TC pragma to list for subprogram
2189
2190             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2191             Set_Spec_TC_List (Contract (S), N);
2192          end Chain_TC;
2193
2194       --  Start of processing for Check_Test_Case
2195
2196       begin
2197          if not Is_List_Member (N) then
2198             Pragma_Misplaced;
2199          end if;
2200
2201          --  Test cases should only appear in package spec unit
2202
2203          if Get_Source_Unit (N) = No_Unit
2204            or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2205                                  N_Package_Declaration,
2206                                  N_Generic_Package_Declaration)
2207          then
2208             Pragma_Misplaced;
2209          end if;
2210
2211          --  Search prior declarations
2212
2213          P := N;
2214          while Present (Prev (P)) loop
2215             P := Prev (P);
2216
2217             --  If the previous node is a generic subprogram, do not go to to
2218             --  the original node, which is the unanalyzed tree: we need to
2219             --  attach the test-case to the analyzed version at this point.
2220             --  They get propagated to the original tree when analyzing the
2221             --  corresponding body.
2222
2223             if Nkind (P) not in N_Generic_Declaration then
2224                PO := Original_Node (P);
2225             else
2226                PO := P;
2227             end if;
2228
2229             --  Skip past prior pragma
2230
2231             if Nkind (PO) = N_Pragma then
2232                null;
2233
2234             --  Skip stuff not coming from source
2235
2236             elsif not Comes_From_Source (PO) then
2237                null;
2238
2239             --  Only remaining possibility is subprogram declaration. First
2240             --  check that it is declared directly in a package declaration.
2241             --  This may be either the package declaration for the current unit
2242             --  being defined or a local package declaration.
2243
2244             elsif not Present (Parent (Parent (PO)))
2245               or else not Present (Parent (Parent (Parent (PO))))
2246               or else not Nkind_In (Parent (Parent (PO)),
2247                                     N_Package_Declaration,
2248                                     N_Generic_Package_Declaration)
2249             then
2250                Pragma_Misplaced;
2251
2252             else
2253                Chain_TC (PO);
2254                return;
2255             end if;
2256          end loop;
2257
2258          --  If we fall through, pragma was misplaced
2259
2260          Pragma_Misplaced;
2261       end Check_Test_Case;
2262
2263       --------------------------------------
2264       -- Check_Valid_Configuration_Pragma --
2265       --------------------------------------
2266
2267       --  A configuration pragma must appear in the context clause of a
2268       --  compilation unit, and only other pragmas may precede it. Note that
2269       --  the test also allows use in a configuration pragma file.
2270
2271       procedure Check_Valid_Configuration_Pragma is
2272       begin
2273          if not Is_Configuration_Pragma then
2274             Error_Pragma ("incorrect placement for configuration pragma%");
2275          end if;
2276       end Check_Valid_Configuration_Pragma;
2277
2278       -------------------------------------
2279       -- Check_Valid_Library_Unit_Pragma --
2280       -------------------------------------
2281
2282       procedure Check_Valid_Library_Unit_Pragma is
2283          Plist       : List_Id;
2284          Parent_Node : Node_Id;
2285          Unit_Name   : Entity_Id;
2286          Unit_Kind   : Node_Kind;
2287          Unit_Node   : Node_Id;
2288          Sindex      : Source_File_Index;
2289
2290       begin
2291          if not Is_List_Member (N) then
2292             Pragma_Misplaced;
2293
2294          else
2295             Plist := List_Containing (N);
2296             Parent_Node := Parent (Plist);
2297
2298             if Parent_Node = Empty then
2299                Pragma_Misplaced;
2300
2301             --  Case of pragma appearing after a compilation unit. In this case
2302             --  it must have an argument with the corresponding name and must
2303             --  be part of the following pragmas of its parent.
2304
2305             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2306                if Plist /= Pragmas_After (Parent_Node) then
2307                   Pragma_Misplaced;
2308
2309                elsif Arg_Count = 0 then
2310                   Error_Pragma
2311                     ("argument required if outside compilation unit");
2312
2313                else
2314                   Check_No_Identifiers;
2315                   Check_Arg_Count (1);
2316                   Unit_Node := Unit (Parent (Parent_Node));
2317                   Unit_Kind := Nkind (Unit_Node);
2318
2319                   Analyze (Get_Pragma_Arg (Arg1));
2320
2321                   if Unit_Kind = N_Generic_Subprogram_Declaration
2322                     or else Unit_Kind = N_Subprogram_Declaration
2323                   then
2324                      Unit_Name := Defining_Entity (Unit_Node);
2325
2326                   elsif Unit_Kind in N_Generic_Instantiation then
2327                      Unit_Name := Defining_Entity (Unit_Node);
2328
2329                   else
2330                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2331                   end if;
2332
2333                   if Chars (Unit_Name) /=
2334                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2335                   then
2336                      Error_Pragma_Arg
2337                        ("pragma% argument is not current unit name", Arg1);
2338                   end if;
2339
2340                   if Ekind (Unit_Name) = E_Package
2341                     and then Present (Renamed_Entity (Unit_Name))
2342                   then
2343                      Error_Pragma ("pragma% not allowed for renamed package");
2344                   end if;
2345                end if;
2346
2347             --  Pragma appears other than after a compilation unit
2348
2349             else
2350                --  Here we check for the generic instantiation case and also
2351                --  for the case of processing a generic formal package. We
2352                --  detect these cases by noting that the Sloc on the node
2353                --  does not belong to the current compilation unit.
2354
2355                Sindex := Source_Index (Current_Sem_Unit);
2356
2357                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2358                   Rewrite (N, Make_Null_Statement (Loc));
2359                   return;
2360
2361                --  If before first declaration, the pragma applies to the
2362                --  enclosing unit, and the name if present must be this name.
2363
2364                elsif Is_Before_First_Decl (N, Plist) then
2365                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2366                   Unit_Kind := Nkind (Unit_Node);
2367
2368                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2369                      Pragma_Misplaced;
2370
2371                   elsif Unit_Kind = N_Subprogram_Body
2372                     and then not Acts_As_Spec (Unit_Node)
2373                   then
2374                      Pragma_Misplaced;
2375
2376                   elsif Nkind (Parent_Node) = N_Package_Body then
2377                      Pragma_Misplaced;
2378
2379                   elsif Nkind (Parent_Node) = N_Package_Specification
2380                     and then Plist = Private_Declarations (Parent_Node)
2381                   then
2382                      Pragma_Misplaced;
2383
2384                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2385                            or else Nkind (Parent_Node) =
2386                                              N_Generic_Subprogram_Declaration)
2387                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2388                   then
2389                      Pragma_Misplaced;
2390
2391                   elsif Arg_Count > 0 then
2392                      Analyze (Get_Pragma_Arg (Arg1));
2393
2394                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2395                         Error_Pragma_Arg
2396                           ("name in pragma% must be enclosing unit", Arg1);
2397                      end if;
2398
2399                   --  It is legal to have no argument in this context
2400
2401                   else
2402                      return;
2403                   end if;
2404
2405                --  Error if not before first declaration. This is because a
2406                --  library unit pragma argument must be the name of a library
2407                --  unit (RM 10.1.5(7)), but the only names permitted in this
2408                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2409                --  generic subprogram declarations or generic instantiations.
2410
2411                else
2412                   Error_Pragma
2413                     ("pragma% misplaced, must be before first declaration");
2414                end if;
2415             end if;
2416          end if;
2417       end Check_Valid_Library_Unit_Pragma;
2418
2419       -------------------
2420       -- Check_Variant --
2421       -------------------
2422
2423       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2424          Clist : constant Node_Id := Component_List (Variant);
2425          Comp  : Node_Id;
2426
2427       begin
2428          if not Is_Non_Empty_List (Component_Items (Clist)) then
2429             Error_Msg_N
2430               ("Unchecked_Union may not have empty component list",
2431                Variant);
2432             return;
2433          end if;
2434
2435          Comp := First (Component_Items (Clist));
2436          while Present (Comp) loop
2437             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2438             Next (Comp);
2439          end loop;
2440       end Check_Variant;
2441
2442       ------------------
2443       -- Error_Pragma --
2444       ------------------
2445
2446       procedure Error_Pragma (Msg : String) is
2447          MsgF : String := Msg;
2448       begin
2449          Error_Msg_Name_1 := Pname;
2450          Fix_Error (MsgF);
2451          Error_Msg_N (MsgF, N);
2452          raise Pragma_Exit;
2453       end Error_Pragma;
2454
2455       ----------------------
2456       -- Error_Pragma_Arg --
2457       ----------------------
2458
2459       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2460          MsgF : String := Msg;
2461       begin
2462          Error_Msg_Name_1 := Pname;
2463          Fix_Error (MsgF);
2464          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2465          raise Pragma_Exit;
2466       end Error_Pragma_Arg;
2467
2468       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2469          MsgF : String := Msg1;
2470       begin
2471          Error_Msg_Name_1 := Pname;
2472          Fix_Error (MsgF);
2473          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2474          Error_Pragma_Arg (Msg2, Arg);
2475       end Error_Pragma_Arg;
2476
2477       ----------------------------
2478       -- Error_Pragma_Arg_Ident --
2479       ----------------------------
2480
2481       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2482          MsgF : String := Msg;
2483       begin
2484          Error_Msg_Name_1 := Pname;
2485          Fix_Error (MsgF);
2486          Error_Msg_N (MsgF, Arg);
2487          raise Pragma_Exit;
2488       end Error_Pragma_Arg_Ident;
2489
2490       ----------------------
2491       -- Error_Pragma_Ref --
2492       ----------------------
2493
2494       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2495          MsgF : String := Msg;
2496       begin
2497          Error_Msg_Name_1 := Pname;
2498          Fix_Error (MsgF);
2499          Error_Msg_Sloc   := Sloc (Ref);
2500          Error_Msg_NE (MsgF, N, Ref);
2501          raise Pragma_Exit;
2502       end Error_Pragma_Ref;
2503
2504       ------------------------
2505       -- Find_Lib_Unit_Name --
2506       ------------------------
2507
2508       function Find_Lib_Unit_Name return Entity_Id is
2509       begin
2510          --  Return inner compilation unit entity, for case of nested
2511          --  categorization pragmas. This happens in generic unit.
2512
2513          if Nkind (Parent (N)) = N_Package_Specification
2514            and then Defining_Entity (Parent (N)) /= Current_Scope
2515          then
2516             return Defining_Entity (Parent (N));
2517          else
2518             return Current_Scope;
2519          end if;
2520       end Find_Lib_Unit_Name;
2521
2522       ----------------------------
2523       -- Find_Program_Unit_Name --
2524       ----------------------------
2525
2526       procedure Find_Program_Unit_Name (Id : Node_Id) is
2527          Unit_Name : Entity_Id;
2528          Unit_Kind : Node_Kind;
2529          P         : constant Node_Id := Parent (N);
2530
2531       begin
2532          if Nkind (P) = N_Compilation_Unit then
2533             Unit_Kind := Nkind (Unit (P));
2534
2535             if Unit_Kind = N_Subprogram_Declaration
2536               or else Unit_Kind = N_Package_Declaration
2537               or else Unit_Kind in N_Generic_Declaration
2538             then
2539                Unit_Name := Defining_Entity (Unit (P));
2540
2541                if Chars (Id) = Chars (Unit_Name) then
2542                   Set_Entity (Id, Unit_Name);
2543                   Set_Etype (Id, Etype (Unit_Name));
2544                else
2545                   Set_Etype (Id, Any_Type);
2546                   Error_Pragma
2547                     ("cannot find program unit referenced by pragma%");
2548                end if;
2549
2550             else
2551                Set_Etype (Id, Any_Type);
2552                Error_Pragma ("pragma% inapplicable to this unit");
2553             end if;
2554
2555          else
2556             Analyze (Id);
2557          end if;
2558       end Find_Program_Unit_Name;
2559
2560       -----------------------------------------
2561       -- Find_Unique_Parameterless_Procedure --
2562       -----------------------------------------
2563
2564       function Find_Unique_Parameterless_Procedure
2565         (Name : Entity_Id;
2566          Arg  : Node_Id) return Entity_Id
2567       is
2568          Proc : Entity_Id := Empty;
2569
2570       begin
2571          --  The body of this procedure needs some comments ???
2572
2573          if not Is_Entity_Name (Name) then
2574             Error_Pragma_Arg
2575               ("argument of pragma% must be entity name", Arg);
2576
2577          elsif not Is_Overloaded (Name) then
2578             Proc := Entity (Name);
2579
2580             if Ekind (Proc) /= E_Procedure
2581               or else Present (First_Formal (Proc))
2582             then
2583                Error_Pragma_Arg
2584                  ("argument of pragma% must be parameterless procedure", Arg);
2585             end if;
2586
2587          else
2588             declare
2589                Found : Boolean := False;
2590                It    : Interp;
2591                Index : Interp_Index;
2592
2593             begin
2594                Get_First_Interp (Name, Index, It);
2595                while Present (It.Nam) loop
2596                   Proc := It.Nam;
2597
2598                   if Ekind (Proc) = E_Procedure
2599                     and then No (First_Formal (Proc))
2600                   then
2601                      if not Found then
2602                         Found := True;
2603                         Set_Entity (Name, Proc);
2604                         Set_Is_Overloaded (Name, False);
2605                      else
2606                         Error_Pragma_Arg
2607                           ("ambiguous handler name for pragma% ", Arg);
2608                      end if;
2609                   end if;
2610
2611                   Get_Next_Interp (Index, It);
2612                end loop;
2613
2614                if not Found then
2615                   Error_Pragma_Arg
2616                     ("argument of pragma% must be parameterless procedure",
2617                      Arg);
2618                else
2619                   Proc := Entity (Name);
2620                end if;
2621             end;
2622          end if;
2623
2624          return Proc;
2625       end Find_Unique_Parameterless_Procedure;
2626
2627       ---------------
2628       -- Fix_Error --
2629       ---------------
2630
2631       procedure Fix_Error (Msg : in out String) is
2632       begin
2633          if From_Aspect_Specification (N) then
2634             for J in Msg'First .. Msg'Last - 5 loop
2635                if Msg (J .. J + 5) = "pragma" then
2636                   Msg (J .. J + 5) := "aspect";
2637                end if;
2638             end loop;
2639
2640             if Error_Msg_Name_1 = Name_Precondition then
2641                Error_Msg_Name_1 := Name_Pre;
2642             elsif Error_Msg_Name_1 = Name_Postcondition then
2643                Error_Msg_Name_1 := Name_Post;
2644             end if;
2645          end if;
2646       end Fix_Error;
2647
2648       -------------------------
2649       -- Gather_Associations --
2650       -------------------------
2651
2652       procedure Gather_Associations
2653         (Names : Name_List;
2654          Args  : out Args_List)
2655       is
2656          Arg : Node_Id;
2657
2658       begin
2659          --  Initialize all parameters to Empty
2660
2661          for J in Args'Range loop
2662             Args (J) := Empty;
2663          end loop;
2664
2665          --  That's all we have to do if there are no argument associations
2666
2667          if No (Pragma_Argument_Associations (N)) then
2668             return;
2669          end if;
2670
2671          --  Otherwise first deal with any positional parameters present
2672
2673          Arg := First (Pragma_Argument_Associations (N));
2674          for Index in Args'Range loop
2675             exit when No (Arg) or else Chars (Arg) /= No_Name;
2676             Args (Index) := Get_Pragma_Arg (Arg);
2677             Next (Arg);
2678          end loop;
2679
2680          --  Positional parameters all processed, if any left, then we
2681          --  have too many positional parameters.
2682
2683          if Present (Arg) and then Chars (Arg) = No_Name then
2684             Error_Pragma_Arg
2685               ("too many positional associations for pragma%", Arg);
2686          end if;
2687
2688          --  Process named parameters if any are present
2689
2690          while Present (Arg) loop
2691             if Chars (Arg) = No_Name then
2692                Error_Pragma_Arg
2693                  ("positional association cannot follow named association",
2694                   Arg);
2695
2696             else
2697                for Index in Names'Range loop
2698                   if Names (Index) = Chars (Arg) then
2699                      if Present (Args (Index)) then
2700                         Error_Pragma_Arg
2701                           ("duplicate argument association for pragma%", Arg);
2702                      else
2703                         Args (Index) := Get_Pragma_Arg (Arg);
2704                         exit;
2705                      end if;
2706                   end if;
2707
2708                   if Index = Names'Last then
2709                      Error_Msg_Name_1 := Pname;
2710                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2711
2712                      --  Check for possible misspelling
2713
2714                      for Index1 in Names'Range loop
2715                         if Is_Bad_Spelling_Of
2716                              (Chars (Arg), Names (Index1))
2717                         then
2718                            Error_Msg_Name_1 := Names (Index1);
2719                            Error_Msg_N -- CODEFIX
2720                              ("\possible misspelling of%", Arg);
2721                            exit;
2722                         end if;
2723                      end loop;
2724
2725                      raise Pragma_Exit;
2726                   end if;
2727                end loop;
2728             end if;
2729
2730             Next (Arg);
2731          end loop;
2732       end Gather_Associations;
2733
2734       -----------------
2735       -- GNAT_Pragma --
2736       -----------------
2737
2738       procedure GNAT_Pragma is
2739       begin
2740          Check_Restriction (No_Implementation_Pragmas, N);
2741       end GNAT_Pragma;
2742
2743       --------------------------
2744       -- Is_Before_First_Decl --
2745       --------------------------
2746
2747       function Is_Before_First_Decl
2748         (Pragma_Node : Node_Id;
2749          Decls       : List_Id) return Boolean
2750       is
2751          Item : Node_Id := First (Decls);
2752
2753       begin
2754          --  Only other pragmas can come before this pragma
2755
2756          loop
2757             if No (Item) or else Nkind (Item) /= N_Pragma then
2758                return False;
2759
2760             elsif Item = Pragma_Node then
2761                return True;
2762             end if;
2763
2764             Next (Item);
2765          end loop;
2766       end Is_Before_First_Decl;
2767
2768       -----------------------------
2769       -- Is_Configuration_Pragma --
2770       -----------------------------
2771
2772       --  A configuration pragma must appear in the context clause of a
2773       --  compilation unit, and only other pragmas may precede it. Note that
2774       --  the test below also permits use in a configuration pragma file.
2775
2776       function Is_Configuration_Pragma return Boolean is
2777          Lis : constant List_Id := List_Containing (N);
2778          Par : constant Node_Id := Parent (N);
2779          Prg : Node_Id;
2780
2781       begin
2782          --  If no parent, then we are in the configuration pragma file,
2783          --  so the placement is definitely appropriate.
2784
2785          if No (Par) then
2786             return True;
2787
2788          --  Otherwise we must be in the context clause of a compilation unit
2789          --  and the only thing allowed before us in the context list is more
2790          --  configuration pragmas.
2791
2792          elsif Nkind (Par) = N_Compilation_Unit
2793            and then Context_Items (Par) = Lis
2794          then
2795             Prg := First (Lis);
2796
2797             loop
2798                if Prg = N then
2799                   return True;
2800                elsif Nkind (Prg) /= N_Pragma then
2801                   return False;
2802                end if;
2803
2804                Next (Prg);
2805             end loop;
2806
2807          else
2808             return False;
2809          end if;
2810       end Is_Configuration_Pragma;
2811
2812       --------------------------
2813       -- Is_In_Context_Clause --
2814       --------------------------
2815
2816       function Is_In_Context_Clause return Boolean is
2817          Plist       : List_Id;
2818          Parent_Node : Node_Id;
2819
2820       begin
2821          if not Is_List_Member (N) then
2822             return False;
2823
2824          else
2825             Plist := List_Containing (N);
2826             Parent_Node := Parent (Plist);
2827
2828             if Parent_Node = Empty
2829               or else Nkind (Parent_Node) /= N_Compilation_Unit
2830               or else Context_Items (Parent_Node) /= Plist
2831             then
2832                return False;
2833             end if;
2834          end if;
2835
2836          return True;
2837       end Is_In_Context_Clause;
2838
2839       ---------------------------------
2840       -- Is_Static_String_Expression --
2841       ---------------------------------
2842
2843       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2844          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2845
2846       begin
2847          Analyze_And_Resolve (Argx);
2848          return Is_OK_Static_Expression (Argx)
2849            and then Nkind (Argx) = N_String_Literal;
2850       end Is_Static_String_Expression;
2851
2852       ----------------------
2853       -- Pragma_Misplaced --
2854       ----------------------
2855
2856       procedure Pragma_Misplaced is
2857       begin
2858          Error_Pragma ("incorrect placement of pragma%");
2859       end Pragma_Misplaced;
2860
2861       ------------------------------------
2862       -- Process Atomic_Shared_Volatile --
2863       ------------------------------------
2864
2865       procedure Process_Atomic_Shared_Volatile is
2866          E_Id : Node_Id;
2867          E    : Entity_Id;
2868          D    : Node_Id;
2869          K    : Node_Kind;
2870          Utyp : Entity_Id;
2871
2872          procedure Set_Atomic (E : Entity_Id);
2873          --  Set given type as atomic, and if no explicit alignment was given,
2874          --  set alignment to unknown, since back end knows what the alignment
2875          --  requirements are for atomic arrays. Note: this step is necessary
2876          --  for derived types.
2877
2878          ----------------
2879          -- Set_Atomic --
2880          ----------------
2881
2882          procedure Set_Atomic (E : Entity_Id) is
2883          begin
2884             Set_Is_Atomic (E);
2885
2886             if not Has_Alignment_Clause (E) then
2887                Set_Alignment (E, Uint_0);
2888             end if;
2889          end Set_Atomic;
2890
2891       --  Start of processing for Process_Atomic_Shared_Volatile
2892
2893       begin
2894          Check_Ada_83_Warning;
2895          Check_No_Identifiers;
2896          Check_Arg_Count (1);
2897          Check_Arg_Is_Local_Name (Arg1);
2898          E_Id := Get_Pragma_Arg (Arg1);
2899
2900          if Etype (E_Id) = Any_Type then
2901             return;
2902          end if;
2903
2904          E := Entity (E_Id);
2905          D := Declaration_Node (E);
2906          K := Nkind (D);
2907
2908          --  Check duplicate before we chain ourselves!
2909
2910          Check_Duplicate_Pragma (E);
2911
2912          --  Now check appropriateness of the entity
2913
2914          if Is_Type (E) then
2915             if Rep_Item_Too_Early (E, N)
2916                  or else
2917                Rep_Item_Too_Late (E, N)
2918             then
2919                return;
2920             else
2921                Check_First_Subtype (Arg1);
2922             end if;
2923
2924             if Prag_Id /= Pragma_Volatile then
2925                Set_Atomic (E);
2926                Set_Atomic (Underlying_Type (E));
2927                Set_Atomic (Base_Type (E));
2928             end if;
2929
2930             --  Attribute belongs on the base type. If the view of the type is
2931             --  currently private, it also belongs on the underlying type.
2932
2933             Set_Is_Volatile (Base_Type (E));
2934             Set_Is_Volatile (Underlying_Type (E));
2935
2936             Set_Treat_As_Volatile (E);
2937             Set_Treat_As_Volatile (Underlying_Type (E));
2938
2939          elsif K = N_Object_Declaration
2940            or else (K = N_Component_Declaration
2941                      and then Original_Record_Component (E) = E)
2942          then
2943             if Rep_Item_Too_Late (E, N) then
2944                return;
2945             end if;
2946
2947             if Prag_Id /= Pragma_Volatile then
2948                Set_Is_Atomic (E);
2949
2950                --  If the object declaration has an explicit initialization, a
2951                --  temporary may have to be created to hold the expression, to
2952                --  ensure that access to the object remain atomic.
2953
2954                if Nkind (Parent (E)) = N_Object_Declaration
2955                  and then Present (Expression (Parent (E)))
2956                then
2957                   Set_Has_Delayed_Freeze (E);
2958                end if;
2959
2960                --  An interesting improvement here. If an object of type X is
2961                --  declared atomic, and the type X is not atomic, that's a
2962                --  pity, since it may not have appropriate alignment etc. We
2963                --  can rescue this in the special case where the object and
2964                --  type are in the same unit by just setting the type as
2965                --  atomic, so that the back end will process it as atomic.
2966
2967                Utyp := Underlying_Type (Etype (E));
2968
2969                if Present (Utyp)
2970                  and then Sloc (E) > No_Location
2971                  and then Sloc (Utyp) > No_Location
2972                  and then
2973                    Get_Source_File_Index (Sloc (E)) =
2974                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2975                then
2976                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2977                end if;
2978             end if;
2979
2980             Set_Is_Volatile (E);
2981             Set_Treat_As_Volatile (E);
2982
2983          else
2984             Error_Pragma_Arg
2985               ("inappropriate entity for pragma%", Arg1);
2986          end if;
2987       end Process_Atomic_Shared_Volatile;
2988
2989       -------------------------------------------
2990       -- Process_Compile_Time_Warning_Or_Error --
2991       -------------------------------------------
2992
2993       procedure Process_Compile_Time_Warning_Or_Error is
2994          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2995
2996       begin
2997          Check_Arg_Count (2);
2998          Check_No_Identifiers;
2999          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
3000          Analyze_And_Resolve (Arg1x, Standard_Boolean);
3001
3002          if Compile_Time_Known_Value (Arg1x) then
3003             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
3004                declare
3005                   Str   : constant String_Id :=
3006                             Strval (Get_Pragma_Arg (Arg2));
3007                   Len   : constant Int := String_Length (Str);
3008                   Cont  : Boolean;
3009                   Ptr   : Nat;
3010                   CC    : Char_Code;
3011                   C     : Character;
3012                   Cent  : constant Entity_Id :=
3013                             Cunit_Entity (Current_Sem_Unit);
3014
3015                   Force : constant Boolean :=
3016                             Prag_Id = Pragma_Compile_Time_Warning
3017                               and then
3018                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3019                               and then (Ekind (Cent) /= E_Package
3020                                           or else not In_Private_Part (Cent));
3021                   --  Set True if this is the warning case, and we are in the
3022                   --  visible part of a package spec, or in a subprogram spec,
3023                   --  in which case we want to force the client to see the
3024                   --  warning, even though it is not in the main unit.
3025
3026                begin
3027                   --  Loop through segments of message separated by line feeds.
3028                   --  We output these segments as separate messages with
3029                   --  continuation marks for all but the first.
3030
3031                   Cont := False;
3032                   Ptr := 1;
3033                   loop
3034                      Error_Msg_Strlen := 0;
3035
3036                      --  Loop to copy characters from argument to error message
3037                      --  string buffer.
3038
3039                      loop
3040                         exit when Ptr > Len;
3041                         CC := Get_String_Char (Str, Ptr);
3042                         Ptr := Ptr + 1;
3043
3044                         --  Ignore wide chars ??? else store character
3045
3046                         if In_Character_Range (CC) then
3047                            C := Get_Character (CC);
3048                            exit when C = ASCII.LF;
3049                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
3050                            Error_Msg_String (Error_Msg_Strlen) := C;
3051                         end if;
3052                      end loop;
3053
3054                      --  Here with one line ready to go
3055
3056                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3057
3058                      --  If this is a warning in a spec, then we want clients
3059                      --  to see the warning, so mark the message with the
3060                      --  special sequence !! to force the warning. In the case
3061                      --  of a package spec, we do not force this if we are in
3062                      --  the private part of the spec.
3063
3064                      if Force then
3065                         if Cont = False then
3066                            Error_Msg_N ("<~!!", Arg1);
3067                            Cont := True;
3068                         else
3069                            Error_Msg_N ("\<~!!", Arg1);
3070                         end if;
3071
3072                      --  Error, rather than warning, or in a body, so we do not
3073                      --  need to force visibility for client (error will be
3074                      --  output in any case, and this is the situation in which
3075                      --  we do not want a client to get a warning, since the
3076                      --  warning is in the body or the spec private part).
3077
3078                      else
3079                         if Cont = False then
3080                            Error_Msg_N ("<~", Arg1);
3081                            Cont := True;
3082                         else
3083                            Error_Msg_N ("\<~", Arg1);
3084                         end if;
3085                      end if;
3086
3087                      exit when Ptr > Len;
3088                   end loop;
3089                end;
3090             end if;
3091          end if;
3092       end Process_Compile_Time_Warning_Or_Error;
3093
3094       ------------------------
3095       -- Process_Convention --
3096       ------------------------
3097
3098       procedure Process_Convention
3099         (C   : out Convention_Id;
3100          Ent : out Entity_Id)
3101       is
3102          Id        : Node_Id;
3103          E         : Entity_Id;
3104          E1        : Entity_Id;
3105          Cname     : Name_Id;
3106          Comp_Unit : Unit_Number_Type;
3107
3108          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3109          --  Called if we have more than one Export/Import/Convention pragma.
3110          --  This is generally illegal, but we have a special case of allowing
3111          --  Import and Interface to coexist if they specify the convention in
3112          --  a consistent manner. We are allowed to do this, since Interface is
3113          --  an implementation defined pragma, and we choose to do it since we
3114          --  know Rational allows this combination. S is the entity id of the
3115          --  subprogram in question. This procedure also sets the special flag
3116          --  Import_Interface_Present in both pragmas in the case where we do
3117          --  have matching Import and Interface pragmas.
3118
3119          procedure Set_Convention_From_Pragma (E : Entity_Id);
3120          --  Set convention in entity E, and also flag that the entity has a
3121          --  convention pragma. If entity is for a private or incomplete type,
3122          --  also set convention and flag on underlying type. This procedure
3123          --  also deals with the special case of C_Pass_By_Copy convention.
3124
3125          -------------------------------
3126          -- Diagnose_Multiple_Pragmas --
3127          -------------------------------
3128
3129          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3130             Pdec : constant Node_Id := Declaration_Node (S);
3131             Decl : Node_Id;
3132             Err  : Boolean;
3133
3134             function Same_Convention (Decl : Node_Id) return Boolean;
3135             --  Decl is a pragma node. This function returns True if this
3136             --  pragma has a first argument that is an identifier with a
3137             --  Chars field corresponding to the Convention_Id C.
3138
3139             function Same_Name (Decl : Node_Id) return Boolean;
3140             --  Decl is a pragma node. This function returns True if this
3141             --  pragma has a second argument that is an identifier with a
3142             --  Chars field that matches the Chars of the current subprogram.
3143
3144             ---------------------
3145             -- Same_Convention --
3146             ---------------------
3147
3148             function Same_Convention (Decl : Node_Id) return Boolean is
3149                Arg1 : constant Node_Id :=
3150                         First (Pragma_Argument_Associations (Decl));
3151
3152             begin
3153                if Present (Arg1) then
3154                   declare
3155                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3156                   begin
3157                      if Nkind (Arg) = N_Identifier
3158                        and then Is_Convention_Name (Chars (Arg))
3159                        and then Get_Convention_Id (Chars (Arg)) = C
3160                      then
3161                         return True;
3162                      end if;
3163                   end;
3164                end if;
3165
3166                return False;
3167             end Same_Convention;
3168
3169             ---------------
3170             -- Same_Name --
3171             ---------------
3172
3173             function Same_Name (Decl : Node_Id) return Boolean is
3174                Arg1 : constant Node_Id :=
3175                         First (Pragma_Argument_Associations (Decl));
3176                Arg2 : Node_Id;
3177
3178             begin
3179                if No (Arg1) then
3180                   return False;
3181                end if;
3182
3183                Arg2 := Next (Arg1);
3184
3185                if No (Arg2) then
3186                   return False;
3187                end if;
3188
3189                declare
3190                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3191                begin
3192                   if Nkind (Arg) = N_Identifier
3193                     and then Chars (Arg) = Chars (S)
3194                   then
3195                      return True;
3196                   end if;
3197                end;
3198
3199                return False;
3200             end Same_Name;
3201
3202          --  Start of processing for Diagnose_Multiple_Pragmas
3203
3204          begin
3205             Err := True;
3206
3207             --  Definitely give message if we have Convention/Export here
3208
3209             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3210                null;
3211
3212                --  If we have an Import or Export, scan back from pragma to
3213                --  find any previous pragma applying to the same procedure.
3214                --  The scan will be terminated by the start of the list, or
3215                --  hitting the subprogram declaration. This won't allow one
3216                --  pragma to appear in the public part and one in the private
3217                --  part, but that seems very unlikely in practice.
3218
3219             else
3220                Decl := Prev (N);
3221                while Present (Decl) and then Decl /= Pdec loop
3222
3223                   --  Look for pragma with same name as us
3224
3225                   if Nkind (Decl) = N_Pragma
3226                     and then Same_Name (Decl)
3227                   then
3228                      --  Give error if same as our pragma or Export/Convention
3229
3230                      if Pragma_Name (Decl) = Name_Export
3231                           or else
3232                         Pragma_Name (Decl) = Name_Convention
3233                           or else
3234                         Pragma_Name (Decl) = Pragma_Name (N)
3235                      then
3236                         exit;
3237
3238                      --  Case of Import/Interface or the other way round
3239
3240                      elsif Pragma_Name (Decl) = Name_Interface
3241                              or else
3242                            Pragma_Name (Decl) = Name_Import
3243                      then
3244                         --  Here we know that we have Import and Interface. It
3245                         --  doesn't matter which way round they are. See if
3246                         --  they specify the same convention. If so, all OK,
3247                         --  and set special flags to stop other messages
3248
3249                         if Same_Convention (Decl) then
3250                            Set_Import_Interface_Present (N);
3251                            Set_Import_Interface_Present (Decl);
3252                            Err := False;
3253
3254                         --  If different conventions, special message
3255
3256                         else
3257                            Error_Msg_Sloc := Sloc (Decl);
3258                            Error_Pragma_Arg
3259                              ("convention differs from that given#", Arg1);
3260                            return;
3261                         end if;
3262                      end if;
3263                   end if;
3264
3265                   Next (Decl);
3266                end loop;
3267             end if;
3268
3269             --  Give message if needed if we fall through those tests
3270
3271             if Err then
3272                Error_Pragma_Arg
3273                  ("at most one Convention/Export/Import pragma is allowed",
3274                   Arg2);
3275             end if;
3276          end Diagnose_Multiple_Pragmas;
3277
3278          --------------------------------
3279          -- Set_Convention_From_Pragma --
3280          --------------------------------
3281
3282          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3283          begin
3284             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3285             --  for an overridden dispatching operation. Technically this is
3286             --  an amendment and should only be done in Ada 2005 mode. However,
3287             --  this is clearly a mistake, since the problem that is addressed
3288             --  by this AI is that there is a clear gap in the RM!
3289
3290             if Is_Dispatching_Operation (E)
3291               and then Present (Overridden_Operation (E))
3292               and then C /= Convention (Overridden_Operation (E))
3293             then
3294                Error_Pragma_Arg
3295                  ("cannot change convention for " &
3296                   "overridden dispatching operation",
3297                   Arg1);
3298             end if;
3299
3300             --  Set the convention
3301
3302             Set_Convention (E, C);
3303             Set_Has_Convention_Pragma (E);
3304
3305             if Is_Incomplete_Or_Private_Type (E)
3306               and then Present (Underlying_Type (E))
3307             then
3308                Set_Convention            (Underlying_Type (E), C);
3309                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3310             end if;
3311
3312             --  A class-wide type should inherit the convention of the specific
3313             --  root type (although this isn't specified clearly by the RM).
3314
3315             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3316                Set_Convention (Class_Wide_Type (E), C);
3317             end if;
3318
3319             --  If the entity is a record type, then check for special case of
3320             --  C_Pass_By_Copy, which is treated the same as C except that the
3321             --  special record flag is set. This convention is only permitted
3322             --  on record types (see AI95-00131).
3323
3324             if Cname = Name_C_Pass_By_Copy then
3325                if Is_Record_Type (E) then
3326                   Set_C_Pass_By_Copy (Base_Type (E));
3327                elsif Is_Incomplete_Or_Private_Type (E)
3328                  and then Is_Record_Type (Underlying_Type (E))
3329                then
3330                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3331                else
3332                   Error_Pragma_Arg
3333                     ("C_Pass_By_Copy convention allowed only for record type",
3334                      Arg2);
3335                end if;
3336             end if;
3337
3338             --  If the entity is a derived boolean type, check for the special
3339             --  case of convention C, C++, or Fortran, where we consider any
3340             --  nonzero value to represent true.
3341
3342             if Is_Discrete_Type (E)
3343               and then Root_Type (Etype (E)) = Standard_Boolean
3344               and then
3345                 (C = Convention_C
3346                    or else
3347                  C = Convention_CPP
3348                    or else
3349                  C = Convention_Fortran)
3350             then
3351                Set_Nonzero_Is_True (Base_Type (E));
3352             end if;
3353          end Set_Convention_From_Pragma;
3354
3355       --  Start of processing for Process_Convention
3356
3357       begin
3358          Check_At_Least_N_Arguments (2);
3359          Check_Optional_Identifier (Arg1, Name_Convention);
3360          Check_Arg_Is_Identifier (Arg1);
3361          Cname := Chars (Get_Pragma_Arg (Arg1));
3362
3363          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3364          --  tested again below to set the critical flag).
3365
3366          if Cname = Name_C_Pass_By_Copy then
3367             C := Convention_C;
3368
3369          --  Otherwise we must have something in the standard convention list
3370
3371          elsif Is_Convention_Name (Cname) then
3372             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3373
3374          --  In DEC VMS, it seems that there is an undocumented feature that
3375          --  any unrecognized convention is treated as the default, which for
3376          --  us is convention C. It does not seem so terrible to do this
3377          --  unconditionally, silently in the VMS case, and with a warning
3378          --  in the non-VMS case.
3379
3380          else
3381             if Warn_On_Export_Import and not OpenVMS_On_Target then
3382                Error_Msg_N
3383                  ("?unrecognized convention name, C assumed",
3384                   Get_Pragma_Arg (Arg1));
3385             end if;
3386
3387             C := Convention_C;
3388          end if;
3389
3390          Check_Optional_Identifier (Arg2, Name_Entity);
3391          Check_Arg_Is_Local_Name (Arg2);
3392
3393          Id := Get_Pragma_Arg (Arg2);
3394          Analyze (Id);
3395
3396          if not Is_Entity_Name (Id) then
3397             Error_Pragma_Arg ("entity name required", Arg2);
3398          end if;
3399
3400          E := Entity (Id);
3401
3402          --  Set entity to return
3403
3404          Ent := E;
3405
3406          --  Ada_Pass_By_Copy special checking
3407
3408          if C = Convention_Ada_Pass_By_Copy then
3409             if not Is_First_Subtype (E) then
3410                Error_Pragma_Arg
3411                  ("convention `Ada_Pass_By_Copy` only "
3412                   & "allowed for types", Arg2);
3413             end if;
3414
3415             if Is_By_Reference_Type (E) then
3416                Error_Pragma_Arg
3417                  ("convention `Ada_Pass_By_Copy` not allowed for "
3418                   & "by-reference type", Arg1);
3419             end if;
3420          end if;
3421
3422          --  Ada_Pass_By_Reference special checking
3423
3424          if C = Convention_Ada_Pass_By_Reference then
3425             if not Is_First_Subtype (E) then
3426                Error_Pragma_Arg
3427                  ("convention `Ada_Pass_By_Reference` only "
3428                   & "allowed for types", Arg2);
3429             end if;
3430
3431             if Is_By_Copy_Type (E) then
3432                Error_Pragma_Arg
3433                  ("convention `Ada_Pass_By_Reference` not allowed for "
3434                   & "by-copy type", Arg1);
3435             end if;
3436          end if;
3437
3438          --  Go to renamed subprogram if present, since convention applies to
3439          --  the actual renamed entity, not to the renaming entity. If the
3440          --  subprogram is inherited, go to parent subprogram.
3441
3442          if Is_Subprogram (E)
3443            and then Present (Alias (E))
3444          then
3445             if Nkind (Parent (Declaration_Node (E))) =
3446                                        N_Subprogram_Renaming_Declaration
3447             then
3448                if Scope (E) /= Scope (Alias (E)) then
3449                   Error_Pragma_Ref
3450                     ("cannot apply pragma% to non-local entity&#", E);
3451                end if;
3452
3453                E := Alias (E);
3454
3455             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3456                                         N_Private_Extension_Declaration)
3457               and then Scope (E) = Scope (Alias (E))
3458             then
3459                E := Alias (E);
3460
3461                --  Return the parent subprogram the entity was inherited from
3462
3463                Ent := E;
3464             end if;
3465          end if;
3466
3467          --  Check that we are not applying this to a specless body
3468
3469          if Is_Subprogram (E)
3470            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3471          then
3472             Error_Pragma
3473               ("pragma% requires separate spec and must come before body");
3474          end if;
3475
3476          --  Check that we are not applying this to a named constant
3477
3478          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3479             Error_Msg_Name_1 := Pname;
3480             Error_Msg_N
3481               ("cannot apply pragma% to named constant!",
3482                Get_Pragma_Arg (Arg2));
3483             Error_Pragma_Arg
3484               ("\supply appropriate type for&!", Arg2);
3485          end if;
3486
3487          if Ekind (E) = E_Enumeration_Literal then
3488             Error_Pragma ("enumeration literal not allowed for pragma%");
3489          end if;
3490
3491          --  Check for rep item appearing too early or too late
3492
3493          if Etype (E) = Any_Type
3494            or else Rep_Item_Too_Early (E, N)
3495          then
3496             raise Pragma_Exit;
3497
3498          elsif Present (Underlying_Type (E)) then
3499             E := Underlying_Type (E);
3500          end if;
3501
3502          if Rep_Item_Too_Late (E, N) then
3503             raise Pragma_Exit;
3504          end if;
3505
3506          if Has_Convention_Pragma (E) then
3507             Diagnose_Multiple_Pragmas (E);
3508
3509          elsif Convention (E) = Convention_Protected
3510            or else Ekind (Scope (E)) = E_Protected_Type
3511          then
3512             Error_Pragma_Arg
3513               ("a protected operation cannot be given a different convention",
3514                 Arg2);
3515          end if;
3516
3517          --  For Intrinsic, a subprogram is required
3518
3519          if C = Convention_Intrinsic
3520            and then not Is_Subprogram (E)
3521            and then not Is_Generic_Subprogram (E)
3522          then
3523             Error_Pragma_Arg
3524               ("second argument of pragma% must be a subprogram", Arg2);
3525          end if;
3526
3527          --  For Stdcall, a subprogram, variable or subprogram type is required
3528
3529          if C = Convention_Stdcall
3530            and then not Is_Subprogram (E)
3531            and then not Is_Generic_Subprogram (E)
3532            and then Ekind (E) /= E_Variable
3533            and then not
3534              (Is_Access_Type (E)
3535                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3536          then
3537             Error_Pragma_Arg
3538               ("second argument of pragma% must be subprogram (type)",
3539                Arg2);
3540          end if;
3541
3542          if not Is_Subprogram (E)
3543            and then not Is_Generic_Subprogram (E)
3544          then
3545             Set_Convention_From_Pragma (E);
3546
3547             if Is_Type (E) then
3548                Check_First_Subtype (Arg2);
3549                Set_Convention_From_Pragma (Base_Type (E));
3550
3551                --  For subprograms, we must set the convention on the
3552                --  internally generated directly designated type as well.
3553
3554                if Ekind (E) = E_Access_Subprogram_Type then
3555                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3556                end if;
3557             end if;
3558
3559          --  For the subprogram case, set proper convention for all homonyms
3560          --  in same scope and the same declarative part, i.e. the same
3561          --  compilation unit.
3562
3563          else
3564             Comp_Unit := Get_Source_Unit (E);
3565             Set_Convention_From_Pragma (E);
3566
3567             --  Treat a pragma Import as an implicit body, for GPS use
3568
3569             if Prag_Id = Pragma_Import then
3570                Generate_Reference (E, Id, 'b');
3571             end if;
3572
3573             --  Loop through the homonyms of the pragma argument's entity
3574
3575             E1 := Ent;
3576             loop
3577                E1 := Homonym (E1);
3578                exit when No (E1) or else Scope (E1) /= Current_Scope;
3579
3580                --  Do not set the pragma on inherited operations or on formal
3581                --  subprograms.
3582
3583                if Comes_From_Source (E1)
3584                  and then Comp_Unit = Get_Source_Unit (E1)
3585                  and then not Is_Formal_Subprogram (E1)
3586                  and then Nkind (Original_Node (Parent (E1))) /=
3587                                                     N_Full_Type_Declaration
3588                then
3589                   if Present (Alias (E1))
3590                     and then Scope (E1) /= Scope (Alias (E1))
3591                   then
3592                      Error_Pragma_Ref
3593                        ("cannot apply pragma% to non-local entity& declared#",
3594                         E1);
3595                   end if;
3596
3597                   Set_Convention_From_Pragma (E1);
3598
3599                   if Prag_Id = Pragma_Import then
3600                      Generate_Reference (E1, Id, 'b');
3601                   end if;
3602                end if;
3603
3604                --  For aspect case, do NOT apply to homonyms
3605
3606                exit when From_Aspect_Specification (N);
3607             end loop;
3608          end if;
3609       end Process_Convention;
3610
3611       ----------------------------------------
3612       -- Process_Disable_Enable_Atomic_Sync --
3613       ----------------------------------------
3614
3615       procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
3616       begin
3617          GNAT_Pragma;
3618          Check_No_Identifiers;
3619          Check_At_Most_N_Arguments (1);
3620
3621          --  Modeled internally as
3622          --    pragma Unsuppress (Atomic_Synchronization [,Entity])
3623
3624          Rewrite (N,
3625            Make_Pragma (Loc,
3626              Pragma_Identifier            =>
3627                Make_Identifier (Loc, Nam),
3628              Pragma_Argument_Associations => New_List (
3629                Make_Pragma_Argument_Association (Loc,
3630                  Expression =>
3631                    Make_Identifier (Loc, Name_Atomic_Synchronization)))));
3632
3633          if Present (Arg1) then
3634             Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
3635          end if;
3636
3637          Analyze (N);
3638       end Process_Disable_Enable_Atomic_Sync;
3639
3640       -----------------------------------------------------
3641       -- Process_Extended_Import_Export_Exception_Pragma --
3642       -----------------------------------------------------
3643
3644       procedure Process_Extended_Import_Export_Exception_Pragma
3645         (Arg_Internal : Node_Id;
3646          Arg_External : Node_Id;
3647          Arg_Form     : Node_Id;
3648          Arg_Code     : Node_Id)
3649       is
3650          Def_Id   : Entity_Id;
3651          Code_Val : Uint;
3652
3653       begin
3654          if not OpenVMS_On_Target then
3655             Error_Pragma
3656               ("?pragma% ignored (applies only to Open'V'M'S)");
3657          end if;
3658
3659          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3660          Def_Id := Entity (Arg_Internal);
3661
3662          if Ekind (Def_Id) /= E_Exception then
3663             Error_Pragma_Arg
3664               ("pragma% must refer to declared exception", Arg_Internal);
3665          end if;
3666
3667          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3668
3669          if Present (Arg_Form) then
3670             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3671          end if;
3672
3673          if Present (Arg_Form)
3674            and then Chars (Arg_Form) = Name_Ada
3675          then
3676             null;
3677          else
3678             Set_Is_VMS_Exception (Def_Id);
3679             Set_Exception_Code (Def_Id, No_Uint);
3680          end if;
3681
3682          if Present (Arg_Code) then
3683             if not Is_VMS_Exception (Def_Id) then
3684                Error_Pragma_Arg
3685                  ("Code option for pragma% not allowed for Ada case",
3686                   Arg_Code);
3687             end if;
3688
3689             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3690             Code_Val := Expr_Value (Arg_Code);
3691
3692             if not UI_Is_In_Int_Range (Code_Val) then
3693                Error_Pragma_Arg
3694                  ("Code option for pragma% must be in 32-bit range",
3695                   Arg_Code);
3696
3697             else
3698                Set_Exception_Code (Def_Id, Code_Val);
3699             end if;
3700          end if;
3701       end Process_Extended_Import_Export_Exception_Pragma;
3702
3703       -------------------------------------------------
3704       -- Process_Extended_Import_Export_Internal_Arg --
3705       -------------------------------------------------
3706
3707       procedure Process_Extended_Import_Export_Internal_Arg
3708         (Arg_Internal : Node_Id := Empty)
3709       is
3710       begin
3711          if No (Arg_Internal) then
3712             Error_Pragma ("Internal parameter required for pragma%");
3713          end if;
3714
3715          if Nkind (Arg_Internal) = N_Identifier then
3716             null;
3717
3718          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3719            and then (Prag_Id = Pragma_Import_Function
3720                        or else
3721                      Prag_Id = Pragma_Export_Function)
3722          then
3723             null;
3724
3725          else
3726             Error_Pragma_Arg
3727               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3728          end if;
3729
3730          Check_Arg_Is_Local_Name (Arg_Internal);
3731       end Process_Extended_Import_Export_Internal_Arg;
3732
3733       --------------------------------------------------
3734       -- Process_Extended_Import_Export_Object_Pragma --
3735       --------------------------------------------------
3736
3737       procedure Process_Extended_Import_Export_Object_Pragma
3738         (Arg_Internal : Node_Id;
3739          Arg_External : Node_Id;
3740          Arg_Size     : Node_Id)
3741       is
3742          Def_Id : Entity_Id;
3743
3744       begin
3745          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3746          Def_Id := Entity (Arg_Internal);
3747
3748          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3749             Error_Pragma_Arg
3750               ("pragma% must designate an object", Arg_Internal);
3751          end if;
3752
3753          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3754               or else
3755             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3756          then
3757             Error_Pragma_Arg
3758               ("previous Common/Psect_Object applies, pragma % not permitted",
3759                Arg_Internal);
3760          end if;
3761
3762          if Rep_Item_Too_Late (Def_Id, N) then
3763             raise Pragma_Exit;
3764          end if;
3765
3766          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3767
3768          if Present (Arg_Size) then
3769             Check_Arg_Is_External_Name (Arg_Size);
3770          end if;
3771
3772          --  Export_Object case
3773
3774          if Prag_Id = Pragma_Export_Object then
3775             if not Is_Library_Level_Entity (Def_Id) then
3776                Error_Pragma_Arg
3777                  ("argument for pragma% must be library level entity",
3778                   Arg_Internal);
3779             end if;
3780
3781             if Ekind (Current_Scope) = E_Generic_Package then
3782                Error_Pragma ("pragma& cannot appear in a generic unit");
3783             end if;
3784
3785             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3786                Error_Pragma_Arg
3787                  ("exported object must have compile time known size",
3788                   Arg_Internal);
3789             end if;
3790
3791             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3792                Error_Msg_N ("?duplicate Export_Object pragma", N);
3793             else
3794                Set_Exported (Def_Id, Arg_Internal);
3795             end if;
3796
3797          --  Import_Object case
3798
3799          else
3800             if Is_Concurrent_Type (Etype (Def_Id)) then
3801                Error_Pragma_Arg
3802                  ("cannot use pragma% for task/protected object",
3803                   Arg_Internal);
3804             end if;
3805
3806             if Ekind (Def_Id) = E_Constant then
3807                Error_Pragma_Arg
3808                  ("cannot import a constant", Arg_Internal);
3809             end if;
3810
3811             if Warn_On_Export_Import
3812               and then Has_Discriminants (Etype (Def_Id))
3813             then
3814                Error_Msg_N
3815                  ("imported value must be initialized?", Arg_Internal);
3816             end if;
3817
3818             if Warn_On_Export_Import
3819               and then Is_Access_Type (Etype (Def_Id))
3820             then
3821                Error_Pragma_Arg
3822                  ("cannot import object of an access type?", Arg_Internal);
3823             end if;
3824
3825             if Warn_On_Export_Import
3826               and then Is_Imported (Def_Id)
3827             then
3828                Error_Msg_N
3829                  ("?duplicate Import_Object pragma", N);
3830
3831             --  Check for explicit initialization present. Note that an
3832             --  initialization generated by the code generator, e.g. for an
3833             --  access type, does not count here.
3834
3835             elsif Present (Expression (Parent (Def_Id)))
3836                and then
3837                  Comes_From_Source
3838                    (Original_Node (Expression (Parent (Def_Id))))
3839             then
3840                Error_Msg_Sloc := Sloc (Def_Id);
3841                Error_Pragma_Arg
3842                  ("imported entities cannot be initialized (RM B.1(24))",
3843                   "\no initialization allowed for & declared#", Arg1);
3844             else
3845                Set_Imported (Def_Id);
3846                Note_Possible_Modification (Arg_Internal, Sure => False);
3847             end if;
3848          end if;
3849       end Process_Extended_Import_Export_Object_Pragma;
3850
3851       ------------------------------------------------------
3852       -- Process_Extended_Import_Export_Subprogram_Pragma --
3853       ------------------------------------------------------
3854
3855       procedure Process_Extended_Import_Export_Subprogram_Pragma
3856         (Arg_Internal                 : Node_Id;
3857          Arg_External                 : Node_Id;
3858          Arg_Parameter_Types          : Node_Id;
3859          Arg_Result_Type              : Node_Id := Empty;
3860          Arg_Mechanism                : Node_Id;
3861          Arg_Result_Mechanism         : Node_Id := Empty;
3862          Arg_First_Optional_Parameter : Node_Id := Empty)
3863       is
3864          Ent       : Entity_Id;
3865          Def_Id    : Entity_Id;
3866          Hom_Id    : Entity_Id;
3867          Formal    : Entity_Id;
3868          Ambiguous : Boolean;
3869          Match     : Boolean;
3870          Dval      : Node_Id;
3871
3872          function Same_Base_Type
3873           (Ptype  : Node_Id;
3874            Formal : Entity_Id) return Boolean;
3875          --  Determines if Ptype references the type of Formal. Note that only
3876          --  the base types need to match according to the spec. Ptype here is
3877          --  the argument from the pragma, which is either a type name, or an
3878          --  access attribute.
3879
3880          --------------------
3881          -- Same_Base_Type --
3882          --------------------
3883
3884          function Same_Base_Type
3885            (Ptype  : Node_Id;
3886             Formal : Entity_Id) return Boolean
3887          is
3888             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3889             Pref : Node_Id;
3890
3891          begin
3892             --  Case where pragma argument is typ'Access
3893
3894             if Nkind (Ptype) = N_Attribute_Reference
3895               and then Attribute_Name (Ptype) = Name_Access
3896             then
3897                Pref := Prefix (Ptype);
3898                Find_Type (Pref);
3899
3900                if not Is_Entity_Name (Pref)
3901                  or else Entity (Pref) = Any_Type
3902                then
3903                   raise Pragma_Exit;
3904                end if;
3905
3906                --  We have a match if the corresponding argument is of an
3907                --  anonymous access type, and its designated type matches the
3908                --  type of the prefix of the access attribute
3909
3910                return Ekind (Ftyp) = E_Anonymous_Access_Type
3911                  and then Base_Type (Entity (Pref)) =
3912                             Base_Type (Etype (Designated_Type (Ftyp)));
3913
3914             --  Case where pragma argument is a type name
3915
3916             else
3917                Find_Type (Ptype);
3918
3919                if not Is_Entity_Name (Ptype)
3920                  or else Entity (Ptype) = Any_Type
3921                then
3922                   raise Pragma_Exit;
3923                end if;
3924
3925                --  We have a match if the corresponding argument is of the type
3926                --  given in the pragma (comparing base types)
3927
3928                return Base_Type (Entity (Ptype)) = Ftyp;
3929             end if;
3930          end Same_Base_Type;
3931
3932       --  Start of processing for
3933       --  Process_Extended_Import_Export_Subprogram_Pragma
3934
3935       begin
3936          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3937          Ent := Empty;
3938          Ambiguous := False;
3939
3940          --  Loop through homonyms (overloadings) of the entity
3941
3942          Hom_Id := Entity (Arg_Internal);
3943          while Present (Hom_Id) loop
3944             Def_Id := Get_Base_Subprogram (Hom_Id);
3945
3946             --  We need a subprogram in the current scope
3947
3948             if not Is_Subprogram (Def_Id)
3949               or else Scope (Def_Id) /= Current_Scope
3950             then
3951                null;
3952
3953             else
3954                Match := True;
3955
3956                --  Pragma cannot apply to subprogram body
3957
3958                if Is_Subprogram (Def_Id)
3959                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3960                                                              N_Subprogram_Body
3961                then
3962                   Error_Pragma
3963                     ("pragma% requires separate spec"
3964                       & " and must come before body");
3965                end if;
3966
3967                --  Test result type if given, note that the result type
3968                --  parameter can only be present for the function cases.
3969
3970                if Present (Arg_Result_Type)
3971                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3972                then
3973                   Match := False;
3974
3975                elsif Etype (Def_Id) /= Standard_Void_Type
3976                  and then
3977                    (Pname = Name_Export_Procedure
3978                       or else
3979                     Pname = Name_Import_Procedure)
3980                then
3981                   Match := False;
3982
3983                --  Test parameter types if given. Note that this parameter
3984                --  has not been analyzed (and must not be, since it is
3985                --  semantic nonsense), so we get it as the parser left it.
3986
3987                elsif Present (Arg_Parameter_Types) then
3988                   Check_Matching_Types : declare
3989                      Formal : Entity_Id;
3990                      Ptype  : Node_Id;
3991
3992                   begin
3993                      Formal := First_Formal (Def_Id);
3994
3995                      if Nkind (Arg_Parameter_Types) = N_Null then
3996                         if Present (Formal) then
3997                            Match := False;
3998                         end if;
3999
4000                      --  A list of one type, e.g. (List) is parsed as
4001                      --  a parenthesized expression.
4002
4003                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
4004                        and then Paren_Count (Arg_Parameter_Types) = 1
4005                      then
4006                         if No (Formal)
4007                           or else Present (Next_Formal (Formal))
4008                         then
4009                            Match := False;
4010                         else
4011                            Match :=
4012                              Same_Base_Type (Arg_Parameter_Types, Formal);
4013                         end if;
4014
4015                      --  A list of more than one type is parsed as a aggregate
4016
4017                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
4018                        and then Paren_Count (Arg_Parameter_Types) = 0
4019                      then
4020                         Ptype := First (Expressions (Arg_Parameter_Types));
4021                         while Present (Ptype) or else Present (Formal) loop
4022                            if No (Ptype)
4023                              or else No (Formal)
4024                              or else not Same_Base_Type (Ptype, Formal)
4025                            then
4026                               Match := False;
4027                               exit;
4028                            else
4029                               Next_Formal (Formal);
4030                               Next (Ptype);
4031                            end if;
4032                         end loop;
4033
4034                      --  Anything else is of the wrong form
4035
4036                      else
4037                         Error_Pragma_Arg
4038                           ("wrong form for Parameter_Types parameter",
4039                            Arg_Parameter_Types);
4040                      end if;
4041                   end Check_Matching_Types;
4042                end if;
4043
4044                --  Match is now False if the entry we found did not match
4045                --  either a supplied Parameter_Types or Result_Types argument
4046
4047                if Match then
4048                   if No (Ent) then
4049                      Ent := Def_Id;
4050
4051                   --  Ambiguous case, the flag Ambiguous shows if we already
4052                   --  detected this and output the initial messages.
4053
4054                   else
4055                      if not Ambiguous then
4056                         Ambiguous := True;
4057                         Error_Msg_Name_1 := Pname;
4058                         Error_Msg_N
4059                           ("pragma% does not uniquely identify subprogram!",
4060                            N);
4061                         Error_Msg_Sloc := Sloc (Ent);
4062                         Error_Msg_N ("matching subprogram #!", N);
4063                         Ent := Empty;
4064                      end if;
4065
4066                      Error_Msg_Sloc := Sloc (Def_Id);
4067                      Error_Msg_N ("matching subprogram #!", N);
4068                   end if;
4069                end if;
4070             end if;
4071
4072             Hom_Id := Homonym (Hom_Id);
4073          end loop;
4074
4075          --  See if we found an entry
4076
4077          if No (Ent) then
4078             if not Ambiguous then
4079                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4080                   Error_Pragma
4081                     ("pragma% cannot be given for generic subprogram");
4082                else
4083                   Error_Pragma
4084                     ("pragma% does not identify local subprogram");
4085                end if;
4086             end if;
4087
4088             return;
4089          end if;
4090
4091          --  Import pragmas must be for imported entities
4092
4093          if Prag_Id = Pragma_Import_Function
4094               or else
4095             Prag_Id = Pragma_Import_Procedure
4096               or else
4097             Prag_Id = Pragma_Import_Valued_Procedure
4098          then
4099             if not Is_Imported (Ent) then
4100                Error_Pragma
4101                  ("pragma Import or Interface must precede pragma%");
4102             end if;
4103
4104          --  Here we have the Export case which can set the entity as exported
4105
4106          --  But does not do so if the specified external name is null, since
4107          --  that is taken as a signal in DEC Ada 83 (with which we want to be
4108          --  compatible) to request no external name.
4109
4110          elsif Nkind (Arg_External) = N_String_Literal
4111            and then String_Length (Strval (Arg_External)) = 0
4112          then
4113             null;
4114
4115          --  In all other cases, set entity as exported
4116
4117          else
4118             Set_Exported (Ent, Arg_Internal);
4119          end if;
4120
4121          --  Special processing for Valued_Procedure cases
4122
4123          if Prag_Id = Pragma_Import_Valued_Procedure
4124            or else
4125             Prag_Id = Pragma_Export_Valued_Procedure
4126          then
4127             Formal := First_Formal (Ent);
4128
4129             if No (Formal) then
4130                Error_Pragma ("at least one parameter required for pragma%");
4131
4132             elsif Ekind (Formal) /= E_Out_Parameter then
4133                Error_Pragma ("first parameter must have mode out for pragma%");
4134
4135             else
4136                Set_Is_Valued_Procedure (Ent);
4137             end if;
4138          end if;
4139
4140          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4141
4142          --  Process Result_Mechanism argument if present. We have already
4143          --  checked that this is only allowed for the function case.
4144
4145          if Present (Arg_Result_Mechanism) then
4146             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4147          end if;
4148
4149          --  Process Mechanism parameter if present. Note that this parameter
4150          --  is not analyzed, and must not be analyzed since it is semantic
4151          --  nonsense, so we get it in exactly as the parser left it.
4152
4153          if Present (Arg_Mechanism) then
4154             declare
4155                Formal : Entity_Id;
4156                Massoc : Node_Id;
4157                Mname  : Node_Id;
4158                Choice : Node_Id;
4159
4160             begin
4161                --  A single mechanism association without a formal parameter
4162                --  name is parsed as a parenthesized expression. All other
4163                --  cases are parsed as aggregates, so we rewrite the single
4164                --  parameter case as an aggregate for consistency.
4165
4166                if Nkind (Arg_Mechanism) /= N_Aggregate
4167                  and then Paren_Count (Arg_Mechanism) = 1
4168                then
4169                   Rewrite (Arg_Mechanism,
4170                     Make_Aggregate (Sloc (Arg_Mechanism),
4171                       Expressions => New_List (
4172                         Relocate_Node (Arg_Mechanism))));
4173                end if;
4174
4175                --  Case of only mechanism name given, applies to all formals
4176
4177                if Nkind (Arg_Mechanism) /= N_Aggregate then
4178                   Formal := First_Formal (Ent);
4179                   while Present (Formal) loop
4180                      Set_Mechanism_Value (Formal, Arg_Mechanism);
4181                      Next_Formal (Formal);
4182                   end loop;
4183
4184                --  Case of list of mechanism associations given
4185
4186                else
4187                   if Null_Record_Present (Arg_Mechanism) then
4188                      Error_Pragma_Arg
4189                        ("inappropriate form for Mechanism parameter",
4190                         Arg_Mechanism);
4191                   end if;
4192
4193                   --  Deal with positional ones first
4194
4195                   Formal := First_Formal (Ent);
4196
4197                   if Present (Expressions (Arg_Mechanism)) then
4198                      Mname := First (Expressions (Arg_Mechanism));
4199                      while Present (Mname) loop
4200                         if No (Formal) then
4201                            Error_Pragma_Arg
4202                              ("too many mechanism associations", Mname);
4203                         end if;
4204
4205                         Set_Mechanism_Value (Formal, Mname);
4206                         Next_Formal (Formal);
4207                         Next (Mname);
4208                      end loop;
4209                   end if;
4210
4211                   --  Deal with named entries
4212
4213                   if Present (Component_Associations (Arg_Mechanism)) then
4214                      Massoc := First (Component_Associations (Arg_Mechanism));
4215                      while Present (Massoc) loop
4216                         Choice := First (Choices (Massoc));
4217
4218                         if Nkind (Choice) /= N_Identifier
4219                           or else Present (Next (Choice))
4220                         then
4221                            Error_Pragma_Arg
4222                              ("incorrect form for mechanism association",
4223                               Massoc);
4224                         end if;
4225
4226                         Formal := First_Formal (Ent);
4227                         loop
4228                            if No (Formal) then
4229                               Error_Pragma_Arg
4230                                 ("parameter name & not present", Choice);
4231                            end if;
4232
4233                            if Chars (Choice) = Chars (Formal) then
4234                               Set_Mechanism_Value
4235                                 (Formal, Expression (Massoc));
4236
4237                               --  Set entity on identifier (needed by ASIS)
4238
4239                               Set_Entity (Choice, Formal);
4240
4241                               exit;
4242                            end if;
4243
4244                            Next_Formal (Formal);
4245                         end loop;
4246
4247                         Next (Massoc);
4248                      end loop;
4249                   end if;
4250                end if;
4251             end;
4252          end if;
4253
4254          --  Process First_Optional_Parameter argument if present. We have
4255          --  already checked that this is only allowed for the Import case.
4256
4257          if Present (Arg_First_Optional_Parameter) then
4258             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4259                Error_Pragma_Arg
4260                  ("first optional parameter must be formal parameter name",
4261                   Arg_First_Optional_Parameter);
4262             end if;
4263
4264             Formal := First_Formal (Ent);
4265             loop
4266                if No (Formal) then
4267                   Error_Pragma_Arg
4268                     ("specified formal parameter& not found",
4269                      Arg_First_Optional_Parameter);
4270                end if;
4271
4272                exit when Chars (Formal) =
4273                          Chars (Arg_First_Optional_Parameter);
4274
4275                Next_Formal (Formal);
4276             end loop;
4277
4278             Set_First_Optional_Parameter (Ent, Formal);
4279
4280             --  Check specified and all remaining formals have right form
4281
4282             while Present (Formal) loop
4283                if Ekind (Formal) /= E_In_Parameter then
4284                   Error_Msg_NE
4285                     ("optional formal& is not of mode in!",
4286                      Arg_First_Optional_Parameter, Formal);
4287
4288                else
4289                   Dval := Default_Value (Formal);
4290
4291                   if No (Dval) then
4292                      Error_Msg_NE
4293                        ("optional formal& does not have default value!",
4294                         Arg_First_Optional_Parameter, Formal);
4295
4296                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4297                      null;
4298
4299                   else
4300                      Error_Msg_FE
4301                        ("default value for optional formal& is non-static!",
4302                         Arg_First_Optional_Parameter, Formal);
4303                   end if;
4304                end if;
4305
4306                Set_Is_Optional_Parameter (Formal);
4307                Next_Formal (Formal);
4308             end loop;
4309          end if;
4310       end Process_Extended_Import_Export_Subprogram_Pragma;
4311
4312       --------------------------
4313       -- Process_Generic_List --
4314       --------------------------
4315
4316       procedure Process_Generic_List is
4317          Arg : Node_Id;
4318          Exp : Node_Id;
4319
4320       begin
4321          Check_No_Identifiers;
4322          Check_At_Least_N_Arguments (1);
4323
4324          Arg := Arg1;
4325          while Present (Arg) loop
4326             Exp := Get_Pragma_Arg (Arg);
4327             Analyze (Exp);
4328
4329             if not Is_Entity_Name (Exp)
4330               or else
4331                 (not Is_Generic_Instance (Entity (Exp))
4332                   and then
4333                  not Is_Generic_Unit (Entity (Exp)))
4334             then
4335                Error_Pragma_Arg
4336                  ("pragma% argument must be name of generic unit/instance",
4337                   Arg);
4338             end if;
4339
4340             Next (Arg);
4341          end loop;
4342       end Process_Generic_List;
4343
4344       ------------------------------------
4345       -- Process_Import_Predefined_Type --
4346       ------------------------------------
4347
4348       procedure Process_Import_Predefined_Type is
4349          Loc  : constant Source_Ptr := Sloc (N);
4350          Elmt : Elmt_Id;
4351          Ftyp : Node_Id := Empty;
4352          Decl : Node_Id;
4353          Def  : Node_Id;
4354          Nam  : Name_Id;
4355
4356       begin
4357          String_To_Name_Buffer (Strval (Expression (Arg3)));
4358          Nam := Name_Find;
4359
4360          Elmt := First_Elmt (Predefined_Float_Types);
4361          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4362             Next_Elmt (Elmt);
4363          end loop;
4364
4365          Ftyp := Node (Elmt);
4366
4367          if Present (Ftyp) then
4368
4369             --  Don't build a derived type declaration, because predefined C
4370             --  types have no declaration anywhere, so cannot really be named.
4371             --  Instead build a full type declaration, starting with an
4372             --  appropriate type definition is built
4373
4374             if Is_Floating_Point_Type (Ftyp) then
4375                Def := Make_Floating_Point_Definition (Loc,
4376                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4377                  Make_Real_Range_Specification (Loc,
4378                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4379                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4380
4381             --  Should never have a predefined type we cannot handle
4382
4383             else
4384                raise Program_Error;
4385             end if;
4386
4387             --  Build and insert a Full_Type_Declaration, which will be
4388             --  analyzed as soon as this list entry has been analyzed.
4389
4390             Decl := Make_Full_Type_Declaration (Loc,
4391               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4392               Type_Definition => Def);
4393
4394             Insert_After (N, Decl);
4395             Mark_Rewrite_Insertion (Decl);
4396
4397          else
4398             Error_Pragma_Arg ("no matching type found for pragma%",
4399             Arg2);
4400          end if;
4401       end Process_Import_Predefined_Type;
4402
4403       ---------------------------------
4404       -- Process_Import_Or_Interface --
4405       ---------------------------------
4406
4407       procedure Process_Import_Or_Interface is
4408          C      : Convention_Id;
4409          Def_Id : Entity_Id;
4410          Hom_Id : Entity_Id;
4411
4412       begin
4413          Process_Convention (C, Def_Id);
4414          Kill_Size_Check_Code (Def_Id);
4415          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4416
4417          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4418
4419             --  We do not permit Import to apply to a renaming declaration
4420
4421             if Present (Renamed_Object (Def_Id)) then
4422                Error_Pragma_Arg
4423                  ("pragma% not allowed for object renaming", Arg2);
4424
4425             --  User initialization is not allowed for imported object, but
4426             --  the object declaration may contain a default initialization,
4427             --  that will be discarded. Note that an explicit initialization
4428             --  only counts if it comes from source, otherwise it is simply
4429             --  the code generator making an implicit initialization explicit.
4430
4431             elsif Present (Expression (Parent (Def_Id)))
4432               and then Comes_From_Source (Expression (Parent (Def_Id)))
4433             then
4434                Error_Msg_Sloc := Sloc (Def_Id);
4435                Error_Pragma_Arg
4436                  ("no initialization allowed for declaration of& #",
4437                   "\imported entities cannot be initialized (RM B.1(24))",
4438                   Arg2);
4439
4440             else
4441                Set_Imported (Def_Id);
4442                Process_Interface_Name (Def_Id, Arg3, Arg4);
4443
4444                --  Note that we do not set Is_Public here. That's because we
4445                --  only want to set it if there is no address clause, and we
4446                --  don't know that yet, so we delay that processing till
4447                --  freeze time.
4448
4449                --  pragma Import completes deferred constants
4450
4451                if Ekind (Def_Id) = E_Constant then
4452                   Set_Has_Completion (Def_Id);
4453                end if;
4454
4455                --  It is not possible to import a constant of an unconstrained
4456                --  array type (e.g. string) because there is no simple way to
4457                --  write a meaningful subtype for it.
4458
4459                if Is_Array_Type (Etype (Def_Id))
4460                  and then not Is_Constrained (Etype (Def_Id))
4461                then
4462                   Error_Msg_NE
4463                     ("imported constant& must have a constrained subtype",
4464                       N, Def_Id);
4465                end if;
4466             end if;
4467
4468          elsif Is_Subprogram (Def_Id)
4469            or else Is_Generic_Subprogram (Def_Id)
4470          then
4471             --  If the name is overloaded, pragma applies to all of the denoted
4472             --  entities in the same declarative part.
4473
4474             Hom_Id := Def_Id;
4475             while Present (Hom_Id) loop
4476                Def_Id := Get_Base_Subprogram (Hom_Id);
4477
4478                --  Ignore inherited subprograms because the pragma will apply
4479                --  to the parent operation, which is the one called.
4480
4481                if Is_Overloadable (Def_Id)
4482                  and then Present (Alias (Def_Id))
4483                then
4484                   null;
4485
4486                --  If it is not a subprogram, it must be in an outer scope and
4487                --  pragma does not apply.
4488
4489                elsif not Is_Subprogram (Def_Id)
4490                  and then not Is_Generic_Subprogram (Def_Id)
4491                then
4492                   null;
4493
4494                --  The pragma does not apply to primitives of interfaces
4495
4496                elsif Is_Dispatching_Operation (Def_Id)
4497                  and then Present (Find_Dispatching_Type (Def_Id))
4498                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4499                then
4500                   null;
4501
4502                --  Verify that the homonym is in the same declarative part (not
4503                --  just the same scope).
4504
4505                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4506                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4507                then
4508                   exit;
4509
4510                else
4511                   Set_Imported (Def_Id);
4512
4513                   --  Reject an Import applied to an abstract subprogram
4514
4515                   if Is_Subprogram (Def_Id)
4516                     and then Is_Abstract_Subprogram (Def_Id)
4517                   then
4518                      Error_Msg_Sloc := Sloc (Def_Id);
4519                      Error_Msg_NE
4520                        ("cannot import abstract subprogram& declared#",
4521                         Arg2, Def_Id);
4522                   end if;
4523
4524                   --  Special processing for Convention_Intrinsic
4525
4526                   if C = Convention_Intrinsic then
4527
4528                      --  Link_Name argument not allowed for intrinsic
4529
4530                      Check_No_Link_Name;
4531
4532                      Set_Is_Intrinsic_Subprogram (Def_Id);
4533
4534                      --  If no external name is present, then check that this
4535                      --  is a valid intrinsic subprogram. If an external name
4536                      --  is present, then this is handled by the back end.
4537
4538                      if No (Arg3) then
4539                         Check_Intrinsic_Subprogram
4540                           (Def_Id, Get_Pragma_Arg (Arg2));
4541                      end if;
4542                   end if;
4543
4544                   --  All interfaced procedures need an external symbol created
4545                   --  for them since they are always referenced from another
4546                   --  object file.
4547
4548                   Set_Is_Public (Def_Id);
4549
4550                   --  Verify that the subprogram does not have a completion
4551                   --  through a renaming declaration. For other completions the
4552                   --  pragma appears as a too late representation.
4553
4554                   declare
4555                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4556
4557                   begin
4558                      if Present (Decl)
4559                        and then Nkind (Decl) = N_Subprogram_Declaration
4560                        and then Present (Corresponding_Body (Decl))
4561                        and then Nkind (Unit_Declaration_Node
4562                                         (Corresponding_Body (Decl))) =
4563                                              N_Subprogram_Renaming_Declaration
4564                      then
4565                         Error_Msg_Sloc := Sloc (Def_Id);
4566                         Error_Msg_NE
4567                           ("cannot import&, renaming already provided for " &
4568                            "declaration #", N, Def_Id);
4569                      end if;
4570                   end;
4571
4572                   Set_Has_Completion (Def_Id);
4573                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4574                end if;
4575
4576                if Is_Compilation_Unit (Hom_Id) then
4577
4578                   --  Its possible homonyms are not affected by the pragma.
4579                   --  Such homonyms might be present in the context of other
4580                   --  units being compiled.
4581
4582                   exit;
4583
4584                else
4585                   Hom_Id := Homonym (Hom_Id);
4586                end if;
4587             end loop;
4588
4589          --  When the convention is Java or CIL, we also allow Import to be
4590          --  given for packages, generic packages, exceptions, record
4591          --  components, and access to subprograms.
4592
4593          elsif (C = Convention_Java or else C = Convention_CIL)
4594            and then
4595              (Is_Package_Or_Generic_Package (Def_Id)
4596                or else Ekind (Def_Id) = E_Exception
4597                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4598                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4599          then
4600             Set_Imported (Def_Id);
4601             Set_Is_Public (Def_Id);
4602             Process_Interface_Name (Def_Id, Arg3, Arg4);
4603
4604          --  Import a CPP class
4605
4606          elsif Is_Record_Type (Def_Id)
4607            and then C = Convention_CPP
4608          then
4609             --  Types treated as CPP classes must be declared limited (note:
4610             --  this used to be a warning but there is no real benefit to it
4611             --  since we did effectively intend to treat the type as limited
4612             --  anyway).
4613
4614             if not Is_Limited_Type (Def_Id) then
4615                Error_Msg_N
4616                  ("imported 'C'P'P type must be limited",
4617                   Get_Pragma_Arg (Arg2));
4618             end if;
4619
4620             Set_Is_CPP_Class (Def_Id);
4621
4622             --  Imported CPP types must not have discriminants (because C++
4623             --  classes do not have discriminants).
4624
4625             if Has_Discriminants (Def_Id) then
4626                Error_Msg_N
4627                  ("imported 'C'P'P type cannot have discriminants",
4628                   First (Discriminant_Specifications
4629                           (Declaration_Node (Def_Id))));
4630             end if;
4631
4632             --  Components of imported CPP types must not have default
4633             --  expressions because the constructor (if any) is on the
4634             --  C++ side.
4635
4636             declare
4637                Tdef  : constant Node_Id :=
4638                          Type_Definition (Declaration_Node (Def_Id));
4639                Clist : Node_Id;
4640                Comp  : Node_Id;
4641
4642             begin
4643                if Nkind (Tdef) = N_Record_Definition then
4644                   Clist := Component_List (Tdef);
4645
4646                else
4647                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4648                   Clist := Component_List (Record_Extension_Part (Tdef));
4649                end if;
4650
4651                if Present (Clist) then
4652                   Comp := First (Component_Items (Clist));
4653                   while Present (Comp) loop
4654                      if Present (Expression (Comp)) then
4655                         Error_Msg_N
4656                           ("component of imported 'C'P'P type cannot have" &
4657                            " default expression", Expression (Comp));
4658                      end if;
4659
4660                      Next (Comp);
4661                   end loop;
4662                end if;
4663             end;
4664
4665          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4666             Check_No_Link_Name;
4667             Check_Arg_Count (3);
4668             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4669
4670             Process_Import_Predefined_Type;
4671
4672          else
4673             Error_Pragma_Arg
4674               ("second argument of pragma% must be object, subprogram" &
4675                " or incomplete type",
4676                Arg2);
4677          end if;
4678
4679          --  If this pragma applies to a compilation unit, then the unit, which
4680          --  is a subprogram, does not require (or allow) a body. We also do
4681          --  not need to elaborate imported procedures.
4682
4683          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4684             declare
4685                Cunit : constant Node_Id := Parent (Parent (N));
4686             begin
4687                Set_Body_Required (Cunit, False);
4688             end;
4689          end if;
4690       end Process_Import_Or_Interface;
4691
4692       --------------------
4693       -- Process_Inline --
4694       --------------------
4695
4696       procedure Process_Inline (Active : Boolean) is
4697          Assoc     : Node_Id;
4698          Decl      : Node_Id;
4699          Subp_Id   : Node_Id;
4700          Subp      : Entity_Id;
4701          Applies   : Boolean;
4702
4703          Effective : Boolean := False;
4704          --  Set True if inline has some effect, i.e. if there is at least one
4705          --  subprogram set as inlined as a result of the use of the pragma.
4706
4707          procedure Make_Inline (Subp : Entity_Id);
4708          --  Subp is the defining unit name of the subprogram declaration. Set
4709          --  the flag, as well as the flag in the corresponding body, if there
4710          --  is one present.
4711
4712          procedure Set_Inline_Flags (Subp : Entity_Id);
4713          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4714          --  Has_Pragma_Inline_Always for the Inline_Always case.
4715
4716          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4717          --  Returns True if it can be determined at this stage that inlining
4718          --  is not possible, for example if the body is available and contains
4719          --  exception handlers, we prevent inlining, since otherwise we can
4720          --  get undefined symbols at link time. This function also emits a
4721          --  warning if front-end inlining is enabled and the pragma appears
4722          --  too late.
4723          --
4724          --  ??? is business with link symbols still valid, or does it relate
4725          --  to front end ZCX which is being phased out ???
4726
4727          ---------------------------
4728          -- Inlining_Not_Possible --
4729          ---------------------------
4730
4731          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4732             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4733             Stats : Node_Id;
4734
4735          begin
4736             if Nkind (Decl) = N_Subprogram_Body then
4737                Stats := Handled_Statement_Sequence (Decl);
4738                return Present (Exception_Handlers (Stats))
4739                  or else Present (At_End_Proc (Stats));
4740
4741             elsif Nkind (Decl) = N_Subprogram_Declaration
4742               and then Present (Corresponding_Body (Decl))
4743             then
4744                if Front_End_Inlining
4745                  and then Analyzed (Corresponding_Body (Decl))
4746                then
4747                   Error_Msg_N ("pragma appears too late, ignored?", N);
4748                   return True;
4749
4750                --  If the subprogram is a renaming as body, the body is just a
4751                --  call to the renamed subprogram, and inlining is trivially
4752                --  possible.
4753
4754                elsif
4755                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4756                                              N_Subprogram_Renaming_Declaration
4757                then
4758                   return False;
4759
4760                else
4761                   Stats :=
4762                     Handled_Statement_Sequence
4763                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4764
4765                   return
4766                     Present (Exception_Handlers (Stats))
4767                       or else Present (At_End_Proc (Stats));
4768                end if;
4769
4770             else
4771                --  If body is not available, assume the best, the check is
4772                --  performed again when compiling enclosing package bodies.
4773
4774                return False;
4775             end if;
4776          end Inlining_Not_Possible;
4777
4778          -----------------
4779          -- Make_Inline --
4780          -----------------
4781
4782          procedure Make_Inline (Subp : Entity_Id) is
4783             Kind       : constant Entity_Kind := Ekind (Subp);
4784             Inner_Subp : Entity_Id   := Subp;
4785
4786          begin
4787             --  Ignore if bad type, avoid cascaded error
4788
4789             if Etype (Subp) = Any_Type then
4790                Applies := True;
4791                return;
4792
4793             --  Ignore if all inlining is suppressed
4794
4795             elsif Suppress_All_Inlining then
4796                Applies := True;
4797                return;
4798
4799             --  If inlining is not possible, for now do not treat as an error
4800
4801             elsif Inlining_Not_Possible (Subp) then
4802                Applies := True;
4803                return;
4804
4805             --  Here we have a candidate for inlining, but we must exclude
4806             --  derived operations. Otherwise we would end up trying to inline
4807             --  a phantom declaration, and the result would be to drag in a
4808             --  body which has no direct inlining associated with it. That
4809             --  would not only be inefficient but would also result in the
4810             --  backend doing cross-unit inlining in cases where it was
4811             --  definitely inappropriate to do so.
4812
4813             --  However, a simple Comes_From_Source test is insufficient, since
4814             --  we do want to allow inlining of generic instances which also do
4815             --  not come from source. We also need to recognize specs generated
4816             --  by the front-end for bodies that carry the pragma. Finally,
4817             --  predefined operators do not come from source but are not
4818             --  inlineable either.
4819
4820             elsif Is_Generic_Instance (Subp)
4821               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4822             then
4823                null;
4824
4825             elsif not Comes_From_Source (Subp)
4826               and then Scope (Subp) /= Standard_Standard
4827             then
4828                Applies := True;
4829                return;
4830             end if;
4831
4832             --  The referenced entity must either be the enclosing entity, or
4833             --  an entity declared within the current open scope.
4834
4835             if Present (Scope (Subp))
4836               and then Scope (Subp) /= Current_Scope
4837               and then Subp /= Current_Scope
4838             then
4839                Error_Pragma_Arg
4840                  ("argument of% must be entity in current scope", Assoc);
4841                return;
4842             end if;
4843
4844             --  Processing for procedure, operator or function. If subprogram
4845             --  is aliased (as for an instance) indicate that the renamed
4846             --  entity (if declared in the same unit) is inlined.
4847
4848             if Is_Subprogram (Subp) then
4849                Inner_Subp := Ultimate_Alias (Inner_Subp);
4850
4851                if In_Same_Source_Unit (Subp, Inner_Subp) then
4852                   Set_Inline_Flags (Inner_Subp);
4853
4854                   Decl := Parent (Parent (Inner_Subp));
4855
4856                   if Nkind (Decl) = N_Subprogram_Declaration
4857                     and then Present (Corresponding_Body (Decl))
4858                   then
4859                      Set_Inline_Flags (Corresponding_Body (Decl));
4860
4861                   elsif Is_Generic_Instance (Subp) then
4862
4863                      --  Indicate that the body needs to be created for
4864                      --  inlining subsequent calls. The instantiation node
4865                      --  follows the declaration of the wrapper package
4866                      --  created for it.
4867
4868                      if Scope (Subp) /= Standard_Standard
4869                        and then
4870                          Need_Subprogram_Instance_Body
4871                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4872                               Subp)
4873                      then
4874                         null;
4875                      end if;
4876
4877                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
4878                   --  appear in a formal part to apply to a formal subprogram.
4879                   --  Do not apply check within an instance or a formal package
4880                   --  the test will have been applied to the original generic.
4881
4882                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4883                     and then List_Containing (Decl) = List_Containing (N)
4884                     and then not In_Instance
4885                   then
4886                      Error_Msg_N
4887                        ("Inline cannot apply to a formal subprogram", N);
4888                   end if;
4889                end if;
4890
4891                Applies := True;
4892
4893             --  For a generic subprogram set flag as well, for use at the point
4894             --  of instantiation, to determine whether the body should be
4895             --  generated.
4896
4897             elsif Is_Generic_Subprogram (Subp) then
4898                Set_Inline_Flags (Subp);
4899                Applies := True;
4900
4901             --  Literals are by definition inlined
4902
4903             elsif Kind = E_Enumeration_Literal then
4904                null;
4905
4906             --  Anything else is an error
4907
4908             else
4909                Error_Pragma_Arg
4910                  ("expect subprogram name for pragma%", Assoc);
4911             end if;
4912          end Make_Inline;
4913
4914          ----------------------
4915          -- Set_Inline_Flags --
4916          ----------------------
4917
4918          procedure Set_Inline_Flags (Subp : Entity_Id) is
4919          begin
4920             if Active then
4921                Set_Is_Inlined (Subp);
4922             end if;
4923
4924             if not Has_Pragma_Inline (Subp) then
4925                Set_Has_Pragma_Inline (Subp);
4926                Effective := True;
4927             end if;
4928
4929             if Prag_Id = Pragma_Inline_Always then
4930                Set_Has_Pragma_Inline_Always (Subp);
4931             end if;
4932          end Set_Inline_Flags;
4933
4934       --  Start of processing for Process_Inline
4935
4936       begin
4937          Check_No_Identifiers;
4938          Check_At_Least_N_Arguments (1);
4939
4940          if Active then
4941             Inline_Processing_Required := True;
4942          end if;
4943
4944          Assoc := Arg1;
4945          while Present (Assoc) loop
4946             Subp_Id := Get_Pragma_Arg (Assoc);
4947             Analyze (Subp_Id);
4948             Applies := False;
4949
4950             if Is_Entity_Name (Subp_Id) then
4951                Subp := Entity (Subp_Id);
4952
4953                if Subp = Any_Id then
4954
4955                   --  If previous error, avoid cascaded errors
4956
4957                   Applies := True;
4958                   Effective := True;
4959
4960                else
4961                   Make_Inline (Subp);
4962
4963                   --  For the pragma case, climb homonym chain. This is
4964                   --  what implements allowing the pragma in the renaming
4965                   --  case, with the result applying to the ancestors, and
4966                   --  also allows Inline to apply to all previous homonyms.
4967
4968                   if not From_Aspect_Specification (N) then
4969                      while Present (Homonym (Subp))
4970                        and then Scope (Homonym (Subp)) = Current_Scope
4971                      loop
4972                         Make_Inline (Homonym (Subp));
4973                         Subp := Homonym (Subp);
4974                      end loop;
4975                   end if;
4976                end if;
4977             end if;
4978
4979             if not Applies then
4980                Error_Pragma_Arg
4981                  ("inappropriate argument for pragma%", Assoc);
4982
4983             elsif not Effective
4984               and then Warn_On_Redundant_Constructs
4985               and then not Suppress_All_Inlining
4986             then
4987                if Inlining_Not_Possible (Subp) then
4988                   Error_Msg_NE
4989                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4990                else
4991                   Error_Msg_NE
4992                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4993                end if;
4994             end if;
4995
4996             Next (Assoc);
4997          end loop;
4998       end Process_Inline;
4999
5000       ----------------------------
5001       -- Process_Interface_Name --
5002       ----------------------------
5003
5004       procedure Process_Interface_Name
5005         (Subprogram_Def : Entity_Id;
5006          Ext_Arg        : Node_Id;
5007          Link_Arg       : Node_Id)
5008       is
5009          Ext_Nam    : Node_Id;
5010          Link_Nam   : Node_Id;
5011          String_Val : String_Id;
5012
5013          procedure Check_Form_Of_Interface_Name
5014            (SN            : Node_Id;
5015             Ext_Name_Case : Boolean);
5016          --  SN is a string literal node for an interface name. This routine
5017          --  performs some minimal checks that the name is reasonable. In
5018          --  particular that no spaces or other obviously incorrect characters
5019          --  appear. This is only a warning, since any characters are allowed.
5020          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
5021
5022          ----------------------------------
5023          -- Check_Form_Of_Interface_Name --
5024          ----------------------------------
5025
5026          procedure Check_Form_Of_Interface_Name
5027            (SN            : Node_Id;
5028             Ext_Name_Case : Boolean)
5029          is
5030             S  : constant String_Id := Strval (Expr_Value_S (SN));
5031             SL : constant Nat       := String_Length (S);
5032             C  : Char_Code;
5033
5034          begin
5035             if SL = 0 then
5036                Error_Msg_N ("interface name cannot be null string", SN);
5037             end if;
5038
5039             for J in 1 .. SL loop
5040                C := Get_String_Char (S, J);
5041
5042                --  Look for dubious character and issue unconditional warning.
5043                --  Definitely dubious if not in character range.
5044
5045                if not In_Character_Range (C)
5046
5047                   --  For all cases except CLI target,
5048                   --  commas, spaces and slashes are dubious (in CLI, we use
5049                   --  commas and backslashes in external names to specify
5050                   --  assembly version and public key, while slashes and spaces
5051                   --  can be used in names to mark nested classes and
5052                   --  valuetypes).
5053
5054                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5055                              and then (Get_Character (C) = ','
5056                                          or else
5057                                        Get_Character (C) = '\'))
5058                  or else (VM_Target /= CLI_Target
5059                             and then (Get_Character (C) = ' '
5060                                         or else
5061                                       Get_Character (C) = '/'))
5062                then
5063                   Error_Msg
5064                     ("?interface name contains illegal character",
5065                      Sloc (SN) + Source_Ptr (J));
5066                end if;
5067             end loop;
5068          end Check_Form_Of_Interface_Name;
5069
5070       --  Start of processing for Process_Interface_Name
5071
5072       begin
5073          if No (Link_Arg) then
5074             if No (Ext_Arg) then
5075                if VM_Target = CLI_Target
5076                  and then Ekind (Subprogram_Def) = E_Package
5077                  and then Nkind (Parent (Subprogram_Def)) =
5078                                                  N_Package_Specification
5079                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
5080                then
5081                   Set_Interface_Name
5082                      (Subprogram_Def,
5083                       Interface_Name
5084                         (Generic_Parent (Parent (Subprogram_Def))));
5085                end if;
5086
5087                return;
5088
5089             elsif Chars (Ext_Arg) = Name_Link_Name then
5090                Ext_Nam  := Empty;
5091                Link_Nam := Expression (Ext_Arg);
5092
5093             else
5094                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5095                Ext_Nam  := Expression (Ext_Arg);
5096                Link_Nam := Empty;
5097             end if;
5098
5099          else
5100             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
5101             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5102             Ext_Nam  := Expression (Ext_Arg);
5103             Link_Nam := Expression (Link_Arg);
5104          end if;
5105
5106          --  Check expressions for external name and link name are static
5107
5108          if Present (Ext_Nam) then
5109             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5110             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5111
5112             --  Verify that external name is not the name of a local entity,
5113             --  which would hide the imported one and could lead to run-time
5114             --  surprises. The problem can only arise for entities declared in
5115             --  a package body (otherwise the external name is fully qualified
5116             --  and will not conflict).
5117
5118             declare
5119                Nam : Name_Id;
5120                E   : Entity_Id;
5121                Par : Node_Id;
5122
5123             begin
5124                if Prag_Id = Pragma_Import then
5125                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5126                   Nam := Name_Find;
5127                   E   := Entity_Id (Get_Name_Table_Info (Nam));
5128
5129                   if Nam /= Chars (Subprogram_Def)
5130                     and then Present (E)
5131                     and then not Is_Overloadable (E)
5132                     and then Is_Immediately_Visible (E)
5133                     and then not Is_Imported (E)
5134                     and then Ekind (Scope (E)) = E_Package
5135                   then
5136                      Par := Parent (E);
5137                      while Present (Par) loop
5138                         if Nkind (Par) = N_Package_Body then
5139                            Error_Msg_Sloc := Sloc (E);
5140                            Error_Msg_NE
5141                              ("imported entity is hidden by & declared#",
5142                               Ext_Arg, E);
5143                            exit;
5144                         end if;
5145
5146                         Par := Parent (Par);
5147                      end loop;
5148                   end if;
5149                end if;
5150             end;
5151          end if;
5152
5153          if Present (Link_Nam) then
5154             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5155             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5156          end if;
5157
5158          --  If there is no link name, just set the external name
5159
5160          if No (Link_Nam) then
5161             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5162
5163          --  For the Link_Name case, the given literal is preceded by an
5164          --  asterisk, which indicates to GCC that the given name should be
5165          --  taken literally, and in particular that no prepending of
5166          --  underlines should occur, even in systems where this is the
5167          --  normal default.
5168
5169          else
5170             Start_String;
5171
5172             if VM_Target = No_VM then
5173                Store_String_Char (Get_Char_Code ('*'));
5174             end if;
5175
5176             String_Val := Strval (Expr_Value_S (Link_Nam));
5177             Store_String_Chars (String_Val);
5178             Link_Nam :=
5179               Make_String_Literal (Sloc (Link_Nam),
5180                 Strval => End_String);
5181          end if;
5182
5183          --  Set the interface name. If the entity is a generic instance, use
5184          --  its alias, which is the callable entity.
5185
5186          if Is_Generic_Instance (Subprogram_Def) then
5187             Set_Encoded_Interface_Name
5188               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5189          else
5190             Set_Encoded_Interface_Name
5191               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5192          end if;
5193
5194          --  We allow duplicated export names in CIL/Java, as they are always
5195          --  enclosed in a namespace that differentiates them, and overloaded
5196          --  entities are supported by the VM.
5197
5198          if Convention (Subprogram_Def) /= Convention_CIL
5199               and then
5200             Convention (Subprogram_Def) /= Convention_Java
5201          then
5202             Check_Duplicated_Export_Name (Link_Nam);
5203          end if;
5204       end Process_Interface_Name;
5205
5206       -----------------------------------------
5207       -- Process_Interrupt_Or_Attach_Handler --
5208       -----------------------------------------
5209
5210       procedure Process_Interrupt_Or_Attach_Handler is
5211          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5212          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5213          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5214
5215       begin
5216          Set_Is_Interrupt_Handler (Handler_Proc);
5217
5218          --  If the pragma is not associated with a handler procedure within a
5219          --  protected type, then it must be for a nonprotected procedure for
5220          --  the AAMP target, in which case we don't associate a representation
5221          --  item with the procedure's scope.
5222
5223          if Ekind (Proc_Scope) = E_Protected_Type then
5224             if Prag_Id = Pragma_Interrupt_Handler
5225                  or else
5226                Prag_Id = Pragma_Attach_Handler
5227             then
5228                Record_Rep_Item (Proc_Scope, N);
5229             end if;
5230          end if;
5231       end Process_Interrupt_Or_Attach_Handler;
5232
5233       --------------------------------------------------
5234       -- Process_Restrictions_Or_Restriction_Warnings --
5235       --------------------------------------------------
5236
5237       --  Note: some of the simple identifier cases were handled in par-prag,
5238       --  but it is harmless (and more straightforward) to simply handle all
5239       --  cases here, even if it means we repeat a bit of work in some cases.
5240
5241       procedure Process_Restrictions_Or_Restriction_Warnings
5242         (Warn : Boolean)
5243       is
5244          Arg   : Node_Id;
5245          R_Id  : Restriction_Id;
5246          Id    : Name_Id;
5247          Expr  : Node_Id;
5248          Val   : Uint;
5249
5250          procedure Check_Unit_Name (N : Node_Id);
5251          --  Checks unit name parameter for No_Dependence. Returns if it has
5252          --  an appropriate form, otherwise raises pragma argument error.
5253
5254          ---------------------
5255          -- Check_Unit_Name --
5256          ---------------------
5257
5258          procedure Check_Unit_Name (N : Node_Id) is
5259          begin
5260             if Nkind (N) = N_Selected_Component then
5261                Check_Unit_Name (Prefix (N));
5262                Check_Unit_Name (Selector_Name (N));
5263
5264             elsif Nkind (N) = N_Identifier then
5265                return;
5266
5267             else
5268                Error_Pragma_Arg
5269                  ("wrong form for unit name for No_Dependence", N);
5270             end if;
5271          end Check_Unit_Name;
5272
5273       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5274
5275       begin
5276          --  Ignore all Restrictions pragma in CodePeer mode
5277
5278          if CodePeer_Mode then
5279             return;
5280          end if;
5281
5282          Check_Ada_83_Warning;
5283          Check_At_Least_N_Arguments (1);
5284          Check_Valid_Configuration_Pragma;
5285
5286          Arg := Arg1;
5287          while Present (Arg) loop
5288             Id := Chars (Arg);
5289             Expr := Get_Pragma_Arg (Arg);
5290
5291             --  Case of no restriction identifier present
5292
5293             if Id = No_Name then
5294                if Nkind (Expr) /= N_Identifier then
5295                   Error_Pragma_Arg
5296                     ("invalid form for restriction", Arg);
5297                end if;
5298
5299                R_Id :=
5300                  Get_Restriction_Id
5301                    (Process_Restriction_Synonyms (Expr));
5302
5303                if R_Id not in All_Boolean_Restrictions then
5304                   Error_Msg_Name_1 := Pname;
5305                   Error_Msg_N
5306                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5307
5308                   --  Check for possible misspelling
5309
5310                   for J in Restriction_Id loop
5311                      declare
5312                         Rnm : constant String := Restriction_Id'Image (J);
5313
5314                      begin
5315                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5316                         Name_Len := Rnm'Length;
5317                         Set_Casing (All_Lower_Case);
5318
5319                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5320                            Set_Casing
5321                              (Identifier_Casing (Current_Source_File));
5322                            Error_Msg_String (1 .. Rnm'Length) :=
5323                              Name_Buffer (1 .. Name_Len);
5324                            Error_Msg_Strlen := Rnm'Length;
5325                            Error_Msg_N -- CODEFIX
5326                              ("\possible misspelling of ""~""",
5327                               Get_Pragma_Arg (Arg));
5328                            exit;
5329                         end if;
5330                      end;
5331                   end loop;
5332
5333                   raise Pragma_Exit;
5334                end if;
5335
5336                if Implementation_Restriction (R_Id) then
5337                   Check_Restriction (No_Implementation_Restrictions, Arg);
5338                end if;
5339
5340                --  If this is a warning, then set the warning unless we already
5341                --  have a real restriction active (we never want a warning to
5342                --  override a real restriction).
5343
5344                if Warn then
5345                   if not Restriction_Active (R_Id) then
5346                      Set_Restriction (R_Id, N);
5347                      Restriction_Warnings (R_Id) := True;
5348                   end if;
5349
5350                --  If real restriction case, then set it and make sure that the
5351                --  restriction warning flag is off, since a real restriction
5352                --  always overrides a warning.
5353
5354                else
5355                   Set_Restriction (R_Id, N);
5356                   Restriction_Warnings (R_Id) := False;
5357                end if;
5358
5359                --  Check for obsolescent restrictions in Ada 2005 mode
5360
5361                if not Warn
5362                  and then Ada_Version >= Ada_2005
5363                  and then (R_Id = No_Asynchronous_Control
5364                             or else
5365                            R_Id = No_Unchecked_Deallocation
5366                             or else
5367                            R_Id = No_Unchecked_Conversion)
5368                then
5369                   Check_Restriction (No_Obsolescent_Features, N);
5370                end if;
5371
5372                --  A very special case that must be processed here: pragma
5373                --  Restrictions (No_Exceptions) turns off all run-time
5374                --  checking. This is a bit dubious in terms of the formal
5375                --  language definition, but it is what is intended by RM
5376                --  H.4(12). Restriction_Warnings never affects generated code
5377                --  so this is done only in the real restriction case.
5378
5379                --  Atomic_Synchronization is not a real check, so it is not
5380                --  affected by this processing).
5381
5382                if R_Id = No_Exceptions and then not Warn then
5383                   for J in Scope_Suppress'Range loop
5384                      if J /= Atomic_Synchronization then
5385                         Scope_Suppress (J) := True;
5386                      end if;
5387                   end loop;
5388                end if;
5389
5390             --  Case of No_Dependence => unit-name. Note that the parser
5391             --  already made the necessary entry in the No_Dependence table.
5392
5393             elsif Id = Name_No_Dependence then
5394                Check_Unit_Name (Expr);
5395
5396             --  Case of No_Specification_Of_Aspect => Identifier.
5397
5398             elsif Id = Name_No_Specification_Of_Aspect then
5399                declare
5400                   A_Id : Aspect_Id;
5401
5402                begin
5403                   if Nkind (Expr) /= N_Identifier then
5404                      A_Id := No_Aspect;
5405                   else
5406                      A_Id := Get_Aspect_Id (Chars (Expr));
5407                   end if;
5408
5409                   if A_Id = No_Aspect then
5410                      Error_Pragma_Arg ("invalid restriction name", Arg);
5411                   else
5412                      Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
5413                   end if;
5414                end;
5415
5416             --  All other cases of restriction identifier present
5417
5418             else
5419                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5420                Analyze_And_Resolve (Expr, Any_Integer);
5421
5422                if R_Id not in All_Parameter_Restrictions then
5423                   Error_Pragma_Arg
5424                     ("invalid restriction parameter identifier", Arg);
5425
5426                elsif not Is_OK_Static_Expression (Expr) then
5427                   Flag_Non_Static_Expr
5428                     ("value must be static expression!", Expr);
5429                   raise Pragma_Exit;
5430
5431                elsif not Is_Integer_Type (Etype (Expr))
5432                  or else Expr_Value (Expr) < 0
5433                then
5434                   Error_Pragma_Arg
5435                     ("value must be non-negative integer", Arg);
5436                end if;
5437
5438                --  Restriction pragma is active
5439
5440                Val := Expr_Value (Expr);
5441
5442                if not UI_Is_In_Int_Range (Val) then
5443                   Error_Pragma_Arg
5444                     ("pragma ignored, value too large?", Arg);
5445                end if;
5446
5447                --  Warning case. If the real restriction is active, then we
5448                --  ignore the request, since warning never overrides a real
5449                --  restriction. Otherwise we set the proper warning. Note that
5450                --  this circuit sets the warning again if it is already set,
5451                --  which is what we want, since the constant may have changed.
5452
5453                if Warn then
5454                   if not Restriction_Active (R_Id) then
5455                      Set_Restriction
5456                        (R_Id, N, Integer (UI_To_Int (Val)));
5457                      Restriction_Warnings (R_Id) := True;
5458                   end if;
5459
5460                --  Real restriction case, set restriction and make sure warning
5461                --  flag is off since real restriction always overrides warning.
5462
5463                else
5464                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5465                   Restriction_Warnings (R_Id) := False;
5466                end if;
5467             end if;
5468
5469             Next (Arg);
5470          end loop;
5471       end Process_Restrictions_Or_Restriction_Warnings;
5472
5473       ---------------------------------
5474       -- Process_Suppress_Unsuppress --
5475       ---------------------------------
5476
5477       --  Note: this procedure makes entries in the check suppress data
5478       --  structures managed by Sem. See spec of package Sem for full
5479       --  details on how we handle recording of check suppression.
5480
5481       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5482          C    : Check_Id;
5483          E_Id : Node_Id;
5484          E    : Entity_Id;
5485
5486          In_Package_Spec : constant Boolean :=
5487                              Is_Package_Or_Generic_Package (Current_Scope)
5488                                and then not In_Package_Body (Current_Scope);
5489
5490          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5491          --  Used to suppress a single check on the given entity
5492
5493          --------------------------------
5494          -- Suppress_Unsuppress_Echeck --
5495          --------------------------------
5496
5497          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5498          begin
5499             --  Check for error of trying to set atomic synchronization for
5500             --  a non-atomic variable.
5501
5502             if C = Atomic_Synchronization
5503               and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
5504             then
5505                Error_Msg_N
5506                  ("pragma & requires atomic type or variable",
5507                   Pragma_Identifier (Original_Node (N)));
5508             end if;
5509
5510             Set_Checks_May_Be_Suppressed (E);
5511
5512             if In_Package_Spec then
5513                Push_Global_Suppress_Stack_Entry
5514                  (Entity   => E,
5515                   Check    => C,
5516                   Suppress => Suppress_Case);
5517             else
5518                Push_Local_Suppress_Stack_Entry
5519                  (Entity   => E,
5520                   Check    => C,
5521                   Suppress => Suppress_Case);
5522             end if;
5523
5524             --  If this is a first subtype, and the base type is distinct,
5525             --  then also set the suppress flags on the base type.
5526
5527             if Is_First_Subtype (E)
5528               and then Etype (E) /= E
5529             then
5530                Suppress_Unsuppress_Echeck (Etype (E), C);
5531             end if;
5532          end Suppress_Unsuppress_Echeck;
5533
5534       --  Start of processing for Process_Suppress_Unsuppress
5535
5536       begin
5537          --  Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5538          --  user code: we want to generate checks for analysis purposes, as
5539          --  set respectively by -gnatC and -gnatd.F
5540
5541          if (CodePeer_Mode or Alfa_Mode)
5542            and then Comes_From_Source (N)
5543          then
5544             return;
5545          end if;
5546
5547          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5548          --  declarative part or a package spec (RM 11.5(5)).
5549
5550          if not Is_Configuration_Pragma then
5551             Check_Is_In_Decl_Part_Or_Package_Spec;
5552          end if;
5553
5554          Check_At_Least_N_Arguments (1);
5555          Check_At_Most_N_Arguments (2);
5556          Check_No_Identifier (Arg1);
5557          Check_Arg_Is_Identifier (Arg1);
5558
5559          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5560
5561          if C = No_Check_Id then
5562             Error_Pragma_Arg
5563               ("argument of pragma% is not valid check name", Arg1);
5564          end if;
5565
5566          if not Suppress_Case
5567            and then (C = All_Checks or else C = Overflow_Check)
5568          then
5569             Opt.Overflow_Checks_Unsuppressed := True;
5570          end if;
5571
5572          if Arg_Count = 1 then
5573
5574             --  Make an entry in the local scope suppress table. This is the
5575             --  table that directly shows the current value of the scope
5576             --  suppress check for any check id value.
5577
5578             if C = All_Checks then
5579
5580                --  For All_Checks, we set all specific predefined checks with
5581                --  the exception of Elaboration_Check, which is handled
5582                --  specially because of not wanting All_Checks to have the
5583                --  effect of deactivating static elaboration order processing.
5584                --  Atomic_Synchronization is also not affected, since this is
5585                --  not a real check.
5586
5587                for J in Scope_Suppress'Range loop
5588                   if J /= Elaboration_Check
5589                     and then J /= Atomic_Synchronization
5590                   then
5591                      Scope_Suppress (J) := Suppress_Case;
5592                   end if;
5593                end loop;
5594
5595             --  If not All_Checks, and predefined check, then set appropriate
5596             --  scope entry. Note that we will set Elaboration_Check if this
5597             --  is explicitly specified. Atomic_Synchronization is allowed
5598             --  only if internally generated and entity is atomic.
5599
5600             elsif C in Predefined_Check_Id
5601               and then (not Comes_From_Source (N)
5602                          or else C /= Atomic_Synchronization)
5603             then
5604                Scope_Suppress (C) := Suppress_Case;
5605             end if;
5606
5607             --  Also make an entry in the Local_Entity_Suppress table
5608
5609             Push_Local_Suppress_Stack_Entry
5610               (Entity   => Empty,
5611                Check    => C,
5612                Suppress => Suppress_Case);
5613
5614          --  Case of two arguments present, where the check is suppressed for
5615          --  a specified entity (given as the second argument of the pragma)
5616
5617          else
5618             --  This is obsolescent in Ada 2005 mode
5619
5620             if Ada_Version >= Ada_2005 then
5621                Check_Restriction (No_Obsolescent_Features, Arg2);
5622             end if;
5623
5624             Check_Optional_Identifier (Arg2, Name_On);
5625             E_Id := Get_Pragma_Arg (Arg2);
5626             Analyze (E_Id);
5627
5628             if not Is_Entity_Name (E_Id) then
5629                Error_Pragma_Arg
5630                  ("second argument of pragma% must be entity name", Arg2);
5631             end if;
5632
5633             E := Entity (E_Id);
5634
5635             if E = Any_Id then
5636                return;
5637             end if;
5638
5639             --  Enforce RM 11.5(7) which requires that for a pragma that
5640             --  appears within a package spec, the named entity must be
5641             --  within the package spec. We allow the package name itself
5642             --  to be mentioned since that makes sense, although it is not
5643             --  strictly allowed by 11.5(7).
5644
5645             if In_Package_Spec
5646               and then E /= Current_Scope
5647               and then Scope (E) /= Current_Scope
5648             then
5649                Error_Pragma_Arg
5650                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5651                   Arg2);
5652             end if;
5653
5654             --  Loop through homonyms. As noted below, in the case of a package
5655             --  spec, only homonyms within the package spec are considered.
5656
5657             loop
5658                Suppress_Unsuppress_Echeck (E, C);
5659
5660                if Is_Generic_Instance (E)
5661                  and then Is_Subprogram (E)
5662                  and then Present (Alias (E))
5663                then
5664                   Suppress_Unsuppress_Echeck (Alias (E), C);
5665                end if;
5666
5667                --  Move to next homonym if not aspect spec case
5668
5669                exit when From_Aspect_Specification (N);
5670                E := Homonym (E);
5671                exit when No (E);
5672
5673                --  If we are within a package specification, the pragma only
5674                --  applies to homonyms in the same scope.
5675
5676                exit when In_Package_Spec
5677                  and then Scope (E) /= Current_Scope;
5678             end loop;
5679          end if;
5680       end Process_Suppress_Unsuppress;
5681
5682       ------------------
5683       -- Set_Exported --
5684       ------------------
5685
5686       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5687       begin
5688          if Is_Imported (E) then
5689             Error_Pragma_Arg
5690               ("cannot export entity& that was previously imported", Arg);
5691
5692          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5693             Error_Pragma_Arg
5694               ("cannot export entity& that has an address clause", Arg);
5695          end if;
5696
5697          Set_Is_Exported (E);
5698
5699          --  Generate a reference for entity explicitly, because the
5700          --  identifier may be overloaded and name resolution will not
5701          --  generate one.
5702
5703          Generate_Reference (E, Arg);
5704
5705          --  Deal with exporting non-library level entity
5706
5707          if not Is_Library_Level_Entity (E) then
5708
5709             --  Not allowed at all for subprograms
5710
5711             if Is_Subprogram (E) then
5712                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5713
5714             --  Otherwise set public and statically allocated
5715
5716             else
5717                Set_Is_Public (E);
5718                Set_Is_Statically_Allocated (E);
5719
5720                --  Warn if the corresponding W flag is set and the pragma comes
5721                --  from source. The latter may not be true e.g. on VMS where we
5722                --  expand export pragmas for exception codes associated with
5723                --  imported or exported exceptions. We do not want to generate
5724                --  a warning for something that the user did not write.
5725
5726                if Warn_On_Export_Import
5727                  and then Comes_From_Source (Arg)
5728                then
5729                   Error_Msg_NE
5730                     ("?& has been made static as a result of Export", Arg, E);
5731                   Error_Msg_N
5732                     ("\this usage is non-standard and non-portable", Arg);
5733                end if;
5734             end if;
5735          end if;
5736
5737          if Warn_On_Export_Import and then Is_Type (E) then
5738             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5739          end if;
5740
5741          if Warn_On_Export_Import and Inside_A_Generic then
5742             Error_Msg_NE
5743               ("all instances of& will have the same external name?", Arg, E);
5744          end if;
5745       end Set_Exported;
5746
5747       ----------------------------------------------
5748       -- Set_Extended_Import_Export_External_Name --
5749       ----------------------------------------------
5750
5751       procedure Set_Extended_Import_Export_External_Name
5752         (Internal_Ent : Entity_Id;
5753          Arg_External : Node_Id)
5754       is
5755          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5756          New_Name : Node_Id;
5757
5758       begin
5759          if No (Arg_External) then
5760             return;
5761          end if;
5762
5763          Check_Arg_Is_External_Name (Arg_External);
5764
5765          if Nkind (Arg_External) = N_String_Literal then
5766             if String_Length (Strval (Arg_External)) = 0 then
5767                return;
5768             else
5769                New_Name := Adjust_External_Name_Case (Arg_External);
5770             end if;
5771
5772          elsif Nkind (Arg_External) = N_Identifier then
5773             New_Name := Get_Default_External_Name (Arg_External);
5774
5775          --  Check_Arg_Is_External_Name should let through only identifiers and
5776          --  string literals or static string expressions (which are folded to
5777          --  string literals).
5778
5779          else
5780             raise Program_Error;
5781          end if;
5782
5783          --  If we already have an external name set (by a prior normal Import
5784          --  or Export pragma), then the external names must match
5785
5786          if Present (Interface_Name (Internal_Ent)) then
5787             Check_Matching_Internal_Names : declare
5788                S1 : constant String_Id := Strval (Old_Name);
5789                S2 : constant String_Id := Strval (New_Name);
5790
5791                procedure Mismatch;
5792                --  Called if names do not match
5793
5794                --------------
5795                -- Mismatch --
5796                --------------
5797
5798                procedure Mismatch is
5799                begin
5800                   Error_Msg_Sloc := Sloc (Old_Name);
5801                   Error_Pragma_Arg
5802                     ("external name does not match that given #",
5803                      Arg_External);
5804                end Mismatch;
5805
5806             --  Start of processing for Check_Matching_Internal_Names
5807
5808             begin
5809                if String_Length (S1) /= String_Length (S2) then
5810                   Mismatch;
5811
5812                else
5813                   for J in 1 .. String_Length (S1) loop
5814                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5815                         Mismatch;
5816                      end if;
5817                   end loop;
5818                end if;
5819             end Check_Matching_Internal_Names;
5820
5821          --  Otherwise set the given name
5822
5823          else
5824             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5825             Check_Duplicated_Export_Name (New_Name);
5826          end if;
5827       end Set_Extended_Import_Export_External_Name;
5828
5829       ------------------
5830       -- Set_Imported --
5831       ------------------
5832
5833       procedure Set_Imported (E : Entity_Id) is
5834       begin
5835          --  Error message if already imported or exported
5836
5837          if Is_Exported (E) or else Is_Imported (E) then
5838
5839             --  Error if being set Exported twice
5840
5841             if Is_Exported (E) then
5842                Error_Msg_NE ("entity& was previously exported", N, E);
5843
5844             --  OK if Import/Interface case
5845
5846             elsif Import_Interface_Present (N) then
5847                goto OK;
5848
5849             --  Error if being set Imported twice
5850
5851             else
5852                Error_Msg_NE ("entity& was previously imported", N, E);
5853             end if;
5854
5855             Error_Msg_Name_1 := Pname;
5856             Error_Msg_N
5857               ("\(pragma% applies to all previous entities)", N);
5858
5859             Error_Msg_Sloc  := Sloc (E);
5860             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5861
5862          --  Here if not previously imported or exported, OK to import
5863
5864          else
5865             Set_Is_Imported (E);
5866
5867             --  If the entity is an object that is not at the library level,
5868             --  then it is statically allocated. We do not worry about objects
5869             --  with address clauses in this context since they are not really
5870             --  imported in the linker sense.
5871
5872             if Is_Object (E)
5873               and then not Is_Library_Level_Entity (E)
5874               and then No (Address_Clause (E))
5875             then
5876                Set_Is_Statically_Allocated (E);
5877             end if;
5878          end if;
5879
5880          <<OK>> null;
5881       end Set_Imported;
5882
5883       -------------------------
5884       -- Set_Mechanism_Value --
5885       -------------------------
5886
5887       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5888       --  analyzed, since it is semantic nonsense), so we get it in the exact
5889       --  form created by the parser.
5890
5891       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5892          Class        : Node_Id;
5893          Param        : Node_Id;
5894          Mech_Name_Id : Name_Id;
5895
5896          procedure Bad_Class;
5897          --  Signal bad descriptor class name
5898
5899          procedure Bad_Mechanism;
5900          --  Signal bad mechanism name
5901
5902          ---------------
5903          -- Bad_Class --
5904          ---------------
5905
5906          procedure Bad_Class is
5907          begin
5908             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5909          end Bad_Class;
5910
5911          -------------------------
5912          -- Bad_Mechanism_Value --
5913          -------------------------
5914
5915          procedure Bad_Mechanism is
5916          begin
5917             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5918          end Bad_Mechanism;
5919
5920       --  Start of processing for Set_Mechanism_Value
5921
5922       begin
5923          if Mechanism (Ent) /= Default_Mechanism then
5924             Error_Msg_NE
5925               ("mechanism for & has already been set", Mech_Name, Ent);
5926          end if;
5927
5928          --  MECHANISM_NAME ::= value | reference | descriptor |
5929          --                     short_descriptor
5930
5931          if Nkind (Mech_Name) = N_Identifier then
5932             if Chars (Mech_Name) = Name_Value then
5933                Set_Mechanism (Ent, By_Copy);
5934                return;
5935
5936             elsif Chars (Mech_Name) = Name_Reference then
5937                Set_Mechanism (Ent, By_Reference);
5938                return;
5939
5940             elsif Chars (Mech_Name) = Name_Descriptor then
5941                Check_VMS (Mech_Name);
5942
5943                --  Descriptor => Short_Descriptor if pragma was given
5944
5945                if Short_Descriptors then
5946                   Set_Mechanism (Ent, By_Short_Descriptor);
5947                else
5948                   Set_Mechanism (Ent, By_Descriptor);
5949                end if;
5950
5951                return;
5952
5953             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5954                Check_VMS (Mech_Name);
5955                Set_Mechanism (Ent, By_Short_Descriptor);
5956                return;
5957
5958             elsif Chars (Mech_Name) = Name_Copy then
5959                Error_Pragma_Arg
5960                  ("bad mechanism name, Value assumed", Mech_Name);
5961
5962             else
5963                Bad_Mechanism;
5964             end if;
5965
5966          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5967          --                     short_descriptor (CLASS_NAME)
5968          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5969
5970          --  Note: this form is parsed as an indexed component
5971
5972          elsif Nkind (Mech_Name) = N_Indexed_Component then
5973             Class := First (Expressions (Mech_Name));
5974
5975             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5976              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5977                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5978              or else Present (Next (Class))
5979             then
5980                Bad_Mechanism;
5981             else
5982                Mech_Name_Id := Chars (Prefix (Mech_Name));
5983
5984                --  Change Descriptor => Short_Descriptor if pragma was given
5985
5986                if Mech_Name_Id = Name_Descriptor
5987                  and then Short_Descriptors
5988                then
5989                   Mech_Name_Id := Name_Short_Descriptor;
5990                end if;
5991             end if;
5992
5993          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5994          --                     short_descriptor (Class => CLASS_NAME)
5995          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5996
5997          --  Note: this form is parsed as a function call
5998
5999          elsif Nkind (Mech_Name) = N_Function_Call then
6000             Param := First (Parameter_Associations (Mech_Name));
6001
6002             if Nkind (Name (Mech_Name)) /= N_Identifier
6003               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
6004                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
6005               or else Present (Next (Param))
6006               or else No (Selector_Name (Param))
6007               or else Chars (Selector_Name (Param)) /= Name_Class
6008             then
6009                Bad_Mechanism;
6010             else
6011                Class := Explicit_Actual_Parameter (Param);
6012                Mech_Name_Id := Chars (Name (Mech_Name));
6013             end if;
6014
6015          else
6016             Bad_Mechanism;
6017          end if;
6018
6019          --  Fall through here with Class set to descriptor class name
6020
6021          Check_VMS (Mech_Name);
6022
6023          if Nkind (Class) /= N_Identifier then
6024             Bad_Class;
6025
6026          elsif Mech_Name_Id = Name_Descriptor
6027            and then Chars (Class) = Name_UBS
6028          then
6029             Set_Mechanism (Ent, By_Descriptor_UBS);
6030
6031          elsif Mech_Name_Id = Name_Descriptor
6032            and then Chars (Class) = Name_UBSB
6033          then
6034             Set_Mechanism (Ent, By_Descriptor_UBSB);
6035
6036          elsif Mech_Name_Id = Name_Descriptor
6037            and then Chars (Class) = Name_UBA
6038          then
6039             Set_Mechanism (Ent, By_Descriptor_UBA);
6040
6041          elsif Mech_Name_Id = Name_Descriptor
6042            and then Chars (Class) = Name_S
6043          then
6044             Set_Mechanism (Ent, By_Descriptor_S);
6045
6046          elsif Mech_Name_Id = Name_Descriptor
6047            and then Chars (Class) = Name_SB
6048          then
6049             Set_Mechanism (Ent, By_Descriptor_SB);
6050
6051          elsif Mech_Name_Id = Name_Descriptor
6052            and then Chars (Class) = Name_A
6053          then
6054             Set_Mechanism (Ent, By_Descriptor_A);
6055
6056          elsif Mech_Name_Id = Name_Descriptor
6057            and then Chars (Class) = Name_NCA
6058          then
6059             Set_Mechanism (Ent, By_Descriptor_NCA);
6060
6061          elsif Mech_Name_Id = Name_Short_Descriptor
6062            and then Chars (Class) = Name_UBS
6063          then
6064             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
6065
6066          elsif Mech_Name_Id = Name_Short_Descriptor
6067            and then Chars (Class) = Name_UBSB
6068          then
6069             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
6070
6071          elsif Mech_Name_Id = Name_Short_Descriptor
6072            and then Chars (Class) = Name_UBA
6073          then
6074             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
6075
6076          elsif Mech_Name_Id = Name_Short_Descriptor
6077            and then Chars (Class) = Name_S
6078          then
6079             Set_Mechanism (Ent, By_Short_Descriptor_S);
6080
6081          elsif Mech_Name_Id = Name_Short_Descriptor
6082            and then Chars (Class) = Name_SB
6083          then
6084             Set_Mechanism (Ent, By_Short_Descriptor_SB);
6085
6086          elsif Mech_Name_Id = Name_Short_Descriptor
6087            and then Chars (Class) = Name_A
6088          then
6089             Set_Mechanism (Ent, By_Short_Descriptor_A);
6090
6091          elsif Mech_Name_Id = Name_Short_Descriptor
6092            and then Chars (Class) = Name_NCA
6093          then
6094             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6095
6096          else
6097             Bad_Class;
6098          end if;
6099       end Set_Mechanism_Value;
6100
6101       ---------------------------
6102       -- Set_Ravenscar_Profile --
6103       ---------------------------
6104
6105       --  The tasks to be done here are
6106
6107       --    Set required policies
6108
6109       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6110       --      pragma Locking_Policy (Ceiling_Locking)
6111
6112       --    Set Detect_Blocking mode
6113
6114       --    Set required restrictions (see System.Rident for detailed list)
6115
6116       --    Set the No_Dependence rules
6117       --      No_Dependence => Ada.Asynchronous_Task_Control
6118       --      No_Dependence => Ada.Calendar
6119       --      No_Dependence => Ada.Execution_Time.Group_Budget
6120       --      No_Dependence => Ada.Execution_Time.Timers
6121       --      No_Dependence => Ada.Task_Attributes
6122       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
6123
6124       procedure Set_Ravenscar_Profile (N : Node_Id) is
6125          Prefix_Entity   : Entity_Id;
6126          Selector_Entity : Entity_Id;
6127          Prefix_Node     : Node_Id;
6128          Node            : Node_Id;
6129
6130       begin
6131          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6132
6133          if Task_Dispatching_Policy /= ' '
6134            and then Task_Dispatching_Policy /= 'F'
6135          then
6136             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6137             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6138
6139          --  Set the FIFO_Within_Priorities policy, but always preserve
6140          --  System_Location since we like the error message with the run time
6141          --  name.
6142
6143          else
6144             Task_Dispatching_Policy := 'F';
6145
6146             if Task_Dispatching_Policy_Sloc /= System_Location then
6147                Task_Dispatching_Policy_Sloc := Loc;
6148             end if;
6149          end if;
6150
6151          --  pragma Locking_Policy (Ceiling_Locking)
6152
6153          if Locking_Policy /= ' '
6154            and then Locking_Policy /= 'C'
6155          then
6156             Error_Msg_Sloc := Locking_Policy_Sloc;
6157             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6158
6159          --  Set the Ceiling_Locking policy, but preserve System_Location since
6160          --  we like the error message with the run time name.
6161
6162          else
6163             Locking_Policy := 'C';
6164
6165             if Locking_Policy_Sloc /= System_Location then
6166                Locking_Policy_Sloc := Loc;
6167             end if;
6168          end if;
6169
6170          --  pragma Detect_Blocking
6171
6172          Detect_Blocking := True;
6173
6174          --  Set the corresponding restrictions
6175
6176          Set_Profile_Restrictions
6177            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6178
6179          --  Set the No_Dependence restrictions
6180
6181          --  The following No_Dependence restrictions:
6182          --    No_Dependence => Ada.Asynchronous_Task_Control
6183          --    No_Dependence => Ada.Calendar
6184          --    No_Dependence => Ada.Task_Attributes
6185          --  are already set by previous call to Set_Profile_Restrictions.
6186
6187          --  Set the following restrictions which were added to Ada 2005:
6188          --    No_Dependence => Ada.Execution_Time.Group_Budget
6189          --    No_Dependence => Ada.Execution_Time.Timers
6190
6191          if Ada_Version >= Ada_2005 then
6192             Name_Buffer (1 .. 3) := "ada";
6193             Name_Len := 3;
6194
6195             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6196
6197             Name_Buffer (1 .. 14) := "execution_time";
6198             Name_Len := 14;
6199
6200             Selector_Entity := Make_Identifier (Loc, Name_Find);
6201
6202             Prefix_Node :=
6203               Make_Selected_Component
6204                 (Sloc          => Loc,
6205                  Prefix        => Prefix_Entity,
6206                  Selector_Name => Selector_Entity);
6207
6208             Name_Buffer (1 .. 13) := "group_budgets";
6209             Name_Len := 13;
6210
6211             Selector_Entity := Make_Identifier (Loc, Name_Find);
6212
6213             Node :=
6214               Make_Selected_Component
6215                 (Sloc          => Loc,
6216                  Prefix        => Prefix_Node,
6217                  Selector_Name => Selector_Entity);
6218
6219             Set_Restriction_No_Dependence
6220               (Unit    => Node,
6221                Warn    => Treat_Restrictions_As_Warnings,
6222                Profile => Ravenscar);
6223
6224             Name_Buffer (1 .. 6) := "timers";
6225             Name_Len := 6;
6226
6227             Selector_Entity := Make_Identifier (Loc, Name_Find);
6228
6229             Node :=
6230               Make_Selected_Component
6231                 (Sloc          => Loc,
6232                  Prefix        => Prefix_Node,
6233                  Selector_Name => Selector_Entity);
6234
6235             Set_Restriction_No_Dependence
6236               (Unit    => Node,
6237                Warn    => Treat_Restrictions_As_Warnings,
6238                Profile => Ravenscar);
6239          end if;
6240
6241          --  Set the following restrictions which was added to Ada 2012 (see
6242          --  AI-0171):
6243          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
6244
6245          if Ada_Version >= Ada_2012 then
6246             Name_Buffer (1 .. 6) := "system";
6247             Name_Len := 6;
6248
6249             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6250
6251             Name_Buffer (1 .. 15) := "multiprocessors";
6252             Name_Len := 15;
6253
6254             Selector_Entity := Make_Identifier (Loc, Name_Find);
6255
6256             Prefix_Node :=
6257               Make_Selected_Component
6258                 (Sloc          => Loc,
6259                  Prefix        => Prefix_Entity,
6260                  Selector_Name => Selector_Entity);
6261
6262             Name_Buffer (1 .. 19) := "dispatching_domains";
6263             Name_Len := 19;
6264
6265             Selector_Entity := Make_Identifier (Loc, Name_Find);
6266
6267             Node :=
6268               Make_Selected_Component
6269                 (Sloc          => Loc,
6270                  Prefix        => Prefix_Node,
6271                  Selector_Name => Selector_Entity);
6272
6273             Set_Restriction_No_Dependence
6274               (Unit    => Node,
6275                Warn    => Treat_Restrictions_As_Warnings,
6276                Profile => Ravenscar);
6277          end if;
6278       end Set_Ravenscar_Profile;
6279
6280    --  Start of processing for Analyze_Pragma
6281
6282    begin
6283       --  The following code is a defense against recursion. Not clear that
6284       --  this can happen legitimately, but perhaps some error situations
6285       --  can cause it, and we did see this recursion during testing.
6286
6287       if Analyzed (N) then
6288          return;
6289       else
6290          Set_Analyzed (N, True);
6291       end if;
6292
6293       --  Deal with unrecognized pragma
6294
6295       Pname := Pragma_Name (N);
6296
6297       if not Is_Pragma_Name (Pname) then
6298          if Warn_On_Unrecognized_Pragma then
6299             Error_Msg_Name_1 := Pname;
6300             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6301
6302             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6303                if Is_Bad_Spelling_Of (Pname, PN) then
6304                   Error_Msg_Name_1 := PN;
6305                   Error_Msg_N -- CODEFIX
6306                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6307                   exit;
6308                end if;
6309             end loop;
6310          end if;
6311
6312          return;
6313       end if;
6314
6315       --  Here to start processing for recognized pragma
6316
6317       Prag_Id := Get_Pragma_Id (Pname);
6318
6319       if Present (Corresponding_Aspect (N)) then
6320          Pname := Chars (Identifier (Corresponding_Aspect (N)));
6321       end if;
6322
6323       --  Preset arguments
6324
6325       Arg_Count := 0;
6326       Arg1      := Empty;
6327       Arg2      := Empty;
6328       Arg3      := Empty;
6329       Arg4      := Empty;
6330
6331       if Present (Pragma_Argument_Associations (N)) then
6332          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6333          Arg1 := First (Pragma_Argument_Associations (N));
6334
6335          if Present (Arg1) then
6336             Arg2 := Next (Arg1);
6337
6338             if Present (Arg2) then
6339                Arg3 := Next (Arg2);
6340
6341                if Present (Arg3) then
6342                   Arg4 := Next (Arg3);
6343                end if;
6344             end if;
6345          end if;
6346       end if;
6347
6348       --  An enumeration type defines the pragmas that are supported by the
6349       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6350       --  into the corresponding enumeration value for the following case.
6351
6352       case Prag_Id is
6353
6354          -----------------
6355          -- Abort_Defer --
6356          -----------------
6357
6358          --  pragma Abort_Defer;
6359
6360          when Pragma_Abort_Defer =>
6361             GNAT_Pragma;
6362             Check_Arg_Count (0);
6363
6364             --  The only required semantic processing is to check the
6365             --  placement. This pragma must appear at the start of the
6366             --  statement sequence of a handled sequence of statements.
6367
6368             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6369               or else N /= First (Statements (Parent (N)))
6370             then
6371                Pragma_Misplaced;
6372             end if;
6373
6374          ------------
6375          -- Ada_83 --
6376          ------------
6377
6378          --  pragma Ada_83;
6379
6380          --  Note: this pragma also has some specific processing in Par.Prag
6381          --  because we want to set the Ada version mode during parsing.
6382
6383          when Pragma_Ada_83 =>
6384             GNAT_Pragma;
6385             Check_Arg_Count (0);
6386
6387             --  We really should check unconditionally for proper configuration
6388             --  pragma placement, since we really don't want mixed Ada modes
6389             --  within a single unit, and the GNAT reference manual has always
6390             --  said this was a configuration pragma, but we did not check and
6391             --  are hesitant to add the check now.
6392
6393             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6394             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6395             --  or Ada 2012 mode.
6396
6397             if Ada_Version >= Ada_2005 then
6398                Check_Valid_Configuration_Pragma;
6399             end if;
6400
6401             --  Now set Ada 83 mode
6402
6403             Ada_Version := Ada_83;
6404             Ada_Version_Explicit := Ada_Version;
6405
6406          ------------
6407          -- Ada_95 --
6408          ------------
6409
6410          --  pragma Ada_95;
6411
6412          --  Note: this pragma also has some specific processing in Par.Prag
6413          --  because we want to set the Ada 83 version mode during parsing.
6414
6415          when Pragma_Ada_95 =>
6416             GNAT_Pragma;
6417             Check_Arg_Count (0);
6418
6419             --  We really should check unconditionally for proper configuration
6420             --  pragma placement, since we really don't want mixed Ada modes
6421             --  within a single unit, and the GNAT reference manual has always
6422             --  said this was a configuration pragma, but we did not check and
6423             --  are hesitant to add the check now.
6424
6425             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6426             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6427
6428             if Ada_Version >= Ada_2005 then
6429                Check_Valid_Configuration_Pragma;
6430             end if;
6431
6432             --  Now set Ada 95 mode
6433
6434             Ada_Version := Ada_95;
6435             Ada_Version_Explicit := Ada_Version;
6436
6437          ---------------------
6438          -- Ada_05/Ada_2005 --
6439          ---------------------
6440
6441          --  pragma Ada_05;
6442          --  pragma Ada_05 (LOCAL_NAME);
6443
6444          --  pragma Ada_2005;
6445          --  pragma Ada_2005 (LOCAL_NAME):
6446
6447          --  Note: these pragmas also have some specific processing in Par.Prag
6448          --  because we want to set the Ada 2005 version mode during parsing.
6449
6450          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6451             E_Id : Node_Id;
6452
6453          begin
6454             GNAT_Pragma;
6455
6456             if Arg_Count = 1 then
6457                Check_Arg_Is_Local_Name (Arg1);
6458                E_Id := Get_Pragma_Arg (Arg1);
6459
6460                if Etype (E_Id) = Any_Type then
6461                   return;
6462                end if;
6463
6464                Set_Is_Ada_2005_Only (Entity (E_Id));
6465
6466             else
6467                Check_Arg_Count (0);
6468
6469                --  For Ada_2005 we unconditionally enforce the documented
6470                --  configuration pragma placement, since we do not want to
6471                --  tolerate mixed modes in a unit involving Ada 2005. That
6472                --  would cause real difficulties for those cases where there
6473                --  are incompatibilities between Ada 95 and Ada 2005.
6474
6475                Check_Valid_Configuration_Pragma;
6476
6477                --  Now set appropriate Ada mode
6478
6479                Ada_Version          := Ada_2005;
6480                Ada_Version_Explicit := Ada_2005;
6481             end if;
6482          end;
6483
6484          ---------------------
6485          -- Ada_12/Ada_2012 --
6486          ---------------------
6487
6488          --  pragma Ada_12;
6489          --  pragma Ada_12 (LOCAL_NAME);
6490
6491          --  pragma Ada_2012;
6492          --  pragma Ada_2012 (LOCAL_NAME):
6493
6494          --  Note: these pragmas also have some specific processing in Par.Prag
6495          --  because we want to set the Ada 2012 version mode during parsing.
6496
6497          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6498             E_Id : Node_Id;
6499
6500          begin
6501             GNAT_Pragma;
6502
6503             if Arg_Count = 1 then
6504                Check_Arg_Is_Local_Name (Arg1);
6505                E_Id := Get_Pragma_Arg (Arg1);
6506
6507                if Etype (E_Id) = Any_Type then
6508                   return;
6509                end if;
6510
6511                Set_Is_Ada_2012_Only (Entity (E_Id));
6512
6513             else
6514                Check_Arg_Count (0);
6515
6516                --  For Ada_2012 we unconditionally enforce the documented
6517                --  configuration pragma placement, since we do not want to
6518                --  tolerate mixed modes in a unit involving Ada 2012. That
6519                --  would cause real difficulties for those cases where there
6520                --  are incompatibilities between Ada 95 and Ada 2012. We could
6521                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6522
6523                Check_Valid_Configuration_Pragma;
6524
6525                --  Now set appropriate Ada mode
6526
6527                Ada_Version          := Ada_2012;
6528                Ada_Version_Explicit := Ada_2012;
6529             end if;
6530          end;
6531
6532          ----------------------
6533          -- All_Calls_Remote --
6534          ----------------------
6535
6536          --  pragma All_Calls_Remote [(library_package_NAME)];
6537
6538          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6539             Lib_Entity : Entity_Id;
6540
6541          begin
6542             Check_Ada_83_Warning;
6543             Check_Valid_Library_Unit_Pragma;
6544
6545             if Nkind (N) = N_Null_Statement then
6546                return;
6547             end if;
6548
6549             Lib_Entity := Find_Lib_Unit_Name;
6550
6551             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6552
6553             if Present (Lib_Entity)
6554               and then not Debug_Flag_U
6555             then
6556                if not Is_Remote_Call_Interface (Lib_Entity) then
6557                   Error_Pragma ("pragma% only apply to rci unit");
6558
6559                --  Set flag for entity of the library unit
6560
6561                else
6562                   Set_Has_All_Calls_Remote (Lib_Entity);
6563                end if;
6564
6565             end if;
6566          end All_Calls_Remote;
6567
6568          --------------
6569          -- Annotate --
6570          --------------
6571
6572          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6573          --  ARG ::= NAME | EXPRESSION
6574
6575          --  The first two arguments are by convention intended to refer to an
6576          --  external tool and a tool-specific function. These arguments are
6577          --  not analyzed.
6578
6579          when Pragma_Annotate => Annotate : declare
6580             Arg : Node_Id;
6581             Exp : Node_Id;
6582
6583          begin
6584             GNAT_Pragma;
6585             Check_At_Least_N_Arguments (1);
6586             Check_Arg_Is_Identifier (Arg1);
6587             Check_No_Identifiers;
6588             Store_Note (N);
6589
6590             --  Second parameter is optional, it is never analyzed
6591
6592             if No (Arg2) then
6593                null;
6594
6595             --  Here if we have a second parameter
6596
6597             else
6598                --  Second parameter must be identifier
6599
6600                Check_Arg_Is_Identifier (Arg2);
6601
6602                --  Process remaining parameters if any
6603
6604                Arg := Next (Arg2);
6605                while Present (Arg) loop
6606                   Exp := Get_Pragma_Arg (Arg);
6607                   Analyze (Exp);
6608
6609                   if Is_Entity_Name (Exp) then
6610                      null;
6611
6612                   --  For string literals, we assume Standard_String as the
6613                   --  type, unless the string contains wide or wide_wide
6614                   --  characters.
6615
6616                   elsif Nkind (Exp) = N_String_Literal then
6617                      if Has_Wide_Wide_Character (Exp) then
6618                         Resolve (Exp, Standard_Wide_Wide_String);
6619                      elsif Has_Wide_Character (Exp) then
6620                         Resolve (Exp, Standard_Wide_String);
6621                      else
6622                         Resolve (Exp, Standard_String);
6623                      end if;
6624
6625                   elsif Is_Overloaded (Exp) then
6626                         Error_Pragma_Arg
6627                           ("ambiguous argument for pragma%", Exp);
6628
6629                   else
6630                      Resolve (Exp);
6631                   end if;
6632
6633                   Next (Arg);
6634                end loop;
6635             end if;
6636          end Annotate;
6637
6638          ------------
6639          -- Assert --
6640          ------------
6641
6642          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6643          --                 [, [Message =>] Static_String_EXPRESSION]);
6644
6645          when Pragma_Assert => Assert : declare
6646             Expr : Node_Id;
6647             Newa : List_Id;
6648
6649          begin
6650             Ada_2005_Pragma;
6651             Check_At_Least_N_Arguments (1);
6652             Check_At_Most_N_Arguments (2);
6653             Check_Arg_Order ((Name_Check, Name_Message));
6654             Check_Optional_Identifier (Arg1, Name_Check);
6655
6656             --  We treat pragma Assert as equivalent to:
6657
6658             --    pragma Check (Assertion, condition [, msg]);
6659
6660             --  So rewrite pragma in this manner, and analyze the result
6661
6662             Expr := Get_Pragma_Arg (Arg1);
6663             Newa := New_List (
6664               Make_Pragma_Argument_Association (Loc,
6665                 Expression => Make_Identifier (Loc, Name_Assertion)),
6666
6667               Make_Pragma_Argument_Association (Sloc (Expr),
6668                 Expression => Expr));
6669
6670             if Arg_Count > 1 then
6671                Check_Optional_Identifier (Arg2, Name_Message);
6672                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6673                Append_To (Newa, Relocate_Node (Arg2));
6674             end if;
6675
6676             Rewrite (N,
6677               Make_Pragma (Loc,
6678                 Chars                        => Name_Check,
6679                 Pragma_Argument_Associations => Newa));
6680             Analyze (N);
6681          end Assert;
6682
6683          ----------------------
6684          -- Assertion_Policy --
6685          ----------------------
6686
6687          --  pragma Assertion_Policy (Check | Disable |Ignore)
6688
6689          when Pragma_Assertion_Policy => Assertion_Policy : declare
6690             Policy : Node_Id;
6691
6692          begin
6693             Ada_2005_Pragma;
6694             Check_Valid_Configuration_Pragma;
6695             Check_Arg_Count (1);
6696             Check_No_Identifiers;
6697             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6698
6699             --  We treat pragma Assertion_Policy as equivalent to:
6700
6701             --    pragma Check_Policy (Assertion, policy)
6702
6703             --  So rewrite the pragma in that manner and link on to the chain
6704             --  of Check_Policy pragmas, marking the pragma as analyzed.
6705
6706             Policy := Get_Pragma_Arg (Arg1);
6707
6708             Rewrite (N,
6709               Make_Pragma (Loc,
6710                 Chars => Name_Check_Policy,
6711
6712                 Pragma_Argument_Associations => New_List (
6713                   Make_Pragma_Argument_Association (Loc,
6714                     Expression => Make_Identifier (Loc, Name_Assertion)),
6715
6716                   Make_Pragma_Argument_Association (Loc,
6717                     Expression =>
6718                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6719
6720             Set_Analyzed (N);
6721             Set_Next_Pragma (N, Opt.Check_Policy_List);
6722             Opt.Check_Policy_List := N;
6723          end Assertion_Policy;
6724
6725          ------------------------------
6726          -- Assume_No_Invalid_Values --
6727          ------------------------------
6728
6729          --  pragma Assume_No_Invalid_Values (On | Off);
6730
6731          when Pragma_Assume_No_Invalid_Values =>
6732             GNAT_Pragma;
6733             Check_Valid_Configuration_Pragma;
6734             Check_Arg_Count (1);
6735             Check_No_Identifiers;
6736             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6737
6738             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6739                Assume_No_Invalid_Values := True;
6740             else
6741                Assume_No_Invalid_Values := False;
6742             end if;
6743
6744          ---------------
6745          -- AST_Entry --
6746          ---------------
6747
6748          --  pragma AST_Entry (entry_IDENTIFIER);
6749
6750          when Pragma_AST_Entry => AST_Entry : declare
6751             Ent : Node_Id;
6752
6753          begin
6754             GNAT_Pragma;
6755             Check_VMS (N);
6756             Check_Arg_Count (1);
6757             Check_No_Identifiers;
6758             Check_Arg_Is_Local_Name (Arg1);
6759             Ent := Entity (Get_Pragma_Arg (Arg1));
6760
6761             --  Note: the implementation of the AST_Entry pragma could handle
6762             --  the entry family case fine, but for now we are consistent with
6763             --  the DEC rules, and do not allow the pragma, which of course
6764             --  has the effect of also forbidding the attribute.
6765
6766             if Ekind (Ent) /= E_Entry then
6767                Error_Pragma_Arg
6768                  ("pragma% argument must be simple entry name", Arg1);
6769
6770             elsif Is_AST_Entry (Ent) then
6771                Error_Pragma_Arg
6772                  ("duplicate % pragma for entry", Arg1);
6773
6774             elsif Has_Homonym (Ent) then
6775                Error_Pragma_Arg
6776                  ("pragma% argument cannot specify overloaded entry", Arg1);
6777
6778             else
6779                declare
6780                   FF : constant Entity_Id := First_Formal (Ent);
6781
6782                begin
6783                   if Present (FF) then
6784                      if Present (Next_Formal (FF)) then
6785                         Error_Pragma_Arg
6786                           ("entry for pragma% can have only one argument",
6787                            Arg1);
6788
6789                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6790                         Error_Pragma_Arg
6791                           ("entry parameter for pragma% must have mode IN",
6792                            Arg1);
6793                      end if;
6794                   end if;
6795                end;
6796
6797                Set_Is_AST_Entry (Ent);
6798             end if;
6799          end AST_Entry;
6800
6801          ------------------
6802          -- Asynchronous --
6803          ------------------
6804
6805          --  pragma Asynchronous (LOCAL_NAME);
6806
6807          when Pragma_Asynchronous => Asynchronous : declare
6808             Nm     : Entity_Id;
6809             C_Ent  : Entity_Id;
6810             L      : List_Id;
6811             S      : Node_Id;
6812             N      : Node_Id;
6813             Formal : Entity_Id;
6814
6815             procedure Process_Async_Pragma;
6816             --  Common processing for procedure and access-to-procedure case
6817
6818             --------------------------
6819             -- Process_Async_Pragma --
6820             --------------------------
6821
6822             procedure Process_Async_Pragma is
6823             begin
6824                if No (L) then
6825                   Set_Is_Asynchronous (Nm);
6826                   return;
6827                end if;
6828
6829                --  The formals should be of mode IN (RM E.4.1(6))
6830
6831                S := First (L);
6832                while Present (S) loop
6833                   Formal := Defining_Identifier (S);
6834
6835                   if Nkind (Formal) = N_Defining_Identifier
6836                     and then Ekind (Formal) /= E_In_Parameter
6837                   then
6838                      Error_Pragma_Arg
6839                        ("pragma% procedure can only have IN parameter",
6840                         Arg1);
6841                   end if;
6842
6843                   Next (S);
6844                end loop;
6845
6846                Set_Is_Asynchronous (Nm);
6847             end Process_Async_Pragma;
6848
6849          --  Start of processing for pragma Asynchronous
6850
6851          begin
6852             Check_Ada_83_Warning;
6853             Check_No_Identifiers;
6854             Check_Arg_Count (1);
6855             Check_Arg_Is_Local_Name (Arg1);
6856
6857             if Debug_Flag_U then
6858                return;
6859             end if;
6860
6861             C_Ent := Cunit_Entity (Current_Sem_Unit);
6862             Analyze (Get_Pragma_Arg (Arg1));
6863             Nm := Entity (Get_Pragma_Arg (Arg1));
6864
6865             if not Is_Remote_Call_Interface (C_Ent)
6866               and then not Is_Remote_Types (C_Ent)
6867             then
6868                --  This pragma should only appear in an RCI or Remote Types
6869                --  unit (RM E.4.1(4)).
6870
6871                Error_Pragma
6872                  ("pragma% not in Remote_Call_Interface or " &
6873                   "Remote_Types unit");
6874             end if;
6875
6876             if Ekind (Nm) = E_Procedure
6877               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6878             then
6879                if not Is_Remote_Call_Interface (Nm) then
6880                   Error_Pragma_Arg
6881                     ("pragma% cannot be applied on non-remote procedure",
6882                      Arg1);
6883                end if;
6884
6885                L := Parameter_Specifications (Parent (Nm));
6886                Process_Async_Pragma;
6887                return;
6888
6889             elsif Ekind (Nm) = E_Function then
6890                Error_Pragma_Arg
6891                  ("pragma% cannot be applied to function", Arg1);
6892
6893             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6894                   if Is_Record_Type (Nm) then
6895
6896                   --  A record type that is the Equivalent_Type for a remote
6897                   --  access-to-subprogram type.
6898
6899                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6900
6901                   else
6902                      --  A non-expanded RAS type (distribution is not enabled)
6903
6904                      N := Declaration_Node (Nm);
6905                   end if;
6906
6907                if Nkind (N) = N_Full_Type_Declaration
6908                  and then Nkind (Type_Definition (N)) =
6909                                      N_Access_Procedure_Definition
6910                then
6911                   L := Parameter_Specifications (Type_Definition (N));
6912                   Process_Async_Pragma;
6913
6914                   if Is_Asynchronous (Nm)
6915                     and then Expander_Active
6916                     and then Get_PCS_Name /= Name_No_DSA
6917                   then
6918                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6919                   end if;
6920
6921                else
6922                   Error_Pragma_Arg
6923                     ("pragma% cannot reference access-to-function type",
6924                     Arg1);
6925                end if;
6926
6927             --  Only other possibility is Access-to-class-wide type
6928
6929             elsif Is_Access_Type (Nm)
6930               and then Is_Class_Wide_Type (Designated_Type (Nm))
6931             then
6932                Check_First_Subtype (Arg1);
6933                Set_Is_Asynchronous (Nm);
6934                if Expander_Active then
6935                   RACW_Type_Is_Asynchronous (Nm);
6936                end if;
6937
6938             else
6939                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6940             end if;
6941          end Asynchronous;
6942
6943          ------------
6944          -- Atomic --
6945          ------------
6946
6947          --  pragma Atomic (LOCAL_NAME);
6948
6949          when Pragma_Atomic =>
6950             Process_Atomic_Shared_Volatile;
6951
6952          -----------------------
6953          -- Atomic_Components --
6954          -----------------------
6955
6956          --  pragma Atomic_Components (array_LOCAL_NAME);
6957
6958          --  This processing is shared by Volatile_Components
6959
6960          when Pragma_Atomic_Components   |
6961               Pragma_Volatile_Components =>
6962
6963          Atomic_Components : declare
6964             E_Id : Node_Id;
6965             E    : Entity_Id;
6966             D    : Node_Id;
6967             K    : Node_Kind;
6968
6969          begin
6970             Check_Ada_83_Warning;
6971             Check_No_Identifiers;
6972             Check_Arg_Count (1);
6973             Check_Arg_Is_Local_Name (Arg1);
6974             E_Id := Get_Pragma_Arg (Arg1);
6975
6976             if Etype (E_Id) = Any_Type then
6977                return;
6978             end if;
6979
6980             E := Entity (E_Id);
6981
6982             Check_Duplicate_Pragma (E);
6983
6984             if Rep_Item_Too_Early (E, N)
6985                  or else
6986                Rep_Item_Too_Late (E, N)
6987             then
6988                return;
6989             end if;
6990
6991             D := Declaration_Node (E);
6992             K := Nkind (D);
6993
6994             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6995               or else
6996                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6997                    and then Nkind (D) = N_Object_Declaration
6998                    and then Nkind (Object_Definition (D)) =
6999                                        N_Constrained_Array_Definition)
7000             then
7001                --  The flag is set on the object, or on the base type
7002
7003                if Nkind (D) /= N_Object_Declaration then
7004                   E := Base_Type (E);
7005                end if;
7006
7007                Set_Has_Volatile_Components (E);
7008
7009                if Prag_Id = Pragma_Atomic_Components then
7010                   Set_Has_Atomic_Components (E);
7011                end if;
7012
7013             else
7014                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
7015             end if;
7016          end Atomic_Components;
7017          --------------------
7018          -- Attach_Handler --
7019          --------------------
7020
7021          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
7022
7023          when Pragma_Attach_Handler =>
7024             Check_Ada_83_Warning;
7025             Check_No_Identifiers;
7026             Check_Arg_Count (2);
7027
7028             if No_Run_Time_Mode then
7029                Error_Msg_CRT ("Attach_Handler pragma", N);
7030             else
7031                Check_Interrupt_Or_Attach_Handler;
7032
7033                --  The expression that designates the attribute may depend on a
7034                --  discriminant, and is therefore a per- object expression, to
7035                --  be expanded in the init proc. If expansion is enabled, then
7036                --  perform semantic checks on a copy only.
7037
7038                if Expander_Active then
7039                   declare
7040                      Temp : constant Node_Id :=
7041                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
7042                   begin
7043                      Set_Parent (Temp, N);
7044                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
7045                   end;
7046
7047                else
7048                   Analyze (Get_Pragma_Arg (Arg2));
7049                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
7050                end if;
7051
7052                Process_Interrupt_Or_Attach_Handler;
7053             end if;
7054
7055          --------------------
7056          -- C_Pass_By_Copy --
7057          --------------------
7058
7059          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
7060
7061          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
7062             Arg : Node_Id;
7063             Val : Uint;
7064
7065          begin
7066             GNAT_Pragma;
7067             Check_Valid_Configuration_Pragma;
7068             Check_Arg_Count (1);
7069             Check_Optional_Identifier (Arg1, "max_size");
7070
7071             Arg := Get_Pragma_Arg (Arg1);
7072             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
7073
7074             Val := Expr_Value (Arg);
7075
7076             if Val <= 0 then
7077                Error_Pragma_Arg
7078                  ("maximum size for pragma% must be positive", Arg1);
7079
7080             elsif UI_Is_In_Int_Range (Val) then
7081                Default_C_Record_Mechanism := UI_To_Int (Val);
7082
7083             --  If a giant value is given, Int'Last will do well enough.
7084             --  If sometime someone complains that a record larger than
7085             --  two gigabytes is not copied, we will worry about it then!
7086
7087             else
7088                Default_C_Record_Mechanism := Mechanism_Type'Last;
7089             end if;
7090          end C_Pass_By_Copy;
7091
7092          -----------
7093          -- Check --
7094          -----------
7095
7096          --  pragma Check ([Name    =>] IDENTIFIER,
7097          --                [Check   =>] Boolean_EXPRESSION
7098          --              [,[Message =>] String_EXPRESSION]);
7099
7100          when Pragma_Check => Check : declare
7101             Expr : Node_Id;
7102             Eloc : Source_Ptr;
7103
7104             Check_On : Boolean;
7105             --  Set True if category of assertions referenced by Name enabled
7106
7107          begin
7108             GNAT_Pragma;
7109             Check_At_Least_N_Arguments (2);
7110             Check_At_Most_N_Arguments (3);
7111             Check_Optional_Identifier (Arg1, Name_Name);
7112             Check_Optional_Identifier (Arg2, Name_Check);
7113
7114             if Arg_Count = 3 then
7115                Check_Optional_Identifier (Arg3, Name_Message);
7116                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7117             end if;
7118
7119             Check_Arg_Is_Identifier (Arg1);
7120
7121             --  Completely ignore if disabled
7122
7123             if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7124                Rewrite (N, Make_Null_Statement (Loc));
7125                Analyze (N);
7126                return;
7127             end if;
7128
7129             --  Indicate if pragma is enabled. The Original_Node reference here
7130             --  is to deal with pragma Assert rewritten as a Check pragma.
7131
7132             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7133
7134             if Check_On then
7135                Set_SCO_Pragma_Enabled (Loc);
7136             end if;
7137
7138             --  If expansion is active and the check is not enabled then we
7139             --  rewrite the Check as:
7140
7141             --    if False and then condition then
7142             --       null;
7143             --    end if;
7144
7145             --  The reason we do this rewriting during semantic analysis rather
7146             --  than as part of normal expansion is that we cannot analyze and
7147             --  expand the code for the boolean expression directly, or it may
7148             --  cause insertion of actions that would escape the attempt to
7149             --  suppress the check code.
7150
7151             --  Note that the Sloc for the if statement corresponds to the
7152             --  argument condition, not the pragma itself. The reason for this
7153             --  is that we may generate a warning if the condition is False at
7154             --  compile time, and we do not want to delete this warning when we
7155             --  delete the if statement.
7156
7157             Expr := Get_Pragma_Arg (Arg2);
7158
7159             if Expander_Active and then not Check_On then
7160                Eloc := Sloc (Expr);
7161
7162                Rewrite (N,
7163                  Make_If_Statement (Eloc,
7164                    Condition =>
7165                      Make_And_Then (Eloc,
7166                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
7167                        Right_Opnd => Expr),
7168                    Then_Statements => New_List (
7169                      Make_Null_Statement (Eloc))));
7170
7171                Analyze (N);
7172
7173             --  Check is active
7174
7175             else
7176                Analyze_And_Resolve (Expr, Any_Boolean);
7177             end if;
7178          end Check;
7179
7180          ----------------
7181          -- Check_Name --
7182          ----------------
7183
7184          --  pragma Check_Name (check_IDENTIFIER);
7185
7186          when Pragma_Check_Name =>
7187             Check_No_Identifiers;
7188             GNAT_Pragma;
7189             Check_Valid_Configuration_Pragma;
7190             Check_Arg_Count (1);
7191             Check_Arg_Is_Identifier (Arg1);
7192
7193             declare
7194                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7195
7196             begin
7197                for J in Check_Names.First .. Check_Names.Last loop
7198                   if Check_Names.Table (J) = Nam then
7199                      return;
7200                   end if;
7201                end loop;
7202
7203                Check_Names.Append (Nam);
7204             end;
7205
7206          ------------------
7207          -- Check_Policy --
7208          ------------------
7209
7210          --  pragma Check_Policy (
7211          --    [Name   =>] IDENTIFIER,
7212          --    [Policy =>] POLICY_IDENTIFIER);
7213
7214          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7215
7216          --  Note: this is a configuration pragma, but it is allowed to appear
7217          --  anywhere else.
7218
7219          when Pragma_Check_Policy =>
7220             GNAT_Pragma;
7221             Check_Arg_Count (2);
7222             Check_Optional_Identifier (Arg1, Name_Name);
7223             Check_Optional_Identifier (Arg2, Name_Policy);
7224             Check_Arg_Is_One_Of
7225               (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7226
7227             --  A Check_Policy pragma can appear either as a configuration
7228             --  pragma, or in a declarative part or a package spec (see RM
7229             --  11.5(5) for rules for Suppress/Unsuppress which are also
7230             --  followed for Check_Policy).
7231
7232             if not Is_Configuration_Pragma then
7233                Check_Is_In_Decl_Part_Or_Package_Spec;
7234             end if;
7235
7236             Set_Next_Pragma (N, Opt.Check_Policy_List);
7237             Opt.Check_Policy_List := N;
7238
7239          ---------------------
7240          -- CIL_Constructor --
7241          ---------------------
7242
7243          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7244
7245          --  Processing for this pragma is shared with Java_Constructor
7246
7247          -------------
7248          -- Comment --
7249          -------------
7250
7251          --  pragma Comment (static_string_EXPRESSION)
7252
7253          --  Processing for pragma Comment shares the circuitry for pragma
7254          --  Ident. The only differences are that Ident enforces a limit of 31
7255          --  characters on its argument, and also enforces limitations on
7256          --  placement for DEC compatibility. Pragma Comment shares neither of
7257          --  these restrictions.
7258
7259          -------------------
7260          -- Common_Object --
7261          -------------------
7262
7263          --  pragma Common_Object (
7264          --        [Internal =>] LOCAL_NAME
7265          --     [, [External =>] EXTERNAL_SYMBOL]
7266          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7267
7268          --  Processing for this pragma is shared with Psect_Object
7269
7270          ------------------------
7271          -- Compile_Time_Error --
7272          ------------------------
7273
7274          --  pragma Compile_Time_Error
7275          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7276
7277          when Pragma_Compile_Time_Error =>
7278             GNAT_Pragma;
7279             Process_Compile_Time_Warning_Or_Error;
7280
7281          --------------------------
7282          -- Compile_Time_Warning --
7283          --------------------------
7284
7285          --  pragma Compile_Time_Warning
7286          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7287
7288          when Pragma_Compile_Time_Warning =>
7289             GNAT_Pragma;
7290             Process_Compile_Time_Warning_Or_Error;
7291
7292          -------------------
7293          -- Compiler_Unit --
7294          -------------------
7295
7296          when Pragma_Compiler_Unit =>
7297             GNAT_Pragma;
7298             Check_Arg_Count (0);
7299             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7300
7301          -----------------------------
7302          -- Complete_Representation --
7303          -----------------------------
7304
7305          --  pragma Complete_Representation;
7306
7307          when Pragma_Complete_Representation =>
7308             GNAT_Pragma;
7309             Check_Arg_Count (0);
7310
7311             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7312                Error_Pragma
7313                  ("pragma & must appear within record representation clause");
7314             end if;
7315
7316          ----------------------------
7317          -- Complex_Representation --
7318          ----------------------------
7319
7320          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7321
7322          when Pragma_Complex_Representation => Complex_Representation : declare
7323             E_Id : Entity_Id;
7324             E    : Entity_Id;
7325             Ent  : Entity_Id;
7326
7327          begin
7328             GNAT_Pragma;
7329             Check_Arg_Count (1);
7330             Check_Optional_Identifier (Arg1, Name_Entity);
7331             Check_Arg_Is_Local_Name (Arg1);
7332             E_Id := Get_Pragma_Arg (Arg1);
7333
7334             if Etype (E_Id) = Any_Type then
7335                return;
7336             end if;
7337
7338             E := Entity (E_Id);
7339
7340             if not Is_Record_Type (E) then
7341                Error_Pragma_Arg
7342                  ("argument for pragma% must be record type", Arg1);
7343             end if;
7344
7345             Ent := First_Entity (E);
7346
7347             if No (Ent)
7348               or else No (Next_Entity (Ent))
7349               or else Present (Next_Entity (Next_Entity (Ent)))
7350               or else not Is_Floating_Point_Type (Etype (Ent))
7351               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7352             then
7353                Error_Pragma_Arg
7354                  ("record for pragma% must have two fields of the same "
7355                   & "floating-point type", Arg1);
7356
7357             else
7358                Set_Has_Complex_Representation (Base_Type (E));
7359
7360                --  We need to treat the type has having a non-standard
7361                --  representation, for back-end purposes, even though in
7362                --  general a complex will have the default representation
7363                --  of a record with two real components.
7364
7365                Set_Has_Non_Standard_Rep (Base_Type (E));
7366             end if;
7367          end Complex_Representation;
7368
7369          -------------------------
7370          -- Component_Alignment --
7371          -------------------------
7372
7373          --  pragma Component_Alignment (
7374          --        [Form =>] ALIGNMENT_CHOICE
7375          --     [, [Name =>] type_LOCAL_NAME]);
7376          --
7377          --   ALIGNMENT_CHOICE ::=
7378          --     Component_Size
7379          --   | Component_Size_4
7380          --   | Storage_Unit
7381          --   | Default
7382
7383          when Pragma_Component_Alignment => Component_AlignmentP : declare
7384             Args  : Args_List (1 .. 2);
7385             Names : constant Name_List (1 .. 2) := (
7386                       Name_Form,
7387                       Name_Name);
7388
7389             Form  : Node_Id renames Args (1);
7390             Name  : Node_Id renames Args (2);
7391
7392             Atype : Component_Alignment_Kind;
7393             Typ   : Entity_Id;
7394
7395          begin
7396             GNAT_Pragma;
7397             Gather_Associations (Names, Args);
7398
7399             if No (Form) then
7400                Error_Pragma ("missing Form argument for pragma%");
7401             end if;
7402
7403             Check_Arg_Is_Identifier (Form);
7404
7405             --  Get proper alignment, note that Default = Component_Size on all
7406             --  machines we have so far, and we want to set this value rather
7407             --  than the default value to indicate that it has been explicitly
7408             --  set (and thus will not get overridden by the default component
7409             --  alignment for the current scope)
7410
7411             if Chars (Form) = Name_Component_Size then
7412                Atype := Calign_Component_Size;
7413
7414             elsif Chars (Form) = Name_Component_Size_4 then
7415                Atype := Calign_Component_Size_4;
7416
7417             elsif Chars (Form) = Name_Default then
7418                Atype := Calign_Component_Size;
7419
7420             elsif Chars (Form) = Name_Storage_Unit then
7421                Atype := Calign_Storage_Unit;
7422
7423             else
7424                Error_Pragma_Arg
7425                  ("invalid Form parameter for pragma%", Form);
7426             end if;
7427
7428             --  Case with no name, supplied, affects scope table entry
7429
7430             if No (Name) then
7431                Scope_Stack.Table
7432                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7433
7434             --  Case of name supplied
7435
7436             else
7437                Check_Arg_Is_Local_Name (Name);
7438                Find_Type (Name);
7439                Typ := Entity (Name);
7440
7441                if Typ = Any_Type
7442                  or else Rep_Item_Too_Early (Typ, N)
7443                then
7444                   return;
7445                else
7446                   Typ := Underlying_Type (Typ);
7447                end if;
7448
7449                if not Is_Record_Type (Typ)
7450                  and then not Is_Array_Type (Typ)
7451                then
7452                   Error_Pragma_Arg
7453                     ("Name parameter of pragma% must identify record or " &
7454                      "array type", Name);
7455                end if;
7456
7457                --  An explicit Component_Alignment pragma overrides an
7458                --  implicit pragma Pack, but not an explicit one.
7459
7460                if not Has_Pragma_Pack (Base_Type (Typ)) then
7461                   Set_Is_Packed (Base_Type (Typ), False);
7462                   Set_Component_Alignment (Base_Type (Typ), Atype);
7463                end if;
7464             end if;
7465          end Component_AlignmentP;
7466
7467          ----------------
7468          -- Controlled --
7469          ----------------
7470
7471          --  pragma Controlled (first_subtype_LOCAL_NAME);
7472
7473          when Pragma_Controlled => Controlled : declare
7474             Arg : Node_Id;
7475
7476          begin
7477             Check_No_Identifiers;
7478             Check_Arg_Count (1);
7479             Check_Arg_Is_Local_Name (Arg1);
7480             Arg := Get_Pragma_Arg (Arg1);
7481
7482             if not Is_Entity_Name (Arg)
7483               or else not Is_Access_Type (Entity (Arg))
7484             then
7485                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7486             else
7487                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7488             end if;
7489          end Controlled;
7490
7491          ----------------
7492          -- Convention --
7493          ----------------
7494
7495          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7496          --    [Entity =>] LOCAL_NAME);
7497
7498          when Pragma_Convention => Convention : declare
7499             C : Convention_Id;
7500             E : Entity_Id;
7501             pragma Warnings (Off, C);
7502             pragma Warnings (Off, E);
7503          begin
7504             Check_Arg_Order ((Name_Convention, Name_Entity));
7505             Check_Ada_83_Warning;
7506             Check_Arg_Count (2);
7507             Process_Convention (C, E);
7508          end Convention;
7509
7510          ---------------------------
7511          -- Convention_Identifier --
7512          ---------------------------
7513
7514          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7515          --    [Convention =>] convention_IDENTIFIER);
7516
7517          when Pragma_Convention_Identifier => Convention_Identifier : declare
7518             Idnam : Name_Id;
7519             Cname : Name_Id;
7520
7521          begin
7522             GNAT_Pragma;
7523             Check_Arg_Order ((Name_Name, Name_Convention));
7524             Check_Arg_Count (2);
7525             Check_Optional_Identifier (Arg1, Name_Name);
7526             Check_Optional_Identifier (Arg2, Name_Convention);
7527             Check_Arg_Is_Identifier (Arg1);
7528             Check_Arg_Is_Identifier (Arg2);
7529             Idnam := Chars (Get_Pragma_Arg (Arg1));
7530             Cname := Chars (Get_Pragma_Arg (Arg2));
7531
7532             if Is_Convention_Name (Cname) then
7533                Record_Convention_Identifier
7534                  (Idnam, Get_Convention_Id (Cname));
7535             else
7536                Error_Pragma_Arg
7537                  ("second arg for % pragma must be convention", Arg2);
7538             end if;
7539          end Convention_Identifier;
7540
7541          ---------------
7542          -- CPP_Class --
7543          ---------------
7544
7545          --  pragma CPP_Class ([Entity =>] local_NAME)
7546
7547          when Pragma_CPP_Class => CPP_Class : declare
7548             Arg : Node_Id;
7549             Typ : Entity_Id;
7550
7551          begin
7552             if Warn_On_Obsolescent_Feature then
7553                Error_Msg_N
7554                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7555                   " by pragma import?", N);
7556             end if;
7557
7558             GNAT_Pragma;
7559             Check_Arg_Count (1);
7560             Check_Optional_Identifier (Arg1, Name_Entity);
7561             Check_Arg_Is_Local_Name (Arg1);
7562
7563             Arg := Get_Pragma_Arg (Arg1);
7564             Analyze (Arg);
7565
7566             if Etype (Arg) = Any_Type then
7567                return;
7568             end if;
7569
7570             if not Is_Entity_Name (Arg)
7571               or else not Is_Type (Entity (Arg))
7572             then
7573                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7574             end if;
7575
7576             Typ := Entity (Arg);
7577
7578             if not Is_Tagged_Type (Typ) then
7579                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7580             end if;
7581
7582             --  Types treated as CPP classes must be declared limited (note:
7583             --  this used to be a warning but there is no real benefit to it
7584             --  since we did effectively intend to treat the type as limited
7585             --  anyway).
7586
7587             if not Is_Limited_Type (Typ) then
7588                Error_Msg_N
7589                  ("imported 'C'P'P type must be limited",
7590                   Get_Pragma_Arg (Arg1));
7591             end if;
7592
7593             Set_Is_CPP_Class      (Typ);
7594             Set_Convention        (Typ, Convention_CPP);
7595
7596             --  Imported CPP types must not have discriminants (because C++
7597             --  classes do not have discriminants).
7598
7599             if Has_Discriminants (Typ) then
7600                Error_Msg_N
7601                  ("imported 'C'P'P type cannot have discriminants",
7602                   First (Discriminant_Specifications
7603                           (Declaration_Node (Typ))));
7604             end if;
7605
7606             --  Components of imported CPP types must not have default
7607             --  expressions because the constructor (if any) is in the
7608             --  C++ side.
7609
7610             if Is_Incomplete_Or_Private_Type (Typ)
7611               and then No (Underlying_Type (Typ))
7612             then
7613                --  It should be an error to apply pragma CPP to a private
7614                --  type if the underlying type is not visible (as it is
7615                --  for any representation item). For now, for backward
7616                --  compatibility we do nothing but we cannot check components
7617                --  because they are not available at this stage. All this code
7618                --  will be removed when we cleanup this obsolete GNAT pragma???
7619
7620                null;
7621
7622             else
7623                declare
7624                   Tdef  : constant Node_Id :=
7625                             Type_Definition (Declaration_Node (Typ));
7626                   Clist : Node_Id;
7627                   Comp  : Node_Id;
7628
7629                begin
7630                   if Nkind (Tdef) = N_Record_Definition then
7631                      Clist := Component_List (Tdef);
7632                   else
7633                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7634                      Clist := Component_List (Record_Extension_Part (Tdef));
7635                   end if;
7636
7637                   if Present (Clist) then
7638                      Comp := First (Component_Items (Clist));
7639                      while Present (Comp) loop
7640                         if Present (Expression (Comp)) then
7641                            Error_Msg_N
7642                              ("component of imported 'C'P'P type cannot have" &
7643                               " default expression", Expression (Comp));
7644                         end if;
7645
7646                         Next (Comp);
7647                      end loop;
7648                   end if;
7649                end;
7650             end if;
7651          end CPP_Class;
7652
7653          ---------------------
7654          -- CPP_Constructor --
7655          ---------------------
7656
7657          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7658          --    [, [External_Name =>] static_string_EXPRESSION ]
7659          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7660
7661          when Pragma_CPP_Constructor => CPP_Constructor : declare
7662             Elmt    : Elmt_Id;
7663             Id      : Entity_Id;
7664             Def_Id  : Entity_Id;
7665             Tag_Typ : Entity_Id;
7666
7667          begin
7668             GNAT_Pragma;
7669             Check_At_Least_N_Arguments (1);
7670             Check_At_Most_N_Arguments (3);
7671             Check_Optional_Identifier (Arg1, Name_Entity);
7672             Check_Arg_Is_Local_Name (Arg1);
7673
7674             Id := Get_Pragma_Arg (Arg1);
7675             Find_Program_Unit_Name (Id);
7676
7677             --  If we did not find the name, we are done
7678
7679             if Etype (Id) = Any_Type then
7680                return;
7681             end if;
7682
7683             Def_Id := Entity (Id);
7684
7685             --  Check if already defined as constructor
7686
7687             if Is_Constructor (Def_Id) then
7688                Error_Msg_N
7689                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7690                return;
7691             end if;
7692
7693             if Ekind (Def_Id) = E_Function
7694               and then (Is_CPP_Class (Etype (Def_Id))
7695                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7696                                    and then
7697                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7698             then
7699                if Arg_Count >= 2 then
7700                   Set_Imported (Def_Id);
7701                   Set_Is_Public (Def_Id);
7702                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7703                end if;
7704
7705                Set_Has_Completion (Def_Id);
7706                Set_Is_Constructor (Def_Id);
7707
7708                --  Imported C++ constructors are not dispatching primitives
7709                --  because in C++ they don't have a dispatch table slot.
7710                --  However, in Ada the constructor has the profile of a
7711                --  function that returns a tagged type and therefore it has
7712                --  been treated as a primitive operation during semantic
7713                --  analysis. We now remove it from the list of primitive
7714                --  operations of the type.
7715
7716                if Is_Tagged_Type (Etype (Def_Id))
7717                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7718                then
7719                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7720                   Tag_Typ := Etype (Def_Id);
7721
7722                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7723                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7724                      Next_Elmt (Elmt);
7725                   end loop;
7726
7727                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7728                   Set_Is_Dispatching_Operation (Def_Id, False);
7729                end if;
7730
7731                --  For backward compatibility, if the constructor returns a
7732                --  class wide type, and we internally change the return type to
7733                --  the corresponding root type.
7734
7735                if Is_Class_Wide_Type (Etype (Def_Id)) then
7736                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7737                end if;
7738             else
7739                Error_Pragma_Arg
7740                  ("pragma% requires function returning a 'C'P'P_Class type",
7741                    Arg1);
7742             end if;
7743          end CPP_Constructor;
7744
7745          -----------------
7746          -- CPP_Virtual --
7747          -----------------
7748
7749          when Pragma_CPP_Virtual => CPP_Virtual : declare
7750          begin
7751             GNAT_Pragma;
7752
7753             if Warn_On_Obsolescent_Feature then
7754                Error_Msg_N
7755                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7756                   "no effect?", N);
7757             end if;
7758          end CPP_Virtual;
7759
7760          ----------------
7761          -- CPP_Vtable --
7762          ----------------
7763
7764          when Pragma_CPP_Vtable => CPP_Vtable : declare
7765          begin
7766             GNAT_Pragma;
7767
7768             if Warn_On_Obsolescent_Feature then
7769                Error_Msg_N
7770                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7771                   "no effect?", N);
7772             end if;
7773          end CPP_Vtable;
7774
7775          ---------
7776          -- CPU --
7777          ---------
7778
7779          --  pragma CPU (EXPRESSION);
7780
7781          when Pragma_CPU => CPU : declare
7782             P   : constant Node_Id := Parent (N);
7783             Arg : Node_Id;
7784
7785          begin
7786             Ada_2012_Pragma;
7787             Check_No_Identifiers;
7788             Check_Arg_Count (1);
7789
7790             --  Subprogram case
7791
7792             if Nkind (P) = N_Subprogram_Body then
7793                Check_In_Main_Program;
7794
7795                Arg := Get_Pragma_Arg (Arg1);
7796                Analyze_And_Resolve (Arg, Any_Integer);
7797
7798                --  Must be static
7799
7800                if not Is_Static_Expression (Arg) then
7801                   Flag_Non_Static_Expr
7802                     ("main subprogram affinity is not static!", Arg);
7803                   raise Pragma_Exit;
7804
7805                --  If constraint error, then we already signalled an error
7806
7807                elsif Raises_Constraint_Error (Arg) then
7808                   null;
7809
7810                --  Otherwise check in range
7811
7812                else
7813                   declare
7814                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7815                      --  This is the entity System.Multiprocessors.CPU_Range;
7816
7817                      Val : constant Uint := Expr_Value (Arg);
7818
7819                   begin
7820                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7821                           or else
7822                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7823                      then
7824                         Error_Pragma_Arg
7825                           ("main subprogram CPU is out of range", Arg1);
7826                      end if;
7827                   end;
7828                end if;
7829
7830                Set_Main_CPU
7831                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7832
7833             --  Task case
7834
7835             elsif Nkind (P) = N_Task_Definition then
7836                Arg := Get_Pragma_Arg (Arg1);
7837
7838                --  The expression must be analyzed in the special manner
7839                --  described in "Handling of Default and Per-Object
7840                --  Expressions" in sem.ads.
7841
7842                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7843
7844             --  Anything else is incorrect
7845
7846             else
7847                Pragma_Misplaced;
7848             end if;
7849
7850             if Has_Pragma_CPU (P) then
7851                Error_Pragma ("duplicate pragma% not allowed");
7852             else
7853                Set_Has_Pragma_CPU (P, True);
7854
7855                if Nkind (P) = N_Task_Definition then
7856                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7857                end if;
7858             end if;
7859          end CPU;
7860
7861          -----------
7862          -- Debug --
7863          -----------
7864
7865          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7866
7867          when Pragma_Debug => Debug : declare
7868             Cond : Node_Id;
7869             Call : Node_Id;
7870
7871          begin
7872             GNAT_Pragma;
7873
7874             --  Skip analysis if disabled
7875
7876             if Debug_Pragmas_Disabled then
7877                Rewrite (N, Make_Null_Statement (Loc));
7878                Analyze (N);
7879                return;
7880             end if;
7881
7882             Cond :=
7883               New_Occurrence_Of
7884                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7885                  Loc);
7886
7887             if Debug_Pragmas_Enabled then
7888                Set_SCO_Pragma_Enabled (Loc);
7889             end if;
7890
7891             if Arg_Count = 2 then
7892                Cond :=
7893                  Make_And_Then (Loc,
7894                    Left_Opnd  => Relocate_Node (Cond),
7895                    Right_Opnd => Get_Pragma_Arg (Arg1));
7896                Call := Get_Pragma_Arg (Arg2);
7897             else
7898                Call := Get_Pragma_Arg (Arg1);
7899             end if;
7900
7901             if Nkind_In (Call,
7902                  N_Indexed_Component,
7903                  N_Function_Call,
7904                  N_Identifier,
7905                  N_Expanded_Name,
7906                  N_Selected_Component)
7907             then
7908                --  If this pragma Debug comes from source, its argument was
7909                --  parsed as a name form (which is syntactically identical).
7910                --  In a generic context a parameterless call will be left as
7911                --  an expanded name (if global) or selected_component if local.
7912                --  Change it to a procedure call statement now.
7913
7914                Change_Name_To_Procedure_Call_Statement (Call);
7915
7916             elsif Nkind (Call) = N_Procedure_Call_Statement then
7917
7918                --  Already in the form of a procedure call statement: nothing
7919                --  to do (could happen in case of an internally generated
7920                --  pragma Debug).
7921
7922                null;
7923
7924             else
7925                --  All other cases: diagnose error
7926
7927                Error_Msg
7928                  ("argument of pragma ""Debug"" is not procedure call",
7929                   Sloc (Call));
7930                return;
7931             end if;
7932
7933             --  Rewrite into a conditional with an appropriate condition. We
7934             --  wrap the procedure call in a block so that overhead from e.g.
7935             --  use of the secondary stack does not generate execution overhead
7936             --  for suppressed conditions.
7937
7938             Rewrite (N, Make_Implicit_If_Statement (N,
7939               Condition => Cond,
7940                  Then_Statements => New_List (
7941                    Make_Block_Statement (Loc,
7942                      Handled_Statement_Sequence =>
7943                        Make_Handled_Sequence_Of_Statements (Loc,
7944                          Statements => New_List (Relocate_Node (Call)))))));
7945             Analyze (N);
7946          end Debug;
7947
7948          ------------------
7949          -- Debug_Policy --
7950          ------------------
7951
7952          --  pragma Debug_Policy (Check | Ignore)
7953
7954          when Pragma_Debug_Policy =>
7955             GNAT_Pragma;
7956             Check_Arg_Count (1);
7957             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7958             Debug_Pragmas_Enabled :=
7959               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7960             Debug_Pragmas_Disabled :=
7961               Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7962
7963          ---------------------
7964          -- Detect_Blocking --
7965          ---------------------
7966
7967          --  pragma Detect_Blocking;
7968
7969          when Pragma_Detect_Blocking =>
7970             Ada_2005_Pragma;
7971             Check_Arg_Count (0);
7972             Check_Valid_Configuration_Pragma;
7973             Detect_Blocking := True;
7974
7975          --------------------------
7976          -- Default_Storage_Pool --
7977          --------------------------
7978
7979          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7980
7981          when Pragma_Default_Storage_Pool =>
7982             Ada_2012_Pragma;
7983             Check_Arg_Count (1);
7984
7985             --  Default_Storage_Pool can appear as a configuration pragma, or
7986             --  in a declarative part or a package spec.
7987
7988             if not Is_Configuration_Pragma then
7989                Check_Is_In_Decl_Part_Or_Package_Spec;
7990             end if;
7991
7992             --  Case of Default_Storage_Pool (null);
7993
7994             if Nkind (Expression (Arg1)) = N_Null then
7995                Analyze (Expression (Arg1));
7996
7997                --  This is an odd case, this is not really an expression, so
7998                --  we don't have a type for it. So just set the type to Empty.
7999
8000                Set_Etype (Expression (Arg1), Empty);
8001
8002             --  Case of Default_Storage_Pool (storage_pool_NAME);
8003
8004             else
8005                --  If it's a configuration pragma, then the only allowed
8006                --  argument is "null".
8007
8008                if Is_Configuration_Pragma then
8009                   Error_Pragma_Arg ("NULL expected", Arg1);
8010                end if;
8011
8012                --  The expected type for a non-"null" argument is
8013                --  Root_Storage_Pool'Class.
8014
8015                Analyze_And_Resolve
8016                  (Get_Pragma_Arg (Arg1),
8017                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
8018             end if;
8019
8020             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
8021             --  for an access type will use this information to set the
8022             --  appropriate attributes of the access type.
8023
8024             Default_Pool := Expression (Arg1);
8025
8026          ---------------
8027          -- Dimension --
8028          ---------------
8029
8030          when Pragma_Dimension =>
8031             GNAT_Pragma;
8032             Check_Arg_Count (4);
8033             Check_No_Identifiers;
8034             Check_Arg_Is_Local_Name (Arg1);
8035
8036             if not Is_Type (Arg1) then
8037                Error_Pragma ("first argument for pragma% must be subtype");
8038             end if;
8039
8040             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
8041             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
8042             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
8043
8044          ------------------------------------
8045          -- Disable_Atomic_Synchronization --
8046          ------------------------------------
8047
8048          --  pragma Disable_Atomic_Synchronization [(Entity)];
8049
8050          when Pragma_Disable_Atomic_Synchronization =>
8051             Process_Disable_Enable_Atomic_Sync (Name_Suppress);
8052
8053          -------------------
8054          -- Discard_Names --
8055          -------------------
8056
8057          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
8058
8059          when Pragma_Discard_Names => Discard_Names : declare
8060             E    : Entity_Id;
8061             E_Id : Entity_Id;
8062
8063          begin
8064             Check_Ada_83_Warning;
8065
8066             --  Deal with configuration pragma case
8067
8068             if Arg_Count = 0 and then Is_Configuration_Pragma then
8069                Global_Discard_Names := True;
8070                return;
8071
8072             --  Otherwise, check correct appropriate context
8073
8074             else
8075                Check_Is_In_Decl_Part_Or_Package_Spec;
8076
8077                if Arg_Count = 0 then
8078
8079                   --  If there is no parameter, then from now on this pragma
8080                   --  applies to any enumeration, exception or tagged type
8081                   --  defined in the current declarative part, and recursively
8082                   --  to any nested scope.
8083
8084                   Set_Discard_Names (Current_Scope);
8085                   return;
8086
8087                else
8088                   Check_Arg_Count (1);
8089                   Check_Optional_Identifier (Arg1, Name_On);
8090                   Check_Arg_Is_Local_Name (Arg1);
8091
8092                   E_Id := Get_Pragma_Arg (Arg1);
8093
8094                   if Etype (E_Id) = Any_Type then
8095                      return;
8096                   else
8097                      E := Entity (E_Id);
8098                   end if;
8099
8100                   if (Is_First_Subtype (E)
8101                       and then
8102                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8103                     or else Ekind (E) = E_Exception
8104                   then
8105                      Set_Discard_Names (E);
8106                   else
8107                      Error_Pragma_Arg
8108                        ("inappropriate entity for pragma%", Arg1);
8109                   end if;
8110
8111                end if;
8112             end if;
8113          end Discard_Names;
8114
8115          ------------------------
8116          -- Dispatching_Domain --
8117          ------------------------
8118
8119          --  pragma Dispatching_Domain (EXPRESSION);
8120
8121          when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8122             P   : constant Node_Id := Parent (N);
8123             Arg : Node_Id;
8124
8125          begin
8126             Ada_2012_Pragma;
8127             Check_No_Identifiers;
8128             Check_Arg_Count (1);
8129
8130             --  This pragma is born obsolete, but not the aspect
8131
8132             if not From_Aspect_Specification (N) then
8133                Check_Restriction
8134                  (No_Obsolescent_Features, Pragma_Identifier (N));
8135             end if;
8136
8137             if Nkind (P) = N_Task_Definition then
8138                Arg := Get_Pragma_Arg (Arg1);
8139
8140                --  The expression must be analyzed in the special manner
8141                --  described in "Handling of Default and Per-Object
8142                --  Expressions" in sem.ads.
8143
8144                Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8145
8146             --  Anything else is incorrect
8147
8148             else
8149                Pragma_Misplaced;
8150             end if;
8151
8152             if Has_Pragma_Dispatching_Domain (P) then
8153                Error_Pragma ("duplicate pragma% not allowed");
8154             else
8155                Set_Has_Pragma_Dispatching_Domain (P, True);
8156
8157                if Nkind (P) = N_Task_Definition then
8158                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8159                end if;
8160             end if;
8161          end Dispatching_Domain;
8162
8163          ---------------
8164          -- Elaborate --
8165          ---------------
8166
8167          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8168
8169          when Pragma_Elaborate => Elaborate : declare
8170             Arg   : Node_Id;
8171             Citem : Node_Id;
8172
8173          begin
8174             --  Pragma must be in context items list of a compilation unit
8175
8176             if not Is_In_Context_Clause then
8177                Pragma_Misplaced;
8178             end if;
8179
8180             --  Must be at least one argument
8181
8182             if Arg_Count = 0 then
8183                Error_Pragma ("pragma% requires at least one argument");
8184             end if;
8185
8186             --  In Ada 83 mode, there can be no items following it in the
8187             --  context list except other pragmas and implicit with clauses
8188             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8189             --  placement rule does not apply.
8190
8191             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8192                Citem := Next (N);
8193                while Present (Citem) loop
8194                   if Nkind (Citem) = N_Pragma
8195                     or else (Nkind (Citem) = N_With_Clause
8196                               and then Implicit_With (Citem))
8197                   then
8198                      null;
8199                   else
8200                      Error_Pragma
8201                        ("(Ada 83) pragma% must be at end of context clause");
8202                   end if;
8203
8204                   Next (Citem);
8205                end loop;
8206             end if;
8207
8208             --  Finally, the arguments must all be units mentioned in a with
8209             --  clause in the same context clause. Note we already checked (in
8210             --  Par.Prag) that the arguments are all identifiers or selected
8211             --  components.
8212
8213             Arg := Arg1;
8214             Outer : while Present (Arg) loop
8215                Citem := First (List_Containing (N));
8216                Inner : while Citem /= N loop
8217                   if Nkind (Citem) = N_With_Clause
8218                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8219                   then
8220                      Set_Elaborate_Present (Citem, True);
8221                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8222                      Generate_Reference (Entity (Name (Citem)), Citem);
8223
8224                      --  With the pragma present, elaboration calls on
8225                      --  subprograms from the named unit need no further
8226                      --  checks, as long as the pragma appears in the current
8227                      --  compilation unit. If the pragma appears in some unit
8228                      --  in the context, there might still be a need for an
8229                      --  Elaborate_All_Desirable from the current compilation
8230                      --  to the named unit, so we keep the check enabled.
8231
8232                      if In_Extended_Main_Source_Unit (N) then
8233                         Set_Suppress_Elaboration_Warnings
8234                           (Entity (Name (Citem)));
8235                      end if;
8236
8237                      exit Inner;
8238                   end if;
8239
8240                   Next (Citem);
8241                end loop Inner;
8242
8243                if Citem = N then
8244                   Error_Pragma_Arg
8245                     ("argument of pragma% is not with'ed unit", Arg);
8246                end if;
8247
8248                Next (Arg);
8249             end loop Outer;
8250
8251             --  Give a warning if operating in static mode with -gnatwl
8252             --  (elaboration warnings enabled) switch set.
8253
8254             if Elab_Warnings and not Dynamic_Elaboration_Checks then
8255                Error_Msg_N
8256                  ("?use of pragma Elaborate may not be safe", N);
8257                Error_Msg_N
8258                  ("?use pragma Elaborate_All instead if possible", N);
8259             end if;
8260          end Elaborate;
8261
8262          -------------------
8263          -- Elaborate_All --
8264          -------------------
8265
8266          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8267
8268          when Pragma_Elaborate_All => Elaborate_All : declare
8269             Arg   : Node_Id;
8270             Citem : Node_Id;
8271
8272          begin
8273             Check_Ada_83_Warning;
8274
8275             --  Pragma must be in context items list of a compilation unit
8276
8277             if not Is_In_Context_Clause then
8278                Pragma_Misplaced;
8279             end if;
8280
8281             --  Must be at least one argument
8282
8283             if Arg_Count = 0 then
8284                Error_Pragma ("pragma% requires at least one argument");
8285             end if;
8286
8287             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
8288             --  have to appear at the end of the context clause, but may
8289             --  appear mixed in with other items, even in Ada 83 mode.
8290
8291             --  Final check: the arguments must all be units mentioned in
8292             --  a with clause in the same context clause. Note that we
8293             --  already checked (in Par.Prag) that all the arguments are
8294             --  either identifiers or selected components.
8295
8296             Arg := Arg1;
8297             Outr : while Present (Arg) loop
8298                Citem := First (List_Containing (N));
8299                Innr : while Citem /= N loop
8300                   if Nkind (Citem) = N_With_Clause
8301                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8302                   then
8303                      Set_Elaborate_All_Present (Citem, True);
8304                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8305
8306                      --  Suppress warnings and elaboration checks on the named
8307                      --  unit if the pragma is in the current compilation, as
8308                      --  for pragma Elaborate.
8309
8310                      if In_Extended_Main_Source_Unit (N) then
8311                         Set_Suppress_Elaboration_Warnings
8312                           (Entity (Name (Citem)));
8313                      end if;
8314                      exit Innr;
8315                   end if;
8316
8317                   Next (Citem);
8318                end loop Innr;
8319
8320                if Citem = N then
8321                   Set_Error_Posted (N);
8322                   Error_Pragma_Arg
8323                     ("argument of pragma% is not with'ed unit", Arg);
8324                end if;
8325
8326                Next (Arg);
8327             end loop Outr;
8328          end Elaborate_All;
8329
8330          --------------------
8331          -- Elaborate_Body --
8332          --------------------
8333
8334          --  pragma Elaborate_Body [( library_unit_NAME )];
8335
8336          when Pragma_Elaborate_Body => Elaborate_Body : declare
8337             Cunit_Node : Node_Id;
8338             Cunit_Ent  : Entity_Id;
8339
8340          begin
8341             Check_Ada_83_Warning;
8342             Check_Valid_Library_Unit_Pragma;
8343
8344             if Nkind (N) = N_Null_Statement then
8345                return;
8346             end if;
8347
8348             Cunit_Node := Cunit (Current_Sem_Unit);
8349             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8350
8351             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8352                                             N_Subprogram_Body)
8353             then
8354                Error_Pragma ("pragma% must refer to a spec, not a body");
8355             else
8356                Set_Body_Required (Cunit_Node, True);
8357                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8358
8359                --  If we are in dynamic elaboration mode, then we suppress
8360                --  elaboration warnings for the unit, since it is definitely
8361                --  fine NOT to do dynamic checks at the first level (and such
8362                --  checks will be suppressed because no elaboration boolean
8363                --  is created for Elaborate_Body packages).
8364
8365                --  But in the static model of elaboration, Elaborate_Body is
8366                --  definitely NOT good enough to ensure elaboration safety on
8367                --  its own, since the body may WITH other units that are not
8368                --  safe from an elaboration point of view, so a client must
8369                --  still do an Elaborate_All on such units.
8370
8371                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8372                --  Elaborate_Body always suppressed elab warnings.
8373
8374                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8375                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8376                end if;
8377             end if;
8378          end Elaborate_Body;
8379
8380          ------------------------
8381          -- Elaboration_Checks --
8382          ------------------------
8383
8384          --  pragma Elaboration_Checks (Static | Dynamic);
8385
8386          when Pragma_Elaboration_Checks =>
8387             GNAT_Pragma;
8388             Check_Arg_Count (1);
8389             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8390             Dynamic_Elaboration_Checks :=
8391               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8392
8393          ---------------
8394          -- Eliminate --
8395          ---------------
8396
8397          --  pragma Eliminate (
8398          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8399          --    [,[Entity     =>] IDENTIFIER |
8400          --                      SELECTED_COMPONENT |
8401          --                      STRING_LITERAL]
8402          --    [,                OVERLOADING_RESOLUTION]);
8403
8404          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8405          --                             SOURCE_LOCATION
8406
8407          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8408          --                                        FUNCTION_PROFILE
8409
8410          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8411
8412          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8413          --                       Result_Type => result_SUBTYPE_NAME]
8414
8415          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8416          --  SUBTYPE_NAME    ::= STRING_LITERAL
8417
8418          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8419          --  SOURCE_TRACE    ::= STRING_LITERAL
8420
8421          when Pragma_Eliminate => Eliminate : declare
8422             Args  : Args_List (1 .. 5);
8423             Names : constant Name_List (1 .. 5) := (
8424                       Name_Unit_Name,
8425                       Name_Entity,
8426                       Name_Parameter_Types,
8427                       Name_Result_Type,
8428                       Name_Source_Location);
8429
8430             Unit_Name       : Node_Id renames Args (1);
8431             Entity          : Node_Id renames Args (2);
8432             Parameter_Types : Node_Id renames Args (3);
8433             Result_Type     : Node_Id renames Args (4);
8434             Source_Location : Node_Id renames Args (5);
8435
8436          begin
8437             GNAT_Pragma;
8438             Check_Valid_Configuration_Pragma;
8439             Gather_Associations (Names, Args);
8440
8441             if No (Unit_Name) then
8442                Error_Pragma ("missing Unit_Name argument for pragma%");
8443             end if;
8444
8445             if No (Entity)
8446               and then (Present (Parameter_Types)
8447                           or else
8448                         Present (Result_Type)
8449                           or else
8450                         Present (Source_Location))
8451             then
8452                Error_Pragma ("missing Entity argument for pragma%");
8453             end if;
8454
8455             if (Present (Parameter_Types)
8456                   or else
8457                 Present (Result_Type))
8458               and then
8459                 Present (Source_Location)
8460             then
8461                Error_Pragma
8462                  ("parameter profile and source location cannot " &
8463                   "be used together in pragma%");
8464             end if;
8465
8466             Process_Eliminate_Pragma
8467               (N,
8468                Unit_Name,
8469                Entity,
8470                Parameter_Types,
8471                Result_Type,
8472                Source_Location);
8473          end Eliminate;
8474
8475          -----------------------------------
8476          -- Enable_Atomic_Synchronization --
8477          -----------------------------------
8478
8479          --  pragma Enable_Atomic_Synchronization [(Entity)];
8480
8481          when Pragma_Enable_Atomic_Synchronization =>
8482             Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
8483
8484          ------------
8485          -- Export --
8486          ------------
8487
8488          --  pragma Export (
8489          --    [   Convention    =>] convention_IDENTIFIER,
8490          --    [   Entity        =>] local_NAME
8491          --    [, [External_Name =>] static_string_EXPRESSION ]
8492          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8493
8494          when Pragma_Export => Export : declare
8495             C      : Convention_Id;
8496             Def_Id : Entity_Id;
8497
8498             pragma Warnings (Off, C);
8499
8500          begin
8501             Check_Ada_83_Warning;
8502             Check_Arg_Order
8503               ((Name_Convention,
8504                 Name_Entity,
8505                 Name_External_Name,
8506                 Name_Link_Name));
8507             Check_At_Least_N_Arguments (2);
8508             Check_At_Most_N_Arguments  (4);
8509             Process_Convention (C, Def_Id);
8510
8511             if Ekind (Def_Id) /= E_Constant then
8512                Note_Possible_Modification
8513                  (Get_Pragma_Arg (Arg2), Sure => False);
8514             end if;
8515
8516             Process_Interface_Name (Def_Id, Arg3, Arg4);
8517             Set_Exported (Def_Id, Arg2);
8518
8519             --  If the entity is a deferred constant, propagate the information
8520             --  to the full view, because gigi elaborates the full view only.
8521
8522             if Ekind (Def_Id) = E_Constant
8523               and then Present (Full_View (Def_Id))
8524             then
8525                declare
8526                   Id2 : constant Entity_Id := Full_View (Def_Id);
8527                begin
8528                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8529                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8530                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8531                end;
8532             end if;
8533          end Export;
8534
8535          ----------------------
8536          -- Export_Exception --
8537          ----------------------
8538
8539          --  pragma Export_Exception (
8540          --        [Internal         =>] LOCAL_NAME
8541          --     [, [External         =>] EXTERNAL_SYMBOL]
8542          --     [, [Form     =>] Ada | VMS]
8543          --     [, [Code     =>] static_integer_EXPRESSION]);
8544
8545          when Pragma_Export_Exception => Export_Exception : declare
8546             Args  : Args_List (1 .. 4);
8547             Names : constant Name_List (1 .. 4) := (
8548                       Name_Internal,
8549                       Name_External,
8550                       Name_Form,
8551                       Name_Code);
8552
8553             Internal : Node_Id renames Args (1);
8554             External : Node_Id renames Args (2);
8555             Form     : Node_Id renames Args (3);
8556             Code     : Node_Id renames Args (4);
8557
8558          begin
8559             GNAT_Pragma;
8560
8561             if Inside_A_Generic then
8562                Error_Pragma ("pragma% cannot be used for generic entities");
8563             end if;
8564
8565             Gather_Associations (Names, Args);
8566             Process_Extended_Import_Export_Exception_Pragma (
8567               Arg_Internal => Internal,
8568               Arg_External => External,
8569               Arg_Form     => Form,
8570               Arg_Code     => Code);
8571
8572             if not Is_VMS_Exception (Entity (Internal)) then
8573                Set_Exported (Entity (Internal), Internal);
8574             end if;
8575          end Export_Exception;
8576
8577          ---------------------
8578          -- Export_Function --
8579          ---------------------
8580
8581          --  pragma Export_Function (
8582          --        [Internal         =>] LOCAL_NAME
8583          --     [, [External         =>] EXTERNAL_SYMBOL]
8584          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8585          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8586          --     [, [Mechanism        =>] MECHANISM]
8587          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8588
8589          --  EXTERNAL_SYMBOL ::=
8590          --    IDENTIFIER
8591          --  | static_string_EXPRESSION
8592
8593          --  PARAMETER_TYPES ::=
8594          --    null
8595          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8596
8597          --  TYPE_DESIGNATOR ::=
8598          --    subtype_NAME
8599          --  | subtype_Name ' Access
8600
8601          --  MECHANISM ::=
8602          --    MECHANISM_NAME
8603          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8604
8605          --  MECHANISM_ASSOCIATION ::=
8606          --    [formal_parameter_NAME =>] MECHANISM_NAME
8607
8608          --  MECHANISM_NAME ::=
8609          --    Value
8610          --  | Reference
8611          --  | Descriptor [([Class =>] CLASS_NAME)]
8612
8613          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8614
8615          when Pragma_Export_Function => Export_Function : declare
8616             Args  : Args_List (1 .. 6);
8617             Names : constant Name_List (1 .. 6) := (
8618                       Name_Internal,
8619                       Name_External,
8620                       Name_Parameter_Types,
8621                       Name_Result_Type,
8622                       Name_Mechanism,
8623                       Name_Result_Mechanism);
8624
8625             Internal         : Node_Id renames Args (1);
8626             External         : Node_Id renames Args (2);
8627             Parameter_Types  : Node_Id renames Args (3);
8628             Result_Type      : Node_Id renames Args (4);
8629             Mechanism        : Node_Id renames Args (5);
8630             Result_Mechanism : Node_Id renames Args (6);
8631
8632          begin
8633             GNAT_Pragma;
8634             Gather_Associations (Names, Args);
8635             Process_Extended_Import_Export_Subprogram_Pragma (
8636               Arg_Internal         => Internal,
8637               Arg_External         => External,
8638               Arg_Parameter_Types  => Parameter_Types,
8639               Arg_Result_Type      => Result_Type,
8640               Arg_Mechanism        => Mechanism,
8641               Arg_Result_Mechanism => Result_Mechanism);
8642          end Export_Function;
8643
8644          -------------------
8645          -- Export_Object --
8646          -------------------
8647
8648          --  pragma Export_Object (
8649          --        [Internal =>] LOCAL_NAME
8650          --     [, [External =>] EXTERNAL_SYMBOL]
8651          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8652
8653          --  EXTERNAL_SYMBOL ::=
8654          --    IDENTIFIER
8655          --  | static_string_EXPRESSION
8656
8657          --  PARAMETER_TYPES ::=
8658          --    null
8659          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8660
8661          --  TYPE_DESIGNATOR ::=
8662          --    subtype_NAME
8663          --  | subtype_Name ' Access
8664
8665          --  MECHANISM ::=
8666          --    MECHANISM_NAME
8667          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8668
8669          --  MECHANISM_ASSOCIATION ::=
8670          --    [formal_parameter_NAME =>] MECHANISM_NAME
8671
8672          --  MECHANISM_NAME ::=
8673          --    Value
8674          --  | Reference
8675          --  | Descriptor [([Class =>] CLASS_NAME)]
8676
8677          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8678
8679          when Pragma_Export_Object => Export_Object : declare
8680             Args  : Args_List (1 .. 3);
8681             Names : constant Name_List (1 .. 3) := (
8682                       Name_Internal,
8683                       Name_External,
8684                       Name_Size);
8685
8686             Internal : Node_Id renames Args (1);
8687             External : Node_Id renames Args (2);
8688             Size     : Node_Id renames Args (3);
8689
8690          begin
8691             GNAT_Pragma;
8692             Gather_Associations (Names, Args);
8693             Process_Extended_Import_Export_Object_Pragma (
8694               Arg_Internal => Internal,
8695               Arg_External => External,
8696               Arg_Size     => Size);
8697          end Export_Object;
8698
8699          ----------------------
8700          -- Export_Procedure --
8701          ----------------------
8702
8703          --  pragma Export_Procedure (
8704          --        [Internal         =>] LOCAL_NAME
8705          --     [, [External         =>] EXTERNAL_SYMBOL]
8706          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8707          --     [, [Mechanism        =>] MECHANISM]);
8708
8709          --  EXTERNAL_SYMBOL ::=
8710          --    IDENTIFIER
8711          --  | static_string_EXPRESSION
8712
8713          --  PARAMETER_TYPES ::=
8714          --    null
8715          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8716
8717          --  TYPE_DESIGNATOR ::=
8718          --    subtype_NAME
8719          --  | subtype_Name ' Access
8720
8721          --  MECHANISM ::=
8722          --    MECHANISM_NAME
8723          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8724
8725          --  MECHANISM_ASSOCIATION ::=
8726          --    [formal_parameter_NAME =>] MECHANISM_NAME
8727
8728          --  MECHANISM_NAME ::=
8729          --    Value
8730          --  | Reference
8731          --  | Descriptor [([Class =>] CLASS_NAME)]
8732
8733          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8734
8735          when Pragma_Export_Procedure => Export_Procedure : declare
8736             Args  : Args_List (1 .. 4);
8737             Names : constant Name_List (1 .. 4) := (
8738                       Name_Internal,
8739                       Name_External,
8740                       Name_Parameter_Types,
8741                       Name_Mechanism);
8742
8743             Internal        : Node_Id renames Args (1);
8744             External        : Node_Id renames Args (2);
8745             Parameter_Types : Node_Id renames Args (3);
8746             Mechanism       : Node_Id renames Args (4);
8747
8748          begin
8749             GNAT_Pragma;
8750             Gather_Associations (Names, Args);
8751             Process_Extended_Import_Export_Subprogram_Pragma (
8752               Arg_Internal        => Internal,
8753               Arg_External        => External,
8754               Arg_Parameter_Types => Parameter_Types,
8755               Arg_Mechanism       => Mechanism);
8756          end Export_Procedure;
8757
8758          ------------------
8759          -- Export_Value --
8760          ------------------
8761
8762          --  pragma Export_Value (
8763          --     [Value     =>] static_integer_EXPRESSION,
8764          --     [Link_Name =>] static_string_EXPRESSION);
8765
8766          when Pragma_Export_Value =>
8767             GNAT_Pragma;
8768             Check_Arg_Order ((Name_Value, Name_Link_Name));
8769             Check_Arg_Count (2);
8770
8771             Check_Optional_Identifier (Arg1, Name_Value);
8772             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8773
8774             Check_Optional_Identifier (Arg2, Name_Link_Name);
8775             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8776
8777          -----------------------------
8778          -- Export_Valued_Procedure --
8779          -----------------------------
8780
8781          --  pragma Export_Valued_Procedure (
8782          --        [Internal         =>] LOCAL_NAME
8783          --     [, [External         =>] EXTERNAL_SYMBOL,]
8784          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8785          --     [, [Mechanism        =>] MECHANISM]);
8786
8787          --  EXTERNAL_SYMBOL ::=
8788          --    IDENTIFIER
8789          --  | static_string_EXPRESSION
8790
8791          --  PARAMETER_TYPES ::=
8792          --    null
8793          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8794
8795          --  TYPE_DESIGNATOR ::=
8796          --    subtype_NAME
8797          --  | subtype_Name ' Access
8798
8799          --  MECHANISM ::=
8800          --    MECHANISM_NAME
8801          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8802
8803          --  MECHANISM_ASSOCIATION ::=
8804          --    [formal_parameter_NAME =>] MECHANISM_NAME
8805
8806          --  MECHANISM_NAME ::=
8807          --    Value
8808          --  | Reference
8809          --  | Descriptor [([Class =>] CLASS_NAME)]
8810
8811          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8812
8813          when Pragma_Export_Valued_Procedure =>
8814          Export_Valued_Procedure : declare
8815             Args  : Args_List (1 .. 4);
8816             Names : constant Name_List (1 .. 4) := (
8817                       Name_Internal,
8818                       Name_External,
8819                       Name_Parameter_Types,
8820                       Name_Mechanism);
8821
8822             Internal        : Node_Id renames Args (1);
8823             External        : Node_Id renames Args (2);
8824             Parameter_Types : Node_Id renames Args (3);
8825             Mechanism       : Node_Id renames Args (4);
8826
8827          begin
8828             GNAT_Pragma;
8829             Gather_Associations (Names, Args);
8830             Process_Extended_Import_Export_Subprogram_Pragma (
8831               Arg_Internal        => Internal,
8832               Arg_External        => External,
8833               Arg_Parameter_Types => Parameter_Types,
8834               Arg_Mechanism       => Mechanism);
8835          end Export_Valued_Procedure;
8836
8837          -------------------
8838          -- Extend_System --
8839          -------------------
8840
8841          --  pragma Extend_System ([Name =>] Identifier);
8842
8843          when Pragma_Extend_System => Extend_System : declare
8844          begin
8845             GNAT_Pragma;
8846             Check_Valid_Configuration_Pragma;
8847             Check_Arg_Count (1);
8848             Check_Optional_Identifier (Arg1, Name_Name);
8849             Check_Arg_Is_Identifier (Arg1);
8850
8851             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8852
8853             if Name_Len > 4
8854               and then Name_Buffer (1 .. 4) = "aux_"
8855             then
8856                if Present (System_Extend_Pragma_Arg) then
8857                   if Chars (Get_Pragma_Arg (Arg1)) =
8858                      Chars (Expression (System_Extend_Pragma_Arg))
8859                   then
8860                      null;
8861                   else
8862                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8863                      Error_Pragma ("pragma% conflicts with that #");
8864                   end if;
8865
8866                else
8867                   System_Extend_Pragma_Arg := Arg1;
8868
8869                   if not GNAT_Mode then
8870                      System_Extend_Unit := Arg1;
8871                   end if;
8872                end if;
8873             else
8874                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8875             end if;
8876          end Extend_System;
8877
8878          ------------------------
8879          -- Extensions_Allowed --
8880          ------------------------
8881
8882          --  pragma Extensions_Allowed (ON | OFF);
8883
8884          when Pragma_Extensions_Allowed =>
8885             GNAT_Pragma;
8886             Check_Arg_Count (1);
8887             Check_No_Identifiers;
8888             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8889
8890             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8891                Extensions_Allowed := True;
8892                Ada_Version := Ada_Version_Type'Last;
8893
8894             else
8895                Extensions_Allowed := False;
8896                Ada_Version := Ada_Version_Explicit;
8897             end if;
8898
8899          --------------
8900          -- External --
8901          --------------
8902
8903          --  pragma External (
8904          --    [   Convention    =>] convention_IDENTIFIER,
8905          --    [   Entity        =>] local_NAME
8906          --    [, [External_Name =>] static_string_EXPRESSION ]
8907          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8908
8909          when Pragma_External => External : declare
8910                Def_Id : Entity_Id;
8911
8912                C : Convention_Id;
8913                pragma Warnings (Off, C);
8914
8915          begin
8916             GNAT_Pragma;
8917             Check_Arg_Order
8918               ((Name_Convention,
8919                 Name_Entity,
8920                 Name_External_Name,
8921                 Name_Link_Name));
8922             Check_At_Least_N_Arguments (2);
8923             Check_At_Most_N_Arguments  (4);
8924             Process_Convention (C, Def_Id);
8925             Note_Possible_Modification
8926               (Get_Pragma_Arg (Arg2), Sure => False);
8927             Process_Interface_Name (Def_Id, Arg3, Arg4);
8928             Set_Exported (Def_Id, Arg2);
8929          end External;
8930
8931          --------------------------
8932          -- External_Name_Casing --
8933          --------------------------
8934
8935          --  pragma External_Name_Casing (
8936          --    UPPERCASE | LOWERCASE
8937          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8938
8939          when Pragma_External_Name_Casing => External_Name_Casing : declare
8940          begin
8941             GNAT_Pragma;
8942             Check_No_Identifiers;
8943
8944             if Arg_Count = 2 then
8945                Check_Arg_Is_One_Of
8946                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8947
8948                case Chars (Get_Pragma_Arg (Arg2)) is
8949                   when Name_As_Is     =>
8950                      Opt.External_Name_Exp_Casing := As_Is;
8951
8952                   when Name_Uppercase =>
8953                      Opt.External_Name_Exp_Casing := Uppercase;
8954
8955                   when Name_Lowercase =>
8956                      Opt.External_Name_Exp_Casing := Lowercase;
8957
8958                   when others =>
8959                      null;
8960                end case;
8961
8962             else
8963                Check_Arg_Count (1);
8964             end if;
8965
8966             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8967
8968             case Chars (Get_Pragma_Arg (Arg1)) is
8969                when Name_Uppercase =>
8970                   Opt.External_Name_Imp_Casing := Uppercase;
8971
8972                when Name_Lowercase =>
8973                   Opt.External_Name_Imp_Casing := Lowercase;
8974
8975                when others =>
8976                   null;
8977             end case;
8978          end External_Name_Casing;
8979
8980          --------------------------
8981          -- Favor_Top_Level --
8982          --------------------------
8983
8984          --  pragma Favor_Top_Level (type_NAME);
8985
8986          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8987                Named_Entity : Entity_Id;
8988
8989          begin
8990             GNAT_Pragma;
8991             Check_No_Identifiers;
8992             Check_Arg_Count (1);
8993             Check_Arg_Is_Local_Name (Arg1);
8994             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8995
8996             --  If it's an access-to-subprogram type (in particular, not a
8997             --  subtype), set the flag on that type.
8998
8999             if Is_Access_Subprogram_Type (Named_Entity) then
9000                Set_Can_Use_Internal_Rep (Named_Entity, False);
9001
9002             --  Otherwise it's an error (name denotes the wrong sort of entity)
9003
9004             else
9005                Error_Pragma_Arg
9006                  ("access-to-subprogram type expected",
9007                   Get_Pragma_Arg (Arg1));
9008             end if;
9009          end Favor_Top_Level;
9010
9011          ---------------
9012          -- Fast_Math --
9013          ---------------
9014
9015          --  pragma Fast_Math;
9016
9017          when Pragma_Fast_Math =>
9018             GNAT_Pragma;
9019             Check_No_Identifiers;
9020             Check_Valid_Configuration_Pragma;
9021             Fast_Math := True;
9022
9023          ---------------------------
9024          -- Finalize_Storage_Only --
9025          ---------------------------
9026
9027          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
9028
9029          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
9030             Assoc   : constant Node_Id := Arg1;
9031             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
9032             Typ     : Entity_Id;
9033
9034          begin
9035             GNAT_Pragma;
9036             Check_No_Identifiers;
9037             Check_Arg_Count (1);
9038             Check_Arg_Is_Local_Name (Arg1);
9039
9040             Find_Type (Type_Id);
9041             Typ := Entity (Type_Id);
9042
9043             if Typ = Any_Type
9044               or else Rep_Item_Too_Early (Typ, N)
9045             then
9046                return;
9047             else
9048                Typ := Underlying_Type (Typ);
9049             end if;
9050
9051             if not Is_Controlled (Typ) then
9052                Error_Pragma ("pragma% must specify controlled type");
9053             end if;
9054
9055             Check_First_Subtype (Arg1);
9056
9057             if Finalize_Storage_Only (Typ) then
9058                Error_Pragma ("duplicate pragma%, only one allowed");
9059
9060             elsif not Rep_Item_Too_Late (Typ, N) then
9061                Set_Finalize_Storage_Only (Base_Type (Typ), True);
9062             end if;
9063          end Finalize_Storage;
9064
9065          --------------------------
9066          -- Float_Representation --
9067          --------------------------
9068
9069          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
9070
9071          --  FLOAT_REP ::= VAX_Float | IEEE_Float
9072
9073          when Pragma_Float_Representation => Float_Representation : declare
9074             Argx : Node_Id;
9075             Digs : Nat;
9076             Ent  : Entity_Id;
9077
9078          begin
9079             GNAT_Pragma;
9080
9081             if Arg_Count = 1 then
9082                Check_Valid_Configuration_Pragma;
9083             else
9084                Check_Arg_Count (2);
9085                Check_Optional_Identifier (Arg2, Name_Entity);
9086                Check_Arg_Is_Local_Name (Arg2);
9087             end if;
9088
9089             Check_No_Identifier (Arg1);
9090             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
9091
9092             if not OpenVMS_On_Target then
9093                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9094                   Error_Pragma
9095                     ("?pragma% ignored (applies only to Open'V'M'S)");
9096                end if;
9097
9098                return;
9099             end if;
9100
9101             --  One argument case
9102
9103             if Arg_Count = 1 then
9104                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9105                   if Opt.Float_Format = 'I' then
9106                      Error_Pragma ("'I'E'E'E format previously specified");
9107                   end if;
9108
9109                   Opt.Float_Format := 'V';
9110
9111                else
9112                   if Opt.Float_Format = 'V' then
9113                      Error_Pragma ("'V'A'X format previously specified");
9114                   end if;
9115
9116                   Opt.Float_Format := 'I';
9117                end if;
9118
9119                Set_Standard_Fpt_Formats;
9120
9121             --  Two argument case
9122
9123             else
9124                Argx := Get_Pragma_Arg (Arg2);
9125
9126                if not Is_Entity_Name (Argx)
9127                  or else not Is_Floating_Point_Type (Entity (Argx))
9128                then
9129                   Error_Pragma_Arg
9130                     ("second argument of% pragma must be floating-point type",
9131                      Arg2);
9132                end if;
9133
9134                Ent  := Entity (Argx);
9135                Digs := UI_To_Int (Digits_Value (Ent));
9136
9137                --  Two arguments, VAX_Float case
9138
9139                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9140                   case Digs is
9141                      when  6 => Set_F_Float (Ent);
9142                      when  9 => Set_D_Float (Ent);
9143                      when 15 => Set_G_Float (Ent);
9144
9145                      when others =>
9146                         Error_Pragma_Arg
9147                           ("wrong digits value, must be 6,9 or 15", Arg2);
9148                   end case;
9149
9150                --  Two arguments, IEEE_Float case
9151
9152                else
9153                   case Digs is
9154                      when  6 => Set_IEEE_Short (Ent);
9155                      when 15 => Set_IEEE_Long  (Ent);
9156
9157                      when others =>
9158                         Error_Pragma_Arg
9159                           ("wrong digits value, must be 6 or 15", Arg2);
9160                   end case;
9161                end if;
9162             end if;
9163          end Float_Representation;
9164
9165          -----------
9166          -- Ident --
9167          -----------
9168
9169          --  pragma Ident (static_string_EXPRESSION)
9170
9171          --  Note: pragma Comment shares this processing. Pragma Comment is
9172          --  identical to Ident, except that the restriction of the argument to
9173          --  31 characters and the placement restrictions are not enforced for
9174          --  pragma Comment.
9175
9176          when Pragma_Ident | Pragma_Comment => Ident : declare
9177             Str : Node_Id;
9178
9179          begin
9180             GNAT_Pragma;
9181             Check_Arg_Count (1);
9182             Check_No_Identifiers;
9183             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9184             Store_Note (N);
9185
9186             --  For pragma Ident, preserve DEC compatibility by requiring the
9187             --  pragma to appear in a declarative part or package spec.
9188
9189             if Prag_Id = Pragma_Ident then
9190                Check_Is_In_Decl_Part_Or_Package_Spec;
9191             end if;
9192
9193             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9194
9195             declare
9196                CS : Node_Id;
9197                GP : Node_Id;
9198
9199             begin
9200                GP := Parent (Parent (N));
9201
9202                if Nkind_In (GP, N_Package_Declaration,
9203                                 N_Generic_Package_Declaration)
9204                then
9205                   GP := Parent (GP);
9206                end if;
9207
9208                --  If we have a compilation unit, then record the ident value,
9209                --  checking for improper duplication.
9210
9211                if Nkind (GP) = N_Compilation_Unit then
9212                   CS := Ident_String (Current_Sem_Unit);
9213
9214                   if Present (CS) then
9215
9216                      --  For Ident, we do not permit multiple instances
9217
9218                      if Prag_Id = Pragma_Ident then
9219                         Error_Pragma ("duplicate% pragma not permitted");
9220
9221                      --  For Comment, we concatenate the string, unless we want
9222                      --  to preserve the tree structure for ASIS.
9223
9224                      elsif not ASIS_Mode then
9225                         Start_String (Strval (CS));
9226                         Store_String_Char (' ');
9227                         Store_String_Chars (Strval (Str));
9228                         Set_Strval (CS, End_String);
9229                      end if;
9230
9231                   else
9232                      --  In VMS, the effect of IDENT is achieved by passing
9233                      --  --identification=name as a --for-linker switch.
9234
9235                      if OpenVMS_On_Target then
9236                         Start_String;
9237                         Store_String_Chars
9238                           ("--for-linker=--identification=");
9239                         String_To_Name_Buffer (Strval (Str));
9240                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
9241
9242                         --  Only the last processed IDENT is saved. The main
9243                         --  purpose is so an IDENT associated with a main
9244                         --  procedure will be used in preference to an IDENT
9245                         --  associated with a with'd package.
9246
9247                         Replace_Linker_Option_String
9248                           (End_String, "--for-linker=--identification=");
9249                      end if;
9250
9251                      Set_Ident_String (Current_Sem_Unit, Str);
9252                   end if;
9253
9254                --  For subunits, we just ignore the Ident, since in GNAT these
9255                --  are not separate object files, and hence not separate units
9256                --  in the unit table.
9257
9258                elsif Nkind (GP) = N_Subunit then
9259                   null;
9260
9261                --  Otherwise we have a misplaced pragma Ident, but we ignore
9262                --  this if we are in an instantiation, since it comes from
9263                --  a generic, and has no relevance to the instantiation.
9264
9265                elsif Prag_Id = Pragma_Ident then
9266                   if Instantiation_Location (Loc) = No_Location then
9267                      Error_Pragma ("pragma% only allowed at outer level");
9268                   end if;
9269                end if;
9270             end;
9271          end Ident;
9272
9273          ----------------------------
9274          -- Implementation_Defined --
9275          ----------------------------
9276
9277          --  pragma Implementation_Defined (local_NAME);
9278
9279          --  Marks previously declared entity as implementation defined. For
9280          --  an overloaded entity, applies to the most recent homonym.
9281
9282          --  pragma Implementation_Defined;
9283
9284          --  The form with no arguments appears anywhere within a scope, most
9285          --  typically a package spec, and indicates that all entities that are
9286          --  defined within the package spec are Implementation_Defined.
9287
9288          when Pragma_Implementation_Defined => Implementation_Defined : declare
9289             Ent : Entity_Id;
9290
9291          begin
9292             Check_No_Identifiers;
9293
9294             --  Form with no arguments
9295
9296             if Arg_Count = 0 then
9297                Set_Is_Implementation_Defined (Current_Scope);
9298
9299             --  Form with one argument
9300
9301             else
9302                Check_Arg_Count (1);
9303                Check_Arg_Is_Local_Name (Arg1);
9304                Ent := Entity (Get_Pragma_Arg (Arg1));
9305                Set_Is_Implementation_Defined (Ent);
9306             end if;
9307          end Implementation_Defined;
9308
9309          -----------------
9310          -- Implemented --
9311          -----------------
9312
9313          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9314          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9315
9316          when Pragma_Implemented => Implemented : declare
9317             Proc_Id : Entity_Id;
9318             Typ     : Entity_Id;
9319
9320          begin
9321             Ada_2012_Pragma;
9322             Check_Arg_Count (2);
9323             Check_No_Identifiers;
9324             Check_Arg_Is_Identifier (Arg1);
9325             Check_Arg_Is_Local_Name (Arg1);
9326             Check_Arg_Is_One_Of
9327               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9328
9329             --  Extract the name of the local procedure
9330
9331             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9332
9333             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9334             --  primitive procedure of a synchronized tagged type.
9335
9336             if Ekind (Proc_Id) = E_Procedure
9337               and then Is_Primitive (Proc_Id)
9338               and then Present (First_Formal (Proc_Id))
9339             then
9340                Typ := Etype (First_Formal (Proc_Id));
9341
9342                if Is_Tagged_Type (Typ)
9343                  and then
9344
9345                   --  Check for a protected, a synchronized or a task interface
9346
9347                    ((Is_Interface (Typ)
9348                        and then Is_Synchronized_Interface (Typ))
9349
9350                   --  Check for a protected type or a task type that implements
9351                   --  an interface.
9352
9353                    or else
9354                     (Is_Concurrent_Record_Type (Typ)
9355                        and then Present (Interfaces (Typ)))
9356
9357                   --  Check for a private record extension with keyword
9358                   --  "synchronized".
9359
9360                    or else
9361                     (Ekind_In (Typ, E_Record_Type_With_Private,
9362                                     E_Record_Subtype_With_Private)
9363                        and then Synchronized_Present (Parent (Typ))))
9364                then
9365                   null;
9366                else
9367                   Error_Pragma_Arg
9368                     ("controlling formal must be of synchronized " &
9369                      "tagged type", Arg1);
9370                   return;
9371                end if;
9372
9373             --  Procedures declared inside a protected type must be accepted
9374
9375             elsif Ekind (Proc_Id) = E_Procedure
9376               and then Is_Protected_Type (Scope (Proc_Id))
9377             then
9378                null;
9379
9380             --  The first argument is not a primitive procedure
9381
9382             else
9383                Error_Pragma_Arg
9384                  ("pragma % must be applied to a primitive procedure", Arg1);
9385                return;
9386             end if;
9387
9388             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9389             --  By_Protected_Procedure to the primitive procedure of a task
9390             --  interface.
9391
9392             if Chars (Arg2) = Name_By_Protected_Procedure
9393               and then Is_Interface (Typ)
9394               and then Is_Task_Interface (Typ)
9395             then
9396                Error_Pragma_Arg
9397                  ("implementation kind By_Protected_Procedure cannot be " &
9398                   "applied to a task interface primitive", Arg2);
9399                return;
9400             end if;
9401
9402             Record_Rep_Item (Proc_Id, N);
9403          end Implemented;
9404
9405          ----------------------
9406          -- Implicit_Packing --
9407          ----------------------
9408
9409          --  pragma Implicit_Packing;
9410
9411          when Pragma_Implicit_Packing =>
9412             GNAT_Pragma;
9413             Check_Arg_Count (0);
9414             Implicit_Packing := True;
9415
9416          ------------
9417          -- Import --
9418          ------------
9419
9420          --  pragma Import (
9421          --       [Convention    =>] convention_IDENTIFIER,
9422          --       [Entity        =>] local_NAME
9423          --    [, [External_Name =>] static_string_EXPRESSION ]
9424          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9425
9426          when Pragma_Import =>
9427             Check_Ada_83_Warning;
9428             Check_Arg_Order
9429               ((Name_Convention,
9430                 Name_Entity,
9431                 Name_External_Name,
9432                 Name_Link_Name));
9433             Check_At_Least_N_Arguments (2);
9434             Check_At_Most_N_Arguments  (4);
9435             Process_Import_Or_Interface;
9436
9437          ----------------------
9438          -- Import_Exception --
9439          ----------------------
9440
9441          --  pragma Import_Exception (
9442          --        [Internal         =>] LOCAL_NAME
9443          --     [, [External         =>] EXTERNAL_SYMBOL]
9444          --     [, [Form     =>] Ada | VMS]
9445          --     [, [Code     =>] static_integer_EXPRESSION]);
9446
9447          when Pragma_Import_Exception => Import_Exception : declare
9448             Args  : Args_List (1 .. 4);
9449             Names : constant Name_List (1 .. 4) := (
9450                       Name_Internal,
9451                       Name_External,
9452                       Name_Form,
9453                       Name_Code);
9454
9455             Internal : Node_Id renames Args (1);
9456             External : Node_Id renames Args (2);
9457             Form     : Node_Id renames Args (3);
9458             Code     : Node_Id renames Args (4);
9459
9460          begin
9461             GNAT_Pragma;
9462             Gather_Associations (Names, Args);
9463
9464             if Present (External) and then Present (Code) then
9465                Error_Pragma
9466                  ("cannot give both External and Code options for pragma%");
9467             end if;
9468
9469             Process_Extended_Import_Export_Exception_Pragma (
9470               Arg_Internal => Internal,
9471               Arg_External => External,
9472               Arg_Form     => Form,
9473               Arg_Code     => Code);
9474
9475             if not Is_VMS_Exception (Entity (Internal)) then
9476                Set_Imported (Entity (Internal));
9477             end if;
9478          end Import_Exception;
9479
9480          ---------------------
9481          -- Import_Function --
9482          ---------------------
9483
9484          --  pragma Import_Function (
9485          --        [Internal                 =>] LOCAL_NAME,
9486          --     [, [External                 =>] EXTERNAL_SYMBOL]
9487          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9488          --     [, [Result_Type              =>] SUBTYPE_MARK]
9489          --     [, [Mechanism                =>] MECHANISM]
9490          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9491          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9492
9493          --  EXTERNAL_SYMBOL ::=
9494          --    IDENTIFIER
9495          --  | static_string_EXPRESSION
9496
9497          --  PARAMETER_TYPES ::=
9498          --    null
9499          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9500
9501          --  TYPE_DESIGNATOR ::=
9502          --    subtype_NAME
9503          --  | subtype_Name ' Access
9504
9505          --  MECHANISM ::=
9506          --    MECHANISM_NAME
9507          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9508
9509          --  MECHANISM_ASSOCIATION ::=
9510          --    [formal_parameter_NAME =>] MECHANISM_NAME
9511
9512          --  MECHANISM_NAME ::=
9513          --    Value
9514          --  | Reference
9515          --  | Descriptor [([Class =>] CLASS_NAME)]
9516
9517          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9518
9519          when Pragma_Import_Function => Import_Function : declare
9520             Args  : Args_List (1 .. 7);
9521             Names : constant Name_List (1 .. 7) := (
9522                       Name_Internal,
9523                       Name_External,
9524                       Name_Parameter_Types,
9525                       Name_Result_Type,
9526                       Name_Mechanism,
9527                       Name_Result_Mechanism,
9528                       Name_First_Optional_Parameter);
9529
9530             Internal                 : Node_Id renames Args (1);
9531             External                 : Node_Id renames Args (2);
9532             Parameter_Types          : Node_Id renames Args (3);
9533             Result_Type              : Node_Id renames Args (4);
9534             Mechanism                : Node_Id renames Args (5);
9535             Result_Mechanism         : Node_Id renames Args (6);
9536             First_Optional_Parameter : Node_Id renames Args (7);
9537
9538          begin
9539             GNAT_Pragma;
9540             Gather_Associations (Names, Args);
9541             Process_Extended_Import_Export_Subprogram_Pragma (
9542               Arg_Internal                 => Internal,
9543               Arg_External                 => External,
9544               Arg_Parameter_Types          => Parameter_Types,
9545               Arg_Result_Type              => Result_Type,
9546               Arg_Mechanism                => Mechanism,
9547               Arg_Result_Mechanism         => Result_Mechanism,
9548               Arg_First_Optional_Parameter => First_Optional_Parameter);
9549          end Import_Function;
9550
9551          -------------------
9552          -- Import_Object --
9553          -------------------
9554
9555          --  pragma Import_Object (
9556          --        [Internal =>] LOCAL_NAME
9557          --     [, [External =>] EXTERNAL_SYMBOL]
9558          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9559
9560          --  EXTERNAL_SYMBOL ::=
9561          --    IDENTIFIER
9562          --  | static_string_EXPRESSION
9563
9564          when Pragma_Import_Object => Import_Object : declare
9565             Args  : Args_List (1 .. 3);
9566             Names : constant Name_List (1 .. 3) := (
9567                       Name_Internal,
9568                       Name_External,
9569                       Name_Size);
9570
9571             Internal : Node_Id renames Args (1);
9572             External : Node_Id renames Args (2);
9573             Size     : Node_Id renames Args (3);
9574
9575          begin
9576             GNAT_Pragma;
9577             Gather_Associations (Names, Args);
9578             Process_Extended_Import_Export_Object_Pragma (
9579               Arg_Internal => Internal,
9580               Arg_External => External,
9581               Arg_Size     => Size);
9582          end Import_Object;
9583
9584          ----------------------
9585          -- Import_Procedure --
9586          ----------------------
9587
9588          --  pragma Import_Procedure (
9589          --        [Internal                 =>] LOCAL_NAME
9590          --     [, [External                 =>] EXTERNAL_SYMBOL]
9591          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9592          --     [, [Mechanism                =>] MECHANISM]
9593          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9594
9595          --  EXTERNAL_SYMBOL ::=
9596          --    IDENTIFIER
9597          --  | static_string_EXPRESSION
9598
9599          --  PARAMETER_TYPES ::=
9600          --    null
9601          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9602
9603          --  TYPE_DESIGNATOR ::=
9604          --    subtype_NAME
9605          --  | subtype_Name ' Access
9606
9607          --  MECHANISM ::=
9608          --    MECHANISM_NAME
9609          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9610
9611          --  MECHANISM_ASSOCIATION ::=
9612          --    [formal_parameter_NAME =>] MECHANISM_NAME
9613
9614          --  MECHANISM_NAME ::=
9615          --    Value
9616          --  | Reference
9617          --  | Descriptor [([Class =>] CLASS_NAME)]
9618
9619          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9620
9621          when Pragma_Import_Procedure => Import_Procedure : declare
9622             Args  : Args_List (1 .. 5);
9623             Names : constant Name_List (1 .. 5) := (
9624                       Name_Internal,
9625                       Name_External,
9626                       Name_Parameter_Types,
9627                       Name_Mechanism,
9628                       Name_First_Optional_Parameter);
9629
9630             Internal                 : Node_Id renames Args (1);
9631             External                 : Node_Id renames Args (2);
9632             Parameter_Types          : Node_Id renames Args (3);
9633             Mechanism                : Node_Id renames Args (4);
9634             First_Optional_Parameter : Node_Id renames Args (5);
9635
9636          begin
9637             GNAT_Pragma;
9638             Gather_Associations (Names, Args);
9639             Process_Extended_Import_Export_Subprogram_Pragma (
9640               Arg_Internal                 => Internal,
9641               Arg_External                 => External,
9642               Arg_Parameter_Types          => Parameter_Types,
9643               Arg_Mechanism                => Mechanism,
9644               Arg_First_Optional_Parameter => First_Optional_Parameter);
9645          end Import_Procedure;
9646
9647          -----------------------------
9648          -- Import_Valued_Procedure --
9649          -----------------------------
9650
9651          --  pragma Import_Valued_Procedure (
9652          --        [Internal                 =>] LOCAL_NAME
9653          --     [, [External                 =>] EXTERNAL_SYMBOL]
9654          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9655          --     [, [Mechanism                =>] MECHANISM]
9656          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9657
9658          --  EXTERNAL_SYMBOL ::=
9659          --    IDENTIFIER
9660          --  | static_string_EXPRESSION
9661
9662          --  PARAMETER_TYPES ::=
9663          --    null
9664          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9665
9666          --  TYPE_DESIGNATOR ::=
9667          --    subtype_NAME
9668          --  | subtype_Name ' Access
9669
9670          --  MECHANISM ::=
9671          --    MECHANISM_NAME
9672          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9673
9674          --  MECHANISM_ASSOCIATION ::=
9675          --    [formal_parameter_NAME =>] MECHANISM_NAME
9676
9677          --  MECHANISM_NAME ::=
9678          --    Value
9679          --  | Reference
9680          --  | Descriptor [([Class =>] CLASS_NAME)]
9681
9682          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9683
9684          when Pragma_Import_Valued_Procedure =>
9685          Import_Valued_Procedure : declare
9686             Args  : Args_List (1 .. 5);
9687             Names : constant Name_List (1 .. 5) := (
9688                       Name_Internal,
9689                       Name_External,
9690                       Name_Parameter_Types,
9691                       Name_Mechanism,
9692                       Name_First_Optional_Parameter);
9693
9694             Internal                 : Node_Id renames Args (1);
9695             External                 : Node_Id renames Args (2);
9696             Parameter_Types          : Node_Id renames Args (3);
9697             Mechanism                : Node_Id renames Args (4);
9698             First_Optional_Parameter : Node_Id renames Args (5);
9699
9700          begin
9701             GNAT_Pragma;
9702             Gather_Associations (Names, Args);
9703             Process_Extended_Import_Export_Subprogram_Pragma (
9704               Arg_Internal                 => Internal,
9705               Arg_External                 => External,
9706               Arg_Parameter_Types          => Parameter_Types,
9707               Arg_Mechanism                => Mechanism,
9708               Arg_First_Optional_Parameter => First_Optional_Parameter);
9709          end Import_Valued_Procedure;
9710
9711          -----------------
9712          -- Independent --
9713          -----------------
9714
9715          --  pragma Independent (LOCAL_NAME);
9716
9717          when Pragma_Independent => Independent : declare
9718             E_Id : Node_Id;
9719             E    : Entity_Id;
9720             D    : Node_Id;
9721             K    : Node_Kind;
9722
9723          begin
9724             Check_Ada_83_Warning;
9725             Ada_2012_Pragma;
9726             Check_No_Identifiers;
9727             Check_Arg_Count (1);
9728             Check_Arg_Is_Local_Name (Arg1);
9729             E_Id := Get_Pragma_Arg (Arg1);
9730
9731             if Etype (E_Id) = Any_Type then
9732                return;
9733             end if;
9734
9735             E := Entity (E_Id);
9736             D := Declaration_Node (E);
9737             K := Nkind (D);
9738
9739             --  Check duplicate before we chain ourselves!
9740
9741             Check_Duplicate_Pragma (E);
9742
9743             --  Check appropriate entity
9744
9745             if Is_Type (E) then
9746                if Rep_Item_Too_Early (E, N)
9747                     or else
9748                   Rep_Item_Too_Late (E, N)
9749                then
9750                   return;
9751                else
9752                   Check_First_Subtype (Arg1);
9753                end if;
9754
9755             elsif K = N_Object_Declaration
9756               or else (K = N_Component_Declaration
9757                        and then Original_Record_Component (E) = E)
9758             then
9759                if Rep_Item_Too_Late (E, N) then
9760                   return;
9761                end if;
9762
9763             else
9764                Error_Pragma_Arg
9765                  ("inappropriate entity for pragma%", Arg1);
9766             end if;
9767
9768             Independence_Checks.Append ((N, E));
9769          end Independent;
9770
9771          ----------------------------
9772          -- Independent_Components --
9773          ----------------------------
9774
9775          --  pragma Atomic_Components (array_LOCAL_NAME);
9776
9777          --  This processing is shared by Volatile_Components
9778
9779          when Pragma_Independent_Components => Independent_Components : declare
9780             E_Id : Node_Id;
9781             E    : Entity_Id;
9782             D    : Node_Id;
9783             K    : Node_Kind;
9784
9785          begin
9786             Check_Ada_83_Warning;
9787             Ada_2012_Pragma;
9788             Check_No_Identifiers;
9789             Check_Arg_Count (1);
9790             Check_Arg_Is_Local_Name (Arg1);
9791             E_Id := Get_Pragma_Arg (Arg1);
9792
9793             if Etype (E_Id) = Any_Type then
9794                return;
9795             end if;
9796
9797             E := Entity (E_Id);
9798
9799             --  Check duplicate before we chain ourselves!
9800
9801             Check_Duplicate_Pragma (E);
9802
9803             --  Check appropriate entity
9804
9805             if Rep_Item_Too_Early (E, N)
9806                  or else
9807                Rep_Item_Too_Late (E, N)
9808             then
9809                return;
9810             end if;
9811
9812             D := Declaration_Node (E);
9813             K := Nkind (D);
9814
9815             if (K = N_Full_Type_Declaration
9816                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9817               or else
9818                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9819                    and then Nkind (D) = N_Object_Declaration
9820                    and then Nkind (Object_Definition (D)) =
9821                                        N_Constrained_Array_Definition)
9822             then
9823                Independence_Checks.Append ((N, E));
9824
9825             else
9826                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9827             end if;
9828          end Independent_Components;
9829
9830          ------------------------
9831          -- Initialize_Scalars --
9832          ------------------------
9833
9834          --  pragma Initialize_Scalars;
9835
9836          when Pragma_Initialize_Scalars =>
9837             GNAT_Pragma;
9838             Check_Arg_Count (0);
9839             Check_Valid_Configuration_Pragma;
9840             Check_Restriction (No_Initialize_Scalars, N);
9841
9842             --  Initialize_Scalars creates false positives in CodePeer, and
9843             --  incorrect negative results in Alfa mode, so ignore this pragma
9844             --  in these modes.
9845
9846             if not Restriction_Active (No_Initialize_Scalars)
9847               and then not (CodePeer_Mode or Alfa_Mode)
9848             then
9849                Init_Or_Norm_Scalars := True;
9850                Initialize_Scalars := True;
9851             end if;
9852
9853          ------------
9854          -- Inline --
9855          ------------
9856
9857          --  pragma Inline ( NAME {, NAME} );
9858
9859          when Pragma_Inline =>
9860
9861             --  Pragma is active if inlining option is active
9862
9863             Process_Inline (Inline_Active);
9864
9865          -------------------
9866          -- Inline_Always --
9867          -------------------
9868
9869          --  pragma Inline_Always ( NAME {, NAME} );
9870
9871          when Pragma_Inline_Always =>
9872             GNAT_Pragma;
9873
9874             --  Pragma always active unless in CodePeer or Alfa mode, since
9875             --  this causes walk order issues.
9876
9877             if not (CodePeer_Mode or Alfa_Mode) then
9878                Process_Inline (True);
9879             end if;
9880
9881          --------------------
9882          -- Inline_Generic --
9883          --------------------
9884
9885          --  pragma Inline_Generic (NAME {, NAME});
9886
9887          when Pragma_Inline_Generic =>
9888             GNAT_Pragma;
9889             Process_Generic_List;
9890
9891          ----------------------
9892          -- Inspection_Point --
9893          ----------------------
9894
9895          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9896
9897          when Pragma_Inspection_Point => Inspection_Point : declare
9898             Arg : Node_Id;
9899             Exp : Node_Id;
9900
9901          begin
9902             if Arg_Count > 0 then
9903                Arg := Arg1;
9904                loop
9905                   Exp := Get_Pragma_Arg (Arg);
9906                   Analyze (Exp);
9907
9908                   if not Is_Entity_Name (Exp)
9909                     or else not Is_Object (Entity (Exp))
9910                   then
9911                      Error_Pragma_Arg ("object name required", Arg);
9912                   end if;
9913
9914                   Next (Arg);
9915                   exit when No (Arg);
9916                end loop;
9917             end if;
9918          end Inspection_Point;
9919
9920          ---------------
9921          -- Interface --
9922          ---------------
9923
9924          --  pragma Interface (
9925          --    [   Convention    =>] convention_IDENTIFIER,
9926          --    [   Entity        =>] local_NAME
9927          --    [, [External_Name =>] static_string_EXPRESSION ]
9928          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9929
9930          when Pragma_Interface =>
9931             GNAT_Pragma;
9932             Check_Arg_Order
9933               ((Name_Convention,
9934                 Name_Entity,
9935                 Name_External_Name,
9936                 Name_Link_Name));
9937             Check_At_Least_N_Arguments (2);
9938             Check_At_Most_N_Arguments  (4);
9939             Process_Import_Or_Interface;
9940
9941             --  In Ada 2005, the permission to use Interface (a reserved word)
9942             --  as a pragma name is considered an obsolescent feature.
9943
9944             if Ada_Version >= Ada_2005 then
9945                Check_Restriction
9946                  (No_Obsolescent_Features, Pragma_Identifier (N));
9947             end if;
9948
9949          --------------------
9950          -- Interface_Name --
9951          --------------------
9952
9953          --  pragma Interface_Name (
9954          --    [  Entity        =>] local_NAME
9955          --    [,[External_Name =>] static_string_EXPRESSION ]
9956          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9957
9958          when Pragma_Interface_Name => Interface_Name : declare
9959             Id     : Node_Id;
9960             Def_Id : Entity_Id;
9961             Hom_Id : Entity_Id;
9962             Found  : Boolean;
9963
9964          begin
9965             GNAT_Pragma;
9966             Check_Arg_Order
9967               ((Name_Entity, Name_External_Name, Name_Link_Name));
9968             Check_At_Least_N_Arguments (2);
9969             Check_At_Most_N_Arguments  (3);
9970             Id := Get_Pragma_Arg (Arg1);
9971             Analyze (Id);
9972
9973             if not Is_Entity_Name (Id) then
9974                Error_Pragma_Arg
9975                  ("first argument for pragma% must be entity name", Arg1);
9976             elsif Etype (Id) = Any_Type then
9977                return;
9978             else
9979                Def_Id := Entity (Id);
9980             end if;
9981
9982             --  Special DEC-compatible processing for the object case, forces
9983             --  object to be imported.
9984
9985             if Ekind (Def_Id) = E_Variable then
9986                Kill_Size_Check_Code (Def_Id);
9987                Note_Possible_Modification (Id, Sure => False);
9988
9989                --  Initialization is not allowed for imported variable
9990
9991                if Present (Expression (Parent (Def_Id)))
9992                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9993                then
9994                   Error_Msg_Sloc := Sloc (Def_Id);
9995                   Error_Pragma_Arg
9996                     ("no initialization allowed for declaration of& #",
9997                      Arg2);
9998
9999                else
10000                   --  For compatibility, support VADS usage of providing both
10001                   --  pragmas Interface and Interface_Name to obtain the effect
10002                   --  of a single Import pragma.
10003
10004                   if Is_Imported (Def_Id)
10005                     and then Present (First_Rep_Item (Def_Id))
10006                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
10007                     and then
10008                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
10009                   then
10010                      null;
10011                   else
10012                      Set_Imported (Def_Id);
10013                   end if;
10014
10015                   Set_Is_Public (Def_Id);
10016                   Process_Interface_Name (Def_Id, Arg2, Arg3);
10017                end if;
10018
10019             --  Otherwise must be subprogram
10020
10021             elsif not Is_Subprogram (Def_Id) then
10022                Error_Pragma_Arg
10023                  ("argument of pragma% is not subprogram", Arg1);
10024
10025             else
10026                Check_At_Most_N_Arguments (3);
10027                Hom_Id := Def_Id;
10028                Found := False;
10029
10030                --  Loop through homonyms
10031
10032                loop
10033                   Def_Id := Get_Base_Subprogram (Hom_Id);
10034
10035                   if Is_Imported (Def_Id) then
10036                      Process_Interface_Name (Def_Id, Arg2, Arg3);
10037                      Found := True;
10038                   end if;
10039
10040                   exit when From_Aspect_Specification (N);
10041                   Hom_Id := Homonym (Hom_Id);
10042
10043                   exit when No (Hom_Id)
10044                     or else Scope (Hom_Id) /= Current_Scope;
10045                end loop;
10046
10047                if not Found then
10048                   Error_Pragma_Arg
10049                     ("argument of pragma% is not imported subprogram",
10050                      Arg1);
10051                end if;
10052             end if;
10053          end Interface_Name;
10054
10055          -----------------------
10056          -- Interrupt_Handler --
10057          -----------------------
10058
10059          --  pragma Interrupt_Handler (handler_NAME);
10060
10061          when Pragma_Interrupt_Handler =>
10062             Check_Ada_83_Warning;
10063             Check_Arg_Count (1);
10064             Check_No_Identifiers;
10065
10066             if No_Run_Time_Mode then
10067                Error_Msg_CRT ("Interrupt_Handler pragma", N);
10068             else
10069                Check_Interrupt_Or_Attach_Handler;
10070                Process_Interrupt_Or_Attach_Handler;
10071             end if;
10072
10073          ------------------------
10074          -- Interrupt_Priority --
10075          ------------------------
10076
10077          --  pragma Interrupt_Priority [(EXPRESSION)];
10078
10079          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
10080             P   : constant Node_Id := Parent (N);
10081             Arg : Node_Id;
10082
10083          begin
10084             Check_Ada_83_Warning;
10085
10086             if Arg_Count /= 0 then
10087                Arg := Get_Pragma_Arg (Arg1);
10088                Check_Arg_Count (1);
10089                Check_No_Identifiers;
10090
10091                --  The expression must be analyzed in the special manner
10092                --  described in "Handling of Default and Per-Object
10093                --  Expressions" in sem.ads.
10094
10095                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
10096             end if;
10097
10098             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
10099                Pragma_Misplaced;
10100                return;
10101
10102             elsif Has_Pragma_Priority (P) then
10103                Error_Pragma ("duplicate pragma% not allowed");
10104
10105             else
10106                Set_Has_Pragma_Priority (P, True);
10107                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10108             end if;
10109          end Interrupt_Priority;
10110
10111          ---------------------
10112          -- Interrupt_State --
10113          ---------------------
10114
10115          --  pragma Interrupt_State (
10116          --    [Name  =>] INTERRUPT_ID,
10117          --    [State =>] INTERRUPT_STATE);
10118
10119          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10120          --  INTERRUPT_STATE => System | Runtime | User
10121
10122          --  Note: if the interrupt id is given as an identifier, then it must
10123          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10124          --  given as a static integer expression which must be in the range of
10125          --  Ada.Interrupts.Interrupt_ID.
10126
10127          when Pragma_Interrupt_State => Interrupt_State : declare
10128
10129             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10130             --  This is the entity Ada.Interrupts.Interrupt_ID;
10131
10132             State_Type : Character;
10133             --  Set to 's'/'r'/'u' for System/Runtime/User
10134
10135             IST_Num : Pos;
10136             --  Index to entry in Interrupt_States table
10137
10138             Int_Val : Uint;
10139             --  Value of interrupt
10140
10141             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10142             --  The first argument to the pragma
10143
10144             Int_Ent : Entity_Id;
10145             --  Interrupt entity in Ada.Interrupts.Names
10146
10147          begin
10148             GNAT_Pragma;
10149             Check_Arg_Order ((Name_Name, Name_State));
10150             Check_Arg_Count (2);
10151
10152             Check_Optional_Identifier (Arg1, Name_Name);
10153             Check_Optional_Identifier (Arg2, Name_State);
10154             Check_Arg_Is_Identifier (Arg2);
10155
10156             --  First argument is identifier
10157
10158             if Nkind (Arg1X) = N_Identifier then
10159
10160                --  Search list of names in Ada.Interrupts.Names
10161
10162                Int_Ent := First_Entity (RTE (RE_Names));
10163                loop
10164                   if No (Int_Ent) then
10165                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
10166
10167                   elsif Chars (Int_Ent) = Chars (Arg1X) then
10168                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
10169                      exit;
10170                   end if;
10171
10172                   Next_Entity (Int_Ent);
10173                end loop;
10174
10175             --  First argument is not an identifier, so it must be a static
10176             --  expression of type Ada.Interrupts.Interrupt_ID.
10177
10178             else
10179                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10180                Int_Val := Expr_Value (Arg1X);
10181
10182                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10183                     or else
10184                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10185                then
10186                   Error_Pragma_Arg
10187                     ("value not in range of type " &
10188                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10189                end if;
10190             end if;
10191
10192             --  Check OK state
10193
10194             case Chars (Get_Pragma_Arg (Arg2)) is
10195                when Name_Runtime => State_Type := 'r';
10196                when Name_System  => State_Type := 's';
10197                when Name_User    => State_Type := 'u';
10198
10199                when others =>
10200                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
10201             end case;
10202
10203             --  Check if entry is already stored
10204
10205             IST_Num := Interrupt_States.First;
10206             loop
10207                --  If entry not found, add it
10208
10209                if IST_Num > Interrupt_States.Last then
10210                   Interrupt_States.Append
10211                     ((Interrupt_Number => UI_To_Int (Int_Val),
10212                       Interrupt_State  => State_Type,
10213                       Pragma_Loc       => Loc));
10214                   exit;
10215
10216                --  Case of entry for the same entry
10217
10218                elsif Int_Val = Interrupt_States.Table (IST_Num).
10219                                                            Interrupt_Number
10220                then
10221                   --  If state matches, done, no need to make redundant entry
10222
10223                   exit when
10224                     State_Type = Interrupt_States.Table (IST_Num).
10225                                                            Interrupt_State;
10226
10227                   --  Otherwise if state does not match, error
10228
10229                   Error_Msg_Sloc :=
10230                     Interrupt_States.Table (IST_Num).Pragma_Loc;
10231                   Error_Pragma_Arg
10232                     ("state conflicts with that given #", Arg2);
10233                   exit;
10234                end if;
10235
10236                IST_Num := IST_Num + 1;
10237             end loop;
10238          end Interrupt_State;
10239
10240          ---------------
10241          -- Invariant --
10242          ---------------
10243
10244          --  pragma Invariant
10245          --    ([Entity =>]    type_LOCAL_NAME,
10246          --     [Check  =>]    EXPRESSION
10247          --     [,[Message =>] String_Expression]);
10248
10249          when Pragma_Invariant => Invariant : declare
10250             Type_Id : Node_Id;
10251             Typ     : Entity_Id;
10252
10253             Discard : Boolean;
10254             pragma Unreferenced (Discard);
10255
10256          begin
10257             GNAT_Pragma;
10258             Check_At_Least_N_Arguments (2);
10259             Check_At_Most_N_Arguments (3);
10260             Check_Optional_Identifier (Arg1, Name_Entity);
10261             Check_Optional_Identifier (Arg2, Name_Check);
10262
10263             if Arg_Count = 3 then
10264                Check_Optional_Identifier (Arg3, Name_Message);
10265                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10266             end if;
10267
10268             Check_Arg_Is_Local_Name (Arg1);
10269
10270             Type_Id := Get_Pragma_Arg (Arg1);
10271             Find_Type (Type_Id);
10272             Typ := Entity (Type_Id);
10273
10274             if Typ = Any_Type then
10275                return;
10276
10277             --  An invariant must apply to a private type, or appear in the
10278             --  private part of a package spec and apply to a completion.
10279
10280             elsif Ekind_In (Typ, E_Private_Type,
10281                                  E_Record_Type_With_Private,
10282                                  E_Limited_Private_Type)
10283             then
10284                null;
10285
10286             elsif In_Private_Part (Current_Scope)
10287               and then Has_Private_Declaration (Typ)
10288             then
10289                null;
10290
10291             elsif In_Private_Part (Current_Scope) then
10292                Error_Pragma_Arg
10293                  ("pragma% only allowed for private type " &
10294                   "declared in visible part", Arg1);
10295
10296             else
10297                Error_Pragma_Arg
10298                  ("pragma% only allowed for private type", Arg1);
10299             end if;
10300
10301             --  Note that the type has at least one invariant, and also that
10302             --  it has inheritable invariants if we have Invariant'Class.
10303
10304             Set_Has_Invariants (Typ);
10305
10306             if Class_Present (N) then
10307                Set_Has_Inheritable_Invariants (Typ);
10308             end if;
10309
10310             --  The remaining processing is simply to link the pragma on to
10311             --  the rep item chain, for processing when the type is frozen.
10312             --  This is accomplished by a call to Rep_Item_Too_Late.
10313
10314             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10315          end Invariant;
10316
10317          ----------------------
10318          -- Java_Constructor --
10319          ----------------------
10320
10321          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10322
10323          --  Also handles pragma CIL_Constructor
10324
10325          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10326          Java_Constructor : declare
10327             Convention  : Convention_Id;
10328             Def_Id      : Entity_Id;
10329             Hom_Id      : Entity_Id;
10330             Id          : Entity_Id;
10331             This_Formal : Entity_Id;
10332
10333          begin
10334             GNAT_Pragma;
10335             Check_Arg_Count (1);
10336             Check_Optional_Identifier (Arg1, Name_Entity);
10337             Check_Arg_Is_Local_Name (Arg1);
10338
10339             Id := Get_Pragma_Arg (Arg1);
10340             Find_Program_Unit_Name (Id);
10341
10342             --  If we did not find the name, we are done
10343
10344             if Etype (Id) = Any_Type then
10345                return;
10346             end if;
10347
10348             --  Check wrong use of pragma in wrong VM target
10349
10350             if VM_Target = No_VM then
10351                return;
10352
10353             elsif VM_Target = CLI_Target
10354               and then Prag_Id = Pragma_Java_Constructor
10355             then
10356                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10357
10358             elsif VM_Target = JVM_Target
10359               and then Prag_Id = Pragma_CIL_Constructor
10360             then
10361                Error_Pragma ("must use pragma 'Java_'Constructor");
10362             end if;
10363
10364             case Prag_Id is
10365                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
10366                when Pragma_Java_Constructor => Convention := Convention_Java;
10367                when others                  => null;
10368             end case;
10369
10370             Hom_Id := Entity (Id);
10371
10372             --  Loop through homonyms
10373
10374             loop
10375                Def_Id := Get_Base_Subprogram (Hom_Id);
10376
10377                --  The constructor is required to be a function
10378
10379                if Ekind (Def_Id) /= E_Function then
10380                   if VM_Target = JVM_Target then
10381                      Error_Pragma_Arg
10382                        ("pragma% requires function returning a " &
10383                         "'Java access type", Def_Id);
10384                   else
10385                      Error_Pragma_Arg
10386                        ("pragma% requires function returning a " &
10387                         "'C'I'L access type", Def_Id);
10388                   end if;
10389                end if;
10390
10391                --  Check arguments: For tagged type the first formal must be
10392                --  named "this" and its type must be a named access type
10393                --  designating a class-wide tagged type that has convention
10394                --  CIL/Java. The first formal must also have a null default
10395                --  value. For example:
10396
10397                --      type Typ is tagged ...
10398                --      type Ref is access all Typ;
10399                --      pragma Convention (CIL, Typ);
10400
10401                --      function New_Typ (This : Ref) return Ref;
10402                --      function New_Typ (This : Ref; I : Integer) return Ref;
10403                --      pragma Cil_Constructor (New_Typ);
10404
10405                --  Reason: The first formal must NOT be a primitive of the
10406                --  tagged type.
10407
10408                --  This rule also applies to constructors of delegates used
10409                --  to interface with standard target libraries. For example:
10410
10411                --      type Delegate is access procedure ...
10412                --      pragma Import (CIL, Delegate, ...);
10413
10414                --      function new_Delegate
10415                --        (This : Delegate := null; ... ) return Delegate;
10416
10417                --  For value-types this rule does not apply.
10418
10419                if not Is_Value_Type (Etype (Def_Id)) then
10420                   if No (First_Formal (Def_Id)) then
10421                      Error_Msg_Name_1 := Pname;
10422                      Error_Msg_N ("% function must have parameters", Def_Id);
10423                      return;
10424                   end if;
10425
10426                   --  In the JRE library we have several occurrences in which
10427                   --  the "this" parameter is not the first formal.
10428
10429                   This_Formal := First_Formal (Def_Id);
10430
10431                   --  In the JRE library we have several occurrences in which
10432                   --  the "this" parameter is not the first formal. Search for
10433                   --  it.
10434
10435                   if VM_Target = JVM_Target then
10436                      while Present (This_Formal)
10437                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10438                      loop
10439                         Next_Formal (This_Formal);
10440                      end loop;
10441
10442                      if No (This_Formal) then
10443                         This_Formal := First_Formal (Def_Id);
10444                      end if;
10445                   end if;
10446
10447                   --  Warning: The first parameter should be named "this".
10448                   --  We temporarily allow it because we have the following
10449                   --  case in the Java runtime (file s-osinte.ads) ???
10450
10451                   --    function new_Thread
10452                   --      (Self_Id : System.Address) return Thread_Id;
10453                   --    pragma Java_Constructor (new_Thread);
10454
10455                   if VM_Target = JVM_Target
10456                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10457                                = "self_id"
10458                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10459                   then
10460                      null;
10461
10462                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10463                      Error_Msg_Name_1 := Pname;
10464                      Error_Msg_N
10465                        ("first formal of % function must be named `this`",
10466                         Parent (This_Formal));
10467
10468                   elsif not Is_Access_Type (Etype (This_Formal)) then
10469                      Error_Msg_Name_1 := Pname;
10470                      Error_Msg_N
10471                        ("first formal of % function must be an access type",
10472                         Parameter_Type (Parent (This_Formal)));
10473
10474                   --  For delegates the type of the first formal must be a
10475                   --  named access-to-subprogram type (see previous example)
10476
10477                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10478                     and then Ekind (Etype (This_Formal))
10479                                /= E_Access_Subprogram_Type
10480                   then
10481                      Error_Msg_Name_1 := Pname;
10482                      Error_Msg_N
10483                        ("first formal of % function must be a named access" &
10484                         " to subprogram type",
10485                         Parameter_Type (Parent (This_Formal)));
10486
10487                   --  Warning: We should reject anonymous access types because
10488                   --  the constructor must not be handled as a primitive of the
10489                   --  tagged type. We temporarily allow it because this profile
10490                   --  is currently generated by cil2ada???
10491
10492                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10493                     and then not Ekind_In (Etype (This_Formal),
10494                                              E_Access_Type,
10495                                              E_General_Access_Type,
10496                                              E_Anonymous_Access_Type)
10497                   then
10498                      Error_Msg_Name_1 := Pname;
10499                      Error_Msg_N
10500                        ("first formal of % function must be a named access" &
10501                         " type",
10502                         Parameter_Type (Parent (This_Formal)));
10503
10504                   elsif Atree.Convention
10505                          (Designated_Type (Etype (This_Formal))) /= Convention
10506                   then
10507                      Error_Msg_Name_1 := Pname;
10508
10509                      if Convention = Convention_Java then
10510                         Error_Msg_N
10511                           ("pragma% requires convention 'Cil in designated" &
10512                            " type",
10513                            Parameter_Type (Parent (This_Formal)));
10514                      else
10515                         Error_Msg_N
10516                           ("pragma% requires convention 'Java in designated" &
10517                            " type",
10518                            Parameter_Type (Parent (This_Formal)));
10519                      end if;
10520
10521                   elsif No (Expression (Parent (This_Formal)))
10522                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10523                   then
10524                      Error_Msg_Name_1 := Pname;
10525                      Error_Msg_N
10526                        ("pragma% requires first formal with default `null`",
10527                         Parameter_Type (Parent (This_Formal)));
10528                   end if;
10529                end if;
10530
10531                --  Check result type: the constructor must be a function
10532                --  returning:
10533                --   * a value type (only allowed in the CIL compiler)
10534                --   * an access-to-subprogram type with convention Java/CIL
10535                --   * an access-type designating a type that has convention
10536                --     Java/CIL.
10537
10538                if Is_Value_Type (Etype (Def_Id)) then
10539                   null;
10540
10541                --  Access-to-subprogram type with convention Java/CIL
10542
10543                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10544                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10545                      if Convention = Convention_Java then
10546                         Error_Pragma_Arg
10547                           ("pragma% requires function returning a " &
10548                            "'Java access type", Arg1);
10549                      else
10550                         pragma Assert (Convention = Convention_CIL);
10551                         Error_Pragma_Arg
10552                           ("pragma% requires function returning a " &
10553                            "'C'I'L access type", Arg1);
10554                      end if;
10555                   end if;
10556
10557                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10558                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10559                                                    E_General_Access_Type)
10560                     or else
10561                       Atree.Convention
10562                         (Designated_Type (Etype (Def_Id))) /= Convention
10563                   then
10564                      Error_Msg_Name_1 := Pname;
10565
10566                      if Convention = Convention_Java then
10567                         Error_Pragma_Arg
10568                           ("pragma% requires function returning a named" &
10569                            "'Java access type", Arg1);
10570                      else
10571                         Error_Pragma_Arg
10572                           ("pragma% requires function returning a named" &
10573                            "'C'I'L access type", Arg1);
10574                      end if;
10575                   end if;
10576                end if;
10577
10578                Set_Is_Constructor (Def_Id);
10579                Set_Convention     (Def_Id, Convention);
10580                Set_Is_Imported    (Def_Id);
10581
10582                exit when From_Aspect_Specification (N);
10583                Hom_Id := Homonym (Hom_Id);
10584
10585                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10586             end loop;
10587          end Java_Constructor;
10588
10589          ----------------------
10590          -- Java_Interface --
10591          ----------------------
10592
10593          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10594
10595          when Pragma_Java_Interface => Java_Interface : declare
10596             Arg : Node_Id;
10597             Typ : Entity_Id;
10598
10599          begin
10600             GNAT_Pragma;
10601             Check_Arg_Count (1);
10602             Check_Optional_Identifier (Arg1, Name_Entity);
10603             Check_Arg_Is_Local_Name (Arg1);
10604
10605             Arg := Get_Pragma_Arg (Arg1);
10606             Analyze (Arg);
10607
10608             if Etype (Arg) = Any_Type then
10609                return;
10610             end if;
10611
10612             if not Is_Entity_Name (Arg)
10613               or else not Is_Type (Entity (Arg))
10614             then
10615                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10616             end if;
10617
10618             Typ := Underlying_Type (Entity (Arg));
10619
10620             --  For now simply check some of the semantic constraints on the
10621             --  type. This currently leaves out some restrictions on interface
10622             --  types, namely that the parent type must be java.lang.Object.Typ
10623             --  and that all primitives of the type should be declared
10624             --  abstract. ???
10625
10626             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10627                Error_Pragma_Arg ("pragma% requires an abstract "
10628                  & "tagged type", Arg1);
10629
10630             elsif not Has_Discriminants (Typ)
10631               or else Ekind (Etype (First_Discriminant (Typ)))
10632                         /= E_Anonymous_Access_Type
10633               or else
10634                 not Is_Class_Wide_Type
10635                       (Designated_Type (Etype (First_Discriminant (Typ))))
10636             then
10637                Error_Pragma_Arg
10638                  ("type must have a class-wide access discriminant", Arg1);
10639             end if;
10640          end Java_Interface;
10641
10642          ----------------
10643          -- Keep_Names --
10644          ----------------
10645
10646          --  pragma Keep_Names ([On => ] local_NAME);
10647
10648          when Pragma_Keep_Names => Keep_Names : declare
10649             Arg : Node_Id;
10650
10651          begin
10652             GNAT_Pragma;
10653             Check_Arg_Count (1);
10654             Check_Optional_Identifier (Arg1, Name_On);
10655             Check_Arg_Is_Local_Name (Arg1);
10656
10657             Arg := Get_Pragma_Arg (Arg1);
10658             Analyze (Arg);
10659
10660             if Etype (Arg) = Any_Type then
10661                return;
10662             end if;
10663
10664             if not Is_Entity_Name (Arg)
10665               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10666             then
10667                Error_Pragma_Arg
10668                  ("pragma% requires a local enumeration type", Arg1);
10669             end if;
10670
10671             Set_Discard_Names (Entity (Arg), False);
10672          end Keep_Names;
10673
10674          -------------
10675          -- License --
10676          -------------
10677
10678          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10679
10680          when Pragma_License =>
10681             GNAT_Pragma;
10682             Check_Arg_Count (1);
10683             Check_No_Identifiers;
10684             Check_Valid_Configuration_Pragma;
10685             Check_Arg_Is_Identifier (Arg1);
10686
10687             declare
10688                Sind : constant Source_File_Index :=
10689                         Source_Index (Current_Sem_Unit);
10690
10691             begin
10692                case Chars (Get_Pragma_Arg (Arg1)) is
10693                   when Name_GPL =>
10694                      Set_License (Sind, GPL);
10695
10696                   when Name_Modified_GPL =>
10697                      Set_License (Sind, Modified_GPL);
10698
10699                   when Name_Restricted =>
10700                      Set_License (Sind, Restricted);
10701
10702                   when Name_Unrestricted =>
10703                      Set_License (Sind, Unrestricted);
10704
10705                   when others =>
10706                      Error_Pragma_Arg ("invalid license name", Arg1);
10707                end case;
10708             end;
10709
10710          ---------------
10711          -- Link_With --
10712          ---------------
10713
10714          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10715
10716          when Pragma_Link_With => Link_With : declare
10717             Arg : Node_Id;
10718
10719          begin
10720             GNAT_Pragma;
10721
10722             if Operating_Mode = Generate_Code
10723               and then In_Extended_Main_Source_Unit (N)
10724             then
10725                Check_At_Least_N_Arguments (1);
10726                Check_No_Identifiers;
10727                Check_Is_In_Decl_Part_Or_Package_Spec;
10728                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10729                Start_String;
10730
10731                Arg := Arg1;
10732                while Present (Arg) loop
10733                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10734
10735                   --  Store argument, converting sequences of spaces to a
10736                   --  single null character (this is one of the differences
10737                   --  in processing between Link_With and Linker_Options).
10738
10739                   Arg_Store : declare
10740                      C : constant Char_Code := Get_Char_Code (' ');
10741                      S : constant String_Id :=
10742                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10743                      L : constant Nat := String_Length (S);
10744                      F : Nat := 1;
10745
10746                      procedure Skip_Spaces;
10747                      --  Advance F past any spaces
10748
10749                      -----------------
10750                      -- Skip_Spaces --
10751                      -----------------
10752
10753                      procedure Skip_Spaces is
10754                      begin
10755                         while F <= L and then Get_String_Char (S, F) = C loop
10756                            F := F + 1;
10757                         end loop;
10758                      end Skip_Spaces;
10759
10760                   --  Start of processing for Arg_Store
10761
10762                   begin
10763                      Skip_Spaces; -- skip leading spaces
10764
10765                      --  Loop through characters, changing any embedded
10766                      --  sequence of spaces to a single null character (this
10767                      --  is how Link_With/Linker_Options differ)
10768
10769                      while F <= L loop
10770                         if Get_String_Char (S, F) = C then
10771                            Skip_Spaces;
10772                            exit when F > L;
10773                            Store_String_Char (ASCII.NUL);
10774
10775                         else
10776                            Store_String_Char (Get_String_Char (S, F));
10777                            F := F + 1;
10778                         end if;
10779                      end loop;
10780                   end Arg_Store;
10781
10782                   Arg := Next (Arg);
10783
10784                   if Present (Arg) then
10785                      Store_String_Char (ASCII.NUL);
10786                   end if;
10787                end loop;
10788
10789                Store_Linker_Option_String (End_String);
10790             end if;
10791          end Link_With;
10792
10793          ------------------
10794          -- Linker_Alias --
10795          ------------------
10796
10797          --  pragma Linker_Alias (
10798          --      [Entity =>]  LOCAL_NAME
10799          --      [Target =>]  static_string_EXPRESSION);
10800
10801          when Pragma_Linker_Alias =>
10802             GNAT_Pragma;
10803             Check_Arg_Order ((Name_Entity, Name_Target));
10804             Check_Arg_Count (2);
10805             Check_Optional_Identifier (Arg1, Name_Entity);
10806             Check_Optional_Identifier (Arg2, Name_Target);
10807             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10808             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10809
10810             --  The only processing required is to link this item on to the
10811             --  list of rep items for the given entity. This is accomplished
10812             --  by the call to Rep_Item_Too_Late (when no error is detected
10813             --  and False is returned).
10814
10815             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10816                return;
10817             else
10818                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10819             end if;
10820
10821          ------------------------
10822          -- Linker_Constructor --
10823          ------------------------
10824
10825          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10826
10827          --  Code is shared with Linker_Destructor
10828
10829          -----------------------
10830          -- Linker_Destructor --
10831          -----------------------
10832
10833          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10834
10835          when Pragma_Linker_Constructor |
10836               Pragma_Linker_Destructor =>
10837          Linker_Constructor : declare
10838             Arg1_X : Node_Id;
10839             Proc   : Entity_Id;
10840
10841          begin
10842             GNAT_Pragma;
10843             Check_Arg_Count (1);
10844             Check_No_Identifiers;
10845             Check_Arg_Is_Local_Name (Arg1);
10846             Arg1_X := Get_Pragma_Arg (Arg1);
10847             Analyze (Arg1_X);
10848             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10849
10850             if not Is_Library_Level_Entity (Proc) then
10851                Error_Pragma_Arg
10852                 ("argument for pragma% must be library level entity", Arg1);
10853             end if;
10854
10855             --  The only processing required is to link this item on to the
10856             --  list of rep items for the given entity. This is accomplished
10857             --  by the call to Rep_Item_Too_Late (when no error is detected
10858             --  and False is returned).
10859
10860             if Rep_Item_Too_Late (Proc, N) then
10861                return;
10862             else
10863                Set_Has_Gigi_Rep_Item (Proc);
10864             end if;
10865          end Linker_Constructor;
10866
10867          --------------------
10868          -- Linker_Options --
10869          --------------------
10870
10871          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10872
10873          when Pragma_Linker_Options => Linker_Options : declare
10874             Arg : Node_Id;
10875
10876          begin
10877             Check_Ada_83_Warning;
10878             Check_No_Identifiers;
10879             Check_Arg_Count (1);
10880             Check_Is_In_Decl_Part_Or_Package_Spec;
10881             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10882             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10883
10884             Arg := Arg2;
10885             while Present (Arg) loop
10886                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10887                Store_String_Char (ASCII.NUL);
10888                Store_String_Chars
10889                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10890                Arg := Next (Arg);
10891             end loop;
10892
10893             if Operating_Mode = Generate_Code
10894               and then In_Extended_Main_Source_Unit (N)
10895             then
10896                Store_Linker_Option_String (End_String);
10897             end if;
10898          end Linker_Options;
10899
10900          --------------------
10901          -- Linker_Section --
10902          --------------------
10903
10904          --  pragma Linker_Section (
10905          --      [Entity  =>]  LOCAL_NAME
10906          --      [Section =>]  static_string_EXPRESSION);
10907
10908          when Pragma_Linker_Section =>
10909             GNAT_Pragma;
10910             Check_Arg_Order ((Name_Entity, Name_Section));
10911             Check_Arg_Count (2);
10912             Check_Optional_Identifier (Arg1, Name_Entity);
10913             Check_Optional_Identifier (Arg2, Name_Section);
10914             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10915             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10916
10917             --  This pragma applies only to objects
10918
10919             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10920                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10921             end if;
10922
10923             --  The only processing required is to link this item on to the
10924             --  list of rep items for the given entity. This is accomplished
10925             --  by the call to Rep_Item_Too_Late (when no error is detected
10926             --  and False is returned).
10927
10928             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10929                return;
10930             else
10931                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10932             end if;
10933
10934          ----------
10935          -- List --
10936          ----------
10937
10938          --  pragma List (On | Off)
10939
10940          --  There is nothing to do here, since we did all the processing for
10941          --  this pragma in Par.Prag (so that it works properly even in syntax
10942          --  only mode).
10943
10944          when Pragma_List =>
10945             null;
10946
10947          --------------------
10948          -- Locking_Policy --
10949          --------------------
10950
10951          --  pragma Locking_Policy (policy_IDENTIFIER);
10952
10953          when Pragma_Locking_Policy => declare
10954             subtype LP_Range is Name_Id
10955               range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
10956             LP_Val : LP_Range;
10957             LP     : Character;
10958          begin
10959             Check_Ada_83_Warning;
10960             Check_Arg_Count (1);
10961             Check_No_Identifiers;
10962             Check_Arg_Is_Locking_Policy (Arg1);
10963             Check_Valid_Configuration_Pragma;
10964             LP_Val := Chars (Get_Pragma_Arg (Arg1));
10965
10966             case LP_Val is
10967                when Name_Ceiling_Locking            => LP := 'C';
10968                when Name_Inheritance_Locking        => LP := 'I';
10969                when Name_Concurrent_Readers_Locking => LP := 'R';
10970             end case;
10971
10972             if Locking_Policy /= ' '
10973               and then Locking_Policy /= LP
10974             then
10975                Error_Msg_Sloc := Locking_Policy_Sloc;
10976                Error_Pragma ("locking policy incompatible with policy#");
10977
10978             --  Set new policy, but always preserve System_Location since we
10979             --  like the error message with the run time name.
10980
10981             else
10982                Locking_Policy := LP;
10983
10984                if Locking_Policy_Sloc /= System_Location then
10985                   Locking_Policy_Sloc := Loc;
10986                end if;
10987             end if;
10988          end;
10989
10990          ----------------
10991          -- Long_Float --
10992          ----------------
10993
10994          --  pragma Long_Float (D_Float | G_Float);
10995
10996          when Pragma_Long_Float => Long_Float : declare
10997          begin
10998             GNAT_Pragma;
10999             Check_Valid_Configuration_Pragma;
11000             Check_Arg_Count (1);
11001             Check_No_Identifier (Arg1);
11002             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
11003
11004             if not OpenVMS_On_Target then
11005                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
11006             end if;
11007
11008             --  D_Float case
11009
11010             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
11011                if Opt.Float_Format_Long = 'G' then
11012                   Error_Pragma_Arg
11013                     ("G_Float previously specified", Arg1);
11014
11015                elsif Current_Sem_Unit /= Main_Unit
11016                  and then Opt.Float_Format_Long /= 'D'
11017                then
11018                   Error_Pragma_Arg
11019                     ("main unit not compiled with pragma Long_Float (D_Float)",
11020                      "\pragma% must be used consistently for whole partition",
11021                      Arg1);
11022
11023                else
11024                   Opt.Float_Format_Long := 'D';
11025                end if;
11026
11027             --  G_Float case (this is the default, does not need overriding)
11028
11029             else
11030                if Opt.Float_Format_Long = 'D' then
11031                   Error_Pragma ("D_Float previously specified");
11032
11033                elsif Current_Sem_Unit /= Main_Unit
11034                  and then Opt.Float_Format_Long /= 'G'
11035                then
11036                   Error_Pragma_Arg
11037                     ("main unit not compiled with pragma Long_Float (G_Float)",
11038                      "\pragma% must be used consistently for whole partition",
11039                      Arg1);
11040
11041                else
11042                   Opt.Float_Format_Long := 'G';
11043                end if;
11044             end if;
11045
11046             Set_Standard_Fpt_Formats;
11047          end Long_Float;
11048
11049          -----------------------
11050          -- Machine_Attribute --
11051          -----------------------
11052
11053          --  pragma Machine_Attribute (
11054          --       [Entity         =>] LOCAL_NAME,
11055          --       [Attribute_Name =>] static_string_EXPRESSION
11056          --    [, [Info           =>] static_EXPRESSION] );
11057
11058          when Pragma_Machine_Attribute => Machine_Attribute : declare
11059             Def_Id : Entity_Id;
11060
11061          begin
11062             GNAT_Pragma;
11063             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
11064
11065             if Arg_Count = 3 then
11066                Check_Optional_Identifier (Arg3, Name_Info);
11067                Check_Arg_Is_Static_Expression (Arg3);
11068             else
11069                Check_Arg_Count (2);
11070             end if;
11071
11072             Check_Optional_Identifier (Arg1, Name_Entity);
11073             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
11074             Check_Arg_Is_Local_Name (Arg1);
11075             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11076             Def_Id := Entity (Get_Pragma_Arg (Arg1));
11077
11078             if Is_Access_Type (Def_Id) then
11079                Def_Id := Designated_Type (Def_Id);
11080             end if;
11081
11082             if Rep_Item_Too_Early (Def_Id, N) then
11083                return;
11084             end if;
11085
11086             Def_Id := Underlying_Type (Def_Id);
11087
11088             --  The only processing required is to link this item on to the
11089             --  list of rep items for the given entity. This is accomplished
11090             --  by the call to Rep_Item_Too_Late (when no error is detected
11091             --  and False is returned).
11092
11093             if Rep_Item_Too_Late (Def_Id, N) then
11094                return;
11095             else
11096                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
11097             end if;
11098          end Machine_Attribute;
11099
11100          ----------
11101          -- Main --
11102          ----------
11103
11104          --  pragma Main
11105          --   (MAIN_OPTION [, MAIN_OPTION]);
11106
11107          --  MAIN_OPTION ::=
11108          --    [STACK_SIZE              =>] static_integer_EXPRESSION
11109          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
11110          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
11111
11112          when Pragma_Main => Main : declare
11113             Args  : Args_List (1 .. 3);
11114             Names : constant Name_List (1 .. 3) := (
11115                       Name_Stack_Size,
11116                       Name_Task_Stack_Size_Default,
11117                       Name_Time_Slicing_Enabled);
11118
11119             Nod : Node_Id;
11120
11121          begin
11122             GNAT_Pragma;
11123             Gather_Associations (Names, Args);
11124
11125             for J in 1 .. 2 loop
11126                if Present (Args (J)) then
11127                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11128                end if;
11129             end loop;
11130
11131             if Present (Args (3)) then
11132                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11133             end if;
11134
11135             Nod := Next (N);
11136             while Present (Nod) loop
11137                if Nkind (Nod) = N_Pragma
11138                  and then Pragma_Name (Nod) = Name_Main
11139                then
11140                   Error_Msg_Name_1 := Pname;
11141                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11142                end if;
11143
11144                Next (Nod);
11145             end loop;
11146          end Main;
11147
11148          ------------------
11149          -- Main_Storage --
11150          ------------------
11151
11152          --  pragma Main_Storage
11153          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11154
11155          --  MAIN_STORAGE_OPTION ::=
11156          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11157          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11158
11159          when Pragma_Main_Storage => Main_Storage : declare
11160             Args  : Args_List (1 .. 2);
11161             Names : constant Name_List (1 .. 2) := (
11162                       Name_Working_Storage,
11163                       Name_Top_Guard);
11164
11165             Nod : Node_Id;
11166
11167          begin
11168             GNAT_Pragma;
11169             Gather_Associations (Names, Args);
11170
11171             for J in 1 .. 2 loop
11172                if Present (Args (J)) then
11173                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11174                end if;
11175             end loop;
11176
11177             Check_In_Main_Program;
11178
11179             Nod := Next (N);
11180             while Present (Nod) loop
11181                if Nkind (Nod) = N_Pragma
11182                  and then Pragma_Name (Nod) = Name_Main_Storage
11183                then
11184                   Error_Msg_Name_1 := Pname;
11185                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11186                end if;
11187
11188                Next (Nod);
11189             end loop;
11190          end Main_Storage;
11191
11192          -----------------
11193          -- Memory_Size --
11194          -----------------
11195
11196          --  pragma Memory_Size (NUMERIC_LITERAL)
11197
11198          when Pragma_Memory_Size =>
11199             GNAT_Pragma;
11200
11201             --  Memory size is simply ignored
11202
11203             Check_No_Identifiers;
11204             Check_Arg_Count (1);
11205             Check_Arg_Is_Integer_Literal (Arg1);
11206
11207          -------------
11208          -- No_Body --
11209          -------------
11210
11211          --  pragma No_Body;
11212
11213          --  The only correct use of this pragma is on its own in a file, in
11214          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
11215          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11216          --  check for a file containing nothing but a No_Body pragma). If we
11217          --  attempt to process it during normal semantics processing, it means
11218          --  it was misplaced.
11219
11220          when Pragma_No_Body =>
11221             GNAT_Pragma;
11222             Pragma_Misplaced;
11223
11224          ---------------
11225          -- No_Return --
11226          ---------------
11227
11228          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11229
11230          when Pragma_No_Return => No_Return : declare
11231             Id    : Node_Id;
11232             E     : Entity_Id;
11233             Found : Boolean;
11234             Arg   : Node_Id;
11235
11236          begin
11237             Ada_2005_Pragma;
11238             Check_At_Least_N_Arguments (1);
11239
11240             --  Loop through arguments of pragma
11241
11242             Arg := Arg1;
11243             while Present (Arg) loop
11244                Check_Arg_Is_Local_Name (Arg);
11245                Id := Get_Pragma_Arg (Arg);
11246                Analyze (Id);
11247
11248                if not Is_Entity_Name (Id) then
11249                   Error_Pragma_Arg ("entity name required", Arg);
11250                end if;
11251
11252                if Etype (Id) = Any_Type then
11253                   raise Pragma_Exit;
11254                end if;
11255
11256                --  Loop to find matching procedures
11257
11258                E := Entity (Id);
11259                Found := False;
11260                while Present (E)
11261                  and then Scope (E) = Current_Scope
11262                loop
11263                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11264                      Set_No_Return (E);
11265
11266                      --  Set flag on any alias as well
11267
11268                      if Is_Overloadable (E) and then Present (Alias (E)) then
11269                         Set_No_Return (Alias (E));
11270                      end if;
11271
11272                      Found := True;
11273                   end if;
11274
11275                   exit when From_Aspect_Specification (N);
11276                   E := Homonym (E);
11277                end loop;
11278
11279                if not Found then
11280                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11281                end if;
11282
11283                Next (Arg);
11284             end loop;
11285          end No_Return;
11286
11287          -----------------
11288          -- No_Run_Time --
11289          -----------------
11290
11291          --  pragma No_Run_Time;
11292
11293          --  Note: this pragma is retained for backwards compatibility. See
11294          --  body of Rtsfind for full details on its handling.
11295
11296          when Pragma_No_Run_Time =>
11297             GNAT_Pragma;
11298             Check_Valid_Configuration_Pragma;
11299             Check_Arg_Count (0);
11300
11301             No_Run_Time_Mode           := True;
11302             Configurable_Run_Time_Mode := True;
11303
11304             --  Set Duration to 32 bits if word size is 32
11305
11306             if Ttypes.System_Word_Size = 32 then
11307                Duration_32_Bits_On_Target := True;
11308             end if;
11309
11310             --  Set appropriate restrictions
11311
11312             Set_Restriction (No_Finalization, N);
11313             Set_Restriction (No_Exception_Handlers, N);
11314             Set_Restriction (Max_Tasks, N, 0);
11315             Set_Restriction (No_Tasking, N);
11316
11317          ------------------------
11318          -- No_Strict_Aliasing --
11319          ------------------------
11320
11321          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11322
11323          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11324             E_Id : Entity_Id;
11325
11326          begin
11327             GNAT_Pragma;
11328             Check_At_Most_N_Arguments (1);
11329
11330             if Arg_Count = 0 then
11331                Check_Valid_Configuration_Pragma;
11332                Opt.No_Strict_Aliasing := True;
11333
11334             else
11335                Check_Optional_Identifier (Arg2, Name_Entity);
11336                Check_Arg_Is_Local_Name (Arg1);
11337                E_Id := Entity (Get_Pragma_Arg (Arg1));
11338
11339                if E_Id = Any_Type then
11340                   return;
11341                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11342                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
11343                end if;
11344
11345                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11346             end if;
11347          end No_Strict_Aliasing;
11348
11349          -----------------------
11350          -- Normalize_Scalars --
11351          -----------------------
11352
11353          --  pragma Normalize_Scalars;
11354
11355          when Pragma_Normalize_Scalars =>
11356             Check_Ada_83_Warning;
11357             Check_Arg_Count (0);
11358             Check_Valid_Configuration_Pragma;
11359
11360             --  Normalize_Scalars creates false positives in CodePeer, and
11361             --  incorrect negative results in Alfa mode, so ignore this pragma
11362             --  in these modes.
11363
11364             if not (CodePeer_Mode or Alfa_Mode) then
11365                Normalize_Scalars := True;
11366                Init_Or_Norm_Scalars := True;
11367             end if;
11368
11369          -----------------
11370          -- Obsolescent --
11371          -----------------
11372
11373          --  pragma Obsolescent;
11374
11375          --  pragma Obsolescent (
11376          --    [Message =>] static_string_EXPRESSION
11377          --  [,[Version =>] Ada_05]]);
11378
11379          --  pragma Obsolescent (
11380          --    [Entity  =>] NAME
11381          --  [,[Message =>] static_string_EXPRESSION
11382          --  [,[Version =>] Ada_05]] );
11383
11384          when Pragma_Obsolescent => Obsolescent : declare
11385             Ename : Node_Id;
11386             Decl  : Node_Id;
11387
11388             procedure Set_Obsolescent (E : Entity_Id);
11389             --  Given an entity Ent, mark it as obsolescent if appropriate
11390
11391             ---------------------
11392             -- Set_Obsolescent --
11393             ---------------------
11394
11395             procedure Set_Obsolescent (E : Entity_Id) is
11396                Active : Boolean;
11397                Ent    : Entity_Id;
11398                S      : String_Id;
11399
11400             begin
11401                Active := True;
11402                Ent    := E;
11403
11404                --  Entity name was given
11405
11406                if Present (Ename) then
11407
11408                   --  If entity name matches, we are fine. Save entity in
11409                   --  pragma argument, for ASIS use.
11410
11411                   if Chars (Ename) = Chars (Ent) then
11412                      Set_Entity (Ename, Ent);
11413                      Generate_Reference (Ent, Ename);
11414
11415                   --  If entity name does not match, only possibility is an
11416                   --  enumeration literal from an enumeration type declaration.
11417
11418                   elsif Ekind (Ent) /= E_Enumeration_Type then
11419                      Error_Pragma
11420                        ("pragma % entity name does not match declaration");
11421
11422                   else
11423                      Ent := First_Literal (E);
11424                      loop
11425                         if No (Ent) then
11426                            Error_Pragma
11427                              ("pragma % entity name does not match any " &
11428                               "enumeration literal");
11429
11430                         elsif Chars (Ent) = Chars (Ename) then
11431                            Set_Entity (Ename, Ent);
11432                            Generate_Reference (Ent, Ename);
11433                            exit;
11434
11435                         else
11436                            Ent := Next_Literal (Ent);
11437                         end if;
11438                      end loop;
11439                   end if;
11440                end if;
11441
11442                --  Ent points to entity to be marked
11443
11444                if Arg_Count >= 1 then
11445
11446                   --  Deal with static string argument
11447
11448                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11449                   S := Strval (Get_Pragma_Arg (Arg1));
11450
11451                   for J in 1 .. String_Length (S) loop
11452                      if not In_Character_Range (Get_String_Char (S, J)) then
11453                         Error_Pragma_Arg
11454                           ("pragma% argument does not allow wide characters",
11455                            Arg1);
11456                      end if;
11457                   end loop;
11458
11459                   Obsolescent_Warnings.Append
11460                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11461
11462                   --  Check for Ada_05 parameter
11463
11464                   if Arg_Count /= 1 then
11465                      Check_Arg_Count (2);
11466
11467                      declare
11468                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11469
11470                      begin
11471                         Check_Arg_Is_Identifier (Argx);
11472
11473                         if Chars (Argx) /= Name_Ada_05 then
11474                            Error_Msg_Name_2 := Name_Ada_05;
11475                            Error_Pragma_Arg
11476                              ("only allowed argument for pragma% is %", Argx);
11477                         end if;
11478
11479                         if Ada_Version_Explicit < Ada_2005
11480                           or else not Warn_On_Ada_2005_Compatibility
11481                         then
11482                            Active := False;
11483                         end if;
11484                      end;
11485                   end if;
11486                end if;
11487
11488                --  Set flag if pragma active
11489
11490                if Active then
11491                   Set_Is_Obsolescent (Ent);
11492                end if;
11493
11494                return;
11495             end Set_Obsolescent;
11496
11497          --  Start of processing for pragma Obsolescent
11498
11499          begin
11500             GNAT_Pragma;
11501
11502             Check_At_Most_N_Arguments (3);
11503
11504             --  See if first argument specifies an entity name
11505
11506             if Arg_Count >= 1
11507               and then
11508                 (Chars (Arg1) = Name_Entity
11509                    or else
11510                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11511                                                       N_Identifier,
11512                                                       N_Operator_Symbol))
11513             then
11514                Ename := Get_Pragma_Arg (Arg1);
11515
11516                --  Eliminate first argument, so we can share processing
11517
11518                Arg1 := Arg2;
11519                Arg2 := Arg3;
11520                Arg_Count := Arg_Count - 1;
11521
11522             --  No Entity name argument given
11523
11524             else
11525                Ename := Empty;
11526             end if;
11527
11528             if Arg_Count >= 1 then
11529                Check_Optional_Identifier (Arg1, Name_Message);
11530
11531                if Arg_Count = 2 then
11532                   Check_Optional_Identifier (Arg2, Name_Version);
11533                end if;
11534             end if;
11535
11536             --  Get immediately preceding declaration
11537
11538             Decl := Prev (N);
11539             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11540                Prev (Decl);
11541             end loop;
11542
11543             --  Cases where we do not follow anything other than another pragma
11544
11545             if No (Decl) then
11546
11547                --  First case: library level compilation unit declaration with
11548                --  the pragma immediately following the declaration.
11549
11550                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11551                   Set_Obsolescent
11552                     (Defining_Entity (Unit (Parent (Parent (N)))));
11553                   return;
11554
11555                --  Case 2: library unit placement for package
11556
11557                else
11558                   declare
11559                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11560                   begin
11561                      if Is_Package_Or_Generic_Package (Ent) then
11562                         Set_Obsolescent (Ent);
11563                         return;
11564                      end if;
11565                   end;
11566                end if;
11567
11568             --  Cases where we must follow a declaration
11569
11570             else
11571                if         Nkind (Decl) not in N_Declaration
11572                  and then Nkind (Decl) not in N_Later_Decl_Item
11573                  and then Nkind (Decl) not in N_Generic_Declaration
11574                  and then Nkind (Decl) not in N_Renaming_Declaration
11575                then
11576                   Error_Pragma
11577                     ("pragma% misplaced, "
11578                      & "must immediately follow a declaration");
11579
11580                else
11581                   Set_Obsolescent (Defining_Entity (Decl));
11582                   return;
11583                end if;
11584             end if;
11585          end Obsolescent;
11586
11587          --------------
11588          -- Optimize --
11589          --------------
11590
11591          --  pragma Optimize (Time | Space | Off);
11592
11593          --  The actual check for optimize is done in Gigi. Note that this
11594          --  pragma does not actually change the optimization setting, it
11595          --  simply checks that it is consistent with the pragma.
11596
11597          when Pragma_Optimize =>
11598             Check_No_Identifiers;
11599             Check_Arg_Count (1);
11600             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11601
11602          ------------------------
11603          -- Optimize_Alignment --
11604          ------------------------
11605
11606          --  pragma Optimize_Alignment (Time | Space | Off);
11607
11608          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11609             GNAT_Pragma;
11610             Check_No_Identifiers;
11611             Check_Arg_Count (1);
11612             Check_Valid_Configuration_Pragma;
11613
11614             declare
11615                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11616             begin
11617                case Nam is
11618                   when Name_Time =>
11619                      Opt.Optimize_Alignment := 'T';
11620                   when Name_Space =>
11621                      Opt.Optimize_Alignment := 'S';
11622                   when Name_Off =>
11623                      Opt.Optimize_Alignment := 'O';
11624                   when others =>
11625                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11626                end case;
11627             end;
11628
11629             --  Set indication that mode is set locally. If we are in fact in a
11630             --  configuration pragma file, this setting is harmless since the
11631             --  switch will get reset anyway at the start of each unit.
11632
11633             Optimize_Alignment_Local := True;
11634          end Optimize_Alignment;
11635
11636          -------------
11637          -- Ordered --
11638          -------------
11639
11640          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11641
11642          when Pragma_Ordered => Ordered : declare
11643             Assoc   : constant Node_Id := Arg1;
11644             Type_Id : Node_Id;
11645             Typ     : Entity_Id;
11646
11647          begin
11648             GNAT_Pragma;
11649             Check_No_Identifiers;
11650             Check_Arg_Count (1);
11651             Check_Arg_Is_Local_Name (Arg1);
11652
11653             Type_Id := Get_Pragma_Arg (Assoc);
11654             Find_Type (Type_Id);
11655             Typ := Entity (Type_Id);
11656
11657             if Typ = Any_Type then
11658                return;
11659             else
11660                Typ := Underlying_Type (Typ);
11661             end if;
11662
11663             if not Is_Enumeration_Type (Typ) then
11664                Error_Pragma ("pragma% must specify enumeration type");
11665             end if;
11666
11667             Check_First_Subtype (Arg1);
11668             Set_Has_Pragma_Ordered (Base_Type (Typ));
11669          end Ordered;
11670
11671          ----------
11672          -- Pack --
11673          ----------
11674
11675          --  pragma Pack (first_subtype_LOCAL_NAME);
11676
11677          when Pragma_Pack => Pack : declare
11678             Assoc   : constant Node_Id := Arg1;
11679             Type_Id : Node_Id;
11680             Typ     : Entity_Id;
11681             Ctyp    : Entity_Id;
11682             Ignore  : Boolean := False;
11683
11684          begin
11685             Check_No_Identifiers;
11686             Check_Arg_Count (1);
11687             Check_Arg_Is_Local_Name (Arg1);
11688
11689             Type_Id := Get_Pragma_Arg (Assoc);
11690             Find_Type (Type_Id);
11691             Typ := Entity (Type_Id);
11692
11693             if Typ = Any_Type
11694               or else Rep_Item_Too_Early (Typ, N)
11695             then
11696                return;
11697             else
11698                Typ := Underlying_Type (Typ);
11699             end if;
11700
11701             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11702                Error_Pragma ("pragma% must specify array or record type");
11703             end if;
11704
11705             Check_First_Subtype (Arg1);
11706             Check_Duplicate_Pragma (Typ);
11707
11708             --  Array type
11709
11710             if Is_Array_Type (Typ) then
11711                Ctyp := Component_Type (Typ);
11712
11713                --  Ignore pack that does nothing
11714
11715                if Known_Static_Esize (Ctyp)
11716                  and then Known_Static_RM_Size (Ctyp)
11717                  and then Esize (Ctyp) = RM_Size (Ctyp)
11718                  and then Addressable (Esize (Ctyp))
11719                then
11720                   Ignore := True;
11721                end if;
11722
11723                --  Process OK pragma Pack. Note that if there is a separate
11724                --  component clause present, the Pack will be cancelled. This
11725                --  processing is in Freeze.
11726
11727                if not Rep_Item_Too_Late (Typ, N) then
11728
11729                   --  In the context of static code analysis, we do not need
11730                   --  complex front-end expansions related to pragma Pack,
11731                   --  so disable handling of pragma Pack in these cases.
11732
11733                   if CodePeer_Mode or Alfa_Mode then
11734                      null;
11735
11736                   --  Don't attempt any packing for VM targets. We possibly
11737                   --  could deal with some cases of array bit-packing, but we
11738                   --  don't bother, since this is not a typical kind of
11739                   --  representation in the VM context anyway (and would not
11740                   --  for example work nicely with the debugger).
11741
11742                   elsif VM_Target /= No_VM then
11743                      if not GNAT_Mode then
11744                         Error_Pragma
11745                           ("?pragma% ignored in this configuration");
11746                      end if;
11747
11748                   --  Normal case where we do the pack action
11749
11750                   else
11751                      if not Ignore then
11752                         Set_Is_Packed            (Base_Type (Typ));
11753                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11754                      end if;
11755
11756                      Set_Has_Pragma_Pack (Base_Type (Typ));
11757                   end if;
11758                end if;
11759
11760             --  For record types, the pack is always effective
11761
11762             else pragma Assert (Is_Record_Type (Typ));
11763                if not Rep_Item_Too_Late (Typ, N) then
11764
11765                   --  Ignore pack request with warning in VM mode (skip warning
11766                   --  if we are compiling GNAT run time library).
11767
11768                   if VM_Target /= No_VM then
11769                      if not GNAT_Mode then
11770                         Error_Pragma
11771                           ("?pragma% ignored in this configuration");
11772                      end if;
11773
11774                   --  Normal case of pack request active
11775
11776                   else
11777                      Set_Is_Packed            (Base_Type (Typ));
11778                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11779                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11780                   end if;
11781                end if;
11782             end if;
11783          end Pack;
11784
11785          ----------
11786          -- Page --
11787          ----------
11788
11789          --  pragma Page;
11790
11791          --  There is nothing to do here, since we did all the processing for
11792          --  this pragma in Par.Prag (so that it works properly even in syntax
11793          --  only mode).
11794
11795          when Pragma_Page =>
11796             null;
11797
11798          -------------
11799          -- Passive --
11800          -------------
11801
11802          --  pragma Passive [(PASSIVE_FORM)];
11803
11804          --  PASSIVE_FORM ::= Semaphore | No
11805
11806          when Pragma_Passive =>
11807             GNAT_Pragma;
11808
11809             if Nkind (Parent (N)) /= N_Task_Definition then
11810                Error_Pragma ("pragma% must be within task definition");
11811             end if;
11812
11813             if Arg_Count /= 0 then
11814                Check_Arg_Count (1);
11815                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11816             end if;
11817
11818          ----------------------------------
11819          -- Preelaborable_Initialization --
11820          ----------------------------------
11821
11822          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11823
11824          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11825             Ent : Entity_Id;
11826
11827          begin
11828             Ada_2005_Pragma;
11829             Check_Arg_Count (1);
11830             Check_No_Identifiers;
11831             Check_Arg_Is_Identifier (Arg1);
11832             Check_Arg_Is_Local_Name (Arg1);
11833             Check_First_Subtype (Arg1);
11834             Ent := Entity (Get_Pragma_Arg (Arg1));
11835
11836             if not (Is_Private_Type (Ent)
11837                       or else
11838                     Is_Protected_Type (Ent)
11839                       or else
11840                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11841             then
11842                Error_Pragma_Arg
11843                  ("pragma % can only be applied to private, formal derived or "
11844                   & "protected type",
11845                   Arg1);
11846             end if;
11847
11848             --  Give an error if the pragma is applied to a protected type that
11849             --  does not qualify (due to having entries, or due to components
11850             --  that do not qualify).
11851
11852             if Is_Protected_Type (Ent)
11853               and then not Has_Preelaborable_Initialization (Ent)
11854             then
11855                Error_Msg_N
11856                  ("protected type & does not have preelaborable " &
11857                   "initialization", Ent);
11858
11859             --  Otherwise mark the type as definitely having preelaborable
11860             --  initialization.
11861
11862             else
11863                Set_Known_To_Have_Preelab_Init (Ent);
11864             end if;
11865
11866             if Has_Pragma_Preelab_Init (Ent)
11867               and then Warn_On_Redundant_Constructs
11868             then
11869                Error_Pragma ("?duplicate pragma%!");
11870             else
11871                Set_Has_Pragma_Preelab_Init (Ent);
11872             end if;
11873          end Preelab_Init;
11874
11875          --------------------
11876          -- Persistent_BSS --
11877          --------------------
11878
11879          --  pragma Persistent_BSS [(object_NAME)];
11880
11881          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11882             Decl : Node_Id;
11883             Ent  : Entity_Id;
11884             Prag : Node_Id;
11885
11886          begin
11887             GNAT_Pragma;
11888             Check_At_Most_N_Arguments (1);
11889
11890             --  Case of application to specific object (one argument)
11891
11892             if Arg_Count = 1 then
11893                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11894
11895                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11896                  or else not
11897                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11898                                                             E_Constant)
11899                then
11900                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11901                end if;
11902
11903                Ent := Entity (Get_Pragma_Arg (Arg1));
11904                Decl := Parent (Ent);
11905
11906                if Rep_Item_Too_Late (Ent, N) then
11907                   return;
11908                end if;
11909
11910                if Present (Expression (Decl)) then
11911                   Error_Pragma_Arg
11912                     ("object for pragma% cannot have initialization", Arg1);
11913                end if;
11914
11915                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11916                   Error_Pragma_Arg
11917                     ("object type for pragma% is not potentially persistent",
11918                      Arg1);
11919                end if;
11920
11921                Check_Duplicate_Pragma (Ent);
11922
11923                Prag :=
11924                  Make_Linker_Section_Pragma
11925                    (Ent, Sloc (N), ".persistent.bss");
11926                Insert_After (N, Prag);
11927                Analyze (Prag);
11928
11929             --  Case of use as configuration pragma with no arguments
11930
11931             else
11932                Check_Valid_Configuration_Pragma;
11933                Persistent_BSS_Mode := True;
11934             end if;
11935          end Persistent_BSS;
11936
11937          -------------
11938          -- Polling --
11939          -------------
11940
11941          --  pragma Polling (ON | OFF);
11942
11943          when Pragma_Polling =>
11944             GNAT_Pragma;
11945             Check_Arg_Count (1);
11946             Check_No_Identifiers;
11947             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11948             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11949
11950          -------------------
11951          -- Postcondition --
11952          -------------------
11953
11954          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11955          --                      [,[Message =>] String_EXPRESSION]);
11956
11957          when Pragma_Postcondition => Postcondition : declare
11958             In_Body : Boolean;
11959             pragma Warnings (Off, In_Body);
11960
11961          begin
11962             GNAT_Pragma;
11963             Check_At_Least_N_Arguments (1);
11964             Check_At_Most_N_Arguments (2);
11965             Check_Optional_Identifier (Arg1, Name_Check);
11966
11967             --  All we need to do here is call the common check procedure,
11968             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11969
11970             Check_Precondition_Postcondition (In_Body);
11971          end Postcondition;
11972
11973          ------------------
11974          -- Precondition --
11975          ------------------
11976
11977          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11978          --                     [,[Message =>] String_EXPRESSION]);
11979
11980          when Pragma_Precondition => Precondition : declare
11981             In_Body : Boolean;
11982
11983          begin
11984             GNAT_Pragma;
11985             Check_At_Least_N_Arguments (1);
11986             Check_At_Most_N_Arguments (2);
11987             Check_Optional_Identifier (Arg1, Name_Check);
11988             Check_Precondition_Postcondition (In_Body);
11989
11990             --  If in spec, nothing more to do. If in body, then we convert the
11991             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11992             --  this whether or not precondition checks are enabled. That works
11993             --  fine since pragma Check will do this check, and will also
11994             --  analyze the condition itself in the proper context.
11995
11996             if In_Body then
11997                Rewrite (N,
11998                  Make_Pragma (Loc,
11999                    Chars => Name_Check,
12000                    Pragma_Argument_Associations => New_List (
12001                      Make_Pragma_Argument_Association (Loc,
12002                        Expression => Make_Identifier (Loc, Name_Precondition)),
12003
12004                      Make_Pragma_Argument_Association (Sloc (Arg1),
12005                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
12006
12007                if Arg_Count = 2 then
12008                   Append_To (Pragma_Argument_Associations (N),
12009                     Make_Pragma_Argument_Association (Sloc (Arg2),
12010                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
12011                end if;
12012
12013                Analyze (N);
12014             end if;
12015          end Precondition;
12016
12017          ---------------
12018          -- Predicate --
12019          ---------------
12020
12021          --  pragma Predicate
12022          --    ([Entity =>] type_LOCAL_NAME,
12023          --     [Check  =>] EXPRESSION);
12024
12025          when Pragma_Predicate => Predicate : declare
12026             Type_Id : Node_Id;
12027             Typ     : Entity_Id;
12028
12029             Discard : Boolean;
12030             pragma Unreferenced (Discard);
12031
12032          begin
12033             GNAT_Pragma;
12034             Check_Arg_Count (2);
12035             Check_Optional_Identifier (Arg1, Name_Entity);
12036             Check_Optional_Identifier (Arg2, Name_Check);
12037
12038             Check_Arg_Is_Local_Name (Arg1);
12039
12040             Type_Id := Get_Pragma_Arg (Arg1);
12041             Find_Type (Type_Id);
12042             Typ := Entity (Type_Id);
12043
12044             if Typ = Any_Type then
12045                return;
12046             end if;
12047
12048             --  The remaining processing is simply to link the pragma on to
12049             --  the rep item chain, for processing when the type is frozen.
12050             --  This is accomplished by a call to Rep_Item_Too_Late. We also
12051             --  mark the type as having predicates.
12052
12053             Set_Has_Predicates (Typ);
12054             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
12055          end Predicate;
12056
12057          ------------------
12058          -- Preelaborate --
12059          ------------------
12060
12061          --  pragma Preelaborate [(library_unit_NAME)];
12062
12063          --  Set the flag Is_Preelaborated of program unit name entity
12064
12065          when Pragma_Preelaborate => Preelaborate : declare
12066             Pa  : constant Node_Id   := Parent (N);
12067             Pk  : constant Node_Kind := Nkind (Pa);
12068             Ent : Entity_Id;
12069
12070          begin
12071             Check_Ada_83_Warning;
12072             Check_Valid_Library_Unit_Pragma;
12073
12074             if Nkind (N) = N_Null_Statement then
12075                return;
12076             end if;
12077
12078             Ent := Find_Lib_Unit_Name;
12079             Check_Duplicate_Pragma (Ent);
12080
12081             --  This filters out pragmas inside generic parent then
12082             --  show up inside instantiation
12083
12084             if Present (Ent)
12085               and then not (Pk = N_Package_Specification
12086                              and then Present (Generic_Parent (Pa)))
12087             then
12088                if not Debug_Flag_U then
12089                   Set_Is_Preelaborated (Ent);
12090                   Set_Suppress_Elaboration_Warnings (Ent);
12091                end if;
12092             end if;
12093          end Preelaborate;
12094
12095          ---------------------
12096          -- Preelaborate_05 --
12097          ---------------------
12098
12099          --  pragma Preelaborate_05 [(library_unit_NAME)];
12100
12101          --  This pragma is useable only in GNAT_Mode, where it is used like
12102          --  pragma Preelaborate but it is only effective in Ada 2005 mode
12103          --  (otherwise it is ignored). This is used to implement AI-362 which
12104          --  recategorizes some run-time packages in Ada 2005 mode.
12105
12106          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
12107             Ent : Entity_Id;
12108
12109          begin
12110             GNAT_Pragma;
12111             Check_Valid_Library_Unit_Pragma;
12112
12113             if not GNAT_Mode then
12114                Error_Pragma ("pragma% only available in GNAT mode");
12115             end if;
12116
12117             if Nkind (N) = N_Null_Statement then
12118                return;
12119             end if;
12120
12121             --  This is one of the few cases where we need to test the value of
12122             --  Ada_Version_Explicit rather than Ada_Version (which is always
12123             --  set to Ada_2012 in a predefined unit), we need to know the
12124             --  explicit version set to know if this pragma is active.
12125
12126             if Ada_Version_Explicit >= Ada_2005 then
12127                Ent := Find_Lib_Unit_Name;
12128                Set_Is_Preelaborated (Ent);
12129                Set_Suppress_Elaboration_Warnings (Ent);
12130             end if;
12131          end Preelaborate_05;
12132
12133          --------------
12134          -- Priority --
12135          --------------
12136
12137          --  pragma Priority (EXPRESSION);
12138
12139          when Pragma_Priority => Priority : declare
12140             P   : constant Node_Id := Parent (N);
12141             Arg : Node_Id;
12142
12143          begin
12144             Check_No_Identifiers;
12145             Check_Arg_Count (1);
12146
12147             --  Subprogram case
12148
12149             if Nkind (P) = N_Subprogram_Body then
12150                Check_In_Main_Program;
12151
12152                Arg := Get_Pragma_Arg (Arg1);
12153                Analyze_And_Resolve (Arg, Standard_Integer);
12154
12155                --  Must be static
12156
12157                if not Is_Static_Expression (Arg) then
12158                   Flag_Non_Static_Expr
12159                     ("main subprogram priority is not static!", Arg);
12160                   raise Pragma_Exit;
12161
12162                --  If constraint error, then we already signalled an error
12163
12164                elsif Raises_Constraint_Error (Arg) then
12165                   null;
12166
12167                --  Otherwise check in range
12168
12169                else
12170                   declare
12171                      Val : constant Uint := Expr_Value (Arg);
12172
12173                   begin
12174                      if Val < 0
12175                        or else Val > Expr_Value (Expression
12176                                        (Parent (RTE (RE_Max_Priority))))
12177                      then
12178                         Error_Pragma_Arg
12179                           ("main subprogram priority is out of range", Arg1);
12180                      end if;
12181                   end;
12182                end if;
12183
12184                Set_Main_Priority
12185                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12186
12187                --  Load an arbitrary entity from System.Tasking to make sure
12188                --  this package is implicitly with'ed, since we need to have
12189                --  the tasking run-time active for the pragma Priority to have
12190                --  any effect.
12191
12192                declare
12193                   Discard : Entity_Id;
12194                   pragma Warnings (Off, Discard);
12195                begin
12196                   Discard := RTE (RE_Task_List);
12197                end;
12198
12199             --  Task or Protected, must be of type Integer
12200
12201             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12202                Arg := Get_Pragma_Arg (Arg1);
12203
12204                --  The expression must be analyzed in the special manner
12205                --  described in "Handling of Default and Per-Object
12206                --  Expressions" in sem.ads.
12207
12208                Preanalyze_Spec_Expression (Arg, Standard_Integer);
12209
12210                if not Is_Static_Expression (Arg) then
12211                   Check_Restriction (Static_Priorities, Arg);
12212                end if;
12213
12214             --  Anything else is incorrect
12215
12216             else
12217                Pragma_Misplaced;
12218             end if;
12219
12220             if Has_Pragma_Priority (P) then
12221                Error_Pragma ("duplicate pragma% not allowed");
12222             else
12223                Set_Has_Pragma_Priority (P, True);
12224
12225                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12226                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12227                   --  exp_ch9 should use this ???
12228                end if;
12229             end if;
12230          end Priority;
12231
12232          -----------------------------------
12233          -- Priority_Specific_Dispatching --
12234          -----------------------------------
12235
12236          --  pragma Priority_Specific_Dispatching (
12237          --    policy_IDENTIFIER,
12238          --    first_priority_EXPRESSION,
12239          --    last_priority_EXPRESSION);
12240
12241          when Pragma_Priority_Specific_Dispatching =>
12242          Priority_Specific_Dispatching : declare
12243             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12244             --  This is the entity System.Any_Priority;
12245
12246             DP          : Character;
12247             Lower_Bound : Node_Id;
12248             Upper_Bound : Node_Id;
12249             Lower_Val   : Uint;
12250             Upper_Val   : Uint;
12251
12252          begin
12253             Ada_2005_Pragma;
12254             Check_Arg_Count (3);
12255             Check_No_Identifiers;
12256             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12257             Check_Valid_Configuration_Pragma;
12258             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12259             DP := Fold_Upper (Name_Buffer (1));
12260
12261             Lower_Bound := Get_Pragma_Arg (Arg2);
12262             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12263             Lower_Val := Expr_Value (Lower_Bound);
12264
12265             Upper_Bound := Get_Pragma_Arg (Arg3);
12266             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12267             Upper_Val := Expr_Value (Upper_Bound);
12268
12269             --  It is not allowed to use Task_Dispatching_Policy and
12270             --  Priority_Specific_Dispatching in the same partition.
12271
12272             if Task_Dispatching_Policy /= ' ' then
12273                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12274                Error_Pragma
12275                  ("pragma% incompatible with Task_Dispatching_Policy#");
12276
12277             --  Check lower bound in range
12278
12279             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12280                     or else
12281                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12282             then
12283                Error_Pragma_Arg
12284                  ("first_priority is out of range", Arg2);
12285
12286             --  Check upper bound in range
12287
12288             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12289                     or else
12290                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12291             then
12292                Error_Pragma_Arg
12293                  ("last_priority is out of range", Arg3);
12294
12295             --  Check that the priority range is valid
12296
12297             elsif Lower_Val > Upper_Val then
12298                Error_Pragma
12299                  ("last_priority_expression must be greater than" &
12300                   " or equal to first_priority_expression");
12301
12302             --  Store the new policy, but always preserve System_Location since
12303             --  we like the error message with the run-time name.
12304
12305             else
12306                --  Check overlapping in the priority ranges specified in other
12307                --  Priority_Specific_Dispatching pragmas within the same
12308                --  partition. We can only check those we know about!
12309
12310                for J in
12311                   Specific_Dispatching.First .. Specific_Dispatching.Last
12312                loop
12313                   if Specific_Dispatching.Table (J).First_Priority in
12314                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12315                   or else Specific_Dispatching.Table (J).Last_Priority in
12316                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12317                   then
12318                      Error_Msg_Sloc :=
12319                        Specific_Dispatching.Table (J).Pragma_Loc;
12320                         Error_Pragma
12321                           ("priority range overlaps with "
12322                            & "Priority_Specific_Dispatching#");
12323                   end if;
12324                end loop;
12325
12326                --  The use of Priority_Specific_Dispatching is incompatible
12327                --  with Task_Dispatching_Policy.
12328
12329                if Task_Dispatching_Policy /= ' ' then
12330                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12331                      Error_Pragma
12332                        ("Priority_Specific_Dispatching incompatible "
12333                         & "with Task_Dispatching_Policy#");
12334                end if;
12335
12336                --  The use of Priority_Specific_Dispatching forces ceiling
12337                --  locking policy.
12338
12339                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12340                   Error_Msg_Sloc := Locking_Policy_Sloc;
12341                      Error_Pragma
12342                        ("Priority_Specific_Dispatching incompatible "
12343                         & "with Locking_Policy#");
12344
12345                --  Set the Ceiling_Locking policy, but preserve System_Location
12346                --  since we like the error message with the run time name.
12347
12348                else
12349                   Locking_Policy := 'C';
12350
12351                   if Locking_Policy_Sloc /= System_Location then
12352                      Locking_Policy_Sloc := Loc;
12353                   end if;
12354                end if;
12355
12356                --  Add entry in the table
12357
12358                Specific_Dispatching.Append
12359                     ((Dispatching_Policy => DP,
12360                       First_Priority     => UI_To_Int (Lower_Val),
12361                       Last_Priority      => UI_To_Int (Upper_Val),
12362                       Pragma_Loc         => Loc));
12363             end if;
12364          end Priority_Specific_Dispatching;
12365
12366          -------------
12367          -- Profile --
12368          -------------
12369
12370          --  pragma Profile (profile_IDENTIFIER);
12371
12372          --  profile_IDENTIFIER => Restricted | Ravenscar
12373
12374          when Pragma_Profile =>
12375             Ada_2005_Pragma;
12376             Check_Arg_Count (1);
12377             Check_Valid_Configuration_Pragma;
12378             Check_No_Identifiers;
12379
12380             declare
12381                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12382
12383             begin
12384                if Chars (Argx) = Name_Ravenscar then
12385                   Set_Ravenscar_Profile (N);
12386
12387                elsif Chars (Argx) = Name_Restricted then
12388                   Set_Profile_Restrictions
12389                     (Restricted,
12390                      N, Warn => Treat_Restrictions_As_Warnings);
12391
12392                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12393                   Set_Profile_Restrictions
12394                     (No_Implementation_Extensions,
12395                      N, Warn => Treat_Restrictions_As_Warnings);
12396
12397                else
12398                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12399                end if;
12400             end;
12401
12402          ----------------------
12403          -- Profile_Warnings --
12404          ----------------------
12405
12406          --  pragma Profile_Warnings (profile_IDENTIFIER);
12407
12408          --  profile_IDENTIFIER => Restricted | Ravenscar
12409
12410          when Pragma_Profile_Warnings =>
12411             GNAT_Pragma;
12412             Check_Arg_Count (1);
12413             Check_Valid_Configuration_Pragma;
12414             Check_No_Identifiers;
12415
12416             declare
12417                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12418
12419             begin
12420                if Chars (Argx) = Name_Ravenscar then
12421                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12422
12423                elsif Chars (Argx) = Name_Restricted then
12424                   Set_Profile_Restrictions (Restricted, N, Warn => True);
12425
12426                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12427                   Set_Profile_Restrictions
12428                     (No_Implementation_Extensions, N, Warn => True);
12429
12430                else
12431                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12432                end if;
12433             end;
12434
12435          --------------------------
12436          -- Propagate_Exceptions --
12437          --------------------------
12438
12439          --  pragma Propagate_Exceptions;
12440
12441          --  Note: this pragma is obsolete and has no effect
12442
12443          when Pragma_Propagate_Exceptions =>
12444             GNAT_Pragma;
12445             Check_Arg_Count (0);
12446
12447             if In_Extended_Main_Source_Unit (N) then
12448                Propagate_Exceptions := True;
12449             end if;
12450
12451          ------------------
12452          -- Psect_Object --
12453          ------------------
12454
12455          --  pragma Psect_Object (
12456          --        [Internal =>] LOCAL_NAME,
12457          --     [, [External =>] EXTERNAL_SYMBOL]
12458          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12459
12460          when Pragma_Psect_Object | Pragma_Common_Object =>
12461          Psect_Object : declare
12462             Args  : Args_List (1 .. 3);
12463             Names : constant Name_List (1 .. 3) := (
12464                       Name_Internal,
12465                       Name_External,
12466                       Name_Size);
12467
12468             Internal : Node_Id renames Args (1);
12469             External : Node_Id renames Args (2);
12470             Size     : Node_Id renames Args (3);
12471
12472             Def_Id : Entity_Id;
12473
12474             procedure Check_Too_Long (Arg : Node_Id);
12475             --  Posts message if the argument is an identifier with more
12476             --  than 31 characters, or a string literal with more than
12477             --  31 characters, and we are operating under VMS
12478
12479             --------------------
12480             -- Check_Too_Long --
12481             --------------------
12482
12483             procedure Check_Too_Long (Arg : Node_Id) is
12484                X : constant Node_Id := Original_Node (Arg);
12485
12486             begin
12487                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12488                   Error_Pragma_Arg
12489                     ("inappropriate argument for pragma %", Arg);
12490                end if;
12491
12492                if OpenVMS_On_Target then
12493                   if (Nkind (X) = N_String_Literal
12494                        and then String_Length (Strval (X)) > 31)
12495                     or else
12496                      (Nkind (X) = N_Identifier
12497                        and then Length_Of_Name (Chars (X)) > 31)
12498                   then
12499                      Error_Pragma_Arg
12500                        ("argument for pragma % is longer than 31 characters",
12501                         Arg);
12502                   end if;
12503                end if;
12504             end Check_Too_Long;
12505
12506          --  Start of processing for Common_Object/Psect_Object
12507
12508          begin
12509             GNAT_Pragma;
12510             Gather_Associations (Names, Args);
12511             Process_Extended_Import_Export_Internal_Arg (Internal);
12512
12513             Def_Id := Entity (Internal);
12514
12515             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12516                Error_Pragma_Arg
12517                  ("pragma% must designate an object", Internal);
12518             end if;
12519
12520             Check_Too_Long (Internal);
12521
12522             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12523                Error_Pragma_Arg
12524                  ("cannot use pragma% for imported/exported object",
12525                   Internal);
12526             end if;
12527
12528             if Is_Concurrent_Type (Etype (Internal)) then
12529                Error_Pragma_Arg
12530                  ("cannot specify pragma % for task/protected object",
12531                   Internal);
12532             end if;
12533
12534             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12535                  or else
12536                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12537             then
12538                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12539             end if;
12540
12541             if Ekind (Def_Id) = E_Constant then
12542                Error_Pragma_Arg
12543                  ("cannot specify pragma % for a constant", Internal);
12544             end if;
12545
12546             if Is_Record_Type (Etype (Internal)) then
12547                declare
12548                   Ent  : Entity_Id;
12549                   Decl : Entity_Id;
12550
12551                begin
12552                   Ent := First_Entity (Etype (Internal));
12553                   while Present (Ent) loop
12554                      Decl := Declaration_Node (Ent);
12555
12556                      if Ekind (Ent) = E_Component
12557                        and then Nkind (Decl) = N_Component_Declaration
12558                        and then Present (Expression (Decl))
12559                        and then Warn_On_Export_Import
12560                      then
12561                         Error_Msg_N
12562                           ("?object for pragma % has defaults", Internal);
12563                         exit;
12564
12565                      else
12566                         Next_Entity (Ent);
12567                      end if;
12568                   end loop;
12569                end;
12570             end if;
12571
12572             if Present (Size) then
12573                Check_Too_Long (Size);
12574             end if;
12575
12576             if Present (External) then
12577                Check_Arg_Is_External_Name (External);
12578                Check_Too_Long (External);
12579             end if;
12580
12581             --  If all error tests pass, link pragma on to the rep item chain
12582
12583             Record_Rep_Item (Def_Id, N);
12584          end Psect_Object;
12585
12586          ----------
12587          -- Pure --
12588          ----------
12589
12590          --  pragma Pure [(library_unit_NAME)];
12591
12592          when Pragma_Pure => Pure : declare
12593             Ent : Entity_Id;
12594
12595          begin
12596             Check_Ada_83_Warning;
12597             Check_Valid_Library_Unit_Pragma;
12598
12599             if Nkind (N) = N_Null_Statement then
12600                return;
12601             end if;
12602
12603             Ent := Find_Lib_Unit_Name;
12604             Set_Is_Pure (Ent);
12605             Set_Has_Pragma_Pure (Ent);
12606             Set_Suppress_Elaboration_Warnings (Ent);
12607          end Pure;
12608
12609          -------------
12610          -- Pure_05 --
12611          -------------
12612
12613          --  pragma Pure_05 [(library_unit_NAME)];
12614
12615          --  This pragma is useable only in GNAT_Mode, where it is used like
12616          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12617          --  it is ignored). It may be used after a pragma Preelaborate, in
12618          --  which case it overrides the effect of the pragma Preelaborate.
12619          --  This is used to implement AI-362 which recategorizes some run-time
12620          --  packages in Ada 2005 mode.
12621
12622          when Pragma_Pure_05 => Pure_05 : declare
12623             Ent : Entity_Id;
12624
12625          begin
12626             GNAT_Pragma;
12627             Check_Valid_Library_Unit_Pragma;
12628
12629             if not GNAT_Mode then
12630                Error_Pragma ("pragma% only available in GNAT mode");
12631             end if;
12632
12633             if Nkind (N) = N_Null_Statement then
12634                return;
12635             end if;
12636
12637             --  This is one of the few cases where we need to test the value of
12638             --  Ada_Version_Explicit rather than Ada_Version (which is always
12639             --  set to Ada_2012 in a predefined unit), we need to know the
12640             --  explicit version set to know if this pragma is active.
12641
12642             if Ada_Version_Explicit >= Ada_2005 then
12643                Ent := Find_Lib_Unit_Name;
12644                Set_Is_Preelaborated (Ent, False);
12645                Set_Is_Pure (Ent);
12646                Set_Suppress_Elaboration_Warnings (Ent);
12647             end if;
12648          end Pure_05;
12649
12650          -------------------
12651          -- Pure_Function --
12652          -------------------
12653
12654          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12655
12656          when Pragma_Pure_Function => Pure_Function : declare
12657             E_Id      : Node_Id;
12658             E         : Entity_Id;
12659             Def_Id    : Entity_Id;
12660             Effective : Boolean := False;
12661
12662          begin
12663             GNAT_Pragma;
12664             Check_Arg_Count (1);
12665             Check_Optional_Identifier (Arg1, Name_Entity);
12666             Check_Arg_Is_Local_Name (Arg1);
12667             E_Id := Get_Pragma_Arg (Arg1);
12668
12669             if Error_Posted (E_Id) then
12670                return;
12671             end if;
12672
12673             --  Loop through homonyms (overloadings) of referenced entity
12674
12675             E := Entity (E_Id);
12676
12677             if Present (E) then
12678                loop
12679                   Def_Id := Get_Base_Subprogram (E);
12680
12681                   if not Ekind_In (Def_Id, E_Function,
12682                                            E_Generic_Function,
12683                                            E_Operator)
12684                   then
12685                      Error_Pragma_Arg
12686                        ("pragma% requires a function name", Arg1);
12687                   end if;
12688
12689                   Set_Is_Pure (Def_Id);
12690
12691                   if not Has_Pragma_Pure_Function (Def_Id) then
12692                      Set_Has_Pragma_Pure_Function (Def_Id);
12693                      Effective := True;
12694                   end if;
12695
12696                   exit when From_Aspect_Specification (N);
12697                   E := Homonym (E);
12698                   exit when No (E) or else Scope (E) /= Current_Scope;
12699                end loop;
12700
12701                if not Effective
12702                  and then Warn_On_Redundant_Constructs
12703                then
12704                   Error_Msg_NE
12705                     ("pragma Pure_Function on& is redundant?",
12706                      N, Entity (E_Id));
12707                end if;
12708             end if;
12709          end Pure_Function;
12710
12711          --------------------
12712          -- Queuing_Policy --
12713          --------------------
12714
12715          --  pragma Queuing_Policy (policy_IDENTIFIER);
12716
12717          when Pragma_Queuing_Policy => declare
12718             QP : Character;
12719
12720          begin
12721             Check_Ada_83_Warning;
12722             Check_Arg_Count (1);
12723             Check_No_Identifiers;
12724             Check_Arg_Is_Queuing_Policy (Arg1);
12725             Check_Valid_Configuration_Pragma;
12726             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12727             QP := Fold_Upper (Name_Buffer (1));
12728
12729             if Queuing_Policy /= ' '
12730               and then Queuing_Policy /= QP
12731             then
12732                Error_Msg_Sloc := Queuing_Policy_Sloc;
12733                Error_Pragma ("queuing policy incompatible with policy#");
12734
12735             --  Set new policy, but always preserve System_Location since we
12736             --  like the error message with the run time name.
12737
12738             else
12739                Queuing_Policy := QP;
12740
12741                if Queuing_Policy_Sloc /= System_Location then
12742                   Queuing_Policy_Sloc := Loc;
12743                end if;
12744             end if;
12745          end;
12746
12747          -----------------------
12748          -- Relative_Deadline --
12749          -----------------------
12750
12751          --  pragma Relative_Deadline (time_span_EXPRESSION);
12752
12753          when Pragma_Relative_Deadline => Relative_Deadline : declare
12754             P   : constant Node_Id := Parent (N);
12755             Arg : Node_Id;
12756
12757          begin
12758             Ada_2005_Pragma;
12759             Check_No_Identifiers;
12760             Check_Arg_Count (1);
12761
12762             Arg := Get_Pragma_Arg (Arg1);
12763
12764             --  The expression must be analyzed in the special manner described
12765             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12766
12767             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12768
12769             --  Subprogram case
12770
12771             if Nkind (P) = N_Subprogram_Body then
12772                Check_In_Main_Program;
12773
12774             --  Tasks
12775
12776             elsif Nkind (P) = N_Task_Definition then
12777                null;
12778
12779             --  Anything else is incorrect
12780
12781             else
12782                Pragma_Misplaced;
12783             end if;
12784
12785             if Has_Relative_Deadline_Pragma (P) then
12786                Error_Pragma ("duplicate pragma% not allowed");
12787             else
12788                Set_Has_Relative_Deadline_Pragma (P, True);
12789
12790                if Nkind (P) = N_Task_Definition then
12791                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12792                end if;
12793             end if;
12794          end Relative_Deadline;
12795
12796          ---------------------------
12797          -- Remote_Call_Interface --
12798          ---------------------------
12799
12800          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12801
12802          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12803             Cunit_Node : Node_Id;
12804             Cunit_Ent  : Entity_Id;
12805             K          : Node_Kind;
12806
12807          begin
12808             Check_Ada_83_Warning;
12809             Check_Valid_Library_Unit_Pragma;
12810
12811             if Nkind (N) = N_Null_Statement then
12812                return;
12813             end if;
12814
12815             Cunit_Node := Cunit (Current_Sem_Unit);
12816             K          := Nkind (Unit (Cunit_Node));
12817             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12818
12819             if K = N_Package_Declaration
12820               or else K = N_Generic_Package_Declaration
12821               or else K = N_Subprogram_Declaration
12822               or else K = N_Generic_Subprogram_Declaration
12823               or else (K = N_Subprogram_Body
12824                          and then Acts_As_Spec (Unit (Cunit_Node)))
12825             then
12826                null;
12827             else
12828                Error_Pragma (
12829                  "pragma% must apply to package or subprogram declaration");
12830             end if;
12831
12832             Set_Is_Remote_Call_Interface (Cunit_Ent);
12833          end Remote_Call_Interface;
12834
12835          ------------------
12836          -- Remote_Types --
12837          ------------------
12838
12839          --  pragma Remote_Types [(library_unit_NAME)];
12840
12841          when Pragma_Remote_Types => Remote_Types : declare
12842             Cunit_Node : Node_Id;
12843             Cunit_Ent  : Entity_Id;
12844
12845          begin
12846             Check_Ada_83_Warning;
12847             Check_Valid_Library_Unit_Pragma;
12848
12849             if Nkind (N) = N_Null_Statement then
12850                return;
12851             end if;
12852
12853             Cunit_Node := Cunit (Current_Sem_Unit);
12854             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12855
12856             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12857                                                 N_Generic_Package_Declaration)
12858             then
12859                Error_Pragma
12860                  ("pragma% can only apply to a package declaration");
12861             end if;
12862
12863             Set_Is_Remote_Types (Cunit_Ent);
12864          end Remote_Types;
12865
12866          ---------------
12867          -- Ravenscar --
12868          ---------------
12869
12870          --  pragma Ravenscar;
12871
12872          when Pragma_Ravenscar =>
12873             GNAT_Pragma;
12874             Check_Arg_Count (0);
12875             Check_Valid_Configuration_Pragma;
12876             Set_Ravenscar_Profile (N);
12877
12878             if Warn_On_Obsolescent_Feature then
12879                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12880                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12881             end if;
12882
12883          -------------------------
12884          -- Restricted_Run_Time --
12885          -------------------------
12886
12887          --  pragma Restricted_Run_Time;
12888
12889          when Pragma_Restricted_Run_Time =>
12890             GNAT_Pragma;
12891             Check_Arg_Count (0);
12892             Check_Valid_Configuration_Pragma;
12893             Set_Profile_Restrictions
12894               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12895
12896             if Warn_On_Obsolescent_Feature then
12897                Error_Msg_N
12898                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12899                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12900             end if;
12901
12902          ------------------
12903          -- Restrictions --
12904          ------------------
12905
12906          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12907
12908          --  RESTRICTION ::=
12909          --    restriction_IDENTIFIER
12910          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12911
12912          when Pragma_Restrictions =>
12913             Process_Restrictions_Or_Restriction_Warnings
12914               (Warn => Treat_Restrictions_As_Warnings);
12915
12916          --------------------------
12917          -- Restriction_Warnings --
12918          --------------------------
12919
12920          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12921
12922          --  RESTRICTION ::=
12923          --    restriction_IDENTIFIER
12924          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12925
12926          when Pragma_Restriction_Warnings =>
12927             GNAT_Pragma;
12928             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12929
12930          ----------------
12931          -- Reviewable --
12932          ----------------
12933
12934          --  pragma Reviewable;
12935
12936          when Pragma_Reviewable =>
12937             Check_Ada_83_Warning;
12938             Check_Arg_Count (0);
12939
12940             --  Call dummy debugging function rv. This is done to assist front
12941             --  end debugging. By placing a Reviewable pragma in the source
12942             --  program, a breakpoint on rv catches this place in the source,
12943             --  allowing convenient stepping to the point of interest.
12944
12945             rv;
12946
12947          --------------------------
12948          -- Short_Circuit_And_Or --
12949          --------------------------
12950
12951          when Pragma_Short_Circuit_And_Or =>
12952             GNAT_Pragma;
12953             Check_Arg_Count (0);
12954             Check_Valid_Configuration_Pragma;
12955             Short_Circuit_And_Or := True;
12956
12957          -------------------
12958          -- Share_Generic --
12959          -------------------
12960
12961          --  pragma Share_Generic (NAME {, NAME});
12962
12963          when Pragma_Share_Generic =>
12964             GNAT_Pragma;
12965             Process_Generic_List;
12966
12967          ------------
12968          -- Shared --
12969          ------------
12970
12971          --  pragma Shared (LOCAL_NAME);
12972
12973          when Pragma_Shared =>
12974             GNAT_Pragma;
12975             Process_Atomic_Shared_Volatile;
12976
12977          --------------------
12978          -- Shared_Passive --
12979          --------------------
12980
12981          --  pragma Shared_Passive [(library_unit_NAME)];
12982
12983          --  Set the flag Is_Shared_Passive of program unit name entity
12984
12985          when Pragma_Shared_Passive => Shared_Passive : declare
12986             Cunit_Node : Node_Id;
12987             Cunit_Ent  : Entity_Id;
12988
12989          begin
12990             Check_Ada_83_Warning;
12991             Check_Valid_Library_Unit_Pragma;
12992
12993             if Nkind (N) = N_Null_Statement then
12994                return;
12995             end if;
12996
12997             Cunit_Node := Cunit (Current_Sem_Unit);
12998             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12999
13000             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
13001                                                 N_Generic_Package_Declaration)
13002             then
13003                Error_Pragma
13004                  ("pragma% can only apply to a package declaration");
13005             end if;
13006
13007             Set_Is_Shared_Passive (Cunit_Ent);
13008          end Shared_Passive;
13009
13010          -----------------------
13011          -- Short_Descriptors --
13012          -----------------------
13013
13014          --  pragma Short_Descriptors;
13015
13016          when Pragma_Short_Descriptors =>
13017             GNAT_Pragma;
13018             Check_Arg_Count (0);
13019             Check_Valid_Configuration_Pragma;
13020             Short_Descriptors := True;
13021
13022          ----------------------
13023          -- Source_File_Name --
13024          ----------------------
13025
13026          --  There are five forms for this pragma:
13027
13028          --  pragma Source_File_Name (
13029          --    [UNIT_NAME      =>] unit_NAME,
13030          --     BODY_FILE_NAME =>  STRING_LITERAL
13031          --    [, [INDEX =>] INTEGER_LITERAL]);
13032
13033          --  pragma Source_File_Name (
13034          --    [UNIT_NAME      =>] unit_NAME,
13035          --     SPEC_FILE_NAME =>  STRING_LITERAL
13036          --    [, [INDEX =>] INTEGER_LITERAL]);
13037
13038          --  pragma Source_File_Name (
13039          --     BODY_FILE_NAME  => STRING_LITERAL
13040          --  [, DOT_REPLACEMENT => STRING_LITERAL]
13041          --  [, CASING          => CASING_SPEC]);
13042
13043          --  pragma Source_File_Name (
13044          --     SPEC_FILE_NAME  => STRING_LITERAL
13045          --  [, DOT_REPLACEMENT => STRING_LITERAL]
13046          --  [, CASING          => CASING_SPEC]);
13047
13048          --  pragma Source_File_Name (
13049          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
13050          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
13051          --  [, CASING             => CASING_SPEC]);
13052
13053          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
13054
13055          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
13056          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
13057          --  only be used when no project file is used, while SFNP can only be
13058          --  used when a project file is used.
13059
13060          --  No processing here. Processing was completed during parsing, since
13061          --  we need to have file names set as early as possible. Units are
13062          --  loaded well before semantic processing starts.
13063
13064          --  The only processing we defer to this point is the check for
13065          --  correct placement.
13066
13067          when Pragma_Source_File_Name =>
13068             GNAT_Pragma;
13069             Check_Valid_Configuration_Pragma;
13070
13071          ------------------------------
13072          -- Source_File_Name_Project --
13073          ------------------------------
13074
13075          --  See Source_File_Name for syntax
13076
13077          --  No processing here. Processing was completed during parsing, since
13078          --  we need to have file names set as early as possible. Units are
13079          --  loaded well before semantic processing starts.
13080
13081          --  The only processing we defer to this point is the check for
13082          --  correct placement.
13083
13084          when Pragma_Source_File_Name_Project =>
13085             GNAT_Pragma;
13086             Check_Valid_Configuration_Pragma;
13087
13088             --  Check that a pragma Source_File_Name_Project is used only in a
13089             --  configuration pragmas file.
13090
13091             --  Pragmas Source_File_Name_Project should only be generated by
13092             --  the Project Manager in configuration pragmas files.
13093
13094             --  This is really an ugly test. It seems to depend on some
13095             --  accidental and undocumented property. At the very least it
13096             --  needs to be documented, but it would be better to have a
13097             --  clean way of testing if we are in a configuration file???
13098
13099             if Present (Parent (N)) then
13100                Error_Pragma
13101                  ("pragma% can only appear in a configuration pragmas file");
13102             end if;
13103
13104          ----------------------
13105          -- Source_Reference --
13106          ----------------------
13107
13108          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
13109
13110          --  Nothing to do, all processing completed in Par.Prag, since we need
13111          --  the information for possible parser messages that are output.
13112
13113          when Pragma_Source_Reference =>
13114             GNAT_Pragma;
13115
13116          --------------------------------
13117          -- Static_Elaboration_Desired --
13118          --------------------------------
13119
13120          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
13121
13122          when Pragma_Static_Elaboration_Desired =>
13123             GNAT_Pragma;
13124             Check_At_Most_N_Arguments (1);
13125
13126             if Is_Compilation_Unit (Current_Scope)
13127               and then Ekind (Current_Scope) = E_Package
13128             then
13129                Set_Static_Elaboration_Desired (Current_Scope, True);
13130             else
13131                Error_Pragma ("pragma% must apply to a library-level package");
13132             end if;
13133
13134          ------------------
13135          -- Storage_Size --
13136          ------------------
13137
13138          --  pragma Storage_Size (EXPRESSION);
13139
13140          when Pragma_Storage_Size => Storage_Size : declare
13141             P   : constant Node_Id := Parent (N);
13142             Arg : Node_Id;
13143
13144          begin
13145             Check_No_Identifiers;
13146             Check_Arg_Count (1);
13147
13148             --  The expression must be analyzed in the special manner described
13149             --  in "Handling of Default Expressions" in sem.ads.
13150
13151             Arg := Get_Pragma_Arg (Arg1);
13152             Preanalyze_Spec_Expression (Arg, Any_Integer);
13153
13154             if not Is_Static_Expression (Arg) then
13155                Check_Restriction (Static_Storage_Size, Arg);
13156             end if;
13157
13158             if Nkind (P) /= N_Task_Definition then
13159                Pragma_Misplaced;
13160                return;
13161
13162             else
13163                if Has_Storage_Size_Pragma (P) then
13164                   Error_Pragma ("duplicate pragma% not allowed");
13165                else
13166                   Set_Has_Storage_Size_Pragma (P, True);
13167                end if;
13168
13169                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13170                --  ???  exp_ch9 should use this!
13171             end if;
13172          end Storage_Size;
13173
13174          ------------------
13175          -- Storage_Unit --
13176          ------------------
13177
13178          --  pragma Storage_Unit (NUMERIC_LITERAL);
13179
13180          --  Only permitted argument is System'Storage_Unit value
13181
13182          when Pragma_Storage_Unit =>
13183             Check_No_Identifiers;
13184             Check_Arg_Count (1);
13185             Check_Arg_Is_Integer_Literal (Arg1);
13186
13187             if Intval (Get_Pragma_Arg (Arg1)) /=
13188               UI_From_Int (Ttypes.System_Storage_Unit)
13189             then
13190                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13191                Error_Pragma_Arg
13192                  ("the only allowed argument for pragma% is ^", Arg1);
13193             end if;
13194
13195          --------------------
13196          -- Stream_Convert --
13197          --------------------
13198
13199          --  pragma Stream_Convert (
13200          --    [Entity =>] type_LOCAL_NAME,
13201          --    [Read   =>] function_NAME,
13202          --    [Write  =>] function NAME);
13203
13204          when Pragma_Stream_Convert => Stream_Convert : declare
13205
13206             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13207             --  Check that the given argument is the name of a local function
13208             --  of one argument that is not overloaded earlier in the current
13209             --  local scope. A check is also made that the argument is a
13210             --  function with one parameter.
13211
13212             --------------------------------------
13213             -- Check_OK_Stream_Convert_Function --
13214             --------------------------------------
13215
13216             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13217                Ent : Entity_Id;
13218
13219             begin
13220                Check_Arg_Is_Local_Name (Arg);
13221                Ent := Entity (Get_Pragma_Arg (Arg));
13222
13223                if Has_Homonym (Ent) then
13224                   Error_Pragma_Arg
13225                     ("argument for pragma% may not be overloaded", Arg);
13226                end if;
13227
13228                if Ekind (Ent) /= E_Function
13229                  or else No (First_Formal (Ent))
13230                  or else Present (Next_Formal (First_Formal (Ent)))
13231                then
13232                   Error_Pragma_Arg
13233                     ("argument for pragma% must be" &
13234                      " function of one argument", Arg);
13235                end if;
13236             end Check_OK_Stream_Convert_Function;
13237
13238          --  Start of processing for Stream_Convert
13239
13240          begin
13241             GNAT_Pragma;
13242             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13243             Check_Arg_Count (3);
13244             Check_Optional_Identifier (Arg1, Name_Entity);
13245             Check_Optional_Identifier (Arg2, Name_Read);
13246             Check_Optional_Identifier (Arg3, Name_Write);
13247             Check_Arg_Is_Local_Name (Arg1);
13248             Check_OK_Stream_Convert_Function (Arg2);
13249             Check_OK_Stream_Convert_Function (Arg3);
13250
13251             declare
13252                Typ   : constant Entity_Id :=
13253                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13254                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13255                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13256
13257             begin
13258                Check_First_Subtype (Arg1);
13259
13260                --  Check for too early or too late. Note that we don't enforce
13261                --  the rule about primitive operations in this case, since, as
13262                --  is the case for explicit stream attributes themselves, these
13263                --  restrictions are not appropriate. Note that the chaining of
13264                --  the pragma by Rep_Item_Too_Late is actually the critical
13265                --  processing done for this pragma.
13266
13267                if Rep_Item_Too_Early (Typ, N)
13268                     or else
13269                   Rep_Item_Too_Late (Typ, N, FOnly => True)
13270                then
13271                   return;
13272                end if;
13273
13274                --  Return if previous error
13275
13276                if Etype (Typ) = Any_Type
13277                     or else
13278                   Etype (Read) = Any_Type
13279                     or else
13280                   Etype (Write) = Any_Type
13281                then
13282                   return;
13283                end if;
13284
13285                --  Error checks
13286
13287                if Underlying_Type (Etype (Read)) /= Typ then
13288                   Error_Pragma_Arg
13289                     ("incorrect return type for function&", Arg2);
13290                end if;
13291
13292                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13293                   Error_Pragma_Arg
13294                     ("incorrect parameter type for function&", Arg3);
13295                end if;
13296
13297                if Underlying_Type (Etype (First_Formal (Read))) /=
13298                   Underlying_Type (Etype (Write))
13299                then
13300                   Error_Pragma_Arg
13301                     ("result type of & does not match Read parameter type",
13302                      Arg3);
13303                end if;
13304             end;
13305          end Stream_Convert;
13306
13307          -------------------------
13308          -- Style_Checks (GNAT) --
13309          -------------------------
13310
13311          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13312
13313          --  This is processed by the parser since some of the style checks
13314          --  take place during source scanning and parsing. This means that
13315          --  we don't need to issue error messages here.
13316
13317          when Pragma_Style_Checks => Style_Checks : declare
13318             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13319             S  : String_Id;
13320             C  : Char_Code;
13321
13322          begin
13323             GNAT_Pragma;
13324             Check_No_Identifiers;
13325
13326             --  Two argument form
13327
13328             if Arg_Count = 2 then
13329                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13330
13331                declare
13332                   E_Id : Node_Id;
13333                   E    : Entity_Id;
13334
13335                begin
13336                   E_Id := Get_Pragma_Arg (Arg2);
13337                   Analyze (E_Id);
13338
13339                   if not Is_Entity_Name (E_Id) then
13340                      Error_Pragma_Arg
13341                        ("second argument of pragma% must be entity name",
13342                         Arg2);
13343                   end if;
13344
13345                   E := Entity (E_Id);
13346
13347                   if E = Any_Id then
13348                      return;
13349                   else
13350                      loop
13351                         Set_Suppress_Style_Checks (E,
13352                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13353                         exit when No (Homonym (E));
13354                         E := Homonym (E);
13355                      end loop;
13356                   end if;
13357                end;
13358
13359             --  One argument form
13360
13361             else
13362                Check_Arg_Count (1);
13363
13364                if Nkind (A) = N_String_Literal then
13365                   S   := Strval (A);
13366
13367                   declare
13368                      Slen    : constant Natural := Natural (String_Length (S));
13369                      Options : String (1 .. Slen);
13370                      J       : Natural;
13371
13372                   begin
13373                      J := 1;
13374                      loop
13375                         C := Get_String_Char (S, Int (J));
13376                         exit when not In_Character_Range (C);
13377                         Options (J) := Get_Character (C);
13378
13379                         --  If at end of string, set options. As per discussion
13380                         --  above, no need to check for errors, since we issued
13381                         --  them in the parser.
13382
13383                         if J = Slen then
13384                            Set_Style_Check_Options (Options);
13385                            exit;
13386                         end if;
13387
13388                         J := J + 1;
13389                      end loop;
13390                   end;
13391
13392                elsif Nkind (A) = N_Identifier then
13393                   if Chars (A) = Name_All_Checks then
13394                      if GNAT_Mode then
13395                         Set_GNAT_Style_Check_Options;
13396                      else
13397                         Set_Default_Style_Check_Options;
13398                      end if;
13399
13400                   elsif Chars (A) = Name_On then
13401                      Style_Check := True;
13402
13403                   elsif Chars (A) = Name_Off then
13404                      Style_Check := False;
13405                   end if;
13406                end if;
13407             end if;
13408          end Style_Checks;
13409
13410          --------------
13411          -- Subtitle --
13412          --------------
13413
13414          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13415
13416          when Pragma_Subtitle =>
13417             GNAT_Pragma;
13418             Check_Arg_Count (1);
13419             Check_Optional_Identifier (Arg1, Name_Subtitle);
13420             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13421             Store_Note (N);
13422
13423          --------------
13424          -- Suppress --
13425          --------------
13426
13427          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13428
13429          when Pragma_Suppress =>
13430             Process_Suppress_Unsuppress (True);
13431
13432          ------------------
13433          -- Suppress_All --
13434          ------------------
13435
13436          --  pragma Suppress_All;
13437
13438          --  The only check made here is that the pragma has no arguments.
13439          --  There are no placement rules, and the processing required (setting
13440          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
13441          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
13442          --  then creates and inserts a pragma Suppress (All_Checks).
13443
13444          when Pragma_Suppress_All =>
13445             GNAT_Pragma;
13446             Check_Arg_Count (0);
13447
13448          -------------------------
13449          -- Suppress_Debug_Info --
13450          -------------------------
13451
13452          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13453
13454          when Pragma_Suppress_Debug_Info =>
13455             GNAT_Pragma;
13456             Check_Arg_Count (1);
13457             Check_Optional_Identifier (Arg1, Name_Entity);
13458             Check_Arg_Is_Local_Name (Arg1);
13459             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13460
13461          ----------------------------------
13462          -- Suppress_Exception_Locations --
13463          ----------------------------------
13464
13465          --  pragma Suppress_Exception_Locations;
13466
13467          when Pragma_Suppress_Exception_Locations =>
13468             GNAT_Pragma;
13469             Check_Arg_Count (0);
13470             Check_Valid_Configuration_Pragma;
13471             Exception_Locations_Suppressed := True;
13472
13473          -----------------------------
13474          -- Suppress_Initialization --
13475          -----------------------------
13476
13477          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13478
13479          when Pragma_Suppress_Initialization => Suppress_Init : declare
13480             E_Id : Node_Id;
13481             E    : Entity_Id;
13482
13483          begin
13484             GNAT_Pragma;
13485             Check_Arg_Count (1);
13486             Check_Optional_Identifier (Arg1, Name_Entity);
13487             Check_Arg_Is_Local_Name (Arg1);
13488
13489             E_Id := Get_Pragma_Arg (Arg1);
13490
13491             if Etype (E_Id) = Any_Type then
13492                return;
13493             end if;
13494
13495             E := Entity (E_Id);
13496
13497             if not Is_Type (E) then
13498                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13499             end if;
13500
13501             if Rep_Item_Too_Early (E, N)
13502                  or else
13503                Rep_Item_Too_Late (E, N, FOnly => True)
13504             then
13505                return;
13506             end if;
13507
13508             --  For incomplete/private type, set flag on full view
13509
13510             if Is_Incomplete_Or_Private_Type (E) then
13511                if No (Full_View (Base_Type (E))) then
13512                   Error_Pragma_Arg
13513                     ("argument of pragma% cannot be an incomplete type", Arg1);
13514                else
13515                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13516                end if;
13517
13518             --  For first subtype, set flag on base type
13519
13520             elsif Is_First_Subtype (E) then
13521                Set_Suppress_Initialization (Base_Type (E));
13522
13523             --  For other than first subtype, set flag on subtype itself
13524
13525             else
13526                Set_Suppress_Initialization (E);
13527             end if;
13528          end Suppress_Init;
13529
13530          -----------------
13531          -- System_Name --
13532          -----------------
13533
13534          --  pragma System_Name (DIRECT_NAME);
13535
13536          --  Syntax check: one argument, which must be the identifier GNAT or
13537          --  the identifier GCC, no other identifiers are acceptable.
13538
13539          when Pragma_System_Name =>
13540             GNAT_Pragma;
13541             Check_No_Identifiers;
13542             Check_Arg_Count (1);
13543             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13544
13545          -----------------------------
13546          -- Task_Dispatching_Policy --
13547          -----------------------------
13548
13549          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13550
13551          when Pragma_Task_Dispatching_Policy => declare
13552             DP : Character;
13553
13554          begin
13555             Check_Ada_83_Warning;
13556             Check_Arg_Count (1);
13557             Check_No_Identifiers;
13558             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13559             Check_Valid_Configuration_Pragma;
13560             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13561             DP := Fold_Upper (Name_Buffer (1));
13562
13563             if Task_Dispatching_Policy /= ' '
13564               and then Task_Dispatching_Policy /= DP
13565             then
13566                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13567                Error_Pragma
13568                  ("task dispatching policy incompatible with policy#");
13569
13570             --  Set new policy, but always preserve System_Location since we
13571             --  like the error message with the run time name.
13572
13573             else
13574                Task_Dispatching_Policy := DP;
13575
13576                if Task_Dispatching_Policy_Sloc /= System_Location then
13577                   Task_Dispatching_Policy_Sloc := Loc;
13578                end if;
13579             end if;
13580          end;
13581
13582          ---------------
13583          -- Task_Info --
13584          ---------------
13585
13586          --  pragma Task_Info (EXPRESSION);
13587
13588          when Pragma_Task_Info => Task_Info : declare
13589             P : constant Node_Id := Parent (N);
13590
13591          begin
13592             GNAT_Pragma;
13593
13594             if Nkind (P) /= N_Task_Definition then
13595                Error_Pragma ("pragma% must appear in task definition");
13596             end if;
13597
13598             Check_No_Identifiers;
13599             Check_Arg_Count (1);
13600
13601             Analyze_And_Resolve
13602               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13603
13604             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13605                return;
13606             end if;
13607
13608             if Has_Task_Info_Pragma (P) then
13609                Error_Pragma ("duplicate pragma% not allowed");
13610             else
13611                Set_Has_Task_Info_Pragma (P, True);
13612             end if;
13613          end Task_Info;
13614
13615          ---------------
13616          -- Task_Name --
13617          ---------------
13618
13619          --  pragma Task_Name (string_EXPRESSION);
13620
13621          when Pragma_Task_Name => Task_Name : declare
13622             P   : constant Node_Id := Parent (N);
13623             Arg : Node_Id;
13624
13625          begin
13626             Check_No_Identifiers;
13627             Check_Arg_Count (1);
13628
13629             Arg := Get_Pragma_Arg (Arg1);
13630
13631             --  The expression is used in the call to Create_Task, and must be
13632             --  expanded there, not in the context of the current spec. It must
13633             --  however be analyzed to capture global references, in case it
13634             --  appears in a generic context.
13635
13636             Preanalyze_And_Resolve (Arg, Standard_String);
13637
13638             if Nkind (P) /= N_Task_Definition then
13639                Pragma_Misplaced;
13640             end if;
13641
13642             if Has_Task_Name_Pragma (P) then
13643                Error_Pragma ("duplicate pragma% not allowed");
13644             else
13645                Set_Has_Task_Name_Pragma (P, True);
13646                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13647             end if;
13648          end Task_Name;
13649
13650          ------------------
13651          -- Task_Storage --
13652          ------------------
13653
13654          --  pragma Task_Storage (
13655          --     [Task_Type =>] LOCAL_NAME,
13656          --     [Top_Guard =>] static_integer_EXPRESSION);
13657
13658          when Pragma_Task_Storage => Task_Storage : declare
13659             Args  : Args_List (1 .. 2);
13660             Names : constant Name_List (1 .. 2) := (
13661                       Name_Task_Type,
13662                       Name_Top_Guard);
13663
13664             Task_Type : Node_Id renames Args (1);
13665             Top_Guard : Node_Id renames Args (2);
13666
13667             Ent : Entity_Id;
13668
13669          begin
13670             GNAT_Pragma;
13671             Gather_Associations (Names, Args);
13672
13673             if No (Task_Type) then
13674                Error_Pragma
13675                  ("missing task_type argument for pragma%");
13676             end if;
13677
13678             Check_Arg_Is_Local_Name (Task_Type);
13679
13680             Ent := Entity (Task_Type);
13681
13682             if not Is_Task_Type (Ent) then
13683                Error_Pragma_Arg
13684                  ("argument for pragma% must be task type", Task_Type);
13685             end if;
13686
13687             if No (Top_Guard) then
13688                Error_Pragma_Arg
13689                  ("pragma% takes two arguments", Task_Type);
13690             else
13691                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13692             end if;
13693
13694             Check_First_Subtype (Task_Type);
13695
13696             if Rep_Item_Too_Late (Ent, N) then
13697                raise Pragma_Exit;
13698             end if;
13699          end Task_Storage;
13700
13701          ---------------
13702          -- Test_Case --
13703          ---------------
13704
13705          --  pragma Test_Case ([Name     =>] Static_String_EXPRESSION
13706          --                   ,[Mode     =>] MODE_TYPE
13707          --                  [, Requires =>  Boolean_EXPRESSION]
13708          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13709
13710          --  MODE_TYPE ::= Nominal | Robustness
13711
13712          when Pragma_Test_Case => Test_Case : declare
13713          begin
13714             GNAT_Pragma;
13715             Check_At_Least_N_Arguments (2);
13716             Check_At_Most_N_Arguments (4);
13717             Check_Arg_Order
13718                  ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13719
13720             Check_Optional_Identifier (Arg1, Name_Name);
13721             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13722
13723             --  In ASIS mode, for a pragma generated from a source aspect, also
13724             --  analyze the original aspect expression.
13725
13726             if ASIS_Mode
13727               and then Present (Corresponding_Aspect (N))
13728             then
13729                Check_Expr_Is_Static_Expression
13730                  (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
13731             end if;
13732
13733             Check_Optional_Identifier (Arg2, Name_Mode);
13734             Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13735
13736             if Arg_Count = 4 then
13737                Check_Identifier (Arg3, Name_Requires);
13738                Check_Identifier (Arg4, Name_Ensures);
13739
13740             elsif Arg_Count = 3 then
13741                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13742             end if;
13743
13744             Check_Test_Case;
13745          end Test_Case;
13746
13747          --------------------------
13748          -- Thread_Local_Storage --
13749          --------------------------
13750
13751          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13752
13753          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13754             Id : Node_Id;
13755             E  : Entity_Id;
13756
13757          begin
13758             GNAT_Pragma;
13759             Check_Arg_Count (1);
13760             Check_Optional_Identifier (Arg1, Name_Entity);
13761             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13762
13763             Id := Get_Pragma_Arg (Arg1);
13764             Analyze (Id);
13765
13766             if not Is_Entity_Name (Id)
13767               or else Ekind (Entity (Id)) /= E_Variable
13768             then
13769                Error_Pragma_Arg ("local variable name required", Arg1);
13770             end if;
13771
13772             E := Entity (Id);
13773
13774             if Rep_Item_Too_Early (E, N)
13775               or else Rep_Item_Too_Late (E, N)
13776             then
13777                raise Pragma_Exit;
13778             end if;
13779
13780             Set_Has_Pragma_Thread_Local_Storage (E);
13781             Set_Has_Gigi_Rep_Item (E);
13782          end Thread_Local_Storage;
13783
13784          ----------------
13785          -- Time_Slice --
13786          ----------------
13787
13788          --  pragma Time_Slice (static_duration_EXPRESSION);
13789
13790          when Pragma_Time_Slice => Time_Slice : declare
13791             Val : Ureal;
13792             Nod : Node_Id;
13793
13794          begin
13795             GNAT_Pragma;
13796             Check_Arg_Count (1);
13797             Check_No_Identifiers;
13798             Check_In_Main_Program;
13799             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13800
13801             if not Error_Posted (Arg1) then
13802                Nod := Next (N);
13803                while Present (Nod) loop
13804                   if Nkind (Nod) = N_Pragma
13805                     and then Pragma_Name (Nod) = Name_Time_Slice
13806                   then
13807                      Error_Msg_Name_1 := Pname;
13808                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13809                   end if;
13810
13811                   Next (Nod);
13812                end loop;
13813             end if;
13814
13815             --  Process only if in main unit
13816
13817             if Get_Source_Unit (Loc) = Main_Unit then
13818                Opt.Time_Slice_Set := True;
13819                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13820
13821                if Val <= Ureal_0 then
13822                   Opt.Time_Slice_Value := 0;
13823
13824                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13825                   Opt.Time_Slice_Value := 1_000_000_000;
13826
13827                else
13828                   Opt.Time_Slice_Value :=
13829                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13830                end if;
13831             end if;
13832          end Time_Slice;
13833
13834          -----------
13835          -- Title --
13836          -----------
13837
13838          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13839
13840          --   TITLING_OPTION ::=
13841          --     [Title =>] STRING_LITERAL
13842          --   | [Subtitle =>] STRING_LITERAL
13843
13844          when Pragma_Title => Title : declare
13845             Args  : Args_List (1 .. 2);
13846             Names : constant Name_List (1 .. 2) := (
13847                       Name_Title,
13848                       Name_Subtitle);
13849
13850          begin
13851             GNAT_Pragma;
13852             Gather_Associations (Names, Args);
13853             Store_Note (N);
13854
13855             for J in 1 .. 2 loop
13856                if Present (Args (J)) then
13857                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13858                end if;
13859             end loop;
13860          end Title;
13861
13862          ---------------------
13863          -- Unchecked_Union --
13864          ---------------------
13865
13866          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13867
13868          when Pragma_Unchecked_Union => Unchecked_Union : declare
13869             Assoc   : constant Node_Id := Arg1;
13870             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13871             Typ     : Entity_Id;
13872             Discr   : Entity_Id;
13873             Tdef    : Node_Id;
13874             Clist   : Node_Id;
13875             Vpart   : Node_Id;
13876             Comp    : Node_Id;
13877             Variant : Node_Id;
13878
13879          begin
13880             Ada_2005_Pragma;
13881             Check_No_Identifiers;
13882             Check_Arg_Count (1);
13883             Check_Arg_Is_Local_Name (Arg1);
13884
13885             Find_Type (Type_Id);
13886             Typ := Entity (Type_Id);
13887
13888             if Typ = Any_Type
13889               or else Rep_Item_Too_Early (Typ, N)
13890             then
13891                return;
13892             else
13893                Typ := Underlying_Type (Typ);
13894             end if;
13895
13896             if Rep_Item_Too_Late (Typ, N) then
13897                return;
13898             end if;
13899
13900             Check_First_Subtype (Arg1);
13901
13902             --  Note remaining cases are references to a type in the current
13903             --  declarative part. If we find an error, we post the error on
13904             --  the relevant type declaration at an appropriate point.
13905
13906             if not Is_Record_Type (Typ) then
13907                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13908                return;
13909
13910             elsif Is_Tagged_Type (Typ) then
13911                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13912                return;
13913
13914             elsif not Has_Discriminants (Typ) then
13915                Error_Msg_N
13916                 ("Unchecked_Union must have one discriminant", Typ);
13917                return;
13918
13919             --  Note: in previous versions of GNAT we used to check for limited
13920             --  types and give an error, but in fact the standard does allow
13921             --  Unchecked_Union on limited types, so this check was removed.
13922
13923             --  Proceed with basic error checks completed
13924
13925             else
13926                Discr := First_Discriminant (Typ);
13927                while Present (Discr) loop
13928                   if No (Discriminant_Default_Value (Discr)) then
13929                      Error_Msg_N
13930                        ("Unchecked_Union discriminant must have default value",
13931                         Discr);
13932                   end if;
13933
13934                   Next_Discriminant (Discr);
13935                end loop;
13936
13937                Tdef  := Type_Definition (Declaration_Node (Typ));
13938                Clist := Component_List (Tdef);
13939
13940                Comp := First (Component_Items (Clist));
13941                while Present (Comp) loop
13942                   Check_Component (Comp, Typ);
13943                   Next (Comp);
13944                end loop;
13945
13946                if No (Clist) or else No (Variant_Part (Clist)) then
13947                   Error_Msg_N
13948                     ("Unchecked_Union must have variant part",
13949                      Tdef);
13950                   return;
13951                end if;
13952
13953                Vpart := Variant_Part (Clist);
13954
13955                Variant := First (Variants (Vpart));
13956                while Present (Variant) loop
13957                   Check_Variant (Variant, Typ);
13958                   Next (Variant);
13959                end loop;
13960             end if;
13961
13962             Set_Is_Unchecked_Union  (Typ);
13963             Set_Convention (Typ, Convention_C);
13964             Set_Has_Unchecked_Union (Base_Type (Typ));
13965             Set_Is_Unchecked_Union  (Base_Type (Typ));
13966          end Unchecked_Union;
13967
13968          ------------------------
13969          -- Unimplemented_Unit --
13970          ------------------------
13971
13972          --  pragma Unimplemented_Unit;
13973
13974          --  Note: this only gives an error if we are generating code, or if
13975          --  we are in a generic library unit (where the pragma appears in the
13976          --  body, not in the spec).
13977
13978          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13979             Cunitent : constant Entity_Id :=
13980                          Cunit_Entity (Get_Source_Unit (Loc));
13981             Ent_Kind : constant Entity_Kind :=
13982                          Ekind (Cunitent);
13983
13984          begin
13985             GNAT_Pragma;
13986             Check_Arg_Count (0);
13987
13988             if Operating_Mode = Generate_Code
13989               or else Ent_Kind = E_Generic_Function
13990               or else Ent_Kind = E_Generic_Procedure
13991               or else Ent_Kind = E_Generic_Package
13992             then
13993                Get_Name_String (Chars (Cunitent));
13994                Set_Casing (Mixed_Case);
13995                Write_Str (Name_Buffer (1 .. Name_Len));
13996                Write_Str (" is not supported in this configuration");
13997                Write_Eol;
13998                raise Unrecoverable_Error;
13999             end if;
14000          end Unimplemented_Unit;
14001
14002          ------------------------
14003          -- Universal_Aliasing --
14004          ------------------------
14005
14006          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
14007
14008          when Pragma_Universal_Aliasing => Universal_Alias : declare
14009             E_Id : Entity_Id;
14010
14011          begin
14012             GNAT_Pragma;
14013             Check_Arg_Count (1);
14014             Check_Optional_Identifier (Arg2, Name_Entity);
14015             Check_Arg_Is_Local_Name (Arg1);
14016             E_Id := Entity (Get_Pragma_Arg (Arg1));
14017
14018             if E_Id = Any_Type then
14019                return;
14020             elsif No (E_Id) or else not Is_Type (E_Id) then
14021                Error_Pragma_Arg ("pragma% requires type", Arg1);
14022             end if;
14023
14024             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
14025          end Universal_Alias;
14026
14027          --------------------
14028          -- Universal_Data --
14029          --------------------
14030
14031          --  pragma Universal_Data [(library_unit_NAME)];
14032
14033          when Pragma_Universal_Data =>
14034             GNAT_Pragma;
14035
14036             --  If this is a configuration pragma, then set the universal
14037             --  addressing option, otherwise confirm that the pragma satisfies
14038             --  the requirements of library unit pragma placement and leave it
14039             --  to the GNAAMP back end to detect the pragma (avoids transitive
14040             --  setting of the option due to withed units).
14041
14042             if Is_Configuration_Pragma then
14043                Universal_Addressing_On_AAMP := True;
14044             else
14045                Check_Valid_Library_Unit_Pragma;
14046             end if;
14047
14048             if not AAMP_On_Target then
14049                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
14050             end if;
14051
14052          ----------------
14053          -- Unmodified --
14054          ----------------
14055
14056          --  pragma Unmodified (local_Name {, local_Name});
14057
14058          when Pragma_Unmodified => Unmodified : declare
14059             Arg_Node : Node_Id;
14060             Arg_Expr : Node_Id;
14061             Arg_Ent  : Entity_Id;
14062
14063          begin
14064             GNAT_Pragma;
14065             Check_At_Least_N_Arguments (1);
14066
14067             --  Loop through arguments
14068
14069             Arg_Node := Arg1;
14070             while Present (Arg_Node) loop
14071                Check_No_Identifier (Arg_Node);
14072
14073                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
14074                --  in fact generate reference, so that the entity will have a
14075                --  reference, which will inhibit any warnings about it not
14076                --  being referenced, and also properly show up in the ali file
14077                --  as a reference. But this reference is recorded before the
14078                --  Has_Pragma_Unreferenced flag is set, so that no warning is
14079                --  generated for this reference.
14080
14081                Check_Arg_Is_Local_Name (Arg_Node);
14082                Arg_Expr := Get_Pragma_Arg (Arg_Node);
14083
14084                if Is_Entity_Name (Arg_Expr) then
14085                   Arg_Ent := Entity (Arg_Expr);
14086
14087                   if not Is_Assignable (Arg_Ent) then
14088                      Error_Pragma_Arg
14089                        ("pragma% can only be applied to a variable",
14090                         Arg_Expr);
14091                   else
14092                      Set_Has_Pragma_Unmodified (Arg_Ent);
14093                   end if;
14094                end if;
14095
14096                Next (Arg_Node);
14097             end loop;
14098          end Unmodified;
14099
14100          ------------------
14101          -- Unreferenced --
14102          ------------------
14103
14104          --  pragma Unreferenced (local_Name {, local_Name});
14105
14106          --    or when used in a context clause:
14107
14108          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
14109
14110          when Pragma_Unreferenced => Unreferenced : declare
14111             Arg_Node : Node_Id;
14112             Arg_Expr : Node_Id;
14113             Arg_Ent  : Entity_Id;
14114             Citem    : Node_Id;
14115
14116          begin
14117             GNAT_Pragma;
14118             Check_At_Least_N_Arguments (1);
14119
14120             --  Check case of appearing within context clause
14121
14122             if Is_In_Context_Clause then
14123
14124                --  The arguments must all be units mentioned in a with clause
14125                --  in the same context clause. Note we already checked (in
14126                --  Par.Prag) that the arguments are either identifiers or
14127                --  selected components.
14128
14129                Arg_Node := Arg1;
14130                while Present (Arg_Node) loop
14131                   Citem := First (List_Containing (N));
14132                   while Citem /= N loop
14133                      if Nkind (Citem) = N_With_Clause
14134                        and then
14135                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
14136                      then
14137                         Set_Has_Pragma_Unreferenced
14138                           (Cunit_Entity
14139                              (Get_Source_Unit
14140                                 (Library_Unit (Citem))));
14141                         Set_Unit_Name
14142                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
14143                         exit;
14144                      end if;
14145
14146                      Next (Citem);
14147                   end loop;
14148
14149                   if Citem = N then
14150                      Error_Pragma_Arg
14151                        ("argument of pragma% is not with'ed unit", Arg_Node);
14152                   end if;
14153
14154                   Next (Arg_Node);
14155                end loop;
14156
14157             --  Case of not in list of context items
14158
14159             else
14160                Arg_Node := Arg1;
14161                while Present (Arg_Node) loop
14162                   Check_No_Identifier (Arg_Node);
14163
14164                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
14165                   --  will in fact generate reference, so that the entity will
14166                   --  have a reference, which will inhibit any warnings about
14167                   --  it not being referenced, and also properly show up in the
14168                   --  ali file as a reference. But this reference is recorded
14169                   --  before the Has_Pragma_Unreferenced flag is set, so that
14170                   --  no warning is generated for this reference.
14171
14172                   Check_Arg_Is_Local_Name (Arg_Node);
14173                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
14174
14175                   if Is_Entity_Name (Arg_Expr) then
14176                      Arg_Ent := Entity (Arg_Expr);
14177
14178                      --  If the entity is overloaded, the pragma applies to the
14179                      --  most recent overloading, as documented. In this case,
14180                      --  name resolution does not generate a reference, so it
14181                      --  must be done here explicitly.
14182
14183                      if Is_Overloaded (Arg_Expr) then
14184                         Generate_Reference (Arg_Ent, N);
14185                      end if;
14186
14187                      Set_Has_Pragma_Unreferenced (Arg_Ent);
14188                   end if;
14189
14190                   Next (Arg_Node);
14191                end loop;
14192             end if;
14193          end Unreferenced;
14194
14195          --------------------------
14196          -- Unreferenced_Objects --
14197          --------------------------
14198
14199          --  pragma Unreferenced_Objects (local_Name {, local_Name});
14200
14201          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14202             Arg_Node : Node_Id;
14203             Arg_Expr : Node_Id;
14204
14205          begin
14206             GNAT_Pragma;
14207             Check_At_Least_N_Arguments (1);
14208
14209             Arg_Node := Arg1;
14210             while Present (Arg_Node) loop
14211                Check_No_Identifier (Arg_Node);
14212                Check_Arg_Is_Local_Name (Arg_Node);
14213                Arg_Expr := Get_Pragma_Arg (Arg_Node);
14214
14215                if not Is_Entity_Name (Arg_Expr)
14216                  or else not Is_Type (Entity (Arg_Expr))
14217                then
14218                   Error_Pragma_Arg
14219                     ("argument for pragma% must be type or subtype", Arg_Node);
14220                end if;
14221
14222                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14223                Next (Arg_Node);
14224             end loop;
14225          end Unreferenced_Objects;
14226
14227          ------------------------------
14228          -- Unreserve_All_Interrupts --
14229          ------------------------------
14230
14231          --  pragma Unreserve_All_Interrupts;
14232
14233          when Pragma_Unreserve_All_Interrupts =>
14234             GNAT_Pragma;
14235             Check_Arg_Count (0);
14236
14237             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14238                Unreserve_All_Interrupts := True;
14239             end if;
14240
14241          ----------------
14242          -- Unsuppress --
14243          ----------------
14244
14245          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14246
14247          when Pragma_Unsuppress =>
14248             Ada_2005_Pragma;
14249             Process_Suppress_Unsuppress (False);
14250
14251          -------------------
14252          -- Use_VADS_Size --
14253          -------------------
14254
14255          --  pragma Use_VADS_Size;
14256
14257          when Pragma_Use_VADS_Size =>
14258             GNAT_Pragma;
14259             Check_Arg_Count (0);
14260             Check_Valid_Configuration_Pragma;
14261             Use_VADS_Size := True;
14262
14263          ---------------------
14264          -- Validity_Checks --
14265          ---------------------
14266
14267          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14268
14269          when Pragma_Validity_Checks => Validity_Checks : declare
14270             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
14271             S  : String_Id;
14272             C  : Char_Code;
14273
14274          begin
14275             GNAT_Pragma;
14276             Check_Arg_Count (1);
14277             Check_No_Identifiers;
14278
14279             if Nkind (A) = N_String_Literal then
14280                S   := Strval (A);
14281
14282                declare
14283                   Slen    : constant Natural := Natural (String_Length (S));
14284                   Options : String (1 .. Slen);
14285                   J       : Natural;
14286
14287                begin
14288                   J := 1;
14289                   loop
14290                      C := Get_String_Char (S, Int (J));
14291                      exit when not In_Character_Range (C);
14292                      Options (J) := Get_Character (C);
14293
14294                      if J = Slen then
14295                         Set_Validity_Check_Options (Options);
14296                         exit;
14297                      else
14298                         J := J + 1;
14299                      end if;
14300                   end loop;
14301                end;
14302
14303             elsif Nkind (A) = N_Identifier then
14304                if Chars (A) = Name_All_Checks then
14305                   Set_Validity_Check_Options ("a");
14306                elsif Chars (A) = Name_On then
14307                   Validity_Checks_On := True;
14308                elsif Chars (A) = Name_Off then
14309                   Validity_Checks_On := False;
14310                end if;
14311             end if;
14312          end Validity_Checks;
14313
14314          --------------
14315          -- Volatile --
14316          --------------
14317
14318          --  pragma Volatile (LOCAL_NAME);
14319
14320          when Pragma_Volatile =>
14321             Process_Atomic_Shared_Volatile;
14322
14323          -------------------------
14324          -- Volatile_Components --
14325          -------------------------
14326
14327          --  pragma Volatile_Components (array_LOCAL_NAME);
14328
14329          --  Volatile is handled by the same circuit as Atomic_Components
14330
14331          --------------
14332          -- Warnings --
14333          --------------
14334
14335          --  pragma Warnings (On | Off);
14336          --  pragma Warnings (On | Off, LOCAL_NAME);
14337          --  pragma Warnings (static_string_EXPRESSION);
14338          --  pragma Warnings (On | Off, STRING_LITERAL);
14339
14340          when Pragma_Warnings => Warnings : begin
14341             GNAT_Pragma;
14342             Check_At_Least_N_Arguments (1);
14343             Check_No_Identifiers;
14344
14345             --  If debug flag -gnatd.i is set, pragma is ignored
14346
14347             if Debug_Flag_Dot_I then
14348                return;
14349             end if;
14350
14351             --  Process various forms of the pragma
14352
14353             declare
14354                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14355
14356             begin
14357                --  One argument case
14358
14359                if Arg_Count = 1 then
14360
14361                   --  On/Off one argument case was processed by parser
14362
14363                   if Nkind (Argx) = N_Identifier
14364                     and then
14365                       (Chars (Argx) = Name_On
14366                          or else
14367                        Chars (Argx) = Name_Off)
14368                   then
14369                      null;
14370
14371                   --  One argument case must be ON/OFF or static string expr
14372
14373                   elsif not Is_Static_String_Expression (Arg1) then
14374                      Error_Pragma_Arg
14375                        ("argument of pragma% must be On/Off or " &
14376                         "static string expression", Arg1);
14377
14378                   --  One argument string expression case
14379
14380                   else
14381                      declare
14382                         Lit : constant Node_Id   := Expr_Value_S (Argx);
14383                         Str : constant String_Id := Strval (Lit);
14384                         Len : constant Nat       := String_Length (Str);
14385                         C   : Char_Code;
14386                         J   : Nat;
14387                         OK  : Boolean;
14388                         Chr : Character;
14389
14390                      begin
14391                         J := 1;
14392                         while J <= Len loop
14393                            C := Get_String_Char (Str, J);
14394                            OK := In_Character_Range (C);
14395
14396                            if OK then
14397                               Chr := Get_Character (C);
14398
14399                               --  Dot case
14400
14401                               if J < Len and then Chr = '.' then
14402                                  J := J + 1;
14403                                  C := Get_String_Char (Str, J);
14404                                  Chr := Get_Character (C);
14405
14406                                  if not Set_Dot_Warning_Switch (Chr) then
14407                                     Error_Pragma_Arg
14408                                       ("invalid warning switch character " &
14409                                        '.' & Chr, Arg1);
14410                                  end if;
14411
14412                               --  Non-Dot case
14413
14414                               else
14415                                  OK := Set_Warning_Switch (Chr);
14416                               end if;
14417                            end if;
14418
14419                            if not OK then
14420                               Error_Pragma_Arg
14421                                 ("invalid warning switch character " & Chr,
14422                                  Arg1);
14423                            end if;
14424
14425                            J := J + 1;
14426                         end loop;
14427                      end;
14428                   end if;
14429
14430                   --  Two or more arguments (must be two)
14431
14432                else
14433                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14434                   Check_At_Most_N_Arguments (2);
14435
14436                   declare
14437                      E_Id : Node_Id;
14438                      E    : Entity_Id;
14439                      Err  : Boolean;
14440
14441                   begin
14442                      E_Id := Get_Pragma_Arg (Arg2);
14443                      Analyze (E_Id);
14444
14445                      --  In the expansion of an inlined body, a reference to
14446                      --  the formal may be wrapped in a conversion if the
14447                      --  actual is a conversion. Retrieve the real entity name.
14448
14449                      if (In_Instance_Body
14450                           or else In_Inlined_Body)
14451                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14452                      then
14453                         E_Id := Expression (E_Id);
14454                      end if;
14455
14456                      --  Entity name case
14457
14458                      if Is_Entity_Name (E_Id) then
14459                         E := Entity (E_Id);
14460
14461                         if E = Any_Id then
14462                            return;
14463                         else
14464                            loop
14465                               Set_Warnings_Off
14466                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14467                                                               Name_Off));
14468
14469                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14470                                 and then Warn_On_Warnings_Off
14471                               then
14472                                  Warnings_Off_Pragmas.Append ((N, E));
14473                               end if;
14474
14475                               if Is_Enumeration_Type (E) then
14476                                  declare
14477                                     Lit : Entity_Id;
14478                                  begin
14479                                     Lit := First_Literal (E);
14480                                     while Present (Lit) loop
14481                                        Set_Warnings_Off (Lit);
14482                                        Next_Literal (Lit);
14483                                     end loop;
14484                                  end;
14485                               end if;
14486
14487                               exit when No (Homonym (E));
14488                               E := Homonym (E);
14489                            end loop;
14490                         end if;
14491
14492                      --  Error if not entity or static string literal case
14493
14494                      elsif not Is_Static_String_Expression (Arg2) then
14495                         Error_Pragma_Arg
14496                           ("second argument of pragma% must be entity " &
14497                            "name or static string expression", Arg2);
14498
14499                      --  String literal case
14500
14501                      else
14502                         String_To_Name_Buffer
14503                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14504
14505                         --  Note on configuration pragma case: If this is a
14506                         --  configuration pragma, then for an OFF pragma, we
14507                         --  just set Config True in the call, which is all
14508                         --  that needs to be done. For the case of ON, this
14509                         --  is normally an error, unless it is canceling the
14510                         --  effect of a previous OFF pragma in the same file.
14511                         --  In any other case, an error will be signalled (ON
14512                         --  with no matching OFF).
14513
14514                         if Chars (Argx) = Name_Off then
14515                            Set_Specific_Warning_Off
14516                              (Loc, Name_Buffer (1 .. Name_Len),
14517                               Config => Is_Configuration_Pragma);
14518
14519                         elsif Chars (Argx) = Name_On then
14520                            Set_Specific_Warning_On
14521                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14522
14523                            if Err then
14524                               Error_Msg
14525                                 ("?pragma Warnings On with no " &
14526                                  "matching Warnings Off",
14527                                  Loc);
14528                            end if;
14529                         end if;
14530                      end if;
14531                   end;
14532                end if;
14533             end;
14534          end Warnings;
14535
14536          -------------------
14537          -- Weak_External --
14538          -------------------
14539
14540          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14541
14542          when Pragma_Weak_External => Weak_External : declare
14543             Ent : Entity_Id;
14544
14545          begin
14546             GNAT_Pragma;
14547             Check_Arg_Count (1);
14548             Check_Optional_Identifier (Arg1, Name_Entity);
14549             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14550             Ent := Entity (Get_Pragma_Arg (Arg1));
14551
14552             if Rep_Item_Too_Early (Ent, N) then
14553                return;
14554             else
14555                Ent := Underlying_Type (Ent);
14556             end if;
14557
14558             --  The only processing required is to link this item on to the
14559             --  list of rep items for the given entity. This is accomplished
14560             --  by the call to Rep_Item_Too_Late (when no error is detected
14561             --  and False is returned).
14562
14563             if Rep_Item_Too_Late (Ent, N) then
14564                return;
14565             else
14566                Set_Has_Gigi_Rep_Item (Ent);
14567             end if;
14568          end Weak_External;
14569
14570          -----------------------------
14571          -- Wide_Character_Encoding --
14572          -----------------------------
14573
14574          --  pragma Wide_Character_Encoding (IDENTIFIER);
14575
14576          when Pragma_Wide_Character_Encoding =>
14577             GNAT_Pragma;
14578
14579             --  Nothing to do, handled in parser. Note that we do not enforce
14580             --  configuration pragma placement, this pragma can appear at any
14581             --  place in the source, allowing mixed encodings within a single
14582             --  source program.
14583
14584             null;
14585
14586          --------------------
14587          -- Unknown_Pragma --
14588          --------------------
14589
14590          --  Should be impossible, since the case of an unknown pragma is
14591          --  separately processed before the case statement is entered.
14592
14593          when Unknown_Pragma =>
14594             raise Program_Error;
14595       end case;
14596
14597       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14598       --  until AI is formally approved.
14599
14600       --  Check_Order_Dependence;
14601
14602    exception
14603       when Pragma_Exit => null;
14604    end Analyze_Pragma;
14605
14606    -----------------------------
14607    -- Analyze_TC_In_Decl_Part --
14608    -----------------------------
14609
14610    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14611    begin
14612       --  Install formals and push subprogram spec onto scope stack so that we
14613       --  can see the formals from the pragma.
14614
14615       Install_Formals (S);
14616       Push_Scope (S);
14617
14618       --  Preanalyze the boolean expressions, we treat these as spec
14619       --  expressions (i.e. similar to a default expression).
14620
14621       Preanalyze_TC_Args (N,
14622                           Get_Requires_From_Test_Case_Pragma (N),
14623                           Get_Ensures_From_Test_Case_Pragma (N));
14624
14625       --  Remove the subprogram from the scope stack now that the pre-analysis
14626       --  of the expressions in the test-case is done.
14627
14628       End_Scope;
14629    end Analyze_TC_In_Decl_Part;
14630
14631    --------------------
14632    -- Check_Disabled --
14633    --------------------
14634
14635    function Check_Disabled (Nam : Name_Id) return Boolean is
14636       PP : Node_Id;
14637
14638    begin
14639       --  Loop through entries in check policy list
14640
14641       PP := Opt.Check_Policy_List;
14642       loop
14643          --  If there are no specific entries that matched, then nothing is
14644          --  disabled, so return False.
14645
14646          if No (PP) then
14647             return False;
14648
14649          --  Here we have an entry see if it matches
14650
14651          else
14652             declare
14653                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14654             begin
14655                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14656                   return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14657                else
14658                   PP := Next_Pragma (PP);
14659                end if;
14660             end;
14661          end if;
14662       end loop;
14663    end Check_Disabled;
14664
14665    -------------------
14666    -- Check_Enabled --
14667    -------------------
14668
14669    function Check_Enabled (Nam : Name_Id) return Boolean is
14670       PP : Node_Id;
14671
14672    begin
14673       --  Loop through entries in check policy list
14674
14675       PP := Opt.Check_Policy_List;
14676       loop
14677          --  If there are no specific entries that matched, then we let the
14678          --  setting of assertions govern. Note that this provides the needed
14679          --  compatibility with the RM for the cases of assertion, invariant,
14680          --  precondition, predicate, and postcondition.
14681
14682          if No (PP) then
14683             return Assertions_Enabled;
14684
14685          --  Here we have an entry see if it matches
14686
14687          else
14688             declare
14689                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14690
14691             begin
14692                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14693                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14694                      when Name_On | Name_Check =>
14695                         return True;
14696                      when Name_Off | Name_Ignore =>
14697                         return False;
14698                      when others =>
14699                         raise Program_Error;
14700                   end case;
14701
14702                else
14703                   PP := Next_Pragma (PP);
14704                end if;
14705             end;
14706          end if;
14707       end loop;
14708    end Check_Enabled;
14709
14710    ---------------------------------
14711    -- Delay_Config_Pragma_Analyze --
14712    ---------------------------------
14713
14714    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14715    begin
14716       return Pragma_Name (N) = Name_Interrupt_State
14717                or else
14718              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14719    end Delay_Config_Pragma_Analyze;
14720
14721    -------------------------
14722    -- Get_Base_Subprogram --
14723    -------------------------
14724
14725    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14726       Result : Entity_Id;
14727
14728    begin
14729       --  Follow subprogram renaming chain
14730
14731       Result := Def_Id;
14732       while Is_Subprogram (Result)
14733         and then
14734           Nkind (Parent (Declaration_Node (Result))) =
14735                                          N_Subprogram_Renaming_Declaration
14736         and then Present (Alias (Result))
14737       loop
14738          Result := Alias (Result);
14739       end loop;
14740
14741       return Result;
14742    end Get_Base_Subprogram;
14743
14744    ----------------
14745    -- Initialize --
14746    ----------------
14747
14748    procedure Initialize is
14749    begin
14750       Externals.Init;
14751    end Initialize;
14752
14753    -----------------------------
14754    -- Is_Config_Static_String --
14755    -----------------------------
14756
14757    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14758
14759       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14760       --  This is an internal recursive function that is just like the outer
14761       --  function except that it adds the string to the name buffer rather
14762       --  than placing the string in the name buffer.
14763
14764       ------------------------------
14765       -- Add_Config_Static_String --
14766       ------------------------------
14767
14768       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14769          N : Node_Id;
14770          C : Char_Code;
14771
14772       begin
14773          N := Arg;
14774
14775          if Nkind (N) = N_Op_Concat then
14776             if Add_Config_Static_String (Left_Opnd (N)) then
14777                N := Right_Opnd (N);
14778             else
14779                return False;
14780             end if;
14781          end if;
14782
14783          if Nkind (N) /= N_String_Literal then
14784             Error_Msg_N ("string literal expected for pragma argument", N);
14785             return False;
14786
14787          else
14788             for J in 1 .. String_Length (Strval (N)) loop
14789                C := Get_String_Char (Strval (N), J);
14790
14791                if not In_Character_Range (C) then
14792                   Error_Msg
14793                     ("string literal contains invalid wide character",
14794                      Sloc (N) + 1 + Source_Ptr (J));
14795                   return False;
14796                end if;
14797
14798                Add_Char_To_Name_Buffer (Get_Character (C));
14799             end loop;
14800          end if;
14801
14802          return True;
14803       end Add_Config_Static_String;
14804
14805    --  Start of processing for Is_Config_Static_String
14806
14807    begin
14808
14809       Name_Len := 0;
14810       return Add_Config_Static_String (Arg);
14811    end Is_Config_Static_String;
14812
14813    -----------------------------------------
14814    -- Is_Non_Significant_Pragma_Reference --
14815    -----------------------------------------
14816
14817    --  This function makes use of the following static table which indicates
14818    --  whether a given pragma is significant.
14819
14820    --  -1  indicates that references in any argument position are significant
14821    --  0   indicates that appearance in any argument is not significant
14822    --  +n  indicates that appearance as argument n is significant, but all
14823    --      other arguments are not significant
14824    --  99  special processing required (e.g. for pragma Check)
14825
14826    Sig_Flags : constant array (Pragma_Id) of Int :=
14827      (Pragma_AST_Entry                      => -1,
14828       Pragma_Abort_Defer                    => -1,
14829       Pragma_Ada_83                         => -1,
14830       Pragma_Ada_95                         => -1,
14831       Pragma_Ada_05                         => -1,
14832       Pragma_Ada_2005                       => -1,
14833       Pragma_Ada_12                         => -1,
14834       Pragma_Ada_2012                       => -1,
14835       Pragma_All_Calls_Remote               => -1,
14836       Pragma_Annotate                       => -1,
14837       Pragma_Assert                         => -1,
14838       Pragma_Assertion_Policy               =>  0,
14839       Pragma_Assume_No_Invalid_Values       =>  0,
14840       Pragma_Asynchronous                   => -1,
14841       Pragma_Atomic                         =>  0,
14842       Pragma_Atomic_Components              =>  0,
14843       Pragma_Attach_Handler                 => -1,
14844       Pragma_Check                          => 99,
14845       Pragma_Check_Name                     =>  0,
14846       Pragma_Check_Policy                   =>  0,
14847       Pragma_CIL_Constructor                => -1,
14848       Pragma_CPP_Class                      =>  0,
14849       Pragma_CPP_Constructor                =>  0,
14850       Pragma_CPP_Virtual                    =>  0,
14851       Pragma_CPP_Vtable                     =>  0,
14852       Pragma_CPU                            => -1,
14853       Pragma_C_Pass_By_Copy                 =>  0,
14854       Pragma_Comment                        =>  0,
14855       Pragma_Common_Object                  => -1,
14856       Pragma_Compile_Time_Error             => -1,
14857       Pragma_Compile_Time_Warning           => -1,
14858       Pragma_Compiler_Unit                  =>  0,
14859       Pragma_Complete_Representation        =>  0,
14860       Pragma_Complex_Representation         =>  0,
14861       Pragma_Component_Alignment            => -1,
14862       Pragma_Controlled                     =>  0,
14863       Pragma_Convention                     =>  0,
14864       Pragma_Convention_Identifier          =>  0,
14865       Pragma_Debug                          => -1,
14866       Pragma_Debug_Policy                   =>  0,
14867       Pragma_Detect_Blocking                => -1,
14868       Pragma_Default_Storage_Pool           => -1,
14869       Pragma_Dimension                      => -1,
14870       Pragma_Disable_Atomic_Synchronization => -1,
14871       Pragma_Discard_Names                  =>  0,
14872       Pragma_Dispatching_Domain             => -1,
14873       Pragma_Elaborate                      => -1,
14874       Pragma_Elaborate_All                  => -1,
14875       Pragma_Elaborate_Body                 => -1,
14876       Pragma_Elaboration_Checks             => -1,
14877       Pragma_Eliminate                      => -1,
14878       Pragma_Enable_Atomic_Synchronization  => -1,
14879       Pragma_Export                         => -1,
14880       Pragma_Export_Exception               => -1,
14881       Pragma_Export_Function                => -1,
14882       Pragma_Export_Object                  => -1,
14883       Pragma_Export_Procedure               => -1,
14884       Pragma_Export_Value                   => -1,
14885       Pragma_Export_Valued_Procedure        => -1,
14886       Pragma_Extend_System                  => -1,
14887       Pragma_Extensions_Allowed             => -1,
14888       Pragma_External                       => -1,
14889       Pragma_Favor_Top_Level                => -1,
14890       Pragma_External_Name_Casing           => -1,
14891       Pragma_Fast_Math                      => -1,
14892       Pragma_Finalize_Storage_Only          =>  0,
14893       Pragma_Float_Representation           =>  0,
14894       Pragma_Ident                          => -1,
14895       Pragma_Implementation_Defined         => -1,
14896       Pragma_Implemented                    => -1,
14897       Pragma_Implicit_Packing               =>  0,
14898       Pragma_Import                         => +2,
14899       Pragma_Import_Exception               =>  0,
14900       Pragma_Import_Function                =>  0,
14901       Pragma_Import_Object                  =>  0,
14902       Pragma_Import_Procedure               =>  0,
14903       Pragma_Import_Valued_Procedure        =>  0,
14904       Pragma_Independent                    =>  0,
14905       Pragma_Independent_Components         =>  0,
14906       Pragma_Initialize_Scalars             => -1,
14907       Pragma_Inline                         =>  0,
14908       Pragma_Inline_Always                  =>  0,
14909       Pragma_Inline_Generic                 =>  0,
14910       Pragma_Inspection_Point               => -1,
14911       Pragma_Interface                      => +2,
14912       Pragma_Interface_Name                 => +2,
14913       Pragma_Interrupt_Handler              => -1,
14914       Pragma_Interrupt_Priority             => -1,
14915       Pragma_Interrupt_State                => -1,
14916       Pragma_Invariant                      => -1,
14917       Pragma_Java_Constructor               => -1,
14918       Pragma_Java_Interface                 => -1,
14919       Pragma_Keep_Names                     =>  0,
14920       Pragma_License                        => -1,
14921       Pragma_Link_With                      => -1,
14922       Pragma_Linker_Alias                   => -1,
14923       Pragma_Linker_Constructor             => -1,
14924       Pragma_Linker_Destructor              => -1,
14925       Pragma_Linker_Options                 => -1,
14926       Pragma_Linker_Section                 => -1,
14927       Pragma_List                           => -1,
14928       Pragma_Locking_Policy                 => -1,
14929       Pragma_Long_Float                     => -1,
14930       Pragma_Machine_Attribute              => -1,
14931       Pragma_Main                           => -1,
14932       Pragma_Main_Storage                   => -1,
14933       Pragma_Memory_Size                    => -1,
14934       Pragma_No_Return                      =>  0,
14935       Pragma_No_Body                        =>  0,
14936       Pragma_No_Run_Time                    => -1,
14937       Pragma_No_Strict_Aliasing             => -1,
14938       Pragma_Normalize_Scalars              => -1,
14939       Pragma_Obsolescent                    =>  0,
14940       Pragma_Optimize                       => -1,
14941       Pragma_Optimize_Alignment             => -1,
14942       Pragma_Ordered                        =>  0,
14943       Pragma_Pack                           =>  0,
14944       Pragma_Page                           => -1,
14945       Pragma_Passive                        => -1,
14946       Pragma_Preelaborable_Initialization   => -1,
14947       Pragma_Polling                        => -1,
14948       Pragma_Persistent_BSS                 =>  0,
14949       Pragma_Postcondition                  => -1,
14950       Pragma_Precondition                   => -1,
14951       Pragma_Predicate                      => -1,
14952       Pragma_Preelaborate                   => -1,
14953       Pragma_Preelaborate_05                => -1,
14954       Pragma_Priority                       => -1,
14955       Pragma_Priority_Specific_Dispatching  => -1,
14956       Pragma_Profile                        =>  0,
14957       Pragma_Profile_Warnings               =>  0,
14958       Pragma_Propagate_Exceptions           => -1,
14959       Pragma_Psect_Object                   => -1,
14960       Pragma_Pure                           => -1,
14961       Pragma_Pure_05                        => -1,
14962       Pragma_Pure_Function                  => -1,
14963       Pragma_Queuing_Policy                 => -1,
14964       Pragma_Ravenscar                      => -1,
14965       Pragma_Relative_Deadline              => -1,
14966       Pragma_Remote_Call_Interface          => -1,
14967       Pragma_Remote_Types                   => -1,
14968       Pragma_Restricted_Run_Time            => -1,
14969       Pragma_Restriction_Warnings           => -1,
14970       Pragma_Restrictions                   => -1,
14971       Pragma_Reviewable                     => -1,
14972       Pragma_Short_Circuit_And_Or           => -1,
14973       Pragma_Share_Generic                  => -1,
14974       Pragma_Shared                         => -1,
14975       Pragma_Shared_Passive                 => -1,
14976       Pragma_Short_Descriptors              =>  0,
14977       Pragma_Source_File_Name               => -1,
14978       Pragma_Source_File_Name_Project       => -1,
14979       Pragma_Source_Reference               => -1,
14980       Pragma_Storage_Size                   => -1,
14981       Pragma_Storage_Unit                   => -1,
14982       Pragma_Static_Elaboration_Desired     => -1,
14983       Pragma_Stream_Convert                 => -1,
14984       Pragma_Style_Checks                   => -1,
14985       Pragma_Subtitle                       => -1,
14986       Pragma_Suppress                       =>  0,
14987       Pragma_Suppress_Exception_Locations   =>  0,
14988       Pragma_Suppress_All                   => -1,
14989       Pragma_Suppress_Debug_Info            =>  0,
14990       Pragma_Suppress_Initialization        =>  0,
14991       Pragma_System_Name                    => -1,
14992       Pragma_Task_Dispatching_Policy        => -1,
14993       Pragma_Task_Info                      => -1,
14994       Pragma_Task_Name                      => -1,
14995       Pragma_Task_Storage                   =>  0,
14996       Pragma_Test_Case                      => -1,
14997       Pragma_Thread_Local_Storage           =>  0,
14998       Pragma_Time_Slice                     => -1,
14999       Pragma_Title                          => -1,
15000       Pragma_Unchecked_Union                =>  0,
15001       Pragma_Unimplemented_Unit             => -1,
15002       Pragma_Universal_Aliasing             => -1,
15003       Pragma_Universal_Data                 => -1,
15004       Pragma_Unmodified                     => -1,
15005       Pragma_Unreferenced                   => -1,
15006       Pragma_Unreferenced_Objects           => -1,
15007       Pragma_Unreserve_All_Interrupts       => -1,
15008       Pragma_Unsuppress                     =>  0,
15009       Pragma_Use_VADS_Size                  => -1,
15010       Pragma_Validity_Checks                => -1,
15011       Pragma_Volatile                       =>  0,
15012       Pragma_Volatile_Components            =>  0,
15013       Pragma_Warnings                       => -1,
15014       Pragma_Weak_External                  => -1,
15015       Pragma_Wide_Character_Encoding        =>  0,
15016       Unknown_Pragma                        =>  0);
15017
15018    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
15019       Id : Pragma_Id;
15020       P  : Node_Id;
15021       C  : Int;
15022       A  : Node_Id;
15023
15024    begin
15025       P := Parent (N);
15026
15027       if Nkind (P) /= N_Pragma_Argument_Association then
15028          return False;
15029
15030       else
15031          Id := Get_Pragma_Id (Parent (P));
15032          C := Sig_Flags (Id);
15033
15034          case C is
15035             when -1 =>
15036                return False;
15037
15038             when 0 =>
15039                return True;
15040
15041             when 99 =>
15042                case Id is
15043
15044                   --  For pragma Check, the first argument is not significant,
15045                   --  the second and the third (if present) arguments are
15046                   --  significant.
15047
15048                   when Pragma_Check =>
15049                      return
15050                        P = First (Pragma_Argument_Associations (Parent (P)));
15051
15052                   when others =>
15053                      raise Program_Error;
15054                end case;
15055
15056             when others =>
15057                A := First (Pragma_Argument_Associations (Parent (P)));
15058                for J in 1 .. C - 1 loop
15059                   if No (A) then
15060                      return False;
15061                   end if;
15062
15063                   Next (A);
15064                end loop;
15065
15066                return A = P; -- is this wrong way round ???
15067          end case;
15068       end if;
15069    end Is_Non_Significant_Pragma_Reference;
15070
15071    ------------------------------
15072    -- Is_Pragma_String_Literal --
15073    ------------------------------
15074
15075    --  This function returns true if the corresponding pragma argument is a
15076    --  static string expression. These are the only cases in which string
15077    --  literals can appear as pragma arguments. We also allow a string literal
15078    --  as the first argument to pragma Assert (although it will of course
15079    --  always generate a type error).
15080
15081    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
15082       Pragn : constant Node_Id := Parent (Par);
15083       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
15084       Pname : constant Name_Id := Pragma_Name (Pragn);
15085       Argn  : Natural;
15086       N     : Node_Id;
15087
15088    begin
15089       Argn := 1;
15090       N := First (Assoc);
15091       loop
15092          exit when N = Par;
15093          Argn := Argn + 1;
15094          Next (N);
15095       end loop;
15096
15097       if Pname = Name_Assert then
15098          return True;
15099
15100       elsif Pname = Name_Export then
15101          return Argn > 2;
15102
15103       elsif Pname = Name_Ident then
15104          return Argn = 1;
15105
15106       elsif Pname = Name_Import then
15107          return Argn > 2;
15108
15109       elsif Pname = Name_Interface_Name then
15110          return Argn > 1;
15111
15112       elsif Pname = Name_Linker_Alias then
15113          return Argn = 2;
15114
15115       elsif Pname = Name_Linker_Section then
15116          return Argn = 2;
15117
15118       elsif Pname = Name_Machine_Attribute then
15119          return Argn = 2;
15120
15121       elsif Pname = Name_Source_File_Name then
15122          return True;
15123
15124       elsif Pname = Name_Source_Reference then
15125          return Argn = 2;
15126
15127       elsif Pname = Name_Title then
15128          return True;
15129
15130       elsif Pname = Name_Subtitle then
15131          return True;
15132
15133       else
15134          return False;
15135       end if;
15136    end Is_Pragma_String_Literal;
15137
15138    ------------------------
15139    -- Preanalyze_TC_Args --
15140    ------------------------
15141
15142    procedure Preanalyze_TC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
15143    begin
15144       --  Preanalyze the boolean expressions, we treat these as spec
15145       --  expressions (i.e. similar to a default expression).
15146
15147       if Present (Arg_Req) then
15148          Preanalyze_Spec_Expression
15149            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15150
15151          --  In ASIS mode, for a pragma generated from a source aspect, also
15152          --  analyze the original aspect expression.
15153
15154          if ASIS_Mode
15155            and then Present (Corresponding_Aspect (N))
15156          then
15157             Preanalyze_Spec_Expression
15158               (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
15159          end if;
15160       end if;
15161
15162       if Present (Arg_Ens) then
15163          Preanalyze_Spec_Expression
15164            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15165
15166          --  In ASIS mode, for a pragma generated from a source aspect, also
15167          --  analyze the original aspect expression.
15168
15169          if ASIS_Mode
15170            and then Present (Corresponding_Aspect (N))
15171          then
15172             Preanalyze_Spec_Expression
15173               (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
15174          end if;
15175       end if;
15176    end Preanalyze_TC_Args;
15177
15178    --------------------------------------
15179    -- Process_Compilation_Unit_Pragmas --
15180    --------------------------------------
15181
15182    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15183    begin
15184       --  A special check for pragma Suppress_All, a very strange DEC pragma,
15185       --  strange because it comes at the end of the unit. Rational has the
15186       --  same name for a pragma, but treats it as a program unit pragma, In
15187       --  GNAT we just decide to allow it anywhere at all. If it appeared then
15188       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
15189       --  node, and we insert a pragma Suppress (All_Checks) at the start of
15190       --  the context clause to ensure the correct processing.
15191
15192       if Has_Pragma_Suppress_All (N) then
15193          Prepend_To (Context_Items (N),
15194            Make_Pragma (Sloc (N),
15195              Chars                        => Name_Suppress,
15196              Pragma_Argument_Associations => New_List (
15197                Make_Pragma_Argument_Association (Sloc (N),
15198                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15199       end if;
15200
15201       --  Nothing else to do at the current time!
15202
15203    end Process_Compilation_Unit_Pragmas;
15204
15205    --------
15206    -- rv --
15207    --------
15208
15209    procedure rv is
15210    begin
15211       null;
15212    end rv;
15213
15214    --------------------------------
15215    -- Set_Encoded_Interface_Name --
15216    --------------------------------
15217
15218    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15219       Str : constant String_Id := Strval (S);
15220       Len : constant Int       := String_Length (Str);
15221       CC  : Char_Code;
15222       C   : Character;
15223       J   : Int;
15224
15225       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15226
15227       procedure Encode;
15228       --  Stores encoded value of character code CC. The encoding we use an
15229       --  underscore followed by four lower case hex digits.
15230
15231       ------------
15232       -- Encode --
15233       ------------
15234
15235       procedure Encode is
15236       begin
15237          Store_String_Char (Get_Char_Code ('_'));
15238          Store_String_Char
15239            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15240          Store_String_Char
15241            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15242          Store_String_Char
15243            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15244          Store_String_Char
15245            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15246       end Encode;
15247
15248    --  Start of processing for Set_Encoded_Interface_Name
15249
15250    begin
15251       --  If first character is asterisk, this is a link name, and we leave it
15252       --  completely unmodified. We also ignore null strings (the latter case
15253       --  happens only in error cases) and no encoding should occur for Java or
15254       --  AAMP interface names.
15255
15256       if Len = 0
15257         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15258         or else VM_Target /= No_VM
15259         or else AAMP_On_Target
15260       then
15261          Set_Interface_Name (E, S);
15262
15263       else
15264          J := 1;
15265          loop
15266             CC := Get_String_Char (Str, J);
15267
15268             exit when not In_Character_Range (CC);
15269
15270             C := Get_Character (CC);
15271
15272             exit when C /= '_' and then C /= '$'
15273               and then C not in '0' .. '9'
15274               and then C not in 'a' .. 'z'
15275               and then C not in 'A' .. 'Z';
15276
15277             if J = Len then
15278                Set_Interface_Name (E, S);
15279                return;
15280
15281             else
15282                J := J + 1;
15283             end if;
15284          end loop;
15285
15286          --  Here we need to encode. The encoding we use as follows:
15287          --     three underscores  + four hex digits (lower case)
15288
15289          Start_String;
15290
15291          for J in 1 .. String_Length (Str) loop
15292             CC := Get_String_Char (Str, J);
15293
15294             if not In_Character_Range (CC) then
15295                Encode;
15296             else
15297                C := Get_Character (CC);
15298
15299                if C = '_' or else C = '$'
15300                  or else C in '0' .. '9'
15301                  or else C in 'a' .. 'z'
15302                  or else C in 'A' .. 'Z'
15303                then
15304                   Store_String_Char (CC);
15305                else
15306                   Encode;
15307                end if;
15308             end if;
15309          end loop;
15310
15311          Set_Interface_Name (E,
15312            Make_String_Literal (Sloc (S),
15313              Strval => End_String));
15314       end if;
15315    end Set_Encoded_Interface_Name;
15316
15317    -------------------
15318    -- Set_Unit_Name --
15319    -------------------
15320
15321    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15322       Pref : Node_Id;
15323       Scop : Entity_Id;
15324
15325    begin
15326       if Nkind (N) = N_Identifier
15327         and then Nkind (With_Item) = N_Identifier
15328       then
15329          Set_Entity (N, Entity (With_Item));
15330
15331       elsif Nkind (N) = N_Selected_Component then
15332          Change_Selected_Component_To_Expanded_Name (N);
15333          Set_Entity (N, Entity (With_Item));
15334          Set_Entity (Selector_Name (N), Entity (N));
15335
15336          Pref := Prefix (N);
15337          Scop := Scope (Entity (N));
15338          while Nkind (Pref) = N_Selected_Component loop
15339             Change_Selected_Component_To_Expanded_Name (Pref);
15340             Set_Entity (Selector_Name (Pref), Scop);
15341             Set_Entity (Pref, Scop);
15342             Pref := Prefix (Pref);
15343             Scop := Scope (Scop);
15344          end loop;
15345
15346          Set_Entity (Pref, Scop);
15347       end if;
15348    end Set_Unit_Name;
15349
15350 end Sem_Prag;