OSDN Git Service

2011-09-02 Vincent Celier <celier@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 Atree;    use Atree;
33 with Casing;   use Casing;
34 with Checks;   use Checks;
35 with Csets;    use Csets;
36 with Debug;    use Debug;
37 with Einfo;    use Einfo;
38 with Elists;   use Elists;
39 with Errout;   use Errout;
40 with Exp_Dist; use Exp_Dist;
41 with Exp_Util; use Exp_Util;
42 with Freeze;   use Freeze;
43 with Lib;      use Lib;
44 with Lib.Writ; use Lib.Writ;
45 with Lib.Xref; use Lib.Xref;
46 with Namet.Sp; use Namet.Sp;
47 with Nlists;   use Nlists;
48 with Nmake;    use Nmake;
49 with Opt;      use Opt;
50 with Output;   use Output;
51 with Par_SCO;  use Par_SCO;
52 with Restrict; use Restrict;
53 with Rident;   use Rident;
54 with Rtsfind;  use Rtsfind;
55 with Sem;      use Sem;
56 with Sem_Aux;  use Sem_Aux;
57 with Sem_Ch3;  use Sem_Ch3;
58 with Sem_Ch6;  use Sem_Ch6;
59 with Sem_Ch8;  use Sem_Ch8;
60 with Sem_Ch12; use Sem_Ch12;
61 with Sem_Ch13; use Sem_Ch13;
62 with Sem_Disp; use Sem_Disp;
63 with Sem_Dist; use Sem_Dist;
64 with Sem_Elim; use Sem_Elim;
65 with Sem_Eval; use Sem_Eval;
66 with Sem_Intr; use Sem_Intr;
67 with Sem_Mech; use Sem_Mech;
68 with Sem_Res;  use Sem_Res;
69 with Sem_Type; use Sem_Type;
70 with Sem_Util; use Sem_Util;
71 with Sem_VFpt; use Sem_VFpt;
72 with Sem_Warn; use Sem_Warn;
73 with Stand;    use Stand;
74 with Sinfo;    use Sinfo;
75 with Sinfo.CN; use Sinfo.CN;
76 with Sinput;   use Sinput;
77 with Snames;   use Snames;
78 with Stringt;  use Stringt;
79 with Stylesw;  use Stylesw;
80 with Table;
81 with Targparm; use Targparm;
82 with Tbuild;   use Tbuild;
83 with Ttypes;
84 with Uintp;    use Uintp;
85 with Uname;    use Uname;
86 with Urealp;   use Urealp;
87 with Validsw;  use Validsw;
88 with Warnsw;   use Warnsw;
89
90 package body Sem_Prag is
91
92    ----------------------------------------------
93    -- Common Handling of Import-Export Pragmas --
94    ----------------------------------------------
95
96    --  In the following section, a number of Import_xxx and Export_xxx pragmas
97    --  are defined by GNAT. These are compatible with the DEC pragmas of the
98    --  same name, and all have the following common form and processing:
99
100    --  pragma Export_xxx
101    --        [Internal                 =>] LOCAL_NAME
102    --     [, [External                 =>] EXTERNAL_SYMBOL]
103    --     [, other optional parameters   ]);
104
105    --  pragma Import_xxx
106    --        [Internal                 =>] LOCAL_NAME
107    --     [, [External                 =>] EXTERNAL_SYMBOL]
108    --     [, other optional parameters   ]);
109
110    --   EXTERNAL_SYMBOL ::=
111    --     IDENTIFIER
112    --   | static_string_EXPRESSION
113
114    --  The internal LOCAL_NAME designates the entity that is imported or
115    --  exported, and must refer to an entity in the current declarative
116    --  part (as required by the rules for LOCAL_NAME).
117
118    --  The external linker name is designated by the External parameter if
119    --  given, or the Internal parameter if not (if there is no External
120    --  parameter, the External parameter is a copy of the Internal name).
121
122    --  If the External parameter is given as a string, then this string is
123    --  treated as an external name (exactly as though it had been given as an
124    --  External_Name parameter for a normal Import pragma).
125
126    --  If the External parameter is given as an identifier (or there is no
127    --  External parameter, so that the Internal identifier is used), then
128    --  the external name is the characters of the identifier, translated
129    --  to all upper case letters for OpenVMS versions of GNAT, and to all
130    --  lower case letters for all other versions
131
132    --  Note: the external name specified or implied by any of these special
133    --  Import_xxx or Export_xxx pragmas override an external or link name
134    --  specified in a previous Import or Export pragma.
135
136    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
137    --  named notation, following the standard rules for subprogram calls, i.e.
138    --  parameters can be given in any order if named notation is used, and
139    --  positional and named notation can be mixed, subject to the rule that all
140    --  positional parameters must appear first.
141
142    --  Note: All these pragmas are implemented exactly following the DEC design
143    --  and implementation and are intended to be fully compatible with the use
144    --  of these pragmas in the DEC Ada compiler.
145
146    --------------------------------------------
147    -- Checking for Duplicated External Names --
148    --------------------------------------------
149
150    --  It is suspicious if two separate Export pragmas use the same external
151    --  name. The following table is used to diagnose this situation so that
152    --  an appropriate warning can be issued.
153
154    --  The Node_Id stored is for the N_String_Literal node created to hold
155    --  the value of the external name. The Sloc of this node is used to
156    --  cross-reference the location of the duplication.
157
158    package Externals is new Table.Table (
159      Table_Component_Type => Node_Id,
160      Table_Index_Type     => Int,
161      Table_Low_Bound      => 0,
162      Table_Initial        => 100,
163      Table_Increment      => 100,
164      Table_Name           => "Name_Externals");
165
166    -------------------------------------
167    -- Local Subprograms and Variables --
168    -------------------------------------
169
170    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
171    --  This routine is used for possible casing adjustment of an explicit
172    --  external name supplied as a string literal (the node N), according to
173    --  the casing requirement of Opt.External_Name_Casing. If this is set to
174    --  As_Is, then the string literal is returned unchanged, but if it is set
175    --  to Uppercase or Lowercase, then a new string literal with appropriate
176    --  casing is constructed.
177
178    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
179    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
180    --  original one, following the renaming chain) is returned. Otherwise the
181    --  entity is returned unchanged. Should be in Einfo???
182
183    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id);
184    --  Preanalyze the boolean expressions in the Requires and Ensures arguments
185    --  of a Test_Case pragma if present (possibly Empty). We treat these as
186    --  spec expressions (i.e. similar to a default expression).
187
188    procedure rv;
189    --  This is a dummy function called by the processing for pragma Reviewable.
190    --  It is there for assisting front end debugging. By placing a Reviewable
191    --  pragma in the source program, a breakpoint on rv catches this place in
192    --  the source, allowing convenient stepping to the point of interest.
193
194    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
195    --  Place semantic information on the argument of an Elaborate/Elaborate_All
196    --  pragma. Entity name for unit and its parents is taken from item in
197    --  previous with_clause that mentions the unit.
198
199    -------------------------------
200    -- Adjust_External_Name_Case --
201    -------------------------------
202
203    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
204       CC : Char_Code;
205
206    begin
207       --  Adjust case of literal if required
208
209       if Opt.External_Name_Exp_Casing = As_Is then
210          return N;
211
212       else
213          --  Copy existing string
214
215          Start_String;
216
217          --  Set proper casing
218
219          for J in 1 .. String_Length (Strval (N)) loop
220             CC := Get_String_Char (Strval (N), J);
221
222             if Opt.External_Name_Exp_Casing = Uppercase
223               and then CC >= Get_Char_Code ('a')
224               and then CC <= Get_Char_Code ('z')
225             then
226                Store_String_Char (CC - 32);
227
228             elsif Opt.External_Name_Exp_Casing = Lowercase
229               and then CC >= Get_Char_Code ('A')
230               and then CC <= Get_Char_Code ('Z')
231             then
232                Store_String_Char (CC + 32);
233
234             else
235                Store_String_Char (CC);
236             end if;
237          end loop;
238
239          return
240            Make_String_Literal (Sloc (N),
241              Strval => End_String);
242       end if;
243    end Adjust_External_Name_Case;
244
245    ------------------------------
246    -- Analyze_PPC_In_Decl_Part --
247    ------------------------------
248
249    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
250       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
251
252    begin
253       --  Install formals and push subprogram spec onto scope stack so that we
254       --  can see the formals from the pragma.
255
256       Install_Formals (S);
257       Push_Scope (S);
258
259       --  Preanalyze the boolean expression, we treat this as a spec expression
260       --  (i.e. similar to a default expression).
261
262       Preanalyze_Spec_Expression
263         (Get_Pragma_Arg (Arg1), Standard_Boolean);
264
265       if Class_Present (N) then
266          declare
267             T   : constant Entity_Id := Find_Dispatching_Type (S);
268
269             ACW : Entity_Id := Empty;
270             --  Access to T'class, created if there is a controlling formal
271             --  that is an access parameter.
272
273             function Get_ACW return Entity_Id;
274             --  If the expression has a reference to an controlling access
275             --  parameter, create an access to T'class for the necessary
276             --  conversions if one does not exist.
277
278             function Process (N : Node_Id) return Traverse_Result;
279             --  ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
280             --  aspect for a primitive subprogram of a tagged type T, a name
281             --  that denotes a formal parameter of type T is interpreted as
282             --  having type T'Class. Similarly, a name that denotes a formal
283             --  accessparameter of type access-to-T is interpreted as having
284             --  type access-to-T'Class. This ensures the expression is well-
285             --  defined for a primitive subprogram of a type descended from T.
286
287             -------------
288             -- Get_ACW --
289             -------------
290
291             function Get_ACW return Entity_Id is
292                Loc  : constant Source_Ptr := Sloc (N);
293                Decl : Node_Id;
294
295             begin
296                if No (ACW) then
297                   Decl := Make_Full_Type_Declaration (Loc,
298                     Defining_Identifier => Make_Temporary (Loc, 'T'),
299                     Type_Definition =>
300                        Make_Access_To_Object_Definition (Loc,
301                        Subtype_Indication =>
302                          New_Occurrence_Of (Class_Wide_Type (T), Loc),
303                        All_Present => True));
304
305                   Insert_Before (Unit_Declaration_Node (S), Decl);
306                   Analyze (Decl);
307                   ACW := Defining_Identifier (Decl);
308                   Freeze_Before (Unit_Declaration_Node (S), ACW);
309                end if;
310
311                return ACW;
312             end Get_ACW;
313
314             -------------
315             -- Process --
316             -------------
317
318             function Process (N : Node_Id) return Traverse_Result is
319                Loc : constant Source_Ptr := Sloc (N);
320                Typ : Entity_Id;
321
322             begin
323                if Is_Entity_Name (N)
324                  and then Is_Formal (Entity (N))
325                  and then Nkind (Parent (N)) /= N_Type_Conversion
326                then
327                   if Etype (Entity (N)) = T then
328                      Typ := Class_Wide_Type (T);
329
330                   elsif Is_Access_Type (Etype (Entity (N)))
331                     and then Designated_Type (Etype (Entity (N))) = T
332                   then
333                      Typ := Get_ACW;
334                   else
335                      Typ := Empty;
336                   end if;
337
338                   if Present (Typ) then
339                      Rewrite (N,
340                        Make_Type_Conversion (Loc,
341                          Subtype_Mark =>
342                            New_Occurrence_Of (Typ, Loc),
343                          Expression  => New_Occurrence_Of (Entity (N), Loc)));
344                      Set_Etype (N, Typ);
345                   end if;
346                end if;
347
348                return OK;
349             end Process;
350
351             procedure Replace_Type is new Traverse_Proc (Process);
352
353          begin
354             Replace_Type (Get_Pragma_Arg (Arg1));
355          end;
356       end if;
357
358       --  Remove the subprogram from the scope stack now that the pre-analysis
359       --  of the precondition/postcondition is done.
360
361       End_Scope;
362    end Analyze_PPC_In_Decl_Part;
363
364    --------------------
365    -- Analyze_Pragma --
366    --------------------
367
368    procedure Analyze_Pragma (N : Node_Id) is
369       Loc     : constant Source_Ptr := Sloc (N);
370       Pname   : constant Name_Id    := Pragma_Name (N);
371       Prag_Id : Pragma_Id;
372
373       Pragma_Exit : exception;
374       --  This exception is used to exit pragma processing completely. It is
375       --  used when an error is detected, and no further processing is
376       --  required. It is also used if an earlier error has left the tree in
377       --  a state where the pragma should not be processed.
378
379       Arg_Count : Nat;
380       --  Number of pragma argument associations
381
382       Arg1 : Node_Id;
383       Arg2 : Node_Id;
384       Arg3 : Node_Id;
385       Arg4 : Node_Id;
386       --  First four pragma arguments (pragma argument association nodes, or
387       --  Empty if the corresponding argument does not exist).
388
389       type Name_List is array (Natural range <>) of Name_Id;
390       type Args_List is array (Natural range <>) of Node_Id;
391       --  Types used for arguments to Check_Arg_Order and Gather_Associations
392
393       procedure Ada_2005_Pragma;
394       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
395       --  Ada 95 mode, these are implementation defined pragmas, so should be
396       --  caught by the No_Implementation_Pragmas restriction.
397
398       procedure Ada_2012_Pragma;
399       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
400       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
401       --  should be caught by the No_Implementation_Pragmas restriction.
402
403       procedure Check_Ada_83_Warning;
404       --  Issues a warning message for the current pragma if operating in Ada
405       --  83 mode (used for language pragmas that are not a standard part of
406       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
407       --  of 95 pragma.
408
409       procedure Check_Arg_Count (Required : Nat);
410       --  Check argument count for pragma is equal to given parameter. If not,
411       --  then issue an error message and raise Pragma_Exit.
412
413       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
414       --  Arg which can either be a pragma argument association, in which case
415       --  the check is applied to the expression of the association or an
416       --  expression directly.
417
418       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
419       --  Check that an argument has the right form for an EXTERNAL_NAME
420       --  parameter of an extended import/export pragma. The rule is that the
421       --  name must be an identifier or string literal (in Ada 83 mode) or a
422       --  static string expression (in Ada 95 mode).
423
424       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
425       --  Check the specified argument Arg to make sure that it is an
426       --  identifier. If not give error and raise Pragma_Exit.
427
428       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
429       --  Check the specified argument Arg to make sure that it is an integer
430       --  literal. If not give error and raise Pragma_Exit.
431
432       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
433       --  Check the specified argument Arg to make sure that it has the proper
434       --  syntactic form for a local name and meets the semantic requirements
435       --  for a local name. The local name is analyzed as part of the
436       --  processing for this call. In addition, the local name is required
437       --  to represent an entity at the library level.
438
439       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
440       --  Check the specified argument Arg to make sure that it has the proper
441       --  syntactic form for a local name and meets the semantic requirements
442       --  for a local name. The local name is analyzed as part of the
443       --  processing for this call.
444
445       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
446       --  Check the specified argument Arg to make sure that it is a valid
447       --  locking policy name. If not give error and raise Pragma_Exit.
448
449       procedure Check_Arg_Is_One_Of
450         (Arg                : Node_Id;
451          N1, N2             : Name_Id);
452       procedure Check_Arg_Is_One_Of
453         (Arg                : Node_Id;
454          N1, N2, N3         : Name_Id);
455       procedure Check_Arg_Is_One_Of
456         (Arg                : Node_Id;
457          N1, N2, N3, N4, N5 : Name_Id);
458       --  Check the specified argument Arg to make sure that it is an
459       --  identifier whose name matches either N1 or N2 (or N3, N4, N5 if
460       --  present). If not then give error and raise Pragma_Exit.
461
462       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
463       --  Check the specified argument Arg to make sure that it is a valid
464       --  queuing policy name. If not give error and raise Pragma_Exit.
465
466       procedure Check_Arg_Is_Static_Expression
467         (Arg : Node_Id;
468          Typ : Entity_Id := Empty);
469       --  Check the specified argument Arg to make sure that it is a static
470       --  expression of the given type (i.e. it will be analyzed and resolved
471       --  using this type, which can be any valid argument to Resolve, e.g.
472       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
473       --  Typ is left Empty, then any static expression is allowed.
474
475       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
476       --  Check the specified argument Arg to make sure that it is a valid task
477       --  dispatching policy name. If not give error and raise Pragma_Exit.
478
479       procedure Check_Arg_Order (Names : Name_List);
480       --  Checks for an instance of two arguments with identifiers for the
481       --  current pragma which are not in the sequence indicated by Names,
482       --  and if so, generates a fatal message about bad order of arguments.
483
484       procedure Check_At_Least_N_Arguments (N : Nat);
485       --  Check there are at least N arguments present
486
487       procedure Check_At_Most_N_Arguments (N : Nat);
488       --  Check there are no more than N arguments present
489
490       procedure Check_Component
491         (Comp            : Node_Id;
492          UU_Typ          : Entity_Id;
493          In_Variant_Part : Boolean := False);
494       --  Examine an Unchecked_Union component for correct use of per-object
495       --  constrained subtypes, and for restrictions on finalizable components.
496       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
497       --  should be set when Comp comes from a record variant.
498
499       procedure Check_Duplicate_Pragma (E : Entity_Id);
500       --  Check if a pragma of the same name as the current pragma is already
501       --  chained as a rep pragma to the given entity. If so give a message
502       --  about the duplicate, and then raise Pragma_Exit so does not return.
503       --  Also checks for delayed aspect specification node in the chain.
504
505       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
506       --  Nam is an N_String_Literal node containing the external name set by
507       --  an Import or Export pragma (or extended Import or Export pragma).
508       --  This procedure checks for possible duplications if this is the export
509       --  case, and if found, issues an appropriate error message.
510
511       procedure Check_First_Subtype (Arg : Node_Id);
512       --  Checks that Arg, whose expression is an entity name, references a
513       --  first subtype.
514
515       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
516       --  Checks that the given argument has an identifier, and if so, requires
517       --  it to match the given identifier name. If there is no identifier, or
518       --  a non-matching identifier, then an error message is given and
519       --  Pragma_Exit is raised.
520
521       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
522       --  Checks that the given argument has an identifier, and if so, requires
523       --  it to match one of the given identifier names. If there is no
524       --  identifier, or a non-matching identifier, then an error message is
525       --  given and Pragma_Exit is raised.
526
527       procedure Check_In_Main_Program;
528       --  Common checks for pragmas that appear within a main program
529       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
530
531       procedure Check_Interrupt_Or_Attach_Handler;
532       --  Common processing for first argument of pragma Interrupt_Handler or
533       --  pragma Attach_Handler.
534
535       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
536       --  Check that pragma appears in a declarative part, or in a package
537       --  specification, i.e. that it does not occur in a statement sequence
538       --  in a body.
539
540       procedure Check_No_Identifier (Arg : Node_Id);
541       --  Checks that the given argument does not have an identifier. If
542       --  an identifier is present, then an error message is issued, and
543       --  Pragma_Exit is raised.
544
545       procedure Check_No_Identifiers;
546       --  Checks that none of the arguments to the pragma has an identifier.
547       --  If any argument has an identifier, then an error message is issued,
548       --  and Pragma_Exit is raised.
549
550       procedure Check_No_Link_Name;
551       --  Checks that no link name is specified
552
553       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
554       --  Checks if the given argument has an identifier, and if so, requires
555       --  it to match the given identifier name. If there is a non-matching
556       --  identifier, then an error message is given and Pragma_Exit is raised.
557
558       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
559       --  Checks if the given argument has an identifier, and if so, requires
560       --  it to match the given identifier name. If there is a non-matching
561       --  identifier, then an error message is given and Pragma_Exit is raised.
562       --  In this version of the procedure, the identifier name is given as
563       --  a string with lower case letters.
564
565       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
566       --  Called to process a precondition or postcondition pragma. There are
567       --  three cases:
568       --
569       --    The pragma appears after a subprogram spec
570       --
571       --      If the corresponding check is not enabled, the pragma is analyzed
572       --      but otherwise ignored and control returns with In_Body set False.
573       --
574       --      If the check is enabled, then the first step is to analyze the
575       --      pragma, but this is skipped if the subprogram spec appears within
576       --      a package specification (because this is the case where we delay
577       --      analysis till the end of the spec). Then (whether or not it was
578       --      analyzed), the pragma is chained to the subprogram in question
579       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
580       --      caller with In_Body set False.
581       --
582       --    The pragma appears at the start of subprogram body declarations
583       --
584       --      In this case an immediate return to the caller is made with
585       --      In_Body set True, and the pragma is NOT analyzed.
586       --
587       --    In all other cases, an error message for bad placement is given
588
589       procedure Check_Static_Constraint (Constr : Node_Id);
590       --  Constr is a constraint from an N_Subtype_Indication node from a
591       --  component constraint in an Unchecked_Union type. This routine checks
592       --  that the constraint is static as required by the restrictions for
593       --  Unchecked_Union.
594
595       procedure Check_Test_Case;
596       --  Called to process a test-case pragma. The treatment is similar to the
597       --  one for pre- and postcondition in Check_Precondition_Postcondition,
598       --  except the placement rules for the test-case pragma are stricter.
599       --  This pragma may only occur after a subprogram spec declared directly
600       --  in a package spec unit. In this case, the pragma is chained to the
601       --  subprogram in question (using Spec_TC_List and Next_Pragma) and
602       --  analysis of the pragma is delayed till the end of the spec. In
603       --  all other cases, an error message for bad placement is given.
604
605       procedure Check_Valid_Configuration_Pragma;
606       --  Legality checks for placement of a configuration pragma
607
608       procedure Check_Valid_Library_Unit_Pragma;
609       --  Legality checks for library unit pragmas. A special case arises for
610       --  pragmas in generic instances that come from copies of the original
611       --  library unit pragmas in the generic templates. In the case of other
612       --  than library level instantiations these can appear in contexts which
613       --  would normally be invalid (they only apply to the original template
614       --  and to library level instantiations), and they are simply ignored,
615       --  which is implemented by rewriting them as null statements.
616
617       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
618       --  Check an Unchecked_Union variant for lack of nested variants and
619       --  presence of at least one component. UU_Typ is the related Unchecked_
620       --  Union type.
621
622       procedure Error_Pragma (Msg : String);
623       pragma No_Return (Error_Pragma);
624       --  Outputs error message for current pragma. The message contains a %
625       --  that will be replaced with the pragma name, and the flag is placed
626       --  on the pragma itself. Pragma_Exit is then raised.
627
628       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
629       pragma No_Return (Error_Pragma_Arg);
630       --  Outputs error message for current pragma. The message may contain
631       --  a % that will be replaced with the pragma name. The parameter Arg
632       --  may either be a pragma argument association, in which case the flag
633       --  is placed on the expression of this association, or an expression,
634       --  in which case the flag is placed directly on the expression. The
635       --  message is placed using Error_Msg_N, so the message may also contain
636       --  an & insertion character which will reference the given Arg value.
637       --  After placing the message, Pragma_Exit is raised.
638
639       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
640       pragma No_Return (Error_Pragma_Arg);
641       --  Similar to above form of Error_Pragma_Arg except that two messages
642       --  are provided, the second is a continuation comment starting with \.
643
644       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
645       pragma No_Return (Error_Pragma_Arg_Ident);
646       --  Outputs error message for current pragma. The message may contain
647       --  a % that will be replaced with the pragma name. The parameter Arg
648       --  must be a pragma argument association with a non-empty identifier
649       --  (i.e. its Chars field must be set), and the error message is placed
650       --  on the identifier. The message is placed using Error_Msg_N so
651       --  the message may also contain an & insertion character which will
652       --  reference the identifier. After placing the message, Pragma_Exit
653       --  is raised.
654
655       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
656       pragma No_Return (Error_Pragma_Ref);
657       --  Outputs error message for current pragma. The message may contain
658       --  a % that will be replaced with the pragma name. The parameter Ref
659       --  must be an entity whose name can be referenced by & and sloc by #.
660       --  After placing the message, Pragma_Exit is raised.
661
662       function Find_Lib_Unit_Name return Entity_Id;
663       --  Used for a library unit pragma to find the entity to which the
664       --  library unit pragma applies, returns the entity found.
665
666       procedure Find_Program_Unit_Name (Id : Node_Id);
667       --  If the pragma is a compilation unit pragma, the id must denote the
668       --  compilation unit in the same compilation, and the pragma must appear
669       --  in the list of preceding or trailing pragmas. If it is a program
670       --  unit pragma that is not a compilation unit pragma, then the
671       --  identifier must be visible.
672
673       function Find_Unique_Parameterless_Procedure
674         (Name : Entity_Id;
675          Arg  : Node_Id) return Entity_Id;
676       --  Used for a procedure pragma to find the unique parameterless
677       --  procedure identified by Name, returns it if it exists, otherwise
678       --  errors out and uses Arg as the pragma argument for the message.
679
680       procedure Fix_Error (Msg : in out String);
681       --  This is called prior to issuing an error message. Msg is a string
682       --  which typically contains the substring pragma. If the current pragma
683       --  comes from an aspect, each such "pragma" substring is replaced with
684       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
685       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
686
687       procedure Gather_Associations
688         (Names : Name_List;
689          Args  : out Args_List);
690       --  This procedure is used to gather the arguments for a pragma that
691       --  permits arbitrary ordering of parameters using the normal rules
692       --  for named and positional parameters. The Names argument is a list
693       --  of Name_Id values that corresponds to the allowed pragma argument
694       --  association identifiers in order. The result returned in Args is
695       --  a list of corresponding expressions that are the pragma arguments.
696       --  Note that this is a list of expressions, not of pragma argument
697       --  associations (Gather_Associations has completely checked all the
698       --  optional identifiers when it returns). An entry in Args is Empty
699       --  on return if the corresponding argument is not present.
700
701       procedure GNAT_Pragma;
702       --  Called for all GNAT defined pragmas to check the relevant restriction
703       --  (No_Implementation_Pragmas).
704
705       function Is_Before_First_Decl
706         (Pragma_Node : Node_Id;
707          Decls       : List_Id) return Boolean;
708       --  Return True if Pragma_Node is before the first declarative item in
709       --  Decls where Decls is the list of declarative items.
710
711       function Is_Configuration_Pragma return Boolean;
712       --  Determines if the placement of the current pragma is appropriate
713       --  for a configuration pragma.
714
715       function Is_In_Context_Clause return Boolean;
716       --  Returns True if pragma appears within the context clause of a unit,
717       --  and False for any other placement (does not generate any messages).
718
719       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
720       --  Analyzes the argument, and determines if it is a static string
721       --  expression, returns True if so, False if non-static or not String.
722
723       procedure Pragma_Misplaced;
724       pragma No_Return (Pragma_Misplaced);
725       --  Issue fatal error message for misplaced pragma
726
727       procedure Process_Atomic_Shared_Volatile;
728       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
729       --  Shared is an obsolete Ada 83 pragma, treated as being identical
730       --  in effect to pragma Atomic.
731
732       procedure Process_Compile_Time_Warning_Or_Error;
733       --  Common processing for Compile_Time_Error and Compile_Time_Warning
734
735       procedure Process_Convention
736         (C   : out Convention_Id;
737          Ent : out Entity_Id);
738       --  Common processing for Convention, Interface, Import and Export.
739       --  Checks first two arguments of pragma, and sets the appropriate
740       --  convention value in the specified entity or entities. On return
741       --  C is the convention, Ent is the referenced entity.
742
743       procedure Process_Extended_Import_Export_Exception_Pragma
744         (Arg_Internal : Node_Id;
745          Arg_External : Node_Id;
746          Arg_Form     : Node_Id;
747          Arg_Code     : Node_Id);
748       --  Common processing for the pragmas Import/Export_Exception. The three
749       --  arguments correspond to the three named parameters of the pragma. An
750       --  argument is empty if the corresponding parameter is not present in
751       --  the pragma.
752
753       procedure Process_Extended_Import_Export_Object_Pragma
754         (Arg_Internal : Node_Id;
755          Arg_External : Node_Id;
756          Arg_Size     : Node_Id);
757       --  Common processing for the pragmas Import/Export_Object. The three
758       --  arguments correspond to the three named parameters of the pragmas. An
759       --  argument is empty if the corresponding parameter is not present in
760       --  the pragma.
761
762       procedure Process_Extended_Import_Export_Internal_Arg
763         (Arg_Internal : Node_Id := Empty);
764       --  Common processing for all extended Import and Export pragmas. The
765       --  argument is the pragma parameter for the Internal argument. If
766       --  Arg_Internal is empty or inappropriate, an error message is posted.
767       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
768       --  set to identify the referenced entity.
769
770       procedure Process_Extended_Import_Export_Subprogram_Pragma
771         (Arg_Internal                 : Node_Id;
772          Arg_External                 : Node_Id;
773          Arg_Parameter_Types          : Node_Id;
774          Arg_Result_Type              : Node_Id := Empty;
775          Arg_Mechanism                : Node_Id;
776          Arg_Result_Mechanism         : Node_Id := Empty;
777          Arg_First_Optional_Parameter : Node_Id := Empty);
778       --  Common processing for all extended Import and Export pragmas applying
779       --  to subprograms. The caller omits any arguments that do not apply to
780       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
781       --  only in the Import_Function and Export_Function cases). The argument
782       --  names correspond to the allowed pragma association identifiers.
783
784       procedure Process_Generic_List;
785       --  Common processing for Share_Generic and Inline_Generic
786
787       procedure Process_Import_Or_Interface;
788       --  Common processing for Import of Interface
789
790       procedure Process_Import_Predefined_Type;
791       --  Processing for completing a type with pragma Import. This is used
792       --  to declare types that match predefined C types, especially for cases
793       --  without corresponding Ada predefined type.
794
795       procedure Process_Inline (Active : Boolean);
796       --  Common processing for Inline and Inline_Always. The parameter
797       --  indicates if the inline pragma is active, i.e. if it should actually
798       --  cause inlining to occur.
799
800       procedure Process_Interface_Name
801         (Subprogram_Def : Entity_Id;
802          Ext_Arg        : Node_Id;
803          Link_Arg       : Node_Id);
804       --  Given the last two arguments of pragma Import, pragma Export, or
805       --  pragma Interface_Name, performs validity checks and sets the
806       --  Interface_Name field of the given subprogram entity to the
807       --  appropriate external or link name, depending on the arguments given.
808       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
809       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
810       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
811       --  nor Link_Arg is present, the interface name is set to the default
812       --  from the subprogram name.
813
814       procedure Process_Interrupt_Or_Attach_Handler;
815       --  Common processing for Interrupt and Attach_Handler pragmas
816
817       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
818       --  Common processing for Restrictions and Restriction_Warnings pragmas.
819       --  Warn is True for Restriction_Warnings, or for Restrictions if the
820       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
821       --  is not set in the Restrictions case.
822
823       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
824       --  Common processing for Suppress and Unsuppress. The boolean parameter
825       --  Suppress_Case is True for the Suppress case, and False for the
826       --  Unsuppress case.
827
828       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
829       --  This procedure sets the Is_Exported flag for the given entity,
830       --  checking that the entity was not previously imported. Arg is
831       --  the argument that specified the entity. A check is also made
832       --  for exporting inappropriate entities.
833
834       procedure Set_Extended_Import_Export_External_Name
835         (Internal_Ent : Entity_Id;
836          Arg_External : Node_Id);
837       --  Common processing for all extended import export pragmas. The first
838       --  argument, Internal_Ent, is the internal entity, which has already
839       --  been checked for validity by the caller. Arg_External is from the
840       --  Import or Export pragma, and may be null if no External parameter
841       --  was present. If Arg_External is present and is a non-null string
842       --  (a null string is treated as the default), then the Interface_Name
843       --  field of Internal_Ent is set appropriately.
844
845       procedure Set_Imported (E : Entity_Id);
846       --  This procedure sets the Is_Imported flag for the given entity,
847       --  checking that it is not previously exported or imported.
848
849       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
850       --  Mech is a parameter passing mechanism (see Import_Function syntax
851       --  for MECHANISM_NAME). This routine checks that the mechanism argument
852       --  has the right form, and if not issues an error message. If the
853       --  argument has the right form then the Mechanism field of Ent is
854       --  set appropriately.
855
856       procedure Set_Ravenscar_Profile (N : Node_Id);
857       --  Activate the set of configuration pragmas and restrictions that make
858       --  up the Ravenscar Profile. N is the corresponding pragma node, which
859       --  is used for error messages on any constructs that violate the
860       --  profile.
861
862       ---------------------
863       -- Ada_2005_Pragma --
864       ---------------------
865
866       procedure Ada_2005_Pragma is
867       begin
868          if Ada_Version <= Ada_95 then
869             Check_Restriction (No_Implementation_Pragmas, N);
870          end if;
871       end Ada_2005_Pragma;
872
873       ---------------------
874       -- Ada_2012_Pragma --
875       ---------------------
876
877       procedure Ada_2012_Pragma is
878       begin
879          if Ada_Version <= Ada_2005 then
880             Check_Restriction (No_Implementation_Pragmas, N);
881          end if;
882       end Ada_2012_Pragma;
883
884       --------------------------
885       -- Check_Ada_83_Warning --
886       --------------------------
887
888       procedure Check_Ada_83_Warning is
889       begin
890          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
891             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
892          end if;
893       end Check_Ada_83_Warning;
894
895       ---------------------
896       -- Check_Arg_Count --
897       ---------------------
898
899       procedure Check_Arg_Count (Required : Nat) is
900       begin
901          if Arg_Count /= Required then
902             Error_Pragma ("wrong number of arguments for pragma%");
903          end if;
904       end Check_Arg_Count;
905
906       --------------------------------
907       -- Check_Arg_Is_External_Name --
908       --------------------------------
909
910       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
911          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
912
913       begin
914          if Nkind (Argx) = N_Identifier then
915             return;
916
917          else
918             Analyze_And_Resolve (Argx, Standard_String);
919
920             if Is_OK_Static_Expression (Argx) then
921                return;
922
923             elsif Etype (Argx) = Any_Type then
924                raise Pragma_Exit;
925
926             --  An interesting special case, if we have a string literal and
927             --  we are in Ada 83 mode, then we allow it even though it will
928             --  not be flagged as static. This allows expected Ada 83 mode
929             --  use of external names which are string literals, even though
930             --  technically these are not static in Ada 83.
931
932             elsif Ada_Version = Ada_83
933               and then Nkind (Argx) = N_String_Literal
934             then
935                return;
936
937             --  Static expression that raises Constraint_Error. This has
938             --  already been flagged, so just exit from pragma processing.
939
940             elsif Is_Static_Expression (Argx) then
941                raise Pragma_Exit;
942
943             --  Here we have a real error (non-static expression)
944
945             else
946                Error_Msg_Name_1 := Pname;
947
948                declare
949                   Msg : String :=
950                           "argument for pragma% must be a identifier or "
951                           & "static string expression!";
952                begin
953                   Fix_Error (Msg);
954                   Flag_Non_Static_Expr (Msg, Argx);
955                   raise Pragma_Exit;
956                end;
957             end if;
958          end if;
959       end Check_Arg_Is_External_Name;
960
961       -----------------------------
962       -- Check_Arg_Is_Identifier --
963       -----------------------------
964
965       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
966          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
967       begin
968          if Nkind (Argx) /= N_Identifier then
969             Error_Pragma_Arg
970               ("argument for pragma% must be identifier", Argx);
971          end if;
972       end Check_Arg_Is_Identifier;
973
974       ----------------------------------
975       -- Check_Arg_Is_Integer_Literal --
976       ----------------------------------
977
978       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
979          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
980       begin
981          if Nkind (Argx) /= N_Integer_Literal then
982             Error_Pragma_Arg
983               ("argument for pragma% must be integer literal", Argx);
984          end if;
985       end Check_Arg_Is_Integer_Literal;
986
987       -------------------------------------------
988       -- Check_Arg_Is_Library_Level_Local_Name --
989       -------------------------------------------
990
991       --  LOCAL_NAME ::=
992       --    DIRECT_NAME
993       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
994       --  | library_unit_NAME
995
996       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
997       begin
998          Check_Arg_Is_Local_Name (Arg);
999
1000          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1001            and then Comes_From_Source (N)
1002          then
1003             Error_Pragma_Arg
1004               ("argument for pragma% must be library level entity", Arg);
1005          end if;
1006       end Check_Arg_Is_Library_Level_Local_Name;
1007
1008       -----------------------------
1009       -- Check_Arg_Is_Local_Name --
1010       -----------------------------
1011
1012       --  LOCAL_NAME ::=
1013       --    DIRECT_NAME
1014       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1015       --  | library_unit_NAME
1016
1017       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1018          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1019
1020       begin
1021          Analyze (Argx);
1022
1023          if Nkind (Argx) not in N_Direct_Name
1024            and then (Nkind (Argx) /= N_Attribute_Reference
1025                       or else Present (Expressions (Argx))
1026                       or else Nkind (Prefix (Argx)) /= N_Identifier)
1027            and then (not Is_Entity_Name (Argx)
1028                       or else not Is_Compilation_Unit (Entity (Argx)))
1029          then
1030             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1031          end if;
1032
1033          --  No further check required if not an entity name
1034
1035          if not Is_Entity_Name (Argx) then
1036             null;
1037
1038          else
1039             declare
1040                OK   : Boolean;
1041                Ent  : constant Entity_Id := Entity (Argx);
1042                Scop : constant Entity_Id := Scope (Ent);
1043             begin
1044                --  Case of a pragma applied to a compilation unit: pragma must
1045                --  occur immediately after the program unit in the compilation.
1046
1047                if Is_Compilation_Unit (Ent) then
1048                   declare
1049                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1050                   begin
1051                      --  Case of pragma placed immediately after spec
1052
1053                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1054                         OK := True;
1055
1056                      --  Case of pragma placed immediately after body
1057
1058                      elsif Nkind (Decl) = N_Subprogram_Declaration
1059                              and then Present (Corresponding_Body (Decl))
1060                      then
1061                         OK := Parent (N) =
1062                                 Aux_Decls_Node
1063                                   (Parent (Unit_Declaration_Node
1064                                              (Corresponding_Body (Decl))));
1065
1066                      --  All other cases are illegal
1067
1068                      else
1069                         OK := False;
1070                      end if;
1071                   end;
1072
1073                --  Special restricted placement rule from 10.2.1(11.8/2)
1074
1075                elsif Is_Generic_Formal (Ent)
1076                        and then Prag_Id = Pragma_Preelaborable_Initialization
1077                then
1078                   OK := List_Containing (N) =
1079                           Generic_Formal_Declarations
1080                             (Unit_Declaration_Node (Scop));
1081
1082                --  Default case, just check that the pragma occurs in the scope
1083                --  of the entity denoted by the name.
1084
1085                else
1086                   OK := Current_Scope = Scop;
1087                end if;
1088
1089                if not OK then
1090                   Error_Pragma_Arg
1091                     ("pragma% argument must be in same declarative part", Arg);
1092                end if;
1093             end;
1094          end if;
1095       end Check_Arg_Is_Local_Name;
1096
1097       ---------------------------------
1098       -- Check_Arg_Is_Locking_Policy --
1099       ---------------------------------
1100
1101       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1102          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1103
1104       begin
1105          Check_Arg_Is_Identifier (Argx);
1106
1107          if not Is_Locking_Policy_Name (Chars (Argx)) then
1108             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1109          end if;
1110       end Check_Arg_Is_Locking_Policy;
1111
1112       -------------------------
1113       -- Check_Arg_Is_One_Of --
1114       -------------------------
1115
1116       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1117          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1118
1119       begin
1120          Check_Arg_Is_Identifier (Argx);
1121
1122          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1123             Error_Msg_Name_2 := N1;
1124             Error_Msg_Name_3 := N2;
1125             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1126          end if;
1127       end Check_Arg_Is_One_Of;
1128
1129       procedure Check_Arg_Is_One_Of
1130         (Arg        : Node_Id;
1131          N1, N2, N3 : Name_Id)
1132       is
1133          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1134
1135       begin
1136          Check_Arg_Is_Identifier (Argx);
1137
1138          if Chars (Argx) /= N1
1139            and then Chars (Argx) /= N2
1140            and then Chars (Argx) /= N3
1141          then
1142             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1143          end if;
1144       end Check_Arg_Is_One_Of;
1145
1146       procedure Check_Arg_Is_One_Of
1147         (Arg                : Node_Id;
1148          N1, N2, N3, N4, N5 : Name_Id)
1149       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
1156            and then Chars (Argx) /= N2
1157            and then Chars (Argx) /= N3
1158            and then Chars (Argx) /= N4
1159            and then Chars (Argx) /= N5
1160          then
1161             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1162          end if;
1163       end Check_Arg_Is_One_Of;
1164       ---------------------------------
1165       -- Check_Arg_Is_Queuing_Policy --
1166       ---------------------------------
1167
1168       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1169          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1170
1171       begin
1172          Check_Arg_Is_Identifier (Argx);
1173
1174          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1175             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1176          end if;
1177       end Check_Arg_Is_Queuing_Policy;
1178
1179       ------------------------------------
1180       -- Check_Arg_Is_Static_Expression --
1181       ------------------------------------
1182
1183       procedure Check_Arg_Is_Static_Expression
1184         (Arg : Node_Id;
1185          Typ : Entity_Id := Empty)
1186       is
1187          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1188
1189       begin
1190          if Present (Typ) then
1191             Analyze_And_Resolve (Argx, Typ);
1192          else
1193             Analyze_And_Resolve (Argx);
1194          end if;
1195
1196          if Is_OK_Static_Expression (Argx) then
1197             return;
1198
1199          elsif Etype (Argx) = Any_Type then
1200             raise Pragma_Exit;
1201
1202          --  An interesting special case, if we have a string literal and we
1203          --  are in Ada 83 mode, then we allow it even though it will not be
1204          --  flagged as static. This allows the use of Ada 95 pragmas like
1205          --  Import in Ada 83 mode. They will of course be flagged with
1206          --  warnings as usual, but will not cause errors.
1207
1208          elsif Ada_Version = Ada_83
1209            and then Nkind (Argx) = N_String_Literal
1210          then
1211             return;
1212
1213          --  Static expression that raises Constraint_Error. This has already
1214          --  been flagged, so just exit from pragma processing.
1215
1216          elsif Is_Static_Expression (Argx) then
1217             raise Pragma_Exit;
1218
1219          --  Finally, we have a real error
1220
1221          else
1222             Error_Msg_Name_1 := Pname;
1223
1224             declare
1225                Msg : String :=
1226                        "argument for pragma% must be a static expression!";
1227             begin
1228                Fix_Error (Msg);
1229                Flag_Non_Static_Expr (Msg, Argx);
1230             end;
1231
1232             raise Pragma_Exit;
1233          end if;
1234       end Check_Arg_Is_Static_Expression;
1235
1236       ------------------------------------------
1237       -- Check_Arg_Is_Task_Dispatching_Policy --
1238       ------------------------------------------
1239
1240       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1241          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1242
1243       begin
1244          Check_Arg_Is_Identifier (Argx);
1245
1246          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1247             Error_Pragma_Arg
1248               ("& is not a valid task dispatching policy name", Argx);
1249          end if;
1250       end Check_Arg_Is_Task_Dispatching_Policy;
1251
1252       ---------------------
1253       -- Check_Arg_Order --
1254       ---------------------
1255
1256       procedure Check_Arg_Order (Names : Name_List) is
1257          Arg : Node_Id;
1258
1259          Highest_So_Far : Natural := 0;
1260          --  Highest index in Names seen do far
1261
1262       begin
1263          Arg := Arg1;
1264          for J in 1 .. Arg_Count loop
1265             if Chars (Arg) /= No_Name then
1266                for K in Names'Range loop
1267                   if Chars (Arg) = Names (K) then
1268                      if K < Highest_So_Far then
1269                         Error_Msg_Name_1 := Pname;
1270                         Error_Msg_N
1271                           ("parameters out of order for pragma%", Arg);
1272                         Error_Msg_Name_1 := Names (K);
1273                         Error_Msg_Name_2 := Names (Highest_So_Far);
1274                         Error_Msg_N ("\% must appear before %", Arg);
1275                         raise Pragma_Exit;
1276
1277                      else
1278                         Highest_So_Far := K;
1279                      end if;
1280                   end if;
1281                end loop;
1282             end if;
1283
1284             Arg := Next (Arg);
1285          end loop;
1286       end Check_Arg_Order;
1287
1288       --------------------------------
1289       -- Check_At_Least_N_Arguments --
1290       --------------------------------
1291
1292       procedure Check_At_Least_N_Arguments (N : Nat) is
1293       begin
1294          if Arg_Count < N then
1295             Error_Pragma ("too few arguments for pragma%");
1296          end if;
1297       end Check_At_Least_N_Arguments;
1298
1299       -------------------------------
1300       -- Check_At_Most_N_Arguments --
1301       -------------------------------
1302
1303       procedure Check_At_Most_N_Arguments (N : Nat) is
1304          Arg : Node_Id;
1305       begin
1306          if Arg_Count > N then
1307             Arg := Arg1;
1308             for J in 1 .. N loop
1309                Next (Arg);
1310                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1311             end loop;
1312          end if;
1313       end Check_At_Most_N_Arguments;
1314
1315       ---------------------
1316       -- Check_Component --
1317       ---------------------
1318
1319       procedure Check_Component
1320         (Comp            : Node_Id;
1321          UU_Typ          : Entity_Id;
1322          In_Variant_Part : Boolean := False)
1323       is
1324          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1325          Sindic  : constant Node_Id :=
1326                      Subtype_Indication (Component_Definition (Comp));
1327          Typ     : constant Entity_Id := Etype (Comp_Id);
1328
1329          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1330          --  Determine whether entity Id appears inside a generic body.
1331          --  Shouldn't this be in a more general place ???
1332
1333          -------------------------
1334          -- Inside_Generic_Body --
1335          -------------------------
1336
1337          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1338             S : Entity_Id;
1339
1340          begin
1341             S := Id;
1342             while Present (S) and then S /= Standard_Standard loop
1343                if Ekind (S) = E_Generic_Package
1344                  and then In_Package_Body (S)
1345                then
1346                   return True;
1347                end if;
1348
1349                S := Scope (S);
1350             end loop;
1351
1352             return False;
1353          end Inside_Generic_Body;
1354
1355       --  Start of processing for Check_Component
1356
1357       begin
1358          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1359          --  object constraint, then the component type shall be an Unchecked_
1360          --  Union.
1361
1362          if Nkind (Sindic) = N_Subtype_Indication
1363            and then Has_Per_Object_Constraint (Comp_Id)
1364            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1365          then
1366             Error_Msg_N
1367               ("component subtype subject to per-object constraint " &
1368                "must be an Unchecked_Union", Comp);
1369
1370          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1371          --  the body of a generic unit, or within the body of any of its
1372          --  descendant library units, no part of the type of a component
1373          --  declared in a variant_part of the unchecked union type shall be of
1374          --  a formal private type or formal private extension declared within
1375          --  the formal part of the generic unit.
1376
1377          elsif Ada_Version >= Ada_2012
1378            and then Inside_Generic_Body (UU_Typ)
1379            and then In_Variant_Part
1380            and then Is_Private_Type (Typ)
1381            and then Is_Generic_Type (Typ)
1382          then
1383             Error_Msg_N
1384               ("component of Unchecked_Union cannot be of generic type", Comp);
1385
1386          elsif Needs_Finalization (Typ) then
1387             Error_Msg_N
1388               ("component of Unchecked_Union cannot be controlled", Comp);
1389
1390          elsif Has_Task (Typ) then
1391             Error_Msg_N
1392               ("component of Unchecked_Union cannot have tasks", Comp);
1393          end if;
1394       end Check_Component;
1395
1396       ----------------------------
1397       -- Check_Duplicate_Pragma --
1398       ----------------------------
1399
1400       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1401          P : Node_Id;
1402
1403       begin
1404          --  Nothing to do if this pragma comes from an aspect specification,
1405          --  since we could not be duplicating a pragma, and we dealt with the
1406          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1407
1408          if From_Aspect_Specification (N) then
1409             return;
1410          end if;
1411
1412          --  Otherwise current pragma may duplicate previous pragma or a
1413          --  previously given aspect specification for the same pragma.
1414
1415          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1416
1417          if Present (P) then
1418             Error_Msg_Name_1 := Pragma_Name (N);
1419             Error_Msg_Sloc := Sloc (P);
1420
1421             if Nkind (P) = N_Aspect_Specification
1422               or else From_Aspect_Specification (P)
1423             then
1424                Error_Msg_NE ("aspect% for & previously given#", N, E);
1425             else
1426                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1427             end if;
1428
1429             raise Pragma_Exit;
1430          end if;
1431       end Check_Duplicate_Pragma;
1432
1433       ----------------------------------
1434       -- Check_Duplicated_Export_Name --
1435       ----------------------------------
1436
1437       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1438          String_Val : constant String_Id := Strval (Nam);
1439
1440       begin
1441          --  We are only interested in the export case, and in the case of
1442          --  generics, it is the instance, not the template, that is the
1443          --  problem (the template will generate a warning in any case).
1444
1445          if not Inside_A_Generic
1446            and then (Prag_Id = Pragma_Export
1447                        or else
1448                      Prag_Id = Pragma_Export_Procedure
1449                        or else
1450                      Prag_Id = Pragma_Export_Valued_Procedure
1451                        or else
1452                      Prag_Id = Pragma_Export_Function)
1453          then
1454             for J in Externals.First .. Externals.Last loop
1455                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1456                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1457                   Error_Msg_N ("external name duplicates name given#", Nam);
1458                   exit;
1459                end if;
1460             end loop;
1461
1462             Externals.Append (Nam);
1463          end if;
1464       end Check_Duplicated_Export_Name;
1465
1466       -------------------------
1467       -- Check_First_Subtype --
1468       -------------------------
1469
1470       procedure Check_First_Subtype (Arg : Node_Id) is
1471          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1472          Ent  : constant Entity_Id := Entity (Argx);
1473
1474       begin
1475          if Is_First_Subtype (Ent) then
1476             null;
1477
1478          elsif Is_Type (Ent) then
1479             Error_Pragma_Arg
1480               ("pragma% cannot apply to subtype", Argx);
1481
1482          elsif Is_Object (Ent) then
1483             Error_Pragma_Arg
1484               ("pragma% cannot apply to object, requires a type", Argx);
1485
1486          else
1487             Error_Pragma_Arg
1488               ("pragma% cannot apply to&, requires a type", Argx);
1489          end if;
1490       end Check_First_Subtype;
1491
1492       ----------------------
1493       -- Check_Identifier --
1494       ----------------------
1495
1496       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1497       begin
1498          if Present (Arg)
1499            and then Nkind (Arg) = N_Pragma_Argument_Association
1500          then
1501             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1502                Error_Msg_Name_1 := Pname;
1503                Error_Msg_Name_2 := Id;
1504                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1505                raise Pragma_Exit;
1506             end if;
1507          end if;
1508       end Check_Identifier;
1509
1510       --------------------------------
1511       -- Check_Identifier_Is_One_Of --
1512       --------------------------------
1513
1514       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1515       begin
1516          if Present (Arg)
1517            and then Nkind (Arg) = N_Pragma_Argument_Association
1518          then
1519             if Chars (Arg) = No_Name then
1520                Error_Msg_Name_1 := Pname;
1521                Error_Msg_N ("pragma% argument expects an identifier", Arg);
1522                raise Pragma_Exit;
1523
1524             elsif Chars (Arg) /= N1
1525               and then Chars (Arg) /= N2
1526             then
1527                Error_Msg_Name_1 := Pname;
1528                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1529                raise Pragma_Exit;
1530             end if;
1531          end if;
1532       end Check_Identifier_Is_One_Of;
1533
1534       ---------------------------
1535       -- Check_In_Main_Program --
1536       ---------------------------
1537
1538       procedure Check_In_Main_Program is
1539          P : constant Node_Id := Parent (N);
1540
1541       begin
1542          --  Must be at in subprogram body
1543
1544          if Nkind (P) /= N_Subprogram_Body then
1545             Error_Pragma ("% pragma allowed only in subprogram");
1546
1547          --  Otherwise warn if obviously not main program
1548
1549          elsif Present (Parameter_Specifications (Specification (P)))
1550            or else not Is_Compilation_Unit (Defining_Entity (P))
1551          then
1552             Error_Msg_Name_1 := Pname;
1553             Error_Msg_N
1554               ("?pragma% is only effective in main program", N);
1555          end if;
1556       end Check_In_Main_Program;
1557
1558       ---------------------------------------
1559       -- Check_Interrupt_Or_Attach_Handler --
1560       ---------------------------------------
1561
1562       procedure Check_Interrupt_Or_Attach_Handler is
1563          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1564          Handler_Proc, Proc_Scope : Entity_Id;
1565
1566       begin
1567          Analyze (Arg1_X);
1568
1569          if Prag_Id = Pragma_Interrupt_Handler then
1570             Check_Restriction (No_Dynamic_Attachment, N);
1571          end if;
1572
1573          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1574          Proc_Scope := Scope (Handler_Proc);
1575
1576          --  On AAMP only, a pragma Interrupt_Handler is supported for
1577          --  nonprotected parameterless procedures.
1578
1579          if not AAMP_On_Target
1580            or else Prag_Id = Pragma_Attach_Handler
1581          then
1582             if Ekind (Proc_Scope) /= E_Protected_Type then
1583                Error_Pragma_Arg
1584                  ("argument of pragma% must be protected procedure", Arg1);
1585             end if;
1586
1587             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1588                Error_Pragma ("pragma% must be in protected definition");
1589             end if;
1590          end if;
1591
1592          if not Is_Library_Level_Entity (Proc_Scope)
1593            or else (AAMP_On_Target
1594                      and then not Is_Library_Level_Entity (Handler_Proc))
1595          then
1596             Error_Pragma_Arg
1597               ("argument for pragma% must be library level entity", Arg1);
1598          end if;
1599
1600          --  AI05-0033: A pragma cannot appear within a generic body, because
1601          --  instance can be in a nested scope. The check that protected type
1602          --  is itself a library-level declaration is done elsewhere.
1603
1604          --  Note: we omit this check in Codepeer mode to properly handle code
1605          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1606
1607          if Inside_A_Generic then
1608             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1609               and then In_Package_Body (Scope (Current_Scope))
1610               and then not CodePeer_Mode
1611             then
1612                Error_Pragma ("pragma% cannot be used inside a generic");
1613             end if;
1614          end if;
1615       end Check_Interrupt_Or_Attach_Handler;
1616
1617       -------------------------------------------
1618       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1619       -------------------------------------------
1620
1621       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1622          P : Node_Id;
1623
1624       begin
1625          P := Parent (N);
1626          loop
1627             if No (P) then
1628                exit;
1629
1630             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1631                exit;
1632
1633             elsif Nkind_In (P, N_Package_Specification,
1634                                N_Block_Statement)
1635             then
1636                return;
1637
1638             --  Note: the following tests seem a little peculiar, because
1639             --  they test for bodies, but if we were in the statement part
1640             --  of the body, we would already have hit the handled statement
1641             --  sequence, so the only way we get here is by being in the
1642             --  declarative part of the body.
1643
1644             elsif Nkind_In (P, N_Subprogram_Body,
1645                                N_Package_Body,
1646                                N_Task_Body,
1647                                N_Entry_Body)
1648             then
1649                return;
1650             end if;
1651
1652             P := Parent (P);
1653          end loop;
1654
1655          Error_Pragma ("pragma% is not in declarative part or package spec");
1656       end Check_Is_In_Decl_Part_Or_Package_Spec;
1657
1658       -------------------------
1659       -- Check_No_Identifier --
1660       -------------------------
1661
1662       procedure Check_No_Identifier (Arg : Node_Id) is
1663       begin
1664          if Nkind (Arg) = N_Pragma_Argument_Association
1665            and then Chars (Arg) /= No_Name
1666          then
1667             Error_Pragma_Arg_Ident
1668               ("pragma% does not permit identifier& here", Arg);
1669          end if;
1670       end Check_No_Identifier;
1671
1672       --------------------------
1673       -- Check_No_Identifiers --
1674       --------------------------
1675
1676       procedure Check_No_Identifiers is
1677          Arg_Node : Node_Id;
1678       begin
1679          if Arg_Count > 0 then
1680             Arg_Node := Arg1;
1681             while Present (Arg_Node) loop
1682                Check_No_Identifier (Arg_Node);
1683                Next (Arg_Node);
1684             end loop;
1685          end if;
1686       end Check_No_Identifiers;
1687
1688       ------------------------
1689       -- Check_No_Link_Name --
1690       ------------------------
1691
1692       procedure Check_No_Link_Name is
1693       begin
1694          if Present (Arg3)
1695            and then Chars (Arg3) = Name_Link_Name
1696          then
1697             Arg4 := Arg3;
1698          end if;
1699
1700          if Present (Arg4) then
1701             Error_Pragma_Arg
1702               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1703          end if;
1704       end Check_No_Link_Name;
1705
1706       -------------------------------
1707       -- Check_Optional_Identifier --
1708       -------------------------------
1709
1710       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1711       begin
1712          if Present (Arg)
1713            and then Nkind (Arg) = N_Pragma_Argument_Association
1714            and then Chars (Arg) /= No_Name
1715          then
1716             if Chars (Arg) /= Id then
1717                Error_Msg_Name_1 := Pname;
1718                Error_Msg_Name_2 := Id;
1719                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1720                raise Pragma_Exit;
1721             end if;
1722          end if;
1723       end Check_Optional_Identifier;
1724
1725       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1726       begin
1727          Name_Buffer (1 .. Id'Length) := Id;
1728          Name_Len := Id'Length;
1729          Check_Optional_Identifier (Arg, Name_Find);
1730       end Check_Optional_Identifier;
1731
1732       --------------------------------------
1733       -- Check_Precondition_Postcondition --
1734       --------------------------------------
1735
1736       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1737          P  : Node_Id;
1738          PO : Node_Id;
1739
1740          procedure Chain_PPC (PO : Node_Id);
1741          --  If PO is an entry or a [generic] subprogram declaration node, then
1742          --  the precondition/postcondition applies to this subprogram and the
1743          --  processing for the pragma is completed. Otherwise the pragma is
1744          --  misplaced.
1745
1746          ---------------
1747          -- Chain_PPC --
1748          ---------------
1749
1750          procedure Chain_PPC (PO : Node_Id) is
1751             S   : Entity_Id;
1752             P   : Node_Id;
1753
1754          begin
1755             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1756                if not From_Aspect_Specification (N) then
1757                   Error_Pragma
1758                     ("pragma% cannot be applied to abstract subprogram");
1759
1760                elsif Class_Present (N) then
1761                   null;
1762
1763                else
1764                   Error_Pragma
1765                     ("aspect % requires ''Class for abstract subprogram");
1766                end if;
1767
1768             --  AI05-0230: The same restriction applies to null procedures. For
1769             --  compatibility with earlier uses of the Ada pragma, apply this
1770             --  rule only to aspect specifications.
1771
1772             --  The above discrpency needs documentation. Robert is dubious
1773             --  about whether it is a good idea ???
1774
1775             elsif Nkind (PO) = N_Subprogram_Declaration
1776               and then Nkind (Specification (PO)) = N_Procedure_Specification
1777               and then Null_Present (Specification (PO))
1778               and then From_Aspect_Specification (N)
1779               and then not Class_Present (N)
1780             then
1781                Error_Pragma
1782                  ("aspect % requires ''Class for null procedure");
1783
1784             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1785                                     N_Generic_Subprogram_Declaration,
1786                                     N_Entry_Declaration)
1787             then
1788                Pragma_Misplaced;
1789             end if;
1790
1791             --  Here if we have [generic] subprogram or entry declaration
1792
1793             if Nkind (PO) = N_Entry_Declaration then
1794                S := Defining_Entity (PO);
1795             else
1796                S := Defining_Unit_Name (Specification (PO));
1797             end if;
1798
1799             --  Make sure we do not have the case of a precondition pragma when
1800             --  the Pre'Class aspect is present.
1801
1802             --  We do this by looking at pragmas already chained to the entity
1803             --  since the aspect derived pragma will be put on this list first.
1804
1805             if Pragma_Name (N) = Name_Precondition then
1806                if not From_Aspect_Specification (N) then
1807                   P := Spec_PPC_List (Contract (S));
1808                   while Present (P) loop
1809                      if Pragma_Name (P) = Name_Precondition
1810                        and then From_Aspect_Specification (P)
1811                        and then Class_Present (P)
1812                      then
1813                         Error_Msg_Sloc := Sloc (P);
1814                         Error_Pragma
1815                           ("pragma% not allowed, `Pre''Class` aspect given#");
1816                      end if;
1817
1818                      P := Next_Pragma (P);
1819                   end loop;
1820                end if;
1821             end if;
1822
1823             --  Similarly check for Pre with inherited Pre'Class. Note that
1824             --  we cover the aspect case as well here.
1825
1826             if Pragma_Name (N) = Name_Precondition
1827               and then not Class_Present (N)
1828             then
1829                declare
1830                   Inherited : constant Subprogram_List :=
1831                                 Inherited_Subprograms (S);
1832                   P         : Node_Id;
1833
1834                begin
1835                   for J in Inherited'Range loop
1836                      P := Spec_PPC_List (Contract (Inherited (J)));
1837                      while Present (P) loop
1838                         if Pragma_Name (P) = Name_Precondition
1839                           and then Class_Present (P)
1840                         then
1841                            Error_Msg_Sloc := Sloc (P);
1842                            Error_Pragma
1843                              ("pragma% not allowed, `Pre''Class` "
1844                               & "aspect inherited from#");
1845                         end if;
1846
1847                         P := Next_Pragma (P);
1848                      end loop;
1849                   end loop;
1850                end;
1851             end if;
1852
1853             --  Note: we do not analyze the pragma at this point. Instead we
1854             --  delay this analysis until the end of the declarative part in
1855             --  which the pragma appears. This implements the required delay
1856             --  in this analysis, allowing forward references. The analysis
1857             --  happens at the end of Analyze_Declarations.
1858
1859             --  Chain spec PPC pragma to list for subprogram
1860
1861             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1862             Set_Spec_PPC_List (Contract (S), N);
1863
1864             --  Return indicating spec case
1865
1866             In_Body := False;
1867             return;
1868          end Chain_PPC;
1869
1870       --  Start of processing for Check_Precondition_Postcondition
1871
1872       begin
1873          if not Is_List_Member (N) then
1874             Pragma_Misplaced;
1875          end if;
1876
1877          --  Preanalyze message argument if present. Visibility in this
1878          --  argument is established at the point of pragma occurrence.
1879
1880          if Arg_Count = 2 then
1881             Check_Optional_Identifier (Arg2, Name_Message);
1882             Preanalyze_Spec_Expression
1883               (Get_Pragma_Arg (Arg2), Standard_String);
1884          end if;
1885
1886          --  Record if pragma is disabled
1887
1888          if Check_Enabled (Pname) then
1889             Set_SCO_Pragma_Enabled (Loc);
1890          end if;
1891
1892          --  If we are within an inlined body, the legality of the pragma
1893          --  has been checked already.
1894
1895          if In_Inlined_Body then
1896             In_Body := True;
1897             return;
1898          end if;
1899
1900          --  Search prior declarations
1901
1902          P := N;
1903          while Present (Prev (P)) loop
1904             P := Prev (P);
1905
1906             --  If the previous node is a generic subprogram, do not go to to
1907             --  the original node, which is the unanalyzed tree: we need to
1908             --  attach the pre/postconditions to the analyzed version at this
1909             --  point. They get propagated to the original tree when analyzing
1910             --  the corresponding body.
1911
1912             if Nkind (P) not in N_Generic_Declaration then
1913                PO := Original_Node (P);
1914             else
1915                PO := P;
1916             end if;
1917
1918             --  Skip past prior pragma
1919
1920             if Nkind (PO) = N_Pragma then
1921                null;
1922
1923             --  Skip stuff not coming from source
1924
1925             elsif not Comes_From_Source (PO) then
1926
1927                --  The condition may apply to a subprogram instantiation
1928
1929                if Nkind (PO) = N_Subprogram_Declaration
1930                  and then Present (Generic_Parent (Specification (PO)))
1931                then
1932                   Chain_PPC (PO);
1933                   return;
1934
1935                elsif Nkind (PO) = N_Subprogram_Declaration
1936                  and then In_Instance
1937                then
1938                   Chain_PPC (PO);
1939                   return;
1940
1941                --  For all other cases of non source code, do nothing
1942
1943                else
1944                   null;
1945                end if;
1946
1947             --  Only remaining possibility is subprogram declaration
1948
1949             else
1950                Chain_PPC (PO);
1951                return;
1952             end if;
1953          end loop;
1954
1955          --  If we fall through loop, pragma is at start of list, so see if it
1956          --  is at the start of declarations of a subprogram body.
1957
1958          if Nkind (Parent (N)) = N_Subprogram_Body
1959            and then List_Containing (N) = Declarations (Parent (N))
1960          then
1961             if Operating_Mode /= Generate_Code
1962               or else Inside_A_Generic
1963             then
1964                --  Analyze pragma expression for correctness and for ASIS use
1965
1966                Preanalyze_Spec_Expression
1967                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
1968             end if;
1969
1970             In_Body := True;
1971             return;
1972
1973          --  See if it is in the pragmas after a library level subprogram
1974
1975          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1976
1977             --  In formal verification mode, analyze pragma expression for
1978             --  correctness, as it is not expanded later.
1979
1980             if Alfa_Mode then
1981                Analyze_PPC_In_Decl_Part
1982                  (N, Defining_Entity (Unit (Parent (Parent (N)))));
1983             end if;
1984
1985             Chain_PPC (Unit (Parent (Parent (N))));
1986             return;
1987          end if;
1988
1989          --  If we fall through, pragma was misplaced
1990
1991          Pragma_Misplaced;
1992       end Check_Precondition_Postcondition;
1993
1994       -----------------------------
1995       -- Check_Static_Constraint --
1996       -----------------------------
1997
1998       --  Note: for convenience in writing this procedure, in addition to
1999       --  the officially (i.e. by spec) allowed argument which is always a
2000       --  constraint, it also allows ranges and discriminant associations.
2001       --  Above is not clear ???
2002
2003       procedure Check_Static_Constraint (Constr : Node_Id) is
2004
2005          procedure Require_Static (E : Node_Id);
2006          --  Require given expression to be static expression
2007
2008          --------------------
2009          -- Require_Static --
2010          --------------------
2011
2012          procedure Require_Static (E : Node_Id) is
2013          begin
2014             if not Is_OK_Static_Expression (E) then
2015                Flag_Non_Static_Expr
2016                  ("non-static constraint not allowed in Unchecked_Union!", E);
2017                raise Pragma_Exit;
2018             end if;
2019          end Require_Static;
2020
2021       --  Start of processing for Check_Static_Constraint
2022
2023       begin
2024          case Nkind (Constr) is
2025             when N_Discriminant_Association =>
2026                Require_Static (Expression (Constr));
2027
2028             when N_Range =>
2029                Require_Static (Low_Bound (Constr));
2030                Require_Static (High_Bound (Constr));
2031
2032             when N_Attribute_Reference =>
2033                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
2034                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2035
2036             when N_Range_Constraint =>
2037                Check_Static_Constraint (Range_Expression (Constr));
2038
2039             when N_Index_Or_Discriminant_Constraint =>
2040                declare
2041                   IDC : Entity_Id;
2042                begin
2043                   IDC := First (Constraints (Constr));
2044                   while Present (IDC) loop
2045                      Check_Static_Constraint (IDC);
2046                      Next (IDC);
2047                   end loop;
2048                end;
2049
2050             when others =>
2051                null;
2052          end case;
2053       end Check_Static_Constraint;
2054
2055       ---------------------
2056       -- Check_Test_Case --
2057       ---------------------
2058
2059       procedure Check_Test_Case is
2060          P  : Node_Id;
2061          PO : Node_Id;
2062
2063          procedure Chain_TC (PO : Node_Id);
2064          --  If PO is a [generic] subprogram declaration node, then the
2065          --  test-case applies to this subprogram and the processing for the
2066          --  pragma is completed. Otherwise the pragma is misplaced.
2067
2068          --------------
2069          -- Chain_TC --
2070          --------------
2071
2072          procedure Chain_TC (PO : Node_Id) is
2073             S   : Entity_Id;
2074
2075          begin
2076             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2077                if From_Aspect_Specification (N) then
2078                   Error_Pragma
2079                     ("aspect% cannot be applied to abstract subprogram");
2080                else
2081                   Error_Pragma
2082                     ("pragma% cannot be applied to abstract subprogram");
2083                end if;
2084
2085             elsif Nkind (PO) = N_Entry_Declaration then
2086                if From_Aspect_Specification (N) then
2087                   Error_Pragma ("aspect% cannot be applied to entry");
2088                else
2089                   Error_Pragma ("pragma% cannot be applied to entry");
2090                end if;
2091
2092             elsif not Nkind_In (PO, N_Subprogram_Declaration,
2093                                     N_Generic_Subprogram_Declaration)
2094             then
2095                Pragma_Misplaced;
2096             end if;
2097
2098             --  Here if we have [generic] subprogram declaration
2099
2100             S := Defining_Unit_Name (Specification (PO));
2101
2102             --  Note: we do not analyze the pragma at this point. Instead we
2103             --  delay this analysis until the end of the declarative part in
2104             --  which the pragma appears. This implements the required delay
2105             --  in this analysis, allowing forward references. The analysis
2106             --  happens at the end of Analyze_Declarations.
2107
2108             --  There should not be another test case with the same name
2109             --  associated to this subprogram.
2110
2111             declare
2112                Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2113                TC   : Node_Id;
2114
2115             begin
2116                TC := Spec_TC_List (Contract (S));
2117                while Present (TC) loop
2118
2119                   if String_Equal
2120                     (Name, Get_Name_From_Test_Case_Pragma (TC))
2121                   then
2122                      Error_Msg_Sloc := Sloc (TC);
2123
2124                      if From_Aspect_Specification (N) then
2125                         Error_Pragma ("name for aspect% is already used#");
2126                      else
2127                         Error_Pragma ("name for pragma% is already used#");
2128                      end if;
2129                   end if;
2130
2131                   TC := Next_Pragma (TC);
2132                end loop;
2133             end;
2134
2135             --  Chain spec TC pragma to list for subprogram
2136
2137             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2138             Set_Spec_TC_List (Contract (S), N);
2139          end Chain_TC;
2140
2141       --  Start of processing for Check_Test_Case
2142
2143       begin
2144          if not Is_List_Member (N) then
2145             Pragma_Misplaced;
2146          end if;
2147
2148          --  Test cases should only appear in package spec unit
2149
2150          if Get_Source_Unit (N) = No_Unit
2151            or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2152                                  N_Package_Declaration,
2153                                  N_Generic_Package_Declaration)
2154          then
2155             Pragma_Misplaced;
2156          end if;
2157
2158          --  Search prior declarations
2159
2160          P := N;
2161          while Present (Prev (P)) loop
2162             P := Prev (P);
2163
2164             --  If the previous node is a generic subprogram, do not go to to
2165             --  the original node, which is the unanalyzed tree: we need to
2166             --  attach the test-case to the analyzed version at this point.
2167             --  They get propagated to the original tree when analyzing the
2168             --  corresponding body.
2169
2170             if Nkind (P) not in N_Generic_Declaration then
2171                PO := Original_Node (P);
2172             else
2173                PO := P;
2174             end if;
2175
2176             --  Skip past prior pragma
2177
2178             if Nkind (PO) = N_Pragma then
2179                null;
2180
2181             --  Skip stuff not coming from source
2182
2183             elsif not Comes_From_Source (PO) then
2184                null;
2185
2186             --  Only remaining possibility is subprogram declaration. First
2187             --  check that it is declared directly in a package declaration.
2188             --  This may be either the package declaration for the current unit
2189             --  being defined or a local package declaration.
2190
2191             elsif not Present (Parent (Parent (PO)))
2192               or else not Present (Parent (Parent (Parent (PO))))
2193               or else not Nkind_In (Parent (Parent (PO)),
2194                                     N_Package_Declaration,
2195                                     N_Generic_Package_Declaration)
2196             then
2197                Pragma_Misplaced;
2198
2199             else
2200                Chain_TC (PO);
2201                return;
2202             end if;
2203          end loop;
2204
2205          --  If we fall through, pragma was misplaced
2206
2207          Pragma_Misplaced;
2208       end Check_Test_Case;
2209
2210       --------------------------------------
2211       -- Check_Valid_Configuration_Pragma --
2212       --------------------------------------
2213
2214       --  A configuration pragma must appear in the context clause of a
2215       --  compilation unit, and only other pragmas may precede it. Note that
2216       --  the test also allows use in a configuration pragma file.
2217
2218       procedure Check_Valid_Configuration_Pragma is
2219       begin
2220          if not Is_Configuration_Pragma then
2221             Error_Pragma ("incorrect placement for configuration pragma%");
2222          end if;
2223       end Check_Valid_Configuration_Pragma;
2224
2225       -------------------------------------
2226       -- Check_Valid_Library_Unit_Pragma --
2227       -------------------------------------
2228
2229       procedure Check_Valid_Library_Unit_Pragma is
2230          Plist       : List_Id;
2231          Parent_Node : Node_Id;
2232          Unit_Name   : Entity_Id;
2233          Unit_Kind   : Node_Kind;
2234          Unit_Node   : Node_Id;
2235          Sindex      : Source_File_Index;
2236
2237       begin
2238          if not Is_List_Member (N) then
2239             Pragma_Misplaced;
2240
2241          else
2242             Plist := List_Containing (N);
2243             Parent_Node := Parent (Plist);
2244
2245             if Parent_Node = Empty then
2246                Pragma_Misplaced;
2247
2248             --  Case of pragma appearing after a compilation unit. In this case
2249             --  it must have an argument with the corresponding name and must
2250             --  be part of the following pragmas of its parent.
2251
2252             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2253                if Plist /= Pragmas_After (Parent_Node) then
2254                   Pragma_Misplaced;
2255
2256                elsif Arg_Count = 0 then
2257                   Error_Pragma
2258                     ("argument required if outside compilation unit");
2259
2260                else
2261                   Check_No_Identifiers;
2262                   Check_Arg_Count (1);
2263                   Unit_Node := Unit (Parent (Parent_Node));
2264                   Unit_Kind := Nkind (Unit_Node);
2265
2266                   Analyze (Get_Pragma_Arg (Arg1));
2267
2268                   if Unit_Kind = N_Generic_Subprogram_Declaration
2269                     or else Unit_Kind = N_Subprogram_Declaration
2270                   then
2271                      Unit_Name := Defining_Entity (Unit_Node);
2272
2273                   elsif Unit_Kind in N_Generic_Instantiation then
2274                      Unit_Name := Defining_Entity (Unit_Node);
2275
2276                   else
2277                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2278                   end if;
2279
2280                   if Chars (Unit_Name) /=
2281                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2282                   then
2283                      Error_Pragma_Arg
2284                        ("pragma% argument is not current unit name", Arg1);
2285                   end if;
2286
2287                   if Ekind (Unit_Name) = E_Package
2288                     and then Present (Renamed_Entity (Unit_Name))
2289                   then
2290                      Error_Pragma ("pragma% not allowed for renamed package");
2291                   end if;
2292                end if;
2293
2294             --  Pragma appears other than after a compilation unit
2295
2296             else
2297                --  Here we check for the generic instantiation case and also
2298                --  for the case of processing a generic formal package. We
2299                --  detect these cases by noting that the Sloc on the node
2300                --  does not belong to the current compilation unit.
2301
2302                Sindex := Source_Index (Current_Sem_Unit);
2303
2304                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2305                   Rewrite (N, Make_Null_Statement (Loc));
2306                   return;
2307
2308                --  If before first declaration, the pragma applies to the
2309                --  enclosing unit, and the name if present must be this name.
2310
2311                elsif Is_Before_First_Decl (N, Plist) then
2312                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2313                   Unit_Kind := Nkind (Unit_Node);
2314
2315                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2316                      Pragma_Misplaced;
2317
2318                   elsif Unit_Kind = N_Subprogram_Body
2319                     and then not Acts_As_Spec (Unit_Node)
2320                   then
2321                      Pragma_Misplaced;
2322
2323                   elsif Nkind (Parent_Node) = N_Package_Body then
2324                      Pragma_Misplaced;
2325
2326                   elsif Nkind (Parent_Node) = N_Package_Specification
2327                     and then Plist = Private_Declarations (Parent_Node)
2328                   then
2329                      Pragma_Misplaced;
2330
2331                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2332                            or else Nkind (Parent_Node) =
2333                                              N_Generic_Subprogram_Declaration)
2334                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2335                   then
2336                      Pragma_Misplaced;
2337
2338                   elsif Arg_Count > 0 then
2339                      Analyze (Get_Pragma_Arg (Arg1));
2340
2341                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2342                         Error_Pragma_Arg
2343                           ("name in pragma% must be enclosing unit", Arg1);
2344                      end if;
2345
2346                   --  It is legal to have no argument in this context
2347
2348                   else
2349                      return;
2350                   end if;
2351
2352                --  Error if not before first declaration. This is because a
2353                --  library unit pragma argument must be the name of a library
2354                --  unit (RM 10.1.5(7)), but the only names permitted in this
2355                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2356                --  generic subprogram declarations or generic instantiations.
2357
2358                else
2359                   Error_Pragma
2360                     ("pragma% misplaced, must be before first declaration");
2361                end if;
2362             end if;
2363          end if;
2364       end Check_Valid_Library_Unit_Pragma;
2365
2366       -------------------
2367       -- Check_Variant --
2368       -------------------
2369
2370       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2371          Clist : constant Node_Id := Component_List (Variant);
2372          Comp  : Node_Id;
2373
2374       begin
2375          if not Is_Non_Empty_List (Component_Items (Clist)) then
2376             Error_Msg_N
2377               ("Unchecked_Union may not have empty component list",
2378                Variant);
2379             return;
2380          end if;
2381
2382          Comp := First (Component_Items (Clist));
2383          while Present (Comp) loop
2384             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2385             Next (Comp);
2386          end loop;
2387       end Check_Variant;
2388
2389       ------------------
2390       -- Error_Pragma --
2391       ------------------
2392
2393       procedure Error_Pragma (Msg : String) is
2394          MsgF : String := Msg;
2395       begin
2396          Error_Msg_Name_1 := Pname;
2397          Fix_Error (MsgF);
2398          Error_Msg_N (MsgF, N);
2399          raise Pragma_Exit;
2400       end Error_Pragma;
2401
2402       ----------------------
2403       -- Error_Pragma_Arg --
2404       ----------------------
2405
2406       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2407          MsgF : String := Msg;
2408       begin
2409          Error_Msg_Name_1 := Pname;
2410          Fix_Error (MsgF);
2411          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2412          raise Pragma_Exit;
2413       end Error_Pragma_Arg;
2414
2415       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2416          MsgF : String := Msg1;
2417       begin
2418          Error_Msg_Name_1 := Pname;
2419          Fix_Error (MsgF);
2420          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2421          Error_Pragma_Arg (Msg2, Arg);
2422       end Error_Pragma_Arg;
2423
2424       ----------------------------
2425       -- Error_Pragma_Arg_Ident --
2426       ----------------------------
2427
2428       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2429          MsgF : String := Msg;
2430       begin
2431          Error_Msg_Name_1 := Pname;
2432          Fix_Error (MsgF);
2433          Error_Msg_N (MsgF, Arg);
2434          raise Pragma_Exit;
2435       end Error_Pragma_Arg_Ident;
2436
2437       ----------------------
2438       -- Error_Pragma_Ref --
2439       ----------------------
2440
2441       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2442          MsgF : String := Msg;
2443       begin
2444          Error_Msg_Name_1 := Pname;
2445          Fix_Error (MsgF);
2446          Error_Msg_Sloc   := Sloc (Ref);
2447          Error_Msg_NE (MsgF, N, Ref);
2448          raise Pragma_Exit;
2449       end Error_Pragma_Ref;
2450
2451       ------------------------
2452       -- Find_Lib_Unit_Name --
2453       ------------------------
2454
2455       function Find_Lib_Unit_Name return Entity_Id is
2456       begin
2457          --  Return inner compilation unit entity, for case of nested
2458          --  categorization pragmas. This happens in generic unit.
2459
2460          if Nkind (Parent (N)) = N_Package_Specification
2461            and then Defining_Entity (Parent (N)) /= Current_Scope
2462          then
2463             return Defining_Entity (Parent (N));
2464          else
2465             return Current_Scope;
2466          end if;
2467       end Find_Lib_Unit_Name;
2468
2469       ----------------------------
2470       -- Find_Program_Unit_Name --
2471       ----------------------------
2472
2473       procedure Find_Program_Unit_Name (Id : Node_Id) is
2474          Unit_Name : Entity_Id;
2475          Unit_Kind : Node_Kind;
2476          P         : constant Node_Id := Parent (N);
2477
2478       begin
2479          if Nkind (P) = N_Compilation_Unit then
2480             Unit_Kind := Nkind (Unit (P));
2481
2482             if Unit_Kind = N_Subprogram_Declaration
2483               or else Unit_Kind = N_Package_Declaration
2484               or else Unit_Kind in N_Generic_Declaration
2485             then
2486                Unit_Name := Defining_Entity (Unit (P));
2487
2488                if Chars (Id) = Chars (Unit_Name) then
2489                   Set_Entity (Id, Unit_Name);
2490                   Set_Etype (Id, Etype (Unit_Name));
2491                else
2492                   Set_Etype (Id, Any_Type);
2493                   Error_Pragma
2494                     ("cannot find program unit referenced by pragma%");
2495                end if;
2496
2497             else
2498                Set_Etype (Id, Any_Type);
2499                Error_Pragma ("pragma% inapplicable to this unit");
2500             end if;
2501
2502          else
2503             Analyze (Id);
2504          end if;
2505       end Find_Program_Unit_Name;
2506
2507       -----------------------------------------
2508       -- Find_Unique_Parameterless_Procedure --
2509       -----------------------------------------
2510
2511       function Find_Unique_Parameterless_Procedure
2512         (Name : Entity_Id;
2513          Arg  : Node_Id) return Entity_Id
2514       is
2515          Proc : Entity_Id := Empty;
2516
2517       begin
2518          --  The body of this procedure needs some comments ???
2519
2520          if not Is_Entity_Name (Name) then
2521             Error_Pragma_Arg
2522               ("argument of pragma% must be entity name", Arg);
2523
2524          elsif not Is_Overloaded (Name) then
2525             Proc := Entity (Name);
2526
2527             if Ekind (Proc) /= E_Procedure
2528               or else Present (First_Formal (Proc))
2529             then
2530                Error_Pragma_Arg
2531                  ("argument of pragma% must be parameterless procedure", Arg);
2532             end if;
2533
2534          else
2535             declare
2536                Found : Boolean := False;
2537                It    : Interp;
2538                Index : Interp_Index;
2539
2540             begin
2541                Get_First_Interp (Name, Index, It);
2542                while Present (It.Nam) loop
2543                   Proc := It.Nam;
2544
2545                   if Ekind (Proc) = E_Procedure
2546                     and then No (First_Formal (Proc))
2547                   then
2548                      if not Found then
2549                         Found := True;
2550                         Set_Entity (Name, Proc);
2551                         Set_Is_Overloaded (Name, False);
2552                      else
2553                         Error_Pragma_Arg
2554                           ("ambiguous handler name for pragma% ", Arg);
2555                      end if;
2556                   end if;
2557
2558                   Get_Next_Interp (Index, It);
2559                end loop;
2560
2561                if not Found then
2562                   Error_Pragma_Arg
2563                     ("argument of pragma% must be parameterless procedure",
2564                      Arg);
2565                else
2566                   Proc := Entity (Name);
2567                end if;
2568             end;
2569          end if;
2570
2571          return Proc;
2572       end Find_Unique_Parameterless_Procedure;
2573
2574       ---------------
2575       -- Fix_Error --
2576       ---------------
2577
2578       procedure Fix_Error (Msg : in out String) is
2579       begin
2580          if From_Aspect_Specification (N) then
2581             for J in Msg'First .. Msg'Last - 5 loop
2582                if Msg (J .. J + 5) = "pragma" then
2583                   Msg (J .. J + 5) := "aspect";
2584                end if;
2585             end loop;
2586
2587             if Error_Msg_Name_1 = Name_Precondition then
2588                Error_Msg_Name_1 := Name_Pre;
2589             elsif Error_Msg_Name_1 = Name_Postcondition then
2590                Error_Msg_Name_1 := Name_Post;
2591             end if;
2592          end if;
2593       end Fix_Error;
2594
2595       -------------------------
2596       -- Gather_Associations --
2597       -------------------------
2598
2599       procedure Gather_Associations
2600         (Names : Name_List;
2601          Args  : out Args_List)
2602       is
2603          Arg : Node_Id;
2604
2605       begin
2606          --  Initialize all parameters to Empty
2607
2608          for J in Args'Range loop
2609             Args (J) := Empty;
2610          end loop;
2611
2612          --  That's all we have to do if there are no argument associations
2613
2614          if No (Pragma_Argument_Associations (N)) then
2615             return;
2616          end if;
2617
2618          --  Otherwise first deal with any positional parameters present
2619
2620          Arg := First (Pragma_Argument_Associations (N));
2621          for Index in Args'Range loop
2622             exit when No (Arg) or else Chars (Arg) /= No_Name;
2623             Args (Index) := Get_Pragma_Arg (Arg);
2624             Next (Arg);
2625          end loop;
2626
2627          --  Positional parameters all processed, if any left, then we
2628          --  have too many positional parameters.
2629
2630          if Present (Arg) and then Chars (Arg) = No_Name then
2631             Error_Pragma_Arg
2632               ("too many positional associations for pragma%", Arg);
2633          end if;
2634
2635          --  Process named parameters if any are present
2636
2637          while Present (Arg) loop
2638             if Chars (Arg) = No_Name then
2639                Error_Pragma_Arg
2640                  ("positional association cannot follow named association",
2641                   Arg);
2642
2643             else
2644                for Index in Names'Range loop
2645                   if Names (Index) = Chars (Arg) then
2646                      if Present (Args (Index)) then
2647                         Error_Pragma_Arg
2648                           ("duplicate argument association for pragma%", Arg);
2649                      else
2650                         Args (Index) := Get_Pragma_Arg (Arg);
2651                         exit;
2652                      end if;
2653                   end if;
2654
2655                   if Index = Names'Last then
2656                      Error_Msg_Name_1 := Pname;
2657                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2658
2659                      --  Check for possible misspelling
2660
2661                      for Index1 in Names'Range loop
2662                         if Is_Bad_Spelling_Of
2663                              (Chars (Arg), Names (Index1))
2664                         then
2665                            Error_Msg_Name_1 := Names (Index1);
2666                            Error_Msg_N -- CODEFIX
2667                              ("\possible misspelling of%", Arg);
2668                            exit;
2669                         end if;
2670                      end loop;
2671
2672                      raise Pragma_Exit;
2673                   end if;
2674                end loop;
2675             end if;
2676
2677             Next (Arg);
2678          end loop;
2679       end Gather_Associations;
2680
2681       -----------------
2682       -- GNAT_Pragma --
2683       -----------------
2684
2685       procedure GNAT_Pragma is
2686       begin
2687          Check_Restriction (No_Implementation_Pragmas, N);
2688       end GNAT_Pragma;
2689
2690       --------------------------
2691       -- Is_Before_First_Decl --
2692       --------------------------
2693
2694       function Is_Before_First_Decl
2695         (Pragma_Node : Node_Id;
2696          Decls       : List_Id) return Boolean
2697       is
2698          Item : Node_Id := First (Decls);
2699
2700       begin
2701          --  Only other pragmas can come before this pragma
2702
2703          loop
2704             if No (Item) or else Nkind (Item) /= N_Pragma then
2705                return False;
2706
2707             elsif Item = Pragma_Node then
2708                return True;
2709             end if;
2710
2711             Next (Item);
2712          end loop;
2713       end Is_Before_First_Decl;
2714
2715       -----------------------------
2716       -- Is_Configuration_Pragma --
2717       -----------------------------
2718
2719       --  A configuration pragma must appear in the context clause of a
2720       --  compilation unit, and only other pragmas may precede it. Note that
2721       --  the test below also permits use in a configuration pragma file.
2722
2723       function Is_Configuration_Pragma return Boolean is
2724          Lis : constant List_Id := List_Containing (N);
2725          Par : constant Node_Id := Parent (N);
2726          Prg : Node_Id;
2727
2728       begin
2729          --  If no parent, then we are in the configuration pragma file,
2730          --  so the placement is definitely appropriate.
2731
2732          if No (Par) then
2733             return True;
2734
2735          --  Otherwise we must be in the context clause of a compilation unit
2736          --  and the only thing allowed before us in the context list is more
2737          --  configuration pragmas.
2738
2739          elsif Nkind (Par) = N_Compilation_Unit
2740            and then Context_Items (Par) = Lis
2741          then
2742             Prg := First (Lis);
2743
2744             loop
2745                if Prg = N then
2746                   return True;
2747                elsif Nkind (Prg) /= N_Pragma then
2748                   return False;
2749                end if;
2750
2751                Next (Prg);
2752             end loop;
2753
2754          else
2755             return False;
2756          end if;
2757       end Is_Configuration_Pragma;
2758
2759       --------------------------
2760       -- Is_In_Context_Clause --
2761       --------------------------
2762
2763       function Is_In_Context_Clause return Boolean is
2764          Plist       : List_Id;
2765          Parent_Node : Node_Id;
2766
2767       begin
2768          if not Is_List_Member (N) then
2769             return False;
2770
2771          else
2772             Plist := List_Containing (N);
2773             Parent_Node := Parent (Plist);
2774
2775             if Parent_Node = Empty
2776               or else Nkind (Parent_Node) /= N_Compilation_Unit
2777               or else Context_Items (Parent_Node) /= Plist
2778             then
2779                return False;
2780             end if;
2781          end if;
2782
2783          return True;
2784       end Is_In_Context_Clause;
2785
2786       ---------------------------------
2787       -- Is_Static_String_Expression --
2788       ---------------------------------
2789
2790       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2791          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2792
2793       begin
2794          Analyze_And_Resolve (Argx);
2795          return Is_OK_Static_Expression (Argx)
2796            and then Nkind (Argx) = N_String_Literal;
2797       end Is_Static_String_Expression;
2798
2799       ----------------------
2800       -- Pragma_Misplaced --
2801       ----------------------
2802
2803       procedure Pragma_Misplaced is
2804       begin
2805          Error_Pragma ("incorrect placement of pragma%");
2806       end Pragma_Misplaced;
2807
2808       ------------------------------------
2809       -- Process Atomic_Shared_Volatile --
2810       ------------------------------------
2811
2812       procedure Process_Atomic_Shared_Volatile is
2813          E_Id : Node_Id;
2814          E    : Entity_Id;
2815          D    : Node_Id;
2816          K    : Node_Kind;
2817          Utyp : Entity_Id;
2818
2819          procedure Set_Atomic (E : Entity_Id);
2820          --  Set given type as atomic, and if no explicit alignment was given,
2821          --  set alignment to unknown, since back end knows what the alignment
2822          --  requirements are for atomic arrays. Note: this step is necessary
2823          --  for derived types.
2824
2825          ----------------
2826          -- Set_Atomic --
2827          ----------------
2828
2829          procedure Set_Atomic (E : Entity_Id) is
2830          begin
2831             Set_Is_Atomic (E);
2832
2833             if not Has_Alignment_Clause (E) then
2834                Set_Alignment (E, Uint_0);
2835             end if;
2836          end Set_Atomic;
2837
2838       --  Start of processing for Process_Atomic_Shared_Volatile
2839
2840       begin
2841          Check_Ada_83_Warning;
2842          Check_No_Identifiers;
2843          Check_Arg_Count (1);
2844          Check_Arg_Is_Local_Name (Arg1);
2845          E_Id := Get_Pragma_Arg (Arg1);
2846
2847          if Etype (E_Id) = Any_Type then
2848             return;
2849          end if;
2850
2851          E := Entity (E_Id);
2852          D := Declaration_Node (E);
2853          K := Nkind (D);
2854
2855          --  Check duplicate before we chain ourselves!
2856
2857          Check_Duplicate_Pragma (E);
2858
2859          --  Now check appropriateness of the entity
2860
2861          if Is_Type (E) then
2862             if Rep_Item_Too_Early (E, N)
2863                  or else
2864                Rep_Item_Too_Late (E, N)
2865             then
2866                return;
2867             else
2868                Check_First_Subtype (Arg1);
2869             end if;
2870
2871             if Prag_Id /= Pragma_Volatile then
2872                Set_Atomic (E);
2873                Set_Atomic (Underlying_Type (E));
2874                Set_Atomic (Base_Type (E));
2875             end if;
2876
2877             --  Attribute belongs on the base type. If the view of the type is
2878             --  currently private, it also belongs on the underlying type.
2879
2880             Set_Is_Volatile (Base_Type (E));
2881             Set_Is_Volatile (Underlying_Type (E));
2882
2883             Set_Treat_As_Volatile (E);
2884             Set_Treat_As_Volatile (Underlying_Type (E));
2885
2886          elsif K = N_Object_Declaration
2887            or else (K = N_Component_Declaration
2888                      and then Original_Record_Component (E) = E)
2889          then
2890             if Rep_Item_Too_Late (E, N) then
2891                return;
2892             end if;
2893
2894             if Prag_Id /= Pragma_Volatile then
2895                Set_Is_Atomic (E);
2896
2897                --  If the object declaration has an explicit initialization, a
2898                --  temporary may have to be created to hold the expression, to
2899                --  ensure that access to the object remain atomic.
2900
2901                if Nkind (Parent (E)) = N_Object_Declaration
2902                  and then Present (Expression (Parent (E)))
2903                then
2904                   Set_Has_Delayed_Freeze (E);
2905                end if;
2906
2907                --  An interesting improvement here. If an object of type X is
2908                --  declared atomic, and the type X is not atomic, that's a
2909                --  pity, since it may not have appropriate alignment etc. We
2910                --  can rescue this in the special case where the object and
2911                --  type are in the same unit by just setting the type as
2912                --  atomic, so that the back end will process it as atomic.
2913
2914                Utyp := Underlying_Type (Etype (E));
2915
2916                if Present (Utyp)
2917                  and then Sloc (E) > No_Location
2918                  and then Sloc (Utyp) > No_Location
2919                  and then
2920                    Get_Source_File_Index (Sloc (E)) =
2921                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2922                then
2923                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2924                end if;
2925             end if;
2926
2927             Set_Is_Volatile (E);
2928             Set_Treat_As_Volatile (E);
2929
2930          else
2931             Error_Pragma_Arg
2932               ("inappropriate entity for pragma%", Arg1);
2933          end if;
2934       end Process_Atomic_Shared_Volatile;
2935
2936       -------------------------------------------
2937       -- Process_Compile_Time_Warning_Or_Error --
2938       -------------------------------------------
2939
2940       procedure Process_Compile_Time_Warning_Or_Error is
2941          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2942
2943       begin
2944          Check_Arg_Count (2);
2945          Check_No_Identifiers;
2946          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2947          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2948
2949          if Compile_Time_Known_Value (Arg1x) then
2950             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2951                declare
2952                   Str   : constant String_Id :=
2953                             Strval (Get_Pragma_Arg (Arg2));
2954                   Len   : constant Int := String_Length (Str);
2955                   Cont  : Boolean;
2956                   Ptr   : Nat;
2957                   CC    : Char_Code;
2958                   C     : Character;
2959                   Cent  : constant Entity_Id :=
2960                             Cunit_Entity (Current_Sem_Unit);
2961
2962                   Force : constant Boolean :=
2963                             Prag_Id = Pragma_Compile_Time_Warning
2964                               and then
2965                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2966                               and then (Ekind (Cent) /= E_Package
2967                                           or else not In_Private_Part (Cent));
2968                   --  Set True if this is the warning case, and we are in the
2969                   --  visible part of a package spec, or in a subprogram spec,
2970                   --  in which case we want to force the client to see the
2971                   --  warning, even though it is not in the main unit.
2972
2973                begin
2974                   --  Loop through segments of message separated by line feeds.
2975                   --  We output these segments as separate messages with
2976                   --  continuation marks for all but the first.
2977
2978                   Cont := False;
2979                   Ptr := 1;
2980                   loop
2981                      Error_Msg_Strlen := 0;
2982
2983                      --  Loop to copy characters from argument to error message
2984                      --  string buffer.
2985
2986                      loop
2987                         exit when Ptr > Len;
2988                         CC := Get_String_Char (Str, Ptr);
2989                         Ptr := Ptr + 1;
2990
2991                         --  Ignore wide chars ??? else store character
2992
2993                         if In_Character_Range (CC) then
2994                            C := Get_Character (CC);
2995                            exit when C = ASCII.LF;
2996                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
2997                            Error_Msg_String (Error_Msg_Strlen) := C;
2998                         end if;
2999                      end loop;
3000
3001                      --  Here with one line ready to go
3002
3003                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3004
3005                      --  If this is a warning in a spec, then we want clients
3006                      --  to see the warning, so mark the message with the
3007                      --  special sequence !! to force the warning. In the case
3008                      --  of a package spec, we do not force this if we are in
3009                      --  the private part of the spec.
3010
3011                      if Force then
3012                         if Cont = False then
3013                            Error_Msg_N ("<~!!", Arg1);
3014                            Cont := True;
3015                         else
3016                            Error_Msg_N ("\<~!!", Arg1);
3017                         end if;
3018
3019                      --  Error, rather than warning, or in a body, so we do not
3020                      --  need to force visibility for client (error will be
3021                      --  output in any case, and this is the situation in which
3022                      --  we do not want a client to get a warning, since the
3023                      --  warning is in the body or the spec private part).
3024
3025                      else
3026                         if Cont = False then
3027                            Error_Msg_N ("<~", Arg1);
3028                            Cont := True;
3029                         else
3030                            Error_Msg_N ("\<~", Arg1);
3031                         end if;
3032                      end if;
3033
3034                      exit when Ptr > Len;
3035                   end loop;
3036                end;
3037             end if;
3038          end if;
3039       end Process_Compile_Time_Warning_Or_Error;
3040
3041       ------------------------
3042       -- Process_Convention --
3043       ------------------------
3044
3045       procedure Process_Convention
3046         (C   : out Convention_Id;
3047          Ent : out Entity_Id)
3048       is
3049          Id        : Node_Id;
3050          E         : Entity_Id;
3051          E1        : Entity_Id;
3052          Cname     : Name_Id;
3053          Comp_Unit : Unit_Number_Type;
3054
3055          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3056          --  Called if we have more than one Export/Import/Convention pragma.
3057          --  This is generally illegal, but we have a special case of allowing
3058          --  Import and Interface to coexist if they specify the convention in
3059          --  a consistent manner. We are allowed to do this, since Interface is
3060          --  an implementation defined pragma, and we choose to do it since we
3061          --  know Rational allows this combination. S is the entity id of the
3062          --  subprogram in question. This procedure also sets the special flag
3063          --  Import_Interface_Present in both pragmas in the case where we do
3064          --  have matching Import and Interface pragmas.
3065
3066          procedure Set_Convention_From_Pragma (E : Entity_Id);
3067          --  Set convention in entity E, and also flag that the entity has a
3068          --  convention pragma. If entity is for a private or incomplete type,
3069          --  also set convention and flag on underlying type. This procedure
3070          --  also deals with the special case of C_Pass_By_Copy convention.
3071
3072          -------------------------------
3073          -- Diagnose_Multiple_Pragmas --
3074          -------------------------------
3075
3076          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3077             Pdec : constant Node_Id := Declaration_Node (S);
3078             Decl : Node_Id;
3079             Err  : Boolean;
3080
3081             function Same_Convention (Decl : Node_Id) return Boolean;
3082             --  Decl is a pragma node. This function returns True if this
3083             --  pragma has a first argument that is an identifier with a
3084             --  Chars field corresponding to the Convention_Id C.
3085
3086             function Same_Name (Decl : Node_Id) return Boolean;
3087             --  Decl is a pragma node. This function returns True if this
3088             --  pragma has a second argument that is an identifier with a
3089             --  Chars field that matches the Chars of the current subprogram.
3090
3091             ---------------------
3092             -- Same_Convention --
3093             ---------------------
3094
3095             function Same_Convention (Decl : Node_Id) return Boolean is
3096                Arg1 : constant Node_Id :=
3097                         First (Pragma_Argument_Associations (Decl));
3098
3099             begin
3100                if Present (Arg1) then
3101                   declare
3102                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3103                   begin
3104                      if Nkind (Arg) = N_Identifier
3105                        and then Is_Convention_Name (Chars (Arg))
3106                        and then Get_Convention_Id (Chars (Arg)) = C
3107                      then
3108                         return True;
3109                      end if;
3110                   end;
3111                end if;
3112
3113                return False;
3114             end Same_Convention;
3115
3116             ---------------
3117             -- Same_Name --
3118             ---------------
3119
3120             function Same_Name (Decl : Node_Id) return Boolean is
3121                Arg1 : constant Node_Id :=
3122                         First (Pragma_Argument_Associations (Decl));
3123                Arg2 : Node_Id;
3124
3125             begin
3126                if No (Arg1) then
3127                   return False;
3128                end if;
3129
3130                Arg2 := Next (Arg1);
3131
3132                if No (Arg2) then
3133                   return False;
3134                end if;
3135
3136                declare
3137                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3138                begin
3139                   if Nkind (Arg) = N_Identifier
3140                     and then Chars (Arg) = Chars (S)
3141                   then
3142                      return True;
3143                   end if;
3144                end;
3145
3146                return False;
3147             end Same_Name;
3148
3149          --  Start of processing for Diagnose_Multiple_Pragmas
3150
3151          begin
3152             Err := True;
3153
3154             --  Definitely give message if we have Convention/Export here
3155
3156             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3157                null;
3158
3159                --  If we have an Import or Export, scan back from pragma to
3160                --  find any previous pragma applying to the same procedure.
3161                --  The scan will be terminated by the start of the list, or
3162                --  hitting the subprogram declaration. This won't allow one
3163                --  pragma to appear in the public part and one in the private
3164                --  part, but that seems very unlikely in practice.
3165
3166             else
3167                Decl := Prev (N);
3168                while Present (Decl) and then Decl /= Pdec loop
3169
3170                   --  Look for pragma with same name as us
3171
3172                   if Nkind (Decl) = N_Pragma
3173                     and then Same_Name (Decl)
3174                   then
3175                      --  Give error if same as our pragma or Export/Convention
3176
3177                      if Pragma_Name (Decl) = Name_Export
3178                           or else
3179                         Pragma_Name (Decl) = Name_Convention
3180                           or else
3181                         Pragma_Name (Decl) = Pragma_Name (N)
3182                      then
3183                         exit;
3184
3185                      --  Case of Import/Interface or the other way round
3186
3187                      elsif Pragma_Name (Decl) = Name_Interface
3188                              or else
3189                            Pragma_Name (Decl) = Name_Import
3190                      then
3191                         --  Here we know that we have Import and Interface. It
3192                         --  doesn't matter which way round they are. See if
3193                         --  they specify the same convention. If so, all OK,
3194                         --  and set special flags to stop other messages
3195
3196                         if Same_Convention (Decl) then
3197                            Set_Import_Interface_Present (N);
3198                            Set_Import_Interface_Present (Decl);
3199                            Err := False;
3200
3201                         --  If different conventions, special message
3202
3203                         else
3204                            Error_Msg_Sloc := Sloc (Decl);
3205                            Error_Pragma_Arg
3206                              ("convention differs from that given#", Arg1);
3207                            return;
3208                         end if;
3209                      end if;
3210                   end if;
3211
3212                   Next (Decl);
3213                end loop;
3214             end if;
3215
3216             --  Give message if needed if we fall through those tests
3217
3218             if Err then
3219                Error_Pragma_Arg
3220                  ("at most one Convention/Export/Import pragma is allowed",
3221                   Arg2);
3222             end if;
3223          end Diagnose_Multiple_Pragmas;
3224
3225          --------------------------------
3226          -- Set_Convention_From_Pragma --
3227          --------------------------------
3228
3229          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3230          begin
3231             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3232             --  for an overridden dispatching operation. Technically this is
3233             --  an amendment and should only be done in Ada 2005 mode. However,
3234             --  this is clearly a mistake, since the problem that is addressed
3235             --  by this AI is that there is a clear gap in the RM!
3236
3237             if Is_Dispatching_Operation (E)
3238               and then Present (Overridden_Operation (E))
3239               and then C /= Convention (Overridden_Operation (E))
3240             then
3241                Error_Pragma_Arg
3242                  ("cannot change convention for " &
3243                   "overridden dispatching operation",
3244                   Arg1);
3245             end if;
3246
3247             --  Set the convention
3248
3249             Set_Convention (E, C);
3250             Set_Has_Convention_Pragma (E);
3251
3252             if Is_Incomplete_Or_Private_Type (E)
3253               and then Present (Underlying_Type (E))
3254             then
3255                Set_Convention            (Underlying_Type (E), C);
3256                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3257             end if;
3258
3259             --  A class-wide type should inherit the convention of the specific
3260             --  root type (although this isn't specified clearly by the RM).
3261
3262             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3263                Set_Convention (Class_Wide_Type (E), C);
3264             end if;
3265
3266             --  If the entity is a record type, then check for special case of
3267             --  C_Pass_By_Copy, which is treated the same as C except that the
3268             --  special record flag is set. This convention is only permitted
3269             --  on record types (see AI95-00131).
3270
3271             if Cname = Name_C_Pass_By_Copy then
3272                if Is_Record_Type (E) then
3273                   Set_C_Pass_By_Copy (Base_Type (E));
3274                elsif Is_Incomplete_Or_Private_Type (E)
3275                  and then Is_Record_Type (Underlying_Type (E))
3276                then
3277                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3278                else
3279                   Error_Pragma_Arg
3280                     ("C_Pass_By_Copy convention allowed only for record type",
3281                      Arg2);
3282                end if;
3283             end if;
3284
3285             --  If the entity is a derived boolean type, check for the special
3286             --  case of convention C, C++, or Fortran, where we consider any
3287             --  nonzero value to represent true.
3288
3289             if Is_Discrete_Type (E)
3290               and then Root_Type (Etype (E)) = Standard_Boolean
3291               and then
3292                 (C = Convention_C
3293                    or else
3294                  C = Convention_CPP
3295                    or else
3296                  C = Convention_Fortran)
3297             then
3298                Set_Nonzero_Is_True (Base_Type (E));
3299             end if;
3300          end Set_Convention_From_Pragma;
3301
3302       --  Start of processing for Process_Convention
3303
3304       begin
3305          Check_At_Least_N_Arguments (2);
3306          Check_Optional_Identifier (Arg1, Name_Convention);
3307          Check_Arg_Is_Identifier (Arg1);
3308          Cname := Chars (Get_Pragma_Arg (Arg1));
3309
3310          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3311          --  tested again below to set the critical flag).
3312
3313          if Cname = Name_C_Pass_By_Copy then
3314             C := Convention_C;
3315
3316          --  Otherwise we must have something in the standard convention list
3317
3318          elsif Is_Convention_Name (Cname) then
3319             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3320
3321          --  In DEC VMS, it seems that there is an undocumented feature that
3322          --  any unrecognized convention is treated as the default, which for
3323          --  us is convention C. It does not seem so terrible to do this
3324          --  unconditionally, silently in the VMS case, and with a warning
3325          --  in the non-VMS case.
3326
3327          else
3328             if Warn_On_Export_Import and not OpenVMS_On_Target then
3329                Error_Msg_N
3330                  ("?unrecognized convention name, C assumed",
3331                   Get_Pragma_Arg (Arg1));
3332             end if;
3333
3334             C := Convention_C;
3335          end if;
3336
3337          Check_Optional_Identifier (Arg2, Name_Entity);
3338          Check_Arg_Is_Local_Name (Arg2);
3339
3340          Id := Get_Pragma_Arg (Arg2);
3341          Analyze (Id);
3342
3343          if not Is_Entity_Name (Id) then
3344             Error_Pragma_Arg ("entity name required", Arg2);
3345          end if;
3346
3347          E := Entity (Id);
3348
3349          --  Set entity to return
3350
3351          Ent := E;
3352
3353          --  Ada_Pass_By_Copy special checking
3354
3355          if C = Convention_Ada_Pass_By_Copy then
3356             if not Is_First_Subtype (E) then
3357                Error_Pragma_Arg
3358                  ("convention `Ada_Pass_By_Copy` only "
3359                   & "allowed for types", Arg2);
3360             end if;
3361
3362             if Is_By_Reference_Type (E) then
3363                Error_Pragma_Arg
3364                  ("convention `Ada_Pass_By_Copy` not allowed for "
3365                   & "by-reference type", Arg1);
3366             end if;
3367          end if;
3368
3369          --  Ada_Pass_By_Reference special checking
3370
3371          if C = Convention_Ada_Pass_By_Reference then
3372             if not Is_First_Subtype (E) then
3373                Error_Pragma_Arg
3374                  ("convention `Ada_Pass_By_Reference` only "
3375                   & "allowed for types", Arg2);
3376             end if;
3377
3378             if Is_By_Copy_Type (E) then
3379                Error_Pragma_Arg
3380                  ("convention `Ada_Pass_By_Reference` not allowed for "
3381                   & "by-copy type", Arg1);
3382             end if;
3383          end if;
3384
3385          --  Go to renamed subprogram if present, since convention applies to
3386          --  the actual renamed entity, not to the renaming entity. If the
3387          --  subprogram is inherited, go to parent subprogram.
3388
3389          if Is_Subprogram (E)
3390            and then Present (Alias (E))
3391          then
3392             if Nkind (Parent (Declaration_Node (E))) =
3393                                        N_Subprogram_Renaming_Declaration
3394             then
3395                if Scope (E) /= Scope (Alias (E)) then
3396                   Error_Pragma_Ref
3397                     ("cannot apply pragma% to non-local entity&#", E);
3398                end if;
3399
3400                E := Alias (E);
3401
3402             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3403                                         N_Private_Extension_Declaration)
3404               and then Scope (E) = Scope (Alias (E))
3405             then
3406                E := Alias (E);
3407
3408                --  Return the parent subprogram the entity was inherited from
3409
3410                Ent := E;
3411             end if;
3412          end if;
3413
3414          --  Check that we are not applying this to a specless body
3415
3416          if Is_Subprogram (E)
3417            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3418          then
3419             Error_Pragma
3420               ("pragma% requires separate spec and must come before body");
3421          end if;
3422
3423          --  Check that we are not applying this to a named constant
3424
3425          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3426             Error_Msg_Name_1 := Pname;
3427             Error_Msg_N
3428               ("cannot apply pragma% to named constant!",
3429                Get_Pragma_Arg (Arg2));
3430             Error_Pragma_Arg
3431               ("\supply appropriate type for&!", Arg2);
3432          end if;
3433
3434          if Ekind (E) = E_Enumeration_Literal then
3435             Error_Pragma ("enumeration literal not allowed for pragma%");
3436          end if;
3437
3438          --  Check for rep item appearing too early or too late
3439
3440          if Etype (E) = Any_Type
3441            or else Rep_Item_Too_Early (E, N)
3442          then
3443             raise Pragma_Exit;
3444
3445          elsif Present (Underlying_Type (E)) then
3446             E := Underlying_Type (E);
3447          end if;
3448
3449          if Rep_Item_Too_Late (E, N) then
3450             raise Pragma_Exit;
3451          end if;
3452
3453          if Has_Convention_Pragma (E) then
3454             Diagnose_Multiple_Pragmas (E);
3455
3456          elsif Convention (E) = Convention_Protected
3457            or else Ekind (Scope (E)) = E_Protected_Type
3458          then
3459             Error_Pragma_Arg
3460               ("a protected operation cannot be given a different convention",
3461                 Arg2);
3462          end if;
3463
3464          --  For Intrinsic, a subprogram is required
3465
3466          if C = Convention_Intrinsic
3467            and then not Is_Subprogram (E)
3468            and then not Is_Generic_Subprogram (E)
3469          then
3470             Error_Pragma_Arg
3471               ("second argument of pragma% must be a subprogram", Arg2);
3472          end if;
3473
3474          --  For Stdcall, a subprogram, variable or subprogram type is required
3475
3476          if C = Convention_Stdcall
3477            and then not Is_Subprogram (E)
3478            and then not Is_Generic_Subprogram (E)
3479            and then Ekind (E) /= E_Variable
3480            and then not
3481              (Is_Access_Type (E)
3482                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3483          then
3484             Error_Pragma_Arg
3485               ("second argument of pragma% must be subprogram (type)",
3486                Arg2);
3487          end if;
3488
3489          if not Is_Subprogram (E)
3490            and then not Is_Generic_Subprogram (E)
3491          then
3492             Set_Convention_From_Pragma (E);
3493
3494             if Is_Type (E) then
3495                Check_First_Subtype (Arg2);
3496                Set_Convention_From_Pragma (Base_Type (E));
3497
3498                --  For subprograms, we must set the convention on the
3499                --  internally generated directly designated type as well.
3500
3501                if Ekind (E) = E_Access_Subprogram_Type then
3502                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3503                end if;
3504             end if;
3505
3506          --  For the subprogram case, set proper convention for all homonyms
3507          --  in same scope and the same declarative part, i.e. the same
3508          --  compilation unit.
3509
3510          else
3511             Comp_Unit := Get_Source_Unit (E);
3512             Set_Convention_From_Pragma (E);
3513
3514             --  Treat a pragma Import as an implicit body, for GPS use
3515
3516             if Prag_Id = Pragma_Import then
3517                Generate_Reference (E, Id, 'b');
3518             end if;
3519
3520             --  Loop through the homonyms of the pragma argument's entity
3521
3522             E1 := Ent;
3523             loop
3524                E1 := Homonym (E1);
3525                exit when No (E1) or else Scope (E1) /= Current_Scope;
3526
3527                --  Do not set the pragma on inherited operations or on formal
3528                --  subprograms.
3529
3530                if Comes_From_Source (E1)
3531                  and then Comp_Unit = Get_Source_Unit (E1)
3532                  and then not Is_Formal_Subprogram (E1)
3533                  and then Nkind (Original_Node (Parent (E1))) /=
3534                                                     N_Full_Type_Declaration
3535                then
3536                   if Present (Alias (E1))
3537                     and then Scope (E1) /= Scope (Alias (E1))
3538                   then
3539                      Error_Pragma_Ref
3540                        ("cannot apply pragma% to non-local entity& declared#",
3541                         E1);
3542                   end if;
3543
3544                   Set_Convention_From_Pragma (E1);
3545
3546                   if Prag_Id = Pragma_Import then
3547                      Generate_Reference (E1, Id, 'b');
3548                   end if;
3549                end if;
3550
3551                --  For aspect case, do NOT apply to homonyms
3552
3553                exit when From_Aspect_Specification (N);
3554             end loop;
3555          end if;
3556       end Process_Convention;
3557
3558       -----------------------------------------------------
3559       -- Process_Extended_Import_Export_Exception_Pragma --
3560       -----------------------------------------------------
3561
3562       procedure Process_Extended_Import_Export_Exception_Pragma
3563         (Arg_Internal : Node_Id;
3564          Arg_External : Node_Id;
3565          Arg_Form     : Node_Id;
3566          Arg_Code     : Node_Id)
3567       is
3568          Def_Id   : Entity_Id;
3569          Code_Val : Uint;
3570
3571       begin
3572          if not OpenVMS_On_Target then
3573             Error_Pragma
3574               ("?pragma% ignored (applies only to Open'V'M'S)");
3575          end if;
3576
3577          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3578          Def_Id := Entity (Arg_Internal);
3579
3580          if Ekind (Def_Id) /= E_Exception then
3581             Error_Pragma_Arg
3582               ("pragma% must refer to declared exception", Arg_Internal);
3583          end if;
3584
3585          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3586
3587          if Present (Arg_Form) then
3588             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3589          end if;
3590
3591          if Present (Arg_Form)
3592            and then Chars (Arg_Form) = Name_Ada
3593          then
3594             null;
3595          else
3596             Set_Is_VMS_Exception (Def_Id);
3597             Set_Exception_Code (Def_Id, No_Uint);
3598          end if;
3599
3600          if Present (Arg_Code) then
3601             if not Is_VMS_Exception (Def_Id) then
3602                Error_Pragma_Arg
3603                  ("Code option for pragma% not allowed for Ada case",
3604                   Arg_Code);
3605             end if;
3606
3607             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3608             Code_Val := Expr_Value (Arg_Code);
3609
3610             if not UI_Is_In_Int_Range (Code_Val) then
3611                Error_Pragma_Arg
3612                  ("Code option for pragma% must be in 32-bit range",
3613                   Arg_Code);
3614
3615             else
3616                Set_Exception_Code (Def_Id, Code_Val);
3617             end if;
3618          end if;
3619       end Process_Extended_Import_Export_Exception_Pragma;
3620
3621       -------------------------------------------------
3622       -- Process_Extended_Import_Export_Internal_Arg --
3623       -------------------------------------------------
3624
3625       procedure Process_Extended_Import_Export_Internal_Arg
3626         (Arg_Internal : Node_Id := Empty)
3627       is
3628       begin
3629          if No (Arg_Internal) then
3630             Error_Pragma ("Internal parameter required for pragma%");
3631          end if;
3632
3633          if Nkind (Arg_Internal) = N_Identifier then
3634             null;
3635
3636          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3637            and then (Prag_Id = Pragma_Import_Function
3638                        or else
3639                      Prag_Id = Pragma_Export_Function)
3640          then
3641             null;
3642
3643          else
3644             Error_Pragma_Arg
3645               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3646          end if;
3647
3648          Check_Arg_Is_Local_Name (Arg_Internal);
3649       end Process_Extended_Import_Export_Internal_Arg;
3650
3651       --------------------------------------------------
3652       -- Process_Extended_Import_Export_Object_Pragma --
3653       --------------------------------------------------
3654
3655       procedure Process_Extended_Import_Export_Object_Pragma
3656         (Arg_Internal : Node_Id;
3657          Arg_External : Node_Id;
3658          Arg_Size     : Node_Id)
3659       is
3660          Def_Id : Entity_Id;
3661
3662       begin
3663          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3664          Def_Id := Entity (Arg_Internal);
3665
3666          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3667             Error_Pragma_Arg
3668               ("pragma% must designate an object", Arg_Internal);
3669          end if;
3670
3671          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3672               or else
3673             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3674          then
3675             Error_Pragma_Arg
3676               ("previous Common/Psect_Object applies, pragma % not permitted",
3677                Arg_Internal);
3678          end if;
3679
3680          if Rep_Item_Too_Late (Def_Id, N) then
3681             raise Pragma_Exit;
3682          end if;
3683
3684          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3685
3686          if Present (Arg_Size) then
3687             Check_Arg_Is_External_Name (Arg_Size);
3688          end if;
3689
3690          --  Export_Object case
3691
3692          if Prag_Id = Pragma_Export_Object then
3693             if not Is_Library_Level_Entity (Def_Id) then
3694                Error_Pragma_Arg
3695                  ("argument for pragma% must be library level entity",
3696                   Arg_Internal);
3697             end if;
3698
3699             if Ekind (Current_Scope) = E_Generic_Package then
3700                Error_Pragma ("pragma& cannot appear in a generic unit");
3701             end if;
3702
3703             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3704                Error_Pragma_Arg
3705                  ("exported object must have compile time known size",
3706                   Arg_Internal);
3707             end if;
3708
3709             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3710                Error_Msg_N ("?duplicate Export_Object pragma", N);
3711             else
3712                Set_Exported (Def_Id, Arg_Internal);
3713             end if;
3714
3715          --  Import_Object case
3716
3717          else
3718             if Is_Concurrent_Type (Etype (Def_Id)) then
3719                Error_Pragma_Arg
3720                  ("cannot use pragma% for task/protected object",
3721                   Arg_Internal);
3722             end if;
3723
3724             if Ekind (Def_Id) = E_Constant then
3725                Error_Pragma_Arg
3726                  ("cannot import a constant", Arg_Internal);
3727             end if;
3728
3729             if Warn_On_Export_Import
3730               and then Has_Discriminants (Etype (Def_Id))
3731             then
3732                Error_Msg_N
3733                  ("imported value must be initialized?", Arg_Internal);
3734             end if;
3735
3736             if Warn_On_Export_Import
3737               and then Is_Access_Type (Etype (Def_Id))
3738             then
3739                Error_Pragma_Arg
3740                  ("cannot import object of an access type?", Arg_Internal);
3741             end if;
3742
3743             if Warn_On_Export_Import
3744               and then Is_Imported (Def_Id)
3745             then
3746                Error_Msg_N
3747                  ("?duplicate Import_Object pragma", N);
3748
3749             --  Check for explicit initialization present. Note that an
3750             --  initialization generated by the code generator, e.g. for an
3751             --  access type, does not count here.
3752
3753             elsif Present (Expression (Parent (Def_Id)))
3754                and then
3755                  Comes_From_Source
3756                    (Original_Node (Expression (Parent (Def_Id))))
3757             then
3758                Error_Msg_Sloc := Sloc (Def_Id);
3759                Error_Pragma_Arg
3760                  ("imported entities cannot be initialized (RM B.1(24))",
3761                   "\no initialization allowed for & declared#", Arg1);
3762             else
3763                Set_Imported (Def_Id);
3764                Note_Possible_Modification (Arg_Internal, Sure => False);
3765             end if;
3766          end if;
3767       end Process_Extended_Import_Export_Object_Pragma;
3768
3769       ------------------------------------------------------
3770       -- Process_Extended_Import_Export_Subprogram_Pragma --
3771       ------------------------------------------------------
3772
3773       procedure Process_Extended_Import_Export_Subprogram_Pragma
3774         (Arg_Internal                 : Node_Id;
3775          Arg_External                 : Node_Id;
3776          Arg_Parameter_Types          : Node_Id;
3777          Arg_Result_Type              : Node_Id := Empty;
3778          Arg_Mechanism                : Node_Id;
3779          Arg_Result_Mechanism         : Node_Id := Empty;
3780          Arg_First_Optional_Parameter : Node_Id := Empty)
3781       is
3782          Ent       : Entity_Id;
3783          Def_Id    : Entity_Id;
3784          Hom_Id    : Entity_Id;
3785          Formal    : Entity_Id;
3786          Ambiguous : Boolean;
3787          Match     : Boolean;
3788          Dval      : Node_Id;
3789
3790          function Same_Base_Type
3791           (Ptype  : Node_Id;
3792            Formal : Entity_Id) return Boolean;
3793          --  Determines if Ptype references the type of Formal. Note that only
3794          --  the base types need to match according to the spec. Ptype here is
3795          --  the argument from the pragma, which is either a type name, or an
3796          --  access attribute.
3797
3798          --------------------
3799          -- Same_Base_Type --
3800          --------------------
3801
3802          function Same_Base_Type
3803            (Ptype  : Node_Id;
3804             Formal : Entity_Id) return Boolean
3805          is
3806             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3807             Pref : Node_Id;
3808
3809          begin
3810             --  Case where pragma argument is typ'Access
3811
3812             if Nkind (Ptype) = N_Attribute_Reference
3813               and then Attribute_Name (Ptype) = Name_Access
3814             then
3815                Pref := Prefix (Ptype);
3816                Find_Type (Pref);
3817
3818                if not Is_Entity_Name (Pref)
3819                  or else Entity (Pref) = Any_Type
3820                then
3821                   raise Pragma_Exit;
3822                end if;
3823
3824                --  We have a match if the corresponding argument is of an
3825                --  anonymous access type, and its designated type matches the
3826                --  type of the prefix of the access attribute
3827
3828                return Ekind (Ftyp) = E_Anonymous_Access_Type
3829                  and then Base_Type (Entity (Pref)) =
3830                             Base_Type (Etype (Designated_Type (Ftyp)));
3831
3832             --  Case where pragma argument is a type name
3833
3834             else
3835                Find_Type (Ptype);
3836
3837                if not Is_Entity_Name (Ptype)
3838                  or else Entity (Ptype) = Any_Type
3839                then
3840                   raise Pragma_Exit;
3841                end if;
3842
3843                --  We have a match if the corresponding argument is of the type
3844                --  given in the pragma (comparing base types)
3845
3846                return Base_Type (Entity (Ptype)) = Ftyp;
3847             end if;
3848          end Same_Base_Type;
3849
3850       --  Start of processing for
3851       --  Process_Extended_Import_Export_Subprogram_Pragma
3852
3853       begin
3854          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3855          Ent := Empty;
3856          Ambiguous := False;
3857
3858          --  Loop through homonyms (overloadings) of the entity
3859
3860          Hom_Id := Entity (Arg_Internal);
3861          while Present (Hom_Id) loop
3862             Def_Id := Get_Base_Subprogram (Hom_Id);
3863
3864             --  We need a subprogram in the current scope
3865
3866             if not Is_Subprogram (Def_Id)
3867               or else Scope (Def_Id) /= Current_Scope
3868             then
3869                null;
3870
3871             else
3872                Match := True;
3873
3874                --  Pragma cannot apply to subprogram body
3875
3876                if Is_Subprogram (Def_Id)
3877                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3878                                                              N_Subprogram_Body
3879                then
3880                   Error_Pragma
3881                     ("pragma% requires separate spec"
3882                       & " and must come before body");
3883                end if;
3884
3885                --  Test result type if given, note that the result type
3886                --  parameter can only be present for the function cases.
3887
3888                if Present (Arg_Result_Type)
3889                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3890                then
3891                   Match := False;
3892
3893                elsif Etype (Def_Id) /= Standard_Void_Type
3894                  and then
3895                    (Pname = Name_Export_Procedure
3896                       or else
3897                     Pname = Name_Import_Procedure)
3898                then
3899                   Match := False;
3900
3901                --  Test parameter types if given. Note that this parameter
3902                --  has not been analyzed (and must not be, since it is
3903                --  semantic nonsense), so we get it as the parser left it.
3904
3905                elsif Present (Arg_Parameter_Types) then
3906                   Check_Matching_Types : declare
3907                      Formal : Entity_Id;
3908                      Ptype  : Node_Id;
3909
3910                   begin
3911                      Formal := First_Formal (Def_Id);
3912
3913                      if Nkind (Arg_Parameter_Types) = N_Null then
3914                         if Present (Formal) then
3915                            Match := False;
3916                         end if;
3917
3918                      --  A list of one type, e.g. (List) is parsed as
3919                      --  a parenthesized expression.
3920
3921                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3922                        and then Paren_Count (Arg_Parameter_Types) = 1
3923                      then
3924                         if No (Formal)
3925                           or else Present (Next_Formal (Formal))
3926                         then
3927                            Match := False;
3928                         else
3929                            Match :=
3930                              Same_Base_Type (Arg_Parameter_Types, Formal);
3931                         end if;
3932
3933                      --  A list of more than one type is parsed as a aggregate
3934
3935                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3936                        and then Paren_Count (Arg_Parameter_Types) = 0
3937                      then
3938                         Ptype := First (Expressions (Arg_Parameter_Types));
3939                         while Present (Ptype) or else Present (Formal) loop
3940                            if No (Ptype)
3941                              or else No (Formal)
3942                              or else not Same_Base_Type (Ptype, Formal)
3943                            then
3944                               Match := False;
3945                               exit;
3946                            else
3947                               Next_Formal (Formal);
3948                               Next (Ptype);
3949                            end if;
3950                         end loop;
3951
3952                      --  Anything else is of the wrong form
3953
3954                      else
3955                         Error_Pragma_Arg
3956                           ("wrong form for Parameter_Types parameter",
3957                            Arg_Parameter_Types);
3958                      end if;
3959                   end Check_Matching_Types;
3960                end if;
3961
3962                --  Match is now False if the entry we found did not match
3963                --  either a supplied Parameter_Types or Result_Types argument
3964
3965                if Match then
3966                   if No (Ent) then
3967                      Ent := Def_Id;
3968
3969                   --  Ambiguous case, the flag Ambiguous shows if we already
3970                   --  detected this and output the initial messages.
3971
3972                   else
3973                      if not Ambiguous then
3974                         Ambiguous := True;
3975                         Error_Msg_Name_1 := Pname;
3976                         Error_Msg_N
3977                           ("pragma% does not uniquely identify subprogram!",
3978                            N);
3979                         Error_Msg_Sloc := Sloc (Ent);
3980                         Error_Msg_N ("matching subprogram #!", N);
3981                         Ent := Empty;
3982                      end if;
3983
3984                      Error_Msg_Sloc := Sloc (Def_Id);
3985                      Error_Msg_N ("matching subprogram #!", N);
3986                   end if;
3987                end if;
3988             end if;
3989
3990             Hom_Id := Homonym (Hom_Id);
3991          end loop;
3992
3993          --  See if we found an entry
3994
3995          if No (Ent) then
3996             if not Ambiguous then
3997                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3998                   Error_Pragma
3999                     ("pragma% cannot be given for generic subprogram");
4000                else
4001                   Error_Pragma
4002                     ("pragma% does not identify local subprogram");
4003                end if;
4004             end if;
4005
4006             return;
4007          end if;
4008
4009          --  Import pragmas must be for imported entities
4010
4011          if Prag_Id = Pragma_Import_Function
4012               or else
4013             Prag_Id = Pragma_Import_Procedure
4014               or else
4015             Prag_Id = Pragma_Import_Valued_Procedure
4016          then
4017             if not Is_Imported (Ent) then
4018                Error_Pragma
4019                  ("pragma Import or Interface must precede pragma%");
4020             end if;
4021
4022          --  Here we have the Export case which can set the entity as exported
4023
4024          --  But does not do so if the specified external name is null, since
4025          --  that is taken as a signal in DEC Ada 83 (with which we want to be
4026          --  compatible) to request no external name.
4027
4028          elsif Nkind (Arg_External) = N_String_Literal
4029            and then String_Length (Strval (Arg_External)) = 0
4030          then
4031             null;
4032
4033          --  In all other cases, set entity as exported
4034
4035          else
4036             Set_Exported (Ent, Arg_Internal);
4037          end if;
4038
4039          --  Special processing for Valued_Procedure cases
4040
4041          if Prag_Id = Pragma_Import_Valued_Procedure
4042            or else
4043             Prag_Id = Pragma_Export_Valued_Procedure
4044          then
4045             Formal := First_Formal (Ent);
4046
4047             if No (Formal) then
4048                Error_Pragma ("at least one parameter required for pragma%");
4049
4050             elsif Ekind (Formal) /= E_Out_Parameter then
4051                Error_Pragma ("first parameter must have mode out for pragma%");
4052
4053             else
4054                Set_Is_Valued_Procedure (Ent);
4055             end if;
4056          end if;
4057
4058          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4059
4060          --  Process Result_Mechanism argument if present. We have already
4061          --  checked that this is only allowed for the function case.
4062
4063          if Present (Arg_Result_Mechanism) then
4064             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4065          end if;
4066
4067          --  Process Mechanism parameter if present. Note that this parameter
4068          --  is not analyzed, and must not be analyzed since it is semantic
4069          --  nonsense, so we get it in exactly as the parser left it.
4070
4071          if Present (Arg_Mechanism) then
4072             declare
4073                Formal : Entity_Id;
4074                Massoc : Node_Id;
4075                Mname  : Node_Id;
4076                Choice : Node_Id;
4077
4078             begin
4079                --  A single mechanism association without a formal parameter
4080                --  name is parsed as a parenthesized expression. All other
4081                --  cases are parsed as aggregates, so we rewrite the single
4082                --  parameter case as an aggregate for consistency.
4083
4084                if Nkind (Arg_Mechanism) /= N_Aggregate
4085                  and then Paren_Count (Arg_Mechanism) = 1
4086                then
4087                   Rewrite (Arg_Mechanism,
4088                     Make_Aggregate (Sloc (Arg_Mechanism),
4089                       Expressions => New_List (
4090                         Relocate_Node (Arg_Mechanism))));
4091                end if;
4092
4093                --  Case of only mechanism name given, applies to all formals
4094
4095                if Nkind (Arg_Mechanism) /= N_Aggregate then
4096                   Formal := First_Formal (Ent);
4097                   while Present (Formal) loop
4098                      Set_Mechanism_Value (Formal, Arg_Mechanism);
4099                      Next_Formal (Formal);
4100                   end loop;
4101
4102                --  Case of list of mechanism associations given
4103
4104                else
4105                   if Null_Record_Present (Arg_Mechanism) then
4106                      Error_Pragma_Arg
4107                        ("inappropriate form for Mechanism parameter",
4108                         Arg_Mechanism);
4109                   end if;
4110
4111                   --  Deal with positional ones first
4112
4113                   Formal := First_Formal (Ent);
4114
4115                   if Present (Expressions (Arg_Mechanism)) then
4116                      Mname := First (Expressions (Arg_Mechanism));
4117                      while Present (Mname) loop
4118                         if No (Formal) then
4119                            Error_Pragma_Arg
4120                              ("too many mechanism associations", Mname);
4121                         end if;
4122
4123                         Set_Mechanism_Value (Formal, Mname);
4124                         Next_Formal (Formal);
4125                         Next (Mname);
4126                      end loop;
4127                   end if;
4128
4129                   --  Deal with named entries
4130
4131                   if Present (Component_Associations (Arg_Mechanism)) then
4132                      Massoc := First (Component_Associations (Arg_Mechanism));
4133                      while Present (Massoc) loop
4134                         Choice := First (Choices (Massoc));
4135
4136                         if Nkind (Choice) /= N_Identifier
4137                           or else Present (Next (Choice))
4138                         then
4139                            Error_Pragma_Arg
4140                              ("incorrect form for mechanism association",
4141                               Massoc);
4142                         end if;
4143
4144                         Formal := First_Formal (Ent);
4145                         loop
4146                            if No (Formal) then
4147                               Error_Pragma_Arg
4148                                 ("parameter name & not present", Choice);
4149                            end if;
4150
4151                            if Chars (Choice) = Chars (Formal) then
4152                               Set_Mechanism_Value
4153                                 (Formal, Expression (Massoc));
4154
4155                               --  Set entity on identifier (needed by ASIS)
4156
4157                               Set_Entity (Choice, Formal);
4158
4159                               exit;
4160                            end if;
4161
4162                            Next_Formal (Formal);
4163                         end loop;
4164
4165                         Next (Massoc);
4166                      end loop;
4167                   end if;
4168                end if;
4169             end;
4170          end if;
4171
4172          --  Process First_Optional_Parameter argument if present. We have
4173          --  already checked that this is only allowed for the Import case.
4174
4175          if Present (Arg_First_Optional_Parameter) then
4176             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4177                Error_Pragma_Arg
4178                  ("first optional parameter must be formal parameter name",
4179                   Arg_First_Optional_Parameter);
4180             end if;
4181
4182             Formal := First_Formal (Ent);
4183             loop
4184                if No (Formal) then
4185                   Error_Pragma_Arg
4186                     ("specified formal parameter& not found",
4187                      Arg_First_Optional_Parameter);
4188                end if;
4189
4190                exit when Chars (Formal) =
4191                          Chars (Arg_First_Optional_Parameter);
4192
4193                Next_Formal (Formal);
4194             end loop;
4195
4196             Set_First_Optional_Parameter (Ent, Formal);
4197
4198             --  Check specified and all remaining formals have right form
4199
4200             while Present (Formal) loop
4201                if Ekind (Formal) /= E_In_Parameter then
4202                   Error_Msg_NE
4203                     ("optional formal& is not of mode in!",
4204                      Arg_First_Optional_Parameter, Formal);
4205
4206                else
4207                   Dval := Default_Value (Formal);
4208
4209                   if No (Dval) then
4210                      Error_Msg_NE
4211                        ("optional formal& does not have default value!",
4212                         Arg_First_Optional_Parameter, Formal);
4213
4214                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4215                      null;
4216
4217                   else
4218                      Error_Msg_FE
4219                        ("default value for optional formal& is non-static!",
4220                         Arg_First_Optional_Parameter, Formal);
4221                   end if;
4222                end if;
4223
4224                Set_Is_Optional_Parameter (Formal);
4225                Next_Formal (Formal);
4226             end loop;
4227          end if;
4228       end Process_Extended_Import_Export_Subprogram_Pragma;
4229
4230       --------------------------
4231       -- Process_Generic_List --
4232       --------------------------
4233
4234       procedure Process_Generic_List is
4235          Arg : Node_Id;
4236          Exp : Node_Id;
4237
4238       begin
4239          Check_No_Identifiers;
4240          Check_At_Least_N_Arguments (1);
4241
4242          Arg := Arg1;
4243          while Present (Arg) loop
4244             Exp := Get_Pragma_Arg (Arg);
4245             Analyze (Exp);
4246
4247             if not Is_Entity_Name (Exp)
4248               or else
4249                 (not Is_Generic_Instance (Entity (Exp))
4250                   and then
4251                  not Is_Generic_Unit (Entity (Exp)))
4252             then
4253                Error_Pragma_Arg
4254                  ("pragma% argument must be name of generic unit/instance",
4255                   Arg);
4256             end if;
4257
4258             Next (Arg);
4259          end loop;
4260       end Process_Generic_List;
4261
4262       ------------------------------------
4263       -- Process_Import_Predefined_Type --
4264       ------------------------------------
4265
4266       procedure Process_Import_Predefined_Type is
4267          Loc  : constant Source_Ptr := Sloc (N);
4268          Elmt : Elmt_Id;
4269          Ftyp : Node_Id := Empty;
4270          Decl : Node_Id;
4271          Def  : Node_Id;
4272          Nam  : Name_Id;
4273
4274       begin
4275          String_To_Name_Buffer (Strval (Expression (Arg3)));
4276          Nam := Name_Find;
4277
4278          Elmt := First_Elmt (Predefined_Float_Types);
4279          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4280             Next_Elmt (Elmt);
4281          end loop;
4282
4283          Ftyp := Node (Elmt);
4284
4285          if Present (Ftyp) then
4286
4287             --  Don't build a derived type declaration, because predefined C
4288             --  types have no declaration anywhere, so cannot really be named.
4289             --  Instead build a full type declaration, starting with an
4290             --  appropriate type definition is built
4291
4292             if Is_Floating_Point_Type (Ftyp) then
4293                Def := Make_Floating_Point_Definition (Loc,
4294                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4295                  Make_Real_Range_Specification (Loc,
4296                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4297                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4298
4299             --  Should never have a predefined type we cannot handle
4300
4301             else
4302                raise Program_Error;
4303             end if;
4304
4305             --  Build and insert a Full_Type_Declaration, which will be
4306             --  analyzed as soon as this list entry has been analyzed.
4307
4308             Decl := Make_Full_Type_Declaration (Loc,
4309               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4310               Type_Definition => Def);
4311
4312             Insert_After (N, Decl);
4313             Mark_Rewrite_Insertion (Decl);
4314
4315          else
4316             Error_Pragma_Arg ("no matching type found for pragma%",
4317             Arg2);
4318          end if;
4319       end Process_Import_Predefined_Type;
4320
4321       ---------------------------------
4322       -- Process_Import_Or_Interface --
4323       ---------------------------------
4324
4325       procedure Process_Import_Or_Interface is
4326          C      : Convention_Id;
4327          Def_Id : Entity_Id;
4328          Hom_Id : Entity_Id;
4329
4330       begin
4331          Process_Convention (C, Def_Id);
4332          Kill_Size_Check_Code (Def_Id);
4333          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4334
4335          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4336
4337             --  We do not permit Import to apply to a renaming declaration
4338
4339             if Present (Renamed_Object (Def_Id)) then
4340                Error_Pragma_Arg
4341                  ("pragma% not allowed for object renaming", Arg2);
4342
4343             --  User initialization is not allowed for imported object, but
4344             --  the object declaration may contain a default initialization,
4345             --  that will be discarded. Note that an explicit initialization
4346             --  only counts if it comes from source, otherwise it is simply
4347             --  the code generator making an implicit initialization explicit.
4348
4349             elsif Present (Expression (Parent (Def_Id)))
4350               and then Comes_From_Source (Expression (Parent (Def_Id)))
4351             then
4352                Error_Msg_Sloc := Sloc (Def_Id);
4353                Error_Pragma_Arg
4354                  ("no initialization allowed for declaration of& #",
4355                   "\imported entities cannot be initialized (RM B.1(24))",
4356                   Arg2);
4357
4358             else
4359                Set_Imported (Def_Id);
4360                Process_Interface_Name (Def_Id, Arg3, Arg4);
4361
4362                --  Note that we do not set Is_Public here. That's because we
4363                --  only want to set it if there is no address clause, and we
4364                --  don't know that yet, so we delay that processing till
4365                --  freeze time.
4366
4367                --  pragma Import completes deferred constants
4368
4369                if Ekind (Def_Id) = E_Constant then
4370                   Set_Has_Completion (Def_Id);
4371                end if;
4372
4373                --  It is not possible to import a constant of an unconstrained
4374                --  array type (e.g. string) because there is no simple way to
4375                --  write a meaningful subtype for it.
4376
4377                if Is_Array_Type (Etype (Def_Id))
4378                  and then not Is_Constrained (Etype (Def_Id))
4379                then
4380                   Error_Msg_NE
4381                     ("imported constant& must have a constrained subtype",
4382                       N, Def_Id);
4383                end if;
4384             end if;
4385
4386          elsif Is_Subprogram (Def_Id)
4387            or else Is_Generic_Subprogram (Def_Id)
4388          then
4389             --  If the name is overloaded, pragma applies to all of the denoted
4390             --  entities in the same declarative part.
4391
4392             Hom_Id := Def_Id;
4393             while Present (Hom_Id) loop
4394                Def_Id := Get_Base_Subprogram (Hom_Id);
4395
4396                --  Ignore inherited subprograms because the pragma will apply
4397                --  to the parent operation, which is the one called.
4398
4399                if Is_Overloadable (Def_Id)
4400                  and then Present (Alias (Def_Id))
4401                then
4402                   null;
4403
4404                --  If it is not a subprogram, it must be in an outer scope and
4405                --  pragma does not apply.
4406
4407                elsif not Is_Subprogram (Def_Id)
4408                  and then not Is_Generic_Subprogram (Def_Id)
4409                then
4410                   null;
4411
4412                --  The pragma does not apply to primitives of interfaces
4413
4414                elsif Is_Dispatching_Operation (Def_Id)
4415                  and then Present (Find_Dispatching_Type (Def_Id))
4416                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4417                then
4418                   null;
4419
4420                --  Verify that the homonym is in the same declarative part (not
4421                --  just the same scope).
4422
4423                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4424                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4425                then
4426                   exit;
4427
4428                else
4429                   Set_Imported (Def_Id);
4430
4431                   --  Reject an Import applied to an abstract subprogram
4432
4433                   if Is_Subprogram (Def_Id)
4434                     and then Is_Abstract_Subprogram (Def_Id)
4435                   then
4436                      Error_Msg_Sloc := Sloc (Def_Id);
4437                      Error_Msg_NE
4438                        ("cannot import abstract subprogram& declared#",
4439                         Arg2, Def_Id);
4440                   end if;
4441
4442                   --  Special processing for Convention_Intrinsic
4443
4444                   if C = Convention_Intrinsic then
4445
4446                      --  Link_Name argument not allowed for intrinsic
4447
4448                      Check_No_Link_Name;
4449
4450                      Set_Is_Intrinsic_Subprogram (Def_Id);
4451
4452                      --  If no external name is present, then check that this
4453                      --  is a valid intrinsic subprogram. If an external name
4454                      --  is present, then this is handled by the back end.
4455
4456                      if No (Arg3) then
4457                         Check_Intrinsic_Subprogram
4458                           (Def_Id, Get_Pragma_Arg (Arg2));
4459                      end if;
4460                   end if;
4461
4462                   --  All interfaced procedures need an external symbol created
4463                   --  for them since they are always referenced from another
4464                   --  object file.
4465
4466                   Set_Is_Public (Def_Id);
4467
4468                   --  Verify that the subprogram does not have a completion
4469                   --  through a renaming declaration. For other completions the
4470                   --  pragma appears as a too late representation.
4471
4472                   declare
4473                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4474
4475                   begin
4476                      if Present (Decl)
4477                        and then Nkind (Decl) = N_Subprogram_Declaration
4478                        and then Present (Corresponding_Body (Decl))
4479                        and then Nkind (Unit_Declaration_Node
4480                                         (Corresponding_Body (Decl))) =
4481                                              N_Subprogram_Renaming_Declaration
4482                      then
4483                         Error_Msg_Sloc := Sloc (Def_Id);
4484                         Error_Msg_NE
4485                           ("cannot import&, renaming already provided for " &
4486                            "declaration #", N, Def_Id);
4487                      end if;
4488                   end;
4489
4490                   Set_Has_Completion (Def_Id);
4491                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4492                end if;
4493
4494                if Is_Compilation_Unit (Hom_Id) then
4495
4496                   --  Its possible homonyms are not affected by the pragma.
4497                   --  Such homonyms might be present in the context of other
4498                   --  units being compiled.
4499
4500                   exit;
4501
4502                else
4503                   Hom_Id := Homonym (Hom_Id);
4504                end if;
4505             end loop;
4506
4507          --  When the convention is Java or CIL, we also allow Import to be
4508          --  given for packages, generic packages, exceptions, record
4509          --  components, and access to subprograms.
4510
4511          elsif (C = Convention_Java or else C = Convention_CIL)
4512            and then
4513              (Is_Package_Or_Generic_Package (Def_Id)
4514                or else Ekind (Def_Id) = E_Exception
4515                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4516                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4517          then
4518             Set_Imported (Def_Id);
4519             Set_Is_Public (Def_Id);
4520             Process_Interface_Name (Def_Id, Arg3, Arg4);
4521
4522          --  Import a CPP class
4523
4524          elsif Is_Record_Type (Def_Id)
4525            and then C = Convention_CPP
4526          then
4527             --  Types treated as CPP classes must be declared limited (note:
4528             --  this used to be a warning but there is no real benefit to it
4529             --  since we did effectively intend to treat the type as limited
4530             --  anyway).
4531
4532             if not Is_Limited_Type (Def_Id) then
4533                Error_Msg_N
4534                  ("imported 'C'P'P type must be limited",
4535                   Get_Pragma_Arg (Arg2));
4536             end if;
4537
4538             Set_Is_CPP_Class (Def_Id);
4539
4540             --  Imported CPP types must not have discriminants (because C++
4541             --  classes do not have discriminants).
4542
4543             if Has_Discriminants (Def_Id) then
4544                Error_Msg_N
4545                  ("imported 'C'P'P type cannot have discriminants",
4546                   First (Discriminant_Specifications
4547                           (Declaration_Node (Def_Id))));
4548             end if;
4549
4550             --  Components of imported CPP types must not have default
4551             --  expressions because the constructor (if any) is on the
4552             --  C++ side.
4553
4554             declare
4555                Tdef  : constant Node_Id :=
4556                          Type_Definition (Declaration_Node (Def_Id));
4557                Clist : Node_Id;
4558                Comp  : Node_Id;
4559
4560             begin
4561                if Nkind (Tdef) = N_Record_Definition then
4562                   Clist := Component_List (Tdef);
4563
4564                else
4565                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4566                   Clist := Component_List (Record_Extension_Part (Tdef));
4567                end if;
4568
4569                if Present (Clist) then
4570                   Comp := First (Component_Items (Clist));
4571                   while Present (Comp) loop
4572                      if Present (Expression (Comp)) then
4573                         Error_Msg_N
4574                           ("component of imported 'C'P'P type cannot have" &
4575                            " default expression", Expression (Comp));
4576                      end if;
4577
4578                      Next (Comp);
4579                   end loop;
4580                end if;
4581             end;
4582
4583          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4584             Check_No_Link_Name;
4585             Check_Arg_Count (3);
4586             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4587
4588             Process_Import_Predefined_Type;
4589
4590          else
4591             Error_Pragma_Arg
4592               ("second argument of pragma% must be object, subprogram" &
4593                " or incomplete type",
4594                Arg2);
4595          end if;
4596
4597          --  If this pragma applies to a compilation unit, then the unit, which
4598          --  is a subprogram, does not require (or allow) a body. We also do
4599          --  not need to elaborate imported procedures.
4600
4601          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4602             declare
4603                Cunit : constant Node_Id := Parent (Parent (N));
4604             begin
4605                Set_Body_Required (Cunit, False);
4606             end;
4607          end if;
4608       end Process_Import_Or_Interface;
4609
4610       --------------------
4611       -- Process_Inline --
4612       --------------------
4613
4614       procedure Process_Inline (Active : Boolean) is
4615          Assoc     : Node_Id;
4616          Decl      : Node_Id;
4617          Subp_Id   : Node_Id;
4618          Subp      : Entity_Id;
4619          Applies   : Boolean;
4620
4621          Effective : Boolean := False;
4622          --  Set True if inline has some effect, i.e. if there is at least one
4623          --  subprogram set as inlined as a result of the use of the pragma.
4624
4625          procedure Make_Inline (Subp : Entity_Id);
4626          --  Subp is the defining unit name of the subprogram declaration. Set
4627          --  the flag, as well as the flag in the corresponding body, if there
4628          --  is one present.
4629
4630          procedure Set_Inline_Flags (Subp : Entity_Id);
4631          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4632          --  Has_Pragma_Inline_Always for the Inline_Always case.
4633
4634          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4635          --  Returns True if it can be determined at this stage that inlining
4636          --  is not possible, for example if the body is available and contains
4637          --  exception handlers, we prevent inlining, since otherwise we can
4638          --  get undefined symbols at link time. This function also emits a
4639          --  warning if front-end inlining is enabled and the pragma appears
4640          --  too late.
4641          --
4642          --  ??? is business with link symbols still valid, or does it relate
4643          --  to front end ZCX which is being phased out ???
4644
4645          ---------------------------
4646          -- Inlining_Not_Possible --
4647          ---------------------------
4648
4649          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4650             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4651             Stats : Node_Id;
4652
4653          begin
4654             if Nkind (Decl) = N_Subprogram_Body then
4655                Stats := Handled_Statement_Sequence (Decl);
4656                return Present (Exception_Handlers (Stats))
4657                  or else Present (At_End_Proc (Stats));
4658
4659             elsif Nkind (Decl) = N_Subprogram_Declaration
4660               and then Present (Corresponding_Body (Decl))
4661             then
4662                if Front_End_Inlining
4663                  and then Analyzed (Corresponding_Body (Decl))
4664                then
4665                   Error_Msg_N ("pragma appears too late, ignored?", N);
4666                   return True;
4667
4668                --  If the subprogram is a renaming as body, the body is just a
4669                --  call to the renamed subprogram, and inlining is trivially
4670                --  possible.
4671
4672                elsif
4673                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4674                                              N_Subprogram_Renaming_Declaration
4675                then
4676                   return False;
4677
4678                else
4679                   Stats :=
4680                     Handled_Statement_Sequence
4681                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4682
4683                   return
4684                     Present (Exception_Handlers (Stats))
4685                       or else Present (At_End_Proc (Stats));
4686                end if;
4687
4688             else
4689                --  If body is not available, assume the best, the check is
4690                --  performed again when compiling enclosing package bodies.
4691
4692                return False;
4693             end if;
4694          end Inlining_Not_Possible;
4695
4696          -----------------
4697          -- Make_Inline --
4698          -----------------
4699
4700          procedure Make_Inline (Subp : Entity_Id) is
4701             Kind       : constant Entity_Kind := Ekind (Subp);
4702             Inner_Subp : Entity_Id   := Subp;
4703
4704          begin
4705             --  Ignore if bad type, avoid cascaded error
4706
4707             if Etype (Subp) = Any_Type then
4708                Applies := True;
4709                return;
4710
4711             --  Ignore if all inlining is suppressed
4712
4713             elsif Suppress_All_Inlining then
4714                Applies := True;
4715                return;
4716
4717             --  If inlining is not possible, for now do not treat as an error
4718
4719             elsif Inlining_Not_Possible (Subp) then
4720                Applies := True;
4721                return;
4722
4723             --  Here we have a candidate for inlining, but we must exclude
4724             --  derived operations. Otherwise we would end up trying to inline
4725             --  a phantom declaration, and the result would be to drag in a
4726             --  body which has no direct inlining associated with it. That
4727             --  would not only be inefficient but would also result in the
4728             --  backend doing cross-unit inlining in cases where it was
4729             --  definitely inappropriate to do so.
4730
4731             --  However, a simple Comes_From_Source test is insufficient, since
4732             --  we do want to allow inlining of generic instances which also do
4733             --  not come from source. We also need to recognize specs generated
4734             --  by the front-end for bodies that carry the pragma. Finally,
4735             --  predefined operators do not come from source but are not
4736             --  inlineable either.
4737
4738             elsif Is_Generic_Instance (Subp)
4739               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4740             then
4741                null;
4742
4743             elsif not Comes_From_Source (Subp)
4744               and then Scope (Subp) /= Standard_Standard
4745             then
4746                Applies := True;
4747                return;
4748             end if;
4749
4750             --  The referenced entity must either be the enclosing entity, or
4751             --  an entity declared within the current open scope.
4752
4753             if Present (Scope (Subp))
4754               and then Scope (Subp) /= Current_Scope
4755               and then Subp /= Current_Scope
4756             then
4757                Error_Pragma_Arg
4758                  ("argument of% must be entity in current scope", Assoc);
4759                return;
4760             end if;
4761
4762             --  Processing for procedure, operator or function. If subprogram
4763             --  is aliased (as for an instance) indicate that the renamed
4764             --  entity (if declared in the same unit) is inlined.
4765
4766             if Is_Subprogram (Subp) then
4767                Inner_Subp := Ultimate_Alias (Inner_Subp);
4768
4769                if In_Same_Source_Unit (Subp, Inner_Subp) then
4770                   Set_Inline_Flags (Inner_Subp);
4771
4772                   Decl := Parent (Parent (Inner_Subp));
4773
4774                   if Nkind (Decl) = N_Subprogram_Declaration
4775                     and then Present (Corresponding_Body (Decl))
4776                   then
4777                      Set_Inline_Flags (Corresponding_Body (Decl));
4778
4779                   elsif Is_Generic_Instance (Subp) then
4780
4781                      --  Indicate that the body needs to be created for
4782                      --  inlining subsequent calls. The instantiation node
4783                      --  follows the declaration of the wrapper package
4784                      --  created for it.
4785
4786                      if Scope (Subp) /= Standard_Standard
4787                        and then
4788                          Need_Subprogram_Instance_Body
4789                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4790                               Subp)
4791                      then
4792                         null;
4793                      end if;
4794
4795                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
4796                   --  appear in a formal part to apply to a formal subprogram.
4797                   --  Do not apply check within an instance or a formal package
4798                   --  the test will have been applied to the original generic.
4799
4800                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4801                     and then List_Containing (Decl) = List_Containing (N)
4802                     and then not In_Instance
4803                   then
4804                      Error_Msg_N
4805                        ("Inline cannot apply to a formal subprogram", N);
4806                   end if;
4807                end if;
4808
4809                Applies := True;
4810
4811             --  For a generic subprogram set flag as well, for use at the point
4812             --  of instantiation, to determine whether the body should be
4813             --  generated.
4814
4815             elsif Is_Generic_Subprogram (Subp) then
4816                Set_Inline_Flags (Subp);
4817                Applies := True;
4818
4819             --  Literals are by definition inlined
4820
4821             elsif Kind = E_Enumeration_Literal then
4822                null;
4823
4824             --  Anything else is an error
4825
4826             else
4827                Error_Pragma_Arg
4828                  ("expect subprogram name for pragma%", Assoc);
4829             end if;
4830          end Make_Inline;
4831
4832          ----------------------
4833          -- Set_Inline_Flags --
4834          ----------------------
4835
4836          procedure Set_Inline_Flags (Subp : Entity_Id) is
4837          begin
4838             if Active then
4839                Set_Is_Inlined (Subp);
4840             end if;
4841
4842             if not Has_Pragma_Inline (Subp) then
4843                Set_Has_Pragma_Inline (Subp);
4844                Effective := True;
4845             end if;
4846
4847             if Prag_Id = Pragma_Inline_Always then
4848                Set_Has_Pragma_Inline_Always (Subp);
4849             end if;
4850          end Set_Inline_Flags;
4851
4852       --  Start of processing for Process_Inline
4853
4854       begin
4855          Check_No_Identifiers;
4856          Check_At_Least_N_Arguments (1);
4857
4858          if Active then
4859             Inline_Processing_Required := True;
4860          end if;
4861
4862          Assoc := Arg1;
4863          while Present (Assoc) loop
4864             Subp_Id := Get_Pragma_Arg (Assoc);
4865             Analyze (Subp_Id);
4866             Applies := False;
4867
4868             if Is_Entity_Name (Subp_Id) then
4869                Subp := Entity (Subp_Id);
4870
4871                if Subp = Any_Id then
4872
4873                   --  If previous error, avoid cascaded errors
4874
4875                   Applies := True;
4876                   Effective := True;
4877
4878                else
4879                   Make_Inline (Subp);
4880
4881                   --  For the pragma case, climb homonym chain. This is
4882                   --  what implements allowing the pragma in the renaming
4883                   --  case, with the result applying to the ancestors.
4884
4885                   if not From_Aspect_Specification (N) then
4886                      while Present (Homonym (Subp))
4887                        and then Scope (Homonym (Subp)) = Current_Scope
4888                      loop
4889                         Make_Inline (Homonym (Subp));
4890                         Subp := Homonym (Subp);
4891                      end loop;
4892                   end if;
4893                end if;
4894             end if;
4895
4896             if not Applies then
4897                Error_Pragma_Arg
4898                  ("inappropriate argument for pragma%", Assoc);
4899
4900             elsif not Effective
4901               and then Warn_On_Redundant_Constructs
4902               and then not Suppress_All_Inlining
4903             then
4904                if Inlining_Not_Possible (Subp) then
4905                   Error_Msg_NE
4906                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4907                else
4908                   Error_Msg_NE
4909                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4910                end if;
4911             end if;
4912
4913             Next (Assoc);
4914          end loop;
4915       end Process_Inline;
4916
4917       ----------------------------
4918       -- Process_Interface_Name --
4919       ----------------------------
4920
4921       procedure Process_Interface_Name
4922         (Subprogram_Def : Entity_Id;
4923          Ext_Arg        : Node_Id;
4924          Link_Arg       : Node_Id)
4925       is
4926          Ext_Nam    : Node_Id;
4927          Link_Nam   : Node_Id;
4928          String_Val : String_Id;
4929
4930          procedure Check_Form_Of_Interface_Name
4931            (SN            : Node_Id;
4932             Ext_Name_Case : Boolean);
4933          --  SN is a string literal node for an interface name. This routine
4934          --  performs some minimal checks that the name is reasonable. In
4935          --  particular that no spaces or other obviously incorrect characters
4936          --  appear. This is only a warning, since any characters are allowed.
4937          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4938
4939          ----------------------------------
4940          -- Check_Form_Of_Interface_Name --
4941          ----------------------------------
4942
4943          procedure Check_Form_Of_Interface_Name
4944            (SN            : Node_Id;
4945             Ext_Name_Case : Boolean)
4946          is
4947             S  : constant String_Id := Strval (Expr_Value_S (SN));
4948             SL : constant Nat       := String_Length (S);
4949             C  : Char_Code;
4950
4951          begin
4952             if SL = 0 then
4953                Error_Msg_N ("interface name cannot be null string", SN);
4954             end if;
4955
4956             for J in 1 .. SL loop
4957                C := Get_String_Char (S, J);
4958
4959                --  Look for dubious character and issue unconditional warning.
4960                --  Definitely dubious if not in character range.
4961
4962                if not In_Character_Range (C)
4963
4964                   --  For all cases except CLI target,
4965                   --  commas, spaces and slashes are dubious (in CLI, we use
4966                   --  commas and backslashes in external names to specify
4967                   --  assembly version and public key, while slashes and spaces
4968                   --  can be used in names to mark nested classes and
4969                   --  valuetypes).
4970
4971                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4972                              and then (Get_Character (C) = ','
4973                                          or else
4974                                        Get_Character (C) = '\'))
4975                  or else (VM_Target /= CLI_Target
4976                             and then (Get_Character (C) = ' '
4977                                         or else
4978                                       Get_Character (C) = '/'))
4979                then
4980                   Error_Msg
4981                     ("?interface name contains illegal character",
4982                      Sloc (SN) + Source_Ptr (J));
4983                end if;
4984             end loop;
4985          end Check_Form_Of_Interface_Name;
4986
4987       --  Start of processing for Process_Interface_Name
4988
4989       begin
4990          if No (Link_Arg) then
4991             if No (Ext_Arg) then
4992                if VM_Target = CLI_Target
4993                  and then Ekind (Subprogram_Def) = E_Package
4994                  and then Nkind (Parent (Subprogram_Def)) =
4995                                                  N_Package_Specification
4996                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
4997                then
4998                   Set_Interface_Name
4999                      (Subprogram_Def,
5000                       Interface_Name
5001                         (Generic_Parent (Parent (Subprogram_Def))));
5002                end if;
5003
5004                return;
5005
5006             elsif Chars (Ext_Arg) = Name_Link_Name then
5007                Ext_Nam  := Empty;
5008                Link_Nam := Expression (Ext_Arg);
5009
5010             else
5011                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5012                Ext_Nam  := Expression (Ext_Arg);
5013                Link_Nam := Empty;
5014             end if;
5015
5016          else
5017             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
5018             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5019             Ext_Nam  := Expression (Ext_Arg);
5020             Link_Nam := Expression (Link_Arg);
5021          end if;
5022
5023          --  Check expressions for external name and link name are static
5024
5025          if Present (Ext_Nam) then
5026             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5027             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5028
5029             --  Verify that external name is not the name of a local entity,
5030             --  which would hide the imported one and could lead to run-time
5031             --  surprises. The problem can only arise for entities declared in
5032             --  a package body (otherwise the external name is fully qualified
5033             --  and will not conflict).
5034
5035             declare
5036                Nam : Name_Id;
5037                E   : Entity_Id;
5038                Par : Node_Id;
5039
5040             begin
5041                if Prag_Id = Pragma_Import then
5042                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5043                   Nam := Name_Find;
5044                   E   := Entity_Id (Get_Name_Table_Info (Nam));
5045
5046                   if Nam /= Chars (Subprogram_Def)
5047                     and then Present (E)
5048                     and then not Is_Overloadable (E)
5049                     and then Is_Immediately_Visible (E)
5050                     and then not Is_Imported (E)
5051                     and then Ekind (Scope (E)) = E_Package
5052                   then
5053                      Par := Parent (E);
5054                      while Present (Par) loop
5055                         if Nkind (Par) = N_Package_Body then
5056                            Error_Msg_Sloc := Sloc (E);
5057                            Error_Msg_NE
5058                              ("imported entity is hidden by & declared#",
5059                               Ext_Arg, E);
5060                            exit;
5061                         end if;
5062
5063                         Par := Parent (Par);
5064                      end loop;
5065                   end if;
5066                end if;
5067             end;
5068          end if;
5069
5070          if Present (Link_Nam) then
5071             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5072             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5073          end if;
5074
5075          --  If there is no link name, just set the external name
5076
5077          if No (Link_Nam) then
5078             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5079
5080          --  For the Link_Name case, the given literal is preceded by an
5081          --  asterisk, which indicates to GCC that the given name should be
5082          --  taken literally, and in particular that no prepending of
5083          --  underlines should occur, even in systems where this is the
5084          --  normal default.
5085
5086          else
5087             Start_String;
5088
5089             if VM_Target = No_VM then
5090                Store_String_Char (Get_Char_Code ('*'));
5091             end if;
5092
5093             String_Val := Strval (Expr_Value_S (Link_Nam));
5094             Store_String_Chars (String_Val);
5095             Link_Nam :=
5096               Make_String_Literal (Sloc (Link_Nam),
5097                 Strval => End_String);
5098          end if;
5099
5100          --  Set the interface name. If the entity is a generic instance, use
5101          --  its alias, which is the callable entity.
5102
5103          if Is_Generic_Instance (Subprogram_Def) then
5104             Set_Encoded_Interface_Name
5105               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5106          else
5107             Set_Encoded_Interface_Name
5108               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5109          end if;
5110
5111          --  We allow duplicated export names in CIL/Java, as they are always
5112          --  enclosed in a namespace that differentiates them, and overloaded
5113          --  entities are supported by the VM.
5114
5115          if Convention (Subprogram_Def) /= Convention_CIL
5116               and then
5117             Convention (Subprogram_Def) /= Convention_Java
5118          then
5119             Check_Duplicated_Export_Name (Link_Nam);
5120          end if;
5121       end Process_Interface_Name;
5122
5123       -----------------------------------------
5124       -- Process_Interrupt_Or_Attach_Handler --
5125       -----------------------------------------
5126
5127       procedure Process_Interrupt_Or_Attach_Handler is
5128          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5129          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5130          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5131
5132       begin
5133          Set_Is_Interrupt_Handler (Handler_Proc);
5134
5135          --  If the pragma is not associated with a handler procedure within a
5136          --  protected type, then it must be for a nonprotected procedure for
5137          --  the AAMP target, in which case we don't associate a representation
5138          --  item with the procedure's scope.
5139
5140          if Ekind (Proc_Scope) = E_Protected_Type then
5141             if Prag_Id = Pragma_Interrupt_Handler
5142                  or else
5143                Prag_Id = Pragma_Attach_Handler
5144             then
5145                Record_Rep_Item (Proc_Scope, N);
5146             end if;
5147          end if;
5148       end Process_Interrupt_Or_Attach_Handler;
5149
5150       --------------------------------------------------
5151       -- Process_Restrictions_Or_Restriction_Warnings --
5152       --------------------------------------------------
5153
5154       --  Note: some of the simple identifier cases were handled in par-prag,
5155       --  but it is harmless (and more straightforward) to simply handle all
5156       --  cases here, even if it means we repeat a bit of work in some cases.
5157
5158       procedure Process_Restrictions_Or_Restriction_Warnings
5159         (Warn : Boolean)
5160       is
5161          Arg   : Node_Id;
5162          R_Id  : Restriction_Id;
5163          Id    : Name_Id;
5164          Expr  : Node_Id;
5165          Val   : Uint;
5166
5167          procedure Check_Unit_Name (N : Node_Id);
5168          --  Checks unit name parameter for No_Dependence. Returns if it has
5169          --  an appropriate form, otherwise raises pragma argument error.
5170
5171          ---------------------
5172          -- Check_Unit_Name --
5173          ---------------------
5174
5175          procedure Check_Unit_Name (N : Node_Id) is
5176          begin
5177             if Nkind (N) = N_Selected_Component then
5178                Check_Unit_Name (Prefix (N));
5179                Check_Unit_Name (Selector_Name (N));
5180
5181             elsif Nkind (N) = N_Identifier then
5182                return;
5183
5184             else
5185                Error_Pragma_Arg
5186                  ("wrong form for unit name for No_Dependence", N);
5187             end if;
5188          end Check_Unit_Name;
5189
5190       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5191
5192       begin
5193          --  Ignore all Restrictions pragma in CodePeer mode
5194
5195          if CodePeer_Mode then
5196             return;
5197          end if;
5198
5199          Check_Ada_83_Warning;
5200          Check_At_Least_N_Arguments (1);
5201          Check_Valid_Configuration_Pragma;
5202
5203          Arg := Arg1;
5204          while Present (Arg) loop
5205             Id := Chars (Arg);
5206             Expr := Get_Pragma_Arg (Arg);
5207
5208             --  Case of no restriction identifier present
5209
5210             if Id = No_Name then
5211                if Nkind (Expr) /= N_Identifier then
5212                   Error_Pragma_Arg
5213                     ("invalid form for restriction", Arg);
5214                end if;
5215
5216                R_Id :=
5217                  Get_Restriction_Id
5218                    (Process_Restriction_Synonyms (Expr));
5219
5220                if R_Id not in All_Boolean_Restrictions then
5221                   Error_Msg_Name_1 := Pname;
5222                   Error_Msg_N
5223                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5224
5225                   --  Check for possible misspelling
5226
5227                   for J in Restriction_Id loop
5228                      declare
5229                         Rnm : constant String := Restriction_Id'Image (J);
5230
5231                      begin
5232                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5233                         Name_Len := Rnm'Length;
5234                         Set_Casing (All_Lower_Case);
5235
5236                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5237                            Set_Casing
5238                              (Identifier_Casing (Current_Source_File));
5239                            Error_Msg_String (1 .. Rnm'Length) :=
5240                              Name_Buffer (1 .. Name_Len);
5241                            Error_Msg_Strlen := Rnm'Length;
5242                            Error_Msg_N -- CODEFIX
5243                              ("\possible misspelling of ""~""",
5244                               Get_Pragma_Arg (Arg));
5245                            exit;
5246                         end if;
5247                      end;
5248                   end loop;
5249
5250                   raise Pragma_Exit;
5251                end if;
5252
5253                if Implementation_Restriction (R_Id) then
5254                   Check_Restriction (No_Implementation_Restrictions, Arg);
5255                end if;
5256
5257                --  If this is a warning, then set the warning unless we already
5258                --  have a real restriction active (we never want a warning to
5259                --  override a real restriction).
5260
5261                if Warn then
5262                   if not Restriction_Active (R_Id) then
5263                      Set_Restriction (R_Id, N);
5264                      Restriction_Warnings (R_Id) := True;
5265                   end if;
5266
5267                --  If real restriction case, then set it and make sure that the
5268                --  restriction warning flag is off, since a real restriction
5269                --  always overrides a warning.
5270
5271                else
5272                   Set_Restriction (R_Id, N);
5273                   Restriction_Warnings (R_Id) := False;
5274                end if;
5275
5276                --  Check for obsolescent restrictions in Ada 2005 mode
5277
5278                if not Warn
5279                  and then Ada_Version >= Ada_2005
5280                  and then (R_Id = No_Asynchronous_Control
5281                             or else
5282                            R_Id = No_Unchecked_Deallocation
5283                             or else
5284                            R_Id = No_Unchecked_Conversion)
5285                then
5286                   Check_Restriction (No_Obsolescent_Features, N);
5287                end if;
5288
5289                --  A very special case that must be processed here: pragma
5290                --  Restrictions (No_Exceptions) turns off all run-time
5291                --  checking. This is a bit dubious in terms of the formal
5292                --  language definition, but it is what is intended by RM
5293                --  H.4(12). Restriction_Warnings never affects generated code
5294                --  so this is done only in the real restriction case.
5295
5296                if R_Id = No_Exceptions and then not Warn then
5297                   Scope_Suppress := (others => True);
5298                end if;
5299
5300             --  Case of No_Dependence => unit-name. Note that the parser
5301             --  already made the necessary entry in the No_Dependence table.
5302
5303             elsif Id = Name_No_Dependence then
5304                Check_Unit_Name (Expr);
5305
5306             --  All other cases of restriction identifier present
5307
5308             else
5309                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5310                Analyze_And_Resolve (Expr, Any_Integer);
5311
5312                if R_Id not in All_Parameter_Restrictions then
5313                   Error_Pragma_Arg
5314                     ("invalid restriction parameter identifier", Arg);
5315
5316                elsif not Is_OK_Static_Expression (Expr) then
5317                   Flag_Non_Static_Expr
5318                     ("value must be static expression!", Expr);
5319                   raise Pragma_Exit;
5320
5321                elsif not Is_Integer_Type (Etype (Expr))
5322                  or else Expr_Value (Expr) < 0
5323                then
5324                   Error_Pragma_Arg
5325                     ("value must be non-negative integer", Arg);
5326                end if;
5327
5328                --  Restriction pragma is active
5329
5330                Val := Expr_Value (Expr);
5331
5332                if not UI_Is_In_Int_Range (Val) then
5333                   Error_Pragma_Arg
5334                     ("pragma ignored, value too large?", Arg);
5335                end if;
5336
5337                --  Warning case. If the real restriction is active, then we
5338                --  ignore the request, since warning never overrides a real
5339                --  restriction. Otherwise we set the proper warning. Note that
5340                --  this circuit sets the warning again if it is already set,
5341                --  which is what we want, since the constant may have changed.
5342
5343                if Warn then
5344                   if not Restriction_Active (R_Id) then
5345                      Set_Restriction
5346                        (R_Id, N, Integer (UI_To_Int (Val)));
5347                      Restriction_Warnings (R_Id) := True;
5348                   end if;
5349
5350                --  Real restriction case, set restriction and make sure warning
5351                --  flag is off since real restriction always overrides warning.
5352
5353                else
5354                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5355                   Restriction_Warnings (R_Id) := False;
5356                end if;
5357             end if;
5358
5359             Next (Arg);
5360          end loop;
5361       end Process_Restrictions_Or_Restriction_Warnings;
5362
5363       ---------------------------------
5364       -- Process_Suppress_Unsuppress --
5365       ---------------------------------
5366
5367       --  Note: this procedure makes entries in the check suppress data
5368       --  structures managed by Sem. See spec of package Sem for full
5369       --  details on how we handle recording of check suppression.
5370
5371       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5372          C    : Check_Id;
5373          E_Id : Node_Id;
5374          E    : Entity_Id;
5375
5376          In_Package_Spec : constant Boolean :=
5377                              Is_Package_Or_Generic_Package (Current_Scope)
5378                                and then not In_Package_Body (Current_Scope);
5379
5380          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5381          --  Used to suppress a single check on the given entity
5382
5383          --------------------------------
5384          -- Suppress_Unsuppress_Echeck --
5385          --------------------------------
5386
5387          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5388          begin
5389             Set_Checks_May_Be_Suppressed (E);
5390
5391             if In_Package_Spec then
5392                Push_Global_Suppress_Stack_Entry
5393                  (Entity   => E,
5394                   Check    => C,
5395                   Suppress => Suppress_Case);
5396
5397             else
5398                Push_Local_Suppress_Stack_Entry
5399                  (Entity   => E,
5400                   Check    => C,
5401                   Suppress => Suppress_Case);
5402             end if;
5403
5404             --  If this is a first subtype, and the base type is distinct,
5405             --  then also set the suppress flags on the base type.
5406
5407             if Is_First_Subtype (E)
5408               and then Etype (E) /= E
5409             then
5410                Suppress_Unsuppress_Echeck (Etype (E), C);
5411             end if;
5412          end Suppress_Unsuppress_Echeck;
5413
5414       --  Start of processing for Process_Suppress_Unsuppress
5415
5416       begin
5417          --  Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5418          --  user code: we want to generate checks for analysis purposes, as
5419          --  set respectively by -gnatC and -gnatd.F
5420
5421          if (CodePeer_Mode or Alfa_Mode)
5422            and then Comes_From_Source (N)
5423          then
5424             return;
5425          end if;
5426
5427          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5428          --  declarative part or a package spec (RM 11.5(5)).
5429
5430          if not Is_Configuration_Pragma then
5431             Check_Is_In_Decl_Part_Or_Package_Spec;
5432          end if;
5433
5434          Check_At_Least_N_Arguments (1);
5435          Check_At_Most_N_Arguments (2);
5436          Check_No_Identifier (Arg1);
5437          Check_Arg_Is_Identifier (Arg1);
5438
5439          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5440
5441          if C = No_Check_Id then
5442             Error_Pragma_Arg
5443               ("argument of pragma% is not valid check name", Arg1);
5444          end if;
5445
5446          if not Suppress_Case
5447            and then (C = All_Checks or else C = Overflow_Check)
5448          then
5449             Opt.Overflow_Checks_Unsuppressed := True;
5450          end if;
5451
5452          if Arg_Count = 1 then
5453
5454             --  Make an entry in the local scope suppress table. This is the
5455             --  table that directly shows the current value of the scope
5456             --  suppress check for any check id value.
5457
5458             if C = All_Checks then
5459
5460                --  For All_Checks, we set all specific predefined checks with
5461                --  the exception of Elaboration_Check, which is handled
5462                --  specially because of not wanting All_Checks to have the
5463                --  effect of deactivating static elaboration order processing.
5464
5465                for J in Scope_Suppress'Range loop
5466                   if J /= Elaboration_Check then
5467                      Scope_Suppress (J) := Suppress_Case;
5468                   end if;
5469                end loop;
5470
5471             --  If not All_Checks, and predefined check, then set appropriate
5472             --  scope entry. Note that we will set Elaboration_Check if this
5473             --  is explicitly specified.
5474
5475             elsif C in Predefined_Check_Id then
5476                Scope_Suppress (C) := Suppress_Case;
5477             end if;
5478
5479             --  Also make an entry in the Local_Entity_Suppress table
5480
5481             Push_Local_Suppress_Stack_Entry
5482               (Entity   => Empty,
5483                Check    => C,
5484                Suppress => Suppress_Case);
5485
5486          --  Case of two arguments present, where the check is suppressed for
5487          --  a specified entity (given as the second argument of the pragma)
5488
5489          else
5490             --  This is obsolescent in Ada 2005 mode
5491
5492             if Ada_Version >= Ada_2005 then
5493                Check_Restriction (No_Obsolescent_Features, Arg2);
5494             end if;
5495
5496             Check_Optional_Identifier (Arg2, Name_On);
5497             E_Id := Get_Pragma_Arg (Arg2);
5498             Analyze (E_Id);
5499
5500             if not Is_Entity_Name (E_Id) then
5501                Error_Pragma_Arg
5502                  ("second argument of pragma% must be entity name", Arg2);
5503             end if;
5504
5505             E := Entity (E_Id);
5506
5507             if E = Any_Id then
5508                return;
5509             end if;
5510
5511             --  Enforce RM 11.5(7) which requires that for a pragma that
5512             --  appears within a package spec, the named entity must be
5513             --  within the package spec. We allow the package name itself
5514             --  to be mentioned since that makes sense, although it is not
5515             --  strictly allowed by 11.5(7).
5516
5517             if In_Package_Spec
5518               and then E /= Current_Scope
5519               and then Scope (E) /= Current_Scope
5520             then
5521                Error_Pragma_Arg
5522                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5523                   Arg2);
5524             end if;
5525
5526             --  Loop through homonyms. As noted below, in the case of a package
5527             --  spec, only homonyms within the package spec are considered.
5528
5529             loop
5530                Suppress_Unsuppress_Echeck (E, C);
5531
5532                if Is_Generic_Instance (E)
5533                  and then Is_Subprogram (E)
5534                  and then Present (Alias (E))
5535                then
5536                   Suppress_Unsuppress_Echeck (Alias (E), C);
5537                end if;
5538
5539                --  Move to next homonym if not aspect spec case
5540
5541                exit when From_Aspect_Specification (N);
5542                E := Homonym (E);
5543                exit when No (E);
5544
5545                --  If we are within a package specification, the pragma only
5546                --  applies to homonyms in the same scope.
5547
5548                exit when In_Package_Spec
5549                  and then Scope (E) /= Current_Scope;
5550             end loop;
5551          end if;
5552       end Process_Suppress_Unsuppress;
5553
5554       ------------------
5555       -- Set_Exported --
5556       ------------------
5557
5558       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5559       begin
5560          if Is_Imported (E) then
5561             Error_Pragma_Arg
5562               ("cannot export entity& that was previously imported", Arg);
5563
5564          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5565             Error_Pragma_Arg
5566               ("cannot export entity& that has an address clause", Arg);
5567          end if;
5568
5569          Set_Is_Exported (E);
5570
5571          --  Generate a reference for entity explicitly, because the
5572          --  identifier may be overloaded and name resolution will not
5573          --  generate one.
5574
5575          Generate_Reference (E, Arg);
5576
5577          --  Deal with exporting non-library level entity
5578
5579          if not Is_Library_Level_Entity (E) then
5580
5581             --  Not allowed at all for subprograms
5582
5583             if Is_Subprogram (E) then
5584                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5585
5586             --  Otherwise set public and statically allocated
5587
5588             else
5589                Set_Is_Public (E);
5590                Set_Is_Statically_Allocated (E);
5591
5592                --  Warn if the corresponding W flag is set and the pragma comes
5593                --  from source. The latter may not be true e.g. on VMS where we
5594                --  expand export pragmas for exception codes associated with
5595                --  imported or exported exceptions. We do not want to generate
5596                --  a warning for something that the user did not write.
5597
5598                if Warn_On_Export_Import
5599                  and then Comes_From_Source (Arg)
5600                then
5601                   Error_Msg_NE
5602                     ("?& has been made static as a result of Export", Arg, E);
5603                   Error_Msg_N
5604                     ("\this usage is non-standard and non-portable", Arg);
5605                end if;
5606             end if;
5607          end if;
5608
5609          if Warn_On_Export_Import and then Is_Type (E) then
5610             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5611          end if;
5612
5613          if Warn_On_Export_Import and Inside_A_Generic then
5614             Error_Msg_NE
5615               ("all instances of& will have the same external name?", Arg, E);
5616          end if;
5617       end Set_Exported;
5618
5619       ----------------------------------------------
5620       -- Set_Extended_Import_Export_External_Name --
5621       ----------------------------------------------
5622
5623       procedure Set_Extended_Import_Export_External_Name
5624         (Internal_Ent : Entity_Id;
5625          Arg_External : Node_Id)
5626       is
5627          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5628          New_Name : Node_Id;
5629
5630       begin
5631          if No (Arg_External) then
5632             return;
5633          end if;
5634
5635          Check_Arg_Is_External_Name (Arg_External);
5636
5637          if Nkind (Arg_External) = N_String_Literal then
5638             if String_Length (Strval (Arg_External)) = 0 then
5639                return;
5640             else
5641                New_Name := Adjust_External_Name_Case (Arg_External);
5642             end if;
5643
5644          elsif Nkind (Arg_External) = N_Identifier then
5645             New_Name := Get_Default_External_Name (Arg_External);
5646
5647          --  Check_Arg_Is_External_Name should let through only identifiers and
5648          --  string literals or static string expressions (which are folded to
5649          --  string literals).
5650
5651          else
5652             raise Program_Error;
5653          end if;
5654
5655          --  If we already have an external name set (by a prior normal Import
5656          --  or Export pragma), then the external names must match
5657
5658          if Present (Interface_Name (Internal_Ent)) then
5659             Check_Matching_Internal_Names : declare
5660                S1 : constant String_Id := Strval (Old_Name);
5661                S2 : constant String_Id := Strval (New_Name);
5662
5663                procedure Mismatch;
5664                --  Called if names do not match
5665
5666                --------------
5667                -- Mismatch --
5668                --------------
5669
5670                procedure Mismatch is
5671                begin
5672                   Error_Msg_Sloc := Sloc (Old_Name);
5673                   Error_Pragma_Arg
5674                     ("external name does not match that given #",
5675                      Arg_External);
5676                end Mismatch;
5677
5678             --  Start of processing for Check_Matching_Internal_Names
5679
5680             begin
5681                if String_Length (S1) /= String_Length (S2) then
5682                   Mismatch;
5683
5684                else
5685                   for J in 1 .. String_Length (S1) loop
5686                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5687                         Mismatch;
5688                      end if;
5689                   end loop;
5690                end if;
5691             end Check_Matching_Internal_Names;
5692
5693          --  Otherwise set the given name
5694
5695          else
5696             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5697             Check_Duplicated_Export_Name (New_Name);
5698          end if;
5699       end Set_Extended_Import_Export_External_Name;
5700
5701       ------------------
5702       -- Set_Imported --
5703       ------------------
5704
5705       procedure Set_Imported (E : Entity_Id) is
5706       begin
5707          --  Error message if already imported or exported
5708
5709          if Is_Exported (E) or else Is_Imported (E) then
5710
5711             --  Error if being set Exported twice
5712
5713             if Is_Exported (E) then
5714                Error_Msg_NE ("entity& was previously exported", N, E);
5715
5716             --  OK if Import/Interface case
5717
5718             elsif Import_Interface_Present (N) then
5719                goto OK;
5720
5721             --  Error if being set Imported twice
5722
5723             else
5724                Error_Msg_NE ("entity& was previously imported", N, E);
5725             end if;
5726
5727             Error_Msg_Name_1 := Pname;
5728             Error_Msg_N
5729               ("\(pragma% applies to all previous entities)", N);
5730
5731             Error_Msg_Sloc  := Sloc (E);
5732             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5733
5734          --  Here if not previously imported or exported, OK to import
5735
5736          else
5737             Set_Is_Imported (E);
5738
5739             --  If the entity is an object that is not at the library level,
5740             --  then it is statically allocated. We do not worry about objects
5741             --  with address clauses in this context since they are not really
5742             --  imported in the linker sense.
5743
5744             if Is_Object (E)
5745               and then not Is_Library_Level_Entity (E)
5746               and then No (Address_Clause (E))
5747             then
5748                Set_Is_Statically_Allocated (E);
5749             end if;
5750          end if;
5751
5752          <<OK>> null;
5753       end Set_Imported;
5754
5755       -------------------------
5756       -- Set_Mechanism_Value --
5757       -------------------------
5758
5759       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5760       --  analyzed, since it is semantic nonsense), so we get it in the exact
5761       --  form created by the parser.
5762
5763       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5764          Class        : Node_Id;
5765          Param        : Node_Id;
5766          Mech_Name_Id : Name_Id;
5767
5768          procedure Bad_Class;
5769          --  Signal bad descriptor class name
5770
5771          procedure Bad_Mechanism;
5772          --  Signal bad mechanism name
5773
5774          ---------------
5775          -- Bad_Class --
5776          ---------------
5777
5778          procedure Bad_Class is
5779          begin
5780             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5781          end Bad_Class;
5782
5783          -------------------------
5784          -- Bad_Mechanism_Value --
5785          -------------------------
5786
5787          procedure Bad_Mechanism is
5788          begin
5789             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5790          end Bad_Mechanism;
5791
5792       --  Start of processing for Set_Mechanism_Value
5793
5794       begin
5795          if Mechanism (Ent) /= Default_Mechanism then
5796             Error_Msg_NE
5797               ("mechanism for & has already been set", Mech_Name, Ent);
5798          end if;
5799
5800          --  MECHANISM_NAME ::= value | reference | descriptor |
5801          --                     short_descriptor
5802
5803          if Nkind (Mech_Name) = N_Identifier then
5804             if Chars (Mech_Name) = Name_Value then
5805                Set_Mechanism (Ent, By_Copy);
5806                return;
5807
5808             elsif Chars (Mech_Name) = Name_Reference then
5809                Set_Mechanism (Ent, By_Reference);
5810                return;
5811
5812             elsif Chars (Mech_Name) = Name_Descriptor then
5813                Check_VMS (Mech_Name);
5814
5815                --  Descriptor => Short_Descriptor if pragma was given
5816
5817                if Short_Descriptors then
5818                   Set_Mechanism (Ent, By_Short_Descriptor);
5819                else
5820                   Set_Mechanism (Ent, By_Descriptor);
5821                end if;
5822
5823                return;
5824
5825             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5826                Check_VMS (Mech_Name);
5827                Set_Mechanism (Ent, By_Short_Descriptor);
5828                return;
5829
5830             elsif Chars (Mech_Name) = Name_Copy then
5831                Error_Pragma_Arg
5832                  ("bad mechanism name, Value assumed", Mech_Name);
5833
5834             else
5835                Bad_Mechanism;
5836             end if;
5837
5838          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5839          --                     short_descriptor (CLASS_NAME)
5840          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5841
5842          --  Note: this form is parsed as an indexed component
5843
5844          elsif Nkind (Mech_Name) = N_Indexed_Component then
5845             Class := First (Expressions (Mech_Name));
5846
5847             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5848              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5849                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5850              or else Present (Next (Class))
5851             then
5852                Bad_Mechanism;
5853             else
5854                Mech_Name_Id := Chars (Prefix (Mech_Name));
5855
5856                --  Change Descriptor => Short_Descriptor if pragma was given
5857
5858                if Mech_Name_Id = Name_Descriptor
5859                  and then Short_Descriptors
5860                then
5861                   Mech_Name_Id := Name_Short_Descriptor;
5862                end if;
5863             end if;
5864
5865          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5866          --                     short_descriptor (Class => CLASS_NAME)
5867          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5868
5869          --  Note: this form is parsed as a function call
5870
5871          elsif Nkind (Mech_Name) = N_Function_Call then
5872             Param := First (Parameter_Associations (Mech_Name));
5873
5874             if Nkind (Name (Mech_Name)) /= N_Identifier
5875               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5876                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5877               or else Present (Next (Param))
5878               or else No (Selector_Name (Param))
5879               or else Chars (Selector_Name (Param)) /= Name_Class
5880             then
5881                Bad_Mechanism;
5882             else
5883                Class := Explicit_Actual_Parameter (Param);
5884                Mech_Name_Id := Chars (Name (Mech_Name));
5885             end if;
5886
5887          else
5888             Bad_Mechanism;
5889          end if;
5890
5891          --  Fall through here with Class set to descriptor class name
5892
5893          Check_VMS (Mech_Name);
5894
5895          if Nkind (Class) /= N_Identifier then
5896             Bad_Class;
5897
5898          elsif Mech_Name_Id = Name_Descriptor
5899            and then Chars (Class) = Name_UBS
5900          then
5901             Set_Mechanism (Ent, By_Descriptor_UBS);
5902
5903          elsif Mech_Name_Id = Name_Descriptor
5904            and then Chars (Class) = Name_UBSB
5905          then
5906             Set_Mechanism (Ent, By_Descriptor_UBSB);
5907
5908          elsif Mech_Name_Id = Name_Descriptor
5909            and then Chars (Class) = Name_UBA
5910          then
5911             Set_Mechanism (Ent, By_Descriptor_UBA);
5912
5913          elsif Mech_Name_Id = Name_Descriptor
5914            and then Chars (Class) = Name_S
5915          then
5916             Set_Mechanism (Ent, By_Descriptor_S);
5917
5918          elsif Mech_Name_Id = Name_Descriptor
5919            and then Chars (Class) = Name_SB
5920          then
5921             Set_Mechanism (Ent, By_Descriptor_SB);
5922
5923          elsif Mech_Name_Id = Name_Descriptor
5924            and then Chars (Class) = Name_A
5925          then
5926             Set_Mechanism (Ent, By_Descriptor_A);
5927
5928          elsif Mech_Name_Id = Name_Descriptor
5929            and then Chars (Class) = Name_NCA
5930          then
5931             Set_Mechanism (Ent, By_Descriptor_NCA);
5932
5933          elsif Mech_Name_Id = Name_Short_Descriptor
5934            and then Chars (Class) = Name_UBS
5935          then
5936             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5937
5938          elsif Mech_Name_Id = Name_Short_Descriptor
5939            and then Chars (Class) = Name_UBSB
5940          then
5941             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5942
5943          elsif Mech_Name_Id = Name_Short_Descriptor
5944            and then Chars (Class) = Name_UBA
5945          then
5946             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5947
5948          elsif Mech_Name_Id = Name_Short_Descriptor
5949            and then Chars (Class) = Name_S
5950          then
5951             Set_Mechanism (Ent, By_Short_Descriptor_S);
5952
5953          elsif Mech_Name_Id = Name_Short_Descriptor
5954            and then Chars (Class) = Name_SB
5955          then
5956             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5957
5958          elsif Mech_Name_Id = Name_Short_Descriptor
5959            and then Chars (Class) = Name_A
5960          then
5961             Set_Mechanism (Ent, By_Short_Descriptor_A);
5962
5963          elsif Mech_Name_Id = Name_Short_Descriptor
5964            and then Chars (Class) = Name_NCA
5965          then
5966             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5967
5968          else
5969             Bad_Class;
5970          end if;
5971       end Set_Mechanism_Value;
5972
5973       ---------------------------
5974       -- Set_Ravenscar_Profile --
5975       ---------------------------
5976
5977       --  The tasks to be done here are
5978
5979       --    Set required policies
5980
5981       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5982       --      pragma Locking_Policy (Ceiling_Locking)
5983
5984       --    Set Detect_Blocking mode
5985
5986       --    Set required restrictions (see System.Rident for detailed list)
5987
5988       --    Set the No_Dependence rules
5989       --      No_Dependence => Ada.Asynchronous_Task_Control
5990       --      No_Dependence => Ada.Calendar
5991       --      No_Dependence => Ada.Execution_Time.Group_Budget
5992       --      No_Dependence => Ada.Execution_Time.Timers
5993       --      No_Dependence => Ada.Task_Attributes
5994       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
5995
5996       procedure Set_Ravenscar_Profile (N : Node_Id) is
5997          Prefix_Entity   : Entity_Id;
5998          Selector_Entity : Entity_Id;
5999          Prefix_Node     : Node_Id;
6000          Node            : Node_Id;
6001
6002       begin
6003          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6004
6005          if Task_Dispatching_Policy /= ' '
6006            and then Task_Dispatching_Policy /= 'F'
6007          then
6008             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6009             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6010
6011          --  Set the FIFO_Within_Priorities policy, but always preserve
6012          --  System_Location since we like the error message with the run time
6013          --  name.
6014
6015          else
6016             Task_Dispatching_Policy := 'F';
6017
6018             if Task_Dispatching_Policy_Sloc /= System_Location then
6019                Task_Dispatching_Policy_Sloc := Loc;
6020             end if;
6021          end if;
6022
6023          --  pragma Locking_Policy (Ceiling_Locking)
6024
6025          if Locking_Policy /= ' '
6026            and then Locking_Policy /= 'C'
6027          then
6028             Error_Msg_Sloc := Locking_Policy_Sloc;
6029             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6030
6031          --  Set the Ceiling_Locking policy, but preserve System_Location since
6032          --  we like the error message with the run time name.
6033
6034          else
6035             Locking_Policy := 'C';
6036
6037             if Locking_Policy_Sloc /= System_Location then
6038                Locking_Policy_Sloc := Loc;
6039             end if;
6040          end if;
6041
6042          --  pragma Detect_Blocking
6043
6044          Detect_Blocking := True;
6045
6046          --  Set the corresponding restrictions
6047
6048          Set_Profile_Restrictions
6049            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6050
6051          --  Set the No_Dependence restrictions
6052
6053          --  The following No_Dependence restrictions:
6054          --    No_Dependence => Ada.Asynchronous_Task_Control
6055          --    No_Dependence => Ada.Calendar
6056          --    No_Dependence => Ada.Task_Attributes
6057          --  are already set by previous call to Set_Profile_Restrictions.
6058
6059          --  Set the following restrictions which were added to Ada 2005:
6060          --    No_Dependence => Ada.Execution_Time.Group_Budget
6061          --    No_Dependence => Ada.Execution_Time.Timers
6062
6063          if Ada_Version >= Ada_2005 then
6064             Name_Buffer (1 .. 3) := "ada";
6065             Name_Len := 3;
6066
6067             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6068
6069             Name_Buffer (1 .. 14) := "execution_time";
6070             Name_Len := 14;
6071
6072             Selector_Entity := Make_Identifier (Loc, Name_Find);
6073
6074             Prefix_Node :=
6075               Make_Selected_Component
6076                 (Sloc          => Loc,
6077                  Prefix        => Prefix_Entity,
6078                  Selector_Name => Selector_Entity);
6079
6080             Name_Buffer (1 .. 13) := "group_budgets";
6081             Name_Len := 13;
6082
6083             Selector_Entity := Make_Identifier (Loc, Name_Find);
6084
6085             Node :=
6086               Make_Selected_Component
6087                 (Sloc          => Loc,
6088                  Prefix        => Prefix_Node,
6089                  Selector_Name => Selector_Entity);
6090
6091             Set_Restriction_No_Dependence
6092               (Unit    => Node,
6093                Warn    => Treat_Restrictions_As_Warnings,
6094                Profile => Ravenscar);
6095
6096             Name_Buffer (1 .. 6) := "timers";
6097             Name_Len := 6;
6098
6099             Selector_Entity := Make_Identifier (Loc, Name_Find);
6100
6101             Node :=
6102               Make_Selected_Component
6103                 (Sloc          => Loc,
6104                  Prefix        => Prefix_Node,
6105                  Selector_Name => Selector_Entity);
6106
6107             Set_Restriction_No_Dependence
6108               (Unit    => Node,
6109                Warn    => Treat_Restrictions_As_Warnings,
6110                Profile => Ravenscar);
6111          end if;
6112
6113          --  Set the following restrictions which was added to Ada 2012 (see
6114          --  AI-0171):
6115          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
6116
6117          if Ada_Version >= Ada_2012 then
6118             Name_Buffer (1 .. 6) := "system";
6119             Name_Len := 6;
6120
6121             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6122
6123             Name_Buffer (1 .. 15) := "multiprocessors";
6124             Name_Len := 15;
6125
6126             Selector_Entity := Make_Identifier (Loc, Name_Find);
6127
6128             Prefix_Node :=
6129               Make_Selected_Component
6130                 (Sloc          => Loc,
6131                  Prefix        => Prefix_Entity,
6132                  Selector_Name => Selector_Entity);
6133
6134             Name_Buffer (1 .. 19) := "dispatching_domains";
6135             Name_Len := 19;
6136
6137             Selector_Entity := Make_Identifier (Loc, Name_Find);
6138
6139             Node :=
6140               Make_Selected_Component
6141                 (Sloc          => Loc,
6142                  Prefix        => Prefix_Node,
6143                  Selector_Name => Selector_Entity);
6144
6145             Set_Restriction_No_Dependence
6146               (Unit    => Node,
6147                Warn    => Treat_Restrictions_As_Warnings,
6148                Profile => Ravenscar);
6149          end if;
6150       end Set_Ravenscar_Profile;
6151
6152    --  Start of processing for Analyze_Pragma
6153
6154    begin
6155       --  The following code is a defense against recursion. Not clear that
6156       --  this can happen legitimately, but perhaps some error situations
6157       --  can cause it, and we did see this recursion during testing.
6158
6159       if Analyzed (N) then
6160          return;
6161       else
6162          Set_Analyzed (N, True);
6163       end if;
6164
6165       --  Deal with unrecognized pragma
6166
6167       if not Is_Pragma_Name (Pname) then
6168          if Warn_On_Unrecognized_Pragma then
6169             Error_Msg_Name_1 := Pname;
6170             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6171
6172             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6173                if Is_Bad_Spelling_Of (Pname, PN) then
6174                   Error_Msg_Name_1 := PN;
6175                   Error_Msg_N -- CODEFIX
6176                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6177                   exit;
6178                end if;
6179             end loop;
6180          end if;
6181
6182          return;
6183       end if;
6184
6185       --  Here to start processing for recognized pragma
6186
6187       Prag_Id := Get_Pragma_Id (Pname);
6188
6189       --  Preset arguments
6190
6191       Arg_Count := 0;
6192       Arg1      := Empty;
6193       Arg2      := Empty;
6194       Arg3      := Empty;
6195       Arg4      := Empty;
6196
6197       if Present (Pragma_Argument_Associations (N)) then
6198          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6199          Arg1 := First (Pragma_Argument_Associations (N));
6200
6201          if Present (Arg1) then
6202             Arg2 := Next (Arg1);
6203
6204             if Present (Arg2) then
6205                Arg3 := Next (Arg2);
6206
6207                if Present (Arg3) then
6208                   Arg4 := Next (Arg3);
6209                end if;
6210             end if;
6211          end if;
6212       end if;
6213
6214       --  An enumeration type defines the pragmas that are supported by the
6215       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6216       --  into the corresponding enumeration value for the following case.
6217
6218       case Prag_Id is
6219
6220          -----------------
6221          -- Abort_Defer --
6222          -----------------
6223
6224          --  pragma Abort_Defer;
6225
6226          when Pragma_Abort_Defer =>
6227             GNAT_Pragma;
6228             Check_Arg_Count (0);
6229
6230             --  The only required semantic processing is to check the
6231             --  placement. This pragma must appear at the start of the
6232             --  statement sequence of a handled sequence of statements.
6233
6234             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6235               or else N /= First (Statements (Parent (N)))
6236             then
6237                Pragma_Misplaced;
6238             end if;
6239
6240          ------------
6241          -- Ada_83 --
6242          ------------
6243
6244          --  pragma Ada_83;
6245
6246          --  Note: this pragma also has some specific processing in Par.Prag
6247          --  because we want to set the Ada version mode during parsing.
6248
6249          when Pragma_Ada_83 =>
6250             GNAT_Pragma;
6251             Check_Arg_Count (0);
6252
6253             --  We really should check unconditionally for proper configuration
6254             --  pragma placement, since we really don't want mixed Ada modes
6255             --  within a single unit, and the GNAT reference manual has always
6256             --  said this was a configuration pragma, but we did not check and
6257             --  are hesitant to add the check now.
6258
6259             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6260             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6261             --  or Ada 2012 mode.
6262
6263             if Ada_Version >= Ada_2005 then
6264                Check_Valid_Configuration_Pragma;
6265             end if;
6266
6267             --  Now set Ada 83 mode
6268
6269             Ada_Version := Ada_83;
6270             Ada_Version_Explicit := Ada_Version;
6271
6272          ------------
6273          -- Ada_95 --
6274          ------------
6275
6276          --  pragma Ada_95;
6277
6278          --  Note: this pragma also has some specific processing in Par.Prag
6279          --  because we want to set the Ada 83 version mode during parsing.
6280
6281          when Pragma_Ada_95 =>
6282             GNAT_Pragma;
6283             Check_Arg_Count (0);
6284
6285             --  We really should check unconditionally for proper configuration
6286             --  pragma placement, since we really don't want mixed Ada modes
6287             --  within a single unit, and the GNAT reference manual has always
6288             --  said this was a configuration pragma, but we did not check and
6289             --  are hesitant to add the check now.
6290
6291             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6292             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6293
6294             if Ada_Version >= Ada_2005 then
6295                Check_Valid_Configuration_Pragma;
6296             end if;
6297
6298             --  Now set Ada 95 mode
6299
6300             Ada_Version := Ada_95;
6301             Ada_Version_Explicit := Ada_Version;
6302
6303          ---------------------
6304          -- Ada_05/Ada_2005 --
6305          ---------------------
6306
6307          --  pragma Ada_05;
6308          --  pragma Ada_05 (LOCAL_NAME);
6309
6310          --  pragma Ada_2005;
6311          --  pragma Ada_2005 (LOCAL_NAME):
6312
6313          --  Note: these pragmas also have some specific processing in Par.Prag
6314          --  because we want to set the Ada 2005 version mode during parsing.
6315
6316          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6317             E_Id : Node_Id;
6318
6319          begin
6320             GNAT_Pragma;
6321
6322             if Arg_Count = 1 then
6323                Check_Arg_Is_Local_Name (Arg1);
6324                E_Id := Get_Pragma_Arg (Arg1);
6325
6326                if Etype (E_Id) = Any_Type then
6327                   return;
6328                end if;
6329
6330                Set_Is_Ada_2005_Only (Entity (E_Id));
6331
6332             else
6333                Check_Arg_Count (0);
6334
6335                --  For Ada_2005 we unconditionally enforce the documented
6336                --  configuration pragma placement, since we do not want to
6337                --  tolerate mixed modes in a unit involving Ada 2005. That
6338                --  would cause real difficulties for those cases where there
6339                --  are incompatibilities between Ada 95 and Ada 2005.
6340
6341                Check_Valid_Configuration_Pragma;
6342
6343                --  Now set appropriate Ada mode
6344
6345                Ada_Version          := Ada_2005;
6346                Ada_Version_Explicit := Ada_2005;
6347             end if;
6348          end;
6349
6350          ---------------------
6351          -- Ada_12/Ada_2012 --
6352          ---------------------
6353
6354          --  pragma Ada_12;
6355          --  pragma Ada_12 (LOCAL_NAME);
6356
6357          --  pragma Ada_2012;
6358          --  pragma Ada_2012 (LOCAL_NAME):
6359
6360          --  Note: these pragmas also have some specific processing in Par.Prag
6361          --  because we want to set the Ada 2012 version mode during parsing.
6362
6363          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6364             E_Id : Node_Id;
6365
6366          begin
6367             GNAT_Pragma;
6368
6369             if Arg_Count = 1 then
6370                Check_Arg_Is_Local_Name (Arg1);
6371                E_Id := Get_Pragma_Arg (Arg1);
6372
6373                if Etype (E_Id) = Any_Type then
6374                   return;
6375                end if;
6376
6377                Set_Is_Ada_2012_Only (Entity (E_Id));
6378
6379             else
6380                Check_Arg_Count (0);
6381
6382                --  For Ada_2012 we unconditionally enforce the documented
6383                --  configuration pragma placement, since we do not want to
6384                --  tolerate mixed modes in a unit involving Ada 2012. That
6385                --  would cause real difficulties for those cases where there
6386                --  are incompatibilities between Ada 95 and Ada 2012. We could
6387                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6388
6389                Check_Valid_Configuration_Pragma;
6390
6391                --  Now set appropriate Ada mode
6392
6393                Ada_Version          := Ada_2012;
6394                Ada_Version_Explicit := Ada_2012;
6395             end if;
6396          end;
6397
6398          ----------------------
6399          -- All_Calls_Remote --
6400          ----------------------
6401
6402          --  pragma All_Calls_Remote [(library_package_NAME)];
6403
6404          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6405             Lib_Entity : Entity_Id;
6406
6407          begin
6408             Check_Ada_83_Warning;
6409             Check_Valid_Library_Unit_Pragma;
6410
6411             if Nkind (N) = N_Null_Statement then
6412                return;
6413             end if;
6414
6415             Lib_Entity := Find_Lib_Unit_Name;
6416
6417             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6418
6419             if Present (Lib_Entity)
6420               and then not Debug_Flag_U
6421             then
6422                if not Is_Remote_Call_Interface (Lib_Entity) then
6423                   Error_Pragma ("pragma% only apply to rci unit");
6424
6425                --  Set flag for entity of the library unit
6426
6427                else
6428                   Set_Has_All_Calls_Remote (Lib_Entity);
6429                end if;
6430
6431             end if;
6432          end All_Calls_Remote;
6433
6434          --------------
6435          -- Annotate --
6436          --------------
6437
6438          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6439          --  ARG ::= NAME | EXPRESSION
6440
6441          --  The first two arguments are by convention intended to refer to an
6442          --  external tool and a tool-specific function. These arguments are
6443          --  not analyzed.
6444
6445          when Pragma_Annotate => Annotate : declare
6446             Arg : Node_Id;
6447             Exp : Node_Id;
6448
6449          begin
6450             GNAT_Pragma;
6451             Check_At_Least_N_Arguments (1);
6452             Check_Arg_Is_Identifier (Arg1);
6453             Check_No_Identifiers;
6454             Store_Note (N);
6455
6456             --  Second parameter is optional, it is never analyzed
6457
6458             if No (Arg2) then
6459                null;
6460
6461             --  Here if we have a second parameter
6462
6463             else
6464                --  Second parameter must be identifier
6465
6466                Check_Arg_Is_Identifier (Arg2);
6467
6468                --  Process remaining parameters if any
6469
6470                Arg := Next (Arg2);
6471                while Present (Arg) loop
6472                   Exp := Get_Pragma_Arg (Arg);
6473                   Analyze (Exp);
6474
6475                   if Is_Entity_Name (Exp) then
6476                      null;
6477
6478                   --  For string literals, we assume Standard_String as the
6479                   --  type, unless the string contains wide or wide_wide
6480                   --  characters.
6481
6482                   elsif Nkind (Exp) = N_String_Literal then
6483                      if Has_Wide_Wide_Character (Exp) then
6484                         Resolve (Exp, Standard_Wide_Wide_String);
6485                      elsif Has_Wide_Character (Exp) then
6486                         Resolve (Exp, Standard_Wide_String);
6487                      else
6488                         Resolve (Exp, Standard_String);
6489                      end if;
6490
6491                   elsif Is_Overloaded (Exp) then
6492                         Error_Pragma_Arg
6493                           ("ambiguous argument for pragma%", Exp);
6494
6495                   else
6496                      Resolve (Exp);
6497                   end if;
6498
6499                   Next (Arg);
6500                end loop;
6501             end if;
6502          end Annotate;
6503
6504          ------------
6505          -- Assert --
6506          ------------
6507
6508          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6509          --                 [, [Message =>] Static_String_EXPRESSION]);
6510
6511          when Pragma_Assert => Assert : declare
6512             Expr : Node_Id;
6513             Newa : List_Id;
6514
6515          begin
6516             Ada_2005_Pragma;
6517             Check_At_Least_N_Arguments (1);
6518             Check_At_Most_N_Arguments (2);
6519             Check_Arg_Order ((Name_Check, Name_Message));
6520             Check_Optional_Identifier (Arg1, Name_Check);
6521
6522             --  We treat pragma Assert as equivalent to:
6523
6524             --    pragma Check (Assertion, condition [, msg]);
6525
6526             --  So rewrite pragma in this manner, and analyze the result
6527
6528             Expr := Get_Pragma_Arg (Arg1);
6529             Newa := New_List (
6530               Make_Pragma_Argument_Association (Loc,
6531                 Expression => Make_Identifier (Loc, Name_Assertion)),
6532
6533               Make_Pragma_Argument_Association (Sloc (Expr),
6534                 Expression => Expr));
6535
6536             if Arg_Count > 1 then
6537                Check_Optional_Identifier (Arg2, Name_Message);
6538                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6539                Append_To (Newa, Relocate_Node (Arg2));
6540             end if;
6541
6542             Rewrite (N,
6543               Make_Pragma (Loc,
6544                 Chars                        => Name_Check,
6545                 Pragma_Argument_Associations => Newa));
6546             Analyze (N);
6547          end Assert;
6548
6549          ----------------------
6550          -- Assertion_Policy --
6551          ----------------------
6552
6553          --  pragma Assertion_Policy (Check | Disable |Ignore)
6554
6555          when Pragma_Assertion_Policy => Assertion_Policy : declare
6556             Policy : Node_Id;
6557
6558          begin
6559             Ada_2005_Pragma;
6560             Check_Valid_Configuration_Pragma;
6561             Check_Arg_Count (1);
6562             Check_No_Identifiers;
6563             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6564
6565             --  We treat pragma Assertion_Policy as equivalent to:
6566
6567             --    pragma Check_Policy (Assertion, policy)
6568
6569             --  So rewrite the pragma in that manner and link on to the chain
6570             --  of Check_Policy pragmas, marking the pragma as analyzed.
6571
6572             Policy := Get_Pragma_Arg (Arg1);
6573
6574             Rewrite (N,
6575               Make_Pragma (Loc,
6576                 Chars => Name_Check_Policy,
6577
6578                 Pragma_Argument_Associations => New_List (
6579                   Make_Pragma_Argument_Association (Loc,
6580                     Expression => Make_Identifier (Loc, Name_Assertion)),
6581
6582                   Make_Pragma_Argument_Association (Loc,
6583                     Expression =>
6584                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6585
6586             Set_Analyzed (N);
6587             Set_Next_Pragma (N, Opt.Check_Policy_List);
6588             Opt.Check_Policy_List := N;
6589          end Assertion_Policy;
6590
6591          ------------------------------
6592          -- Assume_No_Invalid_Values --
6593          ------------------------------
6594
6595          --  pragma Assume_No_Invalid_Values (On | Off);
6596
6597          when Pragma_Assume_No_Invalid_Values =>
6598             GNAT_Pragma;
6599             Check_Valid_Configuration_Pragma;
6600             Check_Arg_Count (1);
6601             Check_No_Identifiers;
6602             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6603
6604             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6605                Assume_No_Invalid_Values := True;
6606             else
6607                Assume_No_Invalid_Values := False;
6608             end if;
6609
6610          ---------------
6611          -- AST_Entry --
6612          ---------------
6613
6614          --  pragma AST_Entry (entry_IDENTIFIER);
6615
6616          when Pragma_AST_Entry => AST_Entry : declare
6617             Ent : Node_Id;
6618
6619          begin
6620             GNAT_Pragma;
6621             Check_VMS (N);
6622             Check_Arg_Count (1);
6623             Check_No_Identifiers;
6624             Check_Arg_Is_Local_Name (Arg1);
6625             Ent := Entity (Get_Pragma_Arg (Arg1));
6626
6627             --  Note: the implementation of the AST_Entry pragma could handle
6628             --  the entry family case fine, but for now we are consistent with
6629             --  the DEC rules, and do not allow the pragma, which of course
6630             --  has the effect of also forbidding the attribute.
6631
6632             if Ekind (Ent) /= E_Entry then
6633                Error_Pragma_Arg
6634                  ("pragma% argument must be simple entry name", Arg1);
6635
6636             elsif Is_AST_Entry (Ent) then
6637                Error_Pragma_Arg
6638                  ("duplicate % pragma for entry", Arg1);
6639
6640             elsif Has_Homonym (Ent) then
6641                Error_Pragma_Arg
6642                  ("pragma% argument cannot specify overloaded entry", Arg1);
6643
6644             else
6645                declare
6646                   FF : constant Entity_Id := First_Formal (Ent);
6647
6648                begin
6649                   if Present (FF) then
6650                      if Present (Next_Formal (FF)) then
6651                         Error_Pragma_Arg
6652                           ("entry for pragma% can have only one argument",
6653                            Arg1);
6654
6655                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6656                         Error_Pragma_Arg
6657                           ("entry parameter for pragma% must have mode IN",
6658                            Arg1);
6659                      end if;
6660                   end if;
6661                end;
6662
6663                Set_Is_AST_Entry (Ent);
6664             end if;
6665          end AST_Entry;
6666
6667          ------------------
6668          -- Asynchronous --
6669          ------------------
6670
6671          --  pragma Asynchronous (LOCAL_NAME);
6672
6673          when Pragma_Asynchronous => Asynchronous : declare
6674             Nm     : Entity_Id;
6675             C_Ent  : Entity_Id;
6676             L      : List_Id;
6677             S      : Node_Id;
6678             N      : Node_Id;
6679             Formal : Entity_Id;
6680
6681             procedure Process_Async_Pragma;
6682             --  Common processing for procedure and access-to-procedure case
6683
6684             --------------------------
6685             -- Process_Async_Pragma --
6686             --------------------------
6687
6688             procedure Process_Async_Pragma is
6689             begin
6690                if No (L) then
6691                   Set_Is_Asynchronous (Nm);
6692                   return;
6693                end if;
6694
6695                --  The formals should be of mode IN (RM E.4.1(6))
6696
6697                S := First (L);
6698                while Present (S) loop
6699                   Formal := Defining_Identifier (S);
6700
6701                   if Nkind (Formal) = N_Defining_Identifier
6702                     and then Ekind (Formal) /= E_In_Parameter
6703                   then
6704                      Error_Pragma_Arg
6705                        ("pragma% procedure can only have IN parameter",
6706                         Arg1);
6707                   end if;
6708
6709                   Next (S);
6710                end loop;
6711
6712                Set_Is_Asynchronous (Nm);
6713             end Process_Async_Pragma;
6714
6715          --  Start of processing for pragma Asynchronous
6716
6717          begin
6718             Check_Ada_83_Warning;
6719             Check_No_Identifiers;
6720             Check_Arg_Count (1);
6721             Check_Arg_Is_Local_Name (Arg1);
6722
6723             if Debug_Flag_U then
6724                return;
6725             end if;
6726
6727             C_Ent := Cunit_Entity (Current_Sem_Unit);
6728             Analyze (Get_Pragma_Arg (Arg1));
6729             Nm := Entity (Get_Pragma_Arg (Arg1));
6730
6731             if not Is_Remote_Call_Interface (C_Ent)
6732               and then not Is_Remote_Types (C_Ent)
6733             then
6734                --  This pragma should only appear in an RCI or Remote Types
6735                --  unit (RM E.4.1(4)).
6736
6737                Error_Pragma
6738                  ("pragma% not in Remote_Call_Interface or " &
6739                   "Remote_Types unit");
6740             end if;
6741
6742             if Ekind (Nm) = E_Procedure
6743               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6744             then
6745                if not Is_Remote_Call_Interface (Nm) then
6746                   Error_Pragma_Arg
6747                     ("pragma% cannot be applied on non-remote procedure",
6748                      Arg1);
6749                end if;
6750
6751                L := Parameter_Specifications (Parent (Nm));
6752                Process_Async_Pragma;
6753                return;
6754
6755             elsif Ekind (Nm) = E_Function then
6756                Error_Pragma_Arg
6757                  ("pragma% cannot be applied to function", Arg1);
6758
6759             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6760                   if Is_Record_Type (Nm) then
6761
6762                   --  A record type that is the Equivalent_Type for a remote
6763                   --  access-to-subprogram type.
6764
6765                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6766
6767                   else
6768                      --  A non-expanded RAS type (distribution is not enabled)
6769
6770                      N := Declaration_Node (Nm);
6771                   end if;
6772
6773                if Nkind (N) = N_Full_Type_Declaration
6774                  and then Nkind (Type_Definition (N)) =
6775                                      N_Access_Procedure_Definition
6776                then
6777                   L := Parameter_Specifications (Type_Definition (N));
6778                   Process_Async_Pragma;
6779
6780                   if Is_Asynchronous (Nm)
6781                     and then Expander_Active
6782                     and then Get_PCS_Name /= Name_No_DSA
6783                   then
6784                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6785                   end if;
6786
6787                else
6788                   Error_Pragma_Arg
6789                     ("pragma% cannot reference access-to-function type",
6790                     Arg1);
6791                end if;
6792
6793             --  Only other possibility is Access-to-class-wide type
6794
6795             elsif Is_Access_Type (Nm)
6796               and then Is_Class_Wide_Type (Designated_Type (Nm))
6797             then
6798                Check_First_Subtype (Arg1);
6799                Set_Is_Asynchronous (Nm);
6800                if Expander_Active then
6801                   RACW_Type_Is_Asynchronous (Nm);
6802                end if;
6803
6804             else
6805                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6806             end if;
6807          end Asynchronous;
6808
6809          ------------
6810          -- Atomic --
6811          ------------
6812
6813          --  pragma Atomic (LOCAL_NAME);
6814
6815          when Pragma_Atomic =>
6816             Process_Atomic_Shared_Volatile;
6817
6818          -----------------------
6819          -- Atomic_Components --
6820          -----------------------
6821
6822          --  pragma Atomic_Components (array_LOCAL_NAME);
6823
6824          --  This processing is shared by Volatile_Components
6825
6826          when Pragma_Atomic_Components   |
6827               Pragma_Volatile_Components =>
6828
6829          Atomic_Components : declare
6830             E_Id : Node_Id;
6831             E    : Entity_Id;
6832             D    : Node_Id;
6833             K    : Node_Kind;
6834
6835          begin
6836             Check_Ada_83_Warning;
6837             Check_No_Identifiers;
6838             Check_Arg_Count (1);
6839             Check_Arg_Is_Local_Name (Arg1);
6840             E_Id := Get_Pragma_Arg (Arg1);
6841
6842             if Etype (E_Id) = Any_Type then
6843                return;
6844             end if;
6845
6846             E := Entity (E_Id);
6847
6848             Check_Duplicate_Pragma (E);
6849
6850             if Rep_Item_Too_Early (E, N)
6851                  or else
6852                Rep_Item_Too_Late (E, N)
6853             then
6854                return;
6855             end if;
6856
6857             D := Declaration_Node (E);
6858             K := Nkind (D);
6859
6860             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6861               or else
6862                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6863                    and then Nkind (D) = N_Object_Declaration
6864                    and then Nkind (Object_Definition (D)) =
6865                                        N_Constrained_Array_Definition)
6866             then
6867                --  The flag is set on the object, or on the base type
6868
6869                if Nkind (D) /= N_Object_Declaration then
6870                   E := Base_Type (E);
6871                end if;
6872
6873                Set_Has_Volatile_Components (E);
6874
6875                if Prag_Id = Pragma_Atomic_Components then
6876                   Set_Has_Atomic_Components (E);
6877                end if;
6878
6879             else
6880                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6881             end if;
6882          end Atomic_Components;
6883
6884          --------------------
6885          -- Attach_Handler --
6886          --------------------
6887
6888          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6889
6890          when Pragma_Attach_Handler =>
6891             Check_Ada_83_Warning;
6892             Check_No_Identifiers;
6893             Check_Arg_Count (2);
6894
6895             if No_Run_Time_Mode then
6896                Error_Msg_CRT ("Attach_Handler pragma", N);
6897             else
6898                Check_Interrupt_Or_Attach_Handler;
6899
6900                --  The expression that designates the attribute may depend on a
6901                --  discriminant, and is therefore a per- object expression, to
6902                --  be expanded in the init proc. If expansion is enabled, then
6903                --  perform semantic checks on a copy only.
6904
6905                if Expander_Active then
6906                   declare
6907                      Temp : constant Node_Id :=
6908                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6909                   begin
6910                      Set_Parent (Temp, N);
6911                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6912                   end;
6913
6914                else
6915                   Analyze (Get_Pragma_Arg (Arg2));
6916                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6917                end if;
6918
6919                Process_Interrupt_Or_Attach_Handler;
6920             end if;
6921
6922          --------------------
6923          -- C_Pass_By_Copy --
6924          --------------------
6925
6926          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6927
6928          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6929             Arg : Node_Id;
6930             Val : Uint;
6931
6932          begin
6933             GNAT_Pragma;
6934             Check_Valid_Configuration_Pragma;
6935             Check_Arg_Count (1);
6936             Check_Optional_Identifier (Arg1, "max_size");
6937
6938             Arg := Get_Pragma_Arg (Arg1);
6939             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6940
6941             Val := Expr_Value (Arg);
6942
6943             if Val <= 0 then
6944                Error_Pragma_Arg
6945                  ("maximum size for pragma% must be positive", Arg1);
6946
6947             elsif UI_Is_In_Int_Range (Val) then
6948                Default_C_Record_Mechanism := UI_To_Int (Val);
6949
6950             --  If a giant value is given, Int'Last will do well enough.
6951             --  If sometime someone complains that a record larger than
6952             --  two gigabytes is not copied, we will worry about it then!
6953
6954             else
6955                Default_C_Record_Mechanism := Mechanism_Type'Last;
6956             end if;
6957          end C_Pass_By_Copy;
6958
6959          -----------
6960          -- Check --
6961          -----------
6962
6963          --  pragma Check ([Name    =>] IDENTIFIER,
6964          --                [Check   =>] Boolean_EXPRESSION
6965          --              [,[Message =>] String_EXPRESSION]);
6966
6967          when Pragma_Check => Check : declare
6968             Expr : Node_Id;
6969             Eloc : Source_Ptr;
6970
6971             Check_On : Boolean;
6972             --  Set True if category of assertions referenced by Name enabled
6973
6974          begin
6975             GNAT_Pragma;
6976             Check_At_Least_N_Arguments (2);
6977             Check_At_Most_N_Arguments (3);
6978             Check_Optional_Identifier (Arg1, Name_Name);
6979             Check_Optional_Identifier (Arg2, Name_Check);
6980
6981             if Arg_Count = 3 then
6982                Check_Optional_Identifier (Arg3, Name_Message);
6983                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6984             end if;
6985
6986             Check_Arg_Is_Identifier (Arg1);
6987
6988             --  Completely ignore if disabled
6989
6990             if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
6991                Rewrite (N, Make_Null_Statement (Loc));
6992                Analyze (N);
6993                return;
6994             end if;
6995
6996             --  Indicate if pragma is enabled. The Original_Node reference here
6997             --  is to deal with pragma Assert rewritten as a Check pragma.
6998
6999             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7000
7001             if Check_On then
7002                Set_SCO_Pragma_Enabled (Loc);
7003             end if;
7004
7005             --  If expansion is active and the check is not enabled then we
7006             --  rewrite the Check as:
7007
7008             --    if False and then condition then
7009             --       null;
7010             --    end if;
7011
7012             --  The reason we do this rewriting during semantic analysis rather
7013             --  than as part of normal expansion is that we cannot analyze and
7014             --  expand the code for the boolean expression directly, or it may
7015             --  cause insertion of actions that would escape the attempt to
7016             --  suppress the check code.
7017
7018             --  Note that the Sloc for the if statement corresponds to the
7019             --  argument condition, not the pragma itself. The reason for this
7020             --  is that we may generate a warning if the condition is False at
7021             --  compile time, and we do not want to delete this warning when we
7022             --  delete the if statement.
7023
7024             Expr := Get_Pragma_Arg (Arg2);
7025
7026             if Expander_Active and then not Check_On then
7027                Eloc := Sloc (Expr);
7028
7029                Rewrite (N,
7030                  Make_If_Statement (Eloc,
7031                    Condition =>
7032                      Make_And_Then (Eloc,
7033                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
7034                        Right_Opnd => Expr),
7035                    Then_Statements => New_List (
7036                      Make_Null_Statement (Eloc))));
7037
7038                Analyze (N);
7039
7040             --  Check is active
7041
7042             else
7043                Analyze_And_Resolve (Expr, Any_Boolean);
7044             end if;
7045          end Check;
7046
7047          ----------------
7048          -- Check_Name --
7049          ----------------
7050
7051          --  pragma Check_Name (check_IDENTIFIER);
7052
7053          when Pragma_Check_Name =>
7054             Check_No_Identifiers;
7055             GNAT_Pragma;
7056             Check_Valid_Configuration_Pragma;
7057             Check_Arg_Count (1);
7058             Check_Arg_Is_Identifier (Arg1);
7059
7060             declare
7061                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7062
7063             begin
7064                for J in Check_Names.First .. Check_Names.Last loop
7065                   if Check_Names.Table (J) = Nam then
7066                      return;
7067                   end if;
7068                end loop;
7069
7070                Check_Names.Append (Nam);
7071             end;
7072
7073          ------------------
7074          -- Check_Policy --
7075          ------------------
7076
7077          --  pragma Check_Policy (
7078          --    [Name   =>] IDENTIFIER,
7079          --    [Policy =>] POLICY_IDENTIFIER);
7080
7081          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7082
7083          --  Note: this is a configuration pragma, but it is allowed to appear
7084          --  anywhere else.
7085
7086          when Pragma_Check_Policy =>
7087             GNAT_Pragma;
7088             Check_Arg_Count (2);
7089             Check_Optional_Identifier (Arg1, Name_Name);
7090             Check_Optional_Identifier (Arg2, Name_Policy);
7091             Check_Arg_Is_One_Of
7092               (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7093
7094             --  A Check_Policy pragma can appear either as a configuration
7095             --  pragma, or in a declarative part or a package spec (see RM
7096             --  11.5(5) for rules for Suppress/Unsuppress which are also
7097             --  followed for Check_Policy).
7098
7099             if not Is_Configuration_Pragma then
7100                Check_Is_In_Decl_Part_Or_Package_Spec;
7101             end if;
7102
7103             Set_Next_Pragma (N, Opt.Check_Policy_List);
7104             Opt.Check_Policy_List := N;
7105
7106          ---------------------
7107          -- CIL_Constructor --
7108          ---------------------
7109
7110          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7111
7112          --  Processing for this pragma is shared with Java_Constructor
7113
7114          -------------
7115          -- Comment --
7116          -------------
7117
7118          --  pragma Comment (static_string_EXPRESSION)
7119
7120          --  Processing for pragma Comment shares the circuitry for pragma
7121          --  Ident. The only differences are that Ident enforces a limit of 31
7122          --  characters on its argument, and also enforces limitations on
7123          --  placement for DEC compatibility. Pragma Comment shares neither of
7124          --  these restrictions.
7125
7126          -------------------
7127          -- Common_Object --
7128          -------------------
7129
7130          --  pragma Common_Object (
7131          --        [Internal =>] LOCAL_NAME
7132          --     [, [External =>] EXTERNAL_SYMBOL]
7133          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7134
7135          --  Processing for this pragma is shared with Psect_Object
7136
7137          ------------------------
7138          -- Compile_Time_Error --
7139          ------------------------
7140
7141          --  pragma Compile_Time_Error
7142          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7143
7144          when Pragma_Compile_Time_Error =>
7145             GNAT_Pragma;
7146             Process_Compile_Time_Warning_Or_Error;
7147
7148          --------------------------
7149          -- Compile_Time_Warning --
7150          --------------------------
7151
7152          --  pragma Compile_Time_Warning
7153          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7154
7155          when Pragma_Compile_Time_Warning =>
7156             GNAT_Pragma;
7157             Process_Compile_Time_Warning_Or_Error;
7158
7159          -------------------
7160          -- Compiler_Unit --
7161          -------------------
7162
7163          when Pragma_Compiler_Unit =>
7164             GNAT_Pragma;
7165             Check_Arg_Count (0);
7166             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7167
7168          -----------------------------
7169          -- Complete_Representation --
7170          -----------------------------
7171
7172          --  pragma Complete_Representation;
7173
7174          when Pragma_Complete_Representation =>
7175             GNAT_Pragma;
7176             Check_Arg_Count (0);
7177
7178             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7179                Error_Pragma
7180                  ("pragma & must appear within record representation clause");
7181             end if;
7182
7183          ----------------------------
7184          -- Complex_Representation --
7185          ----------------------------
7186
7187          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7188
7189          when Pragma_Complex_Representation => Complex_Representation : declare
7190             E_Id : Entity_Id;
7191             E    : Entity_Id;
7192             Ent  : Entity_Id;
7193
7194          begin
7195             GNAT_Pragma;
7196             Check_Arg_Count (1);
7197             Check_Optional_Identifier (Arg1, Name_Entity);
7198             Check_Arg_Is_Local_Name (Arg1);
7199             E_Id := Get_Pragma_Arg (Arg1);
7200
7201             if Etype (E_Id) = Any_Type then
7202                return;
7203             end if;
7204
7205             E := Entity (E_Id);
7206
7207             if not Is_Record_Type (E) then
7208                Error_Pragma_Arg
7209                  ("argument for pragma% must be record type", Arg1);
7210             end if;
7211
7212             Ent := First_Entity (E);
7213
7214             if No (Ent)
7215               or else No (Next_Entity (Ent))
7216               or else Present (Next_Entity (Next_Entity (Ent)))
7217               or else not Is_Floating_Point_Type (Etype (Ent))
7218               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7219             then
7220                Error_Pragma_Arg
7221                  ("record for pragma% must have two fields of the same "
7222                   & "floating-point type", Arg1);
7223
7224             else
7225                Set_Has_Complex_Representation (Base_Type (E));
7226
7227                --  We need to treat the type has having a non-standard
7228                --  representation, for back-end purposes, even though in
7229                --  general a complex will have the default representation
7230                --  of a record with two real components.
7231
7232                Set_Has_Non_Standard_Rep (Base_Type (E));
7233             end if;
7234          end Complex_Representation;
7235
7236          -------------------------
7237          -- Component_Alignment --
7238          -------------------------
7239
7240          --  pragma Component_Alignment (
7241          --        [Form =>] ALIGNMENT_CHOICE
7242          --     [, [Name =>] type_LOCAL_NAME]);
7243          --
7244          --   ALIGNMENT_CHOICE ::=
7245          --     Component_Size
7246          --   | Component_Size_4
7247          --   | Storage_Unit
7248          --   | Default
7249
7250          when Pragma_Component_Alignment => Component_AlignmentP : declare
7251             Args  : Args_List (1 .. 2);
7252             Names : constant Name_List (1 .. 2) := (
7253                       Name_Form,
7254                       Name_Name);
7255
7256             Form  : Node_Id renames Args (1);
7257             Name  : Node_Id renames Args (2);
7258
7259             Atype : Component_Alignment_Kind;
7260             Typ   : Entity_Id;
7261
7262          begin
7263             GNAT_Pragma;
7264             Gather_Associations (Names, Args);
7265
7266             if No (Form) then
7267                Error_Pragma ("missing Form argument for pragma%");
7268             end if;
7269
7270             Check_Arg_Is_Identifier (Form);
7271
7272             --  Get proper alignment, note that Default = Component_Size on all
7273             --  machines we have so far, and we want to set this value rather
7274             --  than the default value to indicate that it has been explicitly
7275             --  set (and thus will not get overridden by the default component
7276             --  alignment for the current scope)
7277
7278             if Chars (Form) = Name_Component_Size then
7279                Atype := Calign_Component_Size;
7280
7281             elsif Chars (Form) = Name_Component_Size_4 then
7282                Atype := Calign_Component_Size_4;
7283
7284             elsif Chars (Form) = Name_Default then
7285                Atype := Calign_Component_Size;
7286
7287             elsif Chars (Form) = Name_Storage_Unit then
7288                Atype := Calign_Storage_Unit;
7289
7290             else
7291                Error_Pragma_Arg
7292                  ("invalid Form parameter for pragma%", Form);
7293             end if;
7294
7295             --  Case with no name, supplied, affects scope table entry
7296
7297             if No (Name) then
7298                Scope_Stack.Table
7299                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7300
7301             --  Case of name supplied
7302
7303             else
7304                Check_Arg_Is_Local_Name (Name);
7305                Find_Type (Name);
7306                Typ := Entity (Name);
7307
7308                if Typ = Any_Type
7309                  or else Rep_Item_Too_Early (Typ, N)
7310                then
7311                   return;
7312                else
7313                   Typ := Underlying_Type (Typ);
7314                end if;
7315
7316                if not Is_Record_Type (Typ)
7317                  and then not Is_Array_Type (Typ)
7318                then
7319                   Error_Pragma_Arg
7320                     ("Name parameter of pragma% must identify record or " &
7321                      "array type", Name);
7322                end if;
7323
7324                --  An explicit Component_Alignment pragma overrides an
7325                --  implicit pragma Pack, but not an explicit one.
7326
7327                if not Has_Pragma_Pack (Base_Type (Typ)) then
7328                   Set_Is_Packed (Base_Type (Typ), False);
7329                   Set_Component_Alignment (Base_Type (Typ), Atype);
7330                end if;
7331             end if;
7332          end Component_AlignmentP;
7333
7334          ----------------
7335          -- Controlled --
7336          ----------------
7337
7338          --  pragma Controlled (first_subtype_LOCAL_NAME);
7339
7340          when Pragma_Controlled => Controlled : declare
7341             Arg : Node_Id;
7342
7343          begin
7344             Check_No_Identifiers;
7345             Check_Arg_Count (1);
7346             Check_Arg_Is_Local_Name (Arg1);
7347             Arg := Get_Pragma_Arg (Arg1);
7348
7349             if not Is_Entity_Name (Arg)
7350               or else not Is_Access_Type (Entity (Arg))
7351             then
7352                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7353             else
7354                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7355             end if;
7356          end Controlled;
7357
7358          ----------------
7359          -- Convention --
7360          ----------------
7361
7362          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7363          --    [Entity =>] LOCAL_NAME);
7364
7365          when Pragma_Convention => Convention : declare
7366             C : Convention_Id;
7367             E : Entity_Id;
7368             pragma Warnings (Off, C);
7369             pragma Warnings (Off, E);
7370          begin
7371             Check_Arg_Order ((Name_Convention, Name_Entity));
7372             Check_Ada_83_Warning;
7373             Check_Arg_Count (2);
7374             Process_Convention (C, E);
7375          end Convention;
7376
7377          ---------------------------
7378          -- Convention_Identifier --
7379          ---------------------------
7380
7381          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7382          --    [Convention =>] convention_IDENTIFIER);
7383
7384          when Pragma_Convention_Identifier => Convention_Identifier : declare
7385             Idnam : Name_Id;
7386             Cname : Name_Id;
7387
7388          begin
7389             GNAT_Pragma;
7390             Check_Arg_Order ((Name_Name, Name_Convention));
7391             Check_Arg_Count (2);
7392             Check_Optional_Identifier (Arg1, Name_Name);
7393             Check_Optional_Identifier (Arg2, Name_Convention);
7394             Check_Arg_Is_Identifier (Arg1);
7395             Check_Arg_Is_Identifier (Arg2);
7396             Idnam := Chars (Get_Pragma_Arg (Arg1));
7397             Cname := Chars (Get_Pragma_Arg (Arg2));
7398
7399             if Is_Convention_Name (Cname) then
7400                Record_Convention_Identifier
7401                  (Idnam, Get_Convention_Id (Cname));
7402             else
7403                Error_Pragma_Arg
7404                  ("second arg for % pragma must be convention", Arg2);
7405             end if;
7406          end Convention_Identifier;
7407
7408          ---------------
7409          -- CPP_Class --
7410          ---------------
7411
7412          --  pragma CPP_Class ([Entity =>] local_NAME)
7413
7414          when Pragma_CPP_Class => CPP_Class : declare
7415             Arg : Node_Id;
7416             Typ : Entity_Id;
7417
7418          begin
7419             if Warn_On_Obsolescent_Feature then
7420                Error_Msg_N
7421                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7422                   " by pragma import?", N);
7423             end if;
7424
7425             GNAT_Pragma;
7426             Check_Arg_Count (1);
7427             Check_Optional_Identifier (Arg1, Name_Entity);
7428             Check_Arg_Is_Local_Name (Arg1);
7429
7430             Arg := Get_Pragma_Arg (Arg1);
7431             Analyze (Arg);
7432
7433             if Etype (Arg) = Any_Type then
7434                return;
7435             end if;
7436
7437             if not Is_Entity_Name (Arg)
7438               or else not Is_Type (Entity (Arg))
7439             then
7440                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7441             end if;
7442
7443             Typ := Entity (Arg);
7444
7445             if not Is_Tagged_Type (Typ) then
7446                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7447             end if;
7448
7449             --  Types treated as CPP classes must be declared limited (note:
7450             --  this used to be a warning but there is no real benefit to it
7451             --  since we did effectively intend to treat the type as limited
7452             --  anyway).
7453
7454             if not Is_Limited_Type (Typ) then
7455                Error_Msg_N
7456                  ("imported 'C'P'P type must be limited",
7457                   Get_Pragma_Arg (Arg1));
7458             end if;
7459
7460             Set_Is_CPP_Class      (Typ);
7461             Set_Convention        (Typ, Convention_CPP);
7462
7463             --  Imported CPP types must not have discriminants (because C++
7464             --  classes do not have discriminants).
7465
7466             if Has_Discriminants (Typ) then
7467                Error_Msg_N
7468                  ("imported 'C'P'P type cannot have discriminants",
7469                   First (Discriminant_Specifications
7470                           (Declaration_Node (Typ))));
7471             end if;
7472
7473             --  Components of imported CPP types must not have default
7474             --  expressions because the constructor (if any) is in the
7475             --  C++ side.
7476
7477             if Is_Incomplete_Or_Private_Type (Typ)
7478               and then No (Underlying_Type (Typ))
7479             then
7480                --  It should be an error to apply pragma CPP to a private
7481                --  type if the underlying type is not visible (as it is
7482                --  for any representation item). For now, for backward
7483                --  compatibility we do nothing but we cannot check components
7484                --  because they are not available at this stage. All this code
7485                --  will be removed when we cleanup this obsolete GNAT pragma???
7486
7487                null;
7488
7489             else
7490                declare
7491                   Tdef  : constant Node_Id :=
7492                             Type_Definition (Declaration_Node (Typ));
7493                   Clist : Node_Id;
7494                   Comp  : Node_Id;
7495
7496                begin
7497                   if Nkind (Tdef) = N_Record_Definition then
7498                      Clist := Component_List (Tdef);
7499                   else
7500                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7501                      Clist := Component_List (Record_Extension_Part (Tdef));
7502                   end if;
7503
7504                   if Present (Clist) then
7505                      Comp := First (Component_Items (Clist));
7506                      while Present (Comp) loop
7507                         if Present (Expression (Comp)) then
7508                            Error_Msg_N
7509                              ("component of imported 'C'P'P type cannot have" &
7510                               " default expression", Expression (Comp));
7511                         end if;
7512
7513                         Next (Comp);
7514                      end loop;
7515                   end if;
7516                end;
7517             end if;
7518          end CPP_Class;
7519
7520          ---------------------
7521          -- CPP_Constructor --
7522          ---------------------
7523
7524          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7525          --    [, [External_Name =>] static_string_EXPRESSION ]
7526          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7527
7528          when Pragma_CPP_Constructor => CPP_Constructor : declare
7529             Elmt    : Elmt_Id;
7530             Id      : Entity_Id;
7531             Def_Id  : Entity_Id;
7532             Tag_Typ : Entity_Id;
7533
7534          begin
7535             GNAT_Pragma;
7536             Check_At_Least_N_Arguments (1);
7537             Check_At_Most_N_Arguments (3);
7538             Check_Optional_Identifier (Arg1, Name_Entity);
7539             Check_Arg_Is_Local_Name (Arg1);
7540
7541             Id := Get_Pragma_Arg (Arg1);
7542             Find_Program_Unit_Name (Id);
7543
7544             --  If we did not find the name, we are done
7545
7546             if Etype (Id) = Any_Type then
7547                return;
7548             end if;
7549
7550             Def_Id := Entity (Id);
7551
7552             --  Check if already defined as constructor
7553
7554             if Is_Constructor (Def_Id) then
7555                Error_Msg_N
7556                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7557                return;
7558             end if;
7559
7560             if Ekind (Def_Id) = E_Function
7561               and then (Is_CPP_Class (Etype (Def_Id))
7562                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7563                                    and then
7564                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7565             then
7566                if Arg_Count >= 2 then
7567                   Set_Imported (Def_Id);
7568                   Set_Is_Public (Def_Id);
7569                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7570                end if;
7571
7572                Set_Has_Completion (Def_Id);
7573                Set_Is_Constructor (Def_Id);
7574
7575                --  Imported C++ constructors are not dispatching primitives
7576                --  because in C++ they don't have a dispatch table slot.
7577                --  However, in Ada the constructor has the profile of a
7578                --  function that returns a tagged type and therefore it has
7579                --  been treated as a primitive operation during semantic
7580                --  analysis. We now remove it from the list of primitive
7581                --  operations of the type.
7582
7583                if Is_Tagged_Type (Etype (Def_Id))
7584                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7585                then
7586                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7587                   Tag_Typ := Etype (Def_Id);
7588
7589                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7590                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7591                      Next_Elmt (Elmt);
7592                   end loop;
7593
7594                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7595                   Set_Is_Dispatching_Operation (Def_Id, False);
7596                end if;
7597
7598                --  For backward compatibility, if the constructor returns a
7599                --  class wide type, and we internally change the return type to
7600                --  the corresponding root type.
7601
7602                if Is_Class_Wide_Type (Etype (Def_Id)) then
7603                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7604                end if;
7605             else
7606                Error_Pragma_Arg
7607                  ("pragma% requires function returning a 'C'P'P_Class type",
7608                    Arg1);
7609             end if;
7610          end CPP_Constructor;
7611
7612          -----------------
7613          -- CPP_Virtual --
7614          -----------------
7615
7616          when Pragma_CPP_Virtual => CPP_Virtual : declare
7617          begin
7618             GNAT_Pragma;
7619
7620             if Warn_On_Obsolescent_Feature then
7621                Error_Msg_N
7622                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7623                   "no effect?", N);
7624             end if;
7625          end CPP_Virtual;
7626
7627          ----------------
7628          -- CPP_Vtable --
7629          ----------------
7630
7631          when Pragma_CPP_Vtable => CPP_Vtable : declare
7632          begin
7633             GNAT_Pragma;
7634
7635             if Warn_On_Obsolescent_Feature then
7636                Error_Msg_N
7637                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7638                   "no effect?", N);
7639             end if;
7640          end CPP_Vtable;
7641
7642          ---------
7643          -- CPU --
7644          ---------
7645
7646          --  pragma CPU (EXPRESSION);
7647
7648          when Pragma_CPU => CPU : declare
7649             P   : constant Node_Id := Parent (N);
7650             Arg : Node_Id;
7651
7652          begin
7653             Ada_2012_Pragma;
7654             Check_No_Identifiers;
7655             Check_Arg_Count (1);
7656
7657             --  Subprogram case
7658
7659             if Nkind (P) = N_Subprogram_Body then
7660                Check_In_Main_Program;
7661
7662                Arg := Get_Pragma_Arg (Arg1);
7663                Analyze_And_Resolve (Arg, Any_Integer);
7664
7665                --  Must be static
7666
7667                if not Is_Static_Expression (Arg) then
7668                   Flag_Non_Static_Expr
7669                     ("main subprogram affinity is not static!", Arg);
7670                   raise Pragma_Exit;
7671
7672                --  If constraint error, then we already signalled an error
7673
7674                elsif Raises_Constraint_Error (Arg) then
7675                   null;
7676
7677                --  Otherwise check in range
7678
7679                else
7680                   declare
7681                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7682                      --  This is the entity System.Multiprocessors.CPU_Range;
7683
7684                      Val : constant Uint := Expr_Value (Arg);
7685
7686                   begin
7687                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7688                           or else
7689                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7690                      then
7691                         Error_Pragma_Arg
7692                           ("main subprogram CPU is out of range", Arg1);
7693                      end if;
7694                   end;
7695                end if;
7696
7697                Set_Main_CPU
7698                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7699
7700             --  Task case
7701
7702             elsif Nkind (P) = N_Task_Definition then
7703                Arg := Get_Pragma_Arg (Arg1);
7704
7705                --  The expression must be analyzed in the special manner
7706                --  described in "Handling of Default and Per-Object
7707                --  Expressions" in sem.ads.
7708
7709                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7710
7711             --  Anything else is incorrect
7712
7713             else
7714                Pragma_Misplaced;
7715             end if;
7716
7717             if Has_Pragma_CPU (P) then
7718                Error_Pragma ("duplicate pragma% not allowed");
7719             else
7720                Set_Has_Pragma_CPU (P, True);
7721
7722                if Nkind (P) = N_Task_Definition then
7723                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7724                end if;
7725             end if;
7726          end CPU;
7727
7728          -----------
7729          -- Debug --
7730          -----------
7731
7732          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7733
7734          when Pragma_Debug => Debug : declare
7735             Cond : Node_Id;
7736             Call : Node_Id;
7737
7738          begin
7739             GNAT_Pragma;
7740
7741             --  Skip analysis if disabled
7742
7743             if Debug_Pragmas_Disabled then
7744                Rewrite (N, Make_Null_Statement (Loc));
7745                Analyze (N);
7746                return;
7747             end if;
7748
7749             Cond :=
7750               New_Occurrence_Of
7751                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7752                  Loc);
7753
7754             if Debug_Pragmas_Enabled then
7755                Set_SCO_Pragma_Enabled (Loc);
7756             end if;
7757
7758             if Arg_Count = 2 then
7759                Cond :=
7760                  Make_And_Then (Loc,
7761                    Left_Opnd  => Relocate_Node (Cond),
7762                    Right_Opnd => Get_Pragma_Arg (Arg1));
7763                Call := Get_Pragma_Arg (Arg2);
7764             else
7765                Call := Get_Pragma_Arg (Arg1);
7766             end if;
7767
7768             if Nkind_In (Call,
7769                  N_Indexed_Component,
7770                  N_Function_Call,
7771                  N_Identifier,
7772                  N_Selected_Component)
7773             then
7774                --  If this pragma Debug comes from source, its argument was
7775                --  parsed as a name form (which is syntactically identical).
7776                --  Change it to a procedure call statement now.
7777
7778                Change_Name_To_Procedure_Call_Statement (Call);
7779
7780             elsif Nkind (Call) = N_Procedure_Call_Statement then
7781
7782                --  Already in the form of a procedure call statement: nothing
7783                --  to do (could happen in case of an internally generated
7784                --  pragma Debug).
7785
7786                null;
7787
7788             else
7789                --  All other cases: diagnose error
7790
7791                Error_Msg
7792                  ("argument of pragma% is not procedure call", Sloc (Call));
7793                return;
7794             end if;
7795
7796             --  Rewrite into a conditional with an appropriate condition. We
7797             --  wrap the procedure call in a block so that overhead from e.g.
7798             --  use of the secondary stack does not generate execution overhead
7799             --  for suppressed conditions.
7800
7801             Rewrite (N, Make_Implicit_If_Statement (N,
7802               Condition => Cond,
7803                  Then_Statements => New_List (
7804                    Make_Block_Statement (Loc,
7805                      Handled_Statement_Sequence =>
7806                        Make_Handled_Sequence_Of_Statements (Loc,
7807                          Statements => New_List (Relocate_Node (Call)))))));
7808             Analyze (N);
7809          end Debug;
7810
7811          ------------------
7812          -- Debug_Policy --
7813          ------------------
7814
7815          --  pragma Debug_Policy (Check | Ignore)
7816
7817          when Pragma_Debug_Policy =>
7818             GNAT_Pragma;
7819             Check_Arg_Count (1);
7820             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7821             Debug_Pragmas_Enabled :=
7822               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7823             Debug_Pragmas_Disabled :=
7824               Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7825
7826          ---------------------
7827          -- Detect_Blocking --
7828          ---------------------
7829
7830          --  pragma Detect_Blocking;
7831
7832          when Pragma_Detect_Blocking =>
7833             Ada_2005_Pragma;
7834             Check_Arg_Count (0);
7835             Check_Valid_Configuration_Pragma;
7836             Detect_Blocking := True;
7837
7838          --------------------------
7839          -- Default_Storage_Pool --
7840          --------------------------
7841
7842          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7843
7844          when Pragma_Default_Storage_Pool =>
7845             Ada_2012_Pragma;
7846             Check_Arg_Count (1);
7847
7848             --  Default_Storage_Pool can appear as a configuration pragma, or
7849             --  in a declarative part or a package spec.
7850
7851             if not Is_Configuration_Pragma then
7852                Check_Is_In_Decl_Part_Or_Package_Spec;
7853             end if;
7854
7855             --  Case of Default_Storage_Pool (null);
7856
7857             if Nkind (Expression (Arg1)) = N_Null then
7858                Analyze (Expression (Arg1));
7859
7860                --  This is an odd case, this is not really an expression, so
7861                --  we don't have a type for it. So just set the type to Empty.
7862
7863                Set_Etype (Expression (Arg1), Empty);
7864
7865             --  Case of Default_Storage_Pool (storage_pool_NAME);
7866
7867             else
7868                --  If it's a configuration pragma, then the only allowed
7869                --  argument is "null".
7870
7871                if Is_Configuration_Pragma then
7872                   Error_Pragma_Arg ("NULL expected", Arg1);
7873                end if;
7874
7875                --  The expected type for a non-"null" argument is
7876                --  Root_Storage_Pool'Class.
7877
7878                Analyze_And_Resolve
7879                  (Get_Pragma_Arg (Arg1),
7880                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7881             end if;
7882
7883             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7884             --  for an access type will use this information to set the
7885             --  appropriate attributes of the access type.
7886
7887             Default_Pool := Expression (Arg1);
7888
7889          ---------------
7890          -- Dimension --
7891          ---------------
7892
7893          when Pragma_Dimension =>
7894             GNAT_Pragma;
7895             Check_Arg_Count (4);
7896             Check_No_Identifiers;
7897             Check_Arg_Is_Local_Name (Arg1);
7898
7899             if not Is_Type (Arg1) then
7900                Error_Pragma ("first argument for pragma% must be subtype");
7901             end if;
7902
7903             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7904             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7905             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7906
7907          -------------------
7908          -- Discard_Names --
7909          -------------------
7910
7911          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7912
7913          when Pragma_Discard_Names => Discard_Names : declare
7914             E    : Entity_Id;
7915             E_Id : Entity_Id;
7916
7917          begin
7918             Check_Ada_83_Warning;
7919
7920             --  Deal with configuration pragma case
7921
7922             if Arg_Count = 0 and then Is_Configuration_Pragma then
7923                Global_Discard_Names := True;
7924                return;
7925
7926             --  Otherwise, check correct appropriate context
7927
7928             else
7929                Check_Is_In_Decl_Part_Or_Package_Spec;
7930
7931                if Arg_Count = 0 then
7932
7933                   --  If there is no parameter, then from now on this pragma
7934                   --  applies to any enumeration, exception or tagged type
7935                   --  defined in the current declarative part, and recursively
7936                   --  to any nested scope.
7937
7938                   Set_Discard_Names (Current_Scope);
7939                   return;
7940
7941                else
7942                   Check_Arg_Count (1);
7943                   Check_Optional_Identifier (Arg1, Name_On);
7944                   Check_Arg_Is_Local_Name (Arg1);
7945
7946                   E_Id := Get_Pragma_Arg (Arg1);
7947
7948                   if Etype (E_Id) = Any_Type then
7949                      return;
7950                   else
7951                      E := Entity (E_Id);
7952                   end if;
7953
7954                   if (Is_First_Subtype (E)
7955                       and then
7956                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7957                     or else Ekind (E) = E_Exception
7958                   then
7959                      Set_Discard_Names (E);
7960                   else
7961                      Error_Pragma_Arg
7962                        ("inappropriate entity for pragma%", Arg1);
7963                   end if;
7964
7965                end if;
7966             end if;
7967          end Discard_Names;
7968
7969          ------------------------
7970          -- Dispatching_Domain --
7971          ------------------------
7972
7973          --  pragma Dispatching_Domain (EXPRESSION);
7974
7975          when Pragma_Dispatching_Domain => Dispatching_Domain : declare
7976             P   : constant Node_Id := Parent (N);
7977             Arg : Node_Id;
7978
7979          begin
7980             Ada_2012_Pragma;
7981             Check_No_Identifiers;
7982             Check_Arg_Count (1);
7983
7984             --  This pragma is born obsolete, but not the aspect
7985
7986             if not From_Aspect_Specification (N) then
7987                Check_Restriction
7988                  (No_Obsolescent_Features, Pragma_Identifier (N));
7989             end if;
7990
7991             if Nkind (P) = N_Task_Definition then
7992                Arg := Get_Pragma_Arg (Arg1);
7993
7994                --  The expression must be analyzed in the special manner
7995                --  described in "Handling of Default and Per-Object
7996                --  Expressions" in sem.ads.
7997
7998                Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
7999
8000             --  Anything else is incorrect
8001
8002             else
8003                Pragma_Misplaced;
8004             end if;
8005
8006             if Has_Pragma_Dispatching_Domain (P) then
8007                Error_Pragma ("duplicate pragma% not allowed");
8008             else
8009                Set_Has_Pragma_Dispatching_Domain (P, True);
8010
8011                if Nkind (P) = N_Task_Definition then
8012                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8013                end if;
8014             end if;
8015          end Dispatching_Domain;
8016
8017          ---------------
8018          -- Elaborate --
8019          ---------------
8020
8021          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8022
8023          when Pragma_Elaborate => Elaborate : declare
8024             Arg   : Node_Id;
8025             Citem : Node_Id;
8026
8027          begin
8028             --  Pragma must be in context items list of a compilation unit
8029
8030             if not Is_In_Context_Clause then
8031                Pragma_Misplaced;
8032             end if;
8033
8034             --  Must be at least one argument
8035
8036             if Arg_Count = 0 then
8037                Error_Pragma ("pragma% requires at least one argument");
8038             end if;
8039
8040             --  In Ada 83 mode, there can be no items following it in the
8041             --  context list except other pragmas and implicit with clauses
8042             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8043             --  placement rule does not apply.
8044
8045             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8046                Citem := Next (N);
8047                while Present (Citem) loop
8048                   if Nkind (Citem) = N_Pragma
8049                     or else (Nkind (Citem) = N_With_Clause
8050                               and then Implicit_With (Citem))
8051                   then
8052                      null;
8053                   else
8054                      Error_Pragma
8055                        ("(Ada 83) pragma% must be at end of context clause");
8056                   end if;
8057
8058                   Next (Citem);
8059                end loop;
8060             end if;
8061
8062             --  Finally, the arguments must all be units mentioned in a with
8063             --  clause in the same context clause. Note we already checked (in
8064             --  Par.Prag) that the arguments are all identifiers or selected
8065             --  components.
8066
8067             Arg := Arg1;
8068             Outer : while Present (Arg) loop
8069                Citem := First (List_Containing (N));
8070                Inner : while Citem /= N loop
8071                   if Nkind (Citem) = N_With_Clause
8072                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8073                   then
8074                      Set_Elaborate_Present (Citem, True);
8075                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8076                      Generate_Reference (Entity (Name (Citem)), Citem);
8077
8078                      --  With the pragma present, elaboration calls on
8079                      --  subprograms from the named unit need no further
8080                      --  checks, as long as the pragma appears in the current
8081                      --  compilation unit. If the pragma appears in some unit
8082                      --  in the context, there might still be a need for an
8083                      --  Elaborate_All_Desirable from the current compilation
8084                      --  to the named unit, so we keep the check enabled.
8085
8086                      if In_Extended_Main_Source_Unit (N) then
8087                         Set_Suppress_Elaboration_Warnings
8088                           (Entity (Name (Citem)));
8089                      end if;
8090
8091                      exit Inner;
8092                   end if;
8093
8094                   Next (Citem);
8095                end loop Inner;
8096
8097                if Citem = N then
8098                   Error_Pragma_Arg
8099                     ("argument of pragma% is not with'ed unit", Arg);
8100                end if;
8101
8102                Next (Arg);
8103             end loop Outer;
8104
8105             --  Give a warning if operating in static mode with -gnatwl
8106             --  (elaboration warnings enabled) switch set.
8107
8108             if Elab_Warnings and not Dynamic_Elaboration_Checks then
8109                Error_Msg_N
8110                  ("?use of pragma Elaborate may not be safe", N);
8111                Error_Msg_N
8112                  ("?use pragma Elaborate_All instead if possible", N);
8113             end if;
8114          end Elaborate;
8115
8116          -------------------
8117          -- Elaborate_All --
8118          -------------------
8119
8120          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8121
8122          when Pragma_Elaborate_All => Elaborate_All : declare
8123             Arg   : Node_Id;
8124             Citem : Node_Id;
8125
8126          begin
8127             Check_Ada_83_Warning;
8128
8129             --  Pragma must be in context items list of a compilation unit
8130
8131             if not Is_In_Context_Clause then
8132                Pragma_Misplaced;
8133             end if;
8134
8135             --  Must be at least one argument
8136
8137             if Arg_Count = 0 then
8138                Error_Pragma ("pragma% requires at least one argument");
8139             end if;
8140
8141             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
8142             --  have to appear at the end of the context clause, but may
8143             --  appear mixed in with other items, even in Ada 83 mode.
8144
8145             --  Final check: the arguments must all be units mentioned in
8146             --  a with clause in the same context clause. Note that we
8147             --  already checked (in Par.Prag) that all the arguments are
8148             --  either identifiers or selected components.
8149
8150             Arg := Arg1;
8151             Outr : while Present (Arg) loop
8152                Citem := First (List_Containing (N));
8153                Innr : while Citem /= N loop
8154                   if Nkind (Citem) = N_With_Clause
8155                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8156                   then
8157                      Set_Elaborate_All_Present (Citem, True);
8158                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8159
8160                      --  Suppress warnings and elaboration checks on the named
8161                      --  unit if the pragma is in the current compilation, as
8162                      --  for pragma Elaborate.
8163
8164                      if In_Extended_Main_Source_Unit (N) then
8165                         Set_Suppress_Elaboration_Warnings
8166                           (Entity (Name (Citem)));
8167                      end if;
8168                      exit Innr;
8169                   end if;
8170
8171                   Next (Citem);
8172                end loop Innr;
8173
8174                if Citem = N then
8175                   Set_Error_Posted (N);
8176                   Error_Pragma_Arg
8177                     ("argument of pragma% is not with'ed unit", Arg);
8178                end if;
8179
8180                Next (Arg);
8181             end loop Outr;
8182          end Elaborate_All;
8183
8184          --------------------
8185          -- Elaborate_Body --
8186          --------------------
8187
8188          --  pragma Elaborate_Body [( library_unit_NAME )];
8189
8190          when Pragma_Elaborate_Body => Elaborate_Body : declare
8191             Cunit_Node : Node_Id;
8192             Cunit_Ent  : Entity_Id;
8193
8194          begin
8195             Check_Ada_83_Warning;
8196             Check_Valid_Library_Unit_Pragma;
8197
8198             if Nkind (N) = N_Null_Statement then
8199                return;
8200             end if;
8201
8202             Cunit_Node := Cunit (Current_Sem_Unit);
8203             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8204
8205             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8206                                             N_Subprogram_Body)
8207             then
8208                Error_Pragma ("pragma% must refer to a spec, not a body");
8209             else
8210                Set_Body_Required (Cunit_Node, True);
8211                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8212
8213                --  If we are in dynamic elaboration mode, then we suppress
8214                --  elaboration warnings for the unit, since it is definitely
8215                --  fine NOT to do dynamic checks at the first level (and such
8216                --  checks will be suppressed because no elaboration boolean
8217                --  is created for Elaborate_Body packages).
8218
8219                --  But in the static model of elaboration, Elaborate_Body is
8220                --  definitely NOT good enough to ensure elaboration safety on
8221                --  its own, since the body may WITH other units that are not
8222                --  safe from an elaboration point of view, so a client must
8223                --  still do an Elaborate_All on such units.
8224
8225                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8226                --  Elaborate_Body always suppressed elab warnings.
8227
8228                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8229                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8230                end if;
8231             end if;
8232          end Elaborate_Body;
8233
8234          ------------------------
8235          -- Elaboration_Checks --
8236          ------------------------
8237
8238          --  pragma Elaboration_Checks (Static | Dynamic);
8239
8240          when Pragma_Elaboration_Checks =>
8241             GNAT_Pragma;
8242             Check_Arg_Count (1);
8243             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8244             Dynamic_Elaboration_Checks :=
8245               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8246
8247          ---------------
8248          -- Eliminate --
8249          ---------------
8250
8251          --  pragma Eliminate (
8252          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8253          --    [,[Entity     =>] IDENTIFIER |
8254          --                      SELECTED_COMPONENT |
8255          --                      STRING_LITERAL]
8256          --    [,                OVERLOADING_RESOLUTION]);
8257
8258          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8259          --                             SOURCE_LOCATION
8260
8261          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8262          --                                        FUNCTION_PROFILE
8263
8264          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8265
8266          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8267          --                       Result_Type => result_SUBTYPE_NAME]
8268
8269          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8270          --  SUBTYPE_NAME    ::= STRING_LITERAL
8271
8272          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8273          --  SOURCE_TRACE    ::= STRING_LITERAL
8274
8275          when Pragma_Eliminate => Eliminate : declare
8276             Args  : Args_List (1 .. 5);
8277             Names : constant Name_List (1 .. 5) := (
8278                       Name_Unit_Name,
8279                       Name_Entity,
8280                       Name_Parameter_Types,
8281                       Name_Result_Type,
8282                       Name_Source_Location);
8283
8284             Unit_Name       : Node_Id renames Args (1);
8285             Entity          : Node_Id renames Args (2);
8286             Parameter_Types : Node_Id renames Args (3);
8287             Result_Type     : Node_Id renames Args (4);
8288             Source_Location : Node_Id renames Args (5);
8289
8290          begin
8291             GNAT_Pragma;
8292             Check_Valid_Configuration_Pragma;
8293             Gather_Associations (Names, Args);
8294
8295             if No (Unit_Name) then
8296                Error_Pragma ("missing Unit_Name argument for pragma%");
8297             end if;
8298
8299             if No (Entity)
8300               and then (Present (Parameter_Types)
8301                           or else
8302                         Present (Result_Type)
8303                           or else
8304                         Present (Source_Location))
8305             then
8306                Error_Pragma ("missing Entity argument for pragma%");
8307             end if;
8308
8309             if (Present (Parameter_Types)
8310                   or else
8311                 Present (Result_Type))
8312               and then
8313                 Present (Source_Location)
8314             then
8315                Error_Pragma
8316                  ("parameter profile and source location cannot " &
8317                   "be used together in pragma%");
8318             end if;
8319
8320             Process_Eliminate_Pragma
8321               (N,
8322                Unit_Name,
8323                Entity,
8324                Parameter_Types,
8325                Result_Type,
8326                Source_Location);
8327          end Eliminate;
8328
8329          ------------
8330          -- Export --
8331          ------------
8332
8333          --  pragma Export (
8334          --    [   Convention    =>] convention_IDENTIFIER,
8335          --    [   Entity        =>] local_NAME
8336          --    [, [External_Name =>] static_string_EXPRESSION ]
8337          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8338
8339          when Pragma_Export => Export : declare
8340             C      : Convention_Id;
8341             Def_Id : Entity_Id;
8342
8343             pragma Warnings (Off, C);
8344
8345          begin
8346             Check_Ada_83_Warning;
8347             Check_Arg_Order
8348               ((Name_Convention,
8349                 Name_Entity,
8350                 Name_External_Name,
8351                 Name_Link_Name));
8352             Check_At_Least_N_Arguments (2);
8353             Check_At_Most_N_Arguments  (4);
8354             Process_Convention (C, Def_Id);
8355
8356             if Ekind (Def_Id) /= E_Constant then
8357                Note_Possible_Modification
8358                  (Get_Pragma_Arg (Arg2), Sure => False);
8359             end if;
8360
8361             Process_Interface_Name (Def_Id, Arg3, Arg4);
8362             Set_Exported (Def_Id, Arg2);
8363
8364             --  If the entity is a deferred constant, propagate the information
8365             --  to the full view, because gigi elaborates the full view only.
8366
8367             if Ekind (Def_Id) = E_Constant
8368               and then Present (Full_View (Def_Id))
8369             then
8370                declare
8371                   Id2 : constant Entity_Id := Full_View (Def_Id);
8372                begin
8373                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8374                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8375                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8376                end;
8377             end if;
8378          end Export;
8379
8380          ----------------------
8381          -- Export_Exception --
8382          ----------------------
8383
8384          --  pragma Export_Exception (
8385          --        [Internal         =>] LOCAL_NAME
8386          --     [, [External         =>] EXTERNAL_SYMBOL]
8387          --     [, [Form     =>] Ada | VMS]
8388          --     [, [Code     =>] static_integer_EXPRESSION]);
8389
8390          when Pragma_Export_Exception => Export_Exception : declare
8391             Args  : Args_List (1 .. 4);
8392             Names : constant Name_List (1 .. 4) := (
8393                       Name_Internal,
8394                       Name_External,
8395                       Name_Form,
8396                       Name_Code);
8397
8398             Internal : Node_Id renames Args (1);
8399             External : Node_Id renames Args (2);
8400             Form     : Node_Id renames Args (3);
8401             Code     : Node_Id renames Args (4);
8402
8403          begin
8404             GNAT_Pragma;
8405
8406             if Inside_A_Generic then
8407                Error_Pragma ("pragma% cannot be used for generic entities");
8408             end if;
8409
8410             Gather_Associations (Names, Args);
8411             Process_Extended_Import_Export_Exception_Pragma (
8412               Arg_Internal => Internal,
8413               Arg_External => External,
8414               Arg_Form     => Form,
8415               Arg_Code     => Code);
8416
8417             if not Is_VMS_Exception (Entity (Internal)) then
8418                Set_Exported (Entity (Internal), Internal);
8419             end if;
8420          end Export_Exception;
8421
8422          ---------------------
8423          -- Export_Function --
8424          ---------------------
8425
8426          --  pragma Export_Function (
8427          --        [Internal         =>] LOCAL_NAME
8428          --     [, [External         =>] EXTERNAL_SYMBOL]
8429          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8430          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8431          --     [, [Mechanism        =>] MECHANISM]
8432          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8433
8434          --  EXTERNAL_SYMBOL ::=
8435          --    IDENTIFIER
8436          --  | static_string_EXPRESSION
8437
8438          --  PARAMETER_TYPES ::=
8439          --    null
8440          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8441
8442          --  TYPE_DESIGNATOR ::=
8443          --    subtype_NAME
8444          --  | subtype_Name ' Access
8445
8446          --  MECHANISM ::=
8447          --    MECHANISM_NAME
8448          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8449
8450          --  MECHANISM_ASSOCIATION ::=
8451          --    [formal_parameter_NAME =>] MECHANISM_NAME
8452
8453          --  MECHANISM_NAME ::=
8454          --    Value
8455          --  | Reference
8456          --  | Descriptor [([Class =>] CLASS_NAME)]
8457
8458          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8459
8460          when Pragma_Export_Function => Export_Function : declare
8461             Args  : Args_List (1 .. 6);
8462             Names : constant Name_List (1 .. 6) := (
8463                       Name_Internal,
8464                       Name_External,
8465                       Name_Parameter_Types,
8466                       Name_Result_Type,
8467                       Name_Mechanism,
8468                       Name_Result_Mechanism);
8469
8470             Internal         : Node_Id renames Args (1);
8471             External         : Node_Id renames Args (2);
8472             Parameter_Types  : Node_Id renames Args (3);
8473             Result_Type      : Node_Id renames Args (4);
8474             Mechanism        : Node_Id renames Args (5);
8475             Result_Mechanism : Node_Id renames Args (6);
8476
8477          begin
8478             GNAT_Pragma;
8479             Gather_Associations (Names, Args);
8480             Process_Extended_Import_Export_Subprogram_Pragma (
8481               Arg_Internal         => Internal,
8482               Arg_External         => External,
8483               Arg_Parameter_Types  => Parameter_Types,
8484               Arg_Result_Type      => Result_Type,
8485               Arg_Mechanism        => Mechanism,
8486               Arg_Result_Mechanism => Result_Mechanism);
8487          end Export_Function;
8488
8489          -------------------
8490          -- Export_Object --
8491          -------------------
8492
8493          --  pragma Export_Object (
8494          --        [Internal =>] LOCAL_NAME
8495          --     [, [External =>] EXTERNAL_SYMBOL]
8496          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8497
8498          --  EXTERNAL_SYMBOL ::=
8499          --    IDENTIFIER
8500          --  | static_string_EXPRESSION
8501
8502          --  PARAMETER_TYPES ::=
8503          --    null
8504          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8505
8506          --  TYPE_DESIGNATOR ::=
8507          --    subtype_NAME
8508          --  | subtype_Name ' Access
8509
8510          --  MECHANISM ::=
8511          --    MECHANISM_NAME
8512          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8513
8514          --  MECHANISM_ASSOCIATION ::=
8515          --    [formal_parameter_NAME =>] MECHANISM_NAME
8516
8517          --  MECHANISM_NAME ::=
8518          --    Value
8519          --  | Reference
8520          --  | Descriptor [([Class =>] CLASS_NAME)]
8521
8522          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8523
8524          when Pragma_Export_Object => Export_Object : declare
8525             Args  : Args_List (1 .. 3);
8526             Names : constant Name_List (1 .. 3) := (
8527                       Name_Internal,
8528                       Name_External,
8529                       Name_Size);
8530
8531             Internal : Node_Id renames Args (1);
8532             External : Node_Id renames Args (2);
8533             Size     : Node_Id renames Args (3);
8534
8535          begin
8536             GNAT_Pragma;
8537             Gather_Associations (Names, Args);
8538             Process_Extended_Import_Export_Object_Pragma (
8539               Arg_Internal => Internal,
8540               Arg_External => External,
8541               Arg_Size     => Size);
8542          end Export_Object;
8543
8544          ----------------------
8545          -- Export_Procedure --
8546          ----------------------
8547
8548          --  pragma Export_Procedure (
8549          --        [Internal         =>] LOCAL_NAME
8550          --     [, [External         =>] EXTERNAL_SYMBOL]
8551          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8552          --     [, [Mechanism        =>] MECHANISM]);
8553
8554          --  EXTERNAL_SYMBOL ::=
8555          --    IDENTIFIER
8556          --  | static_string_EXPRESSION
8557
8558          --  PARAMETER_TYPES ::=
8559          --    null
8560          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8561
8562          --  TYPE_DESIGNATOR ::=
8563          --    subtype_NAME
8564          --  | subtype_Name ' Access
8565
8566          --  MECHANISM ::=
8567          --    MECHANISM_NAME
8568          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8569
8570          --  MECHANISM_ASSOCIATION ::=
8571          --    [formal_parameter_NAME =>] MECHANISM_NAME
8572
8573          --  MECHANISM_NAME ::=
8574          --    Value
8575          --  | Reference
8576          --  | Descriptor [([Class =>] CLASS_NAME)]
8577
8578          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8579
8580          when Pragma_Export_Procedure => Export_Procedure : declare
8581             Args  : Args_List (1 .. 4);
8582             Names : constant Name_List (1 .. 4) := (
8583                       Name_Internal,
8584                       Name_External,
8585                       Name_Parameter_Types,
8586                       Name_Mechanism);
8587
8588             Internal        : Node_Id renames Args (1);
8589             External        : Node_Id renames Args (2);
8590             Parameter_Types : Node_Id renames Args (3);
8591             Mechanism       : Node_Id renames Args (4);
8592
8593          begin
8594             GNAT_Pragma;
8595             Gather_Associations (Names, Args);
8596             Process_Extended_Import_Export_Subprogram_Pragma (
8597               Arg_Internal        => Internal,
8598               Arg_External        => External,
8599               Arg_Parameter_Types => Parameter_Types,
8600               Arg_Mechanism       => Mechanism);
8601          end Export_Procedure;
8602
8603          ------------------
8604          -- Export_Value --
8605          ------------------
8606
8607          --  pragma Export_Value (
8608          --     [Value     =>] static_integer_EXPRESSION,
8609          --     [Link_Name =>] static_string_EXPRESSION);
8610
8611          when Pragma_Export_Value =>
8612             GNAT_Pragma;
8613             Check_Arg_Order ((Name_Value, Name_Link_Name));
8614             Check_Arg_Count (2);
8615
8616             Check_Optional_Identifier (Arg1, Name_Value);
8617             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8618
8619             Check_Optional_Identifier (Arg2, Name_Link_Name);
8620             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8621
8622          -----------------------------
8623          -- Export_Valued_Procedure --
8624          -----------------------------
8625
8626          --  pragma Export_Valued_Procedure (
8627          --        [Internal         =>] LOCAL_NAME
8628          --     [, [External         =>] EXTERNAL_SYMBOL,]
8629          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8630          --     [, [Mechanism        =>] MECHANISM]);
8631
8632          --  EXTERNAL_SYMBOL ::=
8633          --    IDENTIFIER
8634          --  | static_string_EXPRESSION
8635
8636          --  PARAMETER_TYPES ::=
8637          --    null
8638          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8639
8640          --  TYPE_DESIGNATOR ::=
8641          --    subtype_NAME
8642          --  | subtype_Name ' Access
8643
8644          --  MECHANISM ::=
8645          --    MECHANISM_NAME
8646          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8647
8648          --  MECHANISM_ASSOCIATION ::=
8649          --    [formal_parameter_NAME =>] MECHANISM_NAME
8650
8651          --  MECHANISM_NAME ::=
8652          --    Value
8653          --  | Reference
8654          --  | Descriptor [([Class =>] CLASS_NAME)]
8655
8656          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8657
8658          when Pragma_Export_Valued_Procedure =>
8659          Export_Valued_Procedure : declare
8660             Args  : Args_List (1 .. 4);
8661             Names : constant Name_List (1 .. 4) := (
8662                       Name_Internal,
8663                       Name_External,
8664                       Name_Parameter_Types,
8665                       Name_Mechanism);
8666
8667             Internal        : Node_Id renames Args (1);
8668             External        : Node_Id renames Args (2);
8669             Parameter_Types : Node_Id renames Args (3);
8670             Mechanism       : Node_Id renames Args (4);
8671
8672          begin
8673             GNAT_Pragma;
8674             Gather_Associations (Names, Args);
8675             Process_Extended_Import_Export_Subprogram_Pragma (
8676               Arg_Internal        => Internal,
8677               Arg_External        => External,
8678               Arg_Parameter_Types => Parameter_Types,
8679               Arg_Mechanism       => Mechanism);
8680          end Export_Valued_Procedure;
8681
8682          -------------------
8683          -- Extend_System --
8684          -------------------
8685
8686          --  pragma Extend_System ([Name =>] Identifier);
8687
8688          when Pragma_Extend_System => Extend_System : declare
8689          begin
8690             GNAT_Pragma;
8691             Check_Valid_Configuration_Pragma;
8692             Check_Arg_Count (1);
8693             Check_Optional_Identifier (Arg1, Name_Name);
8694             Check_Arg_Is_Identifier (Arg1);
8695
8696             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8697
8698             if Name_Len > 4
8699               and then Name_Buffer (1 .. 4) = "aux_"
8700             then
8701                if Present (System_Extend_Pragma_Arg) then
8702                   if Chars (Get_Pragma_Arg (Arg1)) =
8703                      Chars (Expression (System_Extend_Pragma_Arg))
8704                   then
8705                      null;
8706                   else
8707                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8708                      Error_Pragma ("pragma% conflicts with that #");
8709                   end if;
8710
8711                else
8712                   System_Extend_Pragma_Arg := Arg1;
8713
8714                   if not GNAT_Mode then
8715                      System_Extend_Unit := Arg1;
8716                   end if;
8717                end if;
8718             else
8719                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8720             end if;
8721          end Extend_System;
8722
8723          ------------------------
8724          -- Extensions_Allowed --
8725          ------------------------
8726
8727          --  pragma Extensions_Allowed (ON | OFF);
8728
8729          when Pragma_Extensions_Allowed =>
8730             GNAT_Pragma;
8731             Check_Arg_Count (1);
8732             Check_No_Identifiers;
8733             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8734
8735             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8736                Extensions_Allowed := True;
8737                Ada_Version := Ada_Version_Type'Last;
8738
8739             else
8740                Extensions_Allowed := False;
8741                Ada_Version := Ada_Version_Explicit;
8742             end if;
8743
8744          --------------
8745          -- External --
8746          --------------
8747
8748          --  pragma External (
8749          --    [   Convention    =>] convention_IDENTIFIER,
8750          --    [   Entity        =>] local_NAME
8751          --    [, [External_Name =>] static_string_EXPRESSION ]
8752          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8753
8754          when Pragma_External => External : declare
8755                Def_Id : Entity_Id;
8756
8757                C : Convention_Id;
8758                pragma Warnings (Off, C);
8759
8760          begin
8761             GNAT_Pragma;
8762             Check_Arg_Order
8763               ((Name_Convention,
8764                 Name_Entity,
8765                 Name_External_Name,
8766                 Name_Link_Name));
8767             Check_At_Least_N_Arguments (2);
8768             Check_At_Most_N_Arguments  (4);
8769             Process_Convention (C, Def_Id);
8770             Note_Possible_Modification
8771               (Get_Pragma_Arg (Arg2), Sure => False);
8772             Process_Interface_Name (Def_Id, Arg3, Arg4);
8773             Set_Exported (Def_Id, Arg2);
8774          end External;
8775
8776          --------------------------
8777          -- External_Name_Casing --
8778          --------------------------
8779
8780          --  pragma External_Name_Casing (
8781          --    UPPERCASE | LOWERCASE
8782          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8783
8784          when Pragma_External_Name_Casing => External_Name_Casing : declare
8785          begin
8786             GNAT_Pragma;
8787             Check_No_Identifiers;
8788
8789             if Arg_Count = 2 then
8790                Check_Arg_Is_One_Of
8791                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8792
8793                case Chars (Get_Pragma_Arg (Arg2)) is
8794                   when Name_As_Is     =>
8795                      Opt.External_Name_Exp_Casing := As_Is;
8796
8797                   when Name_Uppercase =>
8798                      Opt.External_Name_Exp_Casing := Uppercase;
8799
8800                   when Name_Lowercase =>
8801                      Opt.External_Name_Exp_Casing := Lowercase;
8802
8803                   when others =>
8804                      null;
8805                end case;
8806
8807             else
8808                Check_Arg_Count (1);
8809             end if;
8810
8811             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8812
8813             case Chars (Get_Pragma_Arg (Arg1)) is
8814                when Name_Uppercase =>
8815                   Opt.External_Name_Imp_Casing := Uppercase;
8816
8817                when Name_Lowercase =>
8818                   Opt.External_Name_Imp_Casing := Lowercase;
8819
8820                when others =>
8821                   null;
8822             end case;
8823          end External_Name_Casing;
8824
8825          --------------------------
8826          -- Favor_Top_Level --
8827          --------------------------
8828
8829          --  pragma Favor_Top_Level (type_NAME);
8830
8831          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8832                Named_Entity : Entity_Id;
8833
8834          begin
8835             GNAT_Pragma;
8836             Check_No_Identifiers;
8837             Check_Arg_Count (1);
8838             Check_Arg_Is_Local_Name (Arg1);
8839             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8840
8841             --  If it's an access-to-subprogram type (in particular, not a
8842             --  subtype), set the flag on that type.
8843
8844             if Is_Access_Subprogram_Type (Named_Entity) then
8845                Set_Can_Use_Internal_Rep (Named_Entity, False);
8846
8847             --  Otherwise it's an error (name denotes the wrong sort of entity)
8848
8849             else
8850                Error_Pragma_Arg
8851                  ("access-to-subprogram type expected",
8852                   Get_Pragma_Arg (Arg1));
8853             end if;
8854          end Favor_Top_Level;
8855
8856          ---------------
8857          -- Fast_Math --
8858          ---------------
8859
8860          --  pragma Fast_Math;
8861
8862          when Pragma_Fast_Math =>
8863             GNAT_Pragma;
8864             Check_No_Identifiers;
8865             Check_Valid_Configuration_Pragma;
8866             Fast_Math := True;
8867
8868          ---------------------------
8869          -- Finalize_Storage_Only --
8870          ---------------------------
8871
8872          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8873
8874          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8875             Assoc   : constant Node_Id := Arg1;
8876             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8877             Typ     : Entity_Id;
8878
8879          begin
8880             GNAT_Pragma;
8881             Check_No_Identifiers;
8882             Check_Arg_Count (1);
8883             Check_Arg_Is_Local_Name (Arg1);
8884
8885             Find_Type (Type_Id);
8886             Typ := Entity (Type_Id);
8887
8888             if Typ = Any_Type
8889               or else Rep_Item_Too_Early (Typ, N)
8890             then
8891                return;
8892             else
8893                Typ := Underlying_Type (Typ);
8894             end if;
8895
8896             if not Is_Controlled (Typ) then
8897                Error_Pragma ("pragma% must specify controlled type");
8898             end if;
8899
8900             Check_First_Subtype (Arg1);
8901
8902             if Finalize_Storage_Only (Typ) then
8903                Error_Pragma ("duplicate pragma%, only one allowed");
8904
8905             elsif not Rep_Item_Too_Late (Typ, N) then
8906                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8907             end if;
8908          end Finalize_Storage;
8909
8910          --------------------------
8911          -- Float_Representation --
8912          --------------------------
8913
8914          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8915
8916          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8917
8918          when Pragma_Float_Representation => Float_Representation : declare
8919             Argx : Node_Id;
8920             Digs : Nat;
8921             Ent  : Entity_Id;
8922
8923          begin
8924             GNAT_Pragma;
8925
8926             if Arg_Count = 1 then
8927                Check_Valid_Configuration_Pragma;
8928             else
8929                Check_Arg_Count (2);
8930                Check_Optional_Identifier (Arg2, Name_Entity);
8931                Check_Arg_Is_Local_Name (Arg2);
8932             end if;
8933
8934             Check_No_Identifier (Arg1);
8935             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8936
8937             if not OpenVMS_On_Target then
8938                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8939                   Error_Pragma
8940                     ("?pragma% ignored (applies only to Open'V'M'S)");
8941                end if;
8942
8943                return;
8944             end if;
8945
8946             --  One argument case
8947
8948             if Arg_Count = 1 then
8949                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8950                   if Opt.Float_Format = 'I' then
8951                      Error_Pragma ("'I'E'E'E format previously specified");
8952                   end if;
8953
8954                   Opt.Float_Format := 'V';
8955
8956                else
8957                   if Opt.Float_Format = 'V' then
8958                      Error_Pragma ("'V'A'X format previously specified");
8959                   end if;
8960
8961                   Opt.Float_Format := 'I';
8962                end if;
8963
8964                Set_Standard_Fpt_Formats;
8965
8966             --  Two argument case
8967
8968             else
8969                Argx := Get_Pragma_Arg (Arg2);
8970
8971                if not Is_Entity_Name (Argx)
8972                  or else not Is_Floating_Point_Type (Entity (Argx))
8973                then
8974                   Error_Pragma_Arg
8975                     ("second argument of% pragma must be floating-point type",
8976                      Arg2);
8977                end if;
8978
8979                Ent  := Entity (Argx);
8980                Digs := UI_To_Int (Digits_Value (Ent));
8981
8982                --  Two arguments, VAX_Float case
8983
8984                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8985                   case Digs is
8986                      when  6 => Set_F_Float (Ent);
8987                      when  9 => Set_D_Float (Ent);
8988                      when 15 => Set_G_Float (Ent);
8989
8990                      when others =>
8991                         Error_Pragma_Arg
8992                           ("wrong digits value, must be 6,9 or 15", Arg2);
8993                   end case;
8994
8995                --  Two arguments, IEEE_Float case
8996
8997                else
8998                   case Digs is
8999                      when  6 => Set_IEEE_Short (Ent);
9000                      when 15 => Set_IEEE_Long  (Ent);
9001
9002                      when others =>
9003                         Error_Pragma_Arg
9004                           ("wrong digits value, must be 6 or 15", Arg2);
9005                   end case;
9006                end if;
9007             end if;
9008          end Float_Representation;
9009
9010          -----------
9011          -- Ident --
9012          -----------
9013
9014          --  pragma Ident (static_string_EXPRESSION)
9015
9016          --  Note: pragma Comment shares this processing. Pragma Comment is
9017          --  identical to Ident, except that the restriction of the argument to
9018          --  31 characters and the placement restrictions are not enforced for
9019          --  pragma Comment.
9020
9021          when Pragma_Ident | Pragma_Comment => Ident : declare
9022             Str : Node_Id;
9023
9024          begin
9025             GNAT_Pragma;
9026             Check_Arg_Count (1);
9027             Check_No_Identifiers;
9028             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9029             Store_Note (N);
9030
9031             --  For pragma Ident, preserve DEC compatibility by requiring the
9032             --  pragma to appear in a declarative part or package spec.
9033
9034             if Prag_Id = Pragma_Ident then
9035                Check_Is_In_Decl_Part_Or_Package_Spec;
9036             end if;
9037
9038             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9039
9040             declare
9041                CS : Node_Id;
9042                GP : Node_Id;
9043
9044             begin
9045                GP := Parent (Parent (N));
9046
9047                if Nkind_In (GP, N_Package_Declaration,
9048                                 N_Generic_Package_Declaration)
9049                then
9050                   GP := Parent (GP);
9051                end if;
9052
9053                --  If we have a compilation unit, then record the ident value,
9054                --  checking for improper duplication.
9055
9056                if Nkind (GP) = N_Compilation_Unit then
9057                   CS := Ident_String (Current_Sem_Unit);
9058
9059                   if Present (CS) then
9060
9061                      --  For Ident, we do not permit multiple instances
9062
9063                      if Prag_Id = Pragma_Ident then
9064                         Error_Pragma ("duplicate% pragma not permitted");
9065
9066                      --  For Comment, we concatenate the string, unless we want
9067                      --  to preserve the tree structure for ASIS.
9068
9069                      elsif not ASIS_Mode then
9070                         Start_String (Strval (CS));
9071                         Store_String_Char (' ');
9072                         Store_String_Chars (Strval (Str));
9073                         Set_Strval (CS, End_String);
9074                      end if;
9075
9076                   else
9077                      --  In VMS, the effect of IDENT is achieved by passing
9078                      --  --identification=name as a --for-linker switch.
9079
9080                      if OpenVMS_On_Target then
9081                         Start_String;
9082                         Store_String_Chars
9083                           ("--for-linker=--identification=");
9084                         String_To_Name_Buffer (Strval (Str));
9085                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
9086
9087                         --  Only the last processed IDENT is saved. The main
9088                         --  purpose is so an IDENT associated with a main
9089                         --  procedure will be used in preference to an IDENT
9090                         --  associated with a with'd package.
9091
9092                         Replace_Linker_Option_String
9093                           (End_String, "--for-linker=--identification=");
9094                      end if;
9095
9096                      Set_Ident_String (Current_Sem_Unit, Str);
9097                   end if;
9098
9099                --  For subunits, we just ignore the Ident, since in GNAT these
9100                --  are not separate object files, and hence not separate units
9101                --  in the unit table.
9102
9103                elsif Nkind (GP) = N_Subunit then
9104                   null;
9105
9106                --  Otherwise we have a misplaced pragma Ident, but we ignore
9107                --  this if we are in an instantiation, since it comes from
9108                --  a generic, and has no relevance to the instantiation.
9109
9110                elsif Prag_Id = Pragma_Ident then
9111                   if Instantiation_Location (Loc) = No_Location then
9112                      Error_Pragma ("pragma% only allowed at outer level");
9113                   end if;
9114                end if;
9115             end;
9116          end Ident;
9117
9118          -----------------
9119          -- Implemented --
9120          -----------------
9121
9122          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9123          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9124
9125          when Pragma_Implemented => Implemented : declare
9126             Proc_Id : Entity_Id;
9127             Typ     : Entity_Id;
9128
9129          begin
9130             Ada_2012_Pragma;
9131             Check_Arg_Count (2);
9132             Check_No_Identifiers;
9133             Check_Arg_Is_Identifier (Arg1);
9134             Check_Arg_Is_Local_Name (Arg1);
9135             Check_Arg_Is_One_Of
9136               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9137
9138             --  Extract the name of the local procedure
9139
9140             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9141
9142             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9143             --  primitive procedure of a synchronized tagged type.
9144
9145             if Ekind (Proc_Id) = E_Procedure
9146               and then Is_Primitive (Proc_Id)
9147               and then Present (First_Formal (Proc_Id))
9148             then
9149                Typ := Etype (First_Formal (Proc_Id));
9150
9151                if Is_Tagged_Type (Typ)
9152                  and then
9153
9154                   --  Check for a protected, a synchronized or a task interface
9155
9156                    ((Is_Interface (Typ)
9157                        and then Is_Synchronized_Interface (Typ))
9158
9159                   --  Check for a protected type or a task type that implements
9160                   --  an interface.
9161
9162                    or else
9163                     (Is_Concurrent_Record_Type (Typ)
9164                        and then Present (Interfaces (Typ)))
9165
9166                   --  Check for a private record extension with keyword
9167                   --  "synchronized".
9168
9169                    or else
9170                     (Ekind_In (Typ, E_Record_Type_With_Private,
9171                                     E_Record_Subtype_With_Private)
9172                        and then Synchronized_Present (Parent (Typ))))
9173                then
9174                   null;
9175                else
9176                   Error_Pragma_Arg
9177                     ("controlling formal must be of synchronized " &
9178                      "tagged type", Arg1);
9179                   return;
9180                end if;
9181
9182             --  Procedures declared inside a protected type must be accepted
9183
9184             elsif Ekind (Proc_Id) = E_Procedure
9185               and then Is_Protected_Type (Scope (Proc_Id))
9186             then
9187                null;
9188
9189             --  The first argument is not a primitive procedure
9190
9191             else
9192                Error_Pragma_Arg
9193                  ("pragma % must be applied to a primitive procedure", Arg1);
9194                return;
9195             end if;
9196
9197             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9198             --  By_Protected_Procedure to the primitive procedure of a task
9199             --  interface.
9200
9201             if Chars (Arg2) = Name_By_Protected_Procedure
9202               and then Is_Interface (Typ)
9203               and then Is_Task_Interface (Typ)
9204             then
9205                Error_Pragma_Arg
9206                  ("implementation kind By_Protected_Procedure cannot be " &
9207                   "applied to a task interface primitive", Arg2);
9208                return;
9209             end if;
9210
9211             Record_Rep_Item (Proc_Id, N);
9212          end Implemented;
9213
9214          ----------------------
9215          -- Implicit_Packing --
9216          ----------------------
9217
9218          --  pragma Implicit_Packing;
9219
9220          when Pragma_Implicit_Packing =>
9221             GNAT_Pragma;
9222             Check_Arg_Count (0);
9223             Implicit_Packing := True;
9224
9225          ------------
9226          -- Import --
9227          ------------
9228
9229          --  pragma Import (
9230          --       [Convention    =>] convention_IDENTIFIER,
9231          --       [Entity        =>] local_NAME
9232          --    [, [External_Name =>] static_string_EXPRESSION ]
9233          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9234
9235          when Pragma_Import =>
9236             Check_Ada_83_Warning;
9237             Check_Arg_Order
9238               ((Name_Convention,
9239                 Name_Entity,
9240                 Name_External_Name,
9241                 Name_Link_Name));
9242             Check_At_Least_N_Arguments (2);
9243             Check_At_Most_N_Arguments  (4);
9244             Process_Import_Or_Interface;
9245
9246          ----------------------
9247          -- Import_Exception --
9248          ----------------------
9249
9250          --  pragma Import_Exception (
9251          --        [Internal         =>] LOCAL_NAME
9252          --     [, [External         =>] EXTERNAL_SYMBOL]
9253          --     [, [Form     =>] Ada | VMS]
9254          --     [, [Code     =>] static_integer_EXPRESSION]);
9255
9256          when Pragma_Import_Exception => Import_Exception : declare
9257             Args  : Args_List (1 .. 4);
9258             Names : constant Name_List (1 .. 4) := (
9259                       Name_Internal,
9260                       Name_External,
9261                       Name_Form,
9262                       Name_Code);
9263
9264             Internal : Node_Id renames Args (1);
9265             External : Node_Id renames Args (2);
9266             Form     : Node_Id renames Args (3);
9267             Code     : Node_Id renames Args (4);
9268
9269          begin
9270             GNAT_Pragma;
9271             Gather_Associations (Names, Args);
9272
9273             if Present (External) and then Present (Code) then
9274                Error_Pragma
9275                  ("cannot give both External and Code options for pragma%");
9276             end if;
9277
9278             Process_Extended_Import_Export_Exception_Pragma (
9279               Arg_Internal => Internal,
9280               Arg_External => External,
9281               Arg_Form     => Form,
9282               Arg_Code     => Code);
9283
9284             if not Is_VMS_Exception (Entity (Internal)) then
9285                Set_Imported (Entity (Internal));
9286             end if;
9287          end Import_Exception;
9288
9289          ---------------------
9290          -- Import_Function --
9291          ---------------------
9292
9293          --  pragma Import_Function (
9294          --        [Internal                 =>] LOCAL_NAME,
9295          --     [, [External                 =>] EXTERNAL_SYMBOL]
9296          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9297          --     [, [Result_Type              =>] SUBTYPE_MARK]
9298          --     [, [Mechanism                =>] MECHANISM]
9299          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9300          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9301
9302          --  EXTERNAL_SYMBOL ::=
9303          --    IDENTIFIER
9304          --  | static_string_EXPRESSION
9305
9306          --  PARAMETER_TYPES ::=
9307          --    null
9308          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9309
9310          --  TYPE_DESIGNATOR ::=
9311          --    subtype_NAME
9312          --  | subtype_Name ' Access
9313
9314          --  MECHANISM ::=
9315          --    MECHANISM_NAME
9316          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9317
9318          --  MECHANISM_ASSOCIATION ::=
9319          --    [formal_parameter_NAME =>] MECHANISM_NAME
9320
9321          --  MECHANISM_NAME ::=
9322          --    Value
9323          --  | Reference
9324          --  | Descriptor [([Class =>] CLASS_NAME)]
9325
9326          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9327
9328          when Pragma_Import_Function => Import_Function : declare
9329             Args  : Args_List (1 .. 7);
9330             Names : constant Name_List (1 .. 7) := (
9331                       Name_Internal,
9332                       Name_External,
9333                       Name_Parameter_Types,
9334                       Name_Result_Type,
9335                       Name_Mechanism,
9336                       Name_Result_Mechanism,
9337                       Name_First_Optional_Parameter);
9338
9339             Internal                 : Node_Id renames Args (1);
9340             External                 : Node_Id renames Args (2);
9341             Parameter_Types          : Node_Id renames Args (3);
9342             Result_Type              : Node_Id renames Args (4);
9343             Mechanism                : Node_Id renames Args (5);
9344             Result_Mechanism         : Node_Id renames Args (6);
9345             First_Optional_Parameter : Node_Id renames Args (7);
9346
9347          begin
9348             GNAT_Pragma;
9349             Gather_Associations (Names, Args);
9350             Process_Extended_Import_Export_Subprogram_Pragma (
9351               Arg_Internal                 => Internal,
9352               Arg_External                 => External,
9353               Arg_Parameter_Types          => Parameter_Types,
9354               Arg_Result_Type              => Result_Type,
9355               Arg_Mechanism                => Mechanism,
9356               Arg_Result_Mechanism         => Result_Mechanism,
9357               Arg_First_Optional_Parameter => First_Optional_Parameter);
9358          end Import_Function;
9359
9360          -------------------
9361          -- Import_Object --
9362          -------------------
9363
9364          --  pragma Import_Object (
9365          --        [Internal =>] LOCAL_NAME
9366          --     [, [External =>] EXTERNAL_SYMBOL]
9367          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9368
9369          --  EXTERNAL_SYMBOL ::=
9370          --    IDENTIFIER
9371          --  | static_string_EXPRESSION
9372
9373          when Pragma_Import_Object => Import_Object : declare
9374             Args  : Args_List (1 .. 3);
9375             Names : constant Name_List (1 .. 3) := (
9376                       Name_Internal,
9377                       Name_External,
9378                       Name_Size);
9379
9380             Internal : Node_Id renames Args (1);
9381             External : Node_Id renames Args (2);
9382             Size     : Node_Id renames Args (3);
9383
9384          begin
9385             GNAT_Pragma;
9386             Gather_Associations (Names, Args);
9387             Process_Extended_Import_Export_Object_Pragma (
9388               Arg_Internal => Internal,
9389               Arg_External => External,
9390               Arg_Size     => Size);
9391          end Import_Object;
9392
9393          ----------------------
9394          -- Import_Procedure --
9395          ----------------------
9396
9397          --  pragma Import_Procedure (
9398          --        [Internal                 =>] LOCAL_NAME
9399          --     [, [External                 =>] EXTERNAL_SYMBOL]
9400          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9401          --     [, [Mechanism                =>] MECHANISM]
9402          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9403
9404          --  EXTERNAL_SYMBOL ::=
9405          --    IDENTIFIER
9406          --  | static_string_EXPRESSION
9407
9408          --  PARAMETER_TYPES ::=
9409          --    null
9410          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9411
9412          --  TYPE_DESIGNATOR ::=
9413          --    subtype_NAME
9414          --  | subtype_Name ' Access
9415
9416          --  MECHANISM ::=
9417          --    MECHANISM_NAME
9418          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9419
9420          --  MECHANISM_ASSOCIATION ::=
9421          --    [formal_parameter_NAME =>] MECHANISM_NAME
9422
9423          --  MECHANISM_NAME ::=
9424          --    Value
9425          --  | Reference
9426          --  | Descriptor [([Class =>] CLASS_NAME)]
9427
9428          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9429
9430          when Pragma_Import_Procedure => Import_Procedure : declare
9431             Args  : Args_List (1 .. 5);
9432             Names : constant Name_List (1 .. 5) := (
9433                       Name_Internal,
9434                       Name_External,
9435                       Name_Parameter_Types,
9436                       Name_Mechanism,
9437                       Name_First_Optional_Parameter);
9438
9439             Internal                 : Node_Id renames Args (1);
9440             External                 : Node_Id renames Args (2);
9441             Parameter_Types          : Node_Id renames Args (3);
9442             Mechanism                : Node_Id renames Args (4);
9443             First_Optional_Parameter : Node_Id renames Args (5);
9444
9445          begin
9446             GNAT_Pragma;
9447             Gather_Associations (Names, Args);
9448             Process_Extended_Import_Export_Subprogram_Pragma (
9449               Arg_Internal                 => Internal,
9450               Arg_External                 => External,
9451               Arg_Parameter_Types          => Parameter_Types,
9452               Arg_Mechanism                => Mechanism,
9453               Arg_First_Optional_Parameter => First_Optional_Parameter);
9454          end Import_Procedure;
9455
9456          -----------------------------
9457          -- Import_Valued_Procedure --
9458          -----------------------------
9459
9460          --  pragma Import_Valued_Procedure (
9461          --        [Internal                 =>] LOCAL_NAME
9462          --     [, [External                 =>] EXTERNAL_SYMBOL]
9463          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9464          --     [, [Mechanism                =>] MECHANISM]
9465          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9466
9467          --  EXTERNAL_SYMBOL ::=
9468          --    IDENTIFIER
9469          --  | static_string_EXPRESSION
9470
9471          --  PARAMETER_TYPES ::=
9472          --    null
9473          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9474
9475          --  TYPE_DESIGNATOR ::=
9476          --    subtype_NAME
9477          --  | subtype_Name ' Access
9478
9479          --  MECHANISM ::=
9480          --    MECHANISM_NAME
9481          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9482
9483          --  MECHANISM_ASSOCIATION ::=
9484          --    [formal_parameter_NAME =>] MECHANISM_NAME
9485
9486          --  MECHANISM_NAME ::=
9487          --    Value
9488          --  | Reference
9489          --  | Descriptor [([Class =>] CLASS_NAME)]
9490
9491          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9492
9493          when Pragma_Import_Valued_Procedure =>
9494          Import_Valued_Procedure : declare
9495             Args  : Args_List (1 .. 5);
9496             Names : constant Name_List (1 .. 5) := (
9497                       Name_Internal,
9498                       Name_External,
9499                       Name_Parameter_Types,
9500                       Name_Mechanism,
9501                       Name_First_Optional_Parameter);
9502
9503             Internal                 : Node_Id renames Args (1);
9504             External                 : Node_Id renames Args (2);
9505             Parameter_Types          : Node_Id renames Args (3);
9506             Mechanism                : Node_Id renames Args (4);
9507             First_Optional_Parameter : Node_Id renames Args (5);
9508
9509          begin
9510             GNAT_Pragma;
9511             Gather_Associations (Names, Args);
9512             Process_Extended_Import_Export_Subprogram_Pragma (
9513               Arg_Internal                 => Internal,
9514               Arg_External                 => External,
9515               Arg_Parameter_Types          => Parameter_Types,
9516               Arg_Mechanism                => Mechanism,
9517               Arg_First_Optional_Parameter => First_Optional_Parameter);
9518          end Import_Valued_Procedure;
9519
9520          -----------------
9521          -- Independent --
9522          -----------------
9523
9524          --  pragma Independent (LOCAL_NAME);
9525
9526          when Pragma_Independent => Independent : declare
9527             E_Id : Node_Id;
9528             E    : Entity_Id;
9529             D    : Node_Id;
9530             K    : Node_Kind;
9531
9532          begin
9533             Check_Ada_83_Warning;
9534             Ada_2012_Pragma;
9535             Check_No_Identifiers;
9536             Check_Arg_Count (1);
9537             Check_Arg_Is_Local_Name (Arg1);
9538             E_Id := Get_Pragma_Arg (Arg1);
9539
9540             if Etype (E_Id) = Any_Type then
9541                return;
9542             end if;
9543
9544             E := Entity (E_Id);
9545             D := Declaration_Node (E);
9546             K := Nkind (D);
9547
9548             --  Check duplicate before we chain ourselves!
9549
9550             Check_Duplicate_Pragma (E);
9551
9552             --  Check appropriate entity
9553
9554             if Is_Type (E) then
9555                if Rep_Item_Too_Early (E, N)
9556                     or else
9557                   Rep_Item_Too_Late (E, N)
9558                then
9559                   return;
9560                else
9561                   Check_First_Subtype (Arg1);
9562                end if;
9563
9564             elsif K = N_Object_Declaration
9565               or else (K = N_Component_Declaration
9566                        and then Original_Record_Component (E) = E)
9567             then
9568                if Rep_Item_Too_Late (E, N) then
9569                   return;
9570                end if;
9571
9572             else
9573                Error_Pragma_Arg
9574                  ("inappropriate entity for pragma%", Arg1);
9575             end if;
9576
9577             Independence_Checks.Append ((N, E));
9578          end Independent;
9579
9580          ----------------------------
9581          -- Independent_Components --
9582          ----------------------------
9583
9584          --  pragma Atomic_Components (array_LOCAL_NAME);
9585
9586          --  This processing is shared by Volatile_Components
9587
9588          when Pragma_Independent_Components => Independent_Components : declare
9589             E_Id : Node_Id;
9590             E    : Entity_Id;
9591             D    : Node_Id;
9592             K    : Node_Kind;
9593
9594          begin
9595             Check_Ada_83_Warning;
9596             Ada_2012_Pragma;
9597             Check_No_Identifiers;
9598             Check_Arg_Count (1);
9599             Check_Arg_Is_Local_Name (Arg1);
9600             E_Id := Get_Pragma_Arg (Arg1);
9601
9602             if Etype (E_Id) = Any_Type then
9603                return;
9604             end if;
9605
9606             E := Entity (E_Id);
9607
9608             --  Check duplicate before we chain ourselves!
9609
9610             Check_Duplicate_Pragma (E);
9611
9612             --  Check appropriate entity
9613
9614             if Rep_Item_Too_Early (E, N)
9615                  or else
9616                Rep_Item_Too_Late (E, N)
9617             then
9618                return;
9619             end if;
9620
9621             D := Declaration_Node (E);
9622             K := Nkind (D);
9623
9624             if (K = N_Full_Type_Declaration
9625                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9626               or else
9627                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9628                    and then Nkind (D) = N_Object_Declaration
9629                    and then Nkind (Object_Definition (D)) =
9630                                        N_Constrained_Array_Definition)
9631             then
9632                Independence_Checks.Append ((N, E));
9633
9634             else
9635                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9636             end if;
9637          end Independent_Components;
9638
9639          ------------------------
9640          -- Initialize_Scalars --
9641          ------------------------
9642
9643          --  pragma Initialize_Scalars;
9644
9645          when Pragma_Initialize_Scalars =>
9646             GNAT_Pragma;
9647             Check_Arg_Count (0);
9648             Check_Valid_Configuration_Pragma;
9649             Check_Restriction (No_Initialize_Scalars, N);
9650
9651             --  Initialize_Scalars creates false positives in CodePeer, and
9652             --  incorrect negative results in Alfa mode, so ignore this pragma
9653             --  in these modes.
9654
9655             if not Restriction_Active (No_Initialize_Scalars)
9656               and then not (CodePeer_Mode or Alfa_Mode)
9657             then
9658                Init_Or_Norm_Scalars := True;
9659                Initialize_Scalars := True;
9660             end if;
9661
9662          ------------
9663          -- Inline --
9664          ------------
9665
9666          --  pragma Inline ( NAME {, NAME} );
9667
9668          when Pragma_Inline =>
9669
9670             --  Pragma is active if inlining option is active
9671
9672             Process_Inline (Inline_Active);
9673
9674          -------------------
9675          -- Inline_Always --
9676          -------------------
9677
9678          --  pragma Inline_Always ( NAME {, NAME} );
9679
9680          when Pragma_Inline_Always =>
9681             GNAT_Pragma;
9682
9683             --  Pragma always active unless in CodePeer or Alfa mode, since
9684             --  this causes walk order issues.
9685
9686             if not (CodePeer_Mode or Alfa_Mode) then
9687                Process_Inline (True);
9688             end if;
9689
9690          --------------------
9691          -- Inline_Generic --
9692          --------------------
9693
9694          --  pragma Inline_Generic (NAME {, NAME});
9695
9696          when Pragma_Inline_Generic =>
9697             GNAT_Pragma;
9698             Process_Generic_List;
9699
9700          ----------------------
9701          -- Inspection_Point --
9702          ----------------------
9703
9704          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9705
9706          when Pragma_Inspection_Point => Inspection_Point : declare
9707             Arg : Node_Id;
9708             Exp : Node_Id;
9709
9710          begin
9711             if Arg_Count > 0 then
9712                Arg := Arg1;
9713                loop
9714                   Exp := Get_Pragma_Arg (Arg);
9715                   Analyze (Exp);
9716
9717                   if not Is_Entity_Name (Exp)
9718                     or else not Is_Object (Entity (Exp))
9719                   then
9720                      Error_Pragma_Arg ("object name required", Arg);
9721                   end if;
9722
9723                   Next (Arg);
9724                   exit when No (Arg);
9725                end loop;
9726             end if;
9727          end Inspection_Point;
9728
9729          ---------------
9730          -- Interface --
9731          ---------------
9732
9733          --  pragma Interface (
9734          --    [   Convention    =>] convention_IDENTIFIER,
9735          --    [   Entity        =>] local_NAME
9736          --    [, [External_Name =>] static_string_EXPRESSION ]
9737          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9738
9739          when Pragma_Interface =>
9740             GNAT_Pragma;
9741             Check_Arg_Order
9742               ((Name_Convention,
9743                 Name_Entity,
9744                 Name_External_Name,
9745                 Name_Link_Name));
9746             Check_At_Least_N_Arguments (2);
9747             Check_At_Most_N_Arguments  (4);
9748             Process_Import_Or_Interface;
9749
9750             --  In Ada 2005, the permission to use Interface (a reserved word)
9751             --  as a pragma name is considered an obsolescent feature.
9752
9753             if Ada_Version >= Ada_2005 then
9754                Check_Restriction
9755                  (No_Obsolescent_Features, Pragma_Identifier (N));
9756             end if;
9757
9758          --------------------
9759          -- Interface_Name --
9760          --------------------
9761
9762          --  pragma Interface_Name (
9763          --    [  Entity        =>] local_NAME
9764          --    [,[External_Name =>] static_string_EXPRESSION ]
9765          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9766
9767          when Pragma_Interface_Name => Interface_Name : declare
9768             Id     : Node_Id;
9769             Def_Id : Entity_Id;
9770             Hom_Id : Entity_Id;
9771             Found  : Boolean;
9772
9773          begin
9774             GNAT_Pragma;
9775             Check_Arg_Order
9776               ((Name_Entity, Name_External_Name, Name_Link_Name));
9777             Check_At_Least_N_Arguments (2);
9778             Check_At_Most_N_Arguments  (3);
9779             Id := Get_Pragma_Arg (Arg1);
9780             Analyze (Id);
9781
9782             if not Is_Entity_Name (Id) then
9783                Error_Pragma_Arg
9784                  ("first argument for pragma% must be entity name", Arg1);
9785             elsif Etype (Id) = Any_Type then
9786                return;
9787             else
9788                Def_Id := Entity (Id);
9789             end if;
9790
9791             --  Special DEC-compatible processing for the object case, forces
9792             --  object to be imported.
9793
9794             if Ekind (Def_Id) = E_Variable then
9795                Kill_Size_Check_Code (Def_Id);
9796                Note_Possible_Modification (Id, Sure => False);
9797
9798                --  Initialization is not allowed for imported variable
9799
9800                if Present (Expression (Parent (Def_Id)))
9801                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9802                then
9803                   Error_Msg_Sloc := Sloc (Def_Id);
9804                   Error_Pragma_Arg
9805                     ("no initialization allowed for declaration of& #",
9806                      Arg2);
9807
9808                else
9809                   --  For compatibility, support VADS usage of providing both
9810                   --  pragmas Interface and Interface_Name to obtain the effect
9811                   --  of a single Import pragma.
9812
9813                   if Is_Imported (Def_Id)
9814                     and then Present (First_Rep_Item (Def_Id))
9815                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9816                     and then
9817                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9818                   then
9819                      null;
9820                   else
9821                      Set_Imported (Def_Id);
9822                   end if;
9823
9824                   Set_Is_Public (Def_Id);
9825                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9826                end if;
9827
9828             --  Otherwise must be subprogram
9829
9830             elsif not Is_Subprogram (Def_Id) then
9831                Error_Pragma_Arg
9832                  ("argument of pragma% is not subprogram", Arg1);
9833
9834             else
9835                Check_At_Most_N_Arguments (3);
9836                Hom_Id := Def_Id;
9837                Found := False;
9838
9839                --  Loop through homonyms
9840
9841                loop
9842                   Def_Id := Get_Base_Subprogram (Hom_Id);
9843
9844                   if Is_Imported (Def_Id) then
9845                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9846                      Found := True;
9847                   end if;
9848
9849                   exit when From_Aspect_Specification (N);
9850                   Hom_Id := Homonym (Hom_Id);
9851
9852                   exit when No (Hom_Id)
9853                     or else Scope (Hom_Id) /= Current_Scope;
9854                end loop;
9855
9856                if not Found then
9857                   Error_Pragma_Arg
9858                     ("argument of pragma% is not imported subprogram",
9859                      Arg1);
9860                end if;
9861             end if;
9862          end Interface_Name;
9863
9864          -----------------------
9865          -- Interrupt_Handler --
9866          -----------------------
9867
9868          --  pragma Interrupt_Handler (handler_NAME);
9869
9870          when Pragma_Interrupt_Handler =>
9871             Check_Ada_83_Warning;
9872             Check_Arg_Count (1);
9873             Check_No_Identifiers;
9874
9875             if No_Run_Time_Mode then
9876                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9877             else
9878                Check_Interrupt_Or_Attach_Handler;
9879                Process_Interrupt_Or_Attach_Handler;
9880             end if;
9881
9882          ------------------------
9883          -- Interrupt_Priority --
9884          ------------------------
9885
9886          --  pragma Interrupt_Priority [(EXPRESSION)];
9887
9888          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9889             P   : constant Node_Id := Parent (N);
9890             Arg : Node_Id;
9891
9892          begin
9893             Check_Ada_83_Warning;
9894
9895             if Arg_Count /= 0 then
9896                Arg := Get_Pragma_Arg (Arg1);
9897                Check_Arg_Count (1);
9898                Check_No_Identifiers;
9899
9900                --  The expression must be analyzed in the special manner
9901                --  described in "Handling of Default and Per-Object
9902                --  Expressions" in sem.ads.
9903
9904                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9905             end if;
9906
9907             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9908                Pragma_Misplaced;
9909                return;
9910
9911             elsif Has_Pragma_Priority (P) then
9912                Error_Pragma ("duplicate pragma% not allowed");
9913
9914             else
9915                Set_Has_Pragma_Priority (P, True);
9916                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9917             end if;
9918          end Interrupt_Priority;
9919
9920          ---------------------
9921          -- Interrupt_State --
9922          ---------------------
9923
9924          --  pragma Interrupt_State (
9925          --    [Name  =>] INTERRUPT_ID,
9926          --    [State =>] INTERRUPT_STATE);
9927
9928          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9929          --  INTERRUPT_STATE => System | Runtime | User
9930
9931          --  Note: if the interrupt id is given as an identifier, then it must
9932          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9933          --  given as a static integer expression which must be in the range of
9934          --  Ada.Interrupts.Interrupt_ID.
9935
9936          when Pragma_Interrupt_State => Interrupt_State : declare
9937
9938             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9939             --  This is the entity Ada.Interrupts.Interrupt_ID;
9940
9941             State_Type : Character;
9942             --  Set to 's'/'r'/'u' for System/Runtime/User
9943
9944             IST_Num : Pos;
9945             --  Index to entry in Interrupt_States table
9946
9947             Int_Val : Uint;
9948             --  Value of interrupt
9949
9950             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9951             --  The first argument to the pragma
9952
9953             Int_Ent : Entity_Id;
9954             --  Interrupt entity in Ada.Interrupts.Names
9955
9956          begin
9957             GNAT_Pragma;
9958             Check_Arg_Order ((Name_Name, Name_State));
9959             Check_Arg_Count (2);
9960
9961             Check_Optional_Identifier (Arg1, Name_Name);
9962             Check_Optional_Identifier (Arg2, Name_State);
9963             Check_Arg_Is_Identifier (Arg2);
9964
9965             --  First argument is identifier
9966
9967             if Nkind (Arg1X) = N_Identifier then
9968
9969                --  Search list of names in Ada.Interrupts.Names
9970
9971                Int_Ent := First_Entity (RTE (RE_Names));
9972                loop
9973                   if No (Int_Ent) then
9974                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9975
9976                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9977                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9978                      exit;
9979                   end if;
9980
9981                   Next_Entity (Int_Ent);
9982                end loop;
9983
9984             --  First argument is not an identifier, so it must be a static
9985             --  expression of type Ada.Interrupts.Interrupt_ID.
9986
9987             else
9988                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9989                Int_Val := Expr_Value (Arg1X);
9990
9991                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9992                     or else
9993                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9994                then
9995                   Error_Pragma_Arg
9996                     ("value not in range of type " &
9997                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9998                end if;
9999             end if;
10000
10001             --  Check OK state
10002
10003             case Chars (Get_Pragma_Arg (Arg2)) is
10004                when Name_Runtime => State_Type := 'r';
10005                when Name_System  => State_Type := 's';
10006                when Name_User    => State_Type := 'u';
10007
10008                when others =>
10009                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
10010             end case;
10011
10012             --  Check if entry is already stored
10013
10014             IST_Num := Interrupt_States.First;
10015             loop
10016                --  If entry not found, add it
10017
10018                if IST_Num > Interrupt_States.Last then
10019                   Interrupt_States.Append
10020                     ((Interrupt_Number => UI_To_Int (Int_Val),
10021                       Interrupt_State  => State_Type,
10022                       Pragma_Loc       => Loc));
10023                   exit;
10024
10025                --  Case of entry for the same entry
10026
10027                elsif Int_Val = Interrupt_States.Table (IST_Num).
10028                                                            Interrupt_Number
10029                then
10030                   --  If state matches, done, no need to make redundant entry
10031
10032                   exit when
10033                     State_Type = Interrupt_States.Table (IST_Num).
10034                                                            Interrupt_State;
10035
10036                   --  Otherwise if state does not match, error
10037
10038                   Error_Msg_Sloc :=
10039                     Interrupt_States.Table (IST_Num).Pragma_Loc;
10040                   Error_Pragma_Arg
10041                     ("state conflicts with that given #", Arg2);
10042                   exit;
10043                end if;
10044
10045                IST_Num := IST_Num + 1;
10046             end loop;
10047          end Interrupt_State;
10048
10049          ---------------
10050          -- Invariant --
10051          ---------------
10052
10053          --  pragma Invariant
10054          --    ([Entity =>]    type_LOCAL_NAME,
10055          --     [Check  =>]    EXPRESSION
10056          --     [,[Message =>] String_Expression]);
10057
10058          when Pragma_Invariant => Invariant : declare
10059             Type_Id : Node_Id;
10060             Typ     : Entity_Id;
10061
10062             Discard : Boolean;
10063             pragma Unreferenced (Discard);
10064
10065          begin
10066             GNAT_Pragma;
10067             Check_At_Least_N_Arguments (2);
10068             Check_At_Most_N_Arguments (3);
10069             Check_Optional_Identifier (Arg1, Name_Entity);
10070             Check_Optional_Identifier (Arg2, Name_Check);
10071
10072             if Arg_Count = 3 then
10073                Check_Optional_Identifier (Arg3, Name_Message);
10074                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10075             end if;
10076
10077             Check_Arg_Is_Local_Name (Arg1);
10078
10079             Type_Id := Get_Pragma_Arg (Arg1);
10080             Find_Type (Type_Id);
10081             Typ := Entity (Type_Id);
10082
10083             if Typ = Any_Type then
10084                return;
10085
10086             elsif not Ekind_In (Typ, E_Private_Type,
10087                                      E_Record_Type_With_Private,
10088                                      E_Limited_Private_Type)
10089             then
10090                Error_Pragma_Arg
10091                  ("pragma% only allowed for private type", Arg1);
10092             end if;
10093
10094             --  Note that the type has at least one invariant, and also that
10095             --  it has inheritable invariants if we have Invariant'Class.
10096
10097             Set_Has_Invariants (Typ);
10098
10099             if Class_Present (N) then
10100                Set_Has_Inheritable_Invariants (Typ);
10101             end if;
10102
10103             --  The remaining processing is simply to link the pragma on to
10104             --  the rep item chain, for processing when the type is frozen.
10105             --  This is accomplished by a call to Rep_Item_Too_Late.
10106
10107             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10108          end Invariant;
10109
10110          ----------------------
10111          -- Java_Constructor --
10112          ----------------------
10113
10114          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10115
10116          --  Also handles pragma CIL_Constructor
10117
10118          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10119          Java_Constructor : declare
10120             Convention  : Convention_Id;
10121             Def_Id      : Entity_Id;
10122             Hom_Id      : Entity_Id;
10123             Id          : Entity_Id;
10124             This_Formal : Entity_Id;
10125
10126          begin
10127             GNAT_Pragma;
10128             Check_Arg_Count (1);
10129             Check_Optional_Identifier (Arg1, Name_Entity);
10130             Check_Arg_Is_Local_Name (Arg1);
10131
10132             Id := Get_Pragma_Arg (Arg1);
10133             Find_Program_Unit_Name (Id);
10134
10135             --  If we did not find the name, we are done
10136
10137             if Etype (Id) = Any_Type then
10138                return;
10139             end if;
10140
10141             --  Check wrong use of pragma in wrong VM target
10142
10143             if VM_Target = No_VM then
10144                return;
10145
10146             elsif VM_Target = CLI_Target
10147               and then Prag_Id = Pragma_Java_Constructor
10148             then
10149                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10150
10151             elsif VM_Target = JVM_Target
10152               and then Prag_Id = Pragma_CIL_Constructor
10153             then
10154                Error_Pragma ("must use pragma 'Java_'Constructor");
10155             end if;
10156
10157             case Prag_Id is
10158                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
10159                when Pragma_Java_Constructor => Convention := Convention_Java;
10160                when others                  => null;
10161             end case;
10162
10163             Hom_Id := Entity (Id);
10164
10165             --  Loop through homonyms
10166
10167             loop
10168                Def_Id := Get_Base_Subprogram (Hom_Id);
10169
10170                --  The constructor is required to be a function
10171
10172                if Ekind (Def_Id) /= E_Function then
10173                   if VM_Target = JVM_Target then
10174                      Error_Pragma_Arg
10175                        ("pragma% requires function returning a " &
10176                         "'Java access type", Def_Id);
10177                   else
10178                      Error_Pragma_Arg
10179                        ("pragma% requires function returning a " &
10180                         "'C'I'L access type", Def_Id);
10181                   end if;
10182                end if;
10183
10184                --  Check arguments: For tagged type the first formal must be
10185                --  named "this" and its type must be a named access type
10186                --  designating a class-wide tagged type that has convention
10187                --  CIL/Java. The first formal must also have a null default
10188                --  value. For example:
10189
10190                --      type Typ is tagged ...
10191                --      type Ref is access all Typ;
10192                --      pragma Convention (CIL, Typ);
10193
10194                --      function New_Typ (This : Ref) return Ref;
10195                --      function New_Typ (This : Ref; I : Integer) return Ref;
10196                --      pragma Cil_Constructor (New_Typ);
10197
10198                --  Reason: The first formal must NOT be a primitive of the
10199                --  tagged type.
10200
10201                --  This rule also applies to constructors of delegates used
10202                --  to interface with standard target libraries. For example:
10203
10204                --      type Delegate is access procedure ...
10205                --      pragma Import (CIL, Delegate, ...);
10206
10207                --      function new_Delegate
10208                --        (This : Delegate := null; ... ) return Delegate;
10209
10210                --  For value-types this rule does not apply.
10211
10212                if not Is_Value_Type (Etype (Def_Id)) then
10213                   if No (First_Formal (Def_Id)) then
10214                      Error_Msg_Name_1 := Pname;
10215                      Error_Msg_N ("% function must have parameters", Def_Id);
10216                      return;
10217                   end if;
10218
10219                   --  In the JRE library we have several occurrences in which
10220                   --  the "this" parameter is not the first formal.
10221
10222                   This_Formal := First_Formal (Def_Id);
10223
10224                   --  In the JRE library we have several occurrences in which
10225                   --  the "this" parameter is not the first formal. Search for
10226                   --  it.
10227
10228                   if VM_Target = JVM_Target then
10229                      while Present (This_Formal)
10230                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10231                      loop
10232                         Next_Formal (This_Formal);
10233                      end loop;
10234
10235                      if No (This_Formal) then
10236                         This_Formal := First_Formal (Def_Id);
10237                      end if;
10238                   end if;
10239
10240                   --  Warning: The first parameter should be named "this".
10241                   --  We temporarily allow it because we have the following
10242                   --  case in the Java runtime (file s-osinte.ads) ???
10243
10244                   --    function new_Thread
10245                   --      (Self_Id : System.Address) return Thread_Id;
10246                   --    pragma Java_Constructor (new_Thread);
10247
10248                   if VM_Target = JVM_Target
10249                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10250                                = "self_id"
10251                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10252                   then
10253                      null;
10254
10255                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10256                      Error_Msg_Name_1 := Pname;
10257                      Error_Msg_N
10258                        ("first formal of % function must be named `this`",
10259                         Parent (This_Formal));
10260
10261                   elsif not Is_Access_Type (Etype (This_Formal)) then
10262                      Error_Msg_Name_1 := Pname;
10263                      Error_Msg_N
10264                        ("first formal of % function must be an access type",
10265                         Parameter_Type (Parent (This_Formal)));
10266
10267                   --  For delegates the type of the first formal must be a
10268                   --  named access-to-subprogram type (see previous example)
10269
10270                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10271                     and then Ekind (Etype (This_Formal))
10272                                /= E_Access_Subprogram_Type
10273                   then
10274                      Error_Msg_Name_1 := Pname;
10275                      Error_Msg_N
10276                        ("first formal of % function must be a named access" &
10277                         " to subprogram type",
10278                         Parameter_Type (Parent (This_Formal)));
10279
10280                   --  Warning: We should reject anonymous access types because
10281                   --  the constructor must not be handled as a primitive of the
10282                   --  tagged type. We temporarily allow it because this profile
10283                   --  is currently generated by cil2ada???
10284
10285                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10286                     and then not Ekind_In (Etype (This_Formal),
10287                                              E_Access_Type,
10288                                              E_General_Access_Type,
10289                                              E_Anonymous_Access_Type)
10290                   then
10291                      Error_Msg_Name_1 := Pname;
10292                      Error_Msg_N
10293                        ("first formal of % function must be a named access" &
10294                         " type",
10295                         Parameter_Type (Parent (This_Formal)));
10296
10297                   elsif Atree.Convention
10298                          (Designated_Type (Etype (This_Formal))) /= Convention
10299                   then
10300                      Error_Msg_Name_1 := Pname;
10301
10302                      if Convention = Convention_Java then
10303                         Error_Msg_N
10304                           ("pragma% requires convention 'Cil in designated" &
10305                            " type",
10306                            Parameter_Type (Parent (This_Formal)));
10307                      else
10308                         Error_Msg_N
10309                           ("pragma% requires convention 'Java in designated" &
10310                            " type",
10311                            Parameter_Type (Parent (This_Formal)));
10312                      end if;
10313
10314                   elsif No (Expression (Parent (This_Formal)))
10315                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10316                   then
10317                      Error_Msg_Name_1 := Pname;
10318                      Error_Msg_N
10319                        ("pragma% requires first formal with default `null`",
10320                         Parameter_Type (Parent (This_Formal)));
10321                   end if;
10322                end if;
10323
10324                --  Check result type: the constructor must be a function
10325                --  returning:
10326                --   * a value type (only allowed in the CIL compiler)
10327                --   * an access-to-subprogram type with convention Java/CIL
10328                --   * an access-type designating a type that has convention
10329                --     Java/CIL.
10330
10331                if Is_Value_Type (Etype (Def_Id)) then
10332                   null;
10333
10334                --  Access-to-subprogram type with convention Java/CIL
10335
10336                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10337                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10338                      if Convention = Convention_Java then
10339                         Error_Pragma_Arg
10340                           ("pragma% requires function returning a " &
10341                            "'Java access type", Arg1);
10342                      else
10343                         pragma Assert (Convention = Convention_CIL);
10344                         Error_Pragma_Arg
10345                           ("pragma% requires function returning a " &
10346                            "'C'I'L access type", Arg1);
10347                      end if;
10348                   end if;
10349
10350                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10351                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10352                                                    E_General_Access_Type)
10353                     or else
10354                       Atree.Convention
10355                         (Designated_Type (Etype (Def_Id))) /= Convention
10356                   then
10357                      Error_Msg_Name_1 := Pname;
10358
10359                      if Convention = Convention_Java then
10360                         Error_Pragma_Arg
10361                           ("pragma% requires function returning a named" &
10362                            "'Java access type", Arg1);
10363                      else
10364                         Error_Pragma_Arg
10365                           ("pragma% requires function returning a named" &
10366                            "'C'I'L access type", Arg1);
10367                      end if;
10368                   end if;
10369                end if;
10370
10371                Set_Is_Constructor (Def_Id);
10372                Set_Convention     (Def_Id, Convention);
10373                Set_Is_Imported    (Def_Id);
10374
10375                exit when From_Aspect_Specification (N);
10376                Hom_Id := Homonym (Hom_Id);
10377
10378                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10379             end loop;
10380          end Java_Constructor;
10381
10382          ----------------------
10383          -- Java_Interface --
10384          ----------------------
10385
10386          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10387
10388          when Pragma_Java_Interface => Java_Interface : declare
10389             Arg : Node_Id;
10390             Typ : Entity_Id;
10391
10392          begin
10393             GNAT_Pragma;
10394             Check_Arg_Count (1);
10395             Check_Optional_Identifier (Arg1, Name_Entity);
10396             Check_Arg_Is_Local_Name (Arg1);
10397
10398             Arg := Get_Pragma_Arg (Arg1);
10399             Analyze (Arg);
10400
10401             if Etype (Arg) = Any_Type then
10402                return;
10403             end if;
10404
10405             if not Is_Entity_Name (Arg)
10406               or else not Is_Type (Entity (Arg))
10407             then
10408                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10409             end if;
10410
10411             Typ := Underlying_Type (Entity (Arg));
10412
10413             --  For now simply check some of the semantic constraints on the
10414             --  type. This currently leaves out some restrictions on interface
10415             --  types, namely that the parent type must be java.lang.Object.Typ
10416             --  and that all primitives of the type should be declared
10417             --  abstract. ???
10418
10419             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10420                Error_Pragma_Arg ("pragma% requires an abstract "
10421                  & "tagged type", Arg1);
10422
10423             elsif not Has_Discriminants (Typ)
10424               or else Ekind (Etype (First_Discriminant (Typ)))
10425                         /= E_Anonymous_Access_Type
10426               or else
10427                 not Is_Class_Wide_Type
10428                       (Designated_Type (Etype (First_Discriminant (Typ))))
10429             then
10430                Error_Pragma_Arg
10431                  ("type must have a class-wide access discriminant", Arg1);
10432             end if;
10433          end Java_Interface;
10434
10435          ----------------
10436          -- Keep_Names --
10437          ----------------
10438
10439          --  pragma Keep_Names ([On => ] local_NAME);
10440
10441          when Pragma_Keep_Names => Keep_Names : declare
10442             Arg : Node_Id;
10443
10444          begin
10445             GNAT_Pragma;
10446             Check_Arg_Count (1);
10447             Check_Optional_Identifier (Arg1, Name_On);
10448             Check_Arg_Is_Local_Name (Arg1);
10449
10450             Arg := Get_Pragma_Arg (Arg1);
10451             Analyze (Arg);
10452
10453             if Etype (Arg) = Any_Type then
10454                return;
10455             end if;
10456
10457             if not Is_Entity_Name (Arg)
10458               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10459             then
10460                Error_Pragma_Arg
10461                  ("pragma% requires a local enumeration type", Arg1);
10462             end if;
10463
10464             Set_Discard_Names (Entity (Arg), False);
10465          end Keep_Names;
10466
10467          -------------
10468          -- License --
10469          -------------
10470
10471          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10472
10473          when Pragma_License =>
10474             GNAT_Pragma;
10475             Check_Arg_Count (1);
10476             Check_No_Identifiers;
10477             Check_Valid_Configuration_Pragma;
10478             Check_Arg_Is_Identifier (Arg1);
10479
10480             declare
10481                Sind : constant Source_File_Index :=
10482                         Source_Index (Current_Sem_Unit);
10483
10484             begin
10485                case Chars (Get_Pragma_Arg (Arg1)) is
10486                   when Name_GPL =>
10487                      Set_License (Sind, GPL);
10488
10489                   when Name_Modified_GPL =>
10490                      Set_License (Sind, Modified_GPL);
10491
10492                   when Name_Restricted =>
10493                      Set_License (Sind, Restricted);
10494
10495                   when Name_Unrestricted =>
10496                      Set_License (Sind, Unrestricted);
10497
10498                   when others =>
10499                      Error_Pragma_Arg ("invalid license name", Arg1);
10500                end case;
10501             end;
10502
10503          ---------------
10504          -- Link_With --
10505          ---------------
10506
10507          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10508
10509          when Pragma_Link_With => Link_With : declare
10510             Arg : Node_Id;
10511
10512          begin
10513             GNAT_Pragma;
10514
10515             if Operating_Mode = Generate_Code
10516               and then In_Extended_Main_Source_Unit (N)
10517             then
10518                Check_At_Least_N_Arguments (1);
10519                Check_No_Identifiers;
10520                Check_Is_In_Decl_Part_Or_Package_Spec;
10521                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10522                Start_String;
10523
10524                Arg := Arg1;
10525                while Present (Arg) loop
10526                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10527
10528                   --  Store argument, converting sequences of spaces to a
10529                   --  single null character (this is one of the differences
10530                   --  in processing between Link_With and Linker_Options).
10531
10532                   Arg_Store : declare
10533                      C : constant Char_Code := Get_Char_Code (' ');
10534                      S : constant String_Id :=
10535                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10536                      L : constant Nat := String_Length (S);
10537                      F : Nat := 1;
10538
10539                      procedure Skip_Spaces;
10540                      --  Advance F past any spaces
10541
10542                      -----------------
10543                      -- Skip_Spaces --
10544                      -----------------
10545
10546                      procedure Skip_Spaces is
10547                      begin
10548                         while F <= L and then Get_String_Char (S, F) = C loop
10549                            F := F + 1;
10550                         end loop;
10551                      end Skip_Spaces;
10552
10553                   --  Start of processing for Arg_Store
10554
10555                   begin
10556                      Skip_Spaces; -- skip leading spaces
10557
10558                      --  Loop through characters, changing any embedded
10559                      --  sequence of spaces to a single null character (this
10560                      --  is how Link_With/Linker_Options differ)
10561
10562                      while F <= L loop
10563                         if Get_String_Char (S, F) = C then
10564                            Skip_Spaces;
10565                            exit when F > L;
10566                            Store_String_Char (ASCII.NUL);
10567
10568                         else
10569                            Store_String_Char (Get_String_Char (S, F));
10570                            F := F + 1;
10571                         end if;
10572                      end loop;
10573                   end Arg_Store;
10574
10575                   Arg := Next (Arg);
10576
10577                   if Present (Arg) then
10578                      Store_String_Char (ASCII.NUL);
10579                   end if;
10580                end loop;
10581
10582                Store_Linker_Option_String (End_String);
10583             end if;
10584          end Link_With;
10585
10586          ------------------
10587          -- Linker_Alias --
10588          ------------------
10589
10590          --  pragma Linker_Alias (
10591          --      [Entity =>]  LOCAL_NAME
10592          --      [Target =>]  static_string_EXPRESSION);
10593
10594          when Pragma_Linker_Alias =>
10595             GNAT_Pragma;
10596             Check_Arg_Order ((Name_Entity, Name_Target));
10597             Check_Arg_Count (2);
10598             Check_Optional_Identifier (Arg1, Name_Entity);
10599             Check_Optional_Identifier (Arg2, Name_Target);
10600             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10601             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10602
10603             --  The only processing required is to link this item on to the
10604             --  list of rep items for the given entity. This is accomplished
10605             --  by the call to Rep_Item_Too_Late (when no error is detected
10606             --  and False is returned).
10607
10608             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10609                return;
10610             else
10611                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10612             end if;
10613
10614          ------------------------
10615          -- Linker_Constructor --
10616          ------------------------
10617
10618          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10619
10620          --  Code is shared with Linker_Destructor
10621
10622          -----------------------
10623          -- Linker_Destructor --
10624          -----------------------
10625
10626          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10627
10628          when Pragma_Linker_Constructor |
10629               Pragma_Linker_Destructor =>
10630          Linker_Constructor : declare
10631             Arg1_X : Node_Id;
10632             Proc   : Entity_Id;
10633
10634          begin
10635             GNAT_Pragma;
10636             Check_Arg_Count (1);
10637             Check_No_Identifiers;
10638             Check_Arg_Is_Local_Name (Arg1);
10639             Arg1_X := Get_Pragma_Arg (Arg1);
10640             Analyze (Arg1_X);
10641             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10642
10643             if not Is_Library_Level_Entity (Proc) then
10644                Error_Pragma_Arg
10645                 ("argument for pragma% must be library level entity", Arg1);
10646             end if;
10647
10648             --  The only processing required is to link this item on to the
10649             --  list of rep items for the given entity. This is accomplished
10650             --  by the call to Rep_Item_Too_Late (when no error is detected
10651             --  and False is returned).
10652
10653             if Rep_Item_Too_Late (Proc, N) then
10654                return;
10655             else
10656                Set_Has_Gigi_Rep_Item (Proc);
10657             end if;
10658          end Linker_Constructor;
10659
10660          --------------------
10661          -- Linker_Options --
10662          --------------------
10663
10664          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10665
10666          when Pragma_Linker_Options => Linker_Options : declare
10667             Arg : Node_Id;
10668
10669          begin
10670             Check_Ada_83_Warning;
10671             Check_No_Identifiers;
10672             Check_Arg_Count (1);
10673             Check_Is_In_Decl_Part_Or_Package_Spec;
10674             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10675             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10676
10677             Arg := Arg2;
10678             while Present (Arg) loop
10679                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10680                Store_String_Char (ASCII.NUL);
10681                Store_String_Chars
10682                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10683                Arg := Next (Arg);
10684             end loop;
10685
10686             if Operating_Mode = Generate_Code
10687               and then In_Extended_Main_Source_Unit (N)
10688             then
10689                Store_Linker_Option_String (End_String);
10690             end if;
10691          end Linker_Options;
10692
10693          --------------------
10694          -- Linker_Section --
10695          --------------------
10696
10697          --  pragma Linker_Section (
10698          --      [Entity  =>]  LOCAL_NAME
10699          --      [Section =>]  static_string_EXPRESSION);
10700
10701          when Pragma_Linker_Section =>
10702             GNAT_Pragma;
10703             Check_Arg_Order ((Name_Entity, Name_Section));
10704             Check_Arg_Count (2);
10705             Check_Optional_Identifier (Arg1, Name_Entity);
10706             Check_Optional_Identifier (Arg2, Name_Section);
10707             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10708             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10709
10710             --  This pragma applies only to objects
10711
10712             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10713                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10714             end if;
10715
10716             --  The only processing required is to link this item on to the
10717             --  list of rep items for the given entity. This is accomplished
10718             --  by the call to Rep_Item_Too_Late (when no error is detected
10719             --  and False is returned).
10720
10721             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10722                return;
10723             else
10724                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10725             end if;
10726
10727          ----------
10728          -- List --
10729          ----------
10730
10731          --  pragma List (On | Off)
10732
10733          --  There is nothing to do here, since we did all the processing for
10734          --  this pragma in Par.Prag (so that it works properly even in syntax
10735          --  only mode).
10736
10737          when Pragma_List =>
10738             null;
10739
10740          --------------------
10741          -- Locking_Policy --
10742          --------------------
10743
10744          --  pragma Locking_Policy (policy_IDENTIFIER);
10745
10746          when Pragma_Locking_Policy => declare
10747             LP : Character;
10748
10749          begin
10750             Check_Ada_83_Warning;
10751             Check_Arg_Count (1);
10752             Check_No_Identifiers;
10753             Check_Arg_Is_Locking_Policy (Arg1);
10754             Check_Valid_Configuration_Pragma;
10755             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10756             LP := Fold_Upper (Name_Buffer (1));
10757
10758             if Locking_Policy /= ' '
10759               and then Locking_Policy /= LP
10760             then
10761                Error_Msg_Sloc := Locking_Policy_Sloc;
10762                Error_Pragma ("locking policy incompatible with policy#");
10763
10764             --  Set new policy, but always preserve System_Location since we
10765             --  like the error message with the run time name.
10766
10767             else
10768                Locking_Policy := LP;
10769
10770                if Locking_Policy_Sloc /= System_Location then
10771                   Locking_Policy_Sloc := Loc;
10772                end if;
10773             end if;
10774          end;
10775
10776          ----------------
10777          -- Long_Float --
10778          ----------------
10779
10780          --  pragma Long_Float (D_Float | G_Float);
10781
10782          when Pragma_Long_Float =>
10783             GNAT_Pragma;
10784             Check_Valid_Configuration_Pragma;
10785             Check_Arg_Count (1);
10786             Check_No_Identifier (Arg1);
10787             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10788
10789             if not OpenVMS_On_Target then
10790                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10791             end if;
10792
10793             --  D_Float case
10794
10795             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10796                if Opt.Float_Format_Long = 'G' then
10797                   Error_Pragma ("G_Float previously specified");
10798                end if;
10799
10800                Opt.Float_Format_Long := 'D';
10801
10802             --  G_Float case (this is the default, does not need overriding)
10803
10804             else
10805                if Opt.Float_Format_Long = 'D' then
10806                   Error_Pragma ("D_Float previously specified");
10807                end if;
10808
10809                Opt.Float_Format_Long := 'G';
10810             end if;
10811
10812             Set_Standard_Fpt_Formats;
10813
10814          -----------------------
10815          -- Machine_Attribute --
10816          -----------------------
10817
10818          --  pragma Machine_Attribute (
10819          --       [Entity         =>] LOCAL_NAME,
10820          --       [Attribute_Name =>] static_string_EXPRESSION
10821          --    [, [Info           =>] static_EXPRESSION] );
10822
10823          when Pragma_Machine_Attribute => Machine_Attribute : declare
10824             Def_Id : Entity_Id;
10825
10826          begin
10827             GNAT_Pragma;
10828             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10829
10830             if Arg_Count = 3 then
10831                Check_Optional_Identifier (Arg3, Name_Info);
10832                Check_Arg_Is_Static_Expression (Arg3);
10833             else
10834                Check_Arg_Count (2);
10835             end if;
10836
10837             Check_Optional_Identifier (Arg1, Name_Entity);
10838             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10839             Check_Arg_Is_Local_Name (Arg1);
10840             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10841             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10842
10843             if Is_Access_Type (Def_Id) then
10844                Def_Id := Designated_Type (Def_Id);
10845             end if;
10846
10847             if Rep_Item_Too_Early (Def_Id, N) then
10848                return;
10849             end if;
10850
10851             Def_Id := Underlying_Type (Def_Id);
10852
10853             --  The only processing required is to link this item on to the
10854             --  list of rep items for the given entity. This is accomplished
10855             --  by the call to Rep_Item_Too_Late (when no error is detected
10856             --  and False is returned).
10857
10858             if Rep_Item_Too_Late (Def_Id, N) then
10859                return;
10860             else
10861                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10862             end if;
10863          end Machine_Attribute;
10864
10865          ----------
10866          -- Main --
10867          ----------
10868
10869          --  pragma Main
10870          --   (MAIN_OPTION [, MAIN_OPTION]);
10871
10872          --  MAIN_OPTION ::=
10873          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10874          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10875          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10876
10877          when Pragma_Main => Main : declare
10878             Args  : Args_List (1 .. 3);
10879             Names : constant Name_List (1 .. 3) := (
10880                       Name_Stack_Size,
10881                       Name_Task_Stack_Size_Default,
10882                       Name_Time_Slicing_Enabled);
10883
10884             Nod : Node_Id;
10885
10886          begin
10887             GNAT_Pragma;
10888             Gather_Associations (Names, Args);
10889
10890             for J in 1 .. 2 loop
10891                if Present (Args (J)) then
10892                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10893                end if;
10894             end loop;
10895
10896             if Present (Args (3)) then
10897                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10898             end if;
10899
10900             Nod := Next (N);
10901             while Present (Nod) loop
10902                if Nkind (Nod) = N_Pragma
10903                  and then Pragma_Name (Nod) = Name_Main
10904                then
10905                   Error_Msg_Name_1 := Pname;
10906                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10907                end if;
10908
10909                Next (Nod);
10910             end loop;
10911          end Main;
10912
10913          ------------------
10914          -- Main_Storage --
10915          ------------------
10916
10917          --  pragma Main_Storage
10918          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10919
10920          --  MAIN_STORAGE_OPTION ::=
10921          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10922          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10923
10924          when Pragma_Main_Storage => Main_Storage : declare
10925             Args  : Args_List (1 .. 2);
10926             Names : constant Name_List (1 .. 2) := (
10927                       Name_Working_Storage,
10928                       Name_Top_Guard);
10929
10930             Nod : Node_Id;
10931
10932          begin
10933             GNAT_Pragma;
10934             Gather_Associations (Names, Args);
10935
10936             for J in 1 .. 2 loop
10937                if Present (Args (J)) then
10938                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10939                end if;
10940             end loop;
10941
10942             Check_In_Main_Program;
10943
10944             Nod := Next (N);
10945             while Present (Nod) loop
10946                if Nkind (Nod) = N_Pragma
10947                  and then Pragma_Name (Nod) = Name_Main_Storage
10948                then
10949                   Error_Msg_Name_1 := Pname;
10950                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10951                end if;
10952
10953                Next (Nod);
10954             end loop;
10955          end Main_Storage;
10956
10957          -----------------
10958          -- Memory_Size --
10959          -----------------
10960
10961          --  pragma Memory_Size (NUMERIC_LITERAL)
10962
10963          when Pragma_Memory_Size =>
10964             GNAT_Pragma;
10965
10966             --  Memory size is simply ignored
10967
10968             Check_No_Identifiers;
10969             Check_Arg_Count (1);
10970             Check_Arg_Is_Integer_Literal (Arg1);
10971
10972          -------------
10973          -- No_Body --
10974          -------------
10975
10976          --  pragma No_Body;
10977
10978          --  The only correct use of this pragma is on its own in a file, in
10979          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10980          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10981          --  check for a file containing nothing but a No_Body pragma). If we
10982          --  attempt to process it during normal semantics processing, it means
10983          --  it was misplaced.
10984
10985          when Pragma_No_Body =>
10986             GNAT_Pragma;
10987             Pragma_Misplaced;
10988
10989          ---------------
10990          -- No_Return --
10991          ---------------
10992
10993          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10994
10995          when Pragma_No_Return => No_Return : declare
10996             Id    : Node_Id;
10997             E     : Entity_Id;
10998             Found : Boolean;
10999             Arg   : Node_Id;
11000
11001          begin
11002             Ada_2005_Pragma;
11003             Check_At_Least_N_Arguments (1);
11004
11005             --  Loop through arguments of pragma
11006
11007             Arg := Arg1;
11008             while Present (Arg) loop
11009                Check_Arg_Is_Local_Name (Arg);
11010                Id := Get_Pragma_Arg (Arg);
11011                Analyze (Id);
11012
11013                if not Is_Entity_Name (Id) then
11014                   Error_Pragma_Arg ("entity name required", Arg);
11015                end if;
11016
11017                if Etype (Id) = Any_Type then
11018                   raise Pragma_Exit;
11019                end if;
11020
11021                --  Loop to find matching procedures
11022
11023                E := Entity (Id);
11024                Found := False;
11025                while Present (E)
11026                  and then Scope (E) = Current_Scope
11027                loop
11028                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11029                      Set_No_Return (E);
11030
11031                      --  Set flag on any alias as well
11032
11033                      if Is_Overloadable (E) and then Present (Alias (E)) then
11034                         Set_No_Return (Alias (E));
11035                      end if;
11036
11037                      Found := True;
11038                   end if;
11039
11040                   exit when From_Aspect_Specification (N);
11041                   E := Homonym (E);
11042                end loop;
11043
11044                if not Found then
11045                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11046                end if;
11047
11048                Next (Arg);
11049             end loop;
11050          end No_Return;
11051
11052          -----------------
11053          -- No_Run_Time --
11054          -----------------
11055
11056          --  pragma No_Run_Time;
11057
11058          --  Note: this pragma is retained for backwards compatibility. See
11059          --  body of Rtsfind for full details on its handling.
11060
11061          when Pragma_No_Run_Time =>
11062             GNAT_Pragma;
11063             Check_Valid_Configuration_Pragma;
11064             Check_Arg_Count (0);
11065
11066             No_Run_Time_Mode           := True;
11067             Configurable_Run_Time_Mode := True;
11068
11069             --  Set Duration to 32 bits if word size is 32
11070
11071             if Ttypes.System_Word_Size = 32 then
11072                Duration_32_Bits_On_Target := True;
11073             end if;
11074
11075             --  Set appropriate restrictions
11076
11077             Set_Restriction (No_Finalization, N);
11078             Set_Restriction (No_Exception_Handlers, N);
11079             Set_Restriction (Max_Tasks, N, 0);
11080             Set_Restriction (No_Tasking, N);
11081
11082          ------------------------
11083          -- No_Strict_Aliasing --
11084          ------------------------
11085
11086          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11087
11088          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11089             E_Id : Entity_Id;
11090
11091          begin
11092             GNAT_Pragma;
11093             Check_At_Most_N_Arguments (1);
11094
11095             if Arg_Count = 0 then
11096                Check_Valid_Configuration_Pragma;
11097                Opt.No_Strict_Aliasing := True;
11098
11099             else
11100                Check_Optional_Identifier (Arg2, Name_Entity);
11101                Check_Arg_Is_Local_Name (Arg1);
11102                E_Id := Entity (Get_Pragma_Arg (Arg1));
11103
11104                if E_Id = Any_Type then
11105                   return;
11106                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11107                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
11108                end if;
11109
11110                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11111             end if;
11112          end No_Strict_Aliasing;
11113
11114          -----------------------
11115          -- Normalize_Scalars --
11116          -----------------------
11117
11118          --  pragma Normalize_Scalars;
11119
11120          when Pragma_Normalize_Scalars =>
11121             Check_Ada_83_Warning;
11122             Check_Arg_Count (0);
11123             Check_Valid_Configuration_Pragma;
11124
11125             --  Normalize_Scalars creates false positives in CodePeer, and
11126             --  incorrect negative results in Alfa mode, so ignore this pragma
11127             --  in these modes.
11128
11129             if not (CodePeer_Mode or Alfa_Mode) then
11130                Normalize_Scalars := True;
11131                Init_Or_Norm_Scalars := True;
11132             end if;
11133
11134          -----------------
11135          -- Obsolescent --
11136          -----------------
11137
11138          --  pragma Obsolescent;
11139
11140          --  pragma Obsolescent (
11141          --    [Message =>] static_string_EXPRESSION
11142          --  [,[Version =>] Ada_05]]);
11143
11144          --  pragma Obsolescent (
11145          --    [Entity  =>] NAME
11146          --  [,[Message =>] static_string_EXPRESSION
11147          --  [,[Version =>] Ada_05]] );
11148
11149          when Pragma_Obsolescent => Obsolescent : declare
11150             Ename : Node_Id;
11151             Decl  : Node_Id;
11152
11153             procedure Set_Obsolescent (E : Entity_Id);
11154             --  Given an entity Ent, mark it as obsolescent if appropriate
11155
11156             ---------------------
11157             -- Set_Obsolescent --
11158             ---------------------
11159
11160             procedure Set_Obsolescent (E : Entity_Id) is
11161                Active : Boolean;
11162                Ent    : Entity_Id;
11163                S      : String_Id;
11164
11165             begin
11166                Active := True;
11167                Ent    := E;
11168
11169                --  Entity name was given
11170
11171                if Present (Ename) then
11172
11173                   --  If entity name matches, we are fine. Save entity in
11174                   --  pragma argument, for ASIS use.
11175
11176                   if Chars (Ename) = Chars (Ent) then
11177                      Set_Entity (Ename, Ent);
11178                      Generate_Reference (Ent, Ename);
11179
11180                   --  If entity name does not match, only possibility is an
11181                   --  enumeration literal from an enumeration type declaration.
11182
11183                   elsif Ekind (Ent) /= E_Enumeration_Type then
11184                      Error_Pragma
11185                        ("pragma % entity name does not match declaration");
11186
11187                   else
11188                      Ent := First_Literal (E);
11189                      loop
11190                         if No (Ent) then
11191                            Error_Pragma
11192                              ("pragma % entity name does not match any " &
11193                               "enumeration literal");
11194
11195                         elsif Chars (Ent) = Chars (Ename) then
11196                            Set_Entity (Ename, Ent);
11197                            Generate_Reference (Ent, Ename);
11198                            exit;
11199
11200                         else
11201                            Ent := Next_Literal (Ent);
11202                         end if;
11203                      end loop;
11204                   end if;
11205                end if;
11206
11207                --  Ent points to entity to be marked
11208
11209                if Arg_Count >= 1 then
11210
11211                   --  Deal with static string argument
11212
11213                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11214                   S := Strval (Get_Pragma_Arg (Arg1));
11215
11216                   for J in 1 .. String_Length (S) loop
11217                      if not In_Character_Range (Get_String_Char (S, J)) then
11218                         Error_Pragma_Arg
11219                           ("pragma% argument does not allow wide characters",
11220                            Arg1);
11221                      end if;
11222                   end loop;
11223
11224                   Obsolescent_Warnings.Append
11225                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11226
11227                   --  Check for Ada_05 parameter
11228
11229                   if Arg_Count /= 1 then
11230                      Check_Arg_Count (2);
11231
11232                      declare
11233                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11234
11235                      begin
11236                         Check_Arg_Is_Identifier (Argx);
11237
11238                         if Chars (Argx) /= Name_Ada_05 then
11239                            Error_Msg_Name_2 := Name_Ada_05;
11240                            Error_Pragma_Arg
11241                              ("only allowed argument for pragma% is %", Argx);
11242                         end if;
11243
11244                         if Ada_Version_Explicit < Ada_2005
11245                           or else not Warn_On_Ada_2005_Compatibility
11246                         then
11247                            Active := False;
11248                         end if;
11249                      end;
11250                   end if;
11251                end if;
11252
11253                --  Set flag if pragma active
11254
11255                if Active then
11256                   Set_Is_Obsolescent (Ent);
11257                end if;
11258
11259                return;
11260             end Set_Obsolescent;
11261
11262          --  Start of processing for pragma Obsolescent
11263
11264          begin
11265             GNAT_Pragma;
11266
11267             Check_At_Most_N_Arguments (3);
11268
11269             --  See if first argument specifies an entity name
11270
11271             if Arg_Count >= 1
11272               and then
11273                 (Chars (Arg1) = Name_Entity
11274                    or else
11275                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11276                                                       N_Identifier,
11277                                                       N_Operator_Symbol))
11278             then
11279                Ename := Get_Pragma_Arg (Arg1);
11280
11281                --  Eliminate first argument, so we can share processing
11282
11283                Arg1 := Arg2;
11284                Arg2 := Arg3;
11285                Arg_Count := Arg_Count - 1;
11286
11287             --  No Entity name argument given
11288
11289             else
11290                Ename := Empty;
11291             end if;
11292
11293             if Arg_Count >= 1 then
11294                Check_Optional_Identifier (Arg1, Name_Message);
11295
11296                if Arg_Count = 2 then
11297                   Check_Optional_Identifier (Arg2, Name_Version);
11298                end if;
11299             end if;
11300
11301             --  Get immediately preceding declaration
11302
11303             Decl := Prev (N);
11304             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11305                Prev (Decl);
11306             end loop;
11307
11308             --  Cases where we do not follow anything other than another pragma
11309
11310             if No (Decl) then
11311
11312                --  First case: library level compilation unit declaration with
11313                --  the pragma immediately following the declaration.
11314
11315                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11316                   Set_Obsolescent
11317                     (Defining_Entity (Unit (Parent (Parent (N)))));
11318                   return;
11319
11320                --  Case 2: library unit placement for package
11321
11322                else
11323                   declare
11324                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11325                   begin
11326                      if Is_Package_Or_Generic_Package (Ent) then
11327                         Set_Obsolescent (Ent);
11328                         return;
11329                      end if;
11330                   end;
11331                end if;
11332
11333             --  Cases where we must follow a declaration
11334
11335             else
11336                if         Nkind (Decl) not in N_Declaration
11337                  and then Nkind (Decl) not in N_Later_Decl_Item
11338                  and then Nkind (Decl) not in N_Generic_Declaration
11339                  and then Nkind (Decl) not in N_Renaming_Declaration
11340                then
11341                   Error_Pragma
11342                     ("pragma% misplaced, "
11343                      & "must immediately follow a declaration");
11344
11345                else
11346                   Set_Obsolescent (Defining_Entity (Decl));
11347                   return;
11348                end if;
11349             end if;
11350          end Obsolescent;
11351
11352          --------------
11353          -- Optimize --
11354          --------------
11355
11356          --  pragma Optimize (Time | Space | Off);
11357
11358          --  The actual check for optimize is done in Gigi. Note that this
11359          --  pragma does not actually change the optimization setting, it
11360          --  simply checks that it is consistent with the pragma.
11361
11362          when Pragma_Optimize =>
11363             Check_No_Identifiers;
11364             Check_Arg_Count (1);
11365             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11366
11367          ------------------------
11368          -- Optimize_Alignment --
11369          ------------------------
11370
11371          --  pragma Optimize_Alignment (Time | Space | Off);
11372
11373          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11374             GNAT_Pragma;
11375             Check_No_Identifiers;
11376             Check_Arg_Count (1);
11377             Check_Valid_Configuration_Pragma;
11378
11379             declare
11380                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11381             begin
11382                case Nam is
11383                   when Name_Time =>
11384                      Opt.Optimize_Alignment := 'T';
11385                   when Name_Space =>
11386                      Opt.Optimize_Alignment := 'S';
11387                   when Name_Off =>
11388                      Opt.Optimize_Alignment := 'O';
11389                   when others =>
11390                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11391                end case;
11392             end;
11393
11394             --  Set indication that mode is set locally. If we are in fact in a
11395             --  configuration pragma file, this setting is harmless since the
11396             --  switch will get reset anyway at the start of each unit.
11397
11398             Optimize_Alignment_Local := True;
11399          end Optimize_Alignment;
11400
11401          -------------
11402          -- Ordered --
11403          -------------
11404
11405          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11406
11407          when Pragma_Ordered => Ordered : declare
11408             Assoc   : constant Node_Id := Arg1;
11409             Type_Id : Node_Id;
11410             Typ     : Entity_Id;
11411
11412          begin
11413             GNAT_Pragma;
11414             Check_No_Identifiers;
11415             Check_Arg_Count (1);
11416             Check_Arg_Is_Local_Name (Arg1);
11417
11418             Type_Id := Get_Pragma_Arg (Assoc);
11419             Find_Type (Type_Id);
11420             Typ := Entity (Type_Id);
11421
11422             if Typ = Any_Type then
11423                return;
11424             else
11425                Typ := Underlying_Type (Typ);
11426             end if;
11427
11428             if not Is_Enumeration_Type (Typ) then
11429                Error_Pragma ("pragma% must specify enumeration type");
11430             end if;
11431
11432             Check_First_Subtype (Arg1);
11433             Set_Has_Pragma_Ordered (Base_Type (Typ));
11434          end Ordered;
11435
11436          ----------
11437          -- Pack --
11438          ----------
11439
11440          --  pragma Pack (first_subtype_LOCAL_NAME);
11441
11442          when Pragma_Pack => Pack : declare
11443             Assoc   : constant Node_Id := Arg1;
11444             Type_Id : Node_Id;
11445             Typ     : Entity_Id;
11446             Ctyp    : Entity_Id;
11447             Ignore  : Boolean := False;
11448
11449          begin
11450             Check_No_Identifiers;
11451             Check_Arg_Count (1);
11452             Check_Arg_Is_Local_Name (Arg1);
11453
11454             Type_Id := Get_Pragma_Arg (Assoc);
11455             Find_Type (Type_Id);
11456             Typ := Entity (Type_Id);
11457
11458             if Typ = Any_Type
11459               or else Rep_Item_Too_Early (Typ, N)
11460             then
11461                return;
11462             else
11463                Typ := Underlying_Type (Typ);
11464             end if;
11465
11466             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11467                Error_Pragma ("pragma% must specify array or record type");
11468             end if;
11469
11470             Check_First_Subtype (Arg1);
11471             Check_Duplicate_Pragma (Typ);
11472
11473             --  Array type
11474
11475             if Is_Array_Type (Typ) then
11476                Ctyp := Component_Type (Typ);
11477
11478                --  Ignore pack that does nothing
11479
11480                if Known_Static_Esize (Ctyp)
11481                  and then Known_Static_RM_Size (Ctyp)
11482                  and then Esize (Ctyp) = RM_Size (Ctyp)
11483                  and then Addressable (Esize (Ctyp))
11484                then
11485                   Ignore := True;
11486                end if;
11487
11488                --  Process OK pragma Pack. Note that if there is a separate
11489                --  component clause present, the Pack will be cancelled. This
11490                --  processing is in Freeze.
11491
11492                if not Rep_Item_Too_Late (Typ, N) then
11493
11494                   --  In the context of static code analysis, we do not need
11495                   --  complex front-end expansions related to pragma Pack,
11496                   --  so disable handling of pragma Pack in these cases.
11497
11498                   if CodePeer_Mode or Alfa_Mode then
11499                      null;
11500
11501                   --  Don't attempt any packing for VM targets. We possibly
11502                   --  could deal with some cases of array bit-packing, but we
11503                   --  don't bother, since this is not a typical kind of
11504                   --  representation in the VM context anyway (and would not
11505                   --  for example work nicely with the debugger).
11506
11507                   elsif VM_Target /= No_VM then
11508                      if not GNAT_Mode then
11509                         Error_Pragma
11510                           ("?pragma% ignored in this configuration");
11511                      end if;
11512
11513                   --  Normal case where we do the pack action
11514
11515                   else
11516                      if not Ignore then
11517                         Set_Is_Packed            (Base_Type (Typ));
11518                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11519                      end if;
11520
11521                      Set_Has_Pragma_Pack (Base_Type (Typ));
11522                   end if;
11523                end if;
11524
11525             --  For record types, the pack is always effective
11526
11527             else pragma Assert (Is_Record_Type (Typ));
11528                if not Rep_Item_Too_Late (Typ, N) then
11529
11530                   --  Ignore pack request with warning in VM mode (skip warning
11531                   --  if we are compiling GNAT run time library).
11532
11533                   if VM_Target /= No_VM then
11534                      if not GNAT_Mode then
11535                         Error_Pragma
11536                           ("?pragma% ignored in this configuration");
11537                      end if;
11538
11539                   --  Normal case of pack request active
11540
11541                   else
11542                      Set_Is_Packed            (Base_Type (Typ));
11543                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11544                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11545                   end if;
11546                end if;
11547             end if;
11548          end Pack;
11549
11550          ----------
11551          -- Page --
11552          ----------
11553
11554          --  pragma Page;
11555
11556          --  There is nothing to do here, since we did all the processing for
11557          --  this pragma in Par.Prag (so that it works properly even in syntax
11558          --  only mode).
11559
11560          when Pragma_Page =>
11561             null;
11562
11563          -------------
11564          -- Passive --
11565          -------------
11566
11567          --  pragma Passive [(PASSIVE_FORM)];
11568
11569          --  PASSIVE_FORM ::= Semaphore | No
11570
11571          when Pragma_Passive =>
11572             GNAT_Pragma;
11573
11574             if Nkind (Parent (N)) /= N_Task_Definition then
11575                Error_Pragma ("pragma% must be within task definition");
11576             end if;
11577
11578             if Arg_Count /= 0 then
11579                Check_Arg_Count (1);
11580                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11581             end if;
11582
11583          ----------------------------------
11584          -- Preelaborable_Initialization --
11585          ----------------------------------
11586
11587          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11588
11589          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11590             Ent : Entity_Id;
11591
11592          begin
11593             Ada_2005_Pragma;
11594             Check_Arg_Count (1);
11595             Check_No_Identifiers;
11596             Check_Arg_Is_Identifier (Arg1);
11597             Check_Arg_Is_Local_Name (Arg1);
11598             Check_First_Subtype (Arg1);
11599             Ent := Entity (Get_Pragma_Arg (Arg1));
11600
11601             if not (Is_Private_Type (Ent)
11602                       or else
11603                     Is_Protected_Type (Ent)
11604                       or else
11605                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11606             then
11607                Error_Pragma_Arg
11608                  ("pragma % can only be applied to private, formal derived or "
11609                   & "protected type",
11610                   Arg1);
11611             end if;
11612
11613             --  Give an error if the pragma is applied to a protected type that
11614             --  does not qualify (due to having entries, or due to components
11615             --  that do not qualify).
11616
11617             if Is_Protected_Type (Ent)
11618               and then not Has_Preelaborable_Initialization (Ent)
11619             then
11620                Error_Msg_N
11621                  ("protected type & does not have preelaborable " &
11622                   "initialization", Ent);
11623
11624             --  Otherwise mark the type as definitely having preelaborable
11625             --  initialization.
11626
11627             else
11628                Set_Known_To_Have_Preelab_Init (Ent);
11629             end if;
11630
11631             if Has_Pragma_Preelab_Init (Ent)
11632               and then Warn_On_Redundant_Constructs
11633             then
11634                Error_Pragma ("?duplicate pragma%!");
11635             else
11636                Set_Has_Pragma_Preelab_Init (Ent);
11637             end if;
11638          end Preelab_Init;
11639
11640          --------------------
11641          -- Persistent_BSS --
11642          --------------------
11643
11644          --  pragma Persistent_BSS [(object_NAME)];
11645
11646          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11647             Decl : Node_Id;
11648             Ent  : Entity_Id;
11649             Prag : Node_Id;
11650
11651          begin
11652             GNAT_Pragma;
11653             Check_At_Most_N_Arguments (1);
11654
11655             --  Case of application to specific object (one argument)
11656
11657             if Arg_Count = 1 then
11658                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11659
11660                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11661                  or else not
11662                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11663                                                             E_Constant)
11664                then
11665                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11666                end if;
11667
11668                Ent := Entity (Get_Pragma_Arg (Arg1));
11669                Decl := Parent (Ent);
11670
11671                if Rep_Item_Too_Late (Ent, N) then
11672                   return;
11673                end if;
11674
11675                if Present (Expression (Decl)) then
11676                   Error_Pragma_Arg
11677                     ("object for pragma% cannot have initialization", Arg1);
11678                end if;
11679
11680                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11681                   Error_Pragma_Arg
11682                     ("object type for pragma% is not potentially persistent",
11683                      Arg1);
11684                end if;
11685
11686                Check_Duplicate_Pragma (Ent);
11687
11688                Prag :=
11689                  Make_Linker_Section_Pragma
11690                    (Ent, Sloc (N), ".persistent.bss");
11691                Insert_After (N, Prag);
11692                Analyze (Prag);
11693
11694             --  Case of use as configuration pragma with no arguments
11695
11696             else
11697                Check_Valid_Configuration_Pragma;
11698                Persistent_BSS_Mode := True;
11699             end if;
11700          end Persistent_BSS;
11701
11702          -------------
11703          -- Polling --
11704          -------------
11705
11706          --  pragma Polling (ON | OFF);
11707
11708          when Pragma_Polling =>
11709             GNAT_Pragma;
11710             Check_Arg_Count (1);
11711             Check_No_Identifiers;
11712             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11713             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11714
11715          -------------------
11716          -- Postcondition --
11717          -------------------
11718
11719          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11720          --                      [,[Message =>] String_EXPRESSION]);
11721
11722          when Pragma_Postcondition => Postcondition : declare
11723             In_Body : Boolean;
11724             pragma Warnings (Off, In_Body);
11725
11726          begin
11727             GNAT_Pragma;
11728             Check_At_Least_N_Arguments (1);
11729             Check_At_Most_N_Arguments (2);
11730             Check_Optional_Identifier (Arg1, Name_Check);
11731
11732             --  All we need to do here is call the common check procedure,
11733             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11734
11735             Check_Precondition_Postcondition (In_Body);
11736          end Postcondition;
11737
11738          ------------------
11739          -- Precondition --
11740          ------------------
11741
11742          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11743          --                     [,[Message =>] String_EXPRESSION]);
11744
11745          when Pragma_Precondition => Precondition : declare
11746             In_Body : Boolean;
11747
11748          begin
11749             GNAT_Pragma;
11750             Check_At_Least_N_Arguments (1);
11751             Check_At_Most_N_Arguments (2);
11752             Check_Optional_Identifier (Arg1, Name_Check);
11753             Check_Precondition_Postcondition (In_Body);
11754
11755             --  If in spec, nothing more to do. If in body, then we convert the
11756             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11757             --  this whether or not precondition checks are enabled. That works
11758             --  fine since pragma Check will do this check, and will also
11759             --  analyze the condition itself in the proper context.
11760
11761             if In_Body then
11762                Rewrite (N,
11763                  Make_Pragma (Loc,
11764                    Chars => Name_Check,
11765                    Pragma_Argument_Associations => New_List (
11766                      Make_Pragma_Argument_Association (Loc,
11767                        Expression => Make_Identifier (Loc, Name_Precondition)),
11768
11769                      Make_Pragma_Argument_Association (Sloc (Arg1),
11770                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11771
11772                if Arg_Count = 2 then
11773                   Append_To (Pragma_Argument_Associations (N),
11774                     Make_Pragma_Argument_Association (Sloc (Arg2),
11775                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11776                end if;
11777
11778                Analyze (N);
11779             end if;
11780          end Precondition;
11781
11782          ---------------
11783          -- Predicate --
11784          ---------------
11785
11786          --  pragma Predicate
11787          --    ([Entity =>] type_LOCAL_NAME,
11788          --     [Check  =>] EXPRESSION);
11789
11790          when Pragma_Predicate => Predicate : declare
11791             Type_Id : Node_Id;
11792             Typ     : Entity_Id;
11793
11794             Discard : Boolean;
11795             pragma Unreferenced (Discard);
11796
11797          begin
11798             GNAT_Pragma;
11799             Check_Arg_Count (2);
11800             Check_Optional_Identifier (Arg1, Name_Entity);
11801             Check_Optional_Identifier (Arg2, Name_Check);
11802
11803             Check_Arg_Is_Local_Name (Arg1);
11804
11805             Type_Id := Get_Pragma_Arg (Arg1);
11806             Find_Type (Type_Id);
11807             Typ := Entity (Type_Id);
11808
11809             if Typ = Any_Type then
11810                return;
11811             end if;
11812
11813             --  The remaining processing is simply to link the pragma on to
11814             --  the rep item chain, for processing when the type is frozen.
11815             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11816             --  mark the type as having predicates.
11817
11818             Set_Has_Predicates (Typ);
11819             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11820          end Predicate;
11821
11822          ------------------
11823          -- Preelaborate --
11824          ------------------
11825
11826          --  pragma Preelaborate [(library_unit_NAME)];
11827
11828          --  Set the flag Is_Preelaborated of program unit name entity
11829
11830          when Pragma_Preelaborate => Preelaborate : declare
11831             Pa  : constant Node_Id   := Parent (N);
11832             Pk  : constant Node_Kind := Nkind (Pa);
11833             Ent : Entity_Id;
11834
11835          begin
11836             Check_Ada_83_Warning;
11837             Check_Valid_Library_Unit_Pragma;
11838
11839             if Nkind (N) = N_Null_Statement then
11840                return;
11841             end if;
11842
11843             Ent := Find_Lib_Unit_Name;
11844             Check_Duplicate_Pragma (Ent);
11845
11846             --  This filters out pragmas inside generic parent then
11847             --  show up inside instantiation
11848
11849             if Present (Ent)
11850               and then not (Pk = N_Package_Specification
11851                              and then Present (Generic_Parent (Pa)))
11852             then
11853                if not Debug_Flag_U then
11854                   Set_Is_Preelaborated (Ent);
11855                   Set_Suppress_Elaboration_Warnings (Ent);
11856                end if;
11857             end if;
11858          end Preelaborate;
11859
11860          ---------------------
11861          -- Preelaborate_05 --
11862          ---------------------
11863
11864          --  pragma Preelaborate_05 [(library_unit_NAME)];
11865
11866          --  This pragma is useable only in GNAT_Mode, where it is used like
11867          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11868          --  (otherwise it is ignored). This is used to implement AI-362 which
11869          --  recategorizes some run-time packages in Ada 2005 mode.
11870
11871          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11872             Ent : Entity_Id;
11873
11874          begin
11875             GNAT_Pragma;
11876             Check_Valid_Library_Unit_Pragma;
11877
11878             if not GNAT_Mode then
11879                Error_Pragma ("pragma% only available in GNAT mode");
11880             end if;
11881
11882             if Nkind (N) = N_Null_Statement then
11883                return;
11884             end if;
11885
11886             --  This is one of the few cases where we need to test the value of
11887             --  Ada_Version_Explicit rather than Ada_Version (which is always
11888             --  set to Ada_2012 in a predefined unit), we need to know the
11889             --  explicit version set to know if this pragma is active.
11890
11891             if Ada_Version_Explicit >= Ada_2005 then
11892                Ent := Find_Lib_Unit_Name;
11893                Set_Is_Preelaborated (Ent);
11894                Set_Suppress_Elaboration_Warnings (Ent);
11895             end if;
11896          end Preelaborate_05;
11897
11898          --------------
11899          -- Priority --
11900          --------------
11901
11902          --  pragma Priority (EXPRESSION);
11903
11904          when Pragma_Priority => Priority : declare
11905             P   : constant Node_Id := Parent (N);
11906             Arg : Node_Id;
11907
11908          begin
11909             Check_No_Identifiers;
11910             Check_Arg_Count (1);
11911
11912             --  Subprogram case
11913
11914             if Nkind (P) = N_Subprogram_Body then
11915                Check_In_Main_Program;
11916
11917                Arg := Get_Pragma_Arg (Arg1);
11918                Analyze_And_Resolve (Arg, Standard_Integer);
11919
11920                --  Must be static
11921
11922                if not Is_Static_Expression (Arg) then
11923                   Flag_Non_Static_Expr
11924                     ("main subprogram priority is not static!", Arg);
11925                   raise Pragma_Exit;
11926
11927                --  If constraint error, then we already signalled an error
11928
11929                elsif Raises_Constraint_Error (Arg) then
11930                   null;
11931
11932                --  Otherwise check in range
11933
11934                else
11935                   declare
11936                      Val : constant Uint := Expr_Value (Arg);
11937
11938                   begin
11939                      if Val < 0
11940                        or else Val > Expr_Value (Expression
11941                                        (Parent (RTE (RE_Max_Priority))))
11942                      then
11943                         Error_Pragma_Arg
11944                           ("main subprogram priority is out of range", Arg1);
11945                      end if;
11946                   end;
11947                end if;
11948
11949                Set_Main_Priority
11950                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11951
11952                --  Load an arbitrary entity from System.Tasking to make sure
11953                --  this package is implicitly with'ed, since we need to have
11954                --  the tasking run-time active for the pragma Priority to have
11955                --  any effect.
11956
11957                declare
11958                   Discard : Entity_Id;
11959                   pragma Warnings (Off, Discard);
11960                begin
11961                   Discard := RTE (RE_Task_List);
11962                end;
11963
11964             --  Task or Protected, must be of type Integer
11965
11966             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11967                Arg := Get_Pragma_Arg (Arg1);
11968
11969                --  The expression must be analyzed in the special manner
11970                --  described in "Handling of Default and Per-Object
11971                --  Expressions" in sem.ads.
11972
11973                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11974
11975                if not Is_Static_Expression (Arg) then
11976                   Check_Restriction (Static_Priorities, Arg);
11977                end if;
11978
11979             --  Anything else is incorrect
11980
11981             else
11982                Pragma_Misplaced;
11983             end if;
11984
11985             if Has_Pragma_Priority (P) then
11986                Error_Pragma ("duplicate pragma% not allowed");
11987             else
11988                Set_Has_Pragma_Priority (P, True);
11989
11990                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11991                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11992                   --  exp_ch9 should use this ???
11993                end if;
11994             end if;
11995          end Priority;
11996
11997          -----------------------------------
11998          -- Priority_Specific_Dispatching --
11999          -----------------------------------
12000
12001          --  pragma Priority_Specific_Dispatching (
12002          --    policy_IDENTIFIER,
12003          --    first_priority_EXPRESSION,
12004          --    last_priority_EXPRESSION);
12005
12006          when Pragma_Priority_Specific_Dispatching =>
12007          Priority_Specific_Dispatching : declare
12008             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12009             --  This is the entity System.Any_Priority;
12010
12011             DP          : Character;
12012             Lower_Bound : Node_Id;
12013             Upper_Bound : Node_Id;
12014             Lower_Val   : Uint;
12015             Upper_Val   : Uint;
12016
12017          begin
12018             Ada_2005_Pragma;
12019             Check_Arg_Count (3);
12020             Check_No_Identifiers;
12021             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12022             Check_Valid_Configuration_Pragma;
12023             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12024             DP := Fold_Upper (Name_Buffer (1));
12025
12026             Lower_Bound := Get_Pragma_Arg (Arg2);
12027             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12028             Lower_Val := Expr_Value (Lower_Bound);
12029
12030             Upper_Bound := Get_Pragma_Arg (Arg3);
12031             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12032             Upper_Val := Expr_Value (Upper_Bound);
12033
12034             --  It is not allowed to use Task_Dispatching_Policy and
12035             --  Priority_Specific_Dispatching in the same partition.
12036
12037             if Task_Dispatching_Policy /= ' ' then
12038                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12039                Error_Pragma
12040                  ("pragma% incompatible with Task_Dispatching_Policy#");
12041
12042             --  Check lower bound in range
12043
12044             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12045                     or else
12046                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12047             then
12048                Error_Pragma_Arg
12049                  ("first_priority is out of range", Arg2);
12050
12051             --  Check upper bound in range
12052
12053             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12054                     or else
12055                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12056             then
12057                Error_Pragma_Arg
12058                  ("last_priority is out of range", Arg3);
12059
12060             --  Check that the priority range is valid
12061
12062             elsif Lower_Val > Upper_Val then
12063                Error_Pragma
12064                  ("last_priority_expression must be greater than" &
12065                   " or equal to first_priority_expression");
12066
12067             --  Store the new policy, but always preserve System_Location since
12068             --  we like the error message with the run-time name.
12069
12070             else
12071                --  Check overlapping in the priority ranges specified in other
12072                --  Priority_Specific_Dispatching pragmas within the same
12073                --  partition. We can only check those we know about!
12074
12075                for J in
12076                   Specific_Dispatching.First .. Specific_Dispatching.Last
12077                loop
12078                   if Specific_Dispatching.Table (J).First_Priority in
12079                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12080                   or else Specific_Dispatching.Table (J).Last_Priority in
12081                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12082                   then
12083                      Error_Msg_Sloc :=
12084                        Specific_Dispatching.Table (J).Pragma_Loc;
12085                         Error_Pragma
12086                           ("priority range overlaps with "
12087                            & "Priority_Specific_Dispatching#");
12088                   end if;
12089                end loop;
12090
12091                --  The use of Priority_Specific_Dispatching is incompatible
12092                --  with Task_Dispatching_Policy.
12093
12094                if Task_Dispatching_Policy /= ' ' then
12095                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12096                      Error_Pragma
12097                        ("Priority_Specific_Dispatching incompatible "
12098                         & "with Task_Dispatching_Policy#");
12099                end if;
12100
12101                --  The use of Priority_Specific_Dispatching forces ceiling
12102                --  locking policy.
12103
12104                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12105                   Error_Msg_Sloc := Locking_Policy_Sloc;
12106                      Error_Pragma
12107                        ("Priority_Specific_Dispatching incompatible "
12108                         & "with Locking_Policy#");
12109
12110                --  Set the Ceiling_Locking policy, but preserve System_Location
12111                --  since we like the error message with the run time name.
12112
12113                else
12114                   Locking_Policy := 'C';
12115
12116                   if Locking_Policy_Sloc /= System_Location then
12117                      Locking_Policy_Sloc := Loc;
12118                   end if;
12119                end if;
12120
12121                --  Add entry in the table
12122
12123                Specific_Dispatching.Append
12124                     ((Dispatching_Policy => DP,
12125                       First_Priority     => UI_To_Int (Lower_Val),
12126                       Last_Priority      => UI_To_Int (Upper_Val),
12127                       Pragma_Loc         => Loc));
12128             end if;
12129          end Priority_Specific_Dispatching;
12130
12131          -------------
12132          -- Profile --
12133          -------------
12134
12135          --  pragma Profile (profile_IDENTIFIER);
12136
12137          --  profile_IDENTIFIER => Restricted | Ravenscar
12138
12139          when Pragma_Profile =>
12140             Ada_2005_Pragma;
12141             Check_Arg_Count (1);
12142             Check_Valid_Configuration_Pragma;
12143             Check_No_Identifiers;
12144
12145             declare
12146                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12147             begin
12148                if Chars (Argx) = Name_Ravenscar then
12149                   Set_Ravenscar_Profile (N);
12150                elsif Chars (Argx) = Name_Restricted then
12151                   Set_Profile_Restrictions
12152                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12153                else
12154                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12155                end if;
12156             end;
12157
12158          ----------------------
12159          -- Profile_Warnings --
12160          ----------------------
12161
12162          --  pragma Profile_Warnings (profile_IDENTIFIER);
12163
12164          --  profile_IDENTIFIER => Restricted | Ravenscar
12165
12166          when Pragma_Profile_Warnings =>
12167             GNAT_Pragma;
12168             Check_Arg_Count (1);
12169             Check_Valid_Configuration_Pragma;
12170             Check_No_Identifiers;
12171
12172             declare
12173                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12174             begin
12175                if Chars (Argx) = Name_Ravenscar then
12176                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12177                elsif Chars (Argx) = Name_Restricted then
12178                   Set_Profile_Restrictions (Restricted, N, Warn => True);
12179                else
12180                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12181                end if;
12182             end;
12183
12184          --------------------------
12185          -- Propagate_Exceptions --
12186          --------------------------
12187
12188          --  pragma Propagate_Exceptions;
12189
12190          --  Note: this pragma is obsolete and has no effect
12191
12192          when Pragma_Propagate_Exceptions =>
12193             GNAT_Pragma;
12194             Check_Arg_Count (0);
12195
12196             if In_Extended_Main_Source_Unit (N) then
12197                Propagate_Exceptions := True;
12198             end if;
12199
12200          ------------------
12201          -- Psect_Object --
12202          ------------------
12203
12204          --  pragma Psect_Object (
12205          --        [Internal =>] LOCAL_NAME,
12206          --     [, [External =>] EXTERNAL_SYMBOL]
12207          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12208
12209          when Pragma_Psect_Object | Pragma_Common_Object =>
12210          Psect_Object : declare
12211             Args  : Args_List (1 .. 3);
12212             Names : constant Name_List (1 .. 3) := (
12213                       Name_Internal,
12214                       Name_External,
12215                       Name_Size);
12216
12217             Internal : Node_Id renames Args (1);
12218             External : Node_Id renames Args (2);
12219             Size     : Node_Id renames Args (3);
12220
12221             Def_Id : Entity_Id;
12222
12223             procedure Check_Too_Long (Arg : Node_Id);
12224             --  Posts message if the argument is an identifier with more
12225             --  than 31 characters, or a string literal with more than
12226             --  31 characters, and we are operating under VMS
12227
12228             --------------------
12229             -- Check_Too_Long --
12230             --------------------
12231
12232             procedure Check_Too_Long (Arg : Node_Id) is
12233                X : constant Node_Id := Original_Node (Arg);
12234
12235             begin
12236                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12237                   Error_Pragma_Arg
12238                     ("inappropriate argument for pragma %", Arg);
12239                end if;
12240
12241                if OpenVMS_On_Target then
12242                   if (Nkind (X) = N_String_Literal
12243                        and then String_Length (Strval (X)) > 31)
12244                     or else
12245                      (Nkind (X) = N_Identifier
12246                        and then Length_Of_Name (Chars (X)) > 31)
12247                   then
12248                      Error_Pragma_Arg
12249                        ("argument for pragma % is longer than 31 characters",
12250                         Arg);
12251                   end if;
12252                end if;
12253             end Check_Too_Long;
12254
12255          --  Start of processing for Common_Object/Psect_Object
12256
12257          begin
12258             GNAT_Pragma;
12259             Gather_Associations (Names, Args);
12260             Process_Extended_Import_Export_Internal_Arg (Internal);
12261
12262             Def_Id := Entity (Internal);
12263
12264             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12265                Error_Pragma_Arg
12266                  ("pragma% must designate an object", Internal);
12267             end if;
12268
12269             Check_Too_Long (Internal);
12270
12271             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12272                Error_Pragma_Arg
12273                  ("cannot use pragma% for imported/exported object",
12274                   Internal);
12275             end if;
12276
12277             if Is_Concurrent_Type (Etype (Internal)) then
12278                Error_Pragma_Arg
12279                  ("cannot specify pragma % for task/protected object",
12280                   Internal);
12281             end if;
12282
12283             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12284                  or else
12285                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12286             then
12287                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12288             end if;
12289
12290             if Ekind (Def_Id) = E_Constant then
12291                Error_Pragma_Arg
12292                  ("cannot specify pragma % for a constant", Internal);
12293             end if;
12294
12295             if Is_Record_Type (Etype (Internal)) then
12296                declare
12297                   Ent  : Entity_Id;
12298                   Decl : Entity_Id;
12299
12300                begin
12301                   Ent := First_Entity (Etype (Internal));
12302                   while Present (Ent) loop
12303                      Decl := Declaration_Node (Ent);
12304
12305                      if Ekind (Ent) = E_Component
12306                        and then Nkind (Decl) = N_Component_Declaration
12307                        and then Present (Expression (Decl))
12308                        and then Warn_On_Export_Import
12309                      then
12310                         Error_Msg_N
12311                           ("?object for pragma % has defaults", Internal);
12312                         exit;
12313
12314                      else
12315                         Next_Entity (Ent);
12316                      end if;
12317                   end loop;
12318                end;
12319             end if;
12320
12321             if Present (Size) then
12322                Check_Too_Long (Size);
12323             end if;
12324
12325             if Present (External) then
12326                Check_Arg_Is_External_Name (External);
12327                Check_Too_Long (External);
12328             end if;
12329
12330             --  If all error tests pass, link pragma on to the rep item chain
12331
12332             Record_Rep_Item (Def_Id, N);
12333          end Psect_Object;
12334
12335          ----------
12336          -- Pure --
12337          ----------
12338
12339          --  pragma Pure [(library_unit_NAME)];
12340
12341          when Pragma_Pure => Pure : declare
12342             Ent : Entity_Id;
12343
12344          begin
12345             Check_Ada_83_Warning;
12346             Check_Valid_Library_Unit_Pragma;
12347
12348             if Nkind (N) = N_Null_Statement then
12349                return;
12350             end if;
12351
12352             Ent := Find_Lib_Unit_Name;
12353             Set_Is_Pure (Ent);
12354             Set_Has_Pragma_Pure (Ent);
12355             Set_Suppress_Elaboration_Warnings (Ent);
12356          end Pure;
12357
12358          -------------
12359          -- Pure_05 --
12360          -------------
12361
12362          --  pragma Pure_05 [(library_unit_NAME)];
12363
12364          --  This pragma is useable only in GNAT_Mode, where it is used like
12365          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12366          --  it is ignored). It may be used after a pragma Preelaborate, in
12367          --  which case it overrides the effect of the pragma Preelaborate.
12368          --  This is used to implement AI-362 which recategorizes some run-time
12369          --  packages in Ada 2005 mode.
12370
12371          when Pragma_Pure_05 => Pure_05 : declare
12372             Ent : Entity_Id;
12373
12374          begin
12375             GNAT_Pragma;
12376             Check_Valid_Library_Unit_Pragma;
12377
12378             if not GNAT_Mode then
12379                Error_Pragma ("pragma% only available in GNAT mode");
12380             end if;
12381
12382             if Nkind (N) = N_Null_Statement then
12383                return;
12384             end if;
12385
12386             --  This is one of the few cases where we need to test the value of
12387             --  Ada_Version_Explicit rather than Ada_Version (which is always
12388             --  set to Ada_2012 in a predefined unit), we need to know the
12389             --  explicit version set to know if this pragma is active.
12390
12391             if Ada_Version_Explicit >= Ada_2005 then
12392                Ent := Find_Lib_Unit_Name;
12393                Set_Is_Preelaborated (Ent, False);
12394                Set_Is_Pure (Ent);
12395                Set_Suppress_Elaboration_Warnings (Ent);
12396             end if;
12397          end Pure_05;
12398
12399          -------------------
12400          -- Pure_Function --
12401          -------------------
12402
12403          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12404
12405          when Pragma_Pure_Function => Pure_Function : declare
12406             E_Id      : Node_Id;
12407             E         : Entity_Id;
12408             Def_Id    : Entity_Id;
12409             Effective : Boolean := False;
12410
12411          begin
12412             GNAT_Pragma;
12413             Check_Arg_Count (1);
12414             Check_Optional_Identifier (Arg1, Name_Entity);
12415             Check_Arg_Is_Local_Name (Arg1);
12416             E_Id := Get_Pragma_Arg (Arg1);
12417
12418             if Error_Posted (E_Id) then
12419                return;
12420             end if;
12421
12422             --  Loop through homonyms (overloadings) of referenced entity
12423
12424             E := Entity (E_Id);
12425
12426             if Present (E) then
12427                loop
12428                   Def_Id := Get_Base_Subprogram (E);
12429
12430                   if not Ekind_In (Def_Id, E_Function,
12431                                            E_Generic_Function,
12432                                            E_Operator)
12433                   then
12434                      Error_Pragma_Arg
12435                        ("pragma% requires a function name", Arg1);
12436                   end if;
12437
12438                   Set_Is_Pure (Def_Id);
12439
12440                   if not Has_Pragma_Pure_Function (Def_Id) then
12441                      Set_Has_Pragma_Pure_Function (Def_Id);
12442                      Effective := True;
12443                   end if;
12444
12445                   exit when From_Aspect_Specification (N);
12446                   E := Homonym (E);
12447                   exit when No (E) or else Scope (E) /= Current_Scope;
12448                end loop;
12449
12450                if not Effective
12451                  and then Warn_On_Redundant_Constructs
12452                then
12453                   Error_Msg_NE
12454                     ("pragma Pure_Function on& is redundant?",
12455                      N, Entity (E_Id));
12456                end if;
12457             end if;
12458          end Pure_Function;
12459
12460          --------------------
12461          -- Queuing_Policy --
12462          --------------------
12463
12464          --  pragma Queuing_Policy (policy_IDENTIFIER);
12465
12466          when Pragma_Queuing_Policy => declare
12467             QP : Character;
12468
12469          begin
12470             Check_Ada_83_Warning;
12471             Check_Arg_Count (1);
12472             Check_No_Identifiers;
12473             Check_Arg_Is_Queuing_Policy (Arg1);
12474             Check_Valid_Configuration_Pragma;
12475             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12476             QP := Fold_Upper (Name_Buffer (1));
12477
12478             if Queuing_Policy /= ' '
12479               and then Queuing_Policy /= QP
12480             then
12481                Error_Msg_Sloc := Queuing_Policy_Sloc;
12482                Error_Pragma ("queuing policy incompatible with policy#");
12483
12484             --  Set new policy, but always preserve System_Location since we
12485             --  like the error message with the run time name.
12486
12487             else
12488                Queuing_Policy := QP;
12489
12490                if Queuing_Policy_Sloc /= System_Location then
12491                   Queuing_Policy_Sloc := Loc;
12492                end if;
12493             end if;
12494          end;
12495
12496          -----------------------
12497          -- Relative_Deadline --
12498          -----------------------
12499
12500          --  pragma Relative_Deadline (time_span_EXPRESSION);
12501
12502          when Pragma_Relative_Deadline => Relative_Deadline : declare
12503             P   : constant Node_Id := Parent (N);
12504             Arg : Node_Id;
12505
12506          begin
12507             Ada_2005_Pragma;
12508             Check_No_Identifiers;
12509             Check_Arg_Count (1);
12510
12511             Arg := Get_Pragma_Arg (Arg1);
12512
12513             --  The expression must be analyzed in the special manner described
12514             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12515
12516             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12517
12518             --  Subprogram case
12519
12520             if Nkind (P) = N_Subprogram_Body then
12521                Check_In_Main_Program;
12522
12523             --  Tasks
12524
12525             elsif Nkind (P) = N_Task_Definition then
12526                null;
12527
12528             --  Anything else is incorrect
12529
12530             else
12531                Pragma_Misplaced;
12532             end if;
12533
12534             if Has_Relative_Deadline_Pragma (P) then
12535                Error_Pragma ("duplicate pragma% not allowed");
12536             else
12537                Set_Has_Relative_Deadline_Pragma (P, True);
12538
12539                if Nkind (P) = N_Task_Definition then
12540                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12541                end if;
12542             end if;
12543          end Relative_Deadline;
12544
12545          ---------------------------
12546          -- Remote_Call_Interface --
12547          ---------------------------
12548
12549          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12550
12551          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12552             Cunit_Node : Node_Id;
12553             Cunit_Ent  : Entity_Id;
12554             K          : Node_Kind;
12555
12556          begin
12557             Check_Ada_83_Warning;
12558             Check_Valid_Library_Unit_Pragma;
12559
12560             if Nkind (N) = N_Null_Statement then
12561                return;
12562             end if;
12563
12564             Cunit_Node := Cunit (Current_Sem_Unit);
12565             K          := Nkind (Unit (Cunit_Node));
12566             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12567
12568             if K = N_Package_Declaration
12569               or else K = N_Generic_Package_Declaration
12570               or else K = N_Subprogram_Declaration
12571               or else K = N_Generic_Subprogram_Declaration
12572               or else (K = N_Subprogram_Body
12573                          and then Acts_As_Spec (Unit (Cunit_Node)))
12574             then
12575                null;
12576             else
12577                Error_Pragma (
12578                  "pragma% must apply to package or subprogram declaration");
12579             end if;
12580
12581             Set_Is_Remote_Call_Interface (Cunit_Ent);
12582          end Remote_Call_Interface;
12583
12584          ------------------
12585          -- Remote_Types --
12586          ------------------
12587
12588          --  pragma Remote_Types [(library_unit_NAME)];
12589
12590          when Pragma_Remote_Types => Remote_Types : declare
12591             Cunit_Node : Node_Id;
12592             Cunit_Ent  : Entity_Id;
12593
12594          begin
12595             Check_Ada_83_Warning;
12596             Check_Valid_Library_Unit_Pragma;
12597
12598             if Nkind (N) = N_Null_Statement then
12599                return;
12600             end if;
12601
12602             Cunit_Node := Cunit (Current_Sem_Unit);
12603             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12604
12605             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12606                                                 N_Generic_Package_Declaration)
12607             then
12608                Error_Pragma
12609                  ("pragma% can only apply to a package declaration");
12610             end if;
12611
12612             Set_Is_Remote_Types (Cunit_Ent);
12613          end Remote_Types;
12614
12615          ---------------
12616          -- Ravenscar --
12617          ---------------
12618
12619          --  pragma Ravenscar;
12620
12621          when Pragma_Ravenscar =>
12622             GNAT_Pragma;
12623             Check_Arg_Count (0);
12624             Check_Valid_Configuration_Pragma;
12625             Set_Ravenscar_Profile (N);
12626
12627             if Warn_On_Obsolescent_Feature then
12628                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12629                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12630             end if;
12631
12632          -------------------------
12633          -- Restricted_Run_Time --
12634          -------------------------
12635
12636          --  pragma Restricted_Run_Time;
12637
12638          when Pragma_Restricted_Run_Time =>
12639             GNAT_Pragma;
12640             Check_Arg_Count (0);
12641             Check_Valid_Configuration_Pragma;
12642             Set_Profile_Restrictions
12643               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12644
12645             if Warn_On_Obsolescent_Feature then
12646                Error_Msg_N
12647                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12648                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12649             end if;
12650
12651          ------------------
12652          -- Restrictions --
12653          ------------------
12654
12655          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12656
12657          --  RESTRICTION ::=
12658          --    restriction_IDENTIFIER
12659          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12660
12661          when Pragma_Restrictions =>
12662             Process_Restrictions_Or_Restriction_Warnings
12663               (Warn => Treat_Restrictions_As_Warnings);
12664
12665          --------------------------
12666          -- Restriction_Warnings --
12667          --------------------------
12668
12669          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12670
12671          --  RESTRICTION ::=
12672          --    restriction_IDENTIFIER
12673          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12674
12675          when Pragma_Restriction_Warnings =>
12676             GNAT_Pragma;
12677             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12678
12679          ----------------
12680          -- Reviewable --
12681          ----------------
12682
12683          --  pragma Reviewable;
12684
12685          when Pragma_Reviewable =>
12686             Check_Ada_83_Warning;
12687             Check_Arg_Count (0);
12688
12689             --  Call dummy debugging function rv. This is done to assist front
12690             --  end debugging. By placing a Reviewable pragma in the source
12691             --  program, a breakpoint on rv catches this place in the source,
12692             --  allowing convenient stepping to the point of interest.
12693
12694             rv;
12695
12696          --------------------------
12697          -- Short_Circuit_And_Or --
12698          --------------------------
12699
12700          when Pragma_Short_Circuit_And_Or =>
12701             GNAT_Pragma;
12702             Check_Arg_Count (0);
12703             Check_Valid_Configuration_Pragma;
12704             Short_Circuit_And_Or := True;
12705
12706          -------------------
12707          -- Share_Generic --
12708          -------------------
12709
12710          --  pragma Share_Generic (NAME {, NAME});
12711
12712          when Pragma_Share_Generic =>
12713             GNAT_Pragma;
12714             Process_Generic_List;
12715
12716          ------------
12717          -- Shared --
12718          ------------
12719
12720          --  pragma Shared (LOCAL_NAME);
12721
12722          when Pragma_Shared =>
12723             GNAT_Pragma;
12724             Process_Atomic_Shared_Volatile;
12725
12726          --------------------
12727          -- Shared_Passive --
12728          --------------------
12729
12730          --  pragma Shared_Passive [(library_unit_NAME)];
12731
12732          --  Set the flag Is_Shared_Passive of program unit name entity
12733
12734          when Pragma_Shared_Passive => Shared_Passive : declare
12735             Cunit_Node : Node_Id;
12736             Cunit_Ent  : Entity_Id;
12737
12738          begin
12739             Check_Ada_83_Warning;
12740             Check_Valid_Library_Unit_Pragma;
12741
12742             if Nkind (N) = N_Null_Statement then
12743                return;
12744             end if;
12745
12746             Cunit_Node := Cunit (Current_Sem_Unit);
12747             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12748
12749             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12750                                                 N_Generic_Package_Declaration)
12751             then
12752                Error_Pragma
12753                  ("pragma% can only apply to a package declaration");
12754             end if;
12755
12756             Set_Is_Shared_Passive (Cunit_Ent);
12757          end Shared_Passive;
12758
12759          -----------------------
12760          -- Short_Descriptors --
12761          -----------------------
12762
12763          --  pragma Short_Descriptors;
12764
12765          when Pragma_Short_Descriptors =>
12766             GNAT_Pragma;
12767             Check_Arg_Count (0);
12768             Check_Valid_Configuration_Pragma;
12769             Short_Descriptors := True;
12770
12771          ----------------------
12772          -- Source_File_Name --
12773          ----------------------
12774
12775          --  There are five forms for this pragma:
12776
12777          --  pragma Source_File_Name (
12778          --    [UNIT_NAME      =>] unit_NAME,
12779          --     BODY_FILE_NAME =>  STRING_LITERAL
12780          --    [, [INDEX =>] INTEGER_LITERAL]);
12781
12782          --  pragma Source_File_Name (
12783          --    [UNIT_NAME      =>] unit_NAME,
12784          --     SPEC_FILE_NAME =>  STRING_LITERAL
12785          --    [, [INDEX =>] INTEGER_LITERAL]);
12786
12787          --  pragma Source_File_Name (
12788          --     BODY_FILE_NAME  => STRING_LITERAL
12789          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12790          --  [, CASING          => CASING_SPEC]);
12791
12792          --  pragma Source_File_Name (
12793          --     SPEC_FILE_NAME  => STRING_LITERAL
12794          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12795          --  [, CASING          => CASING_SPEC]);
12796
12797          --  pragma Source_File_Name (
12798          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12799          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12800          --  [, CASING             => CASING_SPEC]);
12801
12802          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12803
12804          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12805          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12806          --  only be used when no project file is used, while SFNP can only be
12807          --  used when a project file is used.
12808
12809          --  No processing here. Processing was completed during parsing, since
12810          --  we need to have file names set as early as possible. Units are
12811          --  loaded well before semantic processing starts.
12812
12813          --  The only processing we defer to this point is the check for
12814          --  correct placement.
12815
12816          when Pragma_Source_File_Name =>
12817             GNAT_Pragma;
12818             Check_Valid_Configuration_Pragma;
12819
12820          ------------------------------
12821          -- Source_File_Name_Project --
12822          ------------------------------
12823
12824          --  See Source_File_Name for syntax
12825
12826          --  No processing here. Processing was completed during parsing, since
12827          --  we need to have file names set as early as possible. Units are
12828          --  loaded well before semantic processing starts.
12829
12830          --  The only processing we defer to this point is the check for
12831          --  correct placement.
12832
12833          when Pragma_Source_File_Name_Project =>
12834             GNAT_Pragma;
12835             Check_Valid_Configuration_Pragma;
12836
12837             --  Check that a pragma Source_File_Name_Project is used only in a
12838             --  configuration pragmas file.
12839
12840             --  Pragmas Source_File_Name_Project should only be generated by
12841             --  the Project Manager in configuration pragmas files.
12842
12843             --  This is really an ugly test. It seems to depend on some
12844             --  accidental and undocumented property. At the very least it
12845             --  needs to be documented, but it would be better to have a
12846             --  clean way of testing if we are in a configuration file???
12847
12848             if Present (Parent (N)) then
12849                Error_Pragma
12850                  ("pragma% can only appear in a configuration pragmas file");
12851             end if;
12852
12853          ----------------------
12854          -- Source_Reference --
12855          ----------------------
12856
12857          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12858
12859          --  Nothing to do, all processing completed in Par.Prag, since we need
12860          --  the information for possible parser messages that are output.
12861
12862          when Pragma_Source_Reference =>
12863             GNAT_Pragma;
12864
12865          --------------------------------
12866          -- Static_Elaboration_Desired --
12867          --------------------------------
12868
12869          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12870
12871          when Pragma_Static_Elaboration_Desired =>
12872             GNAT_Pragma;
12873             Check_At_Most_N_Arguments (1);
12874
12875             if Is_Compilation_Unit (Current_Scope)
12876               and then Ekind (Current_Scope) = E_Package
12877             then
12878                Set_Static_Elaboration_Desired (Current_Scope, True);
12879             else
12880                Error_Pragma ("pragma% must apply to a library-level package");
12881             end if;
12882
12883          ------------------
12884          -- Storage_Size --
12885          ------------------
12886
12887          --  pragma Storage_Size (EXPRESSION);
12888
12889          when Pragma_Storage_Size => Storage_Size : declare
12890             P   : constant Node_Id := Parent (N);
12891             Arg : Node_Id;
12892
12893          begin
12894             Check_No_Identifiers;
12895             Check_Arg_Count (1);
12896
12897             --  The expression must be analyzed in the special manner described
12898             --  in "Handling of Default Expressions" in sem.ads.
12899
12900             Arg := Get_Pragma_Arg (Arg1);
12901             Preanalyze_Spec_Expression (Arg, Any_Integer);
12902
12903             if not Is_Static_Expression (Arg) then
12904                Check_Restriction (Static_Storage_Size, Arg);
12905             end if;
12906
12907             if Nkind (P) /= N_Task_Definition then
12908                Pragma_Misplaced;
12909                return;
12910
12911             else
12912                if Has_Storage_Size_Pragma (P) then
12913                   Error_Pragma ("duplicate pragma% not allowed");
12914                else
12915                   Set_Has_Storage_Size_Pragma (P, True);
12916                end if;
12917
12918                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12919                --  ???  exp_ch9 should use this!
12920             end if;
12921          end Storage_Size;
12922
12923          ------------------
12924          -- Storage_Unit --
12925          ------------------
12926
12927          --  pragma Storage_Unit (NUMERIC_LITERAL);
12928
12929          --  Only permitted argument is System'Storage_Unit value
12930
12931          when Pragma_Storage_Unit =>
12932             Check_No_Identifiers;
12933             Check_Arg_Count (1);
12934             Check_Arg_Is_Integer_Literal (Arg1);
12935
12936             if Intval (Get_Pragma_Arg (Arg1)) /=
12937               UI_From_Int (Ttypes.System_Storage_Unit)
12938             then
12939                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12940                Error_Pragma_Arg
12941                  ("the only allowed argument for pragma% is ^", Arg1);
12942             end if;
12943
12944          --------------------
12945          -- Stream_Convert --
12946          --------------------
12947
12948          --  pragma Stream_Convert (
12949          --    [Entity =>] type_LOCAL_NAME,
12950          --    [Read   =>] function_NAME,
12951          --    [Write  =>] function NAME);
12952
12953          when Pragma_Stream_Convert => Stream_Convert : declare
12954
12955             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12956             --  Check that the given argument is the name of a local function
12957             --  of one argument that is not overloaded earlier in the current
12958             --  local scope. A check is also made that the argument is a
12959             --  function with one parameter.
12960
12961             --------------------------------------
12962             -- Check_OK_Stream_Convert_Function --
12963             --------------------------------------
12964
12965             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12966                Ent : Entity_Id;
12967
12968             begin
12969                Check_Arg_Is_Local_Name (Arg);
12970                Ent := Entity (Get_Pragma_Arg (Arg));
12971
12972                if Has_Homonym (Ent) then
12973                   Error_Pragma_Arg
12974                     ("argument for pragma% may not be overloaded", Arg);
12975                end if;
12976
12977                if Ekind (Ent) /= E_Function
12978                  or else No (First_Formal (Ent))
12979                  or else Present (Next_Formal (First_Formal (Ent)))
12980                then
12981                   Error_Pragma_Arg
12982                     ("argument for pragma% must be" &
12983                      " function of one argument", Arg);
12984                end if;
12985             end Check_OK_Stream_Convert_Function;
12986
12987          --  Start of processing for Stream_Convert
12988
12989          begin
12990             GNAT_Pragma;
12991             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12992             Check_Arg_Count (3);
12993             Check_Optional_Identifier (Arg1, Name_Entity);
12994             Check_Optional_Identifier (Arg2, Name_Read);
12995             Check_Optional_Identifier (Arg3, Name_Write);
12996             Check_Arg_Is_Local_Name (Arg1);
12997             Check_OK_Stream_Convert_Function (Arg2);
12998             Check_OK_Stream_Convert_Function (Arg3);
12999
13000             declare
13001                Typ   : constant Entity_Id :=
13002                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13003                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13004                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13005
13006             begin
13007                Check_First_Subtype (Arg1);
13008
13009                --  Check for too early or too late. Note that we don't enforce
13010                --  the rule about primitive operations in this case, since, as
13011                --  is the case for explicit stream attributes themselves, these
13012                --  restrictions are not appropriate. Note that the chaining of
13013                --  the pragma by Rep_Item_Too_Late is actually the critical
13014                --  processing done for this pragma.
13015
13016                if Rep_Item_Too_Early (Typ, N)
13017                     or else
13018                   Rep_Item_Too_Late (Typ, N, FOnly => True)
13019                then
13020                   return;
13021                end if;
13022
13023                --  Return if previous error
13024
13025                if Etype (Typ) = Any_Type
13026                     or else
13027                   Etype (Read) = Any_Type
13028                     or else
13029                   Etype (Write) = Any_Type
13030                then
13031                   return;
13032                end if;
13033
13034                --  Error checks
13035
13036                if Underlying_Type (Etype (Read)) /= Typ then
13037                   Error_Pragma_Arg
13038                     ("incorrect return type for function&", Arg2);
13039                end if;
13040
13041                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13042                   Error_Pragma_Arg
13043                     ("incorrect parameter type for function&", Arg3);
13044                end if;
13045
13046                if Underlying_Type (Etype (First_Formal (Read))) /=
13047                   Underlying_Type (Etype (Write))
13048                then
13049                   Error_Pragma_Arg
13050                     ("result type of & does not match Read parameter type",
13051                      Arg3);
13052                end if;
13053             end;
13054          end Stream_Convert;
13055
13056          -------------------------
13057          -- Style_Checks (GNAT) --
13058          -------------------------
13059
13060          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13061
13062          --  This is processed by the parser since some of the style checks
13063          --  take place during source scanning and parsing. This means that
13064          --  we don't need to issue error messages here.
13065
13066          when Pragma_Style_Checks => Style_Checks : declare
13067             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13068             S  : String_Id;
13069             C  : Char_Code;
13070
13071          begin
13072             GNAT_Pragma;
13073             Check_No_Identifiers;
13074
13075             --  Two argument form
13076
13077             if Arg_Count = 2 then
13078                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13079
13080                declare
13081                   E_Id : Node_Id;
13082                   E    : Entity_Id;
13083
13084                begin
13085                   E_Id := Get_Pragma_Arg (Arg2);
13086                   Analyze (E_Id);
13087
13088                   if not Is_Entity_Name (E_Id) then
13089                      Error_Pragma_Arg
13090                        ("second argument of pragma% must be entity name",
13091                         Arg2);
13092                   end if;
13093
13094                   E := Entity (E_Id);
13095
13096                   if E = Any_Id then
13097                      return;
13098                   else
13099                      loop
13100                         Set_Suppress_Style_Checks (E,
13101                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13102                         exit when No (Homonym (E));
13103                         E := Homonym (E);
13104                      end loop;
13105                   end if;
13106                end;
13107
13108             --  One argument form
13109
13110             else
13111                Check_Arg_Count (1);
13112
13113                if Nkind (A) = N_String_Literal then
13114                   S   := Strval (A);
13115
13116                   declare
13117                      Slen    : constant Natural := Natural (String_Length (S));
13118                      Options : String (1 .. Slen);
13119                      J       : Natural;
13120
13121                   begin
13122                      J := 1;
13123                      loop
13124                         C := Get_String_Char (S, Int (J));
13125                         exit when not In_Character_Range (C);
13126                         Options (J) := Get_Character (C);
13127
13128                         --  If at end of string, set options. As per discussion
13129                         --  above, no need to check for errors, since we issued
13130                         --  them in the parser.
13131
13132                         if J = Slen then
13133                            Set_Style_Check_Options (Options);
13134                            exit;
13135                         end if;
13136
13137                         J := J + 1;
13138                      end loop;
13139                   end;
13140
13141                elsif Nkind (A) = N_Identifier then
13142                   if Chars (A) = Name_All_Checks then
13143                      if GNAT_Mode then
13144                         Set_GNAT_Style_Check_Options;
13145                      else
13146                         Set_Default_Style_Check_Options;
13147                      end if;
13148
13149                   elsif Chars (A) = Name_On then
13150                      Style_Check := True;
13151
13152                   elsif Chars (A) = Name_Off then
13153                      Style_Check := False;
13154                   end if;
13155                end if;
13156             end if;
13157          end Style_Checks;
13158
13159          --------------
13160          -- Subtitle --
13161          --------------
13162
13163          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13164
13165          when Pragma_Subtitle =>
13166             GNAT_Pragma;
13167             Check_Arg_Count (1);
13168             Check_Optional_Identifier (Arg1, Name_Subtitle);
13169             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13170             Store_Note (N);
13171
13172          --------------
13173          -- Suppress --
13174          --------------
13175
13176          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13177
13178          when Pragma_Suppress =>
13179             Process_Suppress_Unsuppress (True);
13180
13181          ------------------
13182          -- Suppress_All --
13183          ------------------
13184
13185          --  pragma Suppress_All;
13186
13187          --  The only check made here is that the pragma has no arguments.
13188          --  There are no placement rules, and the processing required (setting
13189          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
13190          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
13191          --  then creates and inserts a pragma Suppress (All_Checks).
13192
13193          when Pragma_Suppress_All =>
13194             GNAT_Pragma;
13195             Check_Arg_Count (0);
13196
13197          -------------------------
13198          -- Suppress_Debug_Info --
13199          -------------------------
13200
13201          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13202
13203          when Pragma_Suppress_Debug_Info =>
13204             GNAT_Pragma;
13205             Check_Arg_Count (1);
13206             Check_Optional_Identifier (Arg1, Name_Entity);
13207             Check_Arg_Is_Local_Name (Arg1);
13208             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13209
13210          ----------------------------------
13211          -- Suppress_Exception_Locations --
13212          ----------------------------------
13213
13214          --  pragma Suppress_Exception_Locations;
13215
13216          when Pragma_Suppress_Exception_Locations =>
13217             GNAT_Pragma;
13218             Check_Arg_Count (0);
13219             Check_Valid_Configuration_Pragma;
13220             Exception_Locations_Suppressed := True;
13221
13222          -----------------------------
13223          -- Suppress_Initialization --
13224          -----------------------------
13225
13226          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13227
13228          when Pragma_Suppress_Initialization => Suppress_Init : declare
13229             E_Id : Node_Id;
13230             E    : Entity_Id;
13231
13232          begin
13233             GNAT_Pragma;
13234             Check_Arg_Count (1);
13235             Check_Optional_Identifier (Arg1, Name_Entity);
13236             Check_Arg_Is_Local_Name (Arg1);
13237
13238             E_Id := Get_Pragma_Arg (Arg1);
13239
13240             if Etype (E_Id) = Any_Type then
13241                return;
13242             end if;
13243
13244             E := Entity (E_Id);
13245
13246             if not Is_Type (E) then
13247                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13248             end if;
13249
13250             if Rep_Item_Too_Early (E, N)
13251                  or else
13252                Rep_Item_Too_Late (E, N, FOnly => True)
13253             then
13254                return;
13255             end if;
13256
13257             --  For incomplete/private type, set flag on full view
13258
13259             if Is_Incomplete_Or_Private_Type (E) then
13260                if No (Full_View (Base_Type (E))) then
13261                   Error_Pragma_Arg
13262                     ("argument of pragma% cannot be an incomplete type", Arg1);
13263                else
13264                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13265                end if;
13266
13267             --  For first subtype, set flag on base type
13268
13269             elsif Is_First_Subtype (E) then
13270                Set_Suppress_Initialization (Base_Type (E));
13271
13272             --  For other than first subtype, set flag on subtype itself
13273
13274             else
13275                Set_Suppress_Initialization (E);
13276             end if;
13277          end Suppress_Init;
13278
13279          -----------------
13280          -- System_Name --
13281          -----------------
13282
13283          --  pragma System_Name (DIRECT_NAME);
13284
13285          --  Syntax check: one argument, which must be the identifier GNAT or
13286          --  the identifier GCC, no other identifiers are acceptable.
13287
13288          when Pragma_System_Name =>
13289             GNAT_Pragma;
13290             Check_No_Identifiers;
13291             Check_Arg_Count (1);
13292             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13293
13294          -----------------------------
13295          -- Task_Dispatching_Policy --
13296          -----------------------------
13297
13298          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13299
13300          when Pragma_Task_Dispatching_Policy => declare
13301             DP : Character;
13302
13303          begin
13304             Check_Ada_83_Warning;
13305             Check_Arg_Count (1);
13306             Check_No_Identifiers;
13307             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13308             Check_Valid_Configuration_Pragma;
13309             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13310             DP := Fold_Upper (Name_Buffer (1));
13311
13312             if Task_Dispatching_Policy /= ' '
13313               and then Task_Dispatching_Policy /= DP
13314             then
13315                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13316                Error_Pragma
13317                  ("task dispatching policy incompatible with policy#");
13318
13319             --  Set new policy, but always preserve System_Location since we
13320             --  like the error message with the run time name.
13321
13322             else
13323                Task_Dispatching_Policy := DP;
13324
13325                if Task_Dispatching_Policy_Sloc /= System_Location then
13326                   Task_Dispatching_Policy_Sloc := Loc;
13327                end if;
13328             end if;
13329          end;
13330
13331          ---------------
13332          -- Task_Info --
13333          ---------------
13334
13335          --  pragma Task_Info (EXPRESSION);
13336
13337          when Pragma_Task_Info => Task_Info : declare
13338             P : constant Node_Id := Parent (N);
13339
13340          begin
13341             GNAT_Pragma;
13342
13343             if Nkind (P) /= N_Task_Definition then
13344                Error_Pragma ("pragma% must appear in task definition");
13345             end if;
13346
13347             Check_No_Identifiers;
13348             Check_Arg_Count (1);
13349
13350             Analyze_And_Resolve
13351               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13352
13353             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13354                return;
13355             end if;
13356
13357             if Has_Task_Info_Pragma (P) then
13358                Error_Pragma ("duplicate pragma% not allowed");
13359             else
13360                Set_Has_Task_Info_Pragma (P, True);
13361             end if;
13362          end Task_Info;
13363
13364          ---------------
13365          -- Task_Name --
13366          ---------------
13367
13368          --  pragma Task_Name (string_EXPRESSION);
13369
13370          when Pragma_Task_Name => Task_Name : declare
13371             P   : constant Node_Id := Parent (N);
13372             Arg : Node_Id;
13373
13374          begin
13375             Check_No_Identifiers;
13376             Check_Arg_Count (1);
13377
13378             Arg := Get_Pragma_Arg (Arg1);
13379
13380             --  The expression is used in the call to Create_Task, and must be
13381             --  expanded there, not in the context of the current spec. It must
13382             --  however be analyzed to capture global references, in case it
13383             --  appears in a generic context.
13384
13385             Preanalyze_And_Resolve (Arg, Standard_String);
13386
13387             if Nkind (P) /= N_Task_Definition then
13388                Pragma_Misplaced;
13389             end if;
13390
13391             if Has_Task_Name_Pragma (P) then
13392                Error_Pragma ("duplicate pragma% not allowed");
13393             else
13394                Set_Has_Task_Name_Pragma (P, True);
13395                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13396             end if;
13397          end Task_Name;
13398
13399          ------------------
13400          -- Task_Storage --
13401          ------------------
13402
13403          --  pragma Task_Storage (
13404          --     [Task_Type =>] LOCAL_NAME,
13405          --     [Top_Guard =>] static_integer_EXPRESSION);
13406
13407          when Pragma_Task_Storage => Task_Storage : declare
13408             Args  : Args_List (1 .. 2);
13409             Names : constant Name_List (1 .. 2) := (
13410                       Name_Task_Type,
13411                       Name_Top_Guard);
13412
13413             Task_Type : Node_Id renames Args (1);
13414             Top_Guard : Node_Id renames Args (2);
13415
13416             Ent : Entity_Id;
13417
13418          begin
13419             GNAT_Pragma;
13420             Gather_Associations (Names, Args);
13421
13422             if No (Task_Type) then
13423                Error_Pragma
13424                  ("missing task_type argument for pragma%");
13425             end if;
13426
13427             Check_Arg_Is_Local_Name (Task_Type);
13428
13429             Ent := Entity (Task_Type);
13430
13431             if not Is_Task_Type (Ent) then
13432                Error_Pragma_Arg
13433                  ("argument for pragma% must be task type", Task_Type);
13434             end if;
13435
13436             if No (Top_Guard) then
13437                Error_Pragma_Arg
13438                  ("pragma% takes two arguments", Task_Type);
13439             else
13440                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13441             end if;
13442
13443             Check_First_Subtype (Task_Type);
13444
13445             if Rep_Item_Too_Late (Ent, N) then
13446                raise Pragma_Exit;
13447             end if;
13448          end Task_Storage;
13449
13450          ---------------
13451          -- Test_Case --
13452          ---------------
13453
13454          --  pragma Test_Case ([Name     =>] Static_String_EXPRESSION
13455          --                   ,[Mode     =>] MODE_TYPE
13456          --                  [, Requires =>  Boolean_EXPRESSION]
13457          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13458
13459          --  MODE_TYPE ::= Nominal | Robustness
13460
13461          when Pragma_Test_Case => Test_Case : declare
13462          begin
13463             GNAT_Pragma;
13464             Check_At_Least_N_Arguments (2);
13465             Check_At_Most_N_Arguments (4);
13466             Check_Arg_Order
13467                  ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13468
13469             Check_Optional_Identifier (Arg1, Name_Name);
13470             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13471             Check_Optional_Identifier (Arg2, Name_Mode);
13472             Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13473
13474             if Arg_Count = 4 then
13475                Check_Identifier (Arg3, Name_Requires);
13476                Check_Identifier (Arg4, Name_Ensures);
13477
13478             elsif Arg_Count = 3 then
13479                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13480             end if;
13481
13482             Check_Test_Case;
13483          end Test_Case;
13484
13485          --------------------------
13486          -- Thread_Local_Storage --
13487          --------------------------
13488
13489          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13490
13491          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13492             Id : Node_Id;
13493             E  : Entity_Id;
13494
13495          begin
13496             GNAT_Pragma;
13497             Check_Arg_Count (1);
13498             Check_Optional_Identifier (Arg1, Name_Entity);
13499             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13500
13501             Id := Get_Pragma_Arg (Arg1);
13502             Analyze (Id);
13503
13504             if not Is_Entity_Name (Id)
13505               or else Ekind (Entity (Id)) /= E_Variable
13506             then
13507                Error_Pragma_Arg ("local variable name required", Arg1);
13508             end if;
13509
13510             E := Entity (Id);
13511
13512             if Rep_Item_Too_Early (E, N)
13513               or else Rep_Item_Too_Late (E, N)
13514             then
13515                raise Pragma_Exit;
13516             end if;
13517
13518             Set_Has_Pragma_Thread_Local_Storage (E);
13519             Set_Has_Gigi_Rep_Item (E);
13520          end Thread_Local_Storage;
13521
13522          ----------------
13523          -- Time_Slice --
13524          ----------------
13525
13526          --  pragma Time_Slice (static_duration_EXPRESSION);
13527
13528          when Pragma_Time_Slice => Time_Slice : declare
13529             Val : Ureal;
13530             Nod : Node_Id;
13531
13532          begin
13533             GNAT_Pragma;
13534             Check_Arg_Count (1);
13535             Check_No_Identifiers;
13536             Check_In_Main_Program;
13537             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13538
13539             if not Error_Posted (Arg1) then
13540                Nod := Next (N);
13541                while Present (Nod) loop
13542                   if Nkind (Nod) = N_Pragma
13543                     and then Pragma_Name (Nod) = Name_Time_Slice
13544                   then
13545                      Error_Msg_Name_1 := Pname;
13546                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13547                   end if;
13548
13549                   Next (Nod);
13550                end loop;
13551             end if;
13552
13553             --  Process only if in main unit
13554
13555             if Get_Source_Unit (Loc) = Main_Unit then
13556                Opt.Time_Slice_Set := True;
13557                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13558
13559                if Val <= Ureal_0 then
13560                   Opt.Time_Slice_Value := 0;
13561
13562                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13563                   Opt.Time_Slice_Value := 1_000_000_000;
13564
13565                else
13566                   Opt.Time_Slice_Value :=
13567                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13568                end if;
13569             end if;
13570          end Time_Slice;
13571
13572          -----------
13573          -- Title --
13574          -----------
13575
13576          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13577
13578          --   TITLING_OPTION ::=
13579          --     [Title =>] STRING_LITERAL
13580          --   | [Subtitle =>] STRING_LITERAL
13581
13582          when Pragma_Title => Title : declare
13583             Args  : Args_List (1 .. 2);
13584             Names : constant Name_List (1 .. 2) := (
13585                       Name_Title,
13586                       Name_Subtitle);
13587
13588          begin
13589             GNAT_Pragma;
13590             Gather_Associations (Names, Args);
13591             Store_Note (N);
13592
13593             for J in 1 .. 2 loop
13594                if Present (Args (J)) then
13595                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13596                end if;
13597             end loop;
13598          end Title;
13599
13600          ---------------------
13601          -- Unchecked_Union --
13602          ---------------------
13603
13604          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13605
13606          when Pragma_Unchecked_Union => Unchecked_Union : declare
13607             Assoc   : constant Node_Id := Arg1;
13608             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13609             Typ     : Entity_Id;
13610             Discr   : Entity_Id;
13611             Tdef    : Node_Id;
13612             Clist   : Node_Id;
13613             Vpart   : Node_Id;
13614             Comp    : Node_Id;
13615             Variant : Node_Id;
13616
13617          begin
13618             Ada_2005_Pragma;
13619             Check_No_Identifiers;
13620             Check_Arg_Count (1);
13621             Check_Arg_Is_Local_Name (Arg1);
13622
13623             Find_Type (Type_Id);
13624             Typ := Entity (Type_Id);
13625
13626             if Typ = Any_Type
13627               or else Rep_Item_Too_Early (Typ, N)
13628             then
13629                return;
13630             else
13631                Typ := Underlying_Type (Typ);
13632             end if;
13633
13634             if Rep_Item_Too_Late (Typ, N) then
13635                return;
13636             end if;
13637
13638             Check_First_Subtype (Arg1);
13639
13640             --  Note remaining cases are references to a type in the current
13641             --  declarative part. If we find an error, we post the error on
13642             --  the relevant type declaration at an appropriate point.
13643
13644             if not Is_Record_Type (Typ) then
13645                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13646                return;
13647
13648             elsif Is_Tagged_Type (Typ) then
13649                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13650                return;
13651
13652             elsif Is_Limited_Type (Typ) then
13653                Error_Msg_N
13654                  ("Unchecked_Union must not be limited record type", Typ);
13655                Explain_Limited_Type (Typ, Typ);
13656                return;
13657
13658             else
13659                if not Has_Discriminants (Typ) then
13660                   Error_Msg_N
13661                     ("Unchecked_Union must have one discriminant", Typ);
13662                   return;
13663                end if;
13664
13665                Discr := First_Discriminant (Typ);
13666                while Present (Discr) loop
13667                   if No (Discriminant_Default_Value (Discr)) then
13668                      Error_Msg_N
13669                        ("Unchecked_Union discriminant must have default value",
13670                         Discr);
13671                   end if;
13672
13673                   Next_Discriminant (Discr);
13674                end loop;
13675
13676                Tdef  := Type_Definition (Declaration_Node (Typ));
13677                Clist := Component_List (Tdef);
13678
13679                Comp := First (Component_Items (Clist));
13680                while Present (Comp) loop
13681                   Check_Component (Comp, Typ);
13682                   Next (Comp);
13683                end loop;
13684
13685                if No (Clist) or else No (Variant_Part (Clist)) then
13686                   Error_Msg_N
13687                     ("Unchecked_Union must have variant part",
13688                      Tdef);
13689                   return;
13690                end if;
13691
13692                Vpart := Variant_Part (Clist);
13693
13694                Variant := First (Variants (Vpart));
13695                while Present (Variant) loop
13696                   Check_Variant (Variant, Typ);
13697                   Next (Variant);
13698                end loop;
13699             end if;
13700
13701             Set_Is_Unchecked_Union  (Typ);
13702             Set_Convention (Typ, Convention_C);
13703             Set_Has_Unchecked_Union (Base_Type (Typ));
13704             Set_Is_Unchecked_Union  (Base_Type (Typ));
13705          end Unchecked_Union;
13706
13707          ------------------------
13708          -- Unimplemented_Unit --
13709          ------------------------
13710
13711          --  pragma Unimplemented_Unit;
13712
13713          --  Note: this only gives an error if we are generating code, or if
13714          --  we are in a generic library unit (where the pragma appears in the
13715          --  body, not in the spec).
13716
13717          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13718             Cunitent : constant Entity_Id :=
13719                          Cunit_Entity (Get_Source_Unit (Loc));
13720             Ent_Kind : constant Entity_Kind :=
13721                          Ekind (Cunitent);
13722
13723          begin
13724             GNAT_Pragma;
13725             Check_Arg_Count (0);
13726
13727             if Operating_Mode = Generate_Code
13728               or else Ent_Kind = E_Generic_Function
13729               or else Ent_Kind = E_Generic_Procedure
13730               or else Ent_Kind = E_Generic_Package
13731             then
13732                Get_Name_String (Chars (Cunitent));
13733                Set_Casing (Mixed_Case);
13734                Write_Str (Name_Buffer (1 .. Name_Len));
13735                Write_Str (" is not supported in this configuration");
13736                Write_Eol;
13737                raise Unrecoverable_Error;
13738             end if;
13739          end Unimplemented_Unit;
13740
13741          ------------------------
13742          -- Universal_Aliasing --
13743          ------------------------
13744
13745          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13746
13747          when Pragma_Universal_Aliasing => Universal_Alias : declare
13748             E_Id : Entity_Id;
13749
13750          begin
13751             GNAT_Pragma;
13752             Check_Arg_Count (1);
13753             Check_Optional_Identifier (Arg2, Name_Entity);
13754             Check_Arg_Is_Local_Name (Arg1);
13755             E_Id := Entity (Get_Pragma_Arg (Arg1));
13756
13757             if E_Id = Any_Type then
13758                return;
13759             elsif No (E_Id) or else not Is_Type (E_Id) then
13760                Error_Pragma_Arg ("pragma% requires type", Arg1);
13761             end if;
13762
13763             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13764          end Universal_Alias;
13765
13766          --------------------
13767          -- Universal_Data --
13768          --------------------
13769
13770          --  pragma Universal_Data [(library_unit_NAME)];
13771
13772          when Pragma_Universal_Data =>
13773             GNAT_Pragma;
13774
13775             --  If this is a configuration pragma, then set the universal
13776             --  addressing option, otherwise confirm that the pragma satisfies
13777             --  the requirements of library unit pragma placement and leave it
13778             --  to the GNAAMP back end to detect the pragma (avoids transitive
13779             --  setting of the option due to withed units).
13780
13781             if Is_Configuration_Pragma then
13782                Universal_Addressing_On_AAMP := True;
13783             else
13784                Check_Valid_Library_Unit_Pragma;
13785             end if;
13786
13787             if not AAMP_On_Target then
13788                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13789             end if;
13790
13791          ----------------
13792          -- Unmodified --
13793          ----------------
13794
13795          --  pragma Unmodified (local_Name {, local_Name});
13796
13797          when Pragma_Unmodified => Unmodified : declare
13798             Arg_Node : Node_Id;
13799             Arg_Expr : Node_Id;
13800             Arg_Ent  : Entity_Id;
13801
13802          begin
13803             GNAT_Pragma;
13804             Check_At_Least_N_Arguments (1);
13805
13806             --  Loop through arguments
13807
13808             Arg_Node := Arg1;
13809             while Present (Arg_Node) loop
13810                Check_No_Identifier (Arg_Node);
13811
13812                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13813                --  in fact generate reference, so that the entity will have a
13814                --  reference, which will inhibit any warnings about it not
13815                --  being referenced, and also properly show up in the ali file
13816                --  as a reference. But this reference is recorded before the
13817                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13818                --  generated for this reference.
13819
13820                Check_Arg_Is_Local_Name (Arg_Node);
13821                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13822
13823                if Is_Entity_Name (Arg_Expr) then
13824                   Arg_Ent := Entity (Arg_Expr);
13825
13826                   if not Is_Assignable (Arg_Ent) then
13827                      Error_Pragma_Arg
13828                        ("pragma% can only be applied to a variable",
13829                         Arg_Expr);
13830                   else
13831                      Set_Has_Pragma_Unmodified (Arg_Ent);
13832                   end if;
13833                end if;
13834
13835                Next (Arg_Node);
13836             end loop;
13837          end Unmodified;
13838
13839          ------------------
13840          -- Unreferenced --
13841          ------------------
13842
13843          --  pragma Unreferenced (local_Name {, local_Name});
13844
13845          --    or when used in a context clause:
13846
13847          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13848
13849          when Pragma_Unreferenced => Unreferenced : declare
13850             Arg_Node : Node_Id;
13851             Arg_Expr : Node_Id;
13852             Arg_Ent  : Entity_Id;
13853             Citem    : Node_Id;
13854
13855          begin
13856             GNAT_Pragma;
13857             Check_At_Least_N_Arguments (1);
13858
13859             --  Check case of appearing within context clause
13860
13861             if Is_In_Context_Clause then
13862
13863                --  The arguments must all be units mentioned in a with clause
13864                --  in the same context clause. Note we already checked (in
13865                --  Par.Prag) that the arguments are either identifiers or
13866                --  selected components.
13867
13868                Arg_Node := Arg1;
13869                while Present (Arg_Node) loop
13870                   Citem := First (List_Containing (N));
13871                   while Citem /= N loop
13872                      if Nkind (Citem) = N_With_Clause
13873                        and then
13874                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13875                      then
13876                         Set_Has_Pragma_Unreferenced
13877                           (Cunit_Entity
13878                              (Get_Source_Unit
13879                                 (Library_Unit (Citem))));
13880                         Set_Unit_Name
13881                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
13882                         exit;
13883                      end if;
13884
13885                      Next (Citem);
13886                   end loop;
13887
13888                   if Citem = N then
13889                      Error_Pragma_Arg
13890                        ("argument of pragma% is not with'ed unit", Arg_Node);
13891                   end if;
13892
13893                   Next (Arg_Node);
13894                end loop;
13895
13896             --  Case of not in list of context items
13897
13898             else
13899                Arg_Node := Arg1;
13900                while Present (Arg_Node) loop
13901                   Check_No_Identifier (Arg_Node);
13902
13903                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
13904                   --  will in fact generate reference, so that the entity will
13905                   --  have a reference, which will inhibit any warnings about
13906                   --  it not being referenced, and also properly show up in the
13907                   --  ali file as a reference. But this reference is recorded
13908                   --  before the Has_Pragma_Unreferenced flag is set, so that
13909                   --  no warning is generated for this reference.
13910
13911                   Check_Arg_Is_Local_Name (Arg_Node);
13912                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
13913
13914                   if Is_Entity_Name (Arg_Expr) then
13915                      Arg_Ent := Entity (Arg_Expr);
13916
13917                      --  If the entity is overloaded, the pragma applies to the
13918                      --  most recent overloading, as documented. In this case,
13919                      --  name resolution does not generate a reference, so it
13920                      --  must be done here explicitly.
13921
13922                      if Is_Overloaded (Arg_Expr) then
13923                         Generate_Reference (Arg_Ent, N);
13924                      end if;
13925
13926                      Set_Has_Pragma_Unreferenced (Arg_Ent);
13927                   end if;
13928
13929                   Next (Arg_Node);
13930                end loop;
13931             end if;
13932          end Unreferenced;
13933
13934          --------------------------
13935          -- Unreferenced_Objects --
13936          --------------------------
13937
13938          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13939
13940          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13941             Arg_Node : Node_Id;
13942             Arg_Expr : Node_Id;
13943
13944          begin
13945             GNAT_Pragma;
13946             Check_At_Least_N_Arguments (1);
13947
13948             Arg_Node := Arg1;
13949             while Present (Arg_Node) loop
13950                Check_No_Identifier (Arg_Node);
13951                Check_Arg_Is_Local_Name (Arg_Node);
13952                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13953
13954                if not Is_Entity_Name (Arg_Expr)
13955                  or else not Is_Type (Entity (Arg_Expr))
13956                then
13957                   Error_Pragma_Arg
13958                     ("argument for pragma% must be type or subtype", Arg_Node);
13959                end if;
13960
13961                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13962                Next (Arg_Node);
13963             end loop;
13964          end Unreferenced_Objects;
13965
13966          ------------------------------
13967          -- Unreserve_All_Interrupts --
13968          ------------------------------
13969
13970          --  pragma Unreserve_All_Interrupts;
13971
13972          when Pragma_Unreserve_All_Interrupts =>
13973             GNAT_Pragma;
13974             Check_Arg_Count (0);
13975
13976             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13977                Unreserve_All_Interrupts := True;
13978             end if;
13979
13980          ----------------
13981          -- Unsuppress --
13982          ----------------
13983
13984          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13985
13986          when Pragma_Unsuppress =>
13987             Ada_2005_Pragma;
13988             Process_Suppress_Unsuppress (False);
13989
13990          -------------------
13991          -- Use_VADS_Size --
13992          -------------------
13993
13994          --  pragma Use_VADS_Size;
13995
13996          when Pragma_Use_VADS_Size =>
13997             GNAT_Pragma;
13998             Check_Arg_Count (0);
13999             Check_Valid_Configuration_Pragma;
14000             Use_VADS_Size := True;
14001
14002          ---------------------
14003          -- Validity_Checks --
14004          ---------------------
14005
14006          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14007
14008          when Pragma_Validity_Checks => Validity_Checks : declare
14009             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
14010             S  : String_Id;
14011             C  : Char_Code;
14012
14013          begin
14014             GNAT_Pragma;
14015             Check_Arg_Count (1);
14016             Check_No_Identifiers;
14017
14018             if Nkind (A) = N_String_Literal then
14019                S   := Strval (A);
14020
14021                declare
14022                   Slen    : constant Natural := Natural (String_Length (S));
14023                   Options : String (1 .. Slen);
14024                   J       : Natural;
14025
14026                begin
14027                   J := 1;
14028                   loop
14029                      C := Get_String_Char (S, Int (J));
14030                      exit when not In_Character_Range (C);
14031                      Options (J) := Get_Character (C);
14032
14033                      if J = Slen then
14034                         Set_Validity_Check_Options (Options);
14035                         exit;
14036                      else
14037                         J := J + 1;
14038                      end if;
14039                   end loop;
14040                end;
14041
14042             elsif Nkind (A) = N_Identifier then
14043
14044                if Chars (A) = Name_All_Checks then
14045                   Set_Validity_Check_Options ("a");
14046
14047                elsif Chars (A) = Name_On then
14048                   Validity_Checks_On := True;
14049
14050                elsif Chars (A) = Name_Off then
14051                   Validity_Checks_On := False;
14052
14053                end if;
14054             end if;
14055          end Validity_Checks;
14056
14057          --------------
14058          -- Volatile --
14059          --------------
14060
14061          --  pragma Volatile (LOCAL_NAME);
14062
14063          when Pragma_Volatile =>
14064             Process_Atomic_Shared_Volatile;
14065
14066          -------------------------
14067          -- Volatile_Components --
14068          -------------------------
14069
14070          --  pragma Volatile_Components (array_LOCAL_NAME);
14071
14072          --  Volatile is handled by the same circuit as Atomic_Components
14073
14074          --------------
14075          -- Warnings --
14076          --------------
14077
14078          --  pragma Warnings (On | Off);
14079          --  pragma Warnings (On | Off, LOCAL_NAME);
14080          --  pragma Warnings (static_string_EXPRESSION);
14081          --  pragma Warnings (On | Off, STRING_LITERAL);
14082
14083          when Pragma_Warnings => Warnings : begin
14084             GNAT_Pragma;
14085             Check_At_Least_N_Arguments (1);
14086             Check_No_Identifiers;
14087
14088             --  If debug flag -gnatd.i is set, pragma is ignored
14089
14090             if Debug_Flag_Dot_I then
14091                return;
14092             end if;
14093
14094             --  Process various forms of the pragma
14095
14096             declare
14097                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14098
14099             begin
14100                --  One argument case
14101
14102                if Arg_Count = 1 then
14103
14104                   --  On/Off one argument case was processed by parser
14105
14106                   if Nkind (Argx) = N_Identifier
14107                     and then
14108                       (Chars (Argx) = Name_On
14109                          or else
14110                        Chars (Argx) = Name_Off)
14111                   then
14112                      null;
14113
14114                   --  One argument case must be ON/OFF or static string expr
14115
14116                   elsif not Is_Static_String_Expression (Arg1) then
14117                      Error_Pragma_Arg
14118                        ("argument of pragma% must be On/Off or " &
14119                         "static string expression", Arg1);
14120
14121                   --  One argument string expression case
14122
14123                   else
14124                      declare
14125                         Lit : constant Node_Id   := Expr_Value_S (Argx);
14126                         Str : constant String_Id := Strval (Lit);
14127                         Len : constant Nat       := String_Length (Str);
14128                         C   : Char_Code;
14129                         J   : Nat;
14130                         OK  : Boolean;
14131                         Chr : Character;
14132
14133                      begin
14134                         J := 1;
14135                         while J <= Len loop
14136                            C := Get_String_Char (Str, J);
14137                            OK := In_Character_Range (C);
14138
14139                            if OK then
14140                               Chr := Get_Character (C);
14141
14142                               --  Dot case
14143
14144                               if J < Len and then Chr = '.' then
14145                                  J := J + 1;
14146                                  C := Get_String_Char (Str, J);
14147                                  Chr := Get_Character (C);
14148
14149                                  if not Set_Dot_Warning_Switch (Chr) then
14150                                     Error_Pragma_Arg
14151                                       ("invalid warning switch character " &
14152                                        '.' & Chr, Arg1);
14153                                  end if;
14154
14155                               --  Non-Dot case
14156
14157                               else
14158                                  OK := Set_Warning_Switch (Chr);
14159                               end if;
14160                            end if;
14161
14162                            if not OK then
14163                               Error_Pragma_Arg
14164                                 ("invalid warning switch character " & Chr,
14165                                  Arg1);
14166                            end if;
14167
14168                            J := J + 1;
14169                         end loop;
14170                      end;
14171                   end if;
14172
14173                   --  Two or more arguments (must be two)
14174
14175                else
14176                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14177                   Check_At_Most_N_Arguments (2);
14178
14179                   declare
14180                      E_Id : Node_Id;
14181                      E    : Entity_Id;
14182                      Err  : Boolean;
14183
14184                   begin
14185                      E_Id := Get_Pragma_Arg (Arg2);
14186                      Analyze (E_Id);
14187
14188                      --  In the expansion of an inlined body, a reference to
14189                      --  the formal may be wrapped in a conversion if the
14190                      --  actual is a conversion. Retrieve the real entity name.
14191
14192                      if (In_Instance_Body
14193                          or else In_Inlined_Body)
14194                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14195                      then
14196                         E_Id := Expression (E_Id);
14197                      end if;
14198
14199                      --  Entity name case
14200
14201                      if Is_Entity_Name (E_Id) then
14202                         E := Entity (E_Id);
14203
14204                         if E = Any_Id then
14205                            return;
14206                         else
14207                            loop
14208                               Set_Warnings_Off
14209                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14210                                                               Name_Off));
14211
14212                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14213                                 and then Warn_On_Warnings_Off
14214                               then
14215                                  Warnings_Off_Pragmas.Append ((N, E));
14216                               end if;
14217
14218                               if Is_Enumeration_Type (E) then
14219                                  declare
14220                                     Lit : Entity_Id;
14221                                  begin
14222                                     Lit := First_Literal (E);
14223                                     while Present (Lit) loop
14224                                        Set_Warnings_Off (Lit);
14225                                        Next_Literal (Lit);
14226                                     end loop;
14227                                  end;
14228                               end if;
14229
14230                               exit when No (Homonym (E));
14231                               E := Homonym (E);
14232                            end loop;
14233                         end if;
14234
14235                      --  Error if not entity or static string literal case
14236
14237                      elsif not Is_Static_String_Expression (Arg2) then
14238                         Error_Pragma_Arg
14239                           ("second argument of pragma% must be entity " &
14240                            "name or static string expression", Arg2);
14241
14242                      --  String literal case
14243
14244                      else
14245                         String_To_Name_Buffer
14246                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14247
14248                         --  Note on configuration pragma case: If this is a
14249                         --  configuration pragma, then for an OFF pragma, we
14250                         --  just set Config True in the call, which is all
14251                         --  that needs to be done. For the case of ON, this
14252                         --  is normally an error, unless it is canceling the
14253                         --  effect of a previous OFF pragma in the same file.
14254                         --  In any other case, an error will be signalled (ON
14255                         --  with no matching OFF).
14256
14257                         if Chars (Argx) = Name_Off then
14258                            Set_Specific_Warning_Off
14259                              (Loc, Name_Buffer (1 .. Name_Len),
14260                               Config => Is_Configuration_Pragma);
14261
14262                         elsif Chars (Argx) = Name_On then
14263                            Set_Specific_Warning_On
14264                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14265
14266                            if Err then
14267                               Error_Msg
14268                                 ("?pragma Warnings On with no " &
14269                                  "matching Warnings Off",
14270                                  Loc);
14271                            end if;
14272                         end if;
14273                      end if;
14274                   end;
14275                end if;
14276             end;
14277          end Warnings;
14278
14279          -------------------
14280          -- Weak_External --
14281          -------------------
14282
14283          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14284
14285          when Pragma_Weak_External => Weak_External : declare
14286             Ent : Entity_Id;
14287
14288          begin
14289             GNAT_Pragma;
14290             Check_Arg_Count (1);
14291             Check_Optional_Identifier (Arg1, Name_Entity);
14292             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14293             Ent := Entity (Get_Pragma_Arg (Arg1));
14294
14295             if Rep_Item_Too_Early (Ent, N) then
14296                return;
14297             else
14298                Ent := Underlying_Type (Ent);
14299             end if;
14300
14301             --  The only processing required is to link this item on to the
14302             --  list of rep items for the given entity. This is accomplished
14303             --  by the call to Rep_Item_Too_Late (when no error is detected
14304             --  and False is returned).
14305
14306             if Rep_Item_Too_Late (Ent, N) then
14307                return;
14308             else
14309                Set_Has_Gigi_Rep_Item (Ent);
14310             end if;
14311          end Weak_External;
14312
14313          -----------------------------
14314          -- Wide_Character_Encoding --
14315          -----------------------------
14316
14317          --  pragma Wide_Character_Encoding (IDENTIFIER);
14318
14319          when Pragma_Wide_Character_Encoding =>
14320             GNAT_Pragma;
14321
14322             --  Nothing to do, handled in parser. Note that we do not enforce
14323             --  configuration pragma placement, this pragma can appear at any
14324             --  place in the source, allowing mixed encodings within a single
14325             --  source program.
14326
14327             null;
14328
14329          --------------------
14330          -- Unknown_Pragma --
14331          --------------------
14332
14333          --  Should be impossible, since the case of an unknown pragma is
14334          --  separately processed before the case statement is entered.
14335
14336          when Unknown_Pragma =>
14337             raise Program_Error;
14338       end case;
14339
14340       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14341       --  until AI is formally approved.
14342
14343       --  Check_Order_Dependence;
14344
14345    exception
14346       when Pragma_Exit => null;
14347    end Analyze_Pragma;
14348
14349    -----------------------------
14350    -- Analyze_TC_In_Decl_Part --
14351    -----------------------------
14352
14353    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14354    begin
14355       --  Install formals and push subprogram spec onto scope stack so that we
14356       --  can see the formals from the pragma.
14357
14358       Install_Formals (S);
14359       Push_Scope (S);
14360
14361       --  Preanalyze the boolean expressions, we treat these as spec
14362       --  expressions (i.e. similar to a default expression).
14363
14364       Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14365                           Get_Ensures_From_Test_Case_Pragma (N));
14366
14367       --  Remove the subprogram from the scope stack now that the pre-analysis
14368       --  of the expressions in the test-case is done.
14369
14370       End_Scope;
14371    end Analyze_TC_In_Decl_Part;
14372
14373    --------------------
14374    -- Check_Disabled --
14375    --------------------
14376
14377    function Check_Disabled (Nam : Name_Id) return Boolean is
14378       PP : Node_Id;
14379
14380    begin
14381       --  Loop through entries in check policy list
14382
14383       PP := Opt.Check_Policy_List;
14384       loop
14385          --  If there are no specific entries that matched, then nothing is
14386          --  disabled, so return False.
14387
14388          if No (PP) then
14389             return False;
14390
14391          --  Here we have an entry see if it matches
14392
14393          else
14394             declare
14395                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14396             begin
14397                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14398                   return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14399                else
14400                   PP := Next_Pragma (PP);
14401                end if;
14402             end;
14403          end if;
14404       end loop;
14405    end Check_Disabled;
14406
14407    -------------------
14408    -- Check_Enabled --
14409    -------------------
14410
14411    function Check_Enabled (Nam : Name_Id) return Boolean is
14412       PP : Node_Id;
14413
14414    begin
14415       --  Loop through entries in check policy list
14416
14417       PP := Opt.Check_Policy_List;
14418       loop
14419          --  If there are no specific entries that matched, then we let the
14420          --  setting of assertions govern. Note that this provides the needed
14421          --  compatibility with the RM for the cases of assertion, invariant,
14422          --  precondition, predicate, and postcondition.
14423
14424          if No (PP) then
14425             return Assertions_Enabled;
14426
14427          --  Here we have an entry see if it matches
14428
14429          else
14430             declare
14431                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14432
14433             begin
14434                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14435                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14436                      when Name_On | Name_Check =>
14437                         return True;
14438                      when Name_Off | Name_Ignore =>
14439                         return False;
14440                      when others =>
14441                         raise Program_Error;
14442                   end case;
14443
14444                else
14445                   PP := Next_Pragma (PP);
14446                end if;
14447             end;
14448          end if;
14449       end loop;
14450    end Check_Enabled;
14451
14452    ---------------------------------
14453    -- Delay_Config_Pragma_Analyze --
14454    ---------------------------------
14455
14456    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14457    begin
14458       return Pragma_Name (N) = Name_Interrupt_State
14459                or else
14460              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14461    end Delay_Config_Pragma_Analyze;
14462
14463    -------------------------
14464    -- Get_Base_Subprogram --
14465    -------------------------
14466
14467    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14468       Result : Entity_Id;
14469
14470    begin
14471       --  Follow subprogram renaming chain
14472
14473       Result := Def_Id;
14474       while Is_Subprogram (Result)
14475         and then
14476           Nkind (Parent (Declaration_Node (Result))) =
14477                                          N_Subprogram_Renaming_Declaration
14478         and then Present (Alias (Result))
14479       loop
14480          Result := Alias (Result);
14481       end loop;
14482
14483       return Result;
14484    end Get_Base_Subprogram;
14485
14486    ----------------
14487    -- Initialize --
14488    ----------------
14489
14490    procedure Initialize is
14491    begin
14492       Externals.Init;
14493    end Initialize;
14494
14495    -----------------------------
14496    -- Is_Config_Static_String --
14497    -----------------------------
14498
14499    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14500
14501       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14502       --  This is an internal recursive function that is just like the outer
14503       --  function except that it adds the string to the name buffer rather
14504       --  than placing the string in the name buffer.
14505
14506       ------------------------------
14507       -- Add_Config_Static_String --
14508       ------------------------------
14509
14510       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14511          N : Node_Id;
14512          C : Char_Code;
14513
14514       begin
14515          N := Arg;
14516
14517          if Nkind (N) = N_Op_Concat then
14518             if Add_Config_Static_String (Left_Opnd (N)) then
14519                N := Right_Opnd (N);
14520             else
14521                return False;
14522             end if;
14523          end if;
14524
14525          if Nkind (N) /= N_String_Literal then
14526             Error_Msg_N ("string literal expected for pragma argument", N);
14527             return False;
14528
14529          else
14530             for J in 1 .. String_Length (Strval (N)) loop
14531                C := Get_String_Char (Strval (N), J);
14532
14533                if not In_Character_Range (C) then
14534                   Error_Msg
14535                     ("string literal contains invalid wide character",
14536                      Sloc (N) + 1 + Source_Ptr (J));
14537                   return False;
14538                end if;
14539
14540                Add_Char_To_Name_Buffer (Get_Character (C));
14541             end loop;
14542          end if;
14543
14544          return True;
14545       end Add_Config_Static_String;
14546
14547    --  Start of processing for Is_Config_Static_String
14548
14549    begin
14550
14551       Name_Len := 0;
14552       return Add_Config_Static_String (Arg);
14553    end Is_Config_Static_String;
14554
14555    -----------------------------------------
14556    -- Is_Non_Significant_Pragma_Reference --
14557    -----------------------------------------
14558
14559    --  This function makes use of the following static table which indicates
14560    --  whether a given pragma is significant.
14561
14562    --  -1  indicates that references in any argument position are significant
14563    --  0   indicates that appearance in any argument is not significant
14564    --  +n  indicates that appearance as argument n is significant, but all
14565    --      other arguments are not significant
14566    --  99  special processing required (e.g. for pragma Check)
14567
14568    Sig_Flags : constant array (Pragma_Id) of Int :=
14569      (Pragma_AST_Entry                     => -1,
14570       Pragma_Abort_Defer                   => -1,
14571       Pragma_Ada_83                        => -1,
14572       Pragma_Ada_95                        => -1,
14573       Pragma_Ada_05                        => -1,
14574       Pragma_Ada_2005                      => -1,
14575       Pragma_Ada_12                        => -1,
14576       Pragma_Ada_2012                      => -1,
14577       Pragma_All_Calls_Remote              => -1,
14578       Pragma_Annotate                      => -1,
14579       Pragma_Assert                        => -1,
14580       Pragma_Assertion_Policy              =>  0,
14581       Pragma_Assume_No_Invalid_Values      =>  0,
14582       Pragma_Asynchronous                  => -1,
14583       Pragma_Atomic                        =>  0,
14584       Pragma_Atomic_Components             =>  0,
14585       Pragma_Attach_Handler                => -1,
14586       Pragma_Check                         => 99,
14587       Pragma_Check_Name                    =>  0,
14588       Pragma_Check_Policy                  =>  0,
14589       Pragma_CIL_Constructor               => -1,
14590       Pragma_CPP_Class                     =>  0,
14591       Pragma_CPP_Constructor               =>  0,
14592       Pragma_CPP_Virtual                   =>  0,
14593       Pragma_CPP_Vtable                    =>  0,
14594       Pragma_CPU                           => -1,
14595       Pragma_C_Pass_By_Copy                =>  0,
14596       Pragma_Comment                       =>  0,
14597       Pragma_Common_Object                 => -1,
14598       Pragma_Compile_Time_Error            => -1,
14599       Pragma_Compile_Time_Warning          => -1,
14600       Pragma_Compiler_Unit                 =>  0,
14601       Pragma_Complete_Representation       =>  0,
14602       Pragma_Complex_Representation        =>  0,
14603       Pragma_Component_Alignment           => -1,
14604       Pragma_Controlled                    =>  0,
14605       Pragma_Convention                    =>  0,
14606       Pragma_Convention_Identifier         =>  0,
14607       Pragma_Debug                         => -1,
14608       Pragma_Debug_Policy                  =>  0,
14609       Pragma_Detect_Blocking               => -1,
14610       Pragma_Default_Storage_Pool          => -1,
14611       Pragma_Dimension                     => -1,
14612       Pragma_Discard_Names                 =>  0,
14613       Pragma_Dispatching_Domain            => -1,
14614       Pragma_Elaborate                     => -1,
14615       Pragma_Elaborate_All                 => -1,
14616       Pragma_Elaborate_Body                => -1,
14617       Pragma_Elaboration_Checks            => -1,
14618       Pragma_Eliminate                     => -1,
14619       Pragma_Export                        => -1,
14620       Pragma_Export_Exception              => -1,
14621       Pragma_Export_Function               => -1,
14622       Pragma_Export_Object                 => -1,
14623       Pragma_Export_Procedure              => -1,
14624       Pragma_Export_Value                  => -1,
14625       Pragma_Export_Valued_Procedure       => -1,
14626       Pragma_Extend_System                 => -1,
14627       Pragma_Extensions_Allowed            => -1,
14628       Pragma_External                      => -1,
14629       Pragma_Favor_Top_Level               => -1,
14630       Pragma_External_Name_Casing          => -1,
14631       Pragma_Fast_Math                     => -1,
14632       Pragma_Finalize_Storage_Only         =>  0,
14633       Pragma_Float_Representation          =>  0,
14634       Pragma_Ident                         => -1,
14635       Pragma_Implemented                   => -1,
14636       Pragma_Implicit_Packing              =>  0,
14637       Pragma_Import                        => +2,
14638       Pragma_Import_Exception              =>  0,
14639       Pragma_Import_Function               =>  0,
14640       Pragma_Import_Object                 =>  0,
14641       Pragma_Import_Procedure              =>  0,
14642       Pragma_Import_Valued_Procedure       =>  0,
14643       Pragma_Independent                   =>  0,
14644       Pragma_Independent_Components        =>  0,
14645       Pragma_Initialize_Scalars            => -1,
14646       Pragma_Inline                        =>  0,
14647       Pragma_Inline_Always                 =>  0,
14648       Pragma_Inline_Generic                =>  0,
14649       Pragma_Inspection_Point              => -1,
14650       Pragma_Interface                     => +2,
14651       Pragma_Interface_Name                => +2,
14652       Pragma_Interrupt_Handler             => -1,
14653       Pragma_Interrupt_Priority            => -1,
14654       Pragma_Interrupt_State               => -1,
14655       Pragma_Invariant                     => -1,
14656       Pragma_Java_Constructor              => -1,
14657       Pragma_Java_Interface                => -1,
14658       Pragma_Keep_Names                    =>  0,
14659       Pragma_License                       => -1,
14660       Pragma_Link_With                     => -1,
14661       Pragma_Linker_Alias                  => -1,
14662       Pragma_Linker_Constructor            => -1,
14663       Pragma_Linker_Destructor             => -1,
14664       Pragma_Linker_Options                => -1,
14665       Pragma_Linker_Section                => -1,
14666       Pragma_List                          => -1,
14667       Pragma_Locking_Policy                => -1,
14668       Pragma_Long_Float                    => -1,
14669       Pragma_Machine_Attribute             => -1,
14670       Pragma_Main                          => -1,
14671       Pragma_Main_Storage                  => -1,
14672       Pragma_Memory_Size                   => -1,
14673       Pragma_No_Return                     =>  0,
14674       Pragma_No_Body                       =>  0,
14675       Pragma_No_Run_Time                   => -1,
14676       Pragma_No_Strict_Aliasing            => -1,
14677       Pragma_Normalize_Scalars             => -1,
14678       Pragma_Obsolescent                   =>  0,
14679       Pragma_Optimize                      => -1,
14680       Pragma_Optimize_Alignment            => -1,
14681       Pragma_Ordered                       =>  0,
14682       Pragma_Pack                          =>  0,
14683       Pragma_Page                          => -1,
14684       Pragma_Passive                       => -1,
14685       Pragma_Preelaborable_Initialization  => -1,
14686       Pragma_Polling                       => -1,
14687       Pragma_Persistent_BSS                =>  0,
14688       Pragma_Postcondition                 => -1,
14689       Pragma_Precondition                  => -1,
14690       Pragma_Predicate                     => -1,
14691       Pragma_Preelaborate                  => -1,
14692       Pragma_Preelaborate_05               => -1,
14693       Pragma_Priority                      => -1,
14694       Pragma_Priority_Specific_Dispatching => -1,
14695       Pragma_Profile                       =>  0,
14696       Pragma_Profile_Warnings              =>  0,
14697       Pragma_Propagate_Exceptions          => -1,
14698       Pragma_Psect_Object                  => -1,
14699       Pragma_Pure                          => -1,
14700       Pragma_Pure_05                       => -1,
14701       Pragma_Pure_Function                 => -1,
14702       Pragma_Queuing_Policy                => -1,
14703       Pragma_Ravenscar                     => -1,
14704       Pragma_Relative_Deadline             => -1,
14705       Pragma_Remote_Call_Interface         => -1,
14706       Pragma_Remote_Types                  => -1,
14707       Pragma_Restricted_Run_Time           => -1,
14708       Pragma_Restriction_Warnings          => -1,
14709       Pragma_Restrictions                  => -1,
14710       Pragma_Reviewable                    => -1,
14711       Pragma_Short_Circuit_And_Or          => -1,
14712       Pragma_Share_Generic                 => -1,
14713       Pragma_Shared                        => -1,
14714       Pragma_Shared_Passive                => -1,
14715       Pragma_Short_Descriptors             =>  0,
14716       Pragma_Source_File_Name              => -1,
14717       Pragma_Source_File_Name_Project      => -1,
14718       Pragma_Source_Reference              => -1,
14719       Pragma_Storage_Size                  => -1,
14720       Pragma_Storage_Unit                  => -1,
14721       Pragma_Static_Elaboration_Desired    => -1,
14722       Pragma_Stream_Convert                => -1,
14723       Pragma_Style_Checks                  => -1,
14724       Pragma_Subtitle                      => -1,
14725       Pragma_Suppress                      =>  0,
14726       Pragma_Suppress_Exception_Locations  =>  0,
14727       Pragma_Suppress_All                  => -1,
14728       Pragma_Suppress_Debug_Info           =>  0,
14729       Pragma_Suppress_Initialization       =>  0,
14730       Pragma_System_Name                   => -1,
14731       Pragma_Task_Dispatching_Policy       => -1,
14732       Pragma_Task_Info                     => -1,
14733       Pragma_Task_Name                     => -1,
14734       Pragma_Task_Storage                  =>  0,
14735       Pragma_Test_Case                     => -1,
14736       Pragma_Thread_Local_Storage          =>  0,
14737       Pragma_Time_Slice                    => -1,
14738       Pragma_Title                         => -1,
14739       Pragma_Unchecked_Union               =>  0,
14740       Pragma_Unimplemented_Unit            => -1,
14741       Pragma_Universal_Aliasing            => -1,
14742       Pragma_Universal_Data                => -1,
14743       Pragma_Unmodified                    => -1,
14744       Pragma_Unreferenced                  => -1,
14745       Pragma_Unreferenced_Objects          => -1,
14746       Pragma_Unreserve_All_Interrupts      => -1,
14747       Pragma_Unsuppress                    =>  0,
14748       Pragma_Use_VADS_Size                 => -1,
14749       Pragma_Validity_Checks               => -1,
14750       Pragma_Volatile                      =>  0,
14751       Pragma_Volatile_Components           =>  0,
14752       Pragma_Warnings                      => -1,
14753       Pragma_Weak_External                 => -1,
14754       Pragma_Wide_Character_Encoding       =>  0,
14755       Unknown_Pragma                       =>  0);
14756
14757    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14758       Id : Pragma_Id;
14759       P  : Node_Id;
14760       C  : Int;
14761       A  : Node_Id;
14762
14763    begin
14764       P := Parent (N);
14765
14766       if Nkind (P) /= N_Pragma_Argument_Association then
14767          return False;
14768
14769       else
14770          Id := Get_Pragma_Id (Parent (P));
14771          C := Sig_Flags (Id);
14772
14773          case C is
14774             when -1 =>
14775                return False;
14776
14777             when 0 =>
14778                return True;
14779
14780             when 99 =>
14781                case Id is
14782
14783                   --  For pragma Check, the first argument is not significant,
14784                   --  the second and the third (if present) arguments are
14785                   --  significant.
14786
14787                   when Pragma_Check =>
14788                      return
14789                        P = First (Pragma_Argument_Associations (Parent (P)));
14790
14791                   when others =>
14792                      raise Program_Error;
14793                end case;
14794
14795             when others =>
14796                A := First (Pragma_Argument_Associations (Parent (P)));
14797                for J in 1 .. C - 1 loop
14798                   if No (A) then
14799                      return False;
14800                   end if;
14801
14802                   Next (A);
14803                end loop;
14804
14805                return A = P; -- is this wrong way round ???
14806          end case;
14807       end if;
14808    end Is_Non_Significant_Pragma_Reference;
14809
14810    ------------------------------
14811    -- Is_Pragma_String_Literal --
14812    ------------------------------
14813
14814    --  This function returns true if the corresponding pragma argument is a
14815    --  static string expression. These are the only cases in which string
14816    --  literals can appear as pragma arguments. We also allow a string literal
14817    --  as the first argument to pragma Assert (although it will of course
14818    --  always generate a type error).
14819
14820    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14821       Pragn : constant Node_Id := Parent (Par);
14822       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14823       Pname : constant Name_Id := Pragma_Name (Pragn);
14824       Argn  : Natural;
14825       N     : Node_Id;
14826
14827    begin
14828       Argn := 1;
14829       N := First (Assoc);
14830       loop
14831          exit when N = Par;
14832          Argn := Argn + 1;
14833          Next (N);
14834       end loop;
14835
14836       if Pname = Name_Assert then
14837          return True;
14838
14839       elsif Pname = Name_Export then
14840          return Argn > 2;
14841
14842       elsif Pname = Name_Ident then
14843          return Argn = 1;
14844
14845       elsif Pname = Name_Import then
14846          return Argn > 2;
14847
14848       elsif Pname = Name_Interface_Name then
14849          return Argn > 1;
14850
14851       elsif Pname = Name_Linker_Alias then
14852          return Argn = 2;
14853
14854       elsif Pname = Name_Linker_Section then
14855          return Argn = 2;
14856
14857       elsif Pname = Name_Machine_Attribute then
14858          return Argn = 2;
14859
14860       elsif Pname = Name_Source_File_Name then
14861          return True;
14862
14863       elsif Pname = Name_Source_Reference then
14864          return Argn = 2;
14865
14866       elsif Pname = Name_Title then
14867          return True;
14868
14869       elsif Pname = Name_Subtitle then
14870          return True;
14871
14872       else
14873          return False;
14874       end if;
14875    end Is_Pragma_String_Literal;
14876
14877    ------------------------
14878    -- Preanalyze_TC_Args --
14879    ------------------------
14880
14881    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14882    begin
14883       --  Preanalyze the boolean expressions, we treat these as spec
14884       --  expressions (i.e. similar to a default expression).
14885
14886       if Present (Arg_Req) then
14887          Preanalyze_Spec_Expression
14888            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14889       end if;
14890
14891       if Present (Arg_Ens) then
14892          Preanalyze_Spec_Expression
14893            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14894       end if;
14895    end Preanalyze_TC_Args;
14896
14897    --------------------------------------
14898    -- Process_Compilation_Unit_Pragmas --
14899    --------------------------------------
14900
14901    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14902    begin
14903       --  A special check for pragma Suppress_All, a very strange DEC pragma,
14904       --  strange because it comes at the end of the unit. Rational has the
14905       --  same name for a pragma, but treats it as a program unit pragma, In
14906       --  GNAT we just decide to allow it anywhere at all. If it appeared then
14907       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
14908       --  node, and we insert a pragma Suppress (All_Checks) at the start of
14909       --  the context clause to ensure the correct processing.
14910
14911       if Has_Pragma_Suppress_All (N) then
14912          Prepend_To (Context_Items (N),
14913            Make_Pragma (Sloc (N),
14914              Chars                        => Name_Suppress,
14915              Pragma_Argument_Associations => New_List (
14916                Make_Pragma_Argument_Association (Sloc (N),
14917                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14918       end if;
14919
14920       --  Nothing else to do at the current time!
14921
14922    end Process_Compilation_Unit_Pragmas;
14923
14924    --------
14925    -- rv --
14926    --------
14927
14928    procedure rv is
14929    begin
14930       null;
14931    end rv;
14932
14933    --------------------------------
14934    -- Set_Encoded_Interface_Name --
14935    --------------------------------
14936
14937    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14938       Str : constant String_Id := Strval (S);
14939       Len : constant Int       := String_Length (Str);
14940       CC  : Char_Code;
14941       C   : Character;
14942       J   : Int;
14943
14944       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14945
14946       procedure Encode;
14947       --  Stores encoded value of character code CC. The encoding we use an
14948       --  underscore followed by four lower case hex digits.
14949
14950       ------------
14951       -- Encode --
14952       ------------
14953
14954       procedure Encode is
14955       begin
14956          Store_String_Char (Get_Char_Code ('_'));
14957          Store_String_Char
14958            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14959          Store_String_Char
14960            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14961          Store_String_Char
14962            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14963          Store_String_Char
14964            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14965       end Encode;
14966
14967    --  Start of processing for Set_Encoded_Interface_Name
14968
14969    begin
14970       --  If first character is asterisk, this is a link name, and we leave it
14971       --  completely unmodified. We also ignore null strings (the latter case
14972       --  happens only in error cases) and no encoding should occur for Java or
14973       --  AAMP interface names.
14974
14975       if Len = 0
14976         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14977         or else VM_Target /= No_VM
14978         or else AAMP_On_Target
14979       then
14980          Set_Interface_Name (E, S);
14981
14982       else
14983          J := 1;
14984          loop
14985             CC := Get_String_Char (Str, J);
14986
14987             exit when not In_Character_Range (CC);
14988
14989             C := Get_Character (CC);
14990
14991             exit when C /= '_' and then C /= '$'
14992               and then C not in '0' .. '9'
14993               and then C not in 'a' .. 'z'
14994               and then C not in 'A' .. 'Z';
14995
14996             if J = Len then
14997                Set_Interface_Name (E, S);
14998                return;
14999
15000             else
15001                J := J + 1;
15002             end if;
15003          end loop;
15004
15005          --  Here we need to encode. The encoding we use as follows:
15006          --     three underscores  + four hex digits (lower case)
15007
15008          Start_String;
15009
15010          for J in 1 .. String_Length (Str) loop
15011             CC := Get_String_Char (Str, J);
15012
15013             if not In_Character_Range (CC) then
15014                Encode;
15015             else
15016                C := Get_Character (CC);
15017
15018                if C = '_' or else C = '$'
15019                  or else C in '0' .. '9'
15020                  or else C in 'a' .. 'z'
15021                  or else C in 'A' .. 'Z'
15022                then
15023                   Store_String_Char (CC);
15024                else
15025                   Encode;
15026                end if;
15027             end if;
15028          end loop;
15029
15030          Set_Interface_Name (E,
15031            Make_String_Literal (Sloc (S),
15032              Strval => End_String));
15033       end if;
15034    end Set_Encoded_Interface_Name;
15035
15036    -------------------
15037    -- Set_Unit_Name --
15038    -------------------
15039
15040    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15041       Pref : Node_Id;
15042       Scop : Entity_Id;
15043
15044    begin
15045       if Nkind (N) = N_Identifier
15046         and then Nkind (With_Item) = N_Identifier
15047       then
15048          Set_Entity (N, Entity (With_Item));
15049
15050       elsif Nkind (N) = N_Selected_Component then
15051          Change_Selected_Component_To_Expanded_Name (N);
15052          Set_Entity (N, Entity (With_Item));
15053          Set_Entity (Selector_Name (N), Entity (N));
15054
15055          Pref := Prefix (N);
15056          Scop := Scope (Entity (N));
15057          while Nkind (Pref) = N_Selected_Component loop
15058             Change_Selected_Component_To_Expanded_Name (Pref);
15059             Set_Entity (Selector_Name (Pref), Scop);
15060             Set_Entity (Pref, Scop);
15061             Pref := Prefix (Pref);
15062             Scop := Scope (Scop);
15063          end loop;
15064
15065          Set_Entity (Pref, Scop);
15066       end if;
15067    end Set_Unit_Name;
15068
15069 end Sem_Prag;