OSDN Git Service

2011-09-02 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ P R A G                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with 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       --  For a class-wide condition, a reference to a controlling formal must
266       --  be interpreted as having the class-wide type (or an access to such)
267       --  so that the inherited condition can be properly applied to any
268       --  overriding operation (see ARM12 6.6.1 (7)).
269
270       if Class_Present (N) then
271          declare
272             T   : constant Entity_Id := Find_Dispatching_Type (S);
273
274             ACW : Entity_Id := Empty;
275             --  Access to T'class, created if there is a controlling formal
276             --  that is an access parameter.
277
278             function Get_ACW return Entity_Id;
279             --  If the expression has a reference to an controlling access
280             --  parameter, create an access to T'class for the necessary
281             --  conversions if one does not exist.
282
283             function Process (N : Node_Id) return Traverse_Result;
284             --  ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
285             --  aspect for a primitive subprogram of a tagged type T, a name
286             --  that denotes a formal parameter of type T is interpreted as
287             --  having type T'Class. Similarly, a name that denotes a formal
288             --  accessparameter of type access-to-T is interpreted as having
289             --  type access-to-T'Class. This ensures the expression is well-
290             --  defined for a primitive subprogram of a type descended from T.
291
292             -------------
293             -- Get_ACW --
294             -------------
295
296             function Get_ACW return Entity_Id is
297                Loc  : constant Source_Ptr := Sloc (N);
298                Decl : Node_Id;
299
300             begin
301                if No (ACW) then
302                   Decl := Make_Full_Type_Declaration (Loc,
303                     Defining_Identifier => Make_Temporary (Loc, 'T'),
304                     Type_Definition =>
305                        Make_Access_To_Object_Definition (Loc,
306                        Subtype_Indication =>
307                          New_Occurrence_Of (Class_Wide_Type (T), Loc),
308                        All_Present => True));
309
310                   Insert_Before (Unit_Declaration_Node (S), Decl);
311                   Analyze (Decl);
312                   ACW := Defining_Identifier (Decl);
313                   Freeze_Before (Unit_Declaration_Node (S), ACW);
314                end if;
315
316                return ACW;
317             end Get_ACW;
318
319             -------------
320             -- Process --
321             -------------
322
323             function Process (N : Node_Id) return Traverse_Result is
324                Loc : constant Source_Ptr := Sloc (N);
325                Typ : Entity_Id;
326
327             begin
328                if Is_Entity_Name (N)
329                  and then Is_Formal (Entity (N))
330                  and then Nkind (Parent (N)) /= N_Type_Conversion
331                then
332                   if Etype (Entity (N)) = T then
333                      Typ := Class_Wide_Type (T);
334
335                   elsif Is_Access_Type (Etype (Entity (N)))
336                     and then Designated_Type (Etype (Entity (N))) = T
337                   then
338                      Typ := Get_ACW;
339                   else
340                      Typ := Empty;
341                   end if;
342
343                   if Present (Typ) then
344                      Rewrite (N,
345                        Make_Type_Conversion (Loc,
346                          Subtype_Mark =>
347                            New_Occurrence_Of (Typ, Loc),
348                          Expression  => New_Occurrence_Of (Entity (N), Loc)));
349                      Set_Etype (N, Typ);
350                   end if;
351                end if;
352
353                return OK;
354             end Process;
355
356             procedure Replace_Type is new Traverse_Proc (Process);
357
358          begin
359             Replace_Type (Get_Pragma_Arg (Arg1));
360          end;
361       end if;
362
363       --  Remove the subprogram from the scope stack now that the pre-analysis
364       --  of the precondition/postcondition is done.
365
366       End_Scope;
367    end Analyze_PPC_In_Decl_Part;
368
369    --------------------
370    -- Analyze_Pragma --
371    --------------------
372
373    procedure Analyze_Pragma (N : Node_Id) is
374       Loc     : constant Source_Ptr := Sloc (N);
375       Pname   : constant Name_Id    := Pragma_Name (N);
376       Prag_Id : Pragma_Id;
377
378       Pragma_Exit : exception;
379       --  This exception is used to exit pragma processing completely. It is
380       --  used when an error is detected, and no further processing is
381       --  required. It is also used if an earlier error has left the tree in
382       --  a state where the pragma should not be processed.
383
384       Arg_Count : Nat;
385       --  Number of pragma argument associations
386
387       Arg1 : Node_Id;
388       Arg2 : Node_Id;
389       Arg3 : Node_Id;
390       Arg4 : Node_Id;
391       --  First four pragma arguments (pragma argument association nodes, or
392       --  Empty if the corresponding argument does not exist).
393
394       type Name_List is array (Natural range <>) of Name_Id;
395       type Args_List is array (Natural range <>) of Node_Id;
396       --  Types used for arguments to Check_Arg_Order and Gather_Associations
397
398       procedure Ada_2005_Pragma;
399       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
400       --  Ada 95 mode, these are implementation defined pragmas, so should be
401       --  caught by the No_Implementation_Pragmas restriction.
402
403       procedure Ada_2012_Pragma;
404       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
405       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
406       --  should be caught by the No_Implementation_Pragmas restriction.
407
408       procedure Check_Ada_83_Warning;
409       --  Issues a warning message for the current pragma if operating in Ada
410       --  83 mode (used for language pragmas that are not a standard part of
411       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
412       --  of 95 pragma.
413
414       procedure Check_Arg_Count (Required : Nat);
415       --  Check argument count for pragma is equal to given parameter. If not,
416       --  then issue an error message and raise Pragma_Exit.
417
418       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
419       --  Arg which can either be a pragma argument association, in which case
420       --  the check is applied to the expression of the association or an
421       --  expression directly.
422
423       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
424       --  Check that an argument has the right form for an EXTERNAL_NAME
425       --  parameter of an extended import/export pragma. The rule is that the
426       --  name must be an identifier or string literal (in Ada 83 mode) or a
427       --  static string expression (in Ada 95 mode).
428
429       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
430       --  Check the specified argument Arg to make sure that it is an
431       --  identifier. If not give error and raise Pragma_Exit.
432
433       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
434       --  Check the specified argument Arg to make sure that it is an integer
435       --  literal. If not give error and raise Pragma_Exit.
436
437       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
438       --  Check the specified argument Arg to make sure that it has the proper
439       --  syntactic form for a local name and meets the semantic requirements
440       --  for a local name. The local name is analyzed as part of the
441       --  processing for this call. In addition, the local name is required
442       --  to represent an entity at the library level.
443
444       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
445       --  Check the specified argument Arg to make sure that it has the proper
446       --  syntactic form for a local name and meets the semantic requirements
447       --  for a local name. The local name is analyzed as part of the
448       --  processing for this call.
449
450       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
451       --  Check the specified argument Arg to make sure that it is a valid
452       --  locking policy name. If not give error and raise Pragma_Exit.
453
454       procedure Check_Arg_Is_One_Of
455         (Arg                : Node_Id;
456          N1, N2             : Name_Id);
457       procedure Check_Arg_Is_One_Of
458         (Arg                : Node_Id;
459          N1, N2, N3         : Name_Id);
460       procedure Check_Arg_Is_One_Of
461         (Arg                : Node_Id;
462          N1, N2, N3, N4, N5 : Name_Id);
463       --  Check the specified argument Arg to make sure that it is an
464       --  identifier whose name matches either N1 or N2 (or N3, N4, N5 if
465       --  present). If not then give error and raise Pragma_Exit.
466
467       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
468       --  Check the specified argument Arg to make sure that it is a valid
469       --  queuing policy name. If not give error and raise Pragma_Exit.
470
471       procedure Check_Arg_Is_Static_Expression
472         (Arg : Node_Id;
473          Typ : Entity_Id := Empty);
474       --  Check the specified argument Arg to make sure that it is a static
475       --  expression of the given type (i.e. it will be analyzed and resolved
476       --  using this type, which can be any valid argument to Resolve, e.g.
477       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
478       --  Typ is left Empty, then any static expression is allowed.
479
480       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
481       --  Check the specified argument Arg to make sure that it is a valid task
482       --  dispatching policy name. If not give error and raise Pragma_Exit.
483
484       procedure Check_Arg_Order (Names : Name_List);
485       --  Checks for an instance of two arguments with identifiers for the
486       --  current pragma which are not in the sequence indicated by Names,
487       --  and if so, generates a fatal message about bad order of arguments.
488
489       procedure Check_At_Least_N_Arguments (N : Nat);
490       --  Check there are at least N arguments present
491
492       procedure Check_At_Most_N_Arguments (N : Nat);
493       --  Check there are no more than N arguments present
494
495       procedure Check_Component
496         (Comp            : Node_Id;
497          UU_Typ          : Entity_Id;
498          In_Variant_Part : Boolean := False);
499       --  Examine an Unchecked_Union component for correct use of per-object
500       --  constrained subtypes, and for restrictions on finalizable components.
501       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
502       --  should be set when Comp comes from a record variant.
503
504       procedure Check_Duplicate_Pragma (E : Entity_Id);
505       --  Check if a pragma of the same name as the current pragma is already
506       --  chained as a rep pragma to the given entity. If so give a message
507       --  about the duplicate, and then raise Pragma_Exit so does not return.
508       --  Also checks for delayed aspect specification node in the chain.
509
510       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
511       --  Nam is an N_String_Literal node containing the external name set by
512       --  an Import or Export pragma (or extended Import or Export pragma).
513       --  This procedure checks for possible duplications if this is the export
514       --  case, and if found, issues an appropriate error message.
515
516       procedure Check_First_Subtype (Arg : Node_Id);
517       --  Checks that Arg, whose expression is an entity name, references a
518       --  first subtype.
519
520       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
521       --  Checks that the given argument has an identifier, and if so, requires
522       --  it to match the given identifier name. If there is no identifier, or
523       --  a non-matching identifier, then an error message is given and
524       --  Pragma_Exit is raised.
525
526       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
527       --  Checks that the given argument has an identifier, and if so, requires
528       --  it to match one of the given identifier names. If there is no
529       --  identifier, or a non-matching identifier, then an error message is
530       --  given and Pragma_Exit is raised.
531
532       procedure Check_In_Main_Program;
533       --  Common checks for pragmas that appear within a main program
534       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
535
536       procedure Check_Interrupt_Or_Attach_Handler;
537       --  Common processing for first argument of pragma Interrupt_Handler or
538       --  pragma Attach_Handler.
539
540       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
541       --  Check that pragma appears in a declarative part, or in a package
542       --  specification, i.e. that it does not occur in a statement sequence
543       --  in a body.
544
545       procedure Check_No_Identifier (Arg : Node_Id);
546       --  Checks that the given argument does not have an identifier. If
547       --  an identifier is present, then an error message is issued, and
548       --  Pragma_Exit is raised.
549
550       procedure Check_No_Identifiers;
551       --  Checks that none of the arguments to the pragma has an identifier.
552       --  If any argument has an identifier, then an error message is issued,
553       --  and Pragma_Exit is raised.
554
555       procedure Check_No_Link_Name;
556       --  Checks that no link name is specified
557
558       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
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
563       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
564       --  Checks if the given argument has an identifier, and if so, requires
565       --  it to match the given identifier name. If there is a non-matching
566       --  identifier, then an error message is given and Pragma_Exit is raised.
567       --  In this version of the procedure, the identifier name is given as
568       --  a string with lower case letters.
569
570       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
571       --  Called to process a precondition or postcondition pragma. There are
572       --  three cases:
573       --
574       --    The pragma appears after a subprogram spec
575       --
576       --      If the corresponding check is not enabled, the pragma is analyzed
577       --      but otherwise ignored and control returns with In_Body set False.
578       --
579       --      If the check is enabled, then the first step is to analyze the
580       --      pragma, but this is skipped if the subprogram spec appears within
581       --      a package specification (because this is the case where we delay
582       --      analysis till the end of the spec). Then (whether or not it was
583       --      analyzed), the pragma is chained to the subprogram in question
584       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
585       --      caller with In_Body set False.
586       --
587       --    The pragma appears at the start of subprogram body declarations
588       --
589       --      In this case an immediate return to the caller is made with
590       --      In_Body set True, and the pragma is NOT analyzed.
591       --
592       --    In all other cases, an error message for bad placement is given
593
594       procedure Check_Static_Constraint (Constr : Node_Id);
595       --  Constr is a constraint from an N_Subtype_Indication node from a
596       --  component constraint in an Unchecked_Union type. This routine checks
597       --  that the constraint is static as required by the restrictions for
598       --  Unchecked_Union.
599
600       procedure Check_Test_Case;
601       --  Called to process a test-case pragma. The treatment is similar to the
602       --  one for pre- and postcondition in Check_Precondition_Postcondition,
603       --  except the placement rules for the test-case pragma are stricter.
604       --  This pragma may only occur after a subprogram spec declared directly
605       --  in a package spec unit. In this case, the pragma is chained to the
606       --  subprogram in question (using Spec_TC_List and Next_Pragma) and
607       --  analysis of the pragma is delayed till the end of the spec. In
608       --  all other cases, an error message for bad placement is given.
609
610       procedure Check_Valid_Configuration_Pragma;
611       --  Legality checks for placement of a configuration pragma
612
613       procedure Check_Valid_Library_Unit_Pragma;
614       --  Legality checks for library unit pragmas. A special case arises for
615       --  pragmas in generic instances that come from copies of the original
616       --  library unit pragmas in the generic templates. In the case of other
617       --  than library level instantiations these can appear in contexts which
618       --  would normally be invalid (they only apply to the original template
619       --  and to library level instantiations), and they are simply ignored,
620       --  which is implemented by rewriting them as null statements.
621
622       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
623       --  Check an Unchecked_Union variant for lack of nested variants and
624       --  presence of at least one component. UU_Typ is the related Unchecked_
625       --  Union type.
626
627       procedure Error_Pragma (Msg : String);
628       pragma No_Return (Error_Pragma);
629       --  Outputs error message for current pragma. The message contains a %
630       --  that will be replaced with the pragma name, and the flag is placed
631       --  on the pragma itself. Pragma_Exit is then raised.
632
633       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
634       pragma No_Return (Error_Pragma_Arg);
635       --  Outputs error message for current pragma. The message may contain
636       --  a % that will be replaced with the pragma name. The parameter Arg
637       --  may either be a pragma argument association, in which case the flag
638       --  is placed on the expression of this association, or an expression,
639       --  in which case the flag is placed directly on the expression. The
640       --  message is placed using Error_Msg_N, so the message may also contain
641       --  an & insertion character which will reference the given Arg value.
642       --  After placing the message, Pragma_Exit is raised.
643
644       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
645       pragma No_Return (Error_Pragma_Arg);
646       --  Similar to above form of Error_Pragma_Arg except that two messages
647       --  are provided, the second is a continuation comment starting with \.
648
649       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
650       pragma No_Return (Error_Pragma_Arg_Ident);
651       --  Outputs error message for current pragma. The message may contain
652       --  a % that will be replaced with the pragma name. The parameter Arg
653       --  must be a pragma argument association with a non-empty identifier
654       --  (i.e. its Chars field must be set), and the error message is placed
655       --  on the identifier. The message is placed using Error_Msg_N so
656       --  the message may also contain an & insertion character which will
657       --  reference the identifier. After placing the message, Pragma_Exit
658       --  is raised.
659
660       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
661       pragma No_Return (Error_Pragma_Ref);
662       --  Outputs error message for current pragma. The message may contain
663       --  a % that will be replaced with the pragma name. The parameter Ref
664       --  must be an entity whose name can be referenced by & and sloc by #.
665       --  After placing the message, Pragma_Exit is raised.
666
667       function Find_Lib_Unit_Name return Entity_Id;
668       --  Used for a library unit pragma to find the entity to which the
669       --  library unit pragma applies, returns the entity found.
670
671       procedure Find_Program_Unit_Name (Id : Node_Id);
672       --  If the pragma is a compilation unit pragma, the id must denote the
673       --  compilation unit in the same compilation, and the pragma must appear
674       --  in the list of preceding or trailing pragmas. If it is a program
675       --  unit pragma that is not a compilation unit pragma, then the
676       --  identifier must be visible.
677
678       function Find_Unique_Parameterless_Procedure
679         (Name : Entity_Id;
680          Arg  : Node_Id) return Entity_Id;
681       --  Used for a procedure pragma to find the unique parameterless
682       --  procedure identified by Name, returns it if it exists, otherwise
683       --  errors out and uses Arg as the pragma argument for the message.
684
685       procedure Fix_Error (Msg : in out String);
686       --  This is called prior to issuing an error message. Msg is a string
687       --  which typically contains the substring pragma. If the current pragma
688       --  comes from an aspect, each such "pragma" substring is replaced with
689       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
690       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
691
692       procedure Gather_Associations
693         (Names : Name_List;
694          Args  : out Args_List);
695       --  This procedure is used to gather the arguments for a pragma that
696       --  permits arbitrary ordering of parameters using the normal rules
697       --  for named and positional parameters. The Names argument is a list
698       --  of Name_Id values that corresponds to the allowed pragma argument
699       --  association identifiers in order. The result returned in Args is
700       --  a list of corresponding expressions that are the pragma arguments.
701       --  Note that this is a list of expressions, not of pragma argument
702       --  associations (Gather_Associations has completely checked all the
703       --  optional identifiers when it returns). An entry in Args is Empty
704       --  on return if the corresponding argument is not present.
705
706       procedure GNAT_Pragma;
707       --  Called for all GNAT defined pragmas to check the relevant restriction
708       --  (No_Implementation_Pragmas).
709
710       function Is_Before_First_Decl
711         (Pragma_Node : Node_Id;
712          Decls       : List_Id) return Boolean;
713       --  Return True if Pragma_Node is before the first declarative item in
714       --  Decls where Decls is the list of declarative items.
715
716       function Is_Configuration_Pragma return Boolean;
717       --  Determines if the placement of the current pragma is appropriate
718       --  for a configuration pragma.
719
720       function Is_In_Context_Clause return Boolean;
721       --  Returns True if pragma appears within the context clause of a unit,
722       --  and False for any other placement (does not generate any messages).
723
724       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
725       --  Analyzes the argument, and determines if it is a static string
726       --  expression, returns True if so, False if non-static or not String.
727
728       procedure Pragma_Misplaced;
729       pragma No_Return (Pragma_Misplaced);
730       --  Issue fatal error message for misplaced pragma
731
732       procedure Process_Atomic_Shared_Volatile;
733       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
734       --  Shared is an obsolete Ada 83 pragma, treated as being identical
735       --  in effect to pragma Atomic.
736
737       procedure Process_Compile_Time_Warning_Or_Error;
738       --  Common processing for Compile_Time_Error and Compile_Time_Warning
739
740       procedure Process_Convention
741         (C   : out Convention_Id;
742          Ent : out Entity_Id);
743       --  Common processing for Convention, Interface, Import and Export.
744       --  Checks first two arguments of pragma, and sets the appropriate
745       --  convention value in the specified entity or entities. On return
746       --  C is the convention, Ent is the referenced entity.
747
748       procedure Process_Extended_Import_Export_Exception_Pragma
749         (Arg_Internal : Node_Id;
750          Arg_External : Node_Id;
751          Arg_Form     : Node_Id;
752          Arg_Code     : Node_Id);
753       --  Common processing for the pragmas Import/Export_Exception. The three
754       --  arguments correspond to the three named parameters of the pragma. An
755       --  argument is empty if the corresponding parameter is not present in
756       --  the pragma.
757
758       procedure Process_Extended_Import_Export_Object_Pragma
759         (Arg_Internal : Node_Id;
760          Arg_External : Node_Id;
761          Arg_Size     : Node_Id);
762       --  Common processing for the pragmas Import/Export_Object. The three
763       --  arguments correspond to the three named parameters of the pragmas. An
764       --  argument is empty if the corresponding parameter is not present in
765       --  the pragma.
766
767       procedure Process_Extended_Import_Export_Internal_Arg
768         (Arg_Internal : Node_Id := Empty);
769       --  Common processing for all extended Import and Export pragmas. The
770       --  argument is the pragma parameter for the Internal argument. If
771       --  Arg_Internal is empty or inappropriate, an error message is posted.
772       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
773       --  set to identify the referenced entity.
774
775       procedure Process_Extended_Import_Export_Subprogram_Pragma
776         (Arg_Internal                 : Node_Id;
777          Arg_External                 : Node_Id;
778          Arg_Parameter_Types          : Node_Id;
779          Arg_Result_Type              : Node_Id := Empty;
780          Arg_Mechanism                : Node_Id;
781          Arg_Result_Mechanism         : Node_Id := Empty;
782          Arg_First_Optional_Parameter : Node_Id := Empty);
783       --  Common processing for all extended Import and Export pragmas applying
784       --  to subprograms. The caller omits any arguments that do not apply to
785       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
786       --  only in the Import_Function and Export_Function cases). The argument
787       --  names correspond to the allowed pragma association identifiers.
788
789       procedure Process_Generic_List;
790       --  Common processing for Share_Generic and Inline_Generic
791
792       procedure Process_Import_Or_Interface;
793       --  Common processing for Import of Interface
794
795       procedure Process_Import_Predefined_Type;
796       --  Processing for completing a type with pragma Import. This is used
797       --  to declare types that match predefined C types, especially for cases
798       --  without corresponding Ada predefined type.
799
800       procedure Process_Inline (Active : Boolean);
801       --  Common processing for Inline and Inline_Always. The parameter
802       --  indicates if the inline pragma is active, i.e. if it should actually
803       --  cause inlining to occur.
804
805       procedure Process_Interface_Name
806         (Subprogram_Def : Entity_Id;
807          Ext_Arg        : Node_Id;
808          Link_Arg       : Node_Id);
809       --  Given the last two arguments of pragma Import, pragma Export, or
810       --  pragma Interface_Name, performs validity checks and sets the
811       --  Interface_Name field of the given subprogram entity to the
812       --  appropriate external or link name, depending on the arguments given.
813       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
814       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
815       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
816       --  nor Link_Arg is present, the interface name is set to the default
817       --  from the subprogram name.
818
819       procedure Process_Interrupt_Or_Attach_Handler;
820       --  Common processing for Interrupt and Attach_Handler pragmas
821
822       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
823       --  Common processing for Restrictions and Restriction_Warnings pragmas.
824       --  Warn is True for Restriction_Warnings, or for Restrictions if the
825       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
826       --  is not set in the Restrictions case.
827
828       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
829       --  Common processing for Suppress and Unsuppress. The boolean parameter
830       --  Suppress_Case is True for the Suppress case, and False for the
831       --  Unsuppress case.
832
833       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
834       --  This procedure sets the Is_Exported flag for the given entity,
835       --  checking that the entity was not previously imported. Arg is
836       --  the argument that specified the entity. A check is also made
837       --  for exporting inappropriate entities.
838
839       procedure Set_Extended_Import_Export_External_Name
840         (Internal_Ent : Entity_Id;
841          Arg_External : Node_Id);
842       --  Common processing for all extended import export pragmas. The first
843       --  argument, Internal_Ent, is the internal entity, which has already
844       --  been checked for validity by the caller. Arg_External is from the
845       --  Import or Export pragma, and may be null if no External parameter
846       --  was present. If Arg_External is present and is a non-null string
847       --  (a null string is treated as the default), then the Interface_Name
848       --  field of Internal_Ent is set appropriately.
849
850       procedure Set_Imported (E : Entity_Id);
851       --  This procedure sets the Is_Imported flag for the given entity,
852       --  checking that it is not previously exported or imported.
853
854       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
855       --  Mech is a parameter passing mechanism (see Import_Function syntax
856       --  for MECHANISM_NAME). This routine checks that the mechanism argument
857       --  has the right form, and if not issues an error message. If the
858       --  argument has the right form then the Mechanism field of Ent is
859       --  set appropriately.
860
861       procedure Set_Ravenscar_Profile (N : Node_Id);
862       --  Activate the set of configuration pragmas and restrictions that make
863       --  up the Ravenscar Profile. N is the corresponding pragma node, which
864       --  is used for error messages on any constructs that violate the
865       --  profile.
866
867       ---------------------
868       -- Ada_2005_Pragma --
869       ---------------------
870
871       procedure Ada_2005_Pragma is
872       begin
873          if Ada_Version <= Ada_95 then
874             Check_Restriction (No_Implementation_Pragmas, N);
875          end if;
876       end Ada_2005_Pragma;
877
878       ---------------------
879       -- Ada_2012_Pragma --
880       ---------------------
881
882       procedure Ada_2012_Pragma is
883       begin
884          if Ada_Version <= Ada_2005 then
885             Check_Restriction (No_Implementation_Pragmas, N);
886          end if;
887       end Ada_2012_Pragma;
888
889       --------------------------
890       -- Check_Ada_83_Warning --
891       --------------------------
892
893       procedure Check_Ada_83_Warning is
894       begin
895          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
896             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
897          end if;
898       end Check_Ada_83_Warning;
899
900       ---------------------
901       -- Check_Arg_Count --
902       ---------------------
903
904       procedure Check_Arg_Count (Required : Nat) is
905       begin
906          if Arg_Count /= Required then
907             Error_Pragma ("wrong number of arguments for pragma%");
908          end if;
909       end Check_Arg_Count;
910
911       --------------------------------
912       -- Check_Arg_Is_External_Name --
913       --------------------------------
914
915       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
916          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
917
918       begin
919          if Nkind (Argx) = N_Identifier then
920             return;
921
922          else
923             Analyze_And_Resolve (Argx, Standard_String);
924
925             if Is_OK_Static_Expression (Argx) then
926                return;
927
928             elsif Etype (Argx) = Any_Type then
929                raise Pragma_Exit;
930
931             --  An interesting special case, if we have a string literal and
932             --  we are in Ada 83 mode, then we allow it even though it will
933             --  not be flagged as static. This allows expected Ada 83 mode
934             --  use of external names which are string literals, even though
935             --  technically these are not static in Ada 83.
936
937             elsif Ada_Version = Ada_83
938               and then Nkind (Argx) = N_String_Literal
939             then
940                return;
941
942             --  Static expression that raises Constraint_Error. This has
943             --  already been flagged, so just exit from pragma processing.
944
945             elsif Is_Static_Expression (Argx) then
946                raise Pragma_Exit;
947
948             --  Here we have a real error (non-static expression)
949
950             else
951                Error_Msg_Name_1 := Pname;
952
953                declare
954                   Msg : String :=
955                           "argument for pragma% must be a identifier or "
956                           & "static string expression!";
957                begin
958                   Fix_Error (Msg);
959                   Flag_Non_Static_Expr (Msg, Argx);
960                   raise Pragma_Exit;
961                end;
962             end if;
963          end if;
964       end Check_Arg_Is_External_Name;
965
966       -----------------------------
967       -- Check_Arg_Is_Identifier --
968       -----------------------------
969
970       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
971          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
972       begin
973          if Nkind (Argx) /= N_Identifier then
974             Error_Pragma_Arg
975               ("argument for pragma% must be identifier", Argx);
976          end if;
977       end Check_Arg_Is_Identifier;
978
979       ----------------------------------
980       -- Check_Arg_Is_Integer_Literal --
981       ----------------------------------
982
983       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
984          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
985       begin
986          if Nkind (Argx) /= N_Integer_Literal then
987             Error_Pragma_Arg
988               ("argument for pragma% must be integer literal", Argx);
989          end if;
990       end Check_Arg_Is_Integer_Literal;
991
992       -------------------------------------------
993       -- Check_Arg_Is_Library_Level_Local_Name --
994       -------------------------------------------
995
996       --  LOCAL_NAME ::=
997       --    DIRECT_NAME
998       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
999       --  | library_unit_NAME
1000
1001       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1002       begin
1003          Check_Arg_Is_Local_Name (Arg);
1004
1005          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1006            and then Comes_From_Source (N)
1007          then
1008             Error_Pragma_Arg
1009               ("argument for pragma% must be library level entity", Arg);
1010          end if;
1011       end Check_Arg_Is_Library_Level_Local_Name;
1012
1013       -----------------------------
1014       -- Check_Arg_Is_Local_Name --
1015       -----------------------------
1016
1017       --  LOCAL_NAME ::=
1018       --    DIRECT_NAME
1019       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1020       --  | library_unit_NAME
1021
1022       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1023          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1024
1025       begin
1026          Analyze (Argx);
1027
1028          if Nkind (Argx) not in N_Direct_Name
1029            and then (Nkind (Argx) /= N_Attribute_Reference
1030                       or else Present (Expressions (Argx))
1031                       or else Nkind (Prefix (Argx)) /= N_Identifier)
1032            and then (not Is_Entity_Name (Argx)
1033                       or else not Is_Compilation_Unit (Entity (Argx)))
1034          then
1035             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1036          end if;
1037
1038          --  No further check required if not an entity name
1039
1040          if not Is_Entity_Name (Argx) then
1041             null;
1042
1043          else
1044             declare
1045                OK   : Boolean;
1046                Ent  : constant Entity_Id := Entity (Argx);
1047                Scop : constant Entity_Id := Scope (Ent);
1048             begin
1049                --  Case of a pragma applied to a compilation unit: pragma must
1050                --  occur immediately after the program unit in the compilation.
1051
1052                if Is_Compilation_Unit (Ent) then
1053                   declare
1054                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1055                   begin
1056                      --  Case of pragma placed immediately after spec
1057
1058                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1059                         OK := True;
1060
1061                      --  Case of pragma placed immediately after body
1062
1063                      elsif Nkind (Decl) = N_Subprogram_Declaration
1064                              and then Present (Corresponding_Body (Decl))
1065                      then
1066                         OK := Parent (N) =
1067                                 Aux_Decls_Node
1068                                   (Parent (Unit_Declaration_Node
1069                                              (Corresponding_Body (Decl))));
1070
1071                      --  All other cases are illegal
1072
1073                      else
1074                         OK := False;
1075                      end if;
1076                   end;
1077
1078                --  Special restricted placement rule from 10.2.1(11.8/2)
1079
1080                elsif Is_Generic_Formal (Ent)
1081                        and then Prag_Id = Pragma_Preelaborable_Initialization
1082                then
1083                   OK := List_Containing (N) =
1084                           Generic_Formal_Declarations
1085                             (Unit_Declaration_Node (Scop));
1086
1087                --  Default case, just check that the pragma occurs in the scope
1088                --  of the entity denoted by the name.
1089
1090                else
1091                   OK := Current_Scope = Scop;
1092                end if;
1093
1094                if not OK then
1095                   Error_Pragma_Arg
1096                     ("pragma% argument must be in same declarative part", Arg);
1097                end if;
1098             end;
1099          end if;
1100       end Check_Arg_Is_Local_Name;
1101
1102       ---------------------------------
1103       -- Check_Arg_Is_Locking_Policy --
1104       ---------------------------------
1105
1106       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1107          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1108
1109       begin
1110          Check_Arg_Is_Identifier (Argx);
1111
1112          if not Is_Locking_Policy_Name (Chars (Argx)) then
1113             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1114          end if;
1115       end Check_Arg_Is_Locking_Policy;
1116
1117       -------------------------
1118       -- Check_Arg_Is_One_Of --
1119       -------------------------
1120
1121       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1122          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1123
1124       begin
1125          Check_Arg_Is_Identifier (Argx);
1126
1127          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1128             Error_Msg_Name_2 := N1;
1129             Error_Msg_Name_3 := N2;
1130             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1131          end if;
1132       end Check_Arg_Is_One_Of;
1133
1134       procedure Check_Arg_Is_One_Of
1135         (Arg        : Node_Id;
1136          N1, N2, N3 : Name_Id)
1137       is
1138          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1139
1140       begin
1141          Check_Arg_Is_Identifier (Argx);
1142
1143          if Chars (Argx) /= N1
1144            and then Chars (Argx) /= N2
1145            and then Chars (Argx) /= N3
1146          then
1147             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1148          end if;
1149       end Check_Arg_Is_One_Of;
1150
1151       procedure Check_Arg_Is_One_Of
1152         (Arg                : Node_Id;
1153          N1, N2, N3, N4, N5 : Name_Id)
1154       is
1155          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1156
1157       begin
1158          Check_Arg_Is_Identifier (Argx);
1159
1160          if Chars (Argx) /= N1
1161            and then Chars (Argx) /= N2
1162            and then Chars (Argx) /= N3
1163            and then Chars (Argx) /= N4
1164            and then Chars (Argx) /= N5
1165          then
1166             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1167          end if;
1168       end Check_Arg_Is_One_Of;
1169       ---------------------------------
1170       -- Check_Arg_Is_Queuing_Policy --
1171       ---------------------------------
1172
1173       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1174          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1175
1176       begin
1177          Check_Arg_Is_Identifier (Argx);
1178
1179          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1180             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1181          end if;
1182       end Check_Arg_Is_Queuing_Policy;
1183
1184       ------------------------------------
1185       -- Check_Arg_Is_Static_Expression --
1186       ------------------------------------
1187
1188       procedure Check_Arg_Is_Static_Expression
1189         (Arg : Node_Id;
1190          Typ : Entity_Id := Empty)
1191       is
1192          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1193
1194       begin
1195          if Present (Typ) then
1196             Analyze_And_Resolve (Argx, Typ);
1197          else
1198             Analyze_And_Resolve (Argx);
1199          end if;
1200
1201          if Is_OK_Static_Expression (Argx) then
1202             return;
1203
1204          elsif Etype (Argx) = Any_Type then
1205             raise Pragma_Exit;
1206
1207          --  An interesting special case, if we have a string literal and we
1208          --  are in Ada 83 mode, then we allow it even though it will not be
1209          --  flagged as static. This allows the use of Ada 95 pragmas like
1210          --  Import in Ada 83 mode. They will of course be flagged with
1211          --  warnings as usual, but will not cause errors.
1212
1213          elsif Ada_Version = Ada_83
1214            and then Nkind (Argx) = N_String_Literal
1215          then
1216             return;
1217
1218          --  Static expression that raises Constraint_Error. This has already
1219          --  been flagged, so just exit from pragma processing.
1220
1221          elsif Is_Static_Expression (Argx) then
1222             raise Pragma_Exit;
1223
1224          --  Finally, we have a real error
1225
1226          else
1227             Error_Msg_Name_1 := Pname;
1228
1229             declare
1230                Msg : String :=
1231                        "argument for pragma% must be a static expression!";
1232             begin
1233                Fix_Error (Msg);
1234                Flag_Non_Static_Expr (Msg, Argx);
1235             end;
1236
1237             raise Pragma_Exit;
1238          end if;
1239       end Check_Arg_Is_Static_Expression;
1240
1241       ------------------------------------------
1242       -- Check_Arg_Is_Task_Dispatching_Policy --
1243       ------------------------------------------
1244
1245       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1246          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1247
1248       begin
1249          Check_Arg_Is_Identifier (Argx);
1250
1251          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1252             Error_Pragma_Arg
1253               ("& is not a valid task dispatching policy name", Argx);
1254          end if;
1255       end Check_Arg_Is_Task_Dispatching_Policy;
1256
1257       ---------------------
1258       -- Check_Arg_Order --
1259       ---------------------
1260
1261       procedure Check_Arg_Order (Names : Name_List) is
1262          Arg : Node_Id;
1263
1264          Highest_So_Far : Natural := 0;
1265          --  Highest index in Names seen do far
1266
1267       begin
1268          Arg := Arg1;
1269          for J in 1 .. Arg_Count loop
1270             if Chars (Arg) /= No_Name then
1271                for K in Names'Range loop
1272                   if Chars (Arg) = Names (K) then
1273                      if K < Highest_So_Far then
1274                         Error_Msg_Name_1 := Pname;
1275                         Error_Msg_N
1276                           ("parameters out of order for pragma%", Arg);
1277                         Error_Msg_Name_1 := Names (K);
1278                         Error_Msg_Name_2 := Names (Highest_So_Far);
1279                         Error_Msg_N ("\% must appear before %", Arg);
1280                         raise Pragma_Exit;
1281
1282                      else
1283                         Highest_So_Far := K;
1284                      end if;
1285                   end if;
1286                end loop;
1287             end if;
1288
1289             Arg := Next (Arg);
1290          end loop;
1291       end Check_Arg_Order;
1292
1293       --------------------------------
1294       -- Check_At_Least_N_Arguments --
1295       --------------------------------
1296
1297       procedure Check_At_Least_N_Arguments (N : Nat) is
1298       begin
1299          if Arg_Count < N then
1300             Error_Pragma ("too few arguments for pragma%");
1301          end if;
1302       end Check_At_Least_N_Arguments;
1303
1304       -------------------------------
1305       -- Check_At_Most_N_Arguments --
1306       -------------------------------
1307
1308       procedure Check_At_Most_N_Arguments (N : Nat) is
1309          Arg : Node_Id;
1310       begin
1311          if Arg_Count > N then
1312             Arg := Arg1;
1313             for J in 1 .. N loop
1314                Next (Arg);
1315                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1316             end loop;
1317          end if;
1318       end Check_At_Most_N_Arguments;
1319
1320       ---------------------
1321       -- Check_Component --
1322       ---------------------
1323
1324       procedure Check_Component
1325         (Comp            : Node_Id;
1326          UU_Typ          : Entity_Id;
1327          In_Variant_Part : Boolean := False)
1328       is
1329          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1330          Sindic  : constant Node_Id :=
1331                      Subtype_Indication (Component_Definition (Comp));
1332          Typ     : constant Entity_Id := Etype (Comp_Id);
1333
1334          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1335          --  Determine whether entity Id appears inside a generic body.
1336          --  Shouldn't this be in a more general place ???
1337
1338          -------------------------
1339          -- Inside_Generic_Body --
1340          -------------------------
1341
1342          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1343             S : Entity_Id;
1344
1345          begin
1346             S := Id;
1347             while Present (S) and then S /= Standard_Standard loop
1348                if Ekind (S) = E_Generic_Package
1349                  and then In_Package_Body (S)
1350                then
1351                   return True;
1352                end if;
1353
1354                S := Scope (S);
1355             end loop;
1356
1357             return False;
1358          end Inside_Generic_Body;
1359
1360       --  Start of processing for Check_Component
1361
1362       begin
1363          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1364          --  object constraint, then the component type shall be an Unchecked_
1365          --  Union.
1366
1367          if Nkind (Sindic) = N_Subtype_Indication
1368            and then Has_Per_Object_Constraint (Comp_Id)
1369            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1370          then
1371             Error_Msg_N
1372               ("component subtype subject to per-object constraint " &
1373                "must be an Unchecked_Union", Comp);
1374
1375          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1376          --  the body of a generic unit, or within the body of any of its
1377          --  descendant library units, no part of the type of a component
1378          --  declared in a variant_part of the unchecked union type shall be of
1379          --  a formal private type or formal private extension declared within
1380          --  the formal part of the generic unit.
1381
1382          elsif Ada_Version >= Ada_2012
1383            and then Inside_Generic_Body (UU_Typ)
1384            and then In_Variant_Part
1385            and then Is_Private_Type (Typ)
1386            and then Is_Generic_Type (Typ)
1387          then
1388             Error_Msg_N
1389               ("component of Unchecked_Union cannot be of generic type", Comp);
1390
1391          elsif Needs_Finalization (Typ) then
1392             Error_Msg_N
1393               ("component of Unchecked_Union cannot be controlled", Comp);
1394
1395          elsif Has_Task (Typ) then
1396             Error_Msg_N
1397               ("component of Unchecked_Union cannot have tasks", Comp);
1398          end if;
1399       end Check_Component;
1400
1401       ----------------------------
1402       -- Check_Duplicate_Pragma --
1403       ----------------------------
1404
1405       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1406          P : Node_Id;
1407
1408       begin
1409          --  Nothing to do if this pragma comes from an aspect specification,
1410          --  since we could not be duplicating a pragma, and we dealt with the
1411          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1412
1413          if From_Aspect_Specification (N) then
1414             return;
1415          end if;
1416
1417          --  Otherwise current pragma may duplicate previous pragma or a
1418          --  previously given aspect specification for the same pragma.
1419
1420          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1421
1422          if Present (P) then
1423             Error_Msg_Name_1 := Pragma_Name (N);
1424             Error_Msg_Sloc := Sloc (P);
1425
1426             if Nkind (P) = N_Aspect_Specification
1427               or else From_Aspect_Specification (P)
1428             then
1429                Error_Msg_NE ("aspect% for & previously given#", N, E);
1430             else
1431                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1432             end if;
1433
1434             raise Pragma_Exit;
1435          end if;
1436       end Check_Duplicate_Pragma;
1437
1438       ----------------------------------
1439       -- Check_Duplicated_Export_Name --
1440       ----------------------------------
1441
1442       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1443          String_Val : constant String_Id := Strval (Nam);
1444
1445       begin
1446          --  We are only interested in the export case, and in the case of
1447          --  generics, it is the instance, not the template, that is the
1448          --  problem (the template will generate a warning in any case).
1449
1450          if not Inside_A_Generic
1451            and then (Prag_Id = Pragma_Export
1452                        or else
1453                      Prag_Id = Pragma_Export_Procedure
1454                        or else
1455                      Prag_Id = Pragma_Export_Valued_Procedure
1456                        or else
1457                      Prag_Id = Pragma_Export_Function)
1458          then
1459             for J in Externals.First .. Externals.Last loop
1460                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1461                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1462                   Error_Msg_N ("external name duplicates name given#", Nam);
1463                   exit;
1464                end if;
1465             end loop;
1466
1467             Externals.Append (Nam);
1468          end if;
1469       end Check_Duplicated_Export_Name;
1470
1471       -------------------------
1472       -- Check_First_Subtype --
1473       -------------------------
1474
1475       procedure Check_First_Subtype (Arg : Node_Id) is
1476          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1477          Ent  : constant Entity_Id := Entity (Argx);
1478
1479       begin
1480          if Is_First_Subtype (Ent) then
1481             null;
1482
1483          elsif Is_Type (Ent) then
1484             Error_Pragma_Arg
1485               ("pragma% cannot apply to subtype", Argx);
1486
1487          elsif Is_Object (Ent) then
1488             Error_Pragma_Arg
1489               ("pragma% cannot apply to object, requires a type", Argx);
1490
1491          else
1492             Error_Pragma_Arg
1493               ("pragma% cannot apply to&, requires a type", Argx);
1494          end if;
1495       end Check_First_Subtype;
1496
1497       ----------------------
1498       -- Check_Identifier --
1499       ----------------------
1500
1501       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1502       begin
1503          if Present (Arg)
1504            and then Nkind (Arg) = N_Pragma_Argument_Association
1505          then
1506             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1507                Error_Msg_Name_1 := Pname;
1508                Error_Msg_Name_2 := Id;
1509                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1510                raise Pragma_Exit;
1511             end if;
1512          end if;
1513       end Check_Identifier;
1514
1515       --------------------------------
1516       -- Check_Identifier_Is_One_Of --
1517       --------------------------------
1518
1519       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1520       begin
1521          if Present (Arg)
1522            and then Nkind (Arg) = N_Pragma_Argument_Association
1523          then
1524             if Chars (Arg) = No_Name then
1525                Error_Msg_Name_1 := Pname;
1526                Error_Msg_N ("pragma% argument expects an identifier", Arg);
1527                raise Pragma_Exit;
1528
1529             elsif Chars (Arg) /= N1
1530               and then Chars (Arg) /= N2
1531             then
1532                Error_Msg_Name_1 := Pname;
1533                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1534                raise Pragma_Exit;
1535             end if;
1536          end if;
1537       end Check_Identifier_Is_One_Of;
1538
1539       ---------------------------
1540       -- Check_In_Main_Program --
1541       ---------------------------
1542
1543       procedure Check_In_Main_Program is
1544          P : constant Node_Id := Parent (N);
1545
1546       begin
1547          --  Must be at in subprogram body
1548
1549          if Nkind (P) /= N_Subprogram_Body then
1550             Error_Pragma ("% pragma allowed only in subprogram");
1551
1552          --  Otherwise warn if obviously not main program
1553
1554          elsif Present (Parameter_Specifications (Specification (P)))
1555            or else not Is_Compilation_Unit (Defining_Entity (P))
1556          then
1557             Error_Msg_Name_1 := Pname;
1558             Error_Msg_N
1559               ("?pragma% is only effective in main program", N);
1560          end if;
1561       end Check_In_Main_Program;
1562
1563       ---------------------------------------
1564       -- Check_Interrupt_Or_Attach_Handler --
1565       ---------------------------------------
1566
1567       procedure Check_Interrupt_Or_Attach_Handler is
1568          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1569          Handler_Proc, Proc_Scope : Entity_Id;
1570
1571       begin
1572          Analyze (Arg1_X);
1573
1574          if Prag_Id = Pragma_Interrupt_Handler then
1575             Check_Restriction (No_Dynamic_Attachment, N);
1576          end if;
1577
1578          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1579          Proc_Scope := Scope (Handler_Proc);
1580
1581          --  On AAMP only, a pragma Interrupt_Handler is supported for
1582          --  nonprotected parameterless procedures.
1583
1584          if not AAMP_On_Target
1585            or else Prag_Id = Pragma_Attach_Handler
1586          then
1587             if Ekind (Proc_Scope) /= E_Protected_Type then
1588                Error_Pragma_Arg
1589                  ("argument of pragma% must be protected procedure", Arg1);
1590             end if;
1591
1592             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1593                Error_Pragma ("pragma% must be in protected definition");
1594             end if;
1595          end if;
1596
1597          if not Is_Library_Level_Entity (Proc_Scope)
1598            or else (AAMP_On_Target
1599                      and then not Is_Library_Level_Entity (Handler_Proc))
1600          then
1601             Error_Pragma_Arg
1602               ("argument for pragma% must be library level entity", Arg1);
1603          end if;
1604
1605          --  AI05-0033: A pragma cannot appear within a generic body, because
1606          --  instance can be in a nested scope. The check that protected type
1607          --  is itself a library-level declaration is done elsewhere.
1608
1609          --  Note: we omit this check in Codepeer mode to properly handle code
1610          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1611
1612          if Inside_A_Generic then
1613             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1614               and then In_Package_Body (Scope (Current_Scope))
1615               and then not CodePeer_Mode
1616             then
1617                Error_Pragma ("pragma% cannot be used inside a generic");
1618             end if;
1619          end if;
1620       end Check_Interrupt_Or_Attach_Handler;
1621
1622       -------------------------------------------
1623       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1624       -------------------------------------------
1625
1626       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1627          P : Node_Id;
1628
1629       begin
1630          P := Parent (N);
1631          loop
1632             if No (P) then
1633                exit;
1634
1635             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1636                exit;
1637
1638             elsif Nkind_In (P, N_Package_Specification,
1639                                N_Block_Statement)
1640             then
1641                return;
1642
1643             --  Note: the following tests seem a little peculiar, because
1644             --  they test for bodies, but if we were in the statement part
1645             --  of the body, we would already have hit the handled statement
1646             --  sequence, so the only way we get here is by being in the
1647             --  declarative part of the body.
1648
1649             elsif Nkind_In (P, N_Subprogram_Body,
1650                                N_Package_Body,
1651                                N_Task_Body,
1652                                N_Entry_Body)
1653             then
1654                return;
1655             end if;
1656
1657             P := Parent (P);
1658          end loop;
1659
1660          Error_Pragma ("pragma% is not in declarative part or package spec");
1661       end Check_Is_In_Decl_Part_Or_Package_Spec;
1662
1663       -------------------------
1664       -- Check_No_Identifier --
1665       -------------------------
1666
1667       procedure Check_No_Identifier (Arg : Node_Id) is
1668       begin
1669          if Nkind (Arg) = N_Pragma_Argument_Association
1670            and then Chars (Arg) /= No_Name
1671          then
1672             Error_Pragma_Arg_Ident
1673               ("pragma% does not permit identifier& here", Arg);
1674          end if;
1675       end Check_No_Identifier;
1676
1677       --------------------------
1678       -- Check_No_Identifiers --
1679       --------------------------
1680
1681       procedure Check_No_Identifiers is
1682          Arg_Node : Node_Id;
1683       begin
1684          if Arg_Count > 0 then
1685             Arg_Node := Arg1;
1686             while Present (Arg_Node) loop
1687                Check_No_Identifier (Arg_Node);
1688                Next (Arg_Node);
1689             end loop;
1690          end if;
1691       end Check_No_Identifiers;
1692
1693       ------------------------
1694       -- Check_No_Link_Name --
1695       ------------------------
1696
1697       procedure Check_No_Link_Name is
1698       begin
1699          if Present (Arg3)
1700            and then Chars (Arg3) = Name_Link_Name
1701          then
1702             Arg4 := Arg3;
1703          end if;
1704
1705          if Present (Arg4) then
1706             Error_Pragma_Arg
1707               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1708          end if;
1709       end Check_No_Link_Name;
1710
1711       -------------------------------
1712       -- Check_Optional_Identifier --
1713       -------------------------------
1714
1715       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1716       begin
1717          if Present (Arg)
1718            and then Nkind (Arg) = N_Pragma_Argument_Association
1719            and then Chars (Arg) /= No_Name
1720          then
1721             if Chars (Arg) /= Id then
1722                Error_Msg_Name_1 := Pname;
1723                Error_Msg_Name_2 := Id;
1724                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1725                raise Pragma_Exit;
1726             end if;
1727          end if;
1728       end Check_Optional_Identifier;
1729
1730       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1731       begin
1732          Name_Buffer (1 .. Id'Length) := Id;
1733          Name_Len := Id'Length;
1734          Check_Optional_Identifier (Arg, Name_Find);
1735       end Check_Optional_Identifier;
1736
1737       --------------------------------------
1738       -- Check_Precondition_Postcondition --
1739       --------------------------------------
1740
1741       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1742          P  : Node_Id;
1743          PO : Node_Id;
1744
1745          procedure Chain_PPC (PO : Node_Id);
1746          --  If PO is an entry or a [generic] subprogram declaration node, then
1747          --  the precondition/postcondition applies to this subprogram and the
1748          --  processing for the pragma is completed. Otherwise the pragma is
1749          --  misplaced.
1750
1751          ---------------
1752          -- Chain_PPC --
1753          ---------------
1754
1755          procedure Chain_PPC (PO : Node_Id) is
1756             S   : Entity_Id;
1757             P   : Node_Id;
1758
1759          begin
1760             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1761                if not From_Aspect_Specification (N) then
1762                   Error_Pragma
1763                     ("pragma% cannot be applied to abstract subprogram");
1764
1765                elsif Class_Present (N) then
1766                   null;
1767
1768                else
1769                   Error_Pragma
1770                     ("aspect % requires ''Class for abstract subprogram");
1771                end if;
1772
1773             --  AI05-0230: The same restriction applies to null procedures. For
1774             --  compatibility with earlier uses of the Ada pragma, apply this
1775             --  rule only to aspect specifications.
1776
1777             --  The above discrpency needs documentation. Robert is dubious
1778             --  about whether it is a good idea ???
1779
1780             elsif Nkind (PO) = N_Subprogram_Declaration
1781               and then Nkind (Specification (PO)) = N_Procedure_Specification
1782               and then Null_Present (Specification (PO))
1783               and then From_Aspect_Specification (N)
1784               and then not Class_Present (N)
1785             then
1786                Error_Pragma
1787                  ("aspect % requires ''Class for null procedure");
1788
1789             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1790                                     N_Generic_Subprogram_Declaration,
1791                                     N_Entry_Declaration)
1792             then
1793                Pragma_Misplaced;
1794             end if;
1795
1796             --  Here if we have [generic] subprogram or entry declaration
1797
1798             if Nkind (PO) = N_Entry_Declaration then
1799                S := Defining_Entity (PO);
1800             else
1801                S := Defining_Unit_Name (Specification (PO));
1802             end if;
1803
1804             --  Make sure we do not have the case of a precondition pragma when
1805             --  the Pre'Class aspect is present.
1806
1807             --  We do this by looking at pragmas already chained to the entity
1808             --  since the aspect derived pragma will be put on this list first.
1809
1810             if Pragma_Name (N) = Name_Precondition then
1811                if not From_Aspect_Specification (N) then
1812                   P := Spec_PPC_List (Contract (S));
1813                   while Present (P) loop
1814                      if Pragma_Name (P) = Name_Precondition
1815                        and then From_Aspect_Specification (P)
1816                        and then Class_Present (P)
1817                      then
1818                         Error_Msg_Sloc := Sloc (P);
1819                         Error_Pragma
1820                           ("pragma% not allowed, `Pre''Class` aspect given#");
1821                      end if;
1822
1823                      P := Next_Pragma (P);
1824                   end loop;
1825                end if;
1826             end if;
1827
1828             --  Similarly check for Pre with inherited Pre'Class. Note that
1829             --  we cover the aspect case as well here.
1830
1831             if Pragma_Name (N) = Name_Precondition
1832               and then not Class_Present (N)
1833             then
1834                declare
1835                   Inherited : constant Subprogram_List :=
1836                                 Inherited_Subprograms (S);
1837                   P         : Node_Id;
1838
1839                begin
1840                   for J in Inherited'Range loop
1841                      P := Spec_PPC_List (Contract (Inherited (J)));
1842                      while Present (P) loop
1843                         if Pragma_Name (P) = Name_Precondition
1844                           and then Class_Present (P)
1845                         then
1846                            Error_Msg_Sloc := Sloc (P);
1847                            Error_Pragma
1848                              ("pragma% not allowed, `Pre''Class` "
1849                               & "aspect inherited from#");
1850                         end if;
1851
1852                         P := Next_Pragma (P);
1853                      end loop;
1854                   end loop;
1855                end;
1856             end if;
1857
1858             --  Note: we do not analyze the pragma at this point. Instead we
1859             --  delay this analysis until the end of the declarative part in
1860             --  which the pragma appears. This implements the required delay
1861             --  in this analysis, allowing forward references. The analysis
1862             --  happens at the end of Analyze_Declarations.
1863
1864             --  Chain spec PPC pragma to list for subprogram
1865
1866             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1867             Set_Spec_PPC_List (Contract (S), N);
1868
1869             --  Return indicating spec case
1870
1871             In_Body := False;
1872             return;
1873          end Chain_PPC;
1874
1875       --  Start of processing for Check_Precondition_Postcondition
1876
1877       begin
1878          if not Is_List_Member (N) then
1879             Pragma_Misplaced;
1880          end if;
1881
1882          --  Preanalyze message argument if present. Visibility in this
1883          --  argument is established at the point of pragma occurrence.
1884
1885          if Arg_Count = 2 then
1886             Check_Optional_Identifier (Arg2, Name_Message);
1887             Preanalyze_Spec_Expression
1888               (Get_Pragma_Arg (Arg2), Standard_String);
1889          end if;
1890
1891          --  Record if pragma is disabled
1892
1893          if Check_Enabled (Pname) then
1894             Set_SCO_Pragma_Enabled (Loc);
1895          end if;
1896
1897          --  If we are within an inlined body, the legality of the pragma
1898          --  has been checked already.
1899
1900          if In_Inlined_Body then
1901             In_Body := True;
1902             return;
1903          end if;
1904
1905          --  Search prior declarations
1906
1907          P := N;
1908          while Present (Prev (P)) loop
1909             P := Prev (P);
1910
1911             --  If the previous node is a generic subprogram, do not go to to
1912             --  the original node, which is the unanalyzed tree: we need to
1913             --  attach the pre/postconditions to the analyzed version at this
1914             --  point. They get propagated to the original tree when analyzing
1915             --  the corresponding body.
1916
1917             if Nkind (P) not in N_Generic_Declaration then
1918                PO := Original_Node (P);
1919             else
1920                PO := P;
1921             end if;
1922
1923             --  Skip past prior pragma
1924
1925             if Nkind (PO) = N_Pragma then
1926                null;
1927
1928             --  Skip stuff not coming from source
1929
1930             elsif not Comes_From_Source (PO) then
1931
1932                --  The condition may apply to a subprogram instantiation
1933
1934                if Nkind (PO) = N_Subprogram_Declaration
1935                  and then Present (Generic_Parent (Specification (PO)))
1936                then
1937                   Chain_PPC (PO);
1938                   return;
1939
1940                elsif Nkind (PO) = N_Subprogram_Declaration
1941                  and then In_Instance
1942                then
1943                   Chain_PPC (PO);
1944                   return;
1945
1946                --  For all other cases of non source code, do nothing
1947
1948                else
1949                   null;
1950                end if;
1951
1952             --  Only remaining possibility is subprogram declaration
1953
1954             else
1955                Chain_PPC (PO);
1956                return;
1957             end if;
1958          end loop;
1959
1960          --  If we fall through loop, pragma is at start of list, so see if it
1961          --  is at the start of declarations of a subprogram body.
1962
1963          if Nkind (Parent (N)) = N_Subprogram_Body
1964            and then List_Containing (N) = Declarations (Parent (N))
1965          then
1966             if Operating_Mode /= Generate_Code
1967               or else Inside_A_Generic
1968             then
1969                --  Analyze pragma expression for correctness and for ASIS use
1970
1971                Preanalyze_Spec_Expression
1972                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
1973             end if;
1974
1975             In_Body := True;
1976             return;
1977
1978          --  See if it is in the pragmas after a library level subprogram
1979
1980          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1981
1982             --  In formal verification mode, analyze pragma expression for
1983             --  correctness, as it is not expanded later.
1984
1985             if Alfa_Mode then
1986                Analyze_PPC_In_Decl_Part
1987                  (N, Defining_Entity (Unit (Parent (Parent (N)))));
1988             end if;
1989
1990             Chain_PPC (Unit (Parent (Parent (N))));
1991             return;
1992          end if;
1993
1994          --  If we fall through, pragma was misplaced
1995
1996          Pragma_Misplaced;
1997       end Check_Precondition_Postcondition;
1998
1999       -----------------------------
2000       -- Check_Static_Constraint --
2001       -----------------------------
2002
2003       --  Note: for convenience in writing this procedure, in addition to
2004       --  the officially (i.e. by spec) allowed argument which is always a
2005       --  constraint, it also allows ranges and discriminant associations.
2006       --  Above is not clear ???
2007
2008       procedure Check_Static_Constraint (Constr : Node_Id) is
2009
2010          procedure Require_Static (E : Node_Id);
2011          --  Require given expression to be static expression
2012
2013          --------------------
2014          -- Require_Static --
2015          --------------------
2016
2017          procedure Require_Static (E : Node_Id) is
2018          begin
2019             if not Is_OK_Static_Expression (E) then
2020                Flag_Non_Static_Expr
2021                  ("non-static constraint not allowed in Unchecked_Union!", E);
2022                raise Pragma_Exit;
2023             end if;
2024          end Require_Static;
2025
2026       --  Start of processing for Check_Static_Constraint
2027
2028       begin
2029          case Nkind (Constr) is
2030             when N_Discriminant_Association =>
2031                Require_Static (Expression (Constr));
2032
2033             when N_Range =>
2034                Require_Static (Low_Bound (Constr));
2035                Require_Static (High_Bound (Constr));
2036
2037             when N_Attribute_Reference =>
2038                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
2039                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2040
2041             when N_Range_Constraint =>
2042                Check_Static_Constraint (Range_Expression (Constr));
2043
2044             when N_Index_Or_Discriminant_Constraint =>
2045                declare
2046                   IDC : Entity_Id;
2047                begin
2048                   IDC := First (Constraints (Constr));
2049                   while Present (IDC) loop
2050                      Check_Static_Constraint (IDC);
2051                      Next (IDC);
2052                   end loop;
2053                end;
2054
2055             when others =>
2056                null;
2057          end case;
2058       end Check_Static_Constraint;
2059
2060       ---------------------
2061       -- Check_Test_Case --
2062       ---------------------
2063
2064       procedure Check_Test_Case is
2065          P  : Node_Id;
2066          PO : Node_Id;
2067
2068          procedure Chain_TC (PO : Node_Id);
2069          --  If PO is a [generic] subprogram declaration node, then the
2070          --  test-case applies to this subprogram and the processing for the
2071          --  pragma is completed. Otherwise the pragma is misplaced.
2072
2073          --------------
2074          -- Chain_TC --
2075          --------------
2076
2077          procedure Chain_TC (PO : Node_Id) is
2078             S   : Entity_Id;
2079
2080          begin
2081             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2082                if From_Aspect_Specification (N) then
2083                   Error_Pragma
2084                     ("aspect% cannot be applied to abstract subprogram");
2085                else
2086                   Error_Pragma
2087                     ("pragma% cannot be applied to abstract subprogram");
2088                end if;
2089
2090             elsif Nkind (PO) = N_Entry_Declaration then
2091                if From_Aspect_Specification (N) then
2092                   Error_Pragma ("aspect% cannot be applied to entry");
2093                else
2094                   Error_Pragma ("pragma% cannot be applied to entry");
2095                end if;
2096
2097             elsif not Nkind_In (PO, N_Subprogram_Declaration,
2098                                     N_Generic_Subprogram_Declaration)
2099             then
2100                Pragma_Misplaced;
2101             end if;
2102
2103             --  Here if we have [generic] subprogram declaration
2104
2105             S := Defining_Unit_Name (Specification (PO));
2106
2107             --  Note: we do not analyze the pragma at this point. Instead we
2108             --  delay this analysis until the end of the declarative part in
2109             --  which the pragma appears. This implements the required delay
2110             --  in this analysis, allowing forward references. The analysis
2111             --  happens at the end of Analyze_Declarations.
2112
2113             --  There should not be another test case with the same name
2114             --  associated to this subprogram.
2115
2116             declare
2117                Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2118                TC   : Node_Id;
2119
2120             begin
2121                TC := Spec_TC_List (Contract (S));
2122                while Present (TC) loop
2123
2124                   if String_Equal
2125                     (Name, Get_Name_From_Test_Case_Pragma (TC))
2126                   then
2127                      Error_Msg_Sloc := Sloc (TC);
2128
2129                      if From_Aspect_Specification (N) then
2130                         Error_Pragma ("name for aspect% is already used#");
2131                      else
2132                         Error_Pragma ("name for pragma% is already used#");
2133                      end if;
2134                   end if;
2135
2136                   TC := Next_Pragma (TC);
2137                end loop;
2138             end;
2139
2140             --  Chain spec TC pragma to list for subprogram
2141
2142             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2143             Set_Spec_TC_List (Contract (S), N);
2144          end Chain_TC;
2145
2146       --  Start of processing for Check_Test_Case
2147
2148       begin
2149          if not Is_List_Member (N) then
2150             Pragma_Misplaced;
2151          end if;
2152
2153          --  Test cases should only appear in package spec unit
2154
2155          if Get_Source_Unit (N) = No_Unit
2156            or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2157                                  N_Package_Declaration,
2158                                  N_Generic_Package_Declaration)
2159          then
2160             Pragma_Misplaced;
2161          end if;
2162
2163          --  Search prior declarations
2164
2165          P := N;
2166          while Present (Prev (P)) loop
2167             P := Prev (P);
2168
2169             --  If the previous node is a generic subprogram, do not go to to
2170             --  the original node, which is the unanalyzed tree: we need to
2171             --  attach the test-case to the analyzed version at this point.
2172             --  They get propagated to the original tree when analyzing the
2173             --  corresponding body.
2174
2175             if Nkind (P) not in N_Generic_Declaration then
2176                PO := Original_Node (P);
2177             else
2178                PO := P;
2179             end if;
2180
2181             --  Skip past prior pragma
2182
2183             if Nkind (PO) = N_Pragma then
2184                null;
2185
2186             --  Skip stuff not coming from source
2187
2188             elsif not Comes_From_Source (PO) then
2189                null;
2190
2191             --  Only remaining possibility is subprogram declaration. First
2192             --  check that it is declared directly in a package declaration.
2193             --  This may be either the package declaration for the current unit
2194             --  being defined or a local package declaration.
2195
2196             elsif not Present (Parent (Parent (PO)))
2197               or else not Present (Parent (Parent (Parent (PO))))
2198               or else not Nkind_In (Parent (Parent (PO)),
2199                                     N_Package_Declaration,
2200                                     N_Generic_Package_Declaration)
2201             then
2202                Pragma_Misplaced;
2203
2204             else
2205                Chain_TC (PO);
2206                return;
2207             end if;
2208          end loop;
2209
2210          --  If we fall through, pragma was misplaced
2211
2212          Pragma_Misplaced;
2213       end Check_Test_Case;
2214
2215       --------------------------------------
2216       -- Check_Valid_Configuration_Pragma --
2217       --------------------------------------
2218
2219       --  A configuration pragma must appear in the context clause of a
2220       --  compilation unit, and only other pragmas may precede it. Note that
2221       --  the test also allows use in a configuration pragma file.
2222
2223       procedure Check_Valid_Configuration_Pragma is
2224       begin
2225          if not Is_Configuration_Pragma then
2226             Error_Pragma ("incorrect placement for configuration pragma%");
2227          end if;
2228       end Check_Valid_Configuration_Pragma;
2229
2230       -------------------------------------
2231       -- Check_Valid_Library_Unit_Pragma --
2232       -------------------------------------
2233
2234       procedure Check_Valid_Library_Unit_Pragma is
2235          Plist       : List_Id;
2236          Parent_Node : Node_Id;
2237          Unit_Name   : Entity_Id;
2238          Unit_Kind   : Node_Kind;
2239          Unit_Node   : Node_Id;
2240          Sindex      : Source_File_Index;
2241
2242       begin
2243          if not Is_List_Member (N) then
2244             Pragma_Misplaced;
2245
2246          else
2247             Plist := List_Containing (N);
2248             Parent_Node := Parent (Plist);
2249
2250             if Parent_Node = Empty then
2251                Pragma_Misplaced;
2252
2253             --  Case of pragma appearing after a compilation unit. In this case
2254             --  it must have an argument with the corresponding name and must
2255             --  be part of the following pragmas of its parent.
2256
2257             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2258                if Plist /= Pragmas_After (Parent_Node) then
2259                   Pragma_Misplaced;
2260
2261                elsif Arg_Count = 0 then
2262                   Error_Pragma
2263                     ("argument required if outside compilation unit");
2264
2265                else
2266                   Check_No_Identifiers;
2267                   Check_Arg_Count (1);
2268                   Unit_Node := Unit (Parent (Parent_Node));
2269                   Unit_Kind := Nkind (Unit_Node);
2270
2271                   Analyze (Get_Pragma_Arg (Arg1));
2272
2273                   if Unit_Kind = N_Generic_Subprogram_Declaration
2274                     or else Unit_Kind = N_Subprogram_Declaration
2275                   then
2276                      Unit_Name := Defining_Entity (Unit_Node);
2277
2278                   elsif Unit_Kind in N_Generic_Instantiation then
2279                      Unit_Name := Defining_Entity (Unit_Node);
2280
2281                   else
2282                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2283                   end if;
2284
2285                   if Chars (Unit_Name) /=
2286                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2287                   then
2288                      Error_Pragma_Arg
2289                        ("pragma% argument is not current unit name", Arg1);
2290                   end if;
2291
2292                   if Ekind (Unit_Name) = E_Package
2293                     and then Present (Renamed_Entity (Unit_Name))
2294                   then
2295                      Error_Pragma ("pragma% not allowed for renamed package");
2296                   end if;
2297                end if;
2298
2299             --  Pragma appears other than after a compilation unit
2300
2301             else
2302                --  Here we check for the generic instantiation case and also
2303                --  for the case of processing a generic formal package. We
2304                --  detect these cases by noting that the Sloc on the node
2305                --  does not belong to the current compilation unit.
2306
2307                Sindex := Source_Index (Current_Sem_Unit);
2308
2309                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2310                   Rewrite (N, Make_Null_Statement (Loc));
2311                   return;
2312
2313                --  If before first declaration, the pragma applies to the
2314                --  enclosing unit, and the name if present must be this name.
2315
2316                elsif Is_Before_First_Decl (N, Plist) then
2317                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2318                   Unit_Kind := Nkind (Unit_Node);
2319
2320                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2321                      Pragma_Misplaced;
2322
2323                   elsif Unit_Kind = N_Subprogram_Body
2324                     and then not Acts_As_Spec (Unit_Node)
2325                   then
2326                      Pragma_Misplaced;
2327
2328                   elsif Nkind (Parent_Node) = N_Package_Body then
2329                      Pragma_Misplaced;
2330
2331                   elsif Nkind (Parent_Node) = N_Package_Specification
2332                     and then Plist = Private_Declarations (Parent_Node)
2333                   then
2334                      Pragma_Misplaced;
2335
2336                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2337                            or else Nkind (Parent_Node) =
2338                                              N_Generic_Subprogram_Declaration)
2339                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2340                   then
2341                      Pragma_Misplaced;
2342
2343                   elsif Arg_Count > 0 then
2344                      Analyze (Get_Pragma_Arg (Arg1));
2345
2346                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2347                         Error_Pragma_Arg
2348                           ("name in pragma% must be enclosing unit", Arg1);
2349                      end if;
2350
2351                   --  It is legal to have no argument in this context
2352
2353                   else
2354                      return;
2355                   end if;
2356
2357                --  Error if not before first declaration. This is because a
2358                --  library unit pragma argument must be the name of a library
2359                --  unit (RM 10.1.5(7)), but the only names permitted in this
2360                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2361                --  generic subprogram declarations or generic instantiations.
2362
2363                else
2364                   Error_Pragma
2365                     ("pragma% misplaced, must be before first declaration");
2366                end if;
2367             end if;
2368          end if;
2369       end Check_Valid_Library_Unit_Pragma;
2370
2371       -------------------
2372       -- Check_Variant --
2373       -------------------
2374
2375       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2376          Clist : constant Node_Id := Component_List (Variant);
2377          Comp  : Node_Id;
2378
2379       begin
2380          if not Is_Non_Empty_List (Component_Items (Clist)) then
2381             Error_Msg_N
2382               ("Unchecked_Union may not have empty component list",
2383                Variant);
2384             return;
2385          end if;
2386
2387          Comp := First (Component_Items (Clist));
2388          while Present (Comp) loop
2389             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2390             Next (Comp);
2391          end loop;
2392       end Check_Variant;
2393
2394       ------------------
2395       -- Error_Pragma --
2396       ------------------
2397
2398       procedure Error_Pragma (Msg : String) is
2399          MsgF : String := Msg;
2400       begin
2401          Error_Msg_Name_1 := Pname;
2402          Fix_Error (MsgF);
2403          Error_Msg_N (MsgF, N);
2404          raise Pragma_Exit;
2405       end Error_Pragma;
2406
2407       ----------------------
2408       -- Error_Pragma_Arg --
2409       ----------------------
2410
2411       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2412          MsgF : String := Msg;
2413       begin
2414          Error_Msg_Name_1 := Pname;
2415          Fix_Error (MsgF);
2416          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2417          raise Pragma_Exit;
2418       end Error_Pragma_Arg;
2419
2420       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2421          MsgF : String := Msg1;
2422       begin
2423          Error_Msg_Name_1 := Pname;
2424          Fix_Error (MsgF);
2425          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2426          Error_Pragma_Arg (Msg2, Arg);
2427       end Error_Pragma_Arg;
2428
2429       ----------------------------
2430       -- Error_Pragma_Arg_Ident --
2431       ----------------------------
2432
2433       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2434          MsgF : String := Msg;
2435       begin
2436          Error_Msg_Name_1 := Pname;
2437          Fix_Error (MsgF);
2438          Error_Msg_N (MsgF, Arg);
2439          raise Pragma_Exit;
2440       end Error_Pragma_Arg_Ident;
2441
2442       ----------------------
2443       -- Error_Pragma_Ref --
2444       ----------------------
2445
2446       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2447          MsgF : String := Msg;
2448       begin
2449          Error_Msg_Name_1 := Pname;
2450          Fix_Error (MsgF);
2451          Error_Msg_Sloc   := Sloc (Ref);
2452          Error_Msg_NE (MsgF, N, Ref);
2453          raise Pragma_Exit;
2454       end Error_Pragma_Ref;
2455
2456       ------------------------
2457       -- Find_Lib_Unit_Name --
2458       ------------------------
2459
2460       function Find_Lib_Unit_Name return Entity_Id is
2461       begin
2462          --  Return inner compilation unit entity, for case of nested
2463          --  categorization pragmas. This happens in generic unit.
2464
2465          if Nkind (Parent (N)) = N_Package_Specification
2466            and then Defining_Entity (Parent (N)) /= Current_Scope
2467          then
2468             return Defining_Entity (Parent (N));
2469          else
2470             return Current_Scope;
2471          end if;
2472       end Find_Lib_Unit_Name;
2473
2474       ----------------------------
2475       -- Find_Program_Unit_Name --
2476       ----------------------------
2477
2478       procedure Find_Program_Unit_Name (Id : Node_Id) is
2479          Unit_Name : Entity_Id;
2480          Unit_Kind : Node_Kind;
2481          P         : constant Node_Id := Parent (N);
2482
2483       begin
2484          if Nkind (P) = N_Compilation_Unit then
2485             Unit_Kind := Nkind (Unit (P));
2486
2487             if Unit_Kind = N_Subprogram_Declaration
2488               or else Unit_Kind = N_Package_Declaration
2489               or else Unit_Kind in N_Generic_Declaration
2490             then
2491                Unit_Name := Defining_Entity (Unit (P));
2492
2493                if Chars (Id) = Chars (Unit_Name) then
2494                   Set_Entity (Id, Unit_Name);
2495                   Set_Etype (Id, Etype (Unit_Name));
2496                else
2497                   Set_Etype (Id, Any_Type);
2498                   Error_Pragma
2499                     ("cannot find program unit referenced by pragma%");
2500                end if;
2501
2502             else
2503                Set_Etype (Id, Any_Type);
2504                Error_Pragma ("pragma% inapplicable to this unit");
2505             end if;
2506
2507          else
2508             Analyze (Id);
2509          end if;
2510       end Find_Program_Unit_Name;
2511
2512       -----------------------------------------
2513       -- Find_Unique_Parameterless_Procedure --
2514       -----------------------------------------
2515
2516       function Find_Unique_Parameterless_Procedure
2517         (Name : Entity_Id;
2518          Arg  : Node_Id) return Entity_Id
2519       is
2520          Proc : Entity_Id := Empty;
2521
2522       begin
2523          --  The body of this procedure needs some comments ???
2524
2525          if not Is_Entity_Name (Name) then
2526             Error_Pragma_Arg
2527               ("argument of pragma% must be entity name", Arg);
2528
2529          elsif not Is_Overloaded (Name) then
2530             Proc := Entity (Name);
2531
2532             if Ekind (Proc) /= E_Procedure
2533               or else Present (First_Formal (Proc))
2534             then
2535                Error_Pragma_Arg
2536                  ("argument of pragma% must be parameterless procedure", Arg);
2537             end if;
2538
2539          else
2540             declare
2541                Found : Boolean := False;
2542                It    : Interp;
2543                Index : Interp_Index;
2544
2545             begin
2546                Get_First_Interp (Name, Index, It);
2547                while Present (It.Nam) loop
2548                   Proc := It.Nam;
2549
2550                   if Ekind (Proc) = E_Procedure
2551                     and then No (First_Formal (Proc))
2552                   then
2553                      if not Found then
2554                         Found := True;
2555                         Set_Entity (Name, Proc);
2556                         Set_Is_Overloaded (Name, False);
2557                      else
2558                         Error_Pragma_Arg
2559                           ("ambiguous handler name for pragma% ", Arg);
2560                      end if;
2561                   end if;
2562
2563                   Get_Next_Interp (Index, It);
2564                end loop;
2565
2566                if not Found then
2567                   Error_Pragma_Arg
2568                     ("argument of pragma% must be parameterless procedure",
2569                      Arg);
2570                else
2571                   Proc := Entity (Name);
2572                end if;
2573             end;
2574          end if;
2575
2576          return Proc;
2577       end Find_Unique_Parameterless_Procedure;
2578
2579       ---------------
2580       -- Fix_Error --
2581       ---------------
2582
2583       procedure Fix_Error (Msg : in out String) is
2584       begin
2585          if From_Aspect_Specification (N) then
2586             for J in Msg'First .. Msg'Last - 5 loop
2587                if Msg (J .. J + 5) = "pragma" then
2588                   Msg (J .. J + 5) := "aspect";
2589                end if;
2590             end loop;
2591
2592             if Error_Msg_Name_1 = Name_Precondition then
2593                Error_Msg_Name_1 := Name_Pre;
2594             elsif Error_Msg_Name_1 = Name_Postcondition then
2595                Error_Msg_Name_1 := Name_Post;
2596             end if;
2597          end if;
2598       end Fix_Error;
2599
2600       -------------------------
2601       -- Gather_Associations --
2602       -------------------------
2603
2604       procedure Gather_Associations
2605         (Names : Name_List;
2606          Args  : out Args_List)
2607       is
2608          Arg : Node_Id;
2609
2610       begin
2611          --  Initialize all parameters to Empty
2612
2613          for J in Args'Range loop
2614             Args (J) := Empty;
2615          end loop;
2616
2617          --  That's all we have to do if there are no argument associations
2618
2619          if No (Pragma_Argument_Associations (N)) then
2620             return;
2621          end if;
2622
2623          --  Otherwise first deal with any positional parameters present
2624
2625          Arg := First (Pragma_Argument_Associations (N));
2626          for Index in Args'Range loop
2627             exit when No (Arg) or else Chars (Arg) /= No_Name;
2628             Args (Index) := Get_Pragma_Arg (Arg);
2629             Next (Arg);
2630          end loop;
2631
2632          --  Positional parameters all processed, if any left, then we
2633          --  have too many positional parameters.
2634
2635          if Present (Arg) and then Chars (Arg) = No_Name then
2636             Error_Pragma_Arg
2637               ("too many positional associations for pragma%", Arg);
2638          end if;
2639
2640          --  Process named parameters if any are present
2641
2642          while Present (Arg) loop
2643             if Chars (Arg) = No_Name then
2644                Error_Pragma_Arg
2645                  ("positional association cannot follow named association",
2646                   Arg);
2647
2648             else
2649                for Index in Names'Range loop
2650                   if Names (Index) = Chars (Arg) then
2651                      if Present (Args (Index)) then
2652                         Error_Pragma_Arg
2653                           ("duplicate argument association for pragma%", Arg);
2654                      else
2655                         Args (Index) := Get_Pragma_Arg (Arg);
2656                         exit;
2657                      end if;
2658                   end if;
2659
2660                   if Index = Names'Last then
2661                      Error_Msg_Name_1 := Pname;
2662                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2663
2664                      --  Check for possible misspelling
2665
2666                      for Index1 in Names'Range loop
2667                         if Is_Bad_Spelling_Of
2668                              (Chars (Arg), Names (Index1))
2669                         then
2670                            Error_Msg_Name_1 := Names (Index1);
2671                            Error_Msg_N -- CODEFIX
2672                              ("\possible misspelling of%", Arg);
2673                            exit;
2674                         end if;
2675                      end loop;
2676
2677                      raise Pragma_Exit;
2678                   end if;
2679                end loop;
2680             end if;
2681
2682             Next (Arg);
2683          end loop;
2684       end Gather_Associations;
2685
2686       -----------------
2687       -- GNAT_Pragma --
2688       -----------------
2689
2690       procedure GNAT_Pragma is
2691       begin
2692          Check_Restriction (No_Implementation_Pragmas, N);
2693       end GNAT_Pragma;
2694
2695       --------------------------
2696       -- Is_Before_First_Decl --
2697       --------------------------
2698
2699       function Is_Before_First_Decl
2700         (Pragma_Node : Node_Id;
2701          Decls       : List_Id) return Boolean
2702       is
2703          Item : Node_Id := First (Decls);
2704
2705       begin
2706          --  Only other pragmas can come before this pragma
2707
2708          loop
2709             if No (Item) or else Nkind (Item) /= N_Pragma then
2710                return False;
2711
2712             elsif Item = Pragma_Node then
2713                return True;
2714             end if;
2715
2716             Next (Item);
2717          end loop;
2718       end Is_Before_First_Decl;
2719
2720       -----------------------------
2721       -- Is_Configuration_Pragma --
2722       -----------------------------
2723
2724       --  A configuration pragma must appear in the context clause of a
2725       --  compilation unit, and only other pragmas may precede it. Note that
2726       --  the test below also permits use in a configuration pragma file.
2727
2728       function Is_Configuration_Pragma return Boolean is
2729          Lis : constant List_Id := List_Containing (N);
2730          Par : constant Node_Id := Parent (N);
2731          Prg : Node_Id;
2732
2733       begin
2734          --  If no parent, then we are in the configuration pragma file,
2735          --  so the placement is definitely appropriate.
2736
2737          if No (Par) then
2738             return True;
2739
2740          --  Otherwise we must be in the context clause of a compilation unit
2741          --  and the only thing allowed before us in the context list is more
2742          --  configuration pragmas.
2743
2744          elsif Nkind (Par) = N_Compilation_Unit
2745            and then Context_Items (Par) = Lis
2746          then
2747             Prg := First (Lis);
2748
2749             loop
2750                if Prg = N then
2751                   return True;
2752                elsif Nkind (Prg) /= N_Pragma then
2753                   return False;
2754                end if;
2755
2756                Next (Prg);
2757             end loop;
2758
2759          else
2760             return False;
2761          end if;
2762       end Is_Configuration_Pragma;
2763
2764       --------------------------
2765       -- Is_In_Context_Clause --
2766       --------------------------
2767
2768       function Is_In_Context_Clause return Boolean is
2769          Plist       : List_Id;
2770          Parent_Node : Node_Id;
2771
2772       begin
2773          if not Is_List_Member (N) then
2774             return False;
2775
2776          else
2777             Plist := List_Containing (N);
2778             Parent_Node := Parent (Plist);
2779
2780             if Parent_Node = Empty
2781               or else Nkind (Parent_Node) /= N_Compilation_Unit
2782               or else Context_Items (Parent_Node) /= Plist
2783             then
2784                return False;
2785             end if;
2786          end if;
2787
2788          return True;
2789       end Is_In_Context_Clause;
2790
2791       ---------------------------------
2792       -- Is_Static_String_Expression --
2793       ---------------------------------
2794
2795       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2796          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2797
2798       begin
2799          Analyze_And_Resolve (Argx);
2800          return Is_OK_Static_Expression (Argx)
2801            and then Nkind (Argx) = N_String_Literal;
2802       end Is_Static_String_Expression;
2803
2804       ----------------------
2805       -- Pragma_Misplaced --
2806       ----------------------
2807
2808       procedure Pragma_Misplaced is
2809       begin
2810          Error_Pragma ("incorrect placement of pragma%");
2811       end Pragma_Misplaced;
2812
2813       ------------------------------------
2814       -- Process Atomic_Shared_Volatile --
2815       ------------------------------------
2816
2817       procedure Process_Atomic_Shared_Volatile is
2818          E_Id : Node_Id;
2819          E    : Entity_Id;
2820          D    : Node_Id;
2821          K    : Node_Kind;
2822          Utyp : Entity_Id;
2823
2824          procedure Set_Atomic (E : Entity_Id);
2825          --  Set given type as atomic, and if no explicit alignment was given,
2826          --  set alignment to unknown, since back end knows what the alignment
2827          --  requirements are for atomic arrays. Note: this step is necessary
2828          --  for derived types.
2829
2830          ----------------
2831          -- Set_Atomic --
2832          ----------------
2833
2834          procedure Set_Atomic (E : Entity_Id) is
2835          begin
2836             Set_Is_Atomic (E);
2837
2838             if not Has_Alignment_Clause (E) then
2839                Set_Alignment (E, Uint_0);
2840             end if;
2841          end Set_Atomic;
2842
2843       --  Start of processing for Process_Atomic_Shared_Volatile
2844
2845       begin
2846          Check_Ada_83_Warning;
2847          Check_No_Identifiers;
2848          Check_Arg_Count (1);
2849          Check_Arg_Is_Local_Name (Arg1);
2850          E_Id := Get_Pragma_Arg (Arg1);
2851
2852          if Etype (E_Id) = Any_Type then
2853             return;
2854          end if;
2855
2856          E := Entity (E_Id);
2857          D := Declaration_Node (E);
2858          K := Nkind (D);
2859
2860          --  Check duplicate before we chain ourselves!
2861
2862          Check_Duplicate_Pragma (E);
2863
2864          --  Now check appropriateness of the entity
2865
2866          if Is_Type (E) then
2867             if Rep_Item_Too_Early (E, N)
2868                  or else
2869                Rep_Item_Too_Late (E, N)
2870             then
2871                return;
2872             else
2873                Check_First_Subtype (Arg1);
2874             end if;
2875
2876             if Prag_Id /= Pragma_Volatile then
2877                Set_Atomic (E);
2878                Set_Atomic (Underlying_Type (E));
2879                Set_Atomic (Base_Type (E));
2880             end if;
2881
2882             --  Attribute belongs on the base type. If the view of the type is
2883             --  currently private, it also belongs on the underlying type.
2884
2885             Set_Is_Volatile (Base_Type (E));
2886             Set_Is_Volatile (Underlying_Type (E));
2887
2888             Set_Treat_As_Volatile (E);
2889             Set_Treat_As_Volatile (Underlying_Type (E));
2890
2891          elsif K = N_Object_Declaration
2892            or else (K = N_Component_Declaration
2893                      and then Original_Record_Component (E) = E)
2894          then
2895             if Rep_Item_Too_Late (E, N) then
2896                return;
2897             end if;
2898
2899             if Prag_Id /= Pragma_Volatile then
2900                Set_Is_Atomic (E);
2901
2902                --  If the object declaration has an explicit initialization, a
2903                --  temporary may have to be created to hold the expression, to
2904                --  ensure that access to the object remain atomic.
2905
2906                if Nkind (Parent (E)) = N_Object_Declaration
2907                  and then Present (Expression (Parent (E)))
2908                then
2909                   Set_Has_Delayed_Freeze (E);
2910                end if;
2911
2912                --  An interesting improvement here. If an object of type X is
2913                --  declared atomic, and the type X is not atomic, that's a
2914                --  pity, since it may not have appropriate alignment etc. We
2915                --  can rescue this in the special case where the object and
2916                --  type are in the same unit by just setting the type as
2917                --  atomic, so that the back end will process it as atomic.
2918
2919                Utyp := Underlying_Type (Etype (E));
2920
2921                if Present (Utyp)
2922                  and then Sloc (E) > No_Location
2923                  and then Sloc (Utyp) > No_Location
2924                  and then
2925                    Get_Source_File_Index (Sloc (E)) =
2926                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2927                then
2928                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2929                end if;
2930             end if;
2931
2932             Set_Is_Volatile (E);
2933             Set_Treat_As_Volatile (E);
2934
2935          else
2936             Error_Pragma_Arg
2937               ("inappropriate entity for pragma%", Arg1);
2938          end if;
2939       end Process_Atomic_Shared_Volatile;
2940
2941       -------------------------------------------
2942       -- Process_Compile_Time_Warning_Or_Error --
2943       -------------------------------------------
2944
2945       procedure Process_Compile_Time_Warning_Or_Error is
2946          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2947
2948       begin
2949          Check_Arg_Count (2);
2950          Check_No_Identifiers;
2951          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2952          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2953
2954          if Compile_Time_Known_Value (Arg1x) then
2955             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2956                declare
2957                   Str   : constant String_Id :=
2958                             Strval (Get_Pragma_Arg (Arg2));
2959                   Len   : constant Int := String_Length (Str);
2960                   Cont  : Boolean;
2961                   Ptr   : Nat;
2962                   CC    : Char_Code;
2963                   C     : Character;
2964                   Cent  : constant Entity_Id :=
2965                             Cunit_Entity (Current_Sem_Unit);
2966
2967                   Force : constant Boolean :=
2968                             Prag_Id = Pragma_Compile_Time_Warning
2969                               and then
2970                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2971                               and then (Ekind (Cent) /= E_Package
2972                                           or else not In_Private_Part (Cent));
2973                   --  Set True if this is the warning case, and we are in the
2974                   --  visible part of a package spec, or in a subprogram spec,
2975                   --  in which case we want to force the client to see the
2976                   --  warning, even though it is not in the main unit.
2977
2978                begin
2979                   --  Loop through segments of message separated by line feeds.
2980                   --  We output these segments as separate messages with
2981                   --  continuation marks for all but the first.
2982
2983                   Cont := False;
2984                   Ptr := 1;
2985                   loop
2986                      Error_Msg_Strlen := 0;
2987
2988                      --  Loop to copy characters from argument to error message
2989                      --  string buffer.
2990
2991                      loop
2992                         exit when Ptr > Len;
2993                         CC := Get_String_Char (Str, Ptr);
2994                         Ptr := Ptr + 1;
2995
2996                         --  Ignore wide chars ??? else store character
2997
2998                         if In_Character_Range (CC) then
2999                            C := Get_Character (CC);
3000                            exit when C = ASCII.LF;
3001                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
3002                            Error_Msg_String (Error_Msg_Strlen) := C;
3003                         end if;
3004                      end loop;
3005
3006                      --  Here with one line ready to go
3007
3008                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3009
3010                      --  If this is a warning in a spec, then we want clients
3011                      --  to see the warning, so mark the message with the
3012                      --  special sequence !! to force the warning. In the case
3013                      --  of a package spec, we do not force this if we are in
3014                      --  the private part of the spec.
3015
3016                      if Force then
3017                         if Cont = False then
3018                            Error_Msg_N ("<~!!", Arg1);
3019                            Cont := True;
3020                         else
3021                            Error_Msg_N ("\<~!!", Arg1);
3022                         end if;
3023
3024                      --  Error, rather than warning, or in a body, so we do not
3025                      --  need to force visibility for client (error will be
3026                      --  output in any case, and this is the situation in which
3027                      --  we do not want a client to get a warning, since the
3028                      --  warning is in the body or the spec private part).
3029
3030                      else
3031                         if Cont = False then
3032                            Error_Msg_N ("<~", Arg1);
3033                            Cont := True;
3034                         else
3035                            Error_Msg_N ("\<~", Arg1);
3036                         end if;
3037                      end if;
3038
3039                      exit when Ptr > Len;
3040                   end loop;
3041                end;
3042             end if;
3043          end if;
3044       end Process_Compile_Time_Warning_Or_Error;
3045
3046       ------------------------
3047       -- Process_Convention --
3048       ------------------------
3049
3050       procedure Process_Convention
3051         (C   : out Convention_Id;
3052          Ent : out Entity_Id)
3053       is
3054          Id        : Node_Id;
3055          E         : Entity_Id;
3056          E1        : Entity_Id;
3057          Cname     : Name_Id;
3058          Comp_Unit : Unit_Number_Type;
3059
3060          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3061          --  Called if we have more than one Export/Import/Convention pragma.
3062          --  This is generally illegal, but we have a special case of allowing
3063          --  Import and Interface to coexist if they specify the convention in
3064          --  a consistent manner. We are allowed to do this, since Interface is
3065          --  an implementation defined pragma, and we choose to do it since we
3066          --  know Rational allows this combination. S is the entity id of the
3067          --  subprogram in question. This procedure also sets the special flag
3068          --  Import_Interface_Present in both pragmas in the case where we do
3069          --  have matching Import and Interface pragmas.
3070
3071          procedure Set_Convention_From_Pragma (E : Entity_Id);
3072          --  Set convention in entity E, and also flag that the entity has a
3073          --  convention pragma. If entity is for a private or incomplete type,
3074          --  also set convention and flag on underlying type. This procedure
3075          --  also deals with the special case of C_Pass_By_Copy convention.
3076
3077          -------------------------------
3078          -- Diagnose_Multiple_Pragmas --
3079          -------------------------------
3080
3081          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3082             Pdec : constant Node_Id := Declaration_Node (S);
3083             Decl : Node_Id;
3084             Err  : Boolean;
3085
3086             function Same_Convention (Decl : Node_Id) return Boolean;
3087             --  Decl is a pragma node. This function returns True if this
3088             --  pragma has a first argument that is an identifier with a
3089             --  Chars field corresponding to the Convention_Id C.
3090
3091             function Same_Name (Decl : Node_Id) return Boolean;
3092             --  Decl is a pragma node. This function returns True if this
3093             --  pragma has a second argument that is an identifier with a
3094             --  Chars field that matches the Chars of the current subprogram.
3095
3096             ---------------------
3097             -- Same_Convention --
3098             ---------------------
3099
3100             function Same_Convention (Decl : Node_Id) return Boolean is
3101                Arg1 : constant Node_Id :=
3102                         First (Pragma_Argument_Associations (Decl));
3103
3104             begin
3105                if Present (Arg1) then
3106                   declare
3107                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3108                   begin
3109                      if Nkind (Arg) = N_Identifier
3110                        and then Is_Convention_Name (Chars (Arg))
3111                        and then Get_Convention_Id (Chars (Arg)) = C
3112                      then
3113                         return True;
3114                      end if;
3115                   end;
3116                end if;
3117
3118                return False;
3119             end Same_Convention;
3120
3121             ---------------
3122             -- Same_Name --
3123             ---------------
3124
3125             function Same_Name (Decl : Node_Id) return Boolean is
3126                Arg1 : constant Node_Id :=
3127                         First (Pragma_Argument_Associations (Decl));
3128                Arg2 : Node_Id;
3129
3130             begin
3131                if No (Arg1) then
3132                   return False;
3133                end if;
3134
3135                Arg2 := Next (Arg1);
3136
3137                if No (Arg2) then
3138                   return False;
3139                end if;
3140
3141                declare
3142                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3143                begin
3144                   if Nkind (Arg) = N_Identifier
3145                     and then Chars (Arg) = Chars (S)
3146                   then
3147                      return True;
3148                   end if;
3149                end;
3150
3151                return False;
3152             end Same_Name;
3153
3154          --  Start of processing for Diagnose_Multiple_Pragmas
3155
3156          begin
3157             Err := True;
3158
3159             --  Definitely give message if we have Convention/Export here
3160
3161             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3162                null;
3163
3164                --  If we have an Import or Export, scan back from pragma to
3165                --  find any previous pragma applying to the same procedure.
3166                --  The scan will be terminated by the start of the list, or
3167                --  hitting the subprogram declaration. This won't allow one
3168                --  pragma to appear in the public part and one in the private
3169                --  part, but that seems very unlikely in practice.
3170
3171             else
3172                Decl := Prev (N);
3173                while Present (Decl) and then Decl /= Pdec loop
3174
3175                   --  Look for pragma with same name as us
3176
3177                   if Nkind (Decl) = N_Pragma
3178                     and then Same_Name (Decl)
3179                   then
3180                      --  Give error if same as our pragma or Export/Convention
3181
3182                      if Pragma_Name (Decl) = Name_Export
3183                           or else
3184                         Pragma_Name (Decl) = Name_Convention
3185                           or else
3186                         Pragma_Name (Decl) = Pragma_Name (N)
3187                      then
3188                         exit;
3189
3190                      --  Case of Import/Interface or the other way round
3191
3192                      elsif Pragma_Name (Decl) = Name_Interface
3193                              or else
3194                            Pragma_Name (Decl) = Name_Import
3195                      then
3196                         --  Here we know that we have Import and Interface. It
3197                         --  doesn't matter which way round they are. See if
3198                         --  they specify the same convention. If so, all OK,
3199                         --  and set special flags to stop other messages
3200
3201                         if Same_Convention (Decl) then
3202                            Set_Import_Interface_Present (N);
3203                            Set_Import_Interface_Present (Decl);
3204                            Err := False;
3205
3206                         --  If different conventions, special message
3207
3208                         else
3209                            Error_Msg_Sloc := Sloc (Decl);
3210                            Error_Pragma_Arg
3211                              ("convention differs from that given#", Arg1);
3212                            return;
3213                         end if;
3214                      end if;
3215                   end if;
3216
3217                   Next (Decl);
3218                end loop;
3219             end if;
3220
3221             --  Give message if needed if we fall through those tests
3222
3223             if Err then
3224                Error_Pragma_Arg
3225                  ("at most one Convention/Export/Import pragma is allowed",
3226                   Arg2);
3227             end if;
3228          end Diagnose_Multiple_Pragmas;
3229
3230          --------------------------------
3231          -- Set_Convention_From_Pragma --
3232          --------------------------------
3233
3234          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3235          begin
3236             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3237             --  for an overridden dispatching operation. Technically this is
3238             --  an amendment and should only be done in Ada 2005 mode. However,
3239             --  this is clearly a mistake, since the problem that is addressed
3240             --  by this AI is that there is a clear gap in the RM!
3241
3242             if Is_Dispatching_Operation (E)
3243               and then Present (Overridden_Operation (E))
3244               and then C /= Convention (Overridden_Operation (E))
3245             then
3246                Error_Pragma_Arg
3247                  ("cannot change convention for " &
3248                   "overridden dispatching operation",
3249                   Arg1);
3250             end if;
3251
3252             --  Set the convention
3253
3254             Set_Convention (E, C);
3255             Set_Has_Convention_Pragma (E);
3256
3257             if Is_Incomplete_Or_Private_Type (E)
3258               and then Present (Underlying_Type (E))
3259             then
3260                Set_Convention            (Underlying_Type (E), C);
3261                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3262             end if;
3263
3264             --  A class-wide type should inherit the convention of the specific
3265             --  root type (although this isn't specified clearly by the RM).
3266
3267             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3268                Set_Convention (Class_Wide_Type (E), C);
3269             end if;
3270
3271             --  If the entity is a record type, then check for special case of
3272             --  C_Pass_By_Copy, which is treated the same as C except that the
3273             --  special record flag is set. This convention is only permitted
3274             --  on record types (see AI95-00131).
3275
3276             if Cname = Name_C_Pass_By_Copy then
3277                if Is_Record_Type (E) then
3278                   Set_C_Pass_By_Copy (Base_Type (E));
3279                elsif Is_Incomplete_Or_Private_Type (E)
3280                  and then Is_Record_Type (Underlying_Type (E))
3281                then
3282                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3283                else
3284                   Error_Pragma_Arg
3285                     ("C_Pass_By_Copy convention allowed only for record type",
3286                      Arg2);
3287                end if;
3288             end if;
3289
3290             --  If the entity is a derived boolean type, check for the special
3291             --  case of convention C, C++, or Fortran, where we consider any
3292             --  nonzero value to represent true.
3293
3294             if Is_Discrete_Type (E)
3295               and then Root_Type (Etype (E)) = Standard_Boolean
3296               and then
3297                 (C = Convention_C
3298                    or else
3299                  C = Convention_CPP
3300                    or else
3301                  C = Convention_Fortran)
3302             then
3303                Set_Nonzero_Is_True (Base_Type (E));
3304             end if;
3305          end Set_Convention_From_Pragma;
3306
3307       --  Start of processing for Process_Convention
3308
3309       begin
3310          Check_At_Least_N_Arguments (2);
3311          Check_Optional_Identifier (Arg1, Name_Convention);
3312          Check_Arg_Is_Identifier (Arg1);
3313          Cname := Chars (Get_Pragma_Arg (Arg1));
3314
3315          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3316          --  tested again below to set the critical flag).
3317
3318          if Cname = Name_C_Pass_By_Copy then
3319             C := Convention_C;
3320
3321          --  Otherwise we must have something in the standard convention list
3322
3323          elsif Is_Convention_Name (Cname) then
3324             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3325
3326          --  In DEC VMS, it seems that there is an undocumented feature that
3327          --  any unrecognized convention is treated as the default, which for
3328          --  us is convention C. It does not seem so terrible to do this
3329          --  unconditionally, silently in the VMS case, and with a warning
3330          --  in the non-VMS case.
3331
3332          else
3333             if Warn_On_Export_Import and not OpenVMS_On_Target then
3334                Error_Msg_N
3335                  ("?unrecognized convention name, C assumed",
3336                   Get_Pragma_Arg (Arg1));
3337             end if;
3338
3339             C := Convention_C;
3340          end if;
3341
3342          Check_Optional_Identifier (Arg2, Name_Entity);
3343          Check_Arg_Is_Local_Name (Arg2);
3344
3345          Id := Get_Pragma_Arg (Arg2);
3346          Analyze (Id);
3347
3348          if not Is_Entity_Name (Id) then
3349             Error_Pragma_Arg ("entity name required", Arg2);
3350          end if;
3351
3352          E := Entity (Id);
3353
3354          --  Set entity to return
3355
3356          Ent := E;
3357
3358          --  Ada_Pass_By_Copy special checking
3359
3360          if C = Convention_Ada_Pass_By_Copy then
3361             if not Is_First_Subtype (E) then
3362                Error_Pragma_Arg
3363                  ("convention `Ada_Pass_By_Copy` only "
3364                   & "allowed for types", Arg2);
3365             end if;
3366
3367             if Is_By_Reference_Type (E) then
3368                Error_Pragma_Arg
3369                  ("convention `Ada_Pass_By_Copy` not allowed for "
3370                   & "by-reference type", Arg1);
3371             end if;
3372          end if;
3373
3374          --  Ada_Pass_By_Reference special checking
3375
3376          if C = Convention_Ada_Pass_By_Reference then
3377             if not Is_First_Subtype (E) then
3378                Error_Pragma_Arg
3379                  ("convention `Ada_Pass_By_Reference` only "
3380                   & "allowed for types", Arg2);
3381             end if;
3382
3383             if Is_By_Copy_Type (E) then
3384                Error_Pragma_Arg
3385                  ("convention `Ada_Pass_By_Reference` not allowed for "
3386                   & "by-copy type", Arg1);
3387             end if;
3388          end if;
3389
3390          --  Go to renamed subprogram if present, since convention applies to
3391          --  the actual renamed entity, not to the renaming entity. If the
3392          --  subprogram is inherited, go to parent subprogram.
3393
3394          if Is_Subprogram (E)
3395            and then Present (Alias (E))
3396          then
3397             if Nkind (Parent (Declaration_Node (E))) =
3398                                        N_Subprogram_Renaming_Declaration
3399             then
3400                if Scope (E) /= Scope (Alias (E)) then
3401                   Error_Pragma_Ref
3402                     ("cannot apply pragma% to non-local entity&#", E);
3403                end if;
3404
3405                E := Alias (E);
3406
3407             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3408                                         N_Private_Extension_Declaration)
3409               and then Scope (E) = Scope (Alias (E))
3410             then
3411                E := Alias (E);
3412
3413                --  Return the parent subprogram the entity was inherited from
3414
3415                Ent := E;
3416             end if;
3417          end if;
3418
3419          --  Check that we are not applying this to a specless body
3420
3421          if Is_Subprogram (E)
3422            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3423          then
3424             Error_Pragma
3425               ("pragma% requires separate spec and must come before body");
3426          end if;
3427
3428          --  Check that we are not applying this to a named constant
3429
3430          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3431             Error_Msg_Name_1 := Pname;
3432             Error_Msg_N
3433               ("cannot apply pragma% to named constant!",
3434                Get_Pragma_Arg (Arg2));
3435             Error_Pragma_Arg
3436               ("\supply appropriate type for&!", Arg2);
3437          end if;
3438
3439          if Ekind (E) = E_Enumeration_Literal then
3440             Error_Pragma ("enumeration literal not allowed for pragma%");
3441          end if;
3442
3443          --  Check for rep item appearing too early or too late
3444
3445          if Etype (E) = Any_Type
3446            or else Rep_Item_Too_Early (E, N)
3447          then
3448             raise Pragma_Exit;
3449
3450          elsif Present (Underlying_Type (E)) then
3451             E := Underlying_Type (E);
3452          end if;
3453
3454          if Rep_Item_Too_Late (E, N) then
3455             raise Pragma_Exit;
3456          end if;
3457
3458          if Has_Convention_Pragma (E) then
3459             Diagnose_Multiple_Pragmas (E);
3460
3461          elsif Convention (E) = Convention_Protected
3462            or else Ekind (Scope (E)) = E_Protected_Type
3463          then
3464             Error_Pragma_Arg
3465               ("a protected operation cannot be given a different convention",
3466                 Arg2);
3467          end if;
3468
3469          --  For Intrinsic, a subprogram is required
3470
3471          if C = Convention_Intrinsic
3472            and then not Is_Subprogram (E)
3473            and then not Is_Generic_Subprogram (E)
3474          then
3475             Error_Pragma_Arg
3476               ("second argument of pragma% must be a subprogram", Arg2);
3477          end if;
3478
3479          --  For Stdcall, a subprogram, variable or subprogram type is required
3480
3481          if C = Convention_Stdcall
3482            and then not Is_Subprogram (E)
3483            and then not Is_Generic_Subprogram (E)
3484            and then Ekind (E) /= E_Variable
3485            and then not
3486              (Is_Access_Type (E)
3487                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3488          then
3489             Error_Pragma_Arg
3490               ("second argument of pragma% must be subprogram (type)",
3491                Arg2);
3492          end if;
3493
3494          if not Is_Subprogram (E)
3495            and then not Is_Generic_Subprogram (E)
3496          then
3497             Set_Convention_From_Pragma (E);
3498
3499             if Is_Type (E) then
3500                Check_First_Subtype (Arg2);
3501                Set_Convention_From_Pragma (Base_Type (E));
3502
3503                --  For subprograms, we must set the convention on the
3504                --  internally generated directly designated type as well.
3505
3506                if Ekind (E) = E_Access_Subprogram_Type then
3507                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3508                end if;
3509             end if;
3510
3511          --  For the subprogram case, set proper convention for all homonyms
3512          --  in same scope and the same declarative part, i.e. the same
3513          --  compilation unit.
3514
3515          else
3516             Comp_Unit := Get_Source_Unit (E);
3517             Set_Convention_From_Pragma (E);
3518
3519             --  Treat a pragma Import as an implicit body, for GPS use
3520
3521             if Prag_Id = Pragma_Import then
3522                Generate_Reference (E, Id, 'b');
3523             end if;
3524
3525             --  Loop through the homonyms of the pragma argument's entity
3526
3527             E1 := Ent;
3528             loop
3529                E1 := Homonym (E1);
3530                exit when No (E1) or else Scope (E1) /= Current_Scope;
3531
3532                --  Do not set the pragma on inherited operations or on formal
3533                --  subprograms.
3534
3535                if Comes_From_Source (E1)
3536                  and then Comp_Unit = Get_Source_Unit (E1)
3537                  and then not Is_Formal_Subprogram (E1)
3538                  and then Nkind (Original_Node (Parent (E1))) /=
3539                                                     N_Full_Type_Declaration
3540                then
3541                   if Present (Alias (E1))
3542                     and then Scope (E1) /= Scope (Alias (E1))
3543                   then
3544                      Error_Pragma_Ref
3545                        ("cannot apply pragma% to non-local entity& declared#",
3546                         E1);
3547                   end if;
3548
3549                   Set_Convention_From_Pragma (E1);
3550
3551                   if Prag_Id = Pragma_Import then
3552                      Generate_Reference (E1, Id, 'b');
3553                   end if;
3554                end if;
3555
3556                --  For aspect case, do NOT apply to homonyms
3557
3558                exit when From_Aspect_Specification (N);
3559             end loop;
3560          end if;
3561       end Process_Convention;
3562
3563       -----------------------------------------------------
3564       -- Process_Extended_Import_Export_Exception_Pragma --
3565       -----------------------------------------------------
3566
3567       procedure Process_Extended_Import_Export_Exception_Pragma
3568         (Arg_Internal : Node_Id;
3569          Arg_External : Node_Id;
3570          Arg_Form     : Node_Id;
3571          Arg_Code     : Node_Id)
3572       is
3573          Def_Id   : Entity_Id;
3574          Code_Val : Uint;
3575
3576       begin
3577          if not OpenVMS_On_Target then
3578             Error_Pragma
3579               ("?pragma% ignored (applies only to Open'V'M'S)");
3580          end if;
3581
3582          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3583          Def_Id := Entity (Arg_Internal);
3584
3585          if Ekind (Def_Id) /= E_Exception then
3586             Error_Pragma_Arg
3587               ("pragma% must refer to declared exception", Arg_Internal);
3588          end if;
3589
3590          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3591
3592          if Present (Arg_Form) then
3593             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3594          end if;
3595
3596          if Present (Arg_Form)
3597            and then Chars (Arg_Form) = Name_Ada
3598          then
3599             null;
3600          else
3601             Set_Is_VMS_Exception (Def_Id);
3602             Set_Exception_Code (Def_Id, No_Uint);
3603          end if;
3604
3605          if Present (Arg_Code) then
3606             if not Is_VMS_Exception (Def_Id) then
3607                Error_Pragma_Arg
3608                  ("Code option for pragma% not allowed for Ada case",
3609                   Arg_Code);
3610             end if;
3611
3612             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3613             Code_Val := Expr_Value (Arg_Code);
3614
3615             if not UI_Is_In_Int_Range (Code_Val) then
3616                Error_Pragma_Arg
3617                  ("Code option for pragma% must be in 32-bit range",
3618                   Arg_Code);
3619
3620             else
3621                Set_Exception_Code (Def_Id, Code_Val);
3622             end if;
3623          end if;
3624       end Process_Extended_Import_Export_Exception_Pragma;
3625
3626       -------------------------------------------------
3627       -- Process_Extended_Import_Export_Internal_Arg --
3628       -------------------------------------------------
3629
3630       procedure Process_Extended_Import_Export_Internal_Arg
3631         (Arg_Internal : Node_Id := Empty)
3632       is
3633       begin
3634          if No (Arg_Internal) then
3635             Error_Pragma ("Internal parameter required for pragma%");
3636          end if;
3637
3638          if Nkind (Arg_Internal) = N_Identifier then
3639             null;
3640
3641          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3642            and then (Prag_Id = Pragma_Import_Function
3643                        or else
3644                      Prag_Id = Pragma_Export_Function)
3645          then
3646             null;
3647
3648          else
3649             Error_Pragma_Arg
3650               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3651          end if;
3652
3653          Check_Arg_Is_Local_Name (Arg_Internal);
3654       end Process_Extended_Import_Export_Internal_Arg;
3655
3656       --------------------------------------------------
3657       -- Process_Extended_Import_Export_Object_Pragma --
3658       --------------------------------------------------
3659
3660       procedure Process_Extended_Import_Export_Object_Pragma
3661         (Arg_Internal : Node_Id;
3662          Arg_External : Node_Id;
3663          Arg_Size     : Node_Id)
3664       is
3665          Def_Id : Entity_Id;
3666
3667       begin
3668          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3669          Def_Id := Entity (Arg_Internal);
3670
3671          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3672             Error_Pragma_Arg
3673               ("pragma% must designate an object", Arg_Internal);
3674          end if;
3675
3676          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3677               or else
3678             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3679          then
3680             Error_Pragma_Arg
3681               ("previous Common/Psect_Object applies, pragma % not permitted",
3682                Arg_Internal);
3683          end if;
3684
3685          if Rep_Item_Too_Late (Def_Id, N) then
3686             raise Pragma_Exit;
3687          end if;
3688
3689          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3690
3691          if Present (Arg_Size) then
3692             Check_Arg_Is_External_Name (Arg_Size);
3693          end if;
3694
3695          --  Export_Object case
3696
3697          if Prag_Id = Pragma_Export_Object then
3698             if not Is_Library_Level_Entity (Def_Id) then
3699                Error_Pragma_Arg
3700                  ("argument for pragma% must be library level entity",
3701                   Arg_Internal);
3702             end if;
3703
3704             if Ekind (Current_Scope) = E_Generic_Package then
3705                Error_Pragma ("pragma& cannot appear in a generic unit");
3706             end if;
3707
3708             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3709                Error_Pragma_Arg
3710                  ("exported object must have compile time known size",
3711                   Arg_Internal);
3712             end if;
3713
3714             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3715                Error_Msg_N ("?duplicate Export_Object pragma", N);
3716             else
3717                Set_Exported (Def_Id, Arg_Internal);
3718             end if;
3719
3720          --  Import_Object case
3721
3722          else
3723             if Is_Concurrent_Type (Etype (Def_Id)) then
3724                Error_Pragma_Arg
3725                  ("cannot use pragma% for task/protected object",
3726                   Arg_Internal);
3727             end if;
3728
3729             if Ekind (Def_Id) = E_Constant then
3730                Error_Pragma_Arg
3731                  ("cannot import a constant", Arg_Internal);
3732             end if;
3733
3734             if Warn_On_Export_Import
3735               and then Has_Discriminants (Etype (Def_Id))
3736             then
3737                Error_Msg_N
3738                  ("imported value must be initialized?", Arg_Internal);
3739             end if;
3740
3741             if Warn_On_Export_Import
3742               and then Is_Access_Type (Etype (Def_Id))
3743             then
3744                Error_Pragma_Arg
3745                  ("cannot import object of an access type?", Arg_Internal);
3746             end if;
3747
3748             if Warn_On_Export_Import
3749               and then Is_Imported (Def_Id)
3750             then
3751                Error_Msg_N
3752                  ("?duplicate Import_Object pragma", N);
3753
3754             --  Check for explicit initialization present. Note that an
3755             --  initialization generated by the code generator, e.g. for an
3756             --  access type, does not count here.
3757
3758             elsif Present (Expression (Parent (Def_Id)))
3759                and then
3760                  Comes_From_Source
3761                    (Original_Node (Expression (Parent (Def_Id))))
3762             then
3763                Error_Msg_Sloc := Sloc (Def_Id);
3764                Error_Pragma_Arg
3765                  ("imported entities cannot be initialized (RM B.1(24))",
3766                   "\no initialization allowed for & declared#", Arg1);
3767             else
3768                Set_Imported (Def_Id);
3769                Note_Possible_Modification (Arg_Internal, Sure => False);
3770             end if;
3771          end if;
3772       end Process_Extended_Import_Export_Object_Pragma;
3773
3774       ------------------------------------------------------
3775       -- Process_Extended_Import_Export_Subprogram_Pragma --
3776       ------------------------------------------------------
3777
3778       procedure Process_Extended_Import_Export_Subprogram_Pragma
3779         (Arg_Internal                 : Node_Id;
3780          Arg_External                 : Node_Id;
3781          Arg_Parameter_Types          : Node_Id;
3782          Arg_Result_Type              : Node_Id := Empty;
3783          Arg_Mechanism                : Node_Id;
3784          Arg_Result_Mechanism         : Node_Id := Empty;
3785          Arg_First_Optional_Parameter : Node_Id := Empty)
3786       is
3787          Ent       : Entity_Id;
3788          Def_Id    : Entity_Id;
3789          Hom_Id    : Entity_Id;
3790          Formal    : Entity_Id;
3791          Ambiguous : Boolean;
3792          Match     : Boolean;
3793          Dval      : Node_Id;
3794
3795          function Same_Base_Type
3796           (Ptype  : Node_Id;
3797            Formal : Entity_Id) return Boolean;
3798          --  Determines if Ptype references the type of Formal. Note that only
3799          --  the base types need to match according to the spec. Ptype here is
3800          --  the argument from the pragma, which is either a type name, or an
3801          --  access attribute.
3802
3803          --------------------
3804          -- Same_Base_Type --
3805          --------------------
3806
3807          function Same_Base_Type
3808            (Ptype  : Node_Id;
3809             Formal : Entity_Id) return Boolean
3810          is
3811             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3812             Pref : Node_Id;
3813
3814          begin
3815             --  Case where pragma argument is typ'Access
3816
3817             if Nkind (Ptype) = N_Attribute_Reference
3818               and then Attribute_Name (Ptype) = Name_Access
3819             then
3820                Pref := Prefix (Ptype);
3821                Find_Type (Pref);
3822
3823                if not Is_Entity_Name (Pref)
3824                  or else Entity (Pref) = Any_Type
3825                then
3826                   raise Pragma_Exit;
3827                end if;
3828
3829                --  We have a match if the corresponding argument is of an
3830                --  anonymous access type, and its designated type matches the
3831                --  type of the prefix of the access attribute
3832
3833                return Ekind (Ftyp) = E_Anonymous_Access_Type
3834                  and then Base_Type (Entity (Pref)) =
3835                             Base_Type (Etype (Designated_Type (Ftyp)));
3836
3837             --  Case where pragma argument is a type name
3838
3839             else
3840                Find_Type (Ptype);
3841
3842                if not Is_Entity_Name (Ptype)
3843                  or else Entity (Ptype) = Any_Type
3844                then
3845                   raise Pragma_Exit;
3846                end if;
3847
3848                --  We have a match if the corresponding argument is of the type
3849                --  given in the pragma (comparing base types)
3850
3851                return Base_Type (Entity (Ptype)) = Ftyp;
3852             end if;
3853          end Same_Base_Type;
3854
3855       --  Start of processing for
3856       --  Process_Extended_Import_Export_Subprogram_Pragma
3857
3858       begin
3859          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3860          Ent := Empty;
3861          Ambiguous := False;
3862
3863          --  Loop through homonyms (overloadings) of the entity
3864
3865          Hom_Id := Entity (Arg_Internal);
3866          while Present (Hom_Id) loop
3867             Def_Id := Get_Base_Subprogram (Hom_Id);
3868
3869             --  We need a subprogram in the current scope
3870
3871             if not Is_Subprogram (Def_Id)
3872               or else Scope (Def_Id) /= Current_Scope
3873             then
3874                null;
3875
3876             else
3877                Match := True;
3878
3879                --  Pragma cannot apply to subprogram body
3880
3881                if Is_Subprogram (Def_Id)
3882                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3883                                                              N_Subprogram_Body
3884                then
3885                   Error_Pragma
3886                     ("pragma% requires separate spec"
3887                       & " and must come before body");
3888                end if;
3889
3890                --  Test result type if given, note that the result type
3891                --  parameter can only be present for the function cases.
3892
3893                if Present (Arg_Result_Type)
3894                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3895                then
3896                   Match := False;
3897
3898                elsif Etype (Def_Id) /= Standard_Void_Type
3899                  and then
3900                    (Pname = Name_Export_Procedure
3901                       or else
3902                     Pname = Name_Import_Procedure)
3903                then
3904                   Match := False;
3905
3906                --  Test parameter types if given. Note that this parameter
3907                --  has not been analyzed (and must not be, since it is
3908                --  semantic nonsense), so we get it as the parser left it.
3909
3910                elsif Present (Arg_Parameter_Types) then
3911                   Check_Matching_Types : declare
3912                      Formal : Entity_Id;
3913                      Ptype  : Node_Id;
3914
3915                   begin
3916                      Formal := First_Formal (Def_Id);
3917
3918                      if Nkind (Arg_Parameter_Types) = N_Null then
3919                         if Present (Formal) then
3920                            Match := False;
3921                         end if;
3922
3923                      --  A list of one type, e.g. (List) is parsed as
3924                      --  a parenthesized expression.
3925
3926                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3927                        and then Paren_Count (Arg_Parameter_Types) = 1
3928                      then
3929                         if No (Formal)
3930                           or else Present (Next_Formal (Formal))
3931                         then
3932                            Match := False;
3933                         else
3934                            Match :=
3935                              Same_Base_Type (Arg_Parameter_Types, Formal);
3936                         end if;
3937
3938                      --  A list of more than one type is parsed as a aggregate
3939
3940                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3941                        and then Paren_Count (Arg_Parameter_Types) = 0
3942                      then
3943                         Ptype := First (Expressions (Arg_Parameter_Types));
3944                         while Present (Ptype) or else Present (Formal) loop
3945                            if No (Ptype)
3946                              or else No (Formal)
3947                              or else not Same_Base_Type (Ptype, Formal)
3948                            then
3949                               Match := False;
3950                               exit;
3951                            else
3952                               Next_Formal (Formal);
3953                               Next (Ptype);
3954                            end if;
3955                         end loop;
3956
3957                      --  Anything else is of the wrong form
3958
3959                      else
3960                         Error_Pragma_Arg
3961                           ("wrong form for Parameter_Types parameter",
3962                            Arg_Parameter_Types);
3963                      end if;
3964                   end Check_Matching_Types;
3965                end if;
3966
3967                --  Match is now False if the entry we found did not match
3968                --  either a supplied Parameter_Types or Result_Types argument
3969
3970                if Match then
3971                   if No (Ent) then
3972                      Ent := Def_Id;
3973
3974                   --  Ambiguous case, the flag Ambiguous shows if we already
3975                   --  detected this and output the initial messages.
3976
3977                   else
3978                      if not Ambiguous then
3979                         Ambiguous := True;
3980                         Error_Msg_Name_1 := Pname;
3981                         Error_Msg_N
3982                           ("pragma% does not uniquely identify subprogram!",
3983                            N);
3984                         Error_Msg_Sloc := Sloc (Ent);
3985                         Error_Msg_N ("matching subprogram #!", N);
3986                         Ent := Empty;
3987                      end if;
3988
3989                      Error_Msg_Sloc := Sloc (Def_Id);
3990                      Error_Msg_N ("matching subprogram #!", N);
3991                   end if;
3992                end if;
3993             end if;
3994
3995             Hom_Id := Homonym (Hom_Id);
3996          end loop;
3997
3998          --  See if we found an entry
3999
4000          if No (Ent) then
4001             if not Ambiguous then
4002                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4003                   Error_Pragma
4004                     ("pragma% cannot be given for generic subprogram");
4005                else
4006                   Error_Pragma
4007                     ("pragma% does not identify local subprogram");
4008                end if;
4009             end if;
4010
4011             return;
4012          end if;
4013
4014          --  Import pragmas must be for imported entities
4015
4016          if Prag_Id = Pragma_Import_Function
4017               or else
4018             Prag_Id = Pragma_Import_Procedure
4019               or else
4020             Prag_Id = Pragma_Import_Valued_Procedure
4021          then
4022             if not Is_Imported (Ent) then
4023                Error_Pragma
4024                  ("pragma Import or Interface must precede pragma%");
4025             end if;
4026
4027          --  Here we have the Export case which can set the entity as exported
4028
4029          --  But does not do so if the specified external name is null, since
4030          --  that is taken as a signal in DEC Ada 83 (with which we want to be
4031          --  compatible) to request no external name.
4032
4033          elsif Nkind (Arg_External) = N_String_Literal
4034            and then String_Length (Strval (Arg_External)) = 0
4035          then
4036             null;
4037
4038          --  In all other cases, set entity as exported
4039
4040          else
4041             Set_Exported (Ent, Arg_Internal);
4042          end if;
4043
4044          --  Special processing for Valued_Procedure cases
4045
4046          if Prag_Id = Pragma_Import_Valued_Procedure
4047            or else
4048             Prag_Id = Pragma_Export_Valued_Procedure
4049          then
4050             Formal := First_Formal (Ent);
4051
4052             if No (Formal) then
4053                Error_Pragma ("at least one parameter required for pragma%");
4054
4055             elsif Ekind (Formal) /= E_Out_Parameter then
4056                Error_Pragma ("first parameter must have mode out for pragma%");
4057
4058             else
4059                Set_Is_Valued_Procedure (Ent);
4060             end if;
4061          end if;
4062
4063          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4064
4065          --  Process Result_Mechanism argument if present. We have already
4066          --  checked that this is only allowed for the function case.
4067
4068          if Present (Arg_Result_Mechanism) then
4069             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4070          end if;
4071
4072          --  Process Mechanism parameter if present. Note that this parameter
4073          --  is not analyzed, and must not be analyzed since it is semantic
4074          --  nonsense, so we get it in exactly as the parser left it.
4075
4076          if Present (Arg_Mechanism) then
4077             declare
4078                Formal : Entity_Id;
4079                Massoc : Node_Id;
4080                Mname  : Node_Id;
4081                Choice : Node_Id;
4082
4083             begin
4084                --  A single mechanism association without a formal parameter
4085                --  name is parsed as a parenthesized expression. All other
4086                --  cases are parsed as aggregates, so we rewrite the single
4087                --  parameter case as an aggregate for consistency.
4088
4089                if Nkind (Arg_Mechanism) /= N_Aggregate
4090                  and then Paren_Count (Arg_Mechanism) = 1
4091                then
4092                   Rewrite (Arg_Mechanism,
4093                     Make_Aggregate (Sloc (Arg_Mechanism),
4094                       Expressions => New_List (
4095                         Relocate_Node (Arg_Mechanism))));
4096                end if;
4097
4098                --  Case of only mechanism name given, applies to all formals
4099
4100                if Nkind (Arg_Mechanism) /= N_Aggregate then
4101                   Formal := First_Formal (Ent);
4102                   while Present (Formal) loop
4103                      Set_Mechanism_Value (Formal, Arg_Mechanism);
4104                      Next_Formal (Formal);
4105                   end loop;
4106
4107                --  Case of list of mechanism associations given
4108
4109                else
4110                   if Null_Record_Present (Arg_Mechanism) then
4111                      Error_Pragma_Arg
4112                        ("inappropriate form for Mechanism parameter",
4113                         Arg_Mechanism);
4114                   end if;
4115
4116                   --  Deal with positional ones first
4117
4118                   Formal := First_Formal (Ent);
4119
4120                   if Present (Expressions (Arg_Mechanism)) then
4121                      Mname := First (Expressions (Arg_Mechanism));
4122                      while Present (Mname) loop
4123                         if No (Formal) then
4124                            Error_Pragma_Arg
4125                              ("too many mechanism associations", Mname);
4126                         end if;
4127
4128                         Set_Mechanism_Value (Formal, Mname);
4129                         Next_Formal (Formal);
4130                         Next (Mname);
4131                      end loop;
4132                   end if;
4133
4134                   --  Deal with named entries
4135
4136                   if Present (Component_Associations (Arg_Mechanism)) then
4137                      Massoc := First (Component_Associations (Arg_Mechanism));
4138                      while Present (Massoc) loop
4139                         Choice := First (Choices (Massoc));
4140
4141                         if Nkind (Choice) /= N_Identifier
4142                           or else Present (Next (Choice))
4143                         then
4144                            Error_Pragma_Arg
4145                              ("incorrect form for mechanism association",
4146                               Massoc);
4147                         end if;
4148
4149                         Formal := First_Formal (Ent);
4150                         loop
4151                            if No (Formal) then
4152                               Error_Pragma_Arg
4153                                 ("parameter name & not present", Choice);
4154                            end if;
4155
4156                            if Chars (Choice) = Chars (Formal) then
4157                               Set_Mechanism_Value
4158                                 (Formal, Expression (Massoc));
4159
4160                               --  Set entity on identifier (needed by ASIS)
4161
4162                               Set_Entity (Choice, Formal);
4163
4164                               exit;
4165                            end if;
4166
4167                            Next_Formal (Formal);
4168                         end loop;
4169
4170                         Next (Massoc);
4171                      end loop;
4172                   end if;
4173                end if;
4174             end;
4175          end if;
4176
4177          --  Process First_Optional_Parameter argument if present. We have
4178          --  already checked that this is only allowed for the Import case.
4179
4180          if Present (Arg_First_Optional_Parameter) then
4181             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4182                Error_Pragma_Arg
4183                  ("first optional parameter must be formal parameter name",
4184                   Arg_First_Optional_Parameter);
4185             end if;
4186
4187             Formal := First_Formal (Ent);
4188             loop
4189                if No (Formal) then
4190                   Error_Pragma_Arg
4191                     ("specified formal parameter& not found",
4192                      Arg_First_Optional_Parameter);
4193                end if;
4194
4195                exit when Chars (Formal) =
4196                          Chars (Arg_First_Optional_Parameter);
4197
4198                Next_Formal (Formal);
4199             end loop;
4200
4201             Set_First_Optional_Parameter (Ent, Formal);
4202
4203             --  Check specified and all remaining formals have right form
4204
4205             while Present (Formal) loop
4206                if Ekind (Formal) /= E_In_Parameter then
4207                   Error_Msg_NE
4208                     ("optional formal& is not of mode in!",
4209                      Arg_First_Optional_Parameter, Formal);
4210
4211                else
4212                   Dval := Default_Value (Formal);
4213
4214                   if No (Dval) then
4215                      Error_Msg_NE
4216                        ("optional formal& does not have default value!",
4217                         Arg_First_Optional_Parameter, Formal);
4218
4219                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4220                      null;
4221
4222                   else
4223                      Error_Msg_FE
4224                        ("default value for optional formal& is non-static!",
4225                         Arg_First_Optional_Parameter, Formal);
4226                   end if;
4227                end if;
4228
4229                Set_Is_Optional_Parameter (Formal);
4230                Next_Formal (Formal);
4231             end loop;
4232          end if;
4233       end Process_Extended_Import_Export_Subprogram_Pragma;
4234
4235       --------------------------
4236       -- Process_Generic_List --
4237       --------------------------
4238
4239       procedure Process_Generic_List is
4240          Arg : Node_Id;
4241          Exp : Node_Id;
4242
4243       begin
4244          Check_No_Identifiers;
4245          Check_At_Least_N_Arguments (1);
4246
4247          Arg := Arg1;
4248          while Present (Arg) loop
4249             Exp := Get_Pragma_Arg (Arg);
4250             Analyze (Exp);
4251
4252             if not Is_Entity_Name (Exp)
4253               or else
4254                 (not Is_Generic_Instance (Entity (Exp))
4255                   and then
4256                  not Is_Generic_Unit (Entity (Exp)))
4257             then
4258                Error_Pragma_Arg
4259                  ("pragma% argument must be name of generic unit/instance",
4260                   Arg);
4261             end if;
4262
4263             Next (Arg);
4264          end loop;
4265       end Process_Generic_List;
4266
4267       ------------------------------------
4268       -- Process_Import_Predefined_Type --
4269       ------------------------------------
4270
4271       procedure Process_Import_Predefined_Type is
4272          Loc  : constant Source_Ptr := Sloc (N);
4273          Elmt : Elmt_Id;
4274          Ftyp : Node_Id := Empty;
4275          Decl : Node_Id;
4276          Def  : Node_Id;
4277          Nam  : Name_Id;
4278
4279       begin
4280          String_To_Name_Buffer (Strval (Expression (Arg3)));
4281          Nam := Name_Find;
4282
4283          Elmt := First_Elmt (Predefined_Float_Types);
4284          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4285             Next_Elmt (Elmt);
4286          end loop;
4287
4288          Ftyp := Node (Elmt);
4289
4290          if Present (Ftyp) then
4291
4292             --  Don't build a derived type declaration, because predefined C
4293             --  types have no declaration anywhere, so cannot really be named.
4294             --  Instead build a full type declaration, starting with an
4295             --  appropriate type definition is built
4296
4297             if Is_Floating_Point_Type (Ftyp) then
4298                Def := Make_Floating_Point_Definition (Loc,
4299                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4300                  Make_Real_Range_Specification (Loc,
4301                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4302                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4303
4304             --  Should never have a predefined type we cannot handle
4305
4306             else
4307                raise Program_Error;
4308             end if;
4309
4310             --  Build and insert a Full_Type_Declaration, which will be
4311             --  analyzed as soon as this list entry has been analyzed.
4312
4313             Decl := Make_Full_Type_Declaration (Loc,
4314               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4315               Type_Definition => Def);
4316
4317             Insert_After (N, Decl);
4318             Mark_Rewrite_Insertion (Decl);
4319
4320          else
4321             Error_Pragma_Arg ("no matching type found for pragma%",
4322             Arg2);
4323          end if;
4324       end Process_Import_Predefined_Type;
4325
4326       ---------------------------------
4327       -- Process_Import_Or_Interface --
4328       ---------------------------------
4329
4330       procedure Process_Import_Or_Interface is
4331          C      : Convention_Id;
4332          Def_Id : Entity_Id;
4333          Hom_Id : Entity_Id;
4334
4335       begin
4336          Process_Convention (C, Def_Id);
4337          Kill_Size_Check_Code (Def_Id);
4338          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4339
4340          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4341
4342             --  We do not permit Import to apply to a renaming declaration
4343
4344             if Present (Renamed_Object (Def_Id)) then
4345                Error_Pragma_Arg
4346                  ("pragma% not allowed for object renaming", Arg2);
4347
4348             --  User initialization is not allowed for imported object, but
4349             --  the object declaration may contain a default initialization,
4350             --  that will be discarded. Note that an explicit initialization
4351             --  only counts if it comes from source, otherwise it is simply
4352             --  the code generator making an implicit initialization explicit.
4353
4354             elsif Present (Expression (Parent (Def_Id)))
4355               and then Comes_From_Source (Expression (Parent (Def_Id)))
4356             then
4357                Error_Msg_Sloc := Sloc (Def_Id);
4358                Error_Pragma_Arg
4359                  ("no initialization allowed for declaration of& #",
4360                   "\imported entities cannot be initialized (RM B.1(24))",
4361                   Arg2);
4362
4363             else
4364                Set_Imported (Def_Id);
4365                Process_Interface_Name (Def_Id, Arg3, Arg4);
4366
4367                --  Note that we do not set Is_Public here. That's because we
4368                --  only want to set it if there is no address clause, and we
4369                --  don't know that yet, so we delay that processing till
4370                --  freeze time.
4371
4372                --  pragma Import completes deferred constants
4373
4374                if Ekind (Def_Id) = E_Constant then
4375                   Set_Has_Completion (Def_Id);
4376                end if;
4377
4378                --  It is not possible to import a constant of an unconstrained
4379                --  array type (e.g. string) because there is no simple way to
4380                --  write a meaningful subtype for it.
4381
4382                if Is_Array_Type (Etype (Def_Id))
4383                  and then not Is_Constrained (Etype (Def_Id))
4384                then
4385                   Error_Msg_NE
4386                     ("imported constant& must have a constrained subtype",
4387                       N, Def_Id);
4388                end if;
4389             end if;
4390
4391          elsif Is_Subprogram (Def_Id)
4392            or else Is_Generic_Subprogram (Def_Id)
4393          then
4394             --  If the name is overloaded, pragma applies to all of the denoted
4395             --  entities in the same declarative part.
4396
4397             Hom_Id := Def_Id;
4398             while Present (Hom_Id) loop
4399                Def_Id := Get_Base_Subprogram (Hom_Id);
4400
4401                --  Ignore inherited subprograms because the pragma will apply
4402                --  to the parent operation, which is the one called.
4403
4404                if Is_Overloadable (Def_Id)
4405                  and then Present (Alias (Def_Id))
4406                then
4407                   null;
4408
4409                --  If it is not a subprogram, it must be in an outer scope and
4410                --  pragma does not apply.
4411
4412                elsif not Is_Subprogram (Def_Id)
4413                  and then not Is_Generic_Subprogram (Def_Id)
4414                then
4415                   null;
4416
4417                --  The pragma does not apply to primitives of interfaces
4418
4419                elsif Is_Dispatching_Operation (Def_Id)
4420                  and then Present (Find_Dispatching_Type (Def_Id))
4421                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4422                then
4423                   null;
4424
4425                --  Verify that the homonym is in the same declarative part (not
4426                --  just the same scope).
4427
4428                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4429                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4430                then
4431                   exit;
4432
4433                else
4434                   Set_Imported (Def_Id);
4435
4436                   --  Reject an Import applied to an abstract subprogram
4437
4438                   if Is_Subprogram (Def_Id)
4439                     and then Is_Abstract_Subprogram (Def_Id)
4440                   then
4441                      Error_Msg_Sloc := Sloc (Def_Id);
4442                      Error_Msg_NE
4443                        ("cannot import abstract subprogram& declared#",
4444                         Arg2, Def_Id);
4445                   end if;
4446
4447                   --  Special processing for Convention_Intrinsic
4448
4449                   if C = Convention_Intrinsic then
4450
4451                      --  Link_Name argument not allowed for intrinsic
4452
4453                      Check_No_Link_Name;
4454
4455                      Set_Is_Intrinsic_Subprogram (Def_Id);
4456
4457                      --  If no external name is present, then check that this
4458                      --  is a valid intrinsic subprogram. If an external name
4459                      --  is present, then this is handled by the back end.
4460
4461                      if No (Arg3) then
4462                         Check_Intrinsic_Subprogram
4463                           (Def_Id, Get_Pragma_Arg (Arg2));
4464                      end if;
4465                   end if;
4466
4467                   --  All interfaced procedures need an external symbol created
4468                   --  for them since they are always referenced from another
4469                   --  object file.
4470
4471                   Set_Is_Public (Def_Id);
4472
4473                   --  Verify that the subprogram does not have a completion
4474                   --  through a renaming declaration. For other completions the
4475                   --  pragma appears as a too late representation.
4476
4477                   declare
4478                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4479
4480                   begin
4481                      if Present (Decl)
4482                        and then Nkind (Decl) = N_Subprogram_Declaration
4483                        and then Present (Corresponding_Body (Decl))
4484                        and then Nkind (Unit_Declaration_Node
4485                                         (Corresponding_Body (Decl))) =
4486                                              N_Subprogram_Renaming_Declaration
4487                      then
4488                         Error_Msg_Sloc := Sloc (Def_Id);
4489                         Error_Msg_NE
4490                           ("cannot import&, renaming already provided for " &
4491                            "declaration #", N, Def_Id);
4492                      end if;
4493                   end;
4494
4495                   Set_Has_Completion (Def_Id);
4496                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4497                end if;
4498
4499                if Is_Compilation_Unit (Hom_Id) then
4500
4501                   --  Its possible homonyms are not affected by the pragma.
4502                   --  Such homonyms might be present in the context of other
4503                   --  units being compiled.
4504
4505                   exit;
4506
4507                else
4508                   Hom_Id := Homonym (Hom_Id);
4509                end if;
4510             end loop;
4511
4512          --  When the convention is Java or CIL, we also allow Import to be
4513          --  given for packages, generic packages, exceptions, record
4514          --  components, and access to subprograms.
4515
4516          elsif (C = Convention_Java or else C = Convention_CIL)
4517            and then
4518              (Is_Package_Or_Generic_Package (Def_Id)
4519                or else Ekind (Def_Id) = E_Exception
4520                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4521                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4522          then
4523             Set_Imported (Def_Id);
4524             Set_Is_Public (Def_Id);
4525             Process_Interface_Name (Def_Id, Arg3, Arg4);
4526
4527          --  Import a CPP class
4528
4529          elsif Is_Record_Type (Def_Id)
4530            and then C = Convention_CPP
4531          then
4532             --  Types treated as CPP classes must be declared limited (note:
4533             --  this used to be a warning but there is no real benefit to it
4534             --  since we did effectively intend to treat the type as limited
4535             --  anyway).
4536
4537             if not Is_Limited_Type (Def_Id) then
4538                Error_Msg_N
4539                  ("imported 'C'P'P type must be limited",
4540                   Get_Pragma_Arg (Arg2));
4541             end if;
4542
4543             Set_Is_CPP_Class (Def_Id);
4544
4545             --  Imported CPP types must not have discriminants (because C++
4546             --  classes do not have discriminants).
4547
4548             if Has_Discriminants (Def_Id) then
4549                Error_Msg_N
4550                  ("imported 'C'P'P type cannot have discriminants",
4551                   First (Discriminant_Specifications
4552                           (Declaration_Node (Def_Id))));
4553             end if;
4554
4555             --  Components of imported CPP types must not have default
4556             --  expressions because the constructor (if any) is on the
4557             --  C++ side.
4558
4559             declare
4560                Tdef  : constant Node_Id :=
4561                          Type_Definition (Declaration_Node (Def_Id));
4562                Clist : Node_Id;
4563                Comp  : Node_Id;
4564
4565             begin
4566                if Nkind (Tdef) = N_Record_Definition then
4567                   Clist := Component_List (Tdef);
4568
4569                else
4570                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4571                   Clist := Component_List (Record_Extension_Part (Tdef));
4572                end if;
4573
4574                if Present (Clist) then
4575                   Comp := First (Component_Items (Clist));
4576                   while Present (Comp) loop
4577                      if Present (Expression (Comp)) then
4578                         Error_Msg_N
4579                           ("component of imported 'C'P'P type cannot have" &
4580                            " default expression", Expression (Comp));
4581                      end if;
4582
4583                      Next (Comp);
4584                   end loop;
4585                end if;
4586             end;
4587
4588          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4589             Check_No_Link_Name;
4590             Check_Arg_Count (3);
4591             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4592
4593             Process_Import_Predefined_Type;
4594
4595          else
4596             Error_Pragma_Arg
4597               ("second argument of pragma% must be object, subprogram" &
4598                " or incomplete type",
4599                Arg2);
4600          end if;
4601
4602          --  If this pragma applies to a compilation unit, then the unit, which
4603          --  is a subprogram, does not require (or allow) a body. We also do
4604          --  not need to elaborate imported procedures.
4605
4606          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4607             declare
4608                Cunit : constant Node_Id := Parent (Parent (N));
4609             begin
4610                Set_Body_Required (Cunit, False);
4611             end;
4612          end if;
4613       end Process_Import_Or_Interface;
4614
4615       --------------------
4616       -- Process_Inline --
4617       --------------------
4618
4619       procedure Process_Inline (Active : Boolean) is
4620          Assoc     : Node_Id;
4621          Decl      : Node_Id;
4622          Subp_Id   : Node_Id;
4623          Subp      : Entity_Id;
4624          Applies   : Boolean;
4625
4626          Effective : Boolean := False;
4627          --  Set True if inline has some effect, i.e. if there is at least one
4628          --  subprogram set as inlined as a result of the use of the pragma.
4629
4630          procedure Make_Inline (Subp : Entity_Id);
4631          --  Subp is the defining unit name of the subprogram declaration. Set
4632          --  the flag, as well as the flag in the corresponding body, if there
4633          --  is one present.
4634
4635          procedure Set_Inline_Flags (Subp : Entity_Id);
4636          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4637          --  Has_Pragma_Inline_Always for the Inline_Always case.
4638
4639          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4640          --  Returns True if it can be determined at this stage that inlining
4641          --  is not possible, for example if the body is available and contains
4642          --  exception handlers, we prevent inlining, since otherwise we can
4643          --  get undefined symbols at link time. This function also emits a
4644          --  warning if front-end inlining is enabled and the pragma appears
4645          --  too late.
4646          --
4647          --  ??? is business with link symbols still valid, or does it relate
4648          --  to front end ZCX which is being phased out ???
4649
4650          ---------------------------
4651          -- Inlining_Not_Possible --
4652          ---------------------------
4653
4654          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4655             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4656             Stats : Node_Id;
4657
4658          begin
4659             if Nkind (Decl) = N_Subprogram_Body then
4660                Stats := Handled_Statement_Sequence (Decl);
4661                return Present (Exception_Handlers (Stats))
4662                  or else Present (At_End_Proc (Stats));
4663
4664             elsif Nkind (Decl) = N_Subprogram_Declaration
4665               and then Present (Corresponding_Body (Decl))
4666             then
4667                if Front_End_Inlining
4668                  and then Analyzed (Corresponding_Body (Decl))
4669                then
4670                   Error_Msg_N ("pragma appears too late, ignored?", N);
4671                   return True;
4672
4673                --  If the subprogram is a renaming as body, the body is just a
4674                --  call to the renamed subprogram, and inlining is trivially
4675                --  possible.
4676
4677                elsif
4678                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4679                                              N_Subprogram_Renaming_Declaration
4680                then
4681                   return False;
4682
4683                else
4684                   Stats :=
4685                     Handled_Statement_Sequence
4686                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4687
4688                   return
4689                     Present (Exception_Handlers (Stats))
4690                       or else Present (At_End_Proc (Stats));
4691                end if;
4692
4693             else
4694                --  If body is not available, assume the best, the check is
4695                --  performed again when compiling enclosing package bodies.
4696
4697                return False;
4698             end if;
4699          end Inlining_Not_Possible;
4700
4701          -----------------
4702          -- Make_Inline --
4703          -----------------
4704
4705          procedure Make_Inline (Subp : Entity_Id) is
4706             Kind       : constant Entity_Kind := Ekind (Subp);
4707             Inner_Subp : Entity_Id   := Subp;
4708
4709          begin
4710             --  Ignore if bad type, avoid cascaded error
4711
4712             if Etype (Subp) = Any_Type then
4713                Applies := True;
4714                return;
4715
4716             --  Ignore if all inlining is suppressed
4717
4718             elsif Suppress_All_Inlining then
4719                Applies := True;
4720                return;
4721
4722             --  If inlining is not possible, for now do not treat as an error
4723
4724             elsif Inlining_Not_Possible (Subp) then
4725                Applies := True;
4726                return;
4727
4728             --  Here we have a candidate for inlining, but we must exclude
4729             --  derived operations. Otherwise we would end up trying to inline
4730             --  a phantom declaration, and the result would be to drag in a
4731             --  body which has no direct inlining associated with it. That
4732             --  would not only be inefficient but would also result in the
4733             --  backend doing cross-unit inlining in cases where it was
4734             --  definitely inappropriate to do so.
4735
4736             --  However, a simple Comes_From_Source test is insufficient, since
4737             --  we do want to allow inlining of generic instances which also do
4738             --  not come from source. We also need to recognize specs generated
4739             --  by the front-end for bodies that carry the pragma. Finally,
4740             --  predefined operators do not come from source but are not
4741             --  inlineable either.
4742
4743             elsif Is_Generic_Instance (Subp)
4744               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4745             then
4746                null;
4747
4748             elsif not Comes_From_Source (Subp)
4749               and then Scope (Subp) /= Standard_Standard
4750             then
4751                Applies := True;
4752                return;
4753             end if;
4754
4755             --  The referenced entity must either be the enclosing entity, or
4756             --  an entity declared within the current open scope.
4757
4758             if Present (Scope (Subp))
4759               and then Scope (Subp) /= Current_Scope
4760               and then Subp /= Current_Scope
4761             then
4762                Error_Pragma_Arg
4763                  ("argument of% must be entity in current scope", Assoc);
4764                return;
4765             end if;
4766
4767             --  Processing for procedure, operator or function. If subprogram
4768             --  is aliased (as for an instance) indicate that the renamed
4769             --  entity (if declared in the same unit) is inlined.
4770
4771             if Is_Subprogram (Subp) then
4772                Inner_Subp := Ultimate_Alias (Inner_Subp);
4773
4774                if In_Same_Source_Unit (Subp, Inner_Subp) then
4775                   Set_Inline_Flags (Inner_Subp);
4776
4777                   Decl := Parent (Parent (Inner_Subp));
4778
4779                   if Nkind (Decl) = N_Subprogram_Declaration
4780                     and then Present (Corresponding_Body (Decl))
4781                   then
4782                      Set_Inline_Flags (Corresponding_Body (Decl));
4783
4784                   elsif Is_Generic_Instance (Subp) then
4785
4786                      --  Indicate that the body needs to be created for
4787                      --  inlining subsequent calls. The instantiation node
4788                      --  follows the declaration of the wrapper package
4789                      --  created for it.
4790
4791                      if Scope (Subp) /= Standard_Standard
4792                        and then
4793                          Need_Subprogram_Instance_Body
4794                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4795                               Subp)
4796                      then
4797                         null;
4798                      end if;
4799
4800                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
4801                   --  appear in a formal part to apply to a formal subprogram.
4802                   --  Do not apply check within an instance or a formal package
4803                   --  the test will have been applied to the original generic.
4804
4805                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4806                     and then List_Containing (Decl) = List_Containing (N)
4807                     and then not In_Instance
4808                   then
4809                      Error_Msg_N
4810                        ("Inline cannot apply to a formal subprogram", N);
4811                   end if;
4812                end if;
4813
4814                Applies := True;
4815
4816             --  For a generic subprogram set flag as well, for use at the point
4817             --  of instantiation, to determine whether the body should be
4818             --  generated.
4819
4820             elsif Is_Generic_Subprogram (Subp) then
4821                Set_Inline_Flags (Subp);
4822                Applies := True;
4823
4824             --  Literals are by definition inlined
4825
4826             elsif Kind = E_Enumeration_Literal then
4827                null;
4828
4829             --  Anything else is an error
4830
4831             else
4832                Error_Pragma_Arg
4833                  ("expect subprogram name for pragma%", Assoc);
4834             end if;
4835          end Make_Inline;
4836
4837          ----------------------
4838          -- Set_Inline_Flags --
4839          ----------------------
4840
4841          procedure Set_Inline_Flags (Subp : Entity_Id) is
4842          begin
4843             if Active then
4844                Set_Is_Inlined (Subp);
4845             end if;
4846
4847             if not Has_Pragma_Inline (Subp) then
4848                Set_Has_Pragma_Inline (Subp);
4849                Effective := True;
4850             end if;
4851
4852             if Prag_Id = Pragma_Inline_Always then
4853                Set_Has_Pragma_Inline_Always (Subp);
4854             end if;
4855          end Set_Inline_Flags;
4856
4857       --  Start of processing for Process_Inline
4858
4859       begin
4860          Check_No_Identifiers;
4861          Check_At_Least_N_Arguments (1);
4862
4863          if Active then
4864             Inline_Processing_Required := True;
4865          end if;
4866
4867          Assoc := Arg1;
4868          while Present (Assoc) loop
4869             Subp_Id := Get_Pragma_Arg (Assoc);
4870             Analyze (Subp_Id);
4871             Applies := False;
4872
4873             if Is_Entity_Name (Subp_Id) then
4874                Subp := Entity (Subp_Id);
4875
4876                if Subp = Any_Id then
4877
4878                   --  If previous error, avoid cascaded errors
4879
4880                   Applies := True;
4881                   Effective := True;
4882
4883                else
4884                   Make_Inline (Subp);
4885
4886                   --  For the pragma case, climb homonym chain. This is
4887                   --  what implements allowing the pragma in the renaming
4888                   --  case, with the result applying to the ancestors.
4889
4890                   if not From_Aspect_Specification (N) then
4891                      while Present (Homonym (Subp))
4892                        and then Scope (Homonym (Subp)) = Current_Scope
4893                      loop
4894                         Make_Inline (Homonym (Subp));
4895                         Subp := Homonym (Subp);
4896                      end loop;
4897                   end if;
4898                end if;
4899             end if;
4900
4901             if not Applies then
4902                Error_Pragma_Arg
4903                  ("inappropriate argument for pragma%", Assoc);
4904
4905             elsif not Effective
4906               and then Warn_On_Redundant_Constructs
4907               and then not Suppress_All_Inlining
4908             then
4909                if Inlining_Not_Possible (Subp) then
4910                   Error_Msg_NE
4911                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4912                else
4913                   Error_Msg_NE
4914                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4915                end if;
4916             end if;
4917
4918             Next (Assoc);
4919          end loop;
4920       end Process_Inline;
4921
4922       ----------------------------
4923       -- Process_Interface_Name --
4924       ----------------------------
4925
4926       procedure Process_Interface_Name
4927         (Subprogram_Def : Entity_Id;
4928          Ext_Arg        : Node_Id;
4929          Link_Arg       : Node_Id)
4930       is
4931          Ext_Nam    : Node_Id;
4932          Link_Nam   : Node_Id;
4933          String_Val : String_Id;
4934
4935          procedure Check_Form_Of_Interface_Name
4936            (SN            : Node_Id;
4937             Ext_Name_Case : Boolean);
4938          --  SN is a string literal node for an interface name. This routine
4939          --  performs some minimal checks that the name is reasonable. In
4940          --  particular that no spaces or other obviously incorrect characters
4941          --  appear. This is only a warning, since any characters are allowed.
4942          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4943
4944          ----------------------------------
4945          -- Check_Form_Of_Interface_Name --
4946          ----------------------------------
4947
4948          procedure Check_Form_Of_Interface_Name
4949            (SN            : Node_Id;
4950             Ext_Name_Case : Boolean)
4951          is
4952             S  : constant String_Id := Strval (Expr_Value_S (SN));
4953             SL : constant Nat       := String_Length (S);
4954             C  : Char_Code;
4955
4956          begin
4957             if SL = 0 then
4958                Error_Msg_N ("interface name cannot be null string", SN);
4959             end if;
4960
4961             for J in 1 .. SL loop
4962                C := Get_String_Char (S, J);
4963
4964                --  Look for dubious character and issue unconditional warning.
4965                --  Definitely dubious if not in character range.
4966
4967                if not In_Character_Range (C)
4968
4969                   --  For all cases except CLI target,
4970                   --  commas, spaces and slashes are dubious (in CLI, we use
4971                   --  commas and backslashes in external names to specify
4972                   --  assembly version and public key, while slashes and spaces
4973                   --  can be used in names to mark nested classes and
4974                   --  valuetypes).
4975
4976                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4977                              and then (Get_Character (C) = ','
4978                                          or else
4979                                        Get_Character (C) = '\'))
4980                  or else (VM_Target /= CLI_Target
4981                             and then (Get_Character (C) = ' '
4982                                         or else
4983                                       Get_Character (C) = '/'))
4984                then
4985                   Error_Msg
4986                     ("?interface name contains illegal character",
4987                      Sloc (SN) + Source_Ptr (J));
4988                end if;
4989             end loop;
4990          end Check_Form_Of_Interface_Name;
4991
4992       --  Start of processing for Process_Interface_Name
4993
4994       begin
4995          if No (Link_Arg) then
4996             if No (Ext_Arg) then
4997                if VM_Target = CLI_Target
4998                  and then Ekind (Subprogram_Def) = E_Package
4999                  and then Nkind (Parent (Subprogram_Def)) =
5000                                                  N_Package_Specification
5001                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
5002                then
5003                   Set_Interface_Name
5004                      (Subprogram_Def,
5005                       Interface_Name
5006                         (Generic_Parent (Parent (Subprogram_Def))));
5007                end if;
5008
5009                return;
5010
5011             elsif Chars (Ext_Arg) = Name_Link_Name then
5012                Ext_Nam  := Empty;
5013                Link_Nam := Expression (Ext_Arg);
5014
5015             else
5016                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5017                Ext_Nam  := Expression (Ext_Arg);
5018                Link_Nam := Empty;
5019             end if;
5020
5021          else
5022             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
5023             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5024             Ext_Nam  := Expression (Ext_Arg);
5025             Link_Nam := Expression (Link_Arg);
5026          end if;
5027
5028          --  Check expressions for external name and link name are static
5029
5030          if Present (Ext_Nam) then
5031             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5032             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5033
5034             --  Verify that external name is not the name of a local entity,
5035             --  which would hide the imported one and could lead to run-time
5036             --  surprises. The problem can only arise for entities declared in
5037             --  a package body (otherwise the external name is fully qualified
5038             --  and will not conflict).
5039
5040             declare
5041                Nam : Name_Id;
5042                E   : Entity_Id;
5043                Par : Node_Id;
5044
5045             begin
5046                if Prag_Id = Pragma_Import then
5047                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5048                   Nam := Name_Find;
5049                   E   := Entity_Id (Get_Name_Table_Info (Nam));
5050
5051                   if Nam /= Chars (Subprogram_Def)
5052                     and then Present (E)
5053                     and then not Is_Overloadable (E)
5054                     and then Is_Immediately_Visible (E)
5055                     and then not Is_Imported (E)
5056                     and then Ekind (Scope (E)) = E_Package
5057                   then
5058                      Par := Parent (E);
5059                      while Present (Par) loop
5060                         if Nkind (Par) = N_Package_Body then
5061                            Error_Msg_Sloc := Sloc (E);
5062                            Error_Msg_NE
5063                              ("imported entity is hidden by & declared#",
5064                               Ext_Arg, E);
5065                            exit;
5066                         end if;
5067
5068                         Par := Parent (Par);
5069                      end loop;
5070                   end if;
5071                end if;
5072             end;
5073          end if;
5074
5075          if Present (Link_Nam) then
5076             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5077             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5078          end if;
5079
5080          --  If there is no link name, just set the external name
5081
5082          if No (Link_Nam) then
5083             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5084
5085          --  For the Link_Name case, the given literal is preceded by an
5086          --  asterisk, which indicates to GCC that the given name should be
5087          --  taken literally, and in particular that no prepending of
5088          --  underlines should occur, even in systems where this is the
5089          --  normal default.
5090
5091          else
5092             Start_String;
5093
5094             if VM_Target = No_VM then
5095                Store_String_Char (Get_Char_Code ('*'));
5096             end if;
5097
5098             String_Val := Strval (Expr_Value_S (Link_Nam));
5099             Store_String_Chars (String_Val);
5100             Link_Nam :=
5101               Make_String_Literal (Sloc (Link_Nam),
5102                 Strval => End_String);
5103          end if;
5104
5105          --  Set the interface name. If the entity is a generic instance, use
5106          --  its alias, which is the callable entity.
5107
5108          if Is_Generic_Instance (Subprogram_Def) then
5109             Set_Encoded_Interface_Name
5110               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5111          else
5112             Set_Encoded_Interface_Name
5113               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5114          end if;
5115
5116          --  We allow duplicated export names in CIL/Java, as they are always
5117          --  enclosed in a namespace that differentiates them, and overloaded
5118          --  entities are supported by the VM.
5119
5120          if Convention (Subprogram_Def) /= Convention_CIL
5121               and then
5122             Convention (Subprogram_Def) /= Convention_Java
5123          then
5124             Check_Duplicated_Export_Name (Link_Nam);
5125          end if;
5126       end Process_Interface_Name;
5127
5128       -----------------------------------------
5129       -- Process_Interrupt_Or_Attach_Handler --
5130       -----------------------------------------
5131
5132       procedure Process_Interrupt_Or_Attach_Handler is
5133          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5134          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5135          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5136
5137       begin
5138          Set_Is_Interrupt_Handler (Handler_Proc);
5139
5140          --  If the pragma is not associated with a handler procedure within a
5141          --  protected type, then it must be for a nonprotected procedure for
5142          --  the AAMP target, in which case we don't associate a representation
5143          --  item with the procedure's scope.
5144
5145          if Ekind (Proc_Scope) = E_Protected_Type then
5146             if Prag_Id = Pragma_Interrupt_Handler
5147                  or else
5148                Prag_Id = Pragma_Attach_Handler
5149             then
5150                Record_Rep_Item (Proc_Scope, N);
5151             end if;
5152          end if;
5153       end Process_Interrupt_Or_Attach_Handler;
5154
5155       --------------------------------------------------
5156       -- Process_Restrictions_Or_Restriction_Warnings --
5157       --------------------------------------------------
5158
5159       --  Note: some of the simple identifier cases were handled in par-prag,
5160       --  but it is harmless (and more straightforward) to simply handle all
5161       --  cases here, even if it means we repeat a bit of work in some cases.
5162
5163       procedure Process_Restrictions_Or_Restriction_Warnings
5164         (Warn : Boolean)
5165       is
5166          Arg   : Node_Id;
5167          R_Id  : Restriction_Id;
5168          Id    : Name_Id;
5169          Expr  : Node_Id;
5170          Val   : Uint;
5171
5172          procedure Check_Unit_Name (N : Node_Id);
5173          --  Checks unit name parameter for No_Dependence. Returns if it has
5174          --  an appropriate form, otherwise raises pragma argument error.
5175
5176          ---------------------
5177          -- Check_Unit_Name --
5178          ---------------------
5179
5180          procedure Check_Unit_Name (N : Node_Id) is
5181          begin
5182             if Nkind (N) = N_Selected_Component then
5183                Check_Unit_Name (Prefix (N));
5184                Check_Unit_Name (Selector_Name (N));
5185
5186             elsif Nkind (N) = N_Identifier then
5187                return;
5188
5189             else
5190                Error_Pragma_Arg
5191                  ("wrong form for unit name for No_Dependence", N);
5192             end if;
5193          end Check_Unit_Name;
5194
5195       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5196
5197       begin
5198          --  Ignore all Restrictions pragma in CodePeer mode
5199
5200          if CodePeer_Mode then
5201             return;
5202          end if;
5203
5204          Check_Ada_83_Warning;
5205          Check_At_Least_N_Arguments (1);
5206          Check_Valid_Configuration_Pragma;
5207
5208          Arg := Arg1;
5209          while Present (Arg) loop
5210             Id := Chars (Arg);
5211             Expr := Get_Pragma_Arg (Arg);
5212
5213             --  Case of no restriction identifier present
5214
5215             if Id = No_Name then
5216                if Nkind (Expr) /= N_Identifier then
5217                   Error_Pragma_Arg
5218                     ("invalid form for restriction", Arg);
5219                end if;
5220
5221                R_Id :=
5222                  Get_Restriction_Id
5223                    (Process_Restriction_Synonyms (Expr));
5224
5225                if R_Id not in All_Boolean_Restrictions then
5226                   Error_Msg_Name_1 := Pname;
5227                   Error_Msg_N
5228                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5229
5230                   --  Check for possible misspelling
5231
5232                   for J in Restriction_Id loop
5233                      declare
5234                         Rnm : constant String := Restriction_Id'Image (J);
5235
5236                      begin
5237                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5238                         Name_Len := Rnm'Length;
5239                         Set_Casing (All_Lower_Case);
5240
5241                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5242                            Set_Casing
5243                              (Identifier_Casing (Current_Source_File));
5244                            Error_Msg_String (1 .. Rnm'Length) :=
5245                              Name_Buffer (1 .. Name_Len);
5246                            Error_Msg_Strlen := Rnm'Length;
5247                            Error_Msg_N -- CODEFIX
5248                              ("\possible misspelling of ""~""",
5249                               Get_Pragma_Arg (Arg));
5250                            exit;
5251                         end if;
5252                      end;
5253                   end loop;
5254
5255                   raise Pragma_Exit;
5256                end if;
5257
5258                if Implementation_Restriction (R_Id) then
5259                   Check_Restriction (No_Implementation_Restrictions, Arg);
5260                end if;
5261
5262                --  If this is a warning, then set the warning unless we already
5263                --  have a real restriction active (we never want a warning to
5264                --  override a real restriction).
5265
5266                if Warn then
5267                   if not Restriction_Active (R_Id) then
5268                      Set_Restriction (R_Id, N);
5269                      Restriction_Warnings (R_Id) := True;
5270                   end if;
5271
5272                --  If real restriction case, then set it and make sure that the
5273                --  restriction warning flag is off, since a real restriction
5274                --  always overrides a warning.
5275
5276                else
5277                   Set_Restriction (R_Id, N);
5278                   Restriction_Warnings (R_Id) := False;
5279                end if;
5280
5281                --  Check for obsolescent restrictions in Ada 2005 mode
5282
5283                if not Warn
5284                  and then Ada_Version >= Ada_2005
5285                  and then (R_Id = No_Asynchronous_Control
5286                             or else
5287                            R_Id = No_Unchecked_Deallocation
5288                             or else
5289                            R_Id = No_Unchecked_Conversion)
5290                then
5291                   Check_Restriction (No_Obsolescent_Features, N);
5292                end if;
5293
5294                --  A very special case that must be processed here: pragma
5295                --  Restrictions (No_Exceptions) turns off all run-time
5296                --  checking. This is a bit dubious in terms of the formal
5297                --  language definition, but it is what is intended by RM
5298                --  H.4(12). Restriction_Warnings never affects generated code
5299                --  so this is done only in the real restriction case.
5300
5301                if R_Id = No_Exceptions and then not Warn then
5302                   Scope_Suppress := (others => True);
5303                end if;
5304
5305             --  Case of No_Dependence => unit-name. Note that the parser
5306             --  already made the necessary entry in the No_Dependence table.
5307
5308             elsif Id = Name_No_Dependence then
5309                Check_Unit_Name (Expr);
5310
5311             --  All other cases of restriction identifier present
5312
5313             else
5314                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5315                Analyze_And_Resolve (Expr, Any_Integer);
5316
5317                if R_Id not in All_Parameter_Restrictions then
5318                   Error_Pragma_Arg
5319                     ("invalid restriction parameter identifier", Arg);
5320
5321                elsif not Is_OK_Static_Expression (Expr) then
5322                   Flag_Non_Static_Expr
5323                     ("value must be static expression!", Expr);
5324                   raise Pragma_Exit;
5325
5326                elsif not Is_Integer_Type (Etype (Expr))
5327                  or else Expr_Value (Expr) < 0
5328                then
5329                   Error_Pragma_Arg
5330                     ("value must be non-negative integer", Arg);
5331                end if;
5332
5333                --  Restriction pragma is active
5334
5335                Val := Expr_Value (Expr);
5336
5337                if not UI_Is_In_Int_Range (Val) then
5338                   Error_Pragma_Arg
5339                     ("pragma ignored, value too large?", Arg);
5340                end if;
5341
5342                --  Warning case. If the real restriction is active, then we
5343                --  ignore the request, since warning never overrides a real
5344                --  restriction. Otherwise we set the proper warning. Note that
5345                --  this circuit sets the warning again if it is already set,
5346                --  which is what we want, since the constant may have changed.
5347
5348                if Warn then
5349                   if not Restriction_Active (R_Id) then
5350                      Set_Restriction
5351                        (R_Id, N, Integer (UI_To_Int (Val)));
5352                      Restriction_Warnings (R_Id) := True;
5353                   end if;
5354
5355                --  Real restriction case, set restriction and make sure warning
5356                --  flag is off since real restriction always overrides warning.
5357
5358                else
5359                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5360                   Restriction_Warnings (R_Id) := False;
5361                end if;
5362             end if;
5363
5364             Next (Arg);
5365          end loop;
5366       end Process_Restrictions_Or_Restriction_Warnings;
5367
5368       ---------------------------------
5369       -- Process_Suppress_Unsuppress --
5370       ---------------------------------
5371
5372       --  Note: this procedure makes entries in the check suppress data
5373       --  structures managed by Sem. See spec of package Sem for full
5374       --  details on how we handle recording of check suppression.
5375
5376       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5377          C    : Check_Id;
5378          E_Id : Node_Id;
5379          E    : Entity_Id;
5380
5381          In_Package_Spec : constant Boolean :=
5382                              Is_Package_Or_Generic_Package (Current_Scope)
5383                                and then not In_Package_Body (Current_Scope);
5384
5385          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5386          --  Used to suppress a single check on the given entity
5387
5388          --------------------------------
5389          -- Suppress_Unsuppress_Echeck --
5390          --------------------------------
5391
5392          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5393          begin
5394             Set_Checks_May_Be_Suppressed (E);
5395
5396             if In_Package_Spec then
5397                Push_Global_Suppress_Stack_Entry
5398                  (Entity   => E,
5399                   Check    => C,
5400                   Suppress => Suppress_Case);
5401
5402             else
5403                Push_Local_Suppress_Stack_Entry
5404                  (Entity   => E,
5405                   Check    => C,
5406                   Suppress => Suppress_Case);
5407             end if;
5408
5409             --  If this is a first subtype, and the base type is distinct,
5410             --  then also set the suppress flags on the base type.
5411
5412             if Is_First_Subtype (E)
5413               and then Etype (E) /= E
5414             then
5415                Suppress_Unsuppress_Echeck (Etype (E), C);
5416             end if;
5417          end Suppress_Unsuppress_Echeck;
5418
5419       --  Start of processing for Process_Suppress_Unsuppress
5420
5421       begin
5422          --  Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5423          --  user code: we want to generate checks for analysis purposes, as
5424          --  set respectively by -gnatC and -gnatd.F
5425
5426          if (CodePeer_Mode or Alfa_Mode)
5427            and then Comes_From_Source (N)
5428          then
5429             return;
5430          end if;
5431
5432          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5433          --  declarative part or a package spec (RM 11.5(5)).
5434
5435          if not Is_Configuration_Pragma then
5436             Check_Is_In_Decl_Part_Or_Package_Spec;
5437          end if;
5438
5439          Check_At_Least_N_Arguments (1);
5440          Check_At_Most_N_Arguments (2);
5441          Check_No_Identifier (Arg1);
5442          Check_Arg_Is_Identifier (Arg1);
5443
5444          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5445
5446          if C = No_Check_Id then
5447             Error_Pragma_Arg
5448               ("argument of pragma% is not valid check name", Arg1);
5449          end if;
5450
5451          if not Suppress_Case
5452            and then (C = All_Checks or else C = Overflow_Check)
5453          then
5454             Opt.Overflow_Checks_Unsuppressed := True;
5455          end if;
5456
5457          if Arg_Count = 1 then
5458
5459             --  Make an entry in the local scope suppress table. This is the
5460             --  table that directly shows the current value of the scope
5461             --  suppress check for any check id value.
5462
5463             if C = All_Checks then
5464
5465                --  For All_Checks, we set all specific predefined checks with
5466                --  the exception of Elaboration_Check, which is handled
5467                --  specially because of not wanting All_Checks to have the
5468                --  effect of deactivating static elaboration order processing.
5469
5470                for J in Scope_Suppress'Range loop
5471                   if J /= Elaboration_Check then
5472                      Scope_Suppress (J) := Suppress_Case;
5473                   end if;
5474                end loop;
5475
5476             --  If not All_Checks, and predefined check, then set appropriate
5477             --  scope entry. Note that we will set Elaboration_Check if this
5478             --  is explicitly specified.
5479
5480             elsif C in Predefined_Check_Id then
5481                Scope_Suppress (C) := Suppress_Case;
5482             end if;
5483
5484             --  Also make an entry in the Local_Entity_Suppress table
5485
5486             Push_Local_Suppress_Stack_Entry
5487               (Entity   => Empty,
5488                Check    => C,
5489                Suppress => Suppress_Case);
5490
5491          --  Case of two arguments present, where the check is suppressed for
5492          --  a specified entity (given as the second argument of the pragma)
5493
5494          else
5495             --  This is obsolescent in Ada 2005 mode
5496
5497             if Ada_Version >= Ada_2005 then
5498                Check_Restriction (No_Obsolescent_Features, Arg2);
5499             end if;
5500
5501             Check_Optional_Identifier (Arg2, Name_On);
5502             E_Id := Get_Pragma_Arg (Arg2);
5503             Analyze (E_Id);
5504
5505             if not Is_Entity_Name (E_Id) then
5506                Error_Pragma_Arg
5507                  ("second argument of pragma% must be entity name", Arg2);
5508             end if;
5509
5510             E := Entity (E_Id);
5511
5512             if E = Any_Id then
5513                return;
5514             end if;
5515
5516             --  Enforce RM 11.5(7) which requires that for a pragma that
5517             --  appears within a package spec, the named entity must be
5518             --  within the package spec. We allow the package name itself
5519             --  to be mentioned since that makes sense, although it is not
5520             --  strictly allowed by 11.5(7).
5521
5522             if In_Package_Spec
5523               and then E /= Current_Scope
5524               and then Scope (E) /= Current_Scope
5525             then
5526                Error_Pragma_Arg
5527                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5528                   Arg2);
5529             end if;
5530
5531             --  Loop through homonyms. As noted below, in the case of a package
5532             --  spec, only homonyms within the package spec are considered.
5533
5534             loop
5535                Suppress_Unsuppress_Echeck (E, C);
5536
5537                if Is_Generic_Instance (E)
5538                  and then Is_Subprogram (E)
5539                  and then Present (Alias (E))
5540                then
5541                   Suppress_Unsuppress_Echeck (Alias (E), C);
5542                end if;
5543
5544                --  Move to next homonym if not aspect spec case
5545
5546                exit when From_Aspect_Specification (N);
5547                E := Homonym (E);
5548                exit when No (E);
5549
5550                --  If we are within a package specification, the pragma only
5551                --  applies to homonyms in the same scope.
5552
5553                exit when In_Package_Spec
5554                  and then Scope (E) /= Current_Scope;
5555             end loop;
5556          end if;
5557       end Process_Suppress_Unsuppress;
5558
5559       ------------------
5560       -- Set_Exported --
5561       ------------------
5562
5563       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5564       begin
5565          if Is_Imported (E) then
5566             Error_Pragma_Arg
5567               ("cannot export entity& that was previously imported", Arg);
5568
5569          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5570             Error_Pragma_Arg
5571               ("cannot export entity& that has an address clause", Arg);
5572          end if;
5573
5574          Set_Is_Exported (E);
5575
5576          --  Generate a reference for entity explicitly, because the
5577          --  identifier may be overloaded and name resolution will not
5578          --  generate one.
5579
5580          Generate_Reference (E, Arg);
5581
5582          --  Deal with exporting non-library level entity
5583
5584          if not Is_Library_Level_Entity (E) then
5585
5586             --  Not allowed at all for subprograms
5587
5588             if Is_Subprogram (E) then
5589                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5590
5591             --  Otherwise set public and statically allocated
5592
5593             else
5594                Set_Is_Public (E);
5595                Set_Is_Statically_Allocated (E);
5596
5597                --  Warn if the corresponding W flag is set and the pragma comes
5598                --  from source. The latter may not be true e.g. on VMS where we
5599                --  expand export pragmas for exception codes associated with
5600                --  imported or exported exceptions. We do not want to generate
5601                --  a warning for something that the user did not write.
5602
5603                if Warn_On_Export_Import
5604                  and then Comes_From_Source (Arg)
5605                then
5606                   Error_Msg_NE
5607                     ("?& has been made static as a result of Export", Arg, E);
5608                   Error_Msg_N
5609                     ("\this usage is non-standard and non-portable", Arg);
5610                end if;
5611             end if;
5612          end if;
5613
5614          if Warn_On_Export_Import and then Is_Type (E) then
5615             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5616          end if;
5617
5618          if Warn_On_Export_Import and Inside_A_Generic then
5619             Error_Msg_NE
5620               ("all instances of& will have the same external name?", Arg, E);
5621          end if;
5622       end Set_Exported;
5623
5624       ----------------------------------------------
5625       -- Set_Extended_Import_Export_External_Name --
5626       ----------------------------------------------
5627
5628       procedure Set_Extended_Import_Export_External_Name
5629         (Internal_Ent : Entity_Id;
5630          Arg_External : Node_Id)
5631       is
5632          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5633          New_Name : Node_Id;
5634
5635       begin
5636          if No (Arg_External) then
5637             return;
5638          end if;
5639
5640          Check_Arg_Is_External_Name (Arg_External);
5641
5642          if Nkind (Arg_External) = N_String_Literal then
5643             if String_Length (Strval (Arg_External)) = 0 then
5644                return;
5645             else
5646                New_Name := Adjust_External_Name_Case (Arg_External);
5647             end if;
5648
5649          elsif Nkind (Arg_External) = N_Identifier then
5650             New_Name := Get_Default_External_Name (Arg_External);
5651
5652          --  Check_Arg_Is_External_Name should let through only identifiers and
5653          --  string literals or static string expressions (which are folded to
5654          --  string literals).
5655
5656          else
5657             raise Program_Error;
5658          end if;
5659
5660          --  If we already have an external name set (by a prior normal Import
5661          --  or Export pragma), then the external names must match
5662
5663          if Present (Interface_Name (Internal_Ent)) then
5664             Check_Matching_Internal_Names : declare
5665                S1 : constant String_Id := Strval (Old_Name);
5666                S2 : constant String_Id := Strval (New_Name);
5667
5668                procedure Mismatch;
5669                --  Called if names do not match
5670
5671                --------------
5672                -- Mismatch --
5673                --------------
5674
5675                procedure Mismatch is
5676                begin
5677                   Error_Msg_Sloc := Sloc (Old_Name);
5678                   Error_Pragma_Arg
5679                     ("external name does not match that given #",
5680                      Arg_External);
5681                end Mismatch;
5682
5683             --  Start of processing for Check_Matching_Internal_Names
5684
5685             begin
5686                if String_Length (S1) /= String_Length (S2) then
5687                   Mismatch;
5688
5689                else
5690                   for J in 1 .. String_Length (S1) loop
5691                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5692                         Mismatch;
5693                      end if;
5694                   end loop;
5695                end if;
5696             end Check_Matching_Internal_Names;
5697
5698          --  Otherwise set the given name
5699
5700          else
5701             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5702             Check_Duplicated_Export_Name (New_Name);
5703          end if;
5704       end Set_Extended_Import_Export_External_Name;
5705
5706       ------------------
5707       -- Set_Imported --
5708       ------------------
5709
5710       procedure Set_Imported (E : Entity_Id) is
5711       begin
5712          --  Error message if already imported or exported
5713
5714          if Is_Exported (E) or else Is_Imported (E) then
5715
5716             --  Error if being set Exported twice
5717
5718             if Is_Exported (E) then
5719                Error_Msg_NE ("entity& was previously exported", N, E);
5720
5721             --  OK if Import/Interface case
5722
5723             elsif Import_Interface_Present (N) then
5724                goto OK;
5725
5726             --  Error if being set Imported twice
5727
5728             else
5729                Error_Msg_NE ("entity& was previously imported", N, E);
5730             end if;
5731
5732             Error_Msg_Name_1 := Pname;
5733             Error_Msg_N
5734               ("\(pragma% applies to all previous entities)", N);
5735
5736             Error_Msg_Sloc  := Sloc (E);
5737             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5738
5739          --  Here if not previously imported or exported, OK to import
5740
5741          else
5742             Set_Is_Imported (E);
5743
5744             --  If the entity is an object that is not at the library level,
5745             --  then it is statically allocated. We do not worry about objects
5746             --  with address clauses in this context since they are not really
5747             --  imported in the linker sense.
5748
5749             if Is_Object (E)
5750               and then not Is_Library_Level_Entity (E)
5751               and then No (Address_Clause (E))
5752             then
5753                Set_Is_Statically_Allocated (E);
5754             end if;
5755          end if;
5756
5757          <<OK>> null;
5758       end Set_Imported;
5759
5760       -------------------------
5761       -- Set_Mechanism_Value --
5762       -------------------------
5763
5764       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5765       --  analyzed, since it is semantic nonsense), so we get it in the exact
5766       --  form created by the parser.
5767
5768       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5769          Class        : Node_Id;
5770          Param        : Node_Id;
5771          Mech_Name_Id : Name_Id;
5772
5773          procedure Bad_Class;
5774          --  Signal bad descriptor class name
5775
5776          procedure Bad_Mechanism;
5777          --  Signal bad mechanism name
5778
5779          ---------------
5780          -- Bad_Class --
5781          ---------------
5782
5783          procedure Bad_Class is
5784          begin
5785             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5786          end Bad_Class;
5787
5788          -------------------------
5789          -- Bad_Mechanism_Value --
5790          -------------------------
5791
5792          procedure Bad_Mechanism is
5793          begin
5794             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5795          end Bad_Mechanism;
5796
5797       --  Start of processing for Set_Mechanism_Value
5798
5799       begin
5800          if Mechanism (Ent) /= Default_Mechanism then
5801             Error_Msg_NE
5802               ("mechanism for & has already been set", Mech_Name, Ent);
5803          end if;
5804
5805          --  MECHANISM_NAME ::= value | reference | descriptor |
5806          --                     short_descriptor
5807
5808          if Nkind (Mech_Name) = N_Identifier then
5809             if Chars (Mech_Name) = Name_Value then
5810                Set_Mechanism (Ent, By_Copy);
5811                return;
5812
5813             elsif Chars (Mech_Name) = Name_Reference then
5814                Set_Mechanism (Ent, By_Reference);
5815                return;
5816
5817             elsif Chars (Mech_Name) = Name_Descriptor then
5818                Check_VMS (Mech_Name);
5819
5820                --  Descriptor => Short_Descriptor if pragma was given
5821
5822                if Short_Descriptors then
5823                   Set_Mechanism (Ent, By_Short_Descriptor);
5824                else
5825                   Set_Mechanism (Ent, By_Descriptor);
5826                end if;
5827
5828                return;
5829
5830             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5831                Check_VMS (Mech_Name);
5832                Set_Mechanism (Ent, By_Short_Descriptor);
5833                return;
5834
5835             elsif Chars (Mech_Name) = Name_Copy then
5836                Error_Pragma_Arg
5837                  ("bad mechanism name, Value assumed", Mech_Name);
5838
5839             else
5840                Bad_Mechanism;
5841             end if;
5842
5843          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5844          --                     short_descriptor (CLASS_NAME)
5845          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5846
5847          --  Note: this form is parsed as an indexed component
5848
5849          elsif Nkind (Mech_Name) = N_Indexed_Component then
5850             Class := First (Expressions (Mech_Name));
5851
5852             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5853              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5854                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5855              or else Present (Next (Class))
5856             then
5857                Bad_Mechanism;
5858             else
5859                Mech_Name_Id := Chars (Prefix (Mech_Name));
5860
5861                --  Change Descriptor => Short_Descriptor if pragma was given
5862
5863                if Mech_Name_Id = Name_Descriptor
5864                  and then Short_Descriptors
5865                then
5866                   Mech_Name_Id := Name_Short_Descriptor;
5867                end if;
5868             end if;
5869
5870          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5871          --                     short_descriptor (Class => CLASS_NAME)
5872          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5873
5874          --  Note: this form is parsed as a function call
5875
5876          elsif Nkind (Mech_Name) = N_Function_Call then
5877             Param := First (Parameter_Associations (Mech_Name));
5878
5879             if Nkind (Name (Mech_Name)) /= N_Identifier
5880               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5881                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5882               or else Present (Next (Param))
5883               or else No (Selector_Name (Param))
5884               or else Chars (Selector_Name (Param)) /= Name_Class
5885             then
5886                Bad_Mechanism;
5887             else
5888                Class := Explicit_Actual_Parameter (Param);
5889                Mech_Name_Id := Chars (Name (Mech_Name));
5890             end if;
5891
5892          else
5893             Bad_Mechanism;
5894          end if;
5895
5896          --  Fall through here with Class set to descriptor class name
5897
5898          Check_VMS (Mech_Name);
5899
5900          if Nkind (Class) /= N_Identifier then
5901             Bad_Class;
5902
5903          elsif Mech_Name_Id = Name_Descriptor
5904            and then Chars (Class) = Name_UBS
5905          then
5906             Set_Mechanism (Ent, By_Descriptor_UBS);
5907
5908          elsif Mech_Name_Id = Name_Descriptor
5909            and then Chars (Class) = Name_UBSB
5910          then
5911             Set_Mechanism (Ent, By_Descriptor_UBSB);
5912
5913          elsif Mech_Name_Id = Name_Descriptor
5914            and then Chars (Class) = Name_UBA
5915          then
5916             Set_Mechanism (Ent, By_Descriptor_UBA);
5917
5918          elsif Mech_Name_Id = Name_Descriptor
5919            and then Chars (Class) = Name_S
5920          then
5921             Set_Mechanism (Ent, By_Descriptor_S);
5922
5923          elsif Mech_Name_Id = Name_Descriptor
5924            and then Chars (Class) = Name_SB
5925          then
5926             Set_Mechanism (Ent, By_Descriptor_SB);
5927
5928          elsif Mech_Name_Id = Name_Descriptor
5929            and then Chars (Class) = Name_A
5930          then
5931             Set_Mechanism (Ent, By_Descriptor_A);
5932
5933          elsif Mech_Name_Id = Name_Descriptor
5934            and then Chars (Class) = Name_NCA
5935          then
5936             Set_Mechanism (Ent, By_Descriptor_NCA);
5937
5938          elsif Mech_Name_Id = Name_Short_Descriptor
5939            and then Chars (Class) = Name_UBS
5940          then
5941             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5942
5943          elsif Mech_Name_Id = Name_Short_Descriptor
5944            and then Chars (Class) = Name_UBSB
5945          then
5946             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5947
5948          elsif Mech_Name_Id = Name_Short_Descriptor
5949            and then Chars (Class) = Name_UBA
5950          then
5951             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5952
5953          elsif Mech_Name_Id = Name_Short_Descriptor
5954            and then Chars (Class) = Name_S
5955          then
5956             Set_Mechanism (Ent, By_Short_Descriptor_S);
5957
5958          elsif Mech_Name_Id = Name_Short_Descriptor
5959            and then Chars (Class) = Name_SB
5960          then
5961             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5962
5963          elsif Mech_Name_Id = Name_Short_Descriptor
5964            and then Chars (Class) = Name_A
5965          then
5966             Set_Mechanism (Ent, By_Short_Descriptor_A);
5967
5968          elsif Mech_Name_Id = Name_Short_Descriptor
5969            and then Chars (Class) = Name_NCA
5970          then
5971             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5972
5973          else
5974             Bad_Class;
5975          end if;
5976       end Set_Mechanism_Value;
5977
5978       ---------------------------
5979       -- Set_Ravenscar_Profile --
5980       ---------------------------
5981
5982       --  The tasks to be done here are
5983
5984       --    Set required policies
5985
5986       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5987       --      pragma Locking_Policy (Ceiling_Locking)
5988
5989       --    Set Detect_Blocking mode
5990
5991       --    Set required restrictions (see System.Rident for detailed list)
5992
5993       --    Set the No_Dependence rules
5994       --      No_Dependence => Ada.Asynchronous_Task_Control
5995       --      No_Dependence => Ada.Calendar
5996       --      No_Dependence => Ada.Execution_Time.Group_Budget
5997       --      No_Dependence => Ada.Execution_Time.Timers
5998       --      No_Dependence => Ada.Task_Attributes
5999       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
6000
6001       procedure Set_Ravenscar_Profile (N : Node_Id) is
6002          Prefix_Entity   : Entity_Id;
6003          Selector_Entity : Entity_Id;
6004          Prefix_Node     : Node_Id;
6005          Node            : Node_Id;
6006
6007       begin
6008          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6009
6010          if Task_Dispatching_Policy /= ' '
6011            and then Task_Dispatching_Policy /= 'F'
6012          then
6013             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6014             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6015
6016          --  Set the FIFO_Within_Priorities policy, but always preserve
6017          --  System_Location since we like the error message with the run time
6018          --  name.
6019
6020          else
6021             Task_Dispatching_Policy := 'F';
6022
6023             if Task_Dispatching_Policy_Sloc /= System_Location then
6024                Task_Dispatching_Policy_Sloc := Loc;
6025             end if;
6026          end if;
6027
6028          --  pragma Locking_Policy (Ceiling_Locking)
6029
6030          if Locking_Policy /= ' '
6031            and then Locking_Policy /= 'C'
6032          then
6033             Error_Msg_Sloc := Locking_Policy_Sloc;
6034             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6035
6036          --  Set the Ceiling_Locking policy, but preserve System_Location since
6037          --  we like the error message with the run time name.
6038
6039          else
6040             Locking_Policy := 'C';
6041
6042             if Locking_Policy_Sloc /= System_Location then
6043                Locking_Policy_Sloc := Loc;
6044             end if;
6045          end if;
6046
6047          --  pragma Detect_Blocking
6048
6049          Detect_Blocking := True;
6050
6051          --  Set the corresponding restrictions
6052
6053          Set_Profile_Restrictions
6054            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6055
6056          --  Set the No_Dependence restrictions
6057
6058          --  The following No_Dependence restrictions:
6059          --    No_Dependence => Ada.Asynchronous_Task_Control
6060          --    No_Dependence => Ada.Calendar
6061          --    No_Dependence => Ada.Task_Attributes
6062          --  are already set by previous call to Set_Profile_Restrictions.
6063
6064          --  Set the following restrictions which were added to Ada 2005:
6065          --    No_Dependence => Ada.Execution_Time.Group_Budget
6066          --    No_Dependence => Ada.Execution_Time.Timers
6067
6068          if Ada_Version >= Ada_2005 then
6069             Name_Buffer (1 .. 3) := "ada";
6070             Name_Len := 3;
6071
6072             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6073
6074             Name_Buffer (1 .. 14) := "execution_time";
6075             Name_Len := 14;
6076
6077             Selector_Entity := Make_Identifier (Loc, Name_Find);
6078
6079             Prefix_Node :=
6080               Make_Selected_Component
6081                 (Sloc          => Loc,
6082                  Prefix        => Prefix_Entity,
6083                  Selector_Name => Selector_Entity);
6084
6085             Name_Buffer (1 .. 13) := "group_budgets";
6086             Name_Len := 13;
6087
6088             Selector_Entity := Make_Identifier (Loc, Name_Find);
6089
6090             Node :=
6091               Make_Selected_Component
6092                 (Sloc          => Loc,
6093                  Prefix        => Prefix_Node,
6094                  Selector_Name => Selector_Entity);
6095
6096             Set_Restriction_No_Dependence
6097               (Unit    => Node,
6098                Warn    => Treat_Restrictions_As_Warnings,
6099                Profile => Ravenscar);
6100
6101             Name_Buffer (1 .. 6) := "timers";
6102             Name_Len := 6;
6103
6104             Selector_Entity := Make_Identifier (Loc, Name_Find);
6105
6106             Node :=
6107               Make_Selected_Component
6108                 (Sloc          => Loc,
6109                  Prefix        => Prefix_Node,
6110                  Selector_Name => Selector_Entity);
6111
6112             Set_Restriction_No_Dependence
6113               (Unit    => Node,
6114                Warn    => Treat_Restrictions_As_Warnings,
6115                Profile => Ravenscar);
6116          end if;
6117
6118          --  Set the following restrictions which was added to Ada 2012 (see
6119          --  AI-0171):
6120          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
6121
6122          if Ada_Version >= Ada_2012 then
6123             Name_Buffer (1 .. 6) := "system";
6124             Name_Len := 6;
6125
6126             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6127
6128             Name_Buffer (1 .. 15) := "multiprocessors";
6129             Name_Len := 15;
6130
6131             Selector_Entity := Make_Identifier (Loc, Name_Find);
6132
6133             Prefix_Node :=
6134               Make_Selected_Component
6135                 (Sloc          => Loc,
6136                  Prefix        => Prefix_Entity,
6137                  Selector_Name => Selector_Entity);
6138
6139             Name_Buffer (1 .. 19) := "dispatching_domains";
6140             Name_Len := 19;
6141
6142             Selector_Entity := Make_Identifier (Loc, Name_Find);
6143
6144             Node :=
6145               Make_Selected_Component
6146                 (Sloc          => Loc,
6147                  Prefix        => Prefix_Node,
6148                  Selector_Name => Selector_Entity);
6149
6150             Set_Restriction_No_Dependence
6151               (Unit    => Node,
6152                Warn    => Treat_Restrictions_As_Warnings,
6153                Profile => Ravenscar);
6154          end if;
6155       end Set_Ravenscar_Profile;
6156
6157    --  Start of processing for Analyze_Pragma
6158
6159    begin
6160       --  The following code is a defense against recursion. Not clear that
6161       --  this can happen legitimately, but perhaps some error situations
6162       --  can cause it, and we did see this recursion during testing.
6163
6164       if Analyzed (N) then
6165          return;
6166       else
6167          Set_Analyzed (N, True);
6168       end if;
6169
6170       --  Deal with unrecognized pragma
6171
6172       if not Is_Pragma_Name (Pname) then
6173          if Warn_On_Unrecognized_Pragma then
6174             Error_Msg_Name_1 := Pname;
6175             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6176
6177             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6178                if Is_Bad_Spelling_Of (Pname, PN) then
6179                   Error_Msg_Name_1 := PN;
6180                   Error_Msg_N -- CODEFIX
6181                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6182                   exit;
6183                end if;
6184             end loop;
6185          end if;
6186
6187          return;
6188       end if;
6189
6190       --  Here to start processing for recognized pragma
6191
6192       Prag_Id := Get_Pragma_Id (Pname);
6193
6194       --  Preset arguments
6195
6196       Arg_Count := 0;
6197       Arg1      := Empty;
6198       Arg2      := Empty;
6199       Arg3      := Empty;
6200       Arg4      := Empty;
6201
6202       if Present (Pragma_Argument_Associations (N)) then
6203          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6204          Arg1 := First (Pragma_Argument_Associations (N));
6205
6206          if Present (Arg1) then
6207             Arg2 := Next (Arg1);
6208
6209             if Present (Arg2) then
6210                Arg3 := Next (Arg2);
6211
6212                if Present (Arg3) then
6213                   Arg4 := Next (Arg3);
6214                end if;
6215             end if;
6216          end if;
6217       end if;
6218
6219       --  An enumeration type defines the pragmas that are supported by the
6220       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6221       --  into the corresponding enumeration value for the following case.
6222
6223       case Prag_Id is
6224
6225          -----------------
6226          -- Abort_Defer --
6227          -----------------
6228
6229          --  pragma Abort_Defer;
6230
6231          when Pragma_Abort_Defer =>
6232             GNAT_Pragma;
6233             Check_Arg_Count (0);
6234
6235             --  The only required semantic processing is to check the
6236             --  placement. This pragma must appear at the start of the
6237             --  statement sequence of a handled sequence of statements.
6238
6239             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6240               or else N /= First (Statements (Parent (N)))
6241             then
6242                Pragma_Misplaced;
6243             end if;
6244
6245          ------------
6246          -- Ada_83 --
6247          ------------
6248
6249          --  pragma Ada_83;
6250
6251          --  Note: this pragma also has some specific processing in Par.Prag
6252          --  because we want to set the Ada version mode during parsing.
6253
6254          when Pragma_Ada_83 =>
6255             GNAT_Pragma;
6256             Check_Arg_Count (0);
6257
6258             --  We really should check unconditionally for proper configuration
6259             --  pragma placement, since we really don't want mixed Ada modes
6260             --  within a single unit, and the GNAT reference manual has always
6261             --  said this was a configuration pragma, but we did not check and
6262             --  are hesitant to add the check now.
6263
6264             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6265             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6266             --  or Ada 2012 mode.
6267
6268             if Ada_Version >= Ada_2005 then
6269                Check_Valid_Configuration_Pragma;
6270             end if;
6271
6272             --  Now set Ada 83 mode
6273
6274             Ada_Version := Ada_83;
6275             Ada_Version_Explicit := Ada_Version;
6276
6277          ------------
6278          -- Ada_95 --
6279          ------------
6280
6281          --  pragma Ada_95;
6282
6283          --  Note: this pragma also has some specific processing in Par.Prag
6284          --  because we want to set the Ada 83 version mode during parsing.
6285
6286          when Pragma_Ada_95 =>
6287             GNAT_Pragma;
6288             Check_Arg_Count (0);
6289
6290             --  We really should check unconditionally for proper configuration
6291             --  pragma placement, since we really don't want mixed Ada modes
6292             --  within a single unit, and the GNAT reference manual has always
6293             --  said this was a configuration pragma, but we did not check and
6294             --  are hesitant to add the check now.
6295
6296             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6297             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6298
6299             if Ada_Version >= Ada_2005 then
6300                Check_Valid_Configuration_Pragma;
6301             end if;
6302
6303             --  Now set Ada 95 mode
6304
6305             Ada_Version := Ada_95;
6306             Ada_Version_Explicit := Ada_Version;
6307
6308          ---------------------
6309          -- Ada_05/Ada_2005 --
6310          ---------------------
6311
6312          --  pragma Ada_05;
6313          --  pragma Ada_05 (LOCAL_NAME);
6314
6315          --  pragma Ada_2005;
6316          --  pragma Ada_2005 (LOCAL_NAME):
6317
6318          --  Note: these pragmas also have some specific processing in Par.Prag
6319          --  because we want to set the Ada 2005 version mode during parsing.
6320
6321          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6322             E_Id : Node_Id;
6323
6324          begin
6325             GNAT_Pragma;
6326
6327             if Arg_Count = 1 then
6328                Check_Arg_Is_Local_Name (Arg1);
6329                E_Id := Get_Pragma_Arg (Arg1);
6330
6331                if Etype (E_Id) = Any_Type then
6332                   return;
6333                end if;
6334
6335                Set_Is_Ada_2005_Only (Entity (E_Id));
6336
6337             else
6338                Check_Arg_Count (0);
6339
6340                --  For Ada_2005 we unconditionally enforce the documented
6341                --  configuration pragma placement, since we do not want to
6342                --  tolerate mixed modes in a unit involving Ada 2005. That
6343                --  would cause real difficulties for those cases where there
6344                --  are incompatibilities between Ada 95 and Ada 2005.
6345
6346                Check_Valid_Configuration_Pragma;
6347
6348                --  Now set appropriate Ada mode
6349
6350                Ada_Version          := Ada_2005;
6351                Ada_Version_Explicit := Ada_2005;
6352             end if;
6353          end;
6354
6355          ---------------------
6356          -- Ada_12/Ada_2012 --
6357          ---------------------
6358
6359          --  pragma Ada_12;
6360          --  pragma Ada_12 (LOCAL_NAME);
6361
6362          --  pragma Ada_2012;
6363          --  pragma Ada_2012 (LOCAL_NAME):
6364
6365          --  Note: these pragmas also have some specific processing in Par.Prag
6366          --  because we want to set the Ada 2012 version mode during parsing.
6367
6368          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6369             E_Id : Node_Id;
6370
6371          begin
6372             GNAT_Pragma;
6373
6374             if Arg_Count = 1 then
6375                Check_Arg_Is_Local_Name (Arg1);
6376                E_Id := Get_Pragma_Arg (Arg1);
6377
6378                if Etype (E_Id) = Any_Type then
6379                   return;
6380                end if;
6381
6382                Set_Is_Ada_2012_Only (Entity (E_Id));
6383
6384             else
6385                Check_Arg_Count (0);
6386
6387                --  For Ada_2012 we unconditionally enforce the documented
6388                --  configuration pragma placement, since we do not want to
6389                --  tolerate mixed modes in a unit involving Ada 2012. That
6390                --  would cause real difficulties for those cases where there
6391                --  are incompatibilities between Ada 95 and Ada 2012. We could
6392                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6393
6394                Check_Valid_Configuration_Pragma;
6395
6396                --  Now set appropriate Ada mode
6397
6398                Ada_Version          := Ada_2012;
6399                Ada_Version_Explicit := Ada_2012;
6400             end if;
6401          end;
6402
6403          ----------------------
6404          -- All_Calls_Remote --
6405          ----------------------
6406
6407          --  pragma All_Calls_Remote [(library_package_NAME)];
6408
6409          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6410             Lib_Entity : Entity_Id;
6411
6412          begin
6413             Check_Ada_83_Warning;
6414             Check_Valid_Library_Unit_Pragma;
6415
6416             if Nkind (N) = N_Null_Statement then
6417                return;
6418             end if;
6419
6420             Lib_Entity := Find_Lib_Unit_Name;
6421
6422             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6423
6424             if Present (Lib_Entity)
6425               and then not Debug_Flag_U
6426             then
6427                if not Is_Remote_Call_Interface (Lib_Entity) then
6428                   Error_Pragma ("pragma% only apply to rci unit");
6429
6430                --  Set flag for entity of the library unit
6431
6432                else
6433                   Set_Has_All_Calls_Remote (Lib_Entity);
6434                end if;
6435
6436             end if;
6437          end All_Calls_Remote;
6438
6439          --------------
6440          -- Annotate --
6441          --------------
6442
6443          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6444          --  ARG ::= NAME | EXPRESSION
6445
6446          --  The first two arguments are by convention intended to refer to an
6447          --  external tool and a tool-specific function. These arguments are
6448          --  not analyzed.
6449
6450          when Pragma_Annotate => Annotate : declare
6451             Arg : Node_Id;
6452             Exp : Node_Id;
6453
6454          begin
6455             GNAT_Pragma;
6456             Check_At_Least_N_Arguments (1);
6457             Check_Arg_Is_Identifier (Arg1);
6458             Check_No_Identifiers;
6459             Store_Note (N);
6460
6461             --  Second parameter is optional, it is never analyzed
6462
6463             if No (Arg2) then
6464                null;
6465
6466             --  Here if we have a second parameter
6467
6468             else
6469                --  Second parameter must be identifier
6470
6471                Check_Arg_Is_Identifier (Arg2);
6472
6473                --  Process remaining parameters if any
6474
6475                Arg := Next (Arg2);
6476                while Present (Arg) loop
6477                   Exp := Get_Pragma_Arg (Arg);
6478                   Analyze (Exp);
6479
6480                   if Is_Entity_Name (Exp) then
6481                      null;
6482
6483                   --  For string literals, we assume Standard_String as the
6484                   --  type, unless the string contains wide or wide_wide
6485                   --  characters.
6486
6487                   elsif Nkind (Exp) = N_String_Literal then
6488                      if Has_Wide_Wide_Character (Exp) then
6489                         Resolve (Exp, Standard_Wide_Wide_String);
6490                      elsif Has_Wide_Character (Exp) then
6491                         Resolve (Exp, Standard_Wide_String);
6492                      else
6493                         Resolve (Exp, Standard_String);
6494                      end if;
6495
6496                   elsif Is_Overloaded (Exp) then
6497                         Error_Pragma_Arg
6498                           ("ambiguous argument for pragma%", Exp);
6499
6500                   else
6501                      Resolve (Exp);
6502                   end if;
6503
6504                   Next (Arg);
6505                end loop;
6506             end if;
6507          end Annotate;
6508
6509          ------------
6510          -- Assert --
6511          ------------
6512
6513          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6514          --                 [, [Message =>] Static_String_EXPRESSION]);
6515
6516          when Pragma_Assert => Assert : declare
6517             Expr : Node_Id;
6518             Newa : List_Id;
6519
6520          begin
6521             Ada_2005_Pragma;
6522             Check_At_Least_N_Arguments (1);
6523             Check_At_Most_N_Arguments (2);
6524             Check_Arg_Order ((Name_Check, Name_Message));
6525             Check_Optional_Identifier (Arg1, Name_Check);
6526
6527             --  We treat pragma Assert as equivalent to:
6528
6529             --    pragma Check (Assertion, condition [, msg]);
6530
6531             --  So rewrite pragma in this manner, and analyze the result
6532
6533             Expr := Get_Pragma_Arg (Arg1);
6534             Newa := New_List (
6535               Make_Pragma_Argument_Association (Loc,
6536                 Expression => Make_Identifier (Loc, Name_Assertion)),
6537
6538               Make_Pragma_Argument_Association (Sloc (Expr),
6539                 Expression => Expr));
6540
6541             if Arg_Count > 1 then
6542                Check_Optional_Identifier (Arg2, Name_Message);
6543                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6544                Append_To (Newa, Relocate_Node (Arg2));
6545             end if;
6546
6547             Rewrite (N,
6548               Make_Pragma (Loc,
6549                 Chars                        => Name_Check,
6550                 Pragma_Argument_Associations => Newa));
6551             Analyze (N);
6552          end Assert;
6553
6554          ----------------------
6555          -- Assertion_Policy --
6556          ----------------------
6557
6558          --  pragma Assertion_Policy (Check | Disable |Ignore)
6559
6560          when Pragma_Assertion_Policy => Assertion_Policy : declare
6561             Policy : Node_Id;
6562
6563          begin
6564             Ada_2005_Pragma;
6565             Check_Valid_Configuration_Pragma;
6566             Check_Arg_Count (1);
6567             Check_No_Identifiers;
6568             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6569
6570             --  We treat pragma Assertion_Policy as equivalent to:
6571
6572             --    pragma Check_Policy (Assertion, policy)
6573
6574             --  So rewrite the pragma in that manner and link on to the chain
6575             --  of Check_Policy pragmas, marking the pragma as analyzed.
6576
6577             Policy := Get_Pragma_Arg (Arg1);
6578
6579             Rewrite (N,
6580               Make_Pragma (Loc,
6581                 Chars => Name_Check_Policy,
6582
6583                 Pragma_Argument_Associations => New_List (
6584                   Make_Pragma_Argument_Association (Loc,
6585                     Expression => Make_Identifier (Loc, Name_Assertion)),
6586
6587                   Make_Pragma_Argument_Association (Loc,
6588                     Expression =>
6589                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6590
6591             Set_Analyzed (N);
6592             Set_Next_Pragma (N, Opt.Check_Policy_List);
6593             Opt.Check_Policy_List := N;
6594          end Assertion_Policy;
6595
6596          ------------------------------
6597          -- Assume_No_Invalid_Values --
6598          ------------------------------
6599
6600          --  pragma Assume_No_Invalid_Values (On | Off);
6601
6602          when Pragma_Assume_No_Invalid_Values =>
6603             GNAT_Pragma;
6604             Check_Valid_Configuration_Pragma;
6605             Check_Arg_Count (1);
6606             Check_No_Identifiers;
6607             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6608
6609             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6610                Assume_No_Invalid_Values := True;
6611             else
6612                Assume_No_Invalid_Values := False;
6613             end if;
6614
6615          ---------------
6616          -- AST_Entry --
6617          ---------------
6618
6619          --  pragma AST_Entry (entry_IDENTIFIER);
6620
6621          when Pragma_AST_Entry => AST_Entry : declare
6622             Ent : Node_Id;
6623
6624          begin
6625             GNAT_Pragma;
6626             Check_VMS (N);
6627             Check_Arg_Count (1);
6628             Check_No_Identifiers;
6629             Check_Arg_Is_Local_Name (Arg1);
6630             Ent := Entity (Get_Pragma_Arg (Arg1));
6631
6632             --  Note: the implementation of the AST_Entry pragma could handle
6633             --  the entry family case fine, but for now we are consistent with
6634             --  the DEC rules, and do not allow the pragma, which of course
6635             --  has the effect of also forbidding the attribute.
6636
6637             if Ekind (Ent) /= E_Entry then
6638                Error_Pragma_Arg
6639                  ("pragma% argument must be simple entry name", Arg1);
6640
6641             elsif Is_AST_Entry (Ent) then
6642                Error_Pragma_Arg
6643                  ("duplicate % pragma for entry", Arg1);
6644
6645             elsif Has_Homonym (Ent) then
6646                Error_Pragma_Arg
6647                  ("pragma% argument cannot specify overloaded entry", Arg1);
6648
6649             else
6650                declare
6651                   FF : constant Entity_Id := First_Formal (Ent);
6652
6653                begin
6654                   if Present (FF) then
6655                      if Present (Next_Formal (FF)) then
6656                         Error_Pragma_Arg
6657                           ("entry for pragma% can have only one argument",
6658                            Arg1);
6659
6660                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6661                         Error_Pragma_Arg
6662                           ("entry parameter for pragma% must have mode IN",
6663                            Arg1);
6664                      end if;
6665                   end if;
6666                end;
6667
6668                Set_Is_AST_Entry (Ent);
6669             end if;
6670          end AST_Entry;
6671
6672          ------------------
6673          -- Asynchronous --
6674          ------------------
6675
6676          --  pragma Asynchronous (LOCAL_NAME);
6677
6678          when Pragma_Asynchronous => Asynchronous : declare
6679             Nm     : Entity_Id;
6680             C_Ent  : Entity_Id;
6681             L      : List_Id;
6682             S      : Node_Id;
6683             N      : Node_Id;
6684             Formal : Entity_Id;
6685
6686             procedure Process_Async_Pragma;
6687             --  Common processing for procedure and access-to-procedure case
6688
6689             --------------------------
6690             -- Process_Async_Pragma --
6691             --------------------------
6692
6693             procedure Process_Async_Pragma is
6694             begin
6695                if No (L) then
6696                   Set_Is_Asynchronous (Nm);
6697                   return;
6698                end if;
6699
6700                --  The formals should be of mode IN (RM E.4.1(6))
6701
6702                S := First (L);
6703                while Present (S) loop
6704                   Formal := Defining_Identifier (S);
6705
6706                   if Nkind (Formal) = N_Defining_Identifier
6707                     and then Ekind (Formal) /= E_In_Parameter
6708                   then
6709                      Error_Pragma_Arg
6710                        ("pragma% procedure can only have IN parameter",
6711                         Arg1);
6712                   end if;
6713
6714                   Next (S);
6715                end loop;
6716
6717                Set_Is_Asynchronous (Nm);
6718             end Process_Async_Pragma;
6719
6720          --  Start of processing for pragma Asynchronous
6721
6722          begin
6723             Check_Ada_83_Warning;
6724             Check_No_Identifiers;
6725             Check_Arg_Count (1);
6726             Check_Arg_Is_Local_Name (Arg1);
6727
6728             if Debug_Flag_U then
6729                return;
6730             end if;
6731
6732             C_Ent := Cunit_Entity (Current_Sem_Unit);
6733             Analyze (Get_Pragma_Arg (Arg1));
6734             Nm := Entity (Get_Pragma_Arg (Arg1));
6735
6736             if not Is_Remote_Call_Interface (C_Ent)
6737               and then not Is_Remote_Types (C_Ent)
6738             then
6739                --  This pragma should only appear in an RCI or Remote Types
6740                --  unit (RM E.4.1(4)).
6741
6742                Error_Pragma
6743                  ("pragma% not in Remote_Call_Interface or " &
6744                   "Remote_Types unit");
6745             end if;
6746
6747             if Ekind (Nm) = E_Procedure
6748               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6749             then
6750                if not Is_Remote_Call_Interface (Nm) then
6751                   Error_Pragma_Arg
6752                     ("pragma% cannot be applied on non-remote procedure",
6753                      Arg1);
6754                end if;
6755
6756                L := Parameter_Specifications (Parent (Nm));
6757                Process_Async_Pragma;
6758                return;
6759
6760             elsif Ekind (Nm) = E_Function then
6761                Error_Pragma_Arg
6762                  ("pragma% cannot be applied to function", Arg1);
6763
6764             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6765                   if Is_Record_Type (Nm) then
6766
6767                   --  A record type that is the Equivalent_Type for a remote
6768                   --  access-to-subprogram type.
6769
6770                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6771
6772                   else
6773                      --  A non-expanded RAS type (distribution is not enabled)
6774
6775                      N := Declaration_Node (Nm);
6776                   end if;
6777
6778                if Nkind (N) = N_Full_Type_Declaration
6779                  and then Nkind (Type_Definition (N)) =
6780                                      N_Access_Procedure_Definition
6781                then
6782                   L := Parameter_Specifications (Type_Definition (N));
6783                   Process_Async_Pragma;
6784
6785                   if Is_Asynchronous (Nm)
6786                     and then Expander_Active
6787                     and then Get_PCS_Name /= Name_No_DSA
6788                   then
6789                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6790                   end if;
6791
6792                else
6793                   Error_Pragma_Arg
6794                     ("pragma% cannot reference access-to-function type",
6795                     Arg1);
6796                end if;
6797
6798             --  Only other possibility is Access-to-class-wide type
6799
6800             elsif Is_Access_Type (Nm)
6801               and then Is_Class_Wide_Type (Designated_Type (Nm))
6802             then
6803                Check_First_Subtype (Arg1);
6804                Set_Is_Asynchronous (Nm);
6805                if Expander_Active then
6806                   RACW_Type_Is_Asynchronous (Nm);
6807                end if;
6808
6809             else
6810                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6811             end if;
6812          end Asynchronous;
6813
6814          ------------
6815          -- Atomic --
6816          ------------
6817
6818          --  pragma Atomic (LOCAL_NAME);
6819
6820          when Pragma_Atomic =>
6821             Process_Atomic_Shared_Volatile;
6822
6823          -----------------------
6824          -- Atomic_Components --
6825          -----------------------
6826
6827          --  pragma Atomic_Components (array_LOCAL_NAME);
6828
6829          --  This processing is shared by Volatile_Components
6830
6831          when Pragma_Atomic_Components   |
6832               Pragma_Volatile_Components =>
6833
6834          Atomic_Components : declare
6835             E_Id : Node_Id;
6836             E    : Entity_Id;
6837             D    : Node_Id;
6838             K    : Node_Kind;
6839
6840          begin
6841             Check_Ada_83_Warning;
6842             Check_No_Identifiers;
6843             Check_Arg_Count (1);
6844             Check_Arg_Is_Local_Name (Arg1);
6845             E_Id := Get_Pragma_Arg (Arg1);
6846
6847             if Etype (E_Id) = Any_Type then
6848                return;
6849             end if;
6850
6851             E := Entity (E_Id);
6852
6853             Check_Duplicate_Pragma (E);
6854
6855             if Rep_Item_Too_Early (E, N)
6856                  or else
6857                Rep_Item_Too_Late (E, N)
6858             then
6859                return;
6860             end if;
6861
6862             D := Declaration_Node (E);
6863             K := Nkind (D);
6864
6865             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6866               or else
6867                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6868                    and then Nkind (D) = N_Object_Declaration
6869                    and then Nkind (Object_Definition (D)) =
6870                                        N_Constrained_Array_Definition)
6871             then
6872                --  The flag is set on the object, or on the base type
6873
6874                if Nkind (D) /= N_Object_Declaration then
6875                   E := Base_Type (E);
6876                end if;
6877
6878                Set_Has_Volatile_Components (E);
6879
6880                if Prag_Id = Pragma_Atomic_Components then
6881                   Set_Has_Atomic_Components (E);
6882                end if;
6883
6884             else
6885                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6886             end if;
6887          end Atomic_Components;
6888
6889          --------------------
6890          -- Attach_Handler --
6891          --------------------
6892
6893          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6894
6895          when Pragma_Attach_Handler =>
6896             Check_Ada_83_Warning;
6897             Check_No_Identifiers;
6898             Check_Arg_Count (2);
6899
6900             if No_Run_Time_Mode then
6901                Error_Msg_CRT ("Attach_Handler pragma", N);
6902             else
6903                Check_Interrupt_Or_Attach_Handler;
6904
6905                --  The expression that designates the attribute may depend on a
6906                --  discriminant, and is therefore a per- object expression, to
6907                --  be expanded in the init proc. If expansion is enabled, then
6908                --  perform semantic checks on a copy only.
6909
6910                if Expander_Active then
6911                   declare
6912                      Temp : constant Node_Id :=
6913                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6914                   begin
6915                      Set_Parent (Temp, N);
6916                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6917                   end;
6918
6919                else
6920                   Analyze (Get_Pragma_Arg (Arg2));
6921                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6922                end if;
6923
6924                Process_Interrupt_Or_Attach_Handler;
6925             end if;
6926
6927          --------------------
6928          -- C_Pass_By_Copy --
6929          --------------------
6930
6931          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6932
6933          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6934             Arg : Node_Id;
6935             Val : Uint;
6936
6937          begin
6938             GNAT_Pragma;
6939             Check_Valid_Configuration_Pragma;
6940             Check_Arg_Count (1);
6941             Check_Optional_Identifier (Arg1, "max_size");
6942
6943             Arg := Get_Pragma_Arg (Arg1);
6944             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6945
6946             Val := Expr_Value (Arg);
6947
6948             if Val <= 0 then
6949                Error_Pragma_Arg
6950                  ("maximum size for pragma% must be positive", Arg1);
6951
6952             elsif UI_Is_In_Int_Range (Val) then
6953                Default_C_Record_Mechanism := UI_To_Int (Val);
6954
6955             --  If a giant value is given, Int'Last will do well enough.
6956             --  If sometime someone complains that a record larger than
6957             --  two gigabytes is not copied, we will worry about it then!
6958
6959             else
6960                Default_C_Record_Mechanism := Mechanism_Type'Last;
6961             end if;
6962          end C_Pass_By_Copy;
6963
6964          -----------
6965          -- Check --
6966          -----------
6967
6968          --  pragma Check ([Name    =>] IDENTIFIER,
6969          --                [Check   =>] Boolean_EXPRESSION
6970          --              [,[Message =>] String_EXPRESSION]);
6971
6972          when Pragma_Check => Check : declare
6973             Expr : Node_Id;
6974             Eloc : Source_Ptr;
6975
6976             Check_On : Boolean;
6977             --  Set True if category of assertions referenced by Name enabled
6978
6979          begin
6980             GNAT_Pragma;
6981             Check_At_Least_N_Arguments (2);
6982             Check_At_Most_N_Arguments (3);
6983             Check_Optional_Identifier (Arg1, Name_Name);
6984             Check_Optional_Identifier (Arg2, Name_Check);
6985
6986             if Arg_Count = 3 then
6987                Check_Optional_Identifier (Arg3, Name_Message);
6988                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6989             end if;
6990
6991             Check_Arg_Is_Identifier (Arg1);
6992
6993             --  Completely ignore if disabled
6994
6995             if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
6996                Rewrite (N, Make_Null_Statement (Loc));
6997                Analyze (N);
6998                return;
6999             end if;
7000
7001             --  Indicate if pragma is enabled. The Original_Node reference here
7002             --  is to deal with pragma Assert rewritten as a Check pragma.
7003
7004             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7005
7006             if Check_On then
7007                Set_SCO_Pragma_Enabled (Loc);
7008             end if;
7009
7010             --  If expansion is active and the check is not enabled then we
7011             --  rewrite the Check as:
7012
7013             --    if False and then condition then
7014             --       null;
7015             --    end if;
7016
7017             --  The reason we do this rewriting during semantic analysis rather
7018             --  than as part of normal expansion is that we cannot analyze and
7019             --  expand the code for the boolean expression directly, or it may
7020             --  cause insertion of actions that would escape the attempt to
7021             --  suppress the check code.
7022
7023             --  Note that the Sloc for the if statement corresponds to the
7024             --  argument condition, not the pragma itself. The reason for this
7025             --  is that we may generate a warning if the condition is False at
7026             --  compile time, and we do not want to delete this warning when we
7027             --  delete the if statement.
7028
7029             Expr := Get_Pragma_Arg (Arg2);
7030
7031             if Expander_Active and then not Check_On then
7032                Eloc := Sloc (Expr);
7033
7034                Rewrite (N,
7035                  Make_If_Statement (Eloc,
7036                    Condition =>
7037                      Make_And_Then (Eloc,
7038                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
7039                        Right_Opnd => Expr),
7040                    Then_Statements => New_List (
7041                      Make_Null_Statement (Eloc))));
7042
7043                Analyze (N);
7044
7045             --  Check is active
7046
7047             else
7048                Analyze_And_Resolve (Expr, Any_Boolean);
7049             end if;
7050          end Check;
7051
7052          ----------------
7053          -- Check_Name --
7054          ----------------
7055
7056          --  pragma Check_Name (check_IDENTIFIER);
7057
7058          when Pragma_Check_Name =>
7059             Check_No_Identifiers;
7060             GNAT_Pragma;
7061             Check_Valid_Configuration_Pragma;
7062             Check_Arg_Count (1);
7063             Check_Arg_Is_Identifier (Arg1);
7064
7065             declare
7066                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7067
7068             begin
7069                for J in Check_Names.First .. Check_Names.Last loop
7070                   if Check_Names.Table (J) = Nam then
7071                      return;
7072                   end if;
7073                end loop;
7074
7075                Check_Names.Append (Nam);
7076             end;
7077
7078          ------------------
7079          -- Check_Policy --
7080          ------------------
7081
7082          --  pragma Check_Policy (
7083          --    [Name   =>] IDENTIFIER,
7084          --    [Policy =>] POLICY_IDENTIFIER);
7085
7086          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7087
7088          --  Note: this is a configuration pragma, but it is allowed to appear
7089          --  anywhere else.
7090
7091          when Pragma_Check_Policy =>
7092             GNAT_Pragma;
7093             Check_Arg_Count (2);
7094             Check_Optional_Identifier (Arg1, Name_Name);
7095             Check_Optional_Identifier (Arg2, Name_Policy);
7096             Check_Arg_Is_One_Of
7097               (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7098
7099             --  A Check_Policy pragma can appear either as a configuration
7100             --  pragma, or in a declarative part or a package spec (see RM
7101             --  11.5(5) for rules for Suppress/Unsuppress which are also
7102             --  followed for Check_Policy).
7103
7104             if not Is_Configuration_Pragma then
7105                Check_Is_In_Decl_Part_Or_Package_Spec;
7106             end if;
7107
7108             Set_Next_Pragma (N, Opt.Check_Policy_List);
7109             Opt.Check_Policy_List := N;
7110
7111          ---------------------
7112          -- CIL_Constructor --
7113          ---------------------
7114
7115          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7116
7117          --  Processing for this pragma is shared with Java_Constructor
7118
7119          -------------
7120          -- Comment --
7121          -------------
7122
7123          --  pragma Comment (static_string_EXPRESSION)
7124
7125          --  Processing for pragma Comment shares the circuitry for pragma
7126          --  Ident. The only differences are that Ident enforces a limit of 31
7127          --  characters on its argument, and also enforces limitations on
7128          --  placement for DEC compatibility. Pragma Comment shares neither of
7129          --  these restrictions.
7130
7131          -------------------
7132          -- Common_Object --
7133          -------------------
7134
7135          --  pragma Common_Object (
7136          --        [Internal =>] LOCAL_NAME
7137          --     [, [External =>] EXTERNAL_SYMBOL]
7138          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7139
7140          --  Processing for this pragma is shared with Psect_Object
7141
7142          ------------------------
7143          -- Compile_Time_Error --
7144          ------------------------
7145
7146          --  pragma Compile_Time_Error
7147          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7148
7149          when Pragma_Compile_Time_Error =>
7150             GNAT_Pragma;
7151             Process_Compile_Time_Warning_Or_Error;
7152
7153          --------------------------
7154          -- Compile_Time_Warning --
7155          --------------------------
7156
7157          --  pragma Compile_Time_Warning
7158          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7159
7160          when Pragma_Compile_Time_Warning =>
7161             GNAT_Pragma;
7162             Process_Compile_Time_Warning_Or_Error;
7163
7164          -------------------
7165          -- Compiler_Unit --
7166          -------------------
7167
7168          when Pragma_Compiler_Unit =>
7169             GNAT_Pragma;
7170             Check_Arg_Count (0);
7171             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7172
7173          -----------------------------
7174          -- Complete_Representation --
7175          -----------------------------
7176
7177          --  pragma Complete_Representation;
7178
7179          when Pragma_Complete_Representation =>
7180             GNAT_Pragma;
7181             Check_Arg_Count (0);
7182
7183             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7184                Error_Pragma
7185                  ("pragma & must appear within record representation clause");
7186             end if;
7187
7188          ----------------------------
7189          -- Complex_Representation --
7190          ----------------------------
7191
7192          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7193
7194          when Pragma_Complex_Representation => Complex_Representation : declare
7195             E_Id : Entity_Id;
7196             E    : Entity_Id;
7197             Ent  : Entity_Id;
7198
7199          begin
7200             GNAT_Pragma;
7201             Check_Arg_Count (1);
7202             Check_Optional_Identifier (Arg1, Name_Entity);
7203             Check_Arg_Is_Local_Name (Arg1);
7204             E_Id := Get_Pragma_Arg (Arg1);
7205
7206             if Etype (E_Id) = Any_Type then
7207                return;
7208             end if;
7209
7210             E := Entity (E_Id);
7211
7212             if not Is_Record_Type (E) then
7213                Error_Pragma_Arg
7214                  ("argument for pragma% must be record type", Arg1);
7215             end if;
7216
7217             Ent := First_Entity (E);
7218
7219             if No (Ent)
7220               or else No (Next_Entity (Ent))
7221               or else Present (Next_Entity (Next_Entity (Ent)))
7222               or else not Is_Floating_Point_Type (Etype (Ent))
7223               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7224             then
7225                Error_Pragma_Arg
7226                  ("record for pragma% must have two fields of the same "
7227                   & "floating-point type", Arg1);
7228
7229             else
7230                Set_Has_Complex_Representation (Base_Type (E));
7231
7232                --  We need to treat the type has having a non-standard
7233                --  representation, for back-end purposes, even though in
7234                --  general a complex will have the default representation
7235                --  of a record with two real components.
7236
7237                Set_Has_Non_Standard_Rep (Base_Type (E));
7238             end if;
7239          end Complex_Representation;
7240
7241          -------------------------
7242          -- Component_Alignment --
7243          -------------------------
7244
7245          --  pragma Component_Alignment (
7246          --        [Form =>] ALIGNMENT_CHOICE
7247          --     [, [Name =>] type_LOCAL_NAME]);
7248          --
7249          --   ALIGNMENT_CHOICE ::=
7250          --     Component_Size
7251          --   | Component_Size_4
7252          --   | Storage_Unit
7253          --   | Default
7254
7255          when Pragma_Component_Alignment => Component_AlignmentP : declare
7256             Args  : Args_List (1 .. 2);
7257             Names : constant Name_List (1 .. 2) := (
7258                       Name_Form,
7259                       Name_Name);
7260
7261             Form  : Node_Id renames Args (1);
7262             Name  : Node_Id renames Args (2);
7263
7264             Atype : Component_Alignment_Kind;
7265             Typ   : Entity_Id;
7266
7267          begin
7268             GNAT_Pragma;
7269             Gather_Associations (Names, Args);
7270
7271             if No (Form) then
7272                Error_Pragma ("missing Form argument for pragma%");
7273             end if;
7274
7275             Check_Arg_Is_Identifier (Form);
7276
7277             --  Get proper alignment, note that Default = Component_Size on all
7278             --  machines we have so far, and we want to set this value rather
7279             --  than the default value to indicate that it has been explicitly
7280             --  set (and thus will not get overridden by the default component
7281             --  alignment for the current scope)
7282
7283             if Chars (Form) = Name_Component_Size then
7284                Atype := Calign_Component_Size;
7285
7286             elsif Chars (Form) = Name_Component_Size_4 then
7287                Atype := Calign_Component_Size_4;
7288
7289             elsif Chars (Form) = Name_Default then
7290                Atype := Calign_Component_Size;
7291
7292             elsif Chars (Form) = Name_Storage_Unit then
7293                Atype := Calign_Storage_Unit;
7294
7295             else
7296                Error_Pragma_Arg
7297                  ("invalid Form parameter for pragma%", Form);
7298             end if;
7299
7300             --  Case with no name, supplied, affects scope table entry
7301
7302             if No (Name) then
7303                Scope_Stack.Table
7304                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7305
7306             --  Case of name supplied
7307
7308             else
7309                Check_Arg_Is_Local_Name (Name);
7310                Find_Type (Name);
7311                Typ := Entity (Name);
7312
7313                if Typ = Any_Type
7314                  or else Rep_Item_Too_Early (Typ, N)
7315                then
7316                   return;
7317                else
7318                   Typ := Underlying_Type (Typ);
7319                end if;
7320
7321                if not Is_Record_Type (Typ)
7322                  and then not Is_Array_Type (Typ)
7323                then
7324                   Error_Pragma_Arg
7325                     ("Name parameter of pragma% must identify record or " &
7326                      "array type", Name);
7327                end if;
7328
7329                --  An explicit Component_Alignment pragma overrides an
7330                --  implicit pragma Pack, but not an explicit one.
7331
7332                if not Has_Pragma_Pack (Base_Type (Typ)) then
7333                   Set_Is_Packed (Base_Type (Typ), False);
7334                   Set_Component_Alignment (Base_Type (Typ), Atype);
7335                end if;
7336             end if;
7337          end Component_AlignmentP;
7338
7339          ----------------
7340          -- Controlled --
7341          ----------------
7342
7343          --  pragma Controlled (first_subtype_LOCAL_NAME);
7344
7345          when Pragma_Controlled => Controlled : declare
7346             Arg : Node_Id;
7347
7348          begin
7349             Check_No_Identifiers;
7350             Check_Arg_Count (1);
7351             Check_Arg_Is_Local_Name (Arg1);
7352             Arg := Get_Pragma_Arg (Arg1);
7353
7354             if not Is_Entity_Name (Arg)
7355               or else not Is_Access_Type (Entity (Arg))
7356             then
7357                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7358             else
7359                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7360             end if;
7361          end Controlled;
7362
7363          ----------------
7364          -- Convention --
7365          ----------------
7366
7367          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7368          --    [Entity =>] LOCAL_NAME);
7369
7370          when Pragma_Convention => Convention : declare
7371             C : Convention_Id;
7372             E : Entity_Id;
7373             pragma Warnings (Off, C);
7374             pragma Warnings (Off, E);
7375          begin
7376             Check_Arg_Order ((Name_Convention, Name_Entity));
7377             Check_Ada_83_Warning;
7378             Check_Arg_Count (2);
7379             Process_Convention (C, E);
7380          end Convention;
7381
7382          ---------------------------
7383          -- Convention_Identifier --
7384          ---------------------------
7385
7386          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7387          --    [Convention =>] convention_IDENTIFIER);
7388
7389          when Pragma_Convention_Identifier => Convention_Identifier : declare
7390             Idnam : Name_Id;
7391             Cname : Name_Id;
7392
7393          begin
7394             GNAT_Pragma;
7395             Check_Arg_Order ((Name_Name, Name_Convention));
7396             Check_Arg_Count (2);
7397             Check_Optional_Identifier (Arg1, Name_Name);
7398             Check_Optional_Identifier (Arg2, Name_Convention);
7399             Check_Arg_Is_Identifier (Arg1);
7400             Check_Arg_Is_Identifier (Arg2);
7401             Idnam := Chars (Get_Pragma_Arg (Arg1));
7402             Cname := Chars (Get_Pragma_Arg (Arg2));
7403
7404             if Is_Convention_Name (Cname) then
7405                Record_Convention_Identifier
7406                  (Idnam, Get_Convention_Id (Cname));
7407             else
7408                Error_Pragma_Arg
7409                  ("second arg for % pragma must be convention", Arg2);
7410             end if;
7411          end Convention_Identifier;
7412
7413          ---------------
7414          -- CPP_Class --
7415          ---------------
7416
7417          --  pragma CPP_Class ([Entity =>] local_NAME)
7418
7419          when Pragma_CPP_Class => CPP_Class : declare
7420             Arg : Node_Id;
7421             Typ : Entity_Id;
7422
7423          begin
7424             if Warn_On_Obsolescent_Feature then
7425                Error_Msg_N
7426                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7427                   " by pragma import?", N);
7428             end if;
7429
7430             GNAT_Pragma;
7431             Check_Arg_Count (1);
7432             Check_Optional_Identifier (Arg1, Name_Entity);
7433             Check_Arg_Is_Local_Name (Arg1);
7434
7435             Arg := Get_Pragma_Arg (Arg1);
7436             Analyze (Arg);
7437
7438             if Etype (Arg) = Any_Type then
7439                return;
7440             end if;
7441
7442             if not Is_Entity_Name (Arg)
7443               or else not Is_Type (Entity (Arg))
7444             then
7445                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7446             end if;
7447
7448             Typ := Entity (Arg);
7449
7450             if not Is_Tagged_Type (Typ) then
7451                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7452             end if;
7453
7454             --  Types treated as CPP classes must be declared limited (note:
7455             --  this used to be a warning but there is no real benefit to it
7456             --  since we did effectively intend to treat the type as limited
7457             --  anyway).
7458
7459             if not Is_Limited_Type (Typ) then
7460                Error_Msg_N
7461                  ("imported 'C'P'P type must be limited",
7462                   Get_Pragma_Arg (Arg1));
7463             end if;
7464
7465             Set_Is_CPP_Class      (Typ);
7466             Set_Convention        (Typ, Convention_CPP);
7467
7468             --  Imported CPP types must not have discriminants (because C++
7469             --  classes do not have discriminants).
7470
7471             if Has_Discriminants (Typ) then
7472                Error_Msg_N
7473                  ("imported 'C'P'P type cannot have discriminants",
7474                   First (Discriminant_Specifications
7475                           (Declaration_Node (Typ))));
7476             end if;
7477
7478             --  Components of imported CPP types must not have default
7479             --  expressions because the constructor (if any) is in the
7480             --  C++ side.
7481
7482             if Is_Incomplete_Or_Private_Type (Typ)
7483               and then No (Underlying_Type (Typ))
7484             then
7485                --  It should be an error to apply pragma CPP to a private
7486                --  type if the underlying type is not visible (as it is
7487                --  for any representation item). For now, for backward
7488                --  compatibility we do nothing but we cannot check components
7489                --  because they are not available at this stage. All this code
7490                --  will be removed when we cleanup this obsolete GNAT pragma???
7491
7492                null;
7493
7494             else
7495                declare
7496                   Tdef  : constant Node_Id :=
7497                             Type_Definition (Declaration_Node (Typ));
7498                   Clist : Node_Id;
7499                   Comp  : Node_Id;
7500
7501                begin
7502                   if Nkind (Tdef) = N_Record_Definition then
7503                      Clist := Component_List (Tdef);
7504                   else
7505                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7506                      Clist := Component_List (Record_Extension_Part (Tdef));
7507                   end if;
7508
7509                   if Present (Clist) then
7510                      Comp := First (Component_Items (Clist));
7511                      while Present (Comp) loop
7512                         if Present (Expression (Comp)) then
7513                            Error_Msg_N
7514                              ("component of imported 'C'P'P type cannot have" &
7515                               " default expression", Expression (Comp));
7516                         end if;
7517
7518                         Next (Comp);
7519                      end loop;
7520                   end if;
7521                end;
7522             end if;
7523          end CPP_Class;
7524
7525          ---------------------
7526          -- CPP_Constructor --
7527          ---------------------
7528
7529          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7530          --    [, [External_Name =>] static_string_EXPRESSION ]
7531          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7532
7533          when Pragma_CPP_Constructor => CPP_Constructor : declare
7534             Elmt    : Elmt_Id;
7535             Id      : Entity_Id;
7536             Def_Id  : Entity_Id;
7537             Tag_Typ : Entity_Id;
7538
7539          begin
7540             GNAT_Pragma;
7541             Check_At_Least_N_Arguments (1);
7542             Check_At_Most_N_Arguments (3);
7543             Check_Optional_Identifier (Arg1, Name_Entity);
7544             Check_Arg_Is_Local_Name (Arg1);
7545
7546             Id := Get_Pragma_Arg (Arg1);
7547             Find_Program_Unit_Name (Id);
7548
7549             --  If we did not find the name, we are done
7550
7551             if Etype (Id) = Any_Type then
7552                return;
7553             end if;
7554
7555             Def_Id := Entity (Id);
7556
7557             --  Check if already defined as constructor
7558
7559             if Is_Constructor (Def_Id) then
7560                Error_Msg_N
7561                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7562                return;
7563             end if;
7564
7565             if Ekind (Def_Id) = E_Function
7566               and then (Is_CPP_Class (Etype (Def_Id))
7567                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7568                                    and then
7569                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7570             then
7571                if Arg_Count >= 2 then
7572                   Set_Imported (Def_Id);
7573                   Set_Is_Public (Def_Id);
7574                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7575                end if;
7576
7577                Set_Has_Completion (Def_Id);
7578                Set_Is_Constructor (Def_Id);
7579
7580                --  Imported C++ constructors are not dispatching primitives
7581                --  because in C++ they don't have a dispatch table slot.
7582                --  However, in Ada the constructor has the profile of a
7583                --  function that returns a tagged type and therefore it has
7584                --  been treated as a primitive operation during semantic
7585                --  analysis. We now remove it from the list of primitive
7586                --  operations of the type.
7587
7588                if Is_Tagged_Type (Etype (Def_Id))
7589                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7590                then
7591                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7592                   Tag_Typ := Etype (Def_Id);
7593
7594                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7595                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7596                      Next_Elmt (Elmt);
7597                   end loop;
7598
7599                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7600                   Set_Is_Dispatching_Operation (Def_Id, False);
7601                end if;
7602
7603                --  For backward compatibility, if the constructor returns a
7604                --  class wide type, and we internally change the return type to
7605                --  the corresponding root type.
7606
7607                if Is_Class_Wide_Type (Etype (Def_Id)) then
7608                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7609                end if;
7610             else
7611                Error_Pragma_Arg
7612                  ("pragma% requires function returning a 'C'P'P_Class type",
7613                    Arg1);
7614             end if;
7615          end CPP_Constructor;
7616
7617          -----------------
7618          -- CPP_Virtual --
7619          -----------------
7620
7621          when Pragma_CPP_Virtual => CPP_Virtual : declare
7622          begin
7623             GNAT_Pragma;
7624
7625             if Warn_On_Obsolescent_Feature then
7626                Error_Msg_N
7627                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7628                   "no effect?", N);
7629             end if;
7630          end CPP_Virtual;
7631
7632          ----------------
7633          -- CPP_Vtable --
7634          ----------------
7635
7636          when Pragma_CPP_Vtable => CPP_Vtable : declare
7637          begin
7638             GNAT_Pragma;
7639
7640             if Warn_On_Obsolescent_Feature then
7641                Error_Msg_N
7642                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7643                   "no effect?", N);
7644             end if;
7645          end CPP_Vtable;
7646
7647          ---------
7648          -- CPU --
7649          ---------
7650
7651          --  pragma CPU (EXPRESSION);
7652
7653          when Pragma_CPU => CPU : declare
7654             P   : constant Node_Id := Parent (N);
7655             Arg : Node_Id;
7656
7657          begin
7658             Ada_2012_Pragma;
7659             Check_No_Identifiers;
7660             Check_Arg_Count (1);
7661
7662             --  Subprogram case
7663
7664             if Nkind (P) = N_Subprogram_Body then
7665                Check_In_Main_Program;
7666
7667                Arg := Get_Pragma_Arg (Arg1);
7668                Analyze_And_Resolve (Arg, Any_Integer);
7669
7670                --  Must be static
7671
7672                if not Is_Static_Expression (Arg) then
7673                   Flag_Non_Static_Expr
7674                     ("main subprogram affinity is not static!", Arg);
7675                   raise Pragma_Exit;
7676
7677                --  If constraint error, then we already signalled an error
7678
7679                elsif Raises_Constraint_Error (Arg) then
7680                   null;
7681
7682                --  Otherwise check in range
7683
7684                else
7685                   declare
7686                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7687                      --  This is the entity System.Multiprocessors.CPU_Range;
7688
7689                      Val : constant Uint := Expr_Value (Arg);
7690
7691                   begin
7692                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7693                           or else
7694                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7695                      then
7696                         Error_Pragma_Arg
7697                           ("main subprogram CPU is out of range", Arg1);
7698                      end if;
7699                   end;
7700                end if;
7701
7702                Set_Main_CPU
7703                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7704
7705             --  Task case
7706
7707             elsif Nkind (P) = N_Task_Definition then
7708                Arg := Get_Pragma_Arg (Arg1);
7709
7710                --  The expression must be analyzed in the special manner
7711                --  described in "Handling of Default and Per-Object
7712                --  Expressions" in sem.ads.
7713
7714                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7715
7716             --  Anything else is incorrect
7717
7718             else
7719                Pragma_Misplaced;
7720             end if;
7721
7722             if Has_Pragma_CPU (P) then
7723                Error_Pragma ("duplicate pragma% not allowed");
7724             else
7725                Set_Has_Pragma_CPU (P, True);
7726
7727                if Nkind (P) = N_Task_Definition then
7728                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7729                end if;
7730             end if;
7731          end CPU;
7732
7733          -----------
7734          -- Debug --
7735          -----------
7736
7737          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7738
7739          when Pragma_Debug => Debug : declare
7740             Cond : Node_Id;
7741             Call : Node_Id;
7742
7743          begin
7744             GNAT_Pragma;
7745
7746             --  Skip analysis if disabled
7747
7748             if Debug_Pragmas_Disabled then
7749                Rewrite (N, Make_Null_Statement (Loc));
7750                Analyze (N);
7751                return;
7752             end if;
7753
7754             Cond :=
7755               New_Occurrence_Of
7756                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7757                  Loc);
7758
7759             if Debug_Pragmas_Enabled then
7760                Set_SCO_Pragma_Enabled (Loc);
7761             end if;
7762
7763             if Arg_Count = 2 then
7764                Cond :=
7765                  Make_And_Then (Loc,
7766                    Left_Opnd  => Relocate_Node (Cond),
7767                    Right_Opnd => Get_Pragma_Arg (Arg1));
7768                Call := Get_Pragma_Arg (Arg2);
7769             else
7770                Call := Get_Pragma_Arg (Arg1);
7771             end if;
7772
7773             if Nkind_In (Call,
7774                  N_Indexed_Component,
7775                  N_Function_Call,
7776                  N_Identifier,
7777                  N_Selected_Component)
7778             then
7779                --  If this pragma Debug comes from source, its argument was
7780                --  parsed as a name form (which is syntactically identical).
7781                --  Change it to a procedure call statement now.
7782
7783                Change_Name_To_Procedure_Call_Statement (Call);
7784
7785             elsif Nkind (Call) = N_Procedure_Call_Statement then
7786
7787                --  Already in the form of a procedure call statement: nothing
7788                --  to do (could happen in case of an internally generated
7789                --  pragma Debug).
7790
7791                null;
7792
7793             else
7794                --  All other cases: diagnose error
7795
7796                Error_Msg
7797                  ("argument of pragma% is not procedure call", Sloc (Call));
7798                return;
7799             end if;
7800
7801             --  Rewrite into a conditional with an appropriate condition. We
7802             --  wrap the procedure call in a block so that overhead from e.g.
7803             --  use of the secondary stack does not generate execution overhead
7804             --  for suppressed conditions.
7805
7806             Rewrite (N, Make_Implicit_If_Statement (N,
7807               Condition => Cond,
7808                  Then_Statements => New_List (
7809                    Make_Block_Statement (Loc,
7810                      Handled_Statement_Sequence =>
7811                        Make_Handled_Sequence_Of_Statements (Loc,
7812                          Statements => New_List (Relocate_Node (Call)))))));
7813             Analyze (N);
7814          end Debug;
7815
7816          ------------------
7817          -- Debug_Policy --
7818          ------------------
7819
7820          --  pragma Debug_Policy (Check | Ignore)
7821
7822          when Pragma_Debug_Policy =>
7823             GNAT_Pragma;
7824             Check_Arg_Count (1);
7825             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7826             Debug_Pragmas_Enabled :=
7827               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7828             Debug_Pragmas_Disabled :=
7829               Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7830
7831          ---------------------
7832          -- Detect_Blocking --
7833          ---------------------
7834
7835          --  pragma Detect_Blocking;
7836
7837          when Pragma_Detect_Blocking =>
7838             Ada_2005_Pragma;
7839             Check_Arg_Count (0);
7840             Check_Valid_Configuration_Pragma;
7841             Detect_Blocking := True;
7842
7843          --------------------------
7844          -- Default_Storage_Pool --
7845          --------------------------
7846
7847          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7848
7849          when Pragma_Default_Storage_Pool =>
7850             Ada_2012_Pragma;
7851             Check_Arg_Count (1);
7852
7853             --  Default_Storage_Pool can appear as a configuration pragma, or
7854             --  in a declarative part or a package spec.
7855
7856             if not Is_Configuration_Pragma then
7857                Check_Is_In_Decl_Part_Or_Package_Spec;
7858             end if;
7859
7860             --  Case of Default_Storage_Pool (null);
7861
7862             if Nkind (Expression (Arg1)) = N_Null then
7863                Analyze (Expression (Arg1));
7864
7865                --  This is an odd case, this is not really an expression, so
7866                --  we don't have a type for it. So just set the type to Empty.
7867
7868                Set_Etype (Expression (Arg1), Empty);
7869
7870             --  Case of Default_Storage_Pool (storage_pool_NAME);
7871
7872             else
7873                --  If it's a configuration pragma, then the only allowed
7874                --  argument is "null".
7875
7876                if Is_Configuration_Pragma then
7877                   Error_Pragma_Arg ("NULL expected", Arg1);
7878                end if;
7879
7880                --  The expected type for a non-"null" argument is
7881                --  Root_Storage_Pool'Class.
7882
7883                Analyze_And_Resolve
7884                  (Get_Pragma_Arg (Arg1),
7885                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7886             end if;
7887
7888             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7889             --  for an access type will use this information to set the
7890             --  appropriate attributes of the access type.
7891
7892             Default_Pool := Expression (Arg1);
7893
7894          ---------------
7895          -- Dimension --
7896          ---------------
7897
7898          when Pragma_Dimension =>
7899             GNAT_Pragma;
7900             Check_Arg_Count (4);
7901             Check_No_Identifiers;
7902             Check_Arg_Is_Local_Name (Arg1);
7903
7904             if not Is_Type (Arg1) then
7905                Error_Pragma ("first argument for pragma% must be subtype");
7906             end if;
7907
7908             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7909             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7910             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7911
7912          -------------------
7913          -- Discard_Names --
7914          -------------------
7915
7916          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7917
7918          when Pragma_Discard_Names => Discard_Names : declare
7919             E    : Entity_Id;
7920             E_Id : Entity_Id;
7921
7922          begin
7923             Check_Ada_83_Warning;
7924
7925             --  Deal with configuration pragma case
7926
7927             if Arg_Count = 0 and then Is_Configuration_Pragma then
7928                Global_Discard_Names := True;
7929                return;
7930
7931             --  Otherwise, check correct appropriate context
7932
7933             else
7934                Check_Is_In_Decl_Part_Or_Package_Spec;
7935
7936                if Arg_Count = 0 then
7937
7938                   --  If there is no parameter, then from now on this pragma
7939                   --  applies to any enumeration, exception or tagged type
7940                   --  defined in the current declarative part, and recursively
7941                   --  to any nested scope.
7942
7943                   Set_Discard_Names (Current_Scope);
7944                   return;
7945
7946                else
7947                   Check_Arg_Count (1);
7948                   Check_Optional_Identifier (Arg1, Name_On);
7949                   Check_Arg_Is_Local_Name (Arg1);
7950
7951                   E_Id := Get_Pragma_Arg (Arg1);
7952
7953                   if Etype (E_Id) = Any_Type then
7954                      return;
7955                   else
7956                      E := Entity (E_Id);
7957                   end if;
7958
7959                   if (Is_First_Subtype (E)
7960                       and then
7961                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7962                     or else Ekind (E) = E_Exception
7963                   then
7964                      Set_Discard_Names (E);
7965                   else
7966                      Error_Pragma_Arg
7967                        ("inappropriate entity for pragma%", Arg1);
7968                   end if;
7969
7970                end if;
7971             end if;
7972          end Discard_Names;
7973
7974          ------------------------
7975          -- Dispatching_Domain --
7976          ------------------------
7977
7978          --  pragma Dispatching_Domain (EXPRESSION);
7979
7980          when Pragma_Dispatching_Domain => Dispatching_Domain : declare
7981             P   : constant Node_Id := Parent (N);
7982             Arg : Node_Id;
7983
7984          begin
7985             Ada_2012_Pragma;
7986             Check_No_Identifiers;
7987             Check_Arg_Count (1);
7988
7989             --  This pragma is born obsolete, but not the aspect
7990
7991             if not From_Aspect_Specification (N) then
7992                Check_Restriction
7993                  (No_Obsolescent_Features, Pragma_Identifier (N));
7994             end if;
7995
7996             if Nkind (P) = N_Task_Definition then
7997                Arg := Get_Pragma_Arg (Arg1);
7998
7999                --  The expression must be analyzed in the special manner
8000                --  described in "Handling of Default and Per-Object
8001                --  Expressions" in sem.ads.
8002
8003                Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8004
8005             --  Anything else is incorrect
8006
8007             else
8008                Pragma_Misplaced;
8009             end if;
8010
8011             if Has_Pragma_Dispatching_Domain (P) then
8012                Error_Pragma ("duplicate pragma% not allowed");
8013             else
8014                Set_Has_Pragma_Dispatching_Domain (P, True);
8015
8016                if Nkind (P) = N_Task_Definition then
8017                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8018                end if;
8019             end if;
8020          end Dispatching_Domain;
8021
8022          ---------------
8023          -- Elaborate --
8024          ---------------
8025
8026          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8027
8028          when Pragma_Elaborate => Elaborate : declare
8029             Arg   : Node_Id;
8030             Citem : Node_Id;
8031
8032          begin
8033             --  Pragma must be in context items list of a compilation unit
8034
8035             if not Is_In_Context_Clause then
8036                Pragma_Misplaced;
8037             end if;
8038
8039             --  Must be at least one argument
8040
8041             if Arg_Count = 0 then
8042                Error_Pragma ("pragma% requires at least one argument");
8043             end if;
8044
8045             --  In Ada 83 mode, there can be no items following it in the
8046             --  context list except other pragmas and implicit with clauses
8047             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8048             --  placement rule does not apply.
8049
8050             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8051                Citem := Next (N);
8052                while Present (Citem) loop
8053                   if Nkind (Citem) = N_Pragma
8054                     or else (Nkind (Citem) = N_With_Clause
8055                               and then Implicit_With (Citem))
8056                   then
8057                      null;
8058                   else
8059                      Error_Pragma
8060                        ("(Ada 83) pragma% must be at end of context clause");
8061                   end if;
8062
8063                   Next (Citem);
8064                end loop;
8065             end if;
8066
8067             --  Finally, the arguments must all be units mentioned in a with
8068             --  clause in the same context clause. Note we already checked (in
8069             --  Par.Prag) that the arguments are all identifiers or selected
8070             --  components.
8071
8072             Arg := Arg1;
8073             Outer : while Present (Arg) loop
8074                Citem := First (List_Containing (N));
8075                Inner : while Citem /= N loop
8076                   if Nkind (Citem) = N_With_Clause
8077                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8078                   then
8079                      Set_Elaborate_Present (Citem, True);
8080                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8081                      Generate_Reference (Entity (Name (Citem)), Citem);
8082
8083                      --  With the pragma present, elaboration calls on
8084                      --  subprograms from the named unit need no further
8085                      --  checks, as long as the pragma appears in the current
8086                      --  compilation unit. If the pragma appears in some unit
8087                      --  in the context, there might still be a need for an
8088                      --  Elaborate_All_Desirable from the current compilation
8089                      --  to the named unit, so we keep the check enabled.
8090
8091                      if In_Extended_Main_Source_Unit (N) then
8092                         Set_Suppress_Elaboration_Warnings
8093                           (Entity (Name (Citem)));
8094                      end if;
8095
8096                      exit Inner;
8097                   end if;
8098
8099                   Next (Citem);
8100                end loop Inner;
8101
8102                if Citem = N then
8103                   Error_Pragma_Arg
8104                     ("argument of pragma% is not with'ed unit", Arg);
8105                end if;
8106
8107                Next (Arg);
8108             end loop Outer;
8109
8110             --  Give a warning if operating in static mode with -gnatwl
8111             --  (elaboration warnings enabled) switch set.
8112
8113             if Elab_Warnings and not Dynamic_Elaboration_Checks then
8114                Error_Msg_N
8115                  ("?use of pragma Elaborate may not be safe", N);
8116                Error_Msg_N
8117                  ("?use pragma Elaborate_All instead if possible", N);
8118             end if;
8119          end Elaborate;
8120
8121          -------------------
8122          -- Elaborate_All --
8123          -------------------
8124
8125          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8126
8127          when Pragma_Elaborate_All => Elaborate_All : declare
8128             Arg   : Node_Id;
8129             Citem : Node_Id;
8130
8131          begin
8132             Check_Ada_83_Warning;
8133
8134             --  Pragma must be in context items list of a compilation unit
8135
8136             if not Is_In_Context_Clause then
8137                Pragma_Misplaced;
8138             end if;
8139
8140             --  Must be at least one argument
8141
8142             if Arg_Count = 0 then
8143                Error_Pragma ("pragma% requires at least one argument");
8144             end if;
8145
8146             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
8147             --  have to appear at the end of the context clause, but may
8148             --  appear mixed in with other items, even in Ada 83 mode.
8149
8150             --  Final check: the arguments must all be units mentioned in
8151             --  a with clause in the same context clause. Note that we
8152             --  already checked (in Par.Prag) that all the arguments are
8153             --  either identifiers or selected components.
8154
8155             Arg := Arg1;
8156             Outr : while Present (Arg) loop
8157                Citem := First (List_Containing (N));
8158                Innr : while Citem /= N loop
8159                   if Nkind (Citem) = N_With_Clause
8160                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8161                   then
8162                      Set_Elaborate_All_Present (Citem, True);
8163                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8164
8165                      --  Suppress warnings and elaboration checks on the named
8166                      --  unit if the pragma is in the current compilation, as
8167                      --  for pragma Elaborate.
8168
8169                      if In_Extended_Main_Source_Unit (N) then
8170                         Set_Suppress_Elaboration_Warnings
8171                           (Entity (Name (Citem)));
8172                      end if;
8173                      exit Innr;
8174                   end if;
8175
8176                   Next (Citem);
8177                end loop Innr;
8178
8179                if Citem = N then
8180                   Set_Error_Posted (N);
8181                   Error_Pragma_Arg
8182                     ("argument of pragma% is not with'ed unit", Arg);
8183                end if;
8184
8185                Next (Arg);
8186             end loop Outr;
8187          end Elaborate_All;
8188
8189          --------------------
8190          -- Elaborate_Body --
8191          --------------------
8192
8193          --  pragma Elaborate_Body [( library_unit_NAME )];
8194
8195          when Pragma_Elaborate_Body => Elaborate_Body : declare
8196             Cunit_Node : Node_Id;
8197             Cunit_Ent  : Entity_Id;
8198
8199          begin
8200             Check_Ada_83_Warning;
8201             Check_Valid_Library_Unit_Pragma;
8202
8203             if Nkind (N) = N_Null_Statement then
8204                return;
8205             end if;
8206
8207             Cunit_Node := Cunit (Current_Sem_Unit);
8208             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8209
8210             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8211                                             N_Subprogram_Body)
8212             then
8213                Error_Pragma ("pragma% must refer to a spec, not a body");
8214             else
8215                Set_Body_Required (Cunit_Node, True);
8216                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8217
8218                --  If we are in dynamic elaboration mode, then we suppress
8219                --  elaboration warnings for the unit, since it is definitely
8220                --  fine NOT to do dynamic checks at the first level (and such
8221                --  checks will be suppressed because no elaboration boolean
8222                --  is created for Elaborate_Body packages).
8223
8224                --  But in the static model of elaboration, Elaborate_Body is
8225                --  definitely NOT good enough to ensure elaboration safety on
8226                --  its own, since the body may WITH other units that are not
8227                --  safe from an elaboration point of view, so a client must
8228                --  still do an Elaborate_All on such units.
8229
8230                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8231                --  Elaborate_Body always suppressed elab warnings.
8232
8233                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8234                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8235                end if;
8236             end if;
8237          end Elaborate_Body;
8238
8239          ------------------------
8240          -- Elaboration_Checks --
8241          ------------------------
8242
8243          --  pragma Elaboration_Checks (Static | Dynamic);
8244
8245          when Pragma_Elaboration_Checks =>
8246             GNAT_Pragma;
8247             Check_Arg_Count (1);
8248             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8249             Dynamic_Elaboration_Checks :=
8250               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8251
8252          ---------------
8253          -- Eliminate --
8254          ---------------
8255
8256          --  pragma Eliminate (
8257          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8258          --    [,[Entity     =>] IDENTIFIER |
8259          --                      SELECTED_COMPONENT |
8260          --                      STRING_LITERAL]
8261          --    [,                OVERLOADING_RESOLUTION]);
8262
8263          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8264          --                             SOURCE_LOCATION
8265
8266          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8267          --                                        FUNCTION_PROFILE
8268
8269          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8270
8271          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8272          --                       Result_Type => result_SUBTYPE_NAME]
8273
8274          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8275          --  SUBTYPE_NAME    ::= STRING_LITERAL
8276
8277          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8278          --  SOURCE_TRACE    ::= STRING_LITERAL
8279
8280          when Pragma_Eliminate => Eliminate : declare
8281             Args  : Args_List (1 .. 5);
8282             Names : constant Name_List (1 .. 5) := (
8283                       Name_Unit_Name,
8284                       Name_Entity,
8285                       Name_Parameter_Types,
8286                       Name_Result_Type,
8287                       Name_Source_Location);
8288
8289             Unit_Name       : Node_Id renames Args (1);
8290             Entity          : Node_Id renames Args (2);
8291             Parameter_Types : Node_Id renames Args (3);
8292             Result_Type     : Node_Id renames Args (4);
8293             Source_Location : Node_Id renames Args (5);
8294
8295          begin
8296             GNAT_Pragma;
8297             Check_Valid_Configuration_Pragma;
8298             Gather_Associations (Names, Args);
8299
8300             if No (Unit_Name) then
8301                Error_Pragma ("missing Unit_Name argument for pragma%");
8302             end if;
8303
8304             if No (Entity)
8305               and then (Present (Parameter_Types)
8306                           or else
8307                         Present (Result_Type)
8308                           or else
8309                         Present (Source_Location))
8310             then
8311                Error_Pragma ("missing Entity argument for pragma%");
8312             end if;
8313
8314             if (Present (Parameter_Types)
8315                   or else
8316                 Present (Result_Type))
8317               and then
8318                 Present (Source_Location)
8319             then
8320                Error_Pragma
8321                  ("parameter profile and source location cannot " &
8322                   "be used together in pragma%");
8323             end if;
8324
8325             Process_Eliminate_Pragma
8326               (N,
8327                Unit_Name,
8328                Entity,
8329                Parameter_Types,
8330                Result_Type,
8331                Source_Location);
8332          end Eliminate;
8333
8334          ------------
8335          -- Export --
8336          ------------
8337
8338          --  pragma Export (
8339          --    [   Convention    =>] convention_IDENTIFIER,
8340          --    [   Entity        =>] local_NAME
8341          --    [, [External_Name =>] static_string_EXPRESSION ]
8342          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8343
8344          when Pragma_Export => Export : declare
8345             C      : Convention_Id;
8346             Def_Id : Entity_Id;
8347
8348             pragma Warnings (Off, C);
8349
8350          begin
8351             Check_Ada_83_Warning;
8352             Check_Arg_Order
8353               ((Name_Convention,
8354                 Name_Entity,
8355                 Name_External_Name,
8356                 Name_Link_Name));
8357             Check_At_Least_N_Arguments (2);
8358             Check_At_Most_N_Arguments  (4);
8359             Process_Convention (C, Def_Id);
8360
8361             if Ekind (Def_Id) /= E_Constant then
8362                Note_Possible_Modification
8363                  (Get_Pragma_Arg (Arg2), Sure => False);
8364             end if;
8365
8366             Process_Interface_Name (Def_Id, Arg3, Arg4);
8367             Set_Exported (Def_Id, Arg2);
8368
8369             --  If the entity is a deferred constant, propagate the information
8370             --  to the full view, because gigi elaborates the full view only.
8371
8372             if Ekind (Def_Id) = E_Constant
8373               and then Present (Full_View (Def_Id))
8374             then
8375                declare
8376                   Id2 : constant Entity_Id := Full_View (Def_Id);
8377                begin
8378                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8379                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8380                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8381                end;
8382             end if;
8383          end Export;
8384
8385          ----------------------
8386          -- Export_Exception --
8387          ----------------------
8388
8389          --  pragma Export_Exception (
8390          --        [Internal         =>] LOCAL_NAME
8391          --     [, [External         =>] EXTERNAL_SYMBOL]
8392          --     [, [Form     =>] Ada | VMS]
8393          --     [, [Code     =>] static_integer_EXPRESSION]);
8394
8395          when Pragma_Export_Exception => Export_Exception : declare
8396             Args  : Args_List (1 .. 4);
8397             Names : constant Name_List (1 .. 4) := (
8398                       Name_Internal,
8399                       Name_External,
8400                       Name_Form,
8401                       Name_Code);
8402
8403             Internal : Node_Id renames Args (1);
8404             External : Node_Id renames Args (2);
8405             Form     : Node_Id renames Args (3);
8406             Code     : Node_Id renames Args (4);
8407
8408          begin
8409             GNAT_Pragma;
8410
8411             if Inside_A_Generic then
8412                Error_Pragma ("pragma% cannot be used for generic entities");
8413             end if;
8414
8415             Gather_Associations (Names, Args);
8416             Process_Extended_Import_Export_Exception_Pragma (
8417               Arg_Internal => Internal,
8418               Arg_External => External,
8419               Arg_Form     => Form,
8420               Arg_Code     => Code);
8421
8422             if not Is_VMS_Exception (Entity (Internal)) then
8423                Set_Exported (Entity (Internal), Internal);
8424             end if;
8425          end Export_Exception;
8426
8427          ---------------------
8428          -- Export_Function --
8429          ---------------------
8430
8431          --  pragma Export_Function (
8432          --        [Internal         =>] LOCAL_NAME
8433          --     [, [External         =>] EXTERNAL_SYMBOL]
8434          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8435          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8436          --     [, [Mechanism        =>] MECHANISM]
8437          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8438
8439          --  EXTERNAL_SYMBOL ::=
8440          --    IDENTIFIER
8441          --  | static_string_EXPRESSION
8442
8443          --  PARAMETER_TYPES ::=
8444          --    null
8445          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8446
8447          --  TYPE_DESIGNATOR ::=
8448          --    subtype_NAME
8449          --  | subtype_Name ' Access
8450
8451          --  MECHANISM ::=
8452          --    MECHANISM_NAME
8453          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8454
8455          --  MECHANISM_ASSOCIATION ::=
8456          --    [formal_parameter_NAME =>] MECHANISM_NAME
8457
8458          --  MECHANISM_NAME ::=
8459          --    Value
8460          --  | Reference
8461          --  | Descriptor [([Class =>] CLASS_NAME)]
8462
8463          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8464
8465          when Pragma_Export_Function => Export_Function : declare
8466             Args  : Args_List (1 .. 6);
8467             Names : constant Name_List (1 .. 6) := (
8468                       Name_Internal,
8469                       Name_External,
8470                       Name_Parameter_Types,
8471                       Name_Result_Type,
8472                       Name_Mechanism,
8473                       Name_Result_Mechanism);
8474
8475             Internal         : Node_Id renames Args (1);
8476             External         : Node_Id renames Args (2);
8477             Parameter_Types  : Node_Id renames Args (3);
8478             Result_Type      : Node_Id renames Args (4);
8479             Mechanism        : Node_Id renames Args (5);
8480             Result_Mechanism : Node_Id renames Args (6);
8481
8482          begin
8483             GNAT_Pragma;
8484             Gather_Associations (Names, Args);
8485             Process_Extended_Import_Export_Subprogram_Pragma (
8486               Arg_Internal         => Internal,
8487               Arg_External         => External,
8488               Arg_Parameter_Types  => Parameter_Types,
8489               Arg_Result_Type      => Result_Type,
8490               Arg_Mechanism        => Mechanism,
8491               Arg_Result_Mechanism => Result_Mechanism);
8492          end Export_Function;
8493
8494          -------------------
8495          -- Export_Object --
8496          -------------------
8497
8498          --  pragma Export_Object (
8499          --        [Internal =>] LOCAL_NAME
8500          --     [, [External =>] EXTERNAL_SYMBOL]
8501          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8502
8503          --  EXTERNAL_SYMBOL ::=
8504          --    IDENTIFIER
8505          --  | static_string_EXPRESSION
8506
8507          --  PARAMETER_TYPES ::=
8508          --    null
8509          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8510
8511          --  TYPE_DESIGNATOR ::=
8512          --    subtype_NAME
8513          --  | subtype_Name ' Access
8514
8515          --  MECHANISM ::=
8516          --    MECHANISM_NAME
8517          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8518
8519          --  MECHANISM_ASSOCIATION ::=
8520          --    [formal_parameter_NAME =>] MECHANISM_NAME
8521
8522          --  MECHANISM_NAME ::=
8523          --    Value
8524          --  | Reference
8525          --  | Descriptor [([Class =>] CLASS_NAME)]
8526
8527          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8528
8529          when Pragma_Export_Object => Export_Object : declare
8530             Args  : Args_List (1 .. 3);
8531             Names : constant Name_List (1 .. 3) := (
8532                       Name_Internal,
8533                       Name_External,
8534                       Name_Size);
8535
8536             Internal : Node_Id renames Args (1);
8537             External : Node_Id renames Args (2);
8538             Size     : Node_Id renames Args (3);
8539
8540          begin
8541             GNAT_Pragma;
8542             Gather_Associations (Names, Args);
8543             Process_Extended_Import_Export_Object_Pragma (
8544               Arg_Internal => Internal,
8545               Arg_External => External,
8546               Arg_Size     => Size);
8547          end Export_Object;
8548
8549          ----------------------
8550          -- Export_Procedure --
8551          ----------------------
8552
8553          --  pragma Export_Procedure (
8554          --        [Internal         =>] LOCAL_NAME
8555          --     [, [External         =>] EXTERNAL_SYMBOL]
8556          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8557          --     [, [Mechanism        =>] MECHANISM]);
8558
8559          --  EXTERNAL_SYMBOL ::=
8560          --    IDENTIFIER
8561          --  | static_string_EXPRESSION
8562
8563          --  PARAMETER_TYPES ::=
8564          --    null
8565          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8566
8567          --  TYPE_DESIGNATOR ::=
8568          --    subtype_NAME
8569          --  | subtype_Name ' Access
8570
8571          --  MECHANISM ::=
8572          --    MECHANISM_NAME
8573          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8574
8575          --  MECHANISM_ASSOCIATION ::=
8576          --    [formal_parameter_NAME =>] MECHANISM_NAME
8577
8578          --  MECHANISM_NAME ::=
8579          --    Value
8580          --  | Reference
8581          --  | Descriptor [([Class =>] CLASS_NAME)]
8582
8583          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8584
8585          when Pragma_Export_Procedure => Export_Procedure : declare
8586             Args  : Args_List (1 .. 4);
8587             Names : constant Name_List (1 .. 4) := (
8588                       Name_Internal,
8589                       Name_External,
8590                       Name_Parameter_Types,
8591                       Name_Mechanism);
8592
8593             Internal        : Node_Id renames Args (1);
8594             External        : Node_Id renames Args (2);
8595             Parameter_Types : Node_Id renames Args (3);
8596             Mechanism       : Node_Id renames Args (4);
8597
8598          begin
8599             GNAT_Pragma;
8600             Gather_Associations (Names, Args);
8601             Process_Extended_Import_Export_Subprogram_Pragma (
8602               Arg_Internal        => Internal,
8603               Arg_External        => External,
8604               Arg_Parameter_Types => Parameter_Types,
8605               Arg_Mechanism       => Mechanism);
8606          end Export_Procedure;
8607
8608          ------------------
8609          -- Export_Value --
8610          ------------------
8611
8612          --  pragma Export_Value (
8613          --     [Value     =>] static_integer_EXPRESSION,
8614          --     [Link_Name =>] static_string_EXPRESSION);
8615
8616          when Pragma_Export_Value =>
8617             GNAT_Pragma;
8618             Check_Arg_Order ((Name_Value, Name_Link_Name));
8619             Check_Arg_Count (2);
8620
8621             Check_Optional_Identifier (Arg1, Name_Value);
8622             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8623
8624             Check_Optional_Identifier (Arg2, Name_Link_Name);
8625             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8626
8627          -----------------------------
8628          -- Export_Valued_Procedure --
8629          -----------------------------
8630
8631          --  pragma Export_Valued_Procedure (
8632          --        [Internal         =>] LOCAL_NAME
8633          --     [, [External         =>] EXTERNAL_SYMBOL,]
8634          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8635          --     [, [Mechanism        =>] MECHANISM]);
8636
8637          --  EXTERNAL_SYMBOL ::=
8638          --    IDENTIFIER
8639          --  | static_string_EXPRESSION
8640
8641          --  PARAMETER_TYPES ::=
8642          --    null
8643          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8644
8645          --  TYPE_DESIGNATOR ::=
8646          --    subtype_NAME
8647          --  | subtype_Name ' Access
8648
8649          --  MECHANISM ::=
8650          --    MECHANISM_NAME
8651          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8652
8653          --  MECHANISM_ASSOCIATION ::=
8654          --    [formal_parameter_NAME =>] MECHANISM_NAME
8655
8656          --  MECHANISM_NAME ::=
8657          --    Value
8658          --  | Reference
8659          --  | Descriptor [([Class =>] CLASS_NAME)]
8660
8661          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8662
8663          when Pragma_Export_Valued_Procedure =>
8664          Export_Valued_Procedure : declare
8665             Args  : Args_List (1 .. 4);
8666             Names : constant Name_List (1 .. 4) := (
8667                       Name_Internal,
8668                       Name_External,
8669                       Name_Parameter_Types,
8670                       Name_Mechanism);
8671
8672             Internal        : Node_Id renames Args (1);
8673             External        : Node_Id renames Args (2);
8674             Parameter_Types : Node_Id renames Args (3);
8675             Mechanism       : Node_Id renames Args (4);
8676
8677          begin
8678             GNAT_Pragma;
8679             Gather_Associations (Names, Args);
8680             Process_Extended_Import_Export_Subprogram_Pragma (
8681               Arg_Internal        => Internal,
8682               Arg_External        => External,
8683               Arg_Parameter_Types => Parameter_Types,
8684               Arg_Mechanism       => Mechanism);
8685          end Export_Valued_Procedure;
8686
8687          -------------------
8688          -- Extend_System --
8689          -------------------
8690
8691          --  pragma Extend_System ([Name =>] Identifier);
8692
8693          when Pragma_Extend_System => Extend_System : declare
8694          begin
8695             GNAT_Pragma;
8696             Check_Valid_Configuration_Pragma;
8697             Check_Arg_Count (1);
8698             Check_Optional_Identifier (Arg1, Name_Name);
8699             Check_Arg_Is_Identifier (Arg1);
8700
8701             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8702
8703             if Name_Len > 4
8704               and then Name_Buffer (1 .. 4) = "aux_"
8705             then
8706                if Present (System_Extend_Pragma_Arg) then
8707                   if Chars (Get_Pragma_Arg (Arg1)) =
8708                      Chars (Expression (System_Extend_Pragma_Arg))
8709                   then
8710                      null;
8711                   else
8712                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8713                      Error_Pragma ("pragma% conflicts with that #");
8714                   end if;
8715
8716                else
8717                   System_Extend_Pragma_Arg := Arg1;
8718
8719                   if not GNAT_Mode then
8720                      System_Extend_Unit := Arg1;
8721                   end if;
8722                end if;
8723             else
8724                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8725             end if;
8726          end Extend_System;
8727
8728          ------------------------
8729          -- Extensions_Allowed --
8730          ------------------------
8731
8732          --  pragma Extensions_Allowed (ON | OFF);
8733
8734          when Pragma_Extensions_Allowed =>
8735             GNAT_Pragma;
8736             Check_Arg_Count (1);
8737             Check_No_Identifiers;
8738             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8739
8740             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8741                Extensions_Allowed := True;
8742                Ada_Version := Ada_Version_Type'Last;
8743
8744             else
8745                Extensions_Allowed := False;
8746                Ada_Version := Ada_Version_Explicit;
8747             end if;
8748
8749          --------------
8750          -- External --
8751          --------------
8752
8753          --  pragma External (
8754          --    [   Convention    =>] convention_IDENTIFIER,
8755          --    [   Entity        =>] local_NAME
8756          --    [, [External_Name =>] static_string_EXPRESSION ]
8757          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8758
8759          when Pragma_External => External : declare
8760                Def_Id : Entity_Id;
8761
8762                C : Convention_Id;
8763                pragma Warnings (Off, C);
8764
8765          begin
8766             GNAT_Pragma;
8767             Check_Arg_Order
8768               ((Name_Convention,
8769                 Name_Entity,
8770                 Name_External_Name,
8771                 Name_Link_Name));
8772             Check_At_Least_N_Arguments (2);
8773             Check_At_Most_N_Arguments  (4);
8774             Process_Convention (C, Def_Id);
8775             Note_Possible_Modification
8776               (Get_Pragma_Arg (Arg2), Sure => False);
8777             Process_Interface_Name (Def_Id, Arg3, Arg4);
8778             Set_Exported (Def_Id, Arg2);
8779          end External;
8780
8781          --------------------------
8782          -- External_Name_Casing --
8783          --------------------------
8784
8785          --  pragma External_Name_Casing (
8786          --    UPPERCASE | LOWERCASE
8787          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8788
8789          when Pragma_External_Name_Casing => External_Name_Casing : declare
8790          begin
8791             GNAT_Pragma;
8792             Check_No_Identifiers;
8793
8794             if Arg_Count = 2 then
8795                Check_Arg_Is_One_Of
8796                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8797
8798                case Chars (Get_Pragma_Arg (Arg2)) is
8799                   when Name_As_Is     =>
8800                      Opt.External_Name_Exp_Casing := As_Is;
8801
8802                   when Name_Uppercase =>
8803                      Opt.External_Name_Exp_Casing := Uppercase;
8804
8805                   when Name_Lowercase =>
8806                      Opt.External_Name_Exp_Casing := Lowercase;
8807
8808                   when others =>
8809                      null;
8810                end case;
8811
8812             else
8813                Check_Arg_Count (1);
8814             end if;
8815
8816             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8817
8818             case Chars (Get_Pragma_Arg (Arg1)) is
8819                when Name_Uppercase =>
8820                   Opt.External_Name_Imp_Casing := Uppercase;
8821
8822                when Name_Lowercase =>
8823                   Opt.External_Name_Imp_Casing := Lowercase;
8824
8825                when others =>
8826                   null;
8827             end case;
8828          end External_Name_Casing;
8829
8830          --------------------------
8831          -- Favor_Top_Level --
8832          --------------------------
8833
8834          --  pragma Favor_Top_Level (type_NAME);
8835
8836          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8837                Named_Entity : Entity_Id;
8838
8839          begin
8840             GNAT_Pragma;
8841             Check_No_Identifiers;
8842             Check_Arg_Count (1);
8843             Check_Arg_Is_Local_Name (Arg1);
8844             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8845
8846             --  If it's an access-to-subprogram type (in particular, not a
8847             --  subtype), set the flag on that type.
8848
8849             if Is_Access_Subprogram_Type (Named_Entity) then
8850                Set_Can_Use_Internal_Rep (Named_Entity, False);
8851
8852             --  Otherwise it's an error (name denotes the wrong sort of entity)
8853
8854             else
8855                Error_Pragma_Arg
8856                  ("access-to-subprogram type expected",
8857                   Get_Pragma_Arg (Arg1));
8858             end if;
8859          end Favor_Top_Level;
8860
8861          ---------------
8862          -- Fast_Math --
8863          ---------------
8864
8865          --  pragma Fast_Math;
8866
8867          when Pragma_Fast_Math =>
8868             GNAT_Pragma;
8869             Check_No_Identifiers;
8870             Check_Valid_Configuration_Pragma;
8871             Fast_Math := True;
8872
8873          ---------------------------
8874          -- Finalize_Storage_Only --
8875          ---------------------------
8876
8877          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8878
8879          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8880             Assoc   : constant Node_Id := Arg1;
8881             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8882             Typ     : Entity_Id;
8883
8884          begin
8885             GNAT_Pragma;
8886             Check_No_Identifiers;
8887             Check_Arg_Count (1);
8888             Check_Arg_Is_Local_Name (Arg1);
8889
8890             Find_Type (Type_Id);
8891             Typ := Entity (Type_Id);
8892
8893             if Typ = Any_Type
8894               or else Rep_Item_Too_Early (Typ, N)
8895             then
8896                return;
8897             else
8898                Typ := Underlying_Type (Typ);
8899             end if;
8900
8901             if not Is_Controlled (Typ) then
8902                Error_Pragma ("pragma% must specify controlled type");
8903             end if;
8904
8905             Check_First_Subtype (Arg1);
8906
8907             if Finalize_Storage_Only (Typ) then
8908                Error_Pragma ("duplicate pragma%, only one allowed");
8909
8910             elsif not Rep_Item_Too_Late (Typ, N) then
8911                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8912             end if;
8913          end Finalize_Storage;
8914
8915          --------------------------
8916          -- Float_Representation --
8917          --------------------------
8918
8919          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8920
8921          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8922
8923          when Pragma_Float_Representation => Float_Representation : declare
8924             Argx : Node_Id;
8925             Digs : Nat;
8926             Ent  : Entity_Id;
8927
8928          begin
8929             GNAT_Pragma;
8930
8931             if Arg_Count = 1 then
8932                Check_Valid_Configuration_Pragma;
8933             else
8934                Check_Arg_Count (2);
8935                Check_Optional_Identifier (Arg2, Name_Entity);
8936                Check_Arg_Is_Local_Name (Arg2);
8937             end if;
8938
8939             Check_No_Identifier (Arg1);
8940             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8941
8942             if not OpenVMS_On_Target then
8943                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8944                   Error_Pragma
8945                     ("?pragma% ignored (applies only to Open'V'M'S)");
8946                end if;
8947
8948                return;
8949             end if;
8950
8951             --  One argument case
8952
8953             if Arg_Count = 1 then
8954                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8955                   if Opt.Float_Format = 'I' then
8956                      Error_Pragma ("'I'E'E'E format previously specified");
8957                   end if;
8958
8959                   Opt.Float_Format := 'V';
8960
8961                else
8962                   if Opt.Float_Format = 'V' then
8963                      Error_Pragma ("'V'A'X format previously specified");
8964                   end if;
8965
8966                   Opt.Float_Format := 'I';
8967                end if;
8968
8969                Set_Standard_Fpt_Formats;
8970
8971             --  Two argument case
8972
8973             else
8974                Argx := Get_Pragma_Arg (Arg2);
8975
8976                if not Is_Entity_Name (Argx)
8977                  or else not Is_Floating_Point_Type (Entity (Argx))
8978                then
8979                   Error_Pragma_Arg
8980                     ("second argument of% pragma must be floating-point type",
8981                      Arg2);
8982                end if;
8983
8984                Ent  := Entity (Argx);
8985                Digs := UI_To_Int (Digits_Value (Ent));
8986
8987                --  Two arguments, VAX_Float case
8988
8989                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8990                   case Digs is
8991                      when  6 => Set_F_Float (Ent);
8992                      when  9 => Set_D_Float (Ent);
8993                      when 15 => Set_G_Float (Ent);
8994
8995                      when others =>
8996                         Error_Pragma_Arg
8997                           ("wrong digits value, must be 6,9 or 15", Arg2);
8998                   end case;
8999
9000                --  Two arguments, IEEE_Float case
9001
9002                else
9003                   case Digs is
9004                      when  6 => Set_IEEE_Short (Ent);
9005                      when 15 => Set_IEEE_Long  (Ent);
9006
9007                      when others =>
9008                         Error_Pragma_Arg
9009                           ("wrong digits value, must be 6 or 15", Arg2);
9010                   end case;
9011                end if;
9012             end if;
9013          end Float_Representation;
9014
9015          -----------
9016          -- Ident --
9017          -----------
9018
9019          --  pragma Ident (static_string_EXPRESSION)
9020
9021          --  Note: pragma Comment shares this processing. Pragma Comment is
9022          --  identical to Ident, except that the restriction of the argument to
9023          --  31 characters and the placement restrictions are not enforced for
9024          --  pragma Comment.
9025
9026          when Pragma_Ident | Pragma_Comment => Ident : declare
9027             Str : Node_Id;
9028
9029          begin
9030             GNAT_Pragma;
9031             Check_Arg_Count (1);
9032             Check_No_Identifiers;
9033             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9034             Store_Note (N);
9035
9036             --  For pragma Ident, preserve DEC compatibility by requiring the
9037             --  pragma to appear in a declarative part or package spec.
9038
9039             if Prag_Id = Pragma_Ident then
9040                Check_Is_In_Decl_Part_Or_Package_Spec;
9041             end if;
9042
9043             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9044
9045             declare
9046                CS : Node_Id;
9047                GP : Node_Id;
9048
9049             begin
9050                GP := Parent (Parent (N));
9051
9052                if Nkind_In (GP, N_Package_Declaration,
9053                                 N_Generic_Package_Declaration)
9054                then
9055                   GP := Parent (GP);
9056                end if;
9057
9058                --  If we have a compilation unit, then record the ident value,
9059                --  checking for improper duplication.
9060
9061                if Nkind (GP) = N_Compilation_Unit then
9062                   CS := Ident_String (Current_Sem_Unit);
9063
9064                   if Present (CS) then
9065
9066                      --  For Ident, we do not permit multiple instances
9067
9068                      if Prag_Id = Pragma_Ident then
9069                         Error_Pragma ("duplicate% pragma not permitted");
9070
9071                      --  For Comment, we concatenate the string, unless we want
9072                      --  to preserve the tree structure for ASIS.
9073
9074                      elsif not ASIS_Mode then
9075                         Start_String (Strval (CS));
9076                         Store_String_Char (' ');
9077                         Store_String_Chars (Strval (Str));
9078                         Set_Strval (CS, End_String);
9079                      end if;
9080
9081                   else
9082                      --  In VMS, the effect of IDENT is achieved by passing
9083                      --  --identification=name as a --for-linker switch.
9084
9085                      if OpenVMS_On_Target then
9086                         Start_String;
9087                         Store_String_Chars
9088                           ("--for-linker=--identification=");
9089                         String_To_Name_Buffer (Strval (Str));
9090                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
9091
9092                         --  Only the last processed IDENT is saved. The main
9093                         --  purpose is so an IDENT associated with a main
9094                         --  procedure will be used in preference to an IDENT
9095                         --  associated with a with'd package.
9096
9097                         Replace_Linker_Option_String
9098                           (End_String, "--for-linker=--identification=");
9099                      end if;
9100
9101                      Set_Ident_String (Current_Sem_Unit, Str);
9102                   end if;
9103
9104                --  For subunits, we just ignore the Ident, since in GNAT these
9105                --  are not separate object files, and hence not separate units
9106                --  in the unit table.
9107
9108                elsif Nkind (GP) = N_Subunit then
9109                   null;
9110
9111                --  Otherwise we have a misplaced pragma Ident, but we ignore
9112                --  this if we are in an instantiation, since it comes from
9113                --  a generic, and has no relevance to the instantiation.
9114
9115                elsif Prag_Id = Pragma_Ident then
9116                   if Instantiation_Location (Loc) = No_Location then
9117                      Error_Pragma ("pragma% only allowed at outer level");
9118                   end if;
9119                end if;
9120             end;
9121          end Ident;
9122
9123          -----------------
9124          -- Implemented --
9125          -----------------
9126
9127          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9128          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9129
9130          when Pragma_Implemented => Implemented : declare
9131             Proc_Id : Entity_Id;
9132             Typ     : Entity_Id;
9133
9134          begin
9135             Ada_2012_Pragma;
9136             Check_Arg_Count (2);
9137             Check_No_Identifiers;
9138             Check_Arg_Is_Identifier (Arg1);
9139             Check_Arg_Is_Local_Name (Arg1);
9140             Check_Arg_Is_One_Of
9141               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9142
9143             --  Extract the name of the local procedure
9144
9145             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9146
9147             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9148             --  primitive procedure of a synchronized tagged type.
9149
9150             if Ekind (Proc_Id) = E_Procedure
9151               and then Is_Primitive (Proc_Id)
9152               and then Present (First_Formal (Proc_Id))
9153             then
9154                Typ := Etype (First_Formal (Proc_Id));
9155
9156                if Is_Tagged_Type (Typ)
9157                  and then
9158
9159                   --  Check for a protected, a synchronized or a task interface
9160
9161                    ((Is_Interface (Typ)
9162                        and then Is_Synchronized_Interface (Typ))
9163
9164                   --  Check for a protected type or a task type that implements
9165                   --  an interface.
9166
9167                    or else
9168                     (Is_Concurrent_Record_Type (Typ)
9169                        and then Present (Interfaces (Typ)))
9170
9171                   --  Check for a private record extension with keyword
9172                   --  "synchronized".
9173
9174                    or else
9175                     (Ekind_In (Typ, E_Record_Type_With_Private,
9176                                     E_Record_Subtype_With_Private)
9177                        and then Synchronized_Present (Parent (Typ))))
9178                then
9179                   null;
9180                else
9181                   Error_Pragma_Arg
9182                     ("controlling formal must be of synchronized " &
9183                      "tagged type", Arg1);
9184                   return;
9185                end if;
9186
9187             --  Procedures declared inside a protected type must be accepted
9188
9189             elsif Ekind (Proc_Id) = E_Procedure
9190               and then Is_Protected_Type (Scope (Proc_Id))
9191             then
9192                null;
9193
9194             --  The first argument is not a primitive procedure
9195
9196             else
9197                Error_Pragma_Arg
9198                  ("pragma % must be applied to a primitive procedure", Arg1);
9199                return;
9200             end if;
9201
9202             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9203             --  By_Protected_Procedure to the primitive procedure of a task
9204             --  interface.
9205
9206             if Chars (Arg2) = Name_By_Protected_Procedure
9207               and then Is_Interface (Typ)
9208               and then Is_Task_Interface (Typ)
9209             then
9210                Error_Pragma_Arg
9211                  ("implementation kind By_Protected_Procedure cannot be " &
9212                   "applied to a task interface primitive", Arg2);
9213                return;
9214             end if;
9215
9216             Record_Rep_Item (Proc_Id, N);
9217          end Implemented;
9218
9219          ----------------------
9220          -- Implicit_Packing --
9221          ----------------------
9222
9223          --  pragma Implicit_Packing;
9224
9225          when Pragma_Implicit_Packing =>
9226             GNAT_Pragma;
9227             Check_Arg_Count (0);
9228             Implicit_Packing := True;
9229
9230          ------------
9231          -- Import --
9232          ------------
9233
9234          --  pragma Import (
9235          --       [Convention    =>] convention_IDENTIFIER,
9236          --       [Entity        =>] local_NAME
9237          --    [, [External_Name =>] static_string_EXPRESSION ]
9238          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9239
9240          when Pragma_Import =>
9241             Check_Ada_83_Warning;
9242             Check_Arg_Order
9243               ((Name_Convention,
9244                 Name_Entity,
9245                 Name_External_Name,
9246                 Name_Link_Name));
9247             Check_At_Least_N_Arguments (2);
9248             Check_At_Most_N_Arguments  (4);
9249             Process_Import_Or_Interface;
9250
9251          ----------------------
9252          -- Import_Exception --
9253          ----------------------
9254
9255          --  pragma Import_Exception (
9256          --        [Internal         =>] LOCAL_NAME
9257          --     [, [External         =>] EXTERNAL_SYMBOL]
9258          --     [, [Form     =>] Ada | VMS]
9259          --     [, [Code     =>] static_integer_EXPRESSION]);
9260
9261          when Pragma_Import_Exception => Import_Exception : declare
9262             Args  : Args_List (1 .. 4);
9263             Names : constant Name_List (1 .. 4) := (
9264                       Name_Internal,
9265                       Name_External,
9266                       Name_Form,
9267                       Name_Code);
9268
9269             Internal : Node_Id renames Args (1);
9270             External : Node_Id renames Args (2);
9271             Form     : Node_Id renames Args (3);
9272             Code     : Node_Id renames Args (4);
9273
9274          begin
9275             GNAT_Pragma;
9276             Gather_Associations (Names, Args);
9277
9278             if Present (External) and then Present (Code) then
9279                Error_Pragma
9280                  ("cannot give both External and Code options for pragma%");
9281             end if;
9282
9283             Process_Extended_Import_Export_Exception_Pragma (
9284               Arg_Internal => Internal,
9285               Arg_External => External,
9286               Arg_Form     => Form,
9287               Arg_Code     => Code);
9288
9289             if not Is_VMS_Exception (Entity (Internal)) then
9290                Set_Imported (Entity (Internal));
9291             end if;
9292          end Import_Exception;
9293
9294          ---------------------
9295          -- Import_Function --
9296          ---------------------
9297
9298          --  pragma Import_Function (
9299          --        [Internal                 =>] LOCAL_NAME,
9300          --     [, [External                 =>] EXTERNAL_SYMBOL]
9301          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9302          --     [, [Result_Type              =>] SUBTYPE_MARK]
9303          --     [, [Mechanism                =>] MECHANISM]
9304          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9305          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9306
9307          --  EXTERNAL_SYMBOL ::=
9308          --    IDENTIFIER
9309          --  | static_string_EXPRESSION
9310
9311          --  PARAMETER_TYPES ::=
9312          --    null
9313          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9314
9315          --  TYPE_DESIGNATOR ::=
9316          --    subtype_NAME
9317          --  | subtype_Name ' Access
9318
9319          --  MECHANISM ::=
9320          --    MECHANISM_NAME
9321          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9322
9323          --  MECHANISM_ASSOCIATION ::=
9324          --    [formal_parameter_NAME =>] MECHANISM_NAME
9325
9326          --  MECHANISM_NAME ::=
9327          --    Value
9328          --  | Reference
9329          --  | Descriptor [([Class =>] CLASS_NAME)]
9330
9331          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9332
9333          when Pragma_Import_Function => Import_Function : declare
9334             Args  : Args_List (1 .. 7);
9335             Names : constant Name_List (1 .. 7) := (
9336                       Name_Internal,
9337                       Name_External,
9338                       Name_Parameter_Types,
9339                       Name_Result_Type,
9340                       Name_Mechanism,
9341                       Name_Result_Mechanism,
9342                       Name_First_Optional_Parameter);
9343
9344             Internal                 : Node_Id renames Args (1);
9345             External                 : Node_Id renames Args (2);
9346             Parameter_Types          : Node_Id renames Args (3);
9347             Result_Type              : Node_Id renames Args (4);
9348             Mechanism                : Node_Id renames Args (5);
9349             Result_Mechanism         : Node_Id renames Args (6);
9350             First_Optional_Parameter : Node_Id renames Args (7);
9351
9352          begin
9353             GNAT_Pragma;
9354             Gather_Associations (Names, Args);
9355             Process_Extended_Import_Export_Subprogram_Pragma (
9356               Arg_Internal                 => Internal,
9357               Arg_External                 => External,
9358               Arg_Parameter_Types          => Parameter_Types,
9359               Arg_Result_Type              => Result_Type,
9360               Arg_Mechanism                => Mechanism,
9361               Arg_Result_Mechanism         => Result_Mechanism,
9362               Arg_First_Optional_Parameter => First_Optional_Parameter);
9363          end Import_Function;
9364
9365          -------------------
9366          -- Import_Object --
9367          -------------------
9368
9369          --  pragma Import_Object (
9370          --        [Internal =>] LOCAL_NAME
9371          --     [, [External =>] EXTERNAL_SYMBOL]
9372          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9373
9374          --  EXTERNAL_SYMBOL ::=
9375          --    IDENTIFIER
9376          --  | static_string_EXPRESSION
9377
9378          when Pragma_Import_Object => Import_Object : declare
9379             Args  : Args_List (1 .. 3);
9380             Names : constant Name_List (1 .. 3) := (
9381                       Name_Internal,
9382                       Name_External,
9383                       Name_Size);
9384
9385             Internal : Node_Id renames Args (1);
9386             External : Node_Id renames Args (2);
9387             Size     : Node_Id renames Args (3);
9388
9389          begin
9390             GNAT_Pragma;
9391             Gather_Associations (Names, Args);
9392             Process_Extended_Import_Export_Object_Pragma (
9393               Arg_Internal => Internal,
9394               Arg_External => External,
9395               Arg_Size     => Size);
9396          end Import_Object;
9397
9398          ----------------------
9399          -- Import_Procedure --
9400          ----------------------
9401
9402          --  pragma Import_Procedure (
9403          --        [Internal                 =>] LOCAL_NAME
9404          --     [, [External                 =>] EXTERNAL_SYMBOL]
9405          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9406          --     [, [Mechanism                =>] MECHANISM]
9407          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9408
9409          --  EXTERNAL_SYMBOL ::=
9410          --    IDENTIFIER
9411          --  | static_string_EXPRESSION
9412
9413          --  PARAMETER_TYPES ::=
9414          --    null
9415          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9416
9417          --  TYPE_DESIGNATOR ::=
9418          --    subtype_NAME
9419          --  | subtype_Name ' Access
9420
9421          --  MECHANISM ::=
9422          --    MECHANISM_NAME
9423          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9424
9425          --  MECHANISM_ASSOCIATION ::=
9426          --    [formal_parameter_NAME =>] MECHANISM_NAME
9427
9428          --  MECHANISM_NAME ::=
9429          --    Value
9430          --  | Reference
9431          --  | Descriptor [([Class =>] CLASS_NAME)]
9432
9433          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9434
9435          when Pragma_Import_Procedure => Import_Procedure : declare
9436             Args  : Args_List (1 .. 5);
9437             Names : constant Name_List (1 .. 5) := (
9438                       Name_Internal,
9439                       Name_External,
9440                       Name_Parameter_Types,
9441                       Name_Mechanism,
9442                       Name_First_Optional_Parameter);
9443
9444             Internal                 : Node_Id renames Args (1);
9445             External                 : Node_Id renames Args (2);
9446             Parameter_Types          : Node_Id renames Args (3);
9447             Mechanism                : Node_Id renames Args (4);
9448             First_Optional_Parameter : Node_Id renames Args (5);
9449
9450          begin
9451             GNAT_Pragma;
9452             Gather_Associations (Names, Args);
9453             Process_Extended_Import_Export_Subprogram_Pragma (
9454               Arg_Internal                 => Internal,
9455               Arg_External                 => External,
9456               Arg_Parameter_Types          => Parameter_Types,
9457               Arg_Mechanism                => Mechanism,
9458               Arg_First_Optional_Parameter => First_Optional_Parameter);
9459          end Import_Procedure;
9460
9461          -----------------------------
9462          -- Import_Valued_Procedure --
9463          -----------------------------
9464
9465          --  pragma Import_Valued_Procedure (
9466          --        [Internal                 =>] LOCAL_NAME
9467          --     [, [External                 =>] EXTERNAL_SYMBOL]
9468          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9469          --     [, [Mechanism                =>] MECHANISM]
9470          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9471
9472          --  EXTERNAL_SYMBOL ::=
9473          --    IDENTIFIER
9474          --  | static_string_EXPRESSION
9475
9476          --  PARAMETER_TYPES ::=
9477          --    null
9478          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9479
9480          --  TYPE_DESIGNATOR ::=
9481          --    subtype_NAME
9482          --  | subtype_Name ' Access
9483
9484          --  MECHANISM ::=
9485          --    MECHANISM_NAME
9486          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9487
9488          --  MECHANISM_ASSOCIATION ::=
9489          --    [formal_parameter_NAME =>] MECHANISM_NAME
9490
9491          --  MECHANISM_NAME ::=
9492          --    Value
9493          --  | Reference
9494          --  | Descriptor [([Class =>] CLASS_NAME)]
9495
9496          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9497
9498          when Pragma_Import_Valued_Procedure =>
9499          Import_Valued_Procedure : declare
9500             Args  : Args_List (1 .. 5);
9501             Names : constant Name_List (1 .. 5) := (
9502                       Name_Internal,
9503                       Name_External,
9504                       Name_Parameter_Types,
9505                       Name_Mechanism,
9506                       Name_First_Optional_Parameter);
9507
9508             Internal                 : Node_Id renames Args (1);
9509             External                 : Node_Id renames Args (2);
9510             Parameter_Types          : Node_Id renames Args (3);
9511             Mechanism                : Node_Id renames Args (4);
9512             First_Optional_Parameter : Node_Id renames Args (5);
9513
9514          begin
9515             GNAT_Pragma;
9516             Gather_Associations (Names, Args);
9517             Process_Extended_Import_Export_Subprogram_Pragma (
9518               Arg_Internal                 => Internal,
9519               Arg_External                 => External,
9520               Arg_Parameter_Types          => Parameter_Types,
9521               Arg_Mechanism                => Mechanism,
9522               Arg_First_Optional_Parameter => First_Optional_Parameter);
9523          end Import_Valued_Procedure;
9524
9525          -----------------
9526          -- Independent --
9527          -----------------
9528
9529          --  pragma Independent (LOCAL_NAME);
9530
9531          when Pragma_Independent => Independent : declare
9532             E_Id : Node_Id;
9533             E    : Entity_Id;
9534             D    : Node_Id;
9535             K    : Node_Kind;
9536
9537          begin
9538             Check_Ada_83_Warning;
9539             Ada_2012_Pragma;
9540             Check_No_Identifiers;
9541             Check_Arg_Count (1);
9542             Check_Arg_Is_Local_Name (Arg1);
9543             E_Id := Get_Pragma_Arg (Arg1);
9544
9545             if Etype (E_Id) = Any_Type then
9546                return;
9547             end if;
9548
9549             E := Entity (E_Id);
9550             D := Declaration_Node (E);
9551             K := Nkind (D);
9552
9553             --  Check duplicate before we chain ourselves!
9554
9555             Check_Duplicate_Pragma (E);
9556
9557             --  Check appropriate entity
9558
9559             if Is_Type (E) then
9560                if Rep_Item_Too_Early (E, N)
9561                     or else
9562                   Rep_Item_Too_Late (E, N)
9563                then
9564                   return;
9565                else
9566                   Check_First_Subtype (Arg1);
9567                end if;
9568
9569             elsif K = N_Object_Declaration
9570               or else (K = N_Component_Declaration
9571                        and then Original_Record_Component (E) = E)
9572             then
9573                if Rep_Item_Too_Late (E, N) then
9574                   return;
9575                end if;
9576
9577             else
9578                Error_Pragma_Arg
9579                  ("inappropriate entity for pragma%", Arg1);
9580             end if;
9581
9582             Independence_Checks.Append ((N, E));
9583          end Independent;
9584
9585          ----------------------------
9586          -- Independent_Components --
9587          ----------------------------
9588
9589          --  pragma Atomic_Components (array_LOCAL_NAME);
9590
9591          --  This processing is shared by Volatile_Components
9592
9593          when Pragma_Independent_Components => Independent_Components : declare
9594             E_Id : Node_Id;
9595             E    : Entity_Id;
9596             D    : Node_Id;
9597             K    : Node_Kind;
9598
9599          begin
9600             Check_Ada_83_Warning;
9601             Ada_2012_Pragma;
9602             Check_No_Identifiers;
9603             Check_Arg_Count (1);
9604             Check_Arg_Is_Local_Name (Arg1);
9605             E_Id := Get_Pragma_Arg (Arg1);
9606
9607             if Etype (E_Id) = Any_Type then
9608                return;
9609             end if;
9610
9611             E := Entity (E_Id);
9612
9613             --  Check duplicate before we chain ourselves!
9614
9615             Check_Duplicate_Pragma (E);
9616
9617             --  Check appropriate entity
9618
9619             if Rep_Item_Too_Early (E, N)
9620                  or else
9621                Rep_Item_Too_Late (E, N)
9622             then
9623                return;
9624             end if;
9625
9626             D := Declaration_Node (E);
9627             K := Nkind (D);
9628
9629             if (K = N_Full_Type_Declaration
9630                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9631               or else
9632                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9633                    and then Nkind (D) = N_Object_Declaration
9634                    and then Nkind (Object_Definition (D)) =
9635                                        N_Constrained_Array_Definition)
9636             then
9637                Independence_Checks.Append ((N, E));
9638
9639             else
9640                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9641             end if;
9642          end Independent_Components;
9643
9644          ------------------------
9645          -- Initialize_Scalars --
9646          ------------------------
9647
9648          --  pragma Initialize_Scalars;
9649
9650          when Pragma_Initialize_Scalars =>
9651             GNAT_Pragma;
9652             Check_Arg_Count (0);
9653             Check_Valid_Configuration_Pragma;
9654             Check_Restriction (No_Initialize_Scalars, N);
9655
9656             --  Initialize_Scalars creates false positives in CodePeer, and
9657             --  incorrect negative results in Alfa mode, so ignore this pragma
9658             --  in these modes.
9659
9660             if not Restriction_Active (No_Initialize_Scalars)
9661               and then not (CodePeer_Mode or Alfa_Mode)
9662             then
9663                Init_Or_Norm_Scalars := True;
9664                Initialize_Scalars := True;
9665             end if;
9666
9667          ------------
9668          -- Inline --
9669          ------------
9670
9671          --  pragma Inline ( NAME {, NAME} );
9672
9673          when Pragma_Inline =>
9674
9675             --  Pragma is active if inlining option is active
9676
9677             Process_Inline (Inline_Active);
9678
9679          -------------------
9680          -- Inline_Always --
9681          -------------------
9682
9683          --  pragma Inline_Always ( NAME {, NAME} );
9684
9685          when Pragma_Inline_Always =>
9686             GNAT_Pragma;
9687
9688             --  Pragma always active unless in CodePeer or Alfa mode, since
9689             --  this causes walk order issues.
9690
9691             if not (CodePeer_Mode or Alfa_Mode) then
9692                Process_Inline (True);
9693             end if;
9694
9695          --------------------
9696          -- Inline_Generic --
9697          --------------------
9698
9699          --  pragma Inline_Generic (NAME {, NAME});
9700
9701          when Pragma_Inline_Generic =>
9702             GNAT_Pragma;
9703             Process_Generic_List;
9704
9705          ----------------------
9706          -- Inspection_Point --
9707          ----------------------
9708
9709          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9710
9711          when Pragma_Inspection_Point => Inspection_Point : declare
9712             Arg : Node_Id;
9713             Exp : Node_Id;
9714
9715          begin
9716             if Arg_Count > 0 then
9717                Arg := Arg1;
9718                loop
9719                   Exp := Get_Pragma_Arg (Arg);
9720                   Analyze (Exp);
9721
9722                   if not Is_Entity_Name (Exp)
9723                     or else not Is_Object (Entity (Exp))
9724                   then
9725                      Error_Pragma_Arg ("object name required", Arg);
9726                   end if;
9727
9728                   Next (Arg);
9729                   exit when No (Arg);
9730                end loop;
9731             end if;
9732          end Inspection_Point;
9733
9734          ---------------
9735          -- Interface --
9736          ---------------
9737
9738          --  pragma Interface (
9739          --    [   Convention    =>] convention_IDENTIFIER,
9740          --    [   Entity        =>] local_NAME
9741          --    [, [External_Name =>] static_string_EXPRESSION ]
9742          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9743
9744          when Pragma_Interface =>
9745             GNAT_Pragma;
9746             Check_Arg_Order
9747               ((Name_Convention,
9748                 Name_Entity,
9749                 Name_External_Name,
9750                 Name_Link_Name));
9751             Check_At_Least_N_Arguments (2);
9752             Check_At_Most_N_Arguments  (4);
9753             Process_Import_Or_Interface;
9754
9755             --  In Ada 2005, the permission to use Interface (a reserved word)
9756             --  as a pragma name is considered an obsolescent feature.
9757
9758             if Ada_Version >= Ada_2005 then
9759                Check_Restriction
9760                  (No_Obsolescent_Features, Pragma_Identifier (N));
9761             end if;
9762
9763          --------------------
9764          -- Interface_Name --
9765          --------------------
9766
9767          --  pragma Interface_Name (
9768          --    [  Entity        =>] local_NAME
9769          --    [,[External_Name =>] static_string_EXPRESSION ]
9770          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9771
9772          when Pragma_Interface_Name => Interface_Name : declare
9773             Id     : Node_Id;
9774             Def_Id : Entity_Id;
9775             Hom_Id : Entity_Id;
9776             Found  : Boolean;
9777
9778          begin
9779             GNAT_Pragma;
9780             Check_Arg_Order
9781               ((Name_Entity, Name_External_Name, Name_Link_Name));
9782             Check_At_Least_N_Arguments (2);
9783             Check_At_Most_N_Arguments  (3);
9784             Id := Get_Pragma_Arg (Arg1);
9785             Analyze (Id);
9786
9787             if not Is_Entity_Name (Id) then
9788                Error_Pragma_Arg
9789                  ("first argument for pragma% must be entity name", Arg1);
9790             elsif Etype (Id) = Any_Type then
9791                return;
9792             else
9793                Def_Id := Entity (Id);
9794             end if;
9795
9796             --  Special DEC-compatible processing for the object case, forces
9797             --  object to be imported.
9798
9799             if Ekind (Def_Id) = E_Variable then
9800                Kill_Size_Check_Code (Def_Id);
9801                Note_Possible_Modification (Id, Sure => False);
9802
9803                --  Initialization is not allowed for imported variable
9804
9805                if Present (Expression (Parent (Def_Id)))
9806                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9807                then
9808                   Error_Msg_Sloc := Sloc (Def_Id);
9809                   Error_Pragma_Arg
9810                     ("no initialization allowed for declaration of& #",
9811                      Arg2);
9812
9813                else
9814                   --  For compatibility, support VADS usage of providing both
9815                   --  pragmas Interface and Interface_Name to obtain the effect
9816                   --  of a single Import pragma.
9817
9818                   if Is_Imported (Def_Id)
9819                     and then Present (First_Rep_Item (Def_Id))
9820                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9821                     and then
9822                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9823                   then
9824                      null;
9825                   else
9826                      Set_Imported (Def_Id);
9827                   end if;
9828
9829                   Set_Is_Public (Def_Id);
9830                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9831                end if;
9832
9833             --  Otherwise must be subprogram
9834
9835             elsif not Is_Subprogram (Def_Id) then
9836                Error_Pragma_Arg
9837                  ("argument of pragma% is not subprogram", Arg1);
9838
9839             else
9840                Check_At_Most_N_Arguments (3);
9841                Hom_Id := Def_Id;
9842                Found := False;
9843
9844                --  Loop through homonyms
9845
9846                loop
9847                   Def_Id := Get_Base_Subprogram (Hom_Id);
9848
9849                   if Is_Imported (Def_Id) then
9850                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9851                      Found := True;
9852                   end if;
9853
9854                   exit when From_Aspect_Specification (N);
9855                   Hom_Id := Homonym (Hom_Id);
9856
9857                   exit when No (Hom_Id)
9858                     or else Scope (Hom_Id) /= Current_Scope;
9859                end loop;
9860
9861                if not Found then
9862                   Error_Pragma_Arg
9863                     ("argument of pragma% is not imported subprogram",
9864                      Arg1);
9865                end if;
9866             end if;
9867          end Interface_Name;
9868
9869          -----------------------
9870          -- Interrupt_Handler --
9871          -----------------------
9872
9873          --  pragma Interrupt_Handler (handler_NAME);
9874
9875          when Pragma_Interrupt_Handler =>
9876             Check_Ada_83_Warning;
9877             Check_Arg_Count (1);
9878             Check_No_Identifiers;
9879
9880             if No_Run_Time_Mode then
9881                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9882             else
9883                Check_Interrupt_Or_Attach_Handler;
9884                Process_Interrupt_Or_Attach_Handler;
9885             end if;
9886
9887          ------------------------
9888          -- Interrupt_Priority --
9889          ------------------------
9890
9891          --  pragma Interrupt_Priority [(EXPRESSION)];
9892
9893          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9894             P   : constant Node_Id := Parent (N);
9895             Arg : Node_Id;
9896
9897          begin
9898             Check_Ada_83_Warning;
9899
9900             if Arg_Count /= 0 then
9901                Arg := Get_Pragma_Arg (Arg1);
9902                Check_Arg_Count (1);
9903                Check_No_Identifiers;
9904
9905                --  The expression must be analyzed in the special manner
9906                --  described in "Handling of Default and Per-Object
9907                --  Expressions" in sem.ads.
9908
9909                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9910             end if;
9911
9912             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9913                Pragma_Misplaced;
9914                return;
9915
9916             elsif Has_Pragma_Priority (P) then
9917                Error_Pragma ("duplicate pragma% not allowed");
9918
9919             else
9920                Set_Has_Pragma_Priority (P, True);
9921                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9922             end if;
9923          end Interrupt_Priority;
9924
9925          ---------------------
9926          -- Interrupt_State --
9927          ---------------------
9928
9929          --  pragma Interrupt_State (
9930          --    [Name  =>] INTERRUPT_ID,
9931          --    [State =>] INTERRUPT_STATE);
9932
9933          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9934          --  INTERRUPT_STATE => System | Runtime | User
9935
9936          --  Note: if the interrupt id is given as an identifier, then it must
9937          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9938          --  given as a static integer expression which must be in the range of
9939          --  Ada.Interrupts.Interrupt_ID.
9940
9941          when Pragma_Interrupt_State => Interrupt_State : declare
9942
9943             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9944             --  This is the entity Ada.Interrupts.Interrupt_ID;
9945
9946             State_Type : Character;
9947             --  Set to 's'/'r'/'u' for System/Runtime/User
9948
9949             IST_Num : Pos;
9950             --  Index to entry in Interrupt_States table
9951
9952             Int_Val : Uint;
9953             --  Value of interrupt
9954
9955             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9956             --  The first argument to the pragma
9957
9958             Int_Ent : Entity_Id;
9959             --  Interrupt entity in Ada.Interrupts.Names
9960
9961          begin
9962             GNAT_Pragma;
9963             Check_Arg_Order ((Name_Name, Name_State));
9964             Check_Arg_Count (2);
9965
9966             Check_Optional_Identifier (Arg1, Name_Name);
9967             Check_Optional_Identifier (Arg2, Name_State);
9968             Check_Arg_Is_Identifier (Arg2);
9969
9970             --  First argument is identifier
9971
9972             if Nkind (Arg1X) = N_Identifier then
9973
9974                --  Search list of names in Ada.Interrupts.Names
9975
9976                Int_Ent := First_Entity (RTE (RE_Names));
9977                loop
9978                   if No (Int_Ent) then
9979                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9980
9981                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9982                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9983                      exit;
9984                   end if;
9985
9986                   Next_Entity (Int_Ent);
9987                end loop;
9988
9989             --  First argument is not an identifier, so it must be a static
9990             --  expression of type Ada.Interrupts.Interrupt_ID.
9991
9992             else
9993                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9994                Int_Val := Expr_Value (Arg1X);
9995
9996                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9997                     or else
9998                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9999                then
10000                   Error_Pragma_Arg
10001                     ("value not in range of type " &
10002                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10003                end if;
10004             end if;
10005
10006             --  Check OK state
10007
10008             case Chars (Get_Pragma_Arg (Arg2)) is
10009                when Name_Runtime => State_Type := 'r';
10010                when Name_System  => State_Type := 's';
10011                when Name_User    => State_Type := 'u';
10012
10013                when others =>
10014                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
10015             end case;
10016
10017             --  Check if entry is already stored
10018
10019             IST_Num := Interrupt_States.First;
10020             loop
10021                --  If entry not found, add it
10022
10023                if IST_Num > Interrupt_States.Last then
10024                   Interrupt_States.Append
10025                     ((Interrupt_Number => UI_To_Int (Int_Val),
10026                       Interrupt_State  => State_Type,
10027                       Pragma_Loc       => Loc));
10028                   exit;
10029
10030                --  Case of entry for the same entry
10031
10032                elsif Int_Val = Interrupt_States.Table (IST_Num).
10033                                                            Interrupt_Number
10034                then
10035                   --  If state matches, done, no need to make redundant entry
10036
10037                   exit when
10038                     State_Type = Interrupt_States.Table (IST_Num).
10039                                                            Interrupt_State;
10040
10041                   --  Otherwise if state does not match, error
10042
10043                   Error_Msg_Sloc :=
10044                     Interrupt_States.Table (IST_Num).Pragma_Loc;
10045                   Error_Pragma_Arg
10046                     ("state conflicts with that given #", Arg2);
10047                   exit;
10048                end if;
10049
10050                IST_Num := IST_Num + 1;
10051             end loop;
10052          end Interrupt_State;
10053
10054          ---------------
10055          -- Invariant --
10056          ---------------
10057
10058          --  pragma Invariant
10059          --    ([Entity =>]    type_LOCAL_NAME,
10060          --     [Check  =>]    EXPRESSION
10061          --     [,[Message =>] String_Expression]);
10062
10063          when Pragma_Invariant => Invariant : declare
10064             Type_Id : Node_Id;
10065             Typ     : Entity_Id;
10066
10067             Discard : Boolean;
10068             pragma Unreferenced (Discard);
10069
10070          begin
10071             GNAT_Pragma;
10072             Check_At_Least_N_Arguments (2);
10073             Check_At_Most_N_Arguments (3);
10074             Check_Optional_Identifier (Arg1, Name_Entity);
10075             Check_Optional_Identifier (Arg2, Name_Check);
10076
10077             if Arg_Count = 3 then
10078                Check_Optional_Identifier (Arg3, Name_Message);
10079                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10080             end if;
10081
10082             Check_Arg_Is_Local_Name (Arg1);
10083
10084             Type_Id := Get_Pragma_Arg (Arg1);
10085             Find_Type (Type_Id);
10086             Typ := Entity (Type_Id);
10087
10088             if Typ = Any_Type then
10089                return;
10090
10091             elsif not Ekind_In (Typ, E_Private_Type,
10092                                      E_Record_Type_With_Private,
10093                                      E_Limited_Private_Type)
10094             then
10095                Error_Pragma_Arg
10096                  ("pragma% only allowed for private type", Arg1);
10097             end if;
10098
10099             --  Note that the type has at least one invariant, and also that
10100             --  it has inheritable invariants if we have Invariant'Class.
10101
10102             Set_Has_Invariants (Typ);
10103
10104             if Class_Present (N) then
10105                Set_Has_Inheritable_Invariants (Typ);
10106             end if;
10107
10108             --  The remaining processing is simply to link the pragma on to
10109             --  the rep item chain, for processing when the type is frozen.
10110             --  This is accomplished by a call to Rep_Item_Too_Late.
10111
10112             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10113          end Invariant;
10114
10115          ----------------------
10116          -- Java_Constructor --
10117          ----------------------
10118
10119          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10120
10121          --  Also handles pragma CIL_Constructor
10122
10123          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10124          Java_Constructor : declare
10125             Convention  : Convention_Id;
10126             Def_Id      : Entity_Id;
10127             Hom_Id      : Entity_Id;
10128             Id          : Entity_Id;
10129             This_Formal : Entity_Id;
10130
10131          begin
10132             GNAT_Pragma;
10133             Check_Arg_Count (1);
10134             Check_Optional_Identifier (Arg1, Name_Entity);
10135             Check_Arg_Is_Local_Name (Arg1);
10136
10137             Id := Get_Pragma_Arg (Arg1);
10138             Find_Program_Unit_Name (Id);
10139
10140             --  If we did not find the name, we are done
10141
10142             if Etype (Id) = Any_Type then
10143                return;
10144             end if;
10145
10146             --  Check wrong use of pragma in wrong VM target
10147
10148             if VM_Target = No_VM then
10149                return;
10150
10151             elsif VM_Target = CLI_Target
10152               and then Prag_Id = Pragma_Java_Constructor
10153             then
10154                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10155
10156             elsif VM_Target = JVM_Target
10157               and then Prag_Id = Pragma_CIL_Constructor
10158             then
10159                Error_Pragma ("must use pragma 'Java_'Constructor");
10160             end if;
10161
10162             case Prag_Id is
10163                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
10164                when Pragma_Java_Constructor => Convention := Convention_Java;
10165                when others                  => null;
10166             end case;
10167
10168             Hom_Id := Entity (Id);
10169
10170             --  Loop through homonyms
10171
10172             loop
10173                Def_Id := Get_Base_Subprogram (Hom_Id);
10174
10175                --  The constructor is required to be a function
10176
10177                if Ekind (Def_Id) /= E_Function then
10178                   if VM_Target = JVM_Target then
10179                      Error_Pragma_Arg
10180                        ("pragma% requires function returning a " &
10181                         "'Java access type", Def_Id);
10182                   else
10183                      Error_Pragma_Arg
10184                        ("pragma% requires function returning a " &
10185                         "'C'I'L access type", Def_Id);
10186                   end if;
10187                end if;
10188
10189                --  Check arguments: For tagged type the first formal must be
10190                --  named "this" and its type must be a named access type
10191                --  designating a class-wide tagged type that has convention
10192                --  CIL/Java. The first formal must also have a null default
10193                --  value. For example:
10194
10195                --      type Typ is tagged ...
10196                --      type Ref is access all Typ;
10197                --      pragma Convention (CIL, Typ);
10198
10199                --      function New_Typ (This : Ref) return Ref;
10200                --      function New_Typ (This : Ref; I : Integer) return Ref;
10201                --      pragma Cil_Constructor (New_Typ);
10202
10203                --  Reason: The first formal must NOT be a primitive of the
10204                --  tagged type.
10205
10206                --  This rule also applies to constructors of delegates used
10207                --  to interface with standard target libraries. For example:
10208
10209                --      type Delegate is access procedure ...
10210                --      pragma Import (CIL, Delegate, ...);
10211
10212                --      function new_Delegate
10213                --        (This : Delegate := null; ... ) return Delegate;
10214
10215                --  For value-types this rule does not apply.
10216
10217                if not Is_Value_Type (Etype (Def_Id)) then
10218                   if No (First_Formal (Def_Id)) then
10219                      Error_Msg_Name_1 := Pname;
10220                      Error_Msg_N ("% function must have parameters", Def_Id);
10221                      return;
10222                   end if;
10223
10224                   --  In the JRE library we have several occurrences in which
10225                   --  the "this" parameter is not the first formal.
10226
10227                   This_Formal := First_Formal (Def_Id);
10228
10229                   --  In the JRE library we have several occurrences in which
10230                   --  the "this" parameter is not the first formal. Search for
10231                   --  it.
10232
10233                   if VM_Target = JVM_Target then
10234                      while Present (This_Formal)
10235                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10236                      loop
10237                         Next_Formal (This_Formal);
10238                      end loop;
10239
10240                      if No (This_Formal) then
10241                         This_Formal := First_Formal (Def_Id);
10242                      end if;
10243                   end if;
10244
10245                   --  Warning: The first parameter should be named "this".
10246                   --  We temporarily allow it because we have the following
10247                   --  case in the Java runtime (file s-osinte.ads) ???
10248
10249                   --    function new_Thread
10250                   --      (Self_Id : System.Address) return Thread_Id;
10251                   --    pragma Java_Constructor (new_Thread);
10252
10253                   if VM_Target = JVM_Target
10254                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10255                                = "self_id"
10256                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10257                   then
10258                      null;
10259
10260                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10261                      Error_Msg_Name_1 := Pname;
10262                      Error_Msg_N
10263                        ("first formal of % function must be named `this`",
10264                         Parent (This_Formal));
10265
10266                   elsif not Is_Access_Type (Etype (This_Formal)) then
10267                      Error_Msg_Name_1 := Pname;
10268                      Error_Msg_N
10269                        ("first formal of % function must be an access type",
10270                         Parameter_Type (Parent (This_Formal)));
10271
10272                   --  For delegates the type of the first formal must be a
10273                   --  named access-to-subprogram type (see previous example)
10274
10275                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10276                     and then Ekind (Etype (This_Formal))
10277                                /= E_Access_Subprogram_Type
10278                   then
10279                      Error_Msg_Name_1 := Pname;
10280                      Error_Msg_N
10281                        ("first formal of % function must be a named access" &
10282                         " to subprogram type",
10283                         Parameter_Type (Parent (This_Formal)));
10284
10285                   --  Warning: We should reject anonymous access types because
10286                   --  the constructor must not be handled as a primitive of the
10287                   --  tagged type. We temporarily allow it because this profile
10288                   --  is currently generated by cil2ada???
10289
10290                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10291                     and then not Ekind_In (Etype (This_Formal),
10292                                              E_Access_Type,
10293                                              E_General_Access_Type,
10294                                              E_Anonymous_Access_Type)
10295                   then
10296                      Error_Msg_Name_1 := Pname;
10297                      Error_Msg_N
10298                        ("first formal of % function must be a named access" &
10299                         " type",
10300                         Parameter_Type (Parent (This_Formal)));
10301
10302                   elsif Atree.Convention
10303                          (Designated_Type (Etype (This_Formal))) /= Convention
10304                   then
10305                      Error_Msg_Name_1 := Pname;
10306
10307                      if Convention = Convention_Java then
10308                         Error_Msg_N
10309                           ("pragma% requires convention 'Cil in designated" &
10310                            " type",
10311                            Parameter_Type (Parent (This_Formal)));
10312                      else
10313                         Error_Msg_N
10314                           ("pragma% requires convention 'Java in designated" &
10315                            " type",
10316                            Parameter_Type (Parent (This_Formal)));
10317                      end if;
10318
10319                   elsif No (Expression (Parent (This_Formal)))
10320                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10321                   then
10322                      Error_Msg_Name_1 := Pname;
10323                      Error_Msg_N
10324                        ("pragma% requires first formal with default `null`",
10325                         Parameter_Type (Parent (This_Formal)));
10326                   end if;
10327                end if;
10328
10329                --  Check result type: the constructor must be a function
10330                --  returning:
10331                --   * a value type (only allowed in the CIL compiler)
10332                --   * an access-to-subprogram type with convention Java/CIL
10333                --   * an access-type designating a type that has convention
10334                --     Java/CIL.
10335
10336                if Is_Value_Type (Etype (Def_Id)) then
10337                   null;
10338
10339                --  Access-to-subprogram type with convention Java/CIL
10340
10341                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10342                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10343                      if Convention = Convention_Java then
10344                         Error_Pragma_Arg
10345                           ("pragma% requires function returning a " &
10346                            "'Java access type", Arg1);
10347                      else
10348                         pragma Assert (Convention = Convention_CIL);
10349                         Error_Pragma_Arg
10350                           ("pragma% requires function returning a " &
10351                            "'C'I'L access type", Arg1);
10352                      end if;
10353                   end if;
10354
10355                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10356                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10357                                                    E_General_Access_Type)
10358                     or else
10359                       Atree.Convention
10360                         (Designated_Type (Etype (Def_Id))) /= Convention
10361                   then
10362                      Error_Msg_Name_1 := Pname;
10363
10364                      if Convention = Convention_Java then
10365                         Error_Pragma_Arg
10366                           ("pragma% requires function returning a named" &
10367                            "'Java access type", Arg1);
10368                      else
10369                         Error_Pragma_Arg
10370                           ("pragma% requires function returning a named" &
10371                            "'C'I'L access type", Arg1);
10372                      end if;
10373                   end if;
10374                end if;
10375
10376                Set_Is_Constructor (Def_Id);
10377                Set_Convention     (Def_Id, Convention);
10378                Set_Is_Imported    (Def_Id);
10379
10380                exit when From_Aspect_Specification (N);
10381                Hom_Id := Homonym (Hom_Id);
10382
10383                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10384             end loop;
10385          end Java_Constructor;
10386
10387          ----------------------
10388          -- Java_Interface --
10389          ----------------------
10390
10391          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10392
10393          when Pragma_Java_Interface => Java_Interface : declare
10394             Arg : Node_Id;
10395             Typ : Entity_Id;
10396
10397          begin
10398             GNAT_Pragma;
10399             Check_Arg_Count (1);
10400             Check_Optional_Identifier (Arg1, Name_Entity);
10401             Check_Arg_Is_Local_Name (Arg1);
10402
10403             Arg := Get_Pragma_Arg (Arg1);
10404             Analyze (Arg);
10405
10406             if Etype (Arg) = Any_Type then
10407                return;
10408             end if;
10409
10410             if not Is_Entity_Name (Arg)
10411               or else not Is_Type (Entity (Arg))
10412             then
10413                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10414             end if;
10415
10416             Typ := Underlying_Type (Entity (Arg));
10417
10418             --  For now simply check some of the semantic constraints on the
10419             --  type. This currently leaves out some restrictions on interface
10420             --  types, namely that the parent type must be java.lang.Object.Typ
10421             --  and that all primitives of the type should be declared
10422             --  abstract. ???
10423
10424             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10425                Error_Pragma_Arg ("pragma% requires an abstract "
10426                  & "tagged type", Arg1);
10427
10428             elsif not Has_Discriminants (Typ)
10429               or else Ekind (Etype (First_Discriminant (Typ)))
10430                         /= E_Anonymous_Access_Type
10431               or else
10432                 not Is_Class_Wide_Type
10433                       (Designated_Type (Etype (First_Discriminant (Typ))))
10434             then
10435                Error_Pragma_Arg
10436                  ("type must have a class-wide access discriminant", Arg1);
10437             end if;
10438          end Java_Interface;
10439
10440          ----------------
10441          -- Keep_Names --
10442          ----------------
10443
10444          --  pragma Keep_Names ([On => ] local_NAME);
10445
10446          when Pragma_Keep_Names => Keep_Names : declare
10447             Arg : Node_Id;
10448
10449          begin
10450             GNAT_Pragma;
10451             Check_Arg_Count (1);
10452             Check_Optional_Identifier (Arg1, Name_On);
10453             Check_Arg_Is_Local_Name (Arg1);
10454
10455             Arg := Get_Pragma_Arg (Arg1);
10456             Analyze (Arg);
10457
10458             if Etype (Arg) = Any_Type then
10459                return;
10460             end if;
10461
10462             if not Is_Entity_Name (Arg)
10463               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10464             then
10465                Error_Pragma_Arg
10466                  ("pragma% requires a local enumeration type", Arg1);
10467             end if;
10468
10469             Set_Discard_Names (Entity (Arg), False);
10470          end Keep_Names;
10471
10472          -------------
10473          -- License --
10474          -------------
10475
10476          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10477
10478          when Pragma_License =>
10479             GNAT_Pragma;
10480             Check_Arg_Count (1);
10481             Check_No_Identifiers;
10482             Check_Valid_Configuration_Pragma;
10483             Check_Arg_Is_Identifier (Arg1);
10484
10485             declare
10486                Sind : constant Source_File_Index :=
10487                         Source_Index (Current_Sem_Unit);
10488
10489             begin
10490                case Chars (Get_Pragma_Arg (Arg1)) is
10491                   when Name_GPL =>
10492                      Set_License (Sind, GPL);
10493
10494                   when Name_Modified_GPL =>
10495                      Set_License (Sind, Modified_GPL);
10496
10497                   when Name_Restricted =>
10498                      Set_License (Sind, Restricted);
10499
10500                   when Name_Unrestricted =>
10501                      Set_License (Sind, Unrestricted);
10502
10503                   when others =>
10504                      Error_Pragma_Arg ("invalid license name", Arg1);
10505                end case;
10506             end;
10507
10508          ---------------
10509          -- Link_With --
10510          ---------------
10511
10512          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10513
10514          when Pragma_Link_With => Link_With : declare
10515             Arg : Node_Id;
10516
10517          begin
10518             GNAT_Pragma;
10519
10520             if Operating_Mode = Generate_Code
10521               and then In_Extended_Main_Source_Unit (N)
10522             then
10523                Check_At_Least_N_Arguments (1);
10524                Check_No_Identifiers;
10525                Check_Is_In_Decl_Part_Or_Package_Spec;
10526                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10527                Start_String;
10528
10529                Arg := Arg1;
10530                while Present (Arg) loop
10531                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10532
10533                   --  Store argument, converting sequences of spaces to a
10534                   --  single null character (this is one of the differences
10535                   --  in processing between Link_With and Linker_Options).
10536
10537                   Arg_Store : declare
10538                      C : constant Char_Code := Get_Char_Code (' ');
10539                      S : constant String_Id :=
10540                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10541                      L : constant Nat := String_Length (S);
10542                      F : Nat := 1;
10543
10544                      procedure Skip_Spaces;
10545                      --  Advance F past any spaces
10546
10547                      -----------------
10548                      -- Skip_Spaces --
10549                      -----------------
10550
10551                      procedure Skip_Spaces is
10552                      begin
10553                         while F <= L and then Get_String_Char (S, F) = C loop
10554                            F := F + 1;
10555                         end loop;
10556                      end Skip_Spaces;
10557
10558                   --  Start of processing for Arg_Store
10559
10560                   begin
10561                      Skip_Spaces; -- skip leading spaces
10562
10563                      --  Loop through characters, changing any embedded
10564                      --  sequence of spaces to a single null character (this
10565                      --  is how Link_With/Linker_Options differ)
10566
10567                      while F <= L loop
10568                         if Get_String_Char (S, F) = C then
10569                            Skip_Spaces;
10570                            exit when F > L;
10571                            Store_String_Char (ASCII.NUL);
10572
10573                         else
10574                            Store_String_Char (Get_String_Char (S, F));
10575                            F := F + 1;
10576                         end if;
10577                      end loop;
10578                   end Arg_Store;
10579
10580                   Arg := Next (Arg);
10581
10582                   if Present (Arg) then
10583                      Store_String_Char (ASCII.NUL);
10584                   end if;
10585                end loop;
10586
10587                Store_Linker_Option_String (End_String);
10588             end if;
10589          end Link_With;
10590
10591          ------------------
10592          -- Linker_Alias --
10593          ------------------
10594
10595          --  pragma Linker_Alias (
10596          --      [Entity =>]  LOCAL_NAME
10597          --      [Target =>]  static_string_EXPRESSION);
10598
10599          when Pragma_Linker_Alias =>
10600             GNAT_Pragma;
10601             Check_Arg_Order ((Name_Entity, Name_Target));
10602             Check_Arg_Count (2);
10603             Check_Optional_Identifier (Arg1, Name_Entity);
10604             Check_Optional_Identifier (Arg2, Name_Target);
10605             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10606             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10607
10608             --  The only processing required is to link this item on to the
10609             --  list of rep items for the given entity. This is accomplished
10610             --  by the call to Rep_Item_Too_Late (when no error is detected
10611             --  and False is returned).
10612
10613             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10614                return;
10615             else
10616                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10617             end if;
10618
10619          ------------------------
10620          -- Linker_Constructor --
10621          ------------------------
10622
10623          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10624
10625          --  Code is shared with Linker_Destructor
10626
10627          -----------------------
10628          -- Linker_Destructor --
10629          -----------------------
10630
10631          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10632
10633          when Pragma_Linker_Constructor |
10634               Pragma_Linker_Destructor =>
10635          Linker_Constructor : declare
10636             Arg1_X : Node_Id;
10637             Proc   : Entity_Id;
10638
10639          begin
10640             GNAT_Pragma;
10641             Check_Arg_Count (1);
10642             Check_No_Identifiers;
10643             Check_Arg_Is_Local_Name (Arg1);
10644             Arg1_X := Get_Pragma_Arg (Arg1);
10645             Analyze (Arg1_X);
10646             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10647
10648             if not Is_Library_Level_Entity (Proc) then
10649                Error_Pragma_Arg
10650                 ("argument for pragma% must be library level entity", Arg1);
10651             end if;
10652
10653             --  The only processing required is to link this item on to the
10654             --  list of rep items for the given entity. This is accomplished
10655             --  by the call to Rep_Item_Too_Late (when no error is detected
10656             --  and False is returned).
10657
10658             if Rep_Item_Too_Late (Proc, N) then
10659                return;
10660             else
10661                Set_Has_Gigi_Rep_Item (Proc);
10662             end if;
10663          end Linker_Constructor;
10664
10665          --------------------
10666          -- Linker_Options --
10667          --------------------
10668
10669          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10670
10671          when Pragma_Linker_Options => Linker_Options : declare
10672             Arg : Node_Id;
10673
10674          begin
10675             Check_Ada_83_Warning;
10676             Check_No_Identifiers;
10677             Check_Arg_Count (1);
10678             Check_Is_In_Decl_Part_Or_Package_Spec;
10679             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10680             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10681
10682             Arg := Arg2;
10683             while Present (Arg) loop
10684                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10685                Store_String_Char (ASCII.NUL);
10686                Store_String_Chars
10687                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10688                Arg := Next (Arg);
10689             end loop;
10690
10691             if Operating_Mode = Generate_Code
10692               and then In_Extended_Main_Source_Unit (N)
10693             then
10694                Store_Linker_Option_String (End_String);
10695             end if;
10696          end Linker_Options;
10697
10698          --------------------
10699          -- Linker_Section --
10700          --------------------
10701
10702          --  pragma Linker_Section (
10703          --      [Entity  =>]  LOCAL_NAME
10704          --      [Section =>]  static_string_EXPRESSION);
10705
10706          when Pragma_Linker_Section =>
10707             GNAT_Pragma;
10708             Check_Arg_Order ((Name_Entity, Name_Section));
10709             Check_Arg_Count (2);
10710             Check_Optional_Identifier (Arg1, Name_Entity);
10711             Check_Optional_Identifier (Arg2, Name_Section);
10712             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10713             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10714
10715             --  This pragma applies only to objects
10716
10717             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10718                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10719             end if;
10720
10721             --  The only processing required is to link this item on to the
10722             --  list of rep items for the given entity. This is accomplished
10723             --  by the call to Rep_Item_Too_Late (when no error is detected
10724             --  and False is returned).
10725
10726             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10727                return;
10728             else
10729                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10730             end if;
10731
10732          ----------
10733          -- List --
10734          ----------
10735
10736          --  pragma List (On | Off)
10737
10738          --  There is nothing to do here, since we did all the processing for
10739          --  this pragma in Par.Prag (so that it works properly even in syntax
10740          --  only mode).
10741
10742          when Pragma_List =>
10743             null;
10744
10745          --------------------
10746          -- Locking_Policy --
10747          --------------------
10748
10749          --  pragma Locking_Policy (policy_IDENTIFIER);
10750
10751          when Pragma_Locking_Policy => declare
10752             LP : Character;
10753
10754          begin
10755             Check_Ada_83_Warning;
10756             Check_Arg_Count (1);
10757             Check_No_Identifiers;
10758             Check_Arg_Is_Locking_Policy (Arg1);
10759             Check_Valid_Configuration_Pragma;
10760             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10761             LP := Fold_Upper (Name_Buffer (1));
10762
10763             if Locking_Policy /= ' '
10764               and then Locking_Policy /= LP
10765             then
10766                Error_Msg_Sloc := Locking_Policy_Sloc;
10767                Error_Pragma ("locking policy incompatible with policy#");
10768
10769             --  Set new policy, but always preserve System_Location since we
10770             --  like the error message with the run time name.
10771
10772             else
10773                Locking_Policy := LP;
10774
10775                if Locking_Policy_Sloc /= System_Location then
10776                   Locking_Policy_Sloc := Loc;
10777                end if;
10778             end if;
10779          end;
10780
10781          ----------------
10782          -- Long_Float --
10783          ----------------
10784
10785          --  pragma Long_Float (D_Float | G_Float);
10786
10787          when Pragma_Long_Float =>
10788             GNAT_Pragma;
10789             Check_Valid_Configuration_Pragma;
10790             Check_Arg_Count (1);
10791             Check_No_Identifier (Arg1);
10792             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10793
10794             if not OpenVMS_On_Target then
10795                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10796             end if;
10797
10798             --  D_Float case
10799
10800             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10801                if Opt.Float_Format_Long = 'G' then
10802                   Error_Pragma ("G_Float previously specified");
10803                end if;
10804
10805                Opt.Float_Format_Long := 'D';
10806
10807             --  G_Float case (this is the default, does not need overriding)
10808
10809             else
10810                if Opt.Float_Format_Long = 'D' then
10811                   Error_Pragma ("D_Float previously specified");
10812                end if;
10813
10814                Opt.Float_Format_Long := 'G';
10815             end if;
10816
10817             Set_Standard_Fpt_Formats;
10818
10819          -----------------------
10820          -- Machine_Attribute --
10821          -----------------------
10822
10823          --  pragma Machine_Attribute (
10824          --       [Entity         =>] LOCAL_NAME,
10825          --       [Attribute_Name =>] static_string_EXPRESSION
10826          --    [, [Info           =>] static_EXPRESSION] );
10827
10828          when Pragma_Machine_Attribute => Machine_Attribute : declare
10829             Def_Id : Entity_Id;
10830
10831          begin
10832             GNAT_Pragma;
10833             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10834
10835             if Arg_Count = 3 then
10836                Check_Optional_Identifier (Arg3, Name_Info);
10837                Check_Arg_Is_Static_Expression (Arg3);
10838             else
10839                Check_Arg_Count (2);
10840             end if;
10841
10842             Check_Optional_Identifier (Arg1, Name_Entity);
10843             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10844             Check_Arg_Is_Local_Name (Arg1);
10845             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10846             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10847
10848             if Is_Access_Type (Def_Id) then
10849                Def_Id := Designated_Type (Def_Id);
10850             end if;
10851
10852             if Rep_Item_Too_Early (Def_Id, N) then
10853                return;
10854             end if;
10855
10856             Def_Id := Underlying_Type (Def_Id);
10857
10858             --  The only processing required is to link this item on to the
10859             --  list of rep items for the given entity. This is accomplished
10860             --  by the call to Rep_Item_Too_Late (when no error is detected
10861             --  and False is returned).
10862
10863             if Rep_Item_Too_Late (Def_Id, N) then
10864                return;
10865             else
10866                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10867             end if;
10868          end Machine_Attribute;
10869
10870          ----------
10871          -- Main --
10872          ----------
10873
10874          --  pragma Main
10875          --   (MAIN_OPTION [, MAIN_OPTION]);
10876
10877          --  MAIN_OPTION ::=
10878          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10879          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10880          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10881
10882          when Pragma_Main => Main : declare
10883             Args  : Args_List (1 .. 3);
10884             Names : constant Name_List (1 .. 3) := (
10885                       Name_Stack_Size,
10886                       Name_Task_Stack_Size_Default,
10887                       Name_Time_Slicing_Enabled);
10888
10889             Nod : Node_Id;
10890
10891          begin
10892             GNAT_Pragma;
10893             Gather_Associations (Names, Args);
10894
10895             for J in 1 .. 2 loop
10896                if Present (Args (J)) then
10897                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10898                end if;
10899             end loop;
10900
10901             if Present (Args (3)) then
10902                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10903             end if;
10904
10905             Nod := Next (N);
10906             while Present (Nod) loop
10907                if Nkind (Nod) = N_Pragma
10908                  and then Pragma_Name (Nod) = Name_Main
10909                then
10910                   Error_Msg_Name_1 := Pname;
10911                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10912                end if;
10913
10914                Next (Nod);
10915             end loop;
10916          end Main;
10917
10918          ------------------
10919          -- Main_Storage --
10920          ------------------
10921
10922          --  pragma Main_Storage
10923          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10924
10925          --  MAIN_STORAGE_OPTION ::=
10926          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10927          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10928
10929          when Pragma_Main_Storage => Main_Storage : declare
10930             Args  : Args_List (1 .. 2);
10931             Names : constant Name_List (1 .. 2) := (
10932                       Name_Working_Storage,
10933                       Name_Top_Guard);
10934
10935             Nod : Node_Id;
10936
10937          begin
10938             GNAT_Pragma;
10939             Gather_Associations (Names, Args);
10940
10941             for J in 1 .. 2 loop
10942                if Present (Args (J)) then
10943                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10944                end if;
10945             end loop;
10946
10947             Check_In_Main_Program;
10948
10949             Nod := Next (N);
10950             while Present (Nod) loop
10951                if Nkind (Nod) = N_Pragma
10952                  and then Pragma_Name (Nod) = Name_Main_Storage
10953                then
10954                   Error_Msg_Name_1 := Pname;
10955                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10956                end if;
10957
10958                Next (Nod);
10959             end loop;
10960          end Main_Storage;
10961
10962          -----------------
10963          -- Memory_Size --
10964          -----------------
10965
10966          --  pragma Memory_Size (NUMERIC_LITERAL)
10967
10968          when Pragma_Memory_Size =>
10969             GNAT_Pragma;
10970
10971             --  Memory size is simply ignored
10972
10973             Check_No_Identifiers;
10974             Check_Arg_Count (1);
10975             Check_Arg_Is_Integer_Literal (Arg1);
10976
10977          -------------
10978          -- No_Body --
10979          -------------
10980
10981          --  pragma No_Body;
10982
10983          --  The only correct use of this pragma is on its own in a file, in
10984          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10985          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10986          --  check for a file containing nothing but a No_Body pragma). If we
10987          --  attempt to process it during normal semantics processing, it means
10988          --  it was misplaced.
10989
10990          when Pragma_No_Body =>
10991             GNAT_Pragma;
10992             Pragma_Misplaced;
10993
10994          ---------------
10995          -- No_Return --
10996          ---------------
10997
10998          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10999
11000          when Pragma_No_Return => No_Return : declare
11001             Id    : Node_Id;
11002             E     : Entity_Id;
11003             Found : Boolean;
11004             Arg   : Node_Id;
11005
11006          begin
11007             Ada_2005_Pragma;
11008             Check_At_Least_N_Arguments (1);
11009
11010             --  Loop through arguments of pragma
11011
11012             Arg := Arg1;
11013             while Present (Arg) loop
11014                Check_Arg_Is_Local_Name (Arg);
11015                Id := Get_Pragma_Arg (Arg);
11016                Analyze (Id);
11017
11018                if not Is_Entity_Name (Id) then
11019                   Error_Pragma_Arg ("entity name required", Arg);
11020                end if;
11021
11022                if Etype (Id) = Any_Type then
11023                   raise Pragma_Exit;
11024                end if;
11025
11026                --  Loop to find matching procedures
11027
11028                E := Entity (Id);
11029                Found := False;
11030                while Present (E)
11031                  and then Scope (E) = Current_Scope
11032                loop
11033                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11034                      Set_No_Return (E);
11035
11036                      --  Set flag on any alias as well
11037
11038                      if Is_Overloadable (E) and then Present (Alias (E)) then
11039                         Set_No_Return (Alias (E));
11040                      end if;
11041
11042                      Found := True;
11043                   end if;
11044
11045                   exit when From_Aspect_Specification (N);
11046                   E := Homonym (E);
11047                end loop;
11048
11049                if not Found then
11050                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11051                end if;
11052
11053                Next (Arg);
11054             end loop;
11055          end No_Return;
11056
11057          -----------------
11058          -- No_Run_Time --
11059          -----------------
11060
11061          --  pragma No_Run_Time;
11062
11063          --  Note: this pragma is retained for backwards compatibility. See
11064          --  body of Rtsfind for full details on its handling.
11065
11066          when Pragma_No_Run_Time =>
11067             GNAT_Pragma;
11068             Check_Valid_Configuration_Pragma;
11069             Check_Arg_Count (0);
11070
11071             No_Run_Time_Mode           := True;
11072             Configurable_Run_Time_Mode := True;
11073
11074             --  Set Duration to 32 bits if word size is 32
11075
11076             if Ttypes.System_Word_Size = 32 then
11077                Duration_32_Bits_On_Target := True;
11078             end if;
11079
11080             --  Set appropriate restrictions
11081
11082             Set_Restriction (No_Finalization, N);
11083             Set_Restriction (No_Exception_Handlers, N);
11084             Set_Restriction (Max_Tasks, N, 0);
11085             Set_Restriction (No_Tasking, N);
11086
11087          ------------------------
11088          -- No_Strict_Aliasing --
11089          ------------------------
11090
11091          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11092
11093          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11094             E_Id : Entity_Id;
11095
11096          begin
11097             GNAT_Pragma;
11098             Check_At_Most_N_Arguments (1);
11099
11100             if Arg_Count = 0 then
11101                Check_Valid_Configuration_Pragma;
11102                Opt.No_Strict_Aliasing := True;
11103
11104             else
11105                Check_Optional_Identifier (Arg2, Name_Entity);
11106                Check_Arg_Is_Local_Name (Arg1);
11107                E_Id := Entity (Get_Pragma_Arg (Arg1));
11108
11109                if E_Id = Any_Type then
11110                   return;
11111                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11112                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
11113                end if;
11114
11115                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11116             end if;
11117          end No_Strict_Aliasing;
11118
11119          -----------------------
11120          -- Normalize_Scalars --
11121          -----------------------
11122
11123          --  pragma Normalize_Scalars;
11124
11125          when Pragma_Normalize_Scalars =>
11126             Check_Ada_83_Warning;
11127             Check_Arg_Count (0);
11128             Check_Valid_Configuration_Pragma;
11129
11130             --  Normalize_Scalars creates false positives in CodePeer, and
11131             --  incorrect negative results in Alfa mode, so ignore this pragma
11132             --  in these modes.
11133
11134             if not (CodePeer_Mode or Alfa_Mode) then
11135                Normalize_Scalars := True;
11136                Init_Or_Norm_Scalars := True;
11137             end if;
11138
11139          -----------------
11140          -- Obsolescent --
11141          -----------------
11142
11143          --  pragma Obsolescent;
11144
11145          --  pragma Obsolescent (
11146          --    [Message =>] static_string_EXPRESSION
11147          --  [,[Version =>] Ada_05]]);
11148
11149          --  pragma Obsolescent (
11150          --    [Entity  =>] NAME
11151          --  [,[Message =>] static_string_EXPRESSION
11152          --  [,[Version =>] Ada_05]] );
11153
11154          when Pragma_Obsolescent => Obsolescent : declare
11155             Ename : Node_Id;
11156             Decl  : Node_Id;
11157
11158             procedure Set_Obsolescent (E : Entity_Id);
11159             --  Given an entity Ent, mark it as obsolescent if appropriate
11160
11161             ---------------------
11162             -- Set_Obsolescent --
11163             ---------------------
11164
11165             procedure Set_Obsolescent (E : Entity_Id) is
11166                Active : Boolean;
11167                Ent    : Entity_Id;
11168                S      : String_Id;
11169
11170             begin
11171                Active := True;
11172                Ent    := E;
11173
11174                --  Entity name was given
11175
11176                if Present (Ename) then
11177
11178                   --  If entity name matches, we are fine. Save entity in
11179                   --  pragma argument, for ASIS use.
11180
11181                   if Chars (Ename) = Chars (Ent) then
11182                      Set_Entity (Ename, Ent);
11183                      Generate_Reference (Ent, Ename);
11184
11185                   --  If entity name does not match, only possibility is an
11186                   --  enumeration literal from an enumeration type declaration.
11187
11188                   elsif Ekind (Ent) /= E_Enumeration_Type then
11189                      Error_Pragma
11190                        ("pragma % entity name does not match declaration");
11191
11192                   else
11193                      Ent := First_Literal (E);
11194                      loop
11195                         if No (Ent) then
11196                            Error_Pragma
11197                              ("pragma % entity name does not match any " &
11198                               "enumeration literal");
11199
11200                         elsif Chars (Ent) = Chars (Ename) then
11201                            Set_Entity (Ename, Ent);
11202                            Generate_Reference (Ent, Ename);
11203                            exit;
11204
11205                         else
11206                            Ent := Next_Literal (Ent);
11207                         end if;
11208                      end loop;
11209                   end if;
11210                end if;
11211
11212                --  Ent points to entity to be marked
11213
11214                if Arg_Count >= 1 then
11215
11216                   --  Deal with static string argument
11217
11218                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11219                   S := Strval (Get_Pragma_Arg (Arg1));
11220
11221                   for J in 1 .. String_Length (S) loop
11222                      if not In_Character_Range (Get_String_Char (S, J)) then
11223                         Error_Pragma_Arg
11224                           ("pragma% argument does not allow wide characters",
11225                            Arg1);
11226                      end if;
11227                   end loop;
11228
11229                   Obsolescent_Warnings.Append
11230                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11231
11232                   --  Check for Ada_05 parameter
11233
11234                   if Arg_Count /= 1 then
11235                      Check_Arg_Count (2);
11236
11237                      declare
11238                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11239
11240                      begin
11241                         Check_Arg_Is_Identifier (Argx);
11242
11243                         if Chars (Argx) /= Name_Ada_05 then
11244                            Error_Msg_Name_2 := Name_Ada_05;
11245                            Error_Pragma_Arg
11246                              ("only allowed argument for pragma% is %", Argx);
11247                         end if;
11248
11249                         if Ada_Version_Explicit < Ada_2005
11250                           or else not Warn_On_Ada_2005_Compatibility
11251                         then
11252                            Active := False;
11253                         end if;
11254                      end;
11255                   end if;
11256                end if;
11257
11258                --  Set flag if pragma active
11259
11260                if Active then
11261                   Set_Is_Obsolescent (Ent);
11262                end if;
11263
11264                return;
11265             end Set_Obsolescent;
11266
11267          --  Start of processing for pragma Obsolescent
11268
11269          begin
11270             GNAT_Pragma;
11271
11272             Check_At_Most_N_Arguments (3);
11273
11274             --  See if first argument specifies an entity name
11275
11276             if Arg_Count >= 1
11277               and then
11278                 (Chars (Arg1) = Name_Entity
11279                    or else
11280                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11281                                                       N_Identifier,
11282                                                       N_Operator_Symbol))
11283             then
11284                Ename := Get_Pragma_Arg (Arg1);
11285
11286                --  Eliminate first argument, so we can share processing
11287
11288                Arg1 := Arg2;
11289                Arg2 := Arg3;
11290                Arg_Count := Arg_Count - 1;
11291
11292             --  No Entity name argument given
11293
11294             else
11295                Ename := Empty;
11296             end if;
11297
11298             if Arg_Count >= 1 then
11299                Check_Optional_Identifier (Arg1, Name_Message);
11300
11301                if Arg_Count = 2 then
11302                   Check_Optional_Identifier (Arg2, Name_Version);
11303                end if;
11304             end if;
11305
11306             --  Get immediately preceding declaration
11307
11308             Decl := Prev (N);
11309             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11310                Prev (Decl);
11311             end loop;
11312
11313             --  Cases where we do not follow anything other than another pragma
11314
11315             if No (Decl) then
11316
11317                --  First case: library level compilation unit declaration with
11318                --  the pragma immediately following the declaration.
11319
11320                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11321                   Set_Obsolescent
11322                     (Defining_Entity (Unit (Parent (Parent (N)))));
11323                   return;
11324
11325                --  Case 2: library unit placement for package
11326
11327                else
11328                   declare
11329                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11330                   begin
11331                      if Is_Package_Or_Generic_Package (Ent) then
11332                         Set_Obsolescent (Ent);
11333                         return;
11334                      end if;
11335                   end;
11336                end if;
11337
11338             --  Cases where we must follow a declaration
11339
11340             else
11341                if         Nkind (Decl) not in N_Declaration
11342                  and then Nkind (Decl) not in N_Later_Decl_Item
11343                  and then Nkind (Decl) not in N_Generic_Declaration
11344                  and then Nkind (Decl) not in N_Renaming_Declaration
11345                then
11346                   Error_Pragma
11347                     ("pragma% misplaced, "
11348                      & "must immediately follow a declaration");
11349
11350                else
11351                   Set_Obsolescent (Defining_Entity (Decl));
11352                   return;
11353                end if;
11354             end if;
11355          end Obsolescent;
11356
11357          --------------
11358          -- Optimize --
11359          --------------
11360
11361          --  pragma Optimize (Time | Space | Off);
11362
11363          --  The actual check for optimize is done in Gigi. Note that this
11364          --  pragma does not actually change the optimization setting, it
11365          --  simply checks that it is consistent with the pragma.
11366
11367          when Pragma_Optimize =>
11368             Check_No_Identifiers;
11369             Check_Arg_Count (1);
11370             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11371
11372          ------------------------
11373          -- Optimize_Alignment --
11374          ------------------------
11375
11376          --  pragma Optimize_Alignment (Time | Space | Off);
11377
11378          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11379             GNAT_Pragma;
11380             Check_No_Identifiers;
11381             Check_Arg_Count (1);
11382             Check_Valid_Configuration_Pragma;
11383
11384             declare
11385                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11386             begin
11387                case Nam is
11388                   when Name_Time =>
11389                      Opt.Optimize_Alignment := 'T';
11390                   when Name_Space =>
11391                      Opt.Optimize_Alignment := 'S';
11392                   when Name_Off =>
11393                      Opt.Optimize_Alignment := 'O';
11394                   when others =>
11395                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11396                end case;
11397             end;
11398
11399             --  Set indication that mode is set locally. If we are in fact in a
11400             --  configuration pragma file, this setting is harmless since the
11401             --  switch will get reset anyway at the start of each unit.
11402
11403             Optimize_Alignment_Local := True;
11404          end Optimize_Alignment;
11405
11406          -------------
11407          -- Ordered --
11408          -------------
11409
11410          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11411
11412          when Pragma_Ordered => Ordered : declare
11413             Assoc   : constant Node_Id := Arg1;
11414             Type_Id : Node_Id;
11415             Typ     : Entity_Id;
11416
11417          begin
11418             GNAT_Pragma;
11419             Check_No_Identifiers;
11420             Check_Arg_Count (1);
11421             Check_Arg_Is_Local_Name (Arg1);
11422
11423             Type_Id := Get_Pragma_Arg (Assoc);
11424             Find_Type (Type_Id);
11425             Typ := Entity (Type_Id);
11426
11427             if Typ = Any_Type then
11428                return;
11429             else
11430                Typ := Underlying_Type (Typ);
11431             end if;
11432
11433             if not Is_Enumeration_Type (Typ) then
11434                Error_Pragma ("pragma% must specify enumeration type");
11435             end if;
11436
11437             Check_First_Subtype (Arg1);
11438             Set_Has_Pragma_Ordered (Base_Type (Typ));
11439          end Ordered;
11440
11441          ----------
11442          -- Pack --
11443          ----------
11444
11445          --  pragma Pack (first_subtype_LOCAL_NAME);
11446
11447          when Pragma_Pack => Pack : declare
11448             Assoc   : constant Node_Id := Arg1;
11449             Type_Id : Node_Id;
11450             Typ     : Entity_Id;
11451             Ctyp    : Entity_Id;
11452             Ignore  : Boolean := False;
11453
11454          begin
11455             Check_No_Identifiers;
11456             Check_Arg_Count (1);
11457             Check_Arg_Is_Local_Name (Arg1);
11458
11459             Type_Id := Get_Pragma_Arg (Assoc);
11460             Find_Type (Type_Id);
11461             Typ := Entity (Type_Id);
11462
11463             if Typ = Any_Type
11464               or else Rep_Item_Too_Early (Typ, N)
11465             then
11466                return;
11467             else
11468                Typ := Underlying_Type (Typ);
11469             end if;
11470
11471             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11472                Error_Pragma ("pragma% must specify array or record type");
11473             end if;
11474
11475             Check_First_Subtype (Arg1);
11476             Check_Duplicate_Pragma (Typ);
11477
11478             --  Array type
11479
11480             if Is_Array_Type (Typ) then
11481                Ctyp := Component_Type (Typ);
11482
11483                --  Ignore pack that does nothing
11484
11485                if Known_Static_Esize (Ctyp)
11486                  and then Known_Static_RM_Size (Ctyp)
11487                  and then Esize (Ctyp) = RM_Size (Ctyp)
11488                  and then Addressable (Esize (Ctyp))
11489                then
11490                   Ignore := True;
11491                end if;
11492
11493                --  Process OK pragma Pack. Note that if there is a separate
11494                --  component clause present, the Pack will be cancelled. This
11495                --  processing is in Freeze.
11496
11497                if not Rep_Item_Too_Late (Typ, N) then
11498
11499                   --  In the context of static code analysis, we do not need
11500                   --  complex front-end expansions related to pragma Pack,
11501                   --  so disable handling of pragma Pack in these cases.
11502
11503                   if CodePeer_Mode or Alfa_Mode then
11504                      null;
11505
11506                   --  Don't attempt any packing for VM targets. We possibly
11507                   --  could deal with some cases of array bit-packing, but we
11508                   --  don't bother, since this is not a typical kind of
11509                   --  representation in the VM context anyway (and would not
11510                   --  for example work nicely with the debugger).
11511
11512                   elsif VM_Target /= No_VM then
11513                      if not GNAT_Mode then
11514                         Error_Pragma
11515                           ("?pragma% ignored in this configuration");
11516                      end if;
11517
11518                   --  Normal case where we do the pack action
11519
11520                   else
11521                      if not Ignore then
11522                         Set_Is_Packed            (Base_Type (Typ));
11523                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11524                      end if;
11525
11526                      Set_Has_Pragma_Pack (Base_Type (Typ));
11527                   end if;
11528                end if;
11529
11530             --  For record types, the pack is always effective
11531
11532             else pragma Assert (Is_Record_Type (Typ));
11533                if not Rep_Item_Too_Late (Typ, N) then
11534
11535                   --  Ignore pack request with warning in VM mode (skip warning
11536                   --  if we are compiling GNAT run time library).
11537
11538                   if VM_Target /= No_VM then
11539                      if not GNAT_Mode then
11540                         Error_Pragma
11541                           ("?pragma% ignored in this configuration");
11542                      end if;
11543
11544                   --  Normal case of pack request active
11545
11546                   else
11547                      Set_Is_Packed            (Base_Type (Typ));
11548                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11549                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11550                   end if;
11551                end if;
11552             end if;
11553          end Pack;
11554
11555          ----------
11556          -- Page --
11557          ----------
11558
11559          --  pragma Page;
11560
11561          --  There is nothing to do here, since we did all the processing for
11562          --  this pragma in Par.Prag (so that it works properly even in syntax
11563          --  only mode).
11564
11565          when Pragma_Page =>
11566             null;
11567
11568          -------------
11569          -- Passive --
11570          -------------
11571
11572          --  pragma Passive [(PASSIVE_FORM)];
11573
11574          --  PASSIVE_FORM ::= Semaphore | No
11575
11576          when Pragma_Passive =>
11577             GNAT_Pragma;
11578
11579             if Nkind (Parent (N)) /= N_Task_Definition then
11580                Error_Pragma ("pragma% must be within task definition");
11581             end if;
11582
11583             if Arg_Count /= 0 then
11584                Check_Arg_Count (1);
11585                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11586             end if;
11587
11588          ----------------------------------
11589          -- Preelaborable_Initialization --
11590          ----------------------------------
11591
11592          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11593
11594          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11595             Ent : Entity_Id;
11596
11597          begin
11598             Ada_2005_Pragma;
11599             Check_Arg_Count (1);
11600             Check_No_Identifiers;
11601             Check_Arg_Is_Identifier (Arg1);
11602             Check_Arg_Is_Local_Name (Arg1);
11603             Check_First_Subtype (Arg1);
11604             Ent := Entity (Get_Pragma_Arg (Arg1));
11605
11606             if not (Is_Private_Type (Ent)
11607                       or else
11608                     Is_Protected_Type (Ent)
11609                       or else
11610                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11611             then
11612                Error_Pragma_Arg
11613                  ("pragma % can only be applied to private, formal derived or "
11614                   & "protected type",
11615                   Arg1);
11616             end if;
11617
11618             --  Give an error if the pragma is applied to a protected type that
11619             --  does not qualify (due to having entries, or due to components
11620             --  that do not qualify).
11621
11622             if Is_Protected_Type (Ent)
11623               and then not Has_Preelaborable_Initialization (Ent)
11624             then
11625                Error_Msg_N
11626                  ("protected type & does not have preelaborable " &
11627                   "initialization", Ent);
11628
11629             --  Otherwise mark the type as definitely having preelaborable
11630             --  initialization.
11631
11632             else
11633                Set_Known_To_Have_Preelab_Init (Ent);
11634             end if;
11635
11636             if Has_Pragma_Preelab_Init (Ent)
11637               and then Warn_On_Redundant_Constructs
11638             then
11639                Error_Pragma ("?duplicate pragma%!");
11640             else
11641                Set_Has_Pragma_Preelab_Init (Ent);
11642             end if;
11643          end Preelab_Init;
11644
11645          --------------------
11646          -- Persistent_BSS --
11647          --------------------
11648
11649          --  pragma Persistent_BSS [(object_NAME)];
11650
11651          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11652             Decl : Node_Id;
11653             Ent  : Entity_Id;
11654             Prag : Node_Id;
11655
11656          begin
11657             GNAT_Pragma;
11658             Check_At_Most_N_Arguments (1);
11659
11660             --  Case of application to specific object (one argument)
11661
11662             if Arg_Count = 1 then
11663                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11664
11665                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11666                  or else not
11667                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11668                                                             E_Constant)
11669                then
11670                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11671                end if;
11672
11673                Ent := Entity (Get_Pragma_Arg (Arg1));
11674                Decl := Parent (Ent);
11675
11676                if Rep_Item_Too_Late (Ent, N) then
11677                   return;
11678                end if;
11679
11680                if Present (Expression (Decl)) then
11681                   Error_Pragma_Arg
11682                     ("object for pragma% cannot have initialization", Arg1);
11683                end if;
11684
11685                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11686                   Error_Pragma_Arg
11687                     ("object type for pragma% is not potentially persistent",
11688                      Arg1);
11689                end if;
11690
11691                Check_Duplicate_Pragma (Ent);
11692
11693                Prag :=
11694                  Make_Linker_Section_Pragma
11695                    (Ent, Sloc (N), ".persistent.bss");
11696                Insert_After (N, Prag);
11697                Analyze (Prag);
11698
11699             --  Case of use as configuration pragma with no arguments
11700
11701             else
11702                Check_Valid_Configuration_Pragma;
11703                Persistent_BSS_Mode := True;
11704             end if;
11705          end Persistent_BSS;
11706
11707          -------------
11708          -- Polling --
11709          -------------
11710
11711          --  pragma Polling (ON | OFF);
11712
11713          when Pragma_Polling =>
11714             GNAT_Pragma;
11715             Check_Arg_Count (1);
11716             Check_No_Identifiers;
11717             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11718             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11719
11720          -------------------
11721          -- Postcondition --
11722          -------------------
11723
11724          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11725          --                      [,[Message =>] String_EXPRESSION]);
11726
11727          when Pragma_Postcondition => Postcondition : declare
11728             In_Body : Boolean;
11729             pragma Warnings (Off, In_Body);
11730
11731          begin
11732             GNAT_Pragma;
11733             Check_At_Least_N_Arguments (1);
11734             Check_At_Most_N_Arguments (2);
11735             Check_Optional_Identifier (Arg1, Name_Check);
11736
11737             --  All we need to do here is call the common check procedure,
11738             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11739
11740             Check_Precondition_Postcondition (In_Body);
11741          end Postcondition;
11742
11743          ------------------
11744          -- Precondition --
11745          ------------------
11746
11747          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11748          --                     [,[Message =>] String_EXPRESSION]);
11749
11750          when Pragma_Precondition => Precondition : declare
11751             In_Body : Boolean;
11752
11753          begin
11754             GNAT_Pragma;
11755             Check_At_Least_N_Arguments (1);
11756             Check_At_Most_N_Arguments (2);
11757             Check_Optional_Identifier (Arg1, Name_Check);
11758             Check_Precondition_Postcondition (In_Body);
11759
11760             --  If in spec, nothing more to do. If in body, then we convert the
11761             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11762             --  this whether or not precondition checks are enabled. That works
11763             --  fine since pragma Check will do this check, and will also
11764             --  analyze the condition itself in the proper context.
11765
11766             if In_Body then
11767                Rewrite (N,
11768                  Make_Pragma (Loc,
11769                    Chars => Name_Check,
11770                    Pragma_Argument_Associations => New_List (
11771                      Make_Pragma_Argument_Association (Loc,
11772                        Expression => Make_Identifier (Loc, Name_Precondition)),
11773
11774                      Make_Pragma_Argument_Association (Sloc (Arg1),
11775                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11776
11777                if Arg_Count = 2 then
11778                   Append_To (Pragma_Argument_Associations (N),
11779                     Make_Pragma_Argument_Association (Sloc (Arg2),
11780                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11781                end if;
11782
11783                Analyze (N);
11784             end if;
11785          end Precondition;
11786
11787          ---------------
11788          -- Predicate --
11789          ---------------
11790
11791          --  pragma Predicate
11792          --    ([Entity =>] type_LOCAL_NAME,
11793          --     [Check  =>] EXPRESSION);
11794
11795          when Pragma_Predicate => Predicate : declare
11796             Type_Id : Node_Id;
11797             Typ     : Entity_Id;
11798
11799             Discard : Boolean;
11800             pragma Unreferenced (Discard);
11801
11802          begin
11803             GNAT_Pragma;
11804             Check_Arg_Count (2);
11805             Check_Optional_Identifier (Arg1, Name_Entity);
11806             Check_Optional_Identifier (Arg2, Name_Check);
11807
11808             Check_Arg_Is_Local_Name (Arg1);
11809
11810             Type_Id := Get_Pragma_Arg (Arg1);
11811             Find_Type (Type_Id);
11812             Typ := Entity (Type_Id);
11813
11814             if Typ = Any_Type then
11815                return;
11816             end if;
11817
11818             --  The remaining processing is simply to link the pragma on to
11819             --  the rep item chain, for processing when the type is frozen.
11820             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11821             --  mark the type as having predicates.
11822
11823             Set_Has_Predicates (Typ);
11824             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11825          end Predicate;
11826
11827          ------------------
11828          -- Preelaborate --
11829          ------------------
11830
11831          --  pragma Preelaborate [(library_unit_NAME)];
11832
11833          --  Set the flag Is_Preelaborated of program unit name entity
11834
11835          when Pragma_Preelaborate => Preelaborate : declare
11836             Pa  : constant Node_Id   := Parent (N);
11837             Pk  : constant Node_Kind := Nkind (Pa);
11838             Ent : Entity_Id;
11839
11840          begin
11841             Check_Ada_83_Warning;
11842             Check_Valid_Library_Unit_Pragma;
11843
11844             if Nkind (N) = N_Null_Statement then
11845                return;
11846             end if;
11847
11848             Ent := Find_Lib_Unit_Name;
11849             Check_Duplicate_Pragma (Ent);
11850
11851             --  This filters out pragmas inside generic parent then
11852             --  show up inside instantiation
11853
11854             if Present (Ent)
11855               and then not (Pk = N_Package_Specification
11856                              and then Present (Generic_Parent (Pa)))
11857             then
11858                if not Debug_Flag_U then
11859                   Set_Is_Preelaborated (Ent);
11860                   Set_Suppress_Elaboration_Warnings (Ent);
11861                end if;
11862             end if;
11863          end Preelaborate;
11864
11865          ---------------------
11866          -- Preelaborate_05 --
11867          ---------------------
11868
11869          --  pragma Preelaborate_05 [(library_unit_NAME)];
11870
11871          --  This pragma is useable only in GNAT_Mode, where it is used like
11872          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11873          --  (otherwise it is ignored). This is used to implement AI-362 which
11874          --  recategorizes some run-time packages in Ada 2005 mode.
11875
11876          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11877             Ent : Entity_Id;
11878
11879          begin
11880             GNAT_Pragma;
11881             Check_Valid_Library_Unit_Pragma;
11882
11883             if not GNAT_Mode then
11884                Error_Pragma ("pragma% only available in GNAT mode");
11885             end if;
11886
11887             if Nkind (N) = N_Null_Statement then
11888                return;
11889             end if;
11890
11891             --  This is one of the few cases where we need to test the value of
11892             --  Ada_Version_Explicit rather than Ada_Version (which is always
11893             --  set to Ada_2012 in a predefined unit), we need to know the
11894             --  explicit version set to know if this pragma is active.
11895
11896             if Ada_Version_Explicit >= Ada_2005 then
11897                Ent := Find_Lib_Unit_Name;
11898                Set_Is_Preelaborated (Ent);
11899                Set_Suppress_Elaboration_Warnings (Ent);
11900             end if;
11901          end Preelaborate_05;
11902
11903          --------------
11904          -- Priority --
11905          --------------
11906
11907          --  pragma Priority (EXPRESSION);
11908
11909          when Pragma_Priority => Priority : declare
11910             P   : constant Node_Id := Parent (N);
11911             Arg : Node_Id;
11912
11913          begin
11914             Check_No_Identifiers;
11915             Check_Arg_Count (1);
11916
11917             --  Subprogram case
11918
11919             if Nkind (P) = N_Subprogram_Body then
11920                Check_In_Main_Program;
11921
11922                Arg := Get_Pragma_Arg (Arg1);
11923                Analyze_And_Resolve (Arg, Standard_Integer);
11924
11925                --  Must be static
11926
11927                if not Is_Static_Expression (Arg) then
11928                   Flag_Non_Static_Expr
11929                     ("main subprogram priority is not static!", Arg);
11930                   raise Pragma_Exit;
11931
11932                --  If constraint error, then we already signalled an error
11933
11934                elsif Raises_Constraint_Error (Arg) then
11935                   null;
11936
11937                --  Otherwise check in range
11938
11939                else
11940                   declare
11941                      Val : constant Uint := Expr_Value (Arg);
11942
11943                   begin
11944                      if Val < 0
11945                        or else Val > Expr_Value (Expression
11946                                        (Parent (RTE (RE_Max_Priority))))
11947                      then
11948                         Error_Pragma_Arg
11949                           ("main subprogram priority is out of range", Arg1);
11950                      end if;
11951                   end;
11952                end if;
11953
11954                Set_Main_Priority
11955                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11956
11957                --  Load an arbitrary entity from System.Tasking to make sure
11958                --  this package is implicitly with'ed, since we need to have
11959                --  the tasking run-time active for the pragma Priority to have
11960                --  any effect.
11961
11962                declare
11963                   Discard : Entity_Id;
11964                   pragma Warnings (Off, Discard);
11965                begin
11966                   Discard := RTE (RE_Task_List);
11967                end;
11968
11969             --  Task or Protected, must be of type Integer
11970
11971             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11972                Arg := Get_Pragma_Arg (Arg1);
11973
11974                --  The expression must be analyzed in the special manner
11975                --  described in "Handling of Default and Per-Object
11976                --  Expressions" in sem.ads.
11977
11978                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11979
11980                if not Is_Static_Expression (Arg) then
11981                   Check_Restriction (Static_Priorities, Arg);
11982                end if;
11983
11984             --  Anything else is incorrect
11985
11986             else
11987                Pragma_Misplaced;
11988             end if;
11989
11990             if Has_Pragma_Priority (P) then
11991                Error_Pragma ("duplicate pragma% not allowed");
11992             else
11993                Set_Has_Pragma_Priority (P, True);
11994
11995                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11996                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11997                   --  exp_ch9 should use this ???
11998                end if;
11999             end if;
12000          end Priority;
12001
12002          -----------------------------------
12003          -- Priority_Specific_Dispatching --
12004          -----------------------------------
12005
12006          --  pragma Priority_Specific_Dispatching (
12007          --    policy_IDENTIFIER,
12008          --    first_priority_EXPRESSION,
12009          --    last_priority_EXPRESSION);
12010
12011          when Pragma_Priority_Specific_Dispatching =>
12012          Priority_Specific_Dispatching : declare
12013             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12014             --  This is the entity System.Any_Priority;
12015
12016             DP          : Character;
12017             Lower_Bound : Node_Id;
12018             Upper_Bound : Node_Id;
12019             Lower_Val   : Uint;
12020             Upper_Val   : Uint;
12021
12022          begin
12023             Ada_2005_Pragma;
12024             Check_Arg_Count (3);
12025             Check_No_Identifiers;
12026             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12027             Check_Valid_Configuration_Pragma;
12028             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12029             DP := Fold_Upper (Name_Buffer (1));
12030
12031             Lower_Bound := Get_Pragma_Arg (Arg2);
12032             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12033             Lower_Val := Expr_Value (Lower_Bound);
12034
12035             Upper_Bound := Get_Pragma_Arg (Arg3);
12036             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12037             Upper_Val := Expr_Value (Upper_Bound);
12038
12039             --  It is not allowed to use Task_Dispatching_Policy and
12040             --  Priority_Specific_Dispatching in the same partition.
12041
12042             if Task_Dispatching_Policy /= ' ' then
12043                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12044                Error_Pragma
12045                  ("pragma% incompatible with Task_Dispatching_Policy#");
12046
12047             --  Check lower bound in range
12048
12049             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12050                     or else
12051                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12052             then
12053                Error_Pragma_Arg
12054                  ("first_priority is out of range", Arg2);
12055
12056             --  Check upper bound in range
12057
12058             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12059                     or else
12060                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12061             then
12062                Error_Pragma_Arg
12063                  ("last_priority is out of range", Arg3);
12064
12065             --  Check that the priority range is valid
12066
12067             elsif Lower_Val > Upper_Val then
12068                Error_Pragma
12069                  ("last_priority_expression must be greater than" &
12070                   " or equal to first_priority_expression");
12071
12072             --  Store the new policy, but always preserve System_Location since
12073             --  we like the error message with the run-time name.
12074
12075             else
12076                --  Check overlapping in the priority ranges specified in other
12077                --  Priority_Specific_Dispatching pragmas within the same
12078                --  partition. We can only check those we know about!
12079
12080                for J in
12081                   Specific_Dispatching.First .. Specific_Dispatching.Last
12082                loop
12083                   if Specific_Dispatching.Table (J).First_Priority in
12084                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12085                   or else Specific_Dispatching.Table (J).Last_Priority in
12086                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12087                   then
12088                      Error_Msg_Sloc :=
12089                        Specific_Dispatching.Table (J).Pragma_Loc;
12090                         Error_Pragma
12091                           ("priority range overlaps with "
12092                            & "Priority_Specific_Dispatching#");
12093                   end if;
12094                end loop;
12095
12096                --  The use of Priority_Specific_Dispatching is incompatible
12097                --  with Task_Dispatching_Policy.
12098
12099                if Task_Dispatching_Policy /= ' ' then
12100                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12101                      Error_Pragma
12102                        ("Priority_Specific_Dispatching incompatible "
12103                         & "with Task_Dispatching_Policy#");
12104                end if;
12105
12106                --  The use of Priority_Specific_Dispatching forces ceiling
12107                --  locking policy.
12108
12109                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12110                   Error_Msg_Sloc := Locking_Policy_Sloc;
12111                      Error_Pragma
12112                        ("Priority_Specific_Dispatching incompatible "
12113                         & "with Locking_Policy#");
12114
12115                --  Set the Ceiling_Locking policy, but preserve System_Location
12116                --  since we like the error message with the run time name.
12117
12118                else
12119                   Locking_Policy := 'C';
12120
12121                   if Locking_Policy_Sloc /= System_Location then
12122                      Locking_Policy_Sloc := Loc;
12123                   end if;
12124                end if;
12125
12126                --  Add entry in the table
12127
12128                Specific_Dispatching.Append
12129                     ((Dispatching_Policy => DP,
12130                       First_Priority     => UI_To_Int (Lower_Val),
12131                       Last_Priority      => UI_To_Int (Upper_Val),
12132                       Pragma_Loc         => Loc));
12133             end if;
12134          end Priority_Specific_Dispatching;
12135
12136          -------------
12137          -- Profile --
12138          -------------
12139
12140          --  pragma Profile (profile_IDENTIFIER);
12141
12142          --  profile_IDENTIFIER => Restricted | Ravenscar
12143
12144          when Pragma_Profile =>
12145             Ada_2005_Pragma;
12146             Check_Arg_Count (1);
12147             Check_Valid_Configuration_Pragma;
12148             Check_No_Identifiers;
12149
12150             declare
12151                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12152             begin
12153                if Chars (Argx) = Name_Ravenscar then
12154                   Set_Ravenscar_Profile (N);
12155                elsif Chars (Argx) = Name_Restricted then
12156                   Set_Profile_Restrictions
12157                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12158                else
12159                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12160                end if;
12161             end;
12162
12163          ----------------------
12164          -- Profile_Warnings --
12165          ----------------------
12166
12167          --  pragma Profile_Warnings (profile_IDENTIFIER);
12168
12169          --  profile_IDENTIFIER => Restricted | Ravenscar
12170
12171          when Pragma_Profile_Warnings =>
12172             GNAT_Pragma;
12173             Check_Arg_Count (1);
12174             Check_Valid_Configuration_Pragma;
12175             Check_No_Identifiers;
12176
12177             declare
12178                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12179             begin
12180                if Chars (Argx) = Name_Ravenscar then
12181                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12182                elsif Chars (Argx) = Name_Restricted then
12183                   Set_Profile_Restrictions (Restricted, N, Warn => True);
12184                else
12185                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12186                end if;
12187             end;
12188
12189          --------------------------
12190          -- Propagate_Exceptions --
12191          --------------------------
12192
12193          --  pragma Propagate_Exceptions;
12194
12195          --  Note: this pragma is obsolete and has no effect
12196
12197          when Pragma_Propagate_Exceptions =>
12198             GNAT_Pragma;
12199             Check_Arg_Count (0);
12200
12201             if In_Extended_Main_Source_Unit (N) then
12202                Propagate_Exceptions := True;
12203             end if;
12204
12205          ------------------
12206          -- Psect_Object --
12207          ------------------
12208
12209          --  pragma Psect_Object (
12210          --        [Internal =>] LOCAL_NAME,
12211          --     [, [External =>] EXTERNAL_SYMBOL]
12212          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12213
12214          when Pragma_Psect_Object | Pragma_Common_Object =>
12215          Psect_Object : declare
12216             Args  : Args_List (1 .. 3);
12217             Names : constant Name_List (1 .. 3) := (
12218                       Name_Internal,
12219                       Name_External,
12220                       Name_Size);
12221
12222             Internal : Node_Id renames Args (1);
12223             External : Node_Id renames Args (2);
12224             Size     : Node_Id renames Args (3);
12225
12226             Def_Id : Entity_Id;
12227
12228             procedure Check_Too_Long (Arg : Node_Id);
12229             --  Posts message if the argument is an identifier with more
12230             --  than 31 characters, or a string literal with more than
12231             --  31 characters, and we are operating under VMS
12232
12233             --------------------
12234             -- Check_Too_Long --
12235             --------------------
12236
12237             procedure Check_Too_Long (Arg : Node_Id) is
12238                X : constant Node_Id := Original_Node (Arg);
12239
12240             begin
12241                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12242                   Error_Pragma_Arg
12243                     ("inappropriate argument for pragma %", Arg);
12244                end if;
12245
12246                if OpenVMS_On_Target then
12247                   if (Nkind (X) = N_String_Literal
12248                        and then String_Length (Strval (X)) > 31)
12249                     or else
12250                      (Nkind (X) = N_Identifier
12251                        and then Length_Of_Name (Chars (X)) > 31)
12252                   then
12253                      Error_Pragma_Arg
12254                        ("argument for pragma % is longer than 31 characters",
12255                         Arg);
12256                   end if;
12257                end if;
12258             end Check_Too_Long;
12259
12260          --  Start of processing for Common_Object/Psect_Object
12261
12262          begin
12263             GNAT_Pragma;
12264             Gather_Associations (Names, Args);
12265             Process_Extended_Import_Export_Internal_Arg (Internal);
12266
12267             Def_Id := Entity (Internal);
12268
12269             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12270                Error_Pragma_Arg
12271                  ("pragma% must designate an object", Internal);
12272             end if;
12273
12274             Check_Too_Long (Internal);
12275
12276             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12277                Error_Pragma_Arg
12278                  ("cannot use pragma% for imported/exported object",
12279                   Internal);
12280             end if;
12281
12282             if Is_Concurrent_Type (Etype (Internal)) then
12283                Error_Pragma_Arg
12284                  ("cannot specify pragma % for task/protected object",
12285                   Internal);
12286             end if;
12287
12288             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12289                  or else
12290                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12291             then
12292                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12293             end if;
12294
12295             if Ekind (Def_Id) = E_Constant then
12296                Error_Pragma_Arg
12297                  ("cannot specify pragma % for a constant", Internal);
12298             end if;
12299
12300             if Is_Record_Type (Etype (Internal)) then
12301                declare
12302                   Ent  : Entity_Id;
12303                   Decl : Entity_Id;
12304
12305                begin
12306                   Ent := First_Entity (Etype (Internal));
12307                   while Present (Ent) loop
12308                      Decl := Declaration_Node (Ent);
12309
12310                      if Ekind (Ent) = E_Component
12311                        and then Nkind (Decl) = N_Component_Declaration
12312                        and then Present (Expression (Decl))
12313                        and then Warn_On_Export_Import
12314                      then
12315                         Error_Msg_N
12316                           ("?object for pragma % has defaults", Internal);
12317                         exit;
12318
12319                      else
12320                         Next_Entity (Ent);
12321                      end if;
12322                   end loop;
12323                end;
12324             end if;
12325
12326             if Present (Size) then
12327                Check_Too_Long (Size);
12328             end if;
12329
12330             if Present (External) then
12331                Check_Arg_Is_External_Name (External);
12332                Check_Too_Long (External);
12333             end if;
12334
12335             --  If all error tests pass, link pragma on to the rep item chain
12336
12337             Record_Rep_Item (Def_Id, N);
12338          end Psect_Object;
12339
12340          ----------
12341          -- Pure --
12342          ----------
12343
12344          --  pragma Pure [(library_unit_NAME)];
12345
12346          when Pragma_Pure => Pure : declare
12347             Ent : Entity_Id;
12348
12349          begin
12350             Check_Ada_83_Warning;
12351             Check_Valid_Library_Unit_Pragma;
12352
12353             if Nkind (N) = N_Null_Statement then
12354                return;
12355             end if;
12356
12357             Ent := Find_Lib_Unit_Name;
12358             Set_Is_Pure (Ent);
12359             Set_Has_Pragma_Pure (Ent);
12360             Set_Suppress_Elaboration_Warnings (Ent);
12361          end Pure;
12362
12363          -------------
12364          -- Pure_05 --
12365          -------------
12366
12367          --  pragma Pure_05 [(library_unit_NAME)];
12368
12369          --  This pragma is useable only in GNAT_Mode, where it is used like
12370          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12371          --  it is ignored). It may be used after a pragma Preelaborate, in
12372          --  which case it overrides the effect of the pragma Preelaborate.
12373          --  This is used to implement AI-362 which recategorizes some run-time
12374          --  packages in Ada 2005 mode.
12375
12376          when Pragma_Pure_05 => Pure_05 : declare
12377             Ent : Entity_Id;
12378
12379          begin
12380             GNAT_Pragma;
12381             Check_Valid_Library_Unit_Pragma;
12382
12383             if not GNAT_Mode then
12384                Error_Pragma ("pragma% only available in GNAT mode");
12385             end if;
12386
12387             if Nkind (N) = N_Null_Statement then
12388                return;
12389             end if;
12390
12391             --  This is one of the few cases where we need to test the value of
12392             --  Ada_Version_Explicit rather than Ada_Version (which is always
12393             --  set to Ada_2012 in a predefined unit), we need to know the
12394             --  explicit version set to know if this pragma is active.
12395
12396             if Ada_Version_Explicit >= Ada_2005 then
12397                Ent := Find_Lib_Unit_Name;
12398                Set_Is_Preelaborated (Ent, False);
12399                Set_Is_Pure (Ent);
12400                Set_Suppress_Elaboration_Warnings (Ent);
12401             end if;
12402          end Pure_05;
12403
12404          -------------------
12405          -- Pure_Function --
12406          -------------------
12407
12408          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12409
12410          when Pragma_Pure_Function => Pure_Function : declare
12411             E_Id      : Node_Id;
12412             E         : Entity_Id;
12413             Def_Id    : Entity_Id;
12414             Effective : Boolean := False;
12415
12416          begin
12417             GNAT_Pragma;
12418             Check_Arg_Count (1);
12419             Check_Optional_Identifier (Arg1, Name_Entity);
12420             Check_Arg_Is_Local_Name (Arg1);
12421             E_Id := Get_Pragma_Arg (Arg1);
12422
12423             if Error_Posted (E_Id) then
12424                return;
12425             end if;
12426
12427             --  Loop through homonyms (overloadings) of referenced entity
12428
12429             E := Entity (E_Id);
12430
12431             if Present (E) then
12432                loop
12433                   Def_Id := Get_Base_Subprogram (E);
12434
12435                   if not Ekind_In (Def_Id, E_Function,
12436                                            E_Generic_Function,
12437                                            E_Operator)
12438                   then
12439                      Error_Pragma_Arg
12440                        ("pragma% requires a function name", Arg1);
12441                   end if;
12442
12443                   Set_Is_Pure (Def_Id);
12444
12445                   if not Has_Pragma_Pure_Function (Def_Id) then
12446                      Set_Has_Pragma_Pure_Function (Def_Id);
12447                      Effective := True;
12448                   end if;
12449
12450                   exit when From_Aspect_Specification (N);
12451                   E := Homonym (E);
12452                   exit when No (E) or else Scope (E) /= Current_Scope;
12453                end loop;
12454
12455                if not Effective
12456                  and then Warn_On_Redundant_Constructs
12457                then
12458                   Error_Msg_NE
12459                     ("pragma Pure_Function on& is redundant?",
12460                      N, Entity (E_Id));
12461                end if;
12462             end if;
12463          end Pure_Function;
12464
12465          --------------------
12466          -- Queuing_Policy --
12467          --------------------
12468
12469          --  pragma Queuing_Policy (policy_IDENTIFIER);
12470
12471          when Pragma_Queuing_Policy => declare
12472             QP : Character;
12473
12474          begin
12475             Check_Ada_83_Warning;
12476             Check_Arg_Count (1);
12477             Check_No_Identifiers;
12478             Check_Arg_Is_Queuing_Policy (Arg1);
12479             Check_Valid_Configuration_Pragma;
12480             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12481             QP := Fold_Upper (Name_Buffer (1));
12482
12483             if Queuing_Policy /= ' '
12484               and then Queuing_Policy /= QP
12485             then
12486                Error_Msg_Sloc := Queuing_Policy_Sloc;
12487                Error_Pragma ("queuing policy incompatible with policy#");
12488
12489             --  Set new policy, but always preserve System_Location since we
12490             --  like the error message with the run time name.
12491
12492             else
12493                Queuing_Policy := QP;
12494
12495                if Queuing_Policy_Sloc /= System_Location then
12496                   Queuing_Policy_Sloc := Loc;
12497                end if;
12498             end if;
12499          end;
12500
12501          -----------------------
12502          -- Relative_Deadline --
12503          -----------------------
12504
12505          --  pragma Relative_Deadline (time_span_EXPRESSION);
12506
12507          when Pragma_Relative_Deadline => Relative_Deadline : declare
12508             P   : constant Node_Id := Parent (N);
12509             Arg : Node_Id;
12510
12511          begin
12512             Ada_2005_Pragma;
12513             Check_No_Identifiers;
12514             Check_Arg_Count (1);
12515
12516             Arg := Get_Pragma_Arg (Arg1);
12517
12518             --  The expression must be analyzed in the special manner described
12519             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12520
12521             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12522
12523             --  Subprogram case
12524
12525             if Nkind (P) = N_Subprogram_Body then
12526                Check_In_Main_Program;
12527
12528             --  Tasks
12529
12530             elsif Nkind (P) = N_Task_Definition then
12531                null;
12532
12533             --  Anything else is incorrect
12534
12535             else
12536                Pragma_Misplaced;
12537             end if;
12538
12539             if Has_Relative_Deadline_Pragma (P) then
12540                Error_Pragma ("duplicate pragma% not allowed");
12541             else
12542                Set_Has_Relative_Deadline_Pragma (P, True);
12543
12544                if Nkind (P) = N_Task_Definition then
12545                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12546                end if;
12547             end if;
12548          end Relative_Deadline;
12549
12550          ---------------------------
12551          -- Remote_Call_Interface --
12552          ---------------------------
12553
12554          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12555
12556          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12557             Cunit_Node : Node_Id;
12558             Cunit_Ent  : Entity_Id;
12559             K          : Node_Kind;
12560
12561          begin
12562             Check_Ada_83_Warning;
12563             Check_Valid_Library_Unit_Pragma;
12564
12565             if Nkind (N) = N_Null_Statement then
12566                return;
12567             end if;
12568
12569             Cunit_Node := Cunit (Current_Sem_Unit);
12570             K          := Nkind (Unit (Cunit_Node));
12571             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12572
12573             if K = N_Package_Declaration
12574               or else K = N_Generic_Package_Declaration
12575               or else K = N_Subprogram_Declaration
12576               or else K = N_Generic_Subprogram_Declaration
12577               or else (K = N_Subprogram_Body
12578                          and then Acts_As_Spec (Unit (Cunit_Node)))
12579             then
12580                null;
12581             else
12582                Error_Pragma (
12583                  "pragma% must apply to package or subprogram declaration");
12584             end if;
12585
12586             Set_Is_Remote_Call_Interface (Cunit_Ent);
12587          end Remote_Call_Interface;
12588
12589          ------------------
12590          -- Remote_Types --
12591          ------------------
12592
12593          --  pragma Remote_Types [(library_unit_NAME)];
12594
12595          when Pragma_Remote_Types => Remote_Types : declare
12596             Cunit_Node : Node_Id;
12597             Cunit_Ent  : Entity_Id;
12598
12599          begin
12600             Check_Ada_83_Warning;
12601             Check_Valid_Library_Unit_Pragma;
12602
12603             if Nkind (N) = N_Null_Statement then
12604                return;
12605             end if;
12606
12607             Cunit_Node := Cunit (Current_Sem_Unit);
12608             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12609
12610             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12611                                                 N_Generic_Package_Declaration)
12612             then
12613                Error_Pragma
12614                  ("pragma% can only apply to a package declaration");
12615             end if;
12616
12617             Set_Is_Remote_Types (Cunit_Ent);
12618          end Remote_Types;
12619
12620          ---------------
12621          -- Ravenscar --
12622          ---------------
12623
12624          --  pragma Ravenscar;
12625
12626          when Pragma_Ravenscar =>
12627             GNAT_Pragma;
12628             Check_Arg_Count (0);
12629             Check_Valid_Configuration_Pragma;
12630             Set_Ravenscar_Profile (N);
12631
12632             if Warn_On_Obsolescent_Feature then
12633                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12634                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12635             end if;
12636
12637          -------------------------
12638          -- Restricted_Run_Time --
12639          -------------------------
12640
12641          --  pragma Restricted_Run_Time;
12642
12643          when Pragma_Restricted_Run_Time =>
12644             GNAT_Pragma;
12645             Check_Arg_Count (0);
12646             Check_Valid_Configuration_Pragma;
12647             Set_Profile_Restrictions
12648               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12649
12650             if Warn_On_Obsolescent_Feature then
12651                Error_Msg_N
12652                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12653                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12654             end if;
12655
12656          ------------------
12657          -- Restrictions --
12658          ------------------
12659
12660          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12661
12662          --  RESTRICTION ::=
12663          --    restriction_IDENTIFIER
12664          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12665
12666          when Pragma_Restrictions =>
12667             Process_Restrictions_Or_Restriction_Warnings
12668               (Warn => Treat_Restrictions_As_Warnings);
12669
12670          --------------------------
12671          -- Restriction_Warnings --
12672          --------------------------
12673
12674          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12675
12676          --  RESTRICTION ::=
12677          --    restriction_IDENTIFIER
12678          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12679
12680          when Pragma_Restriction_Warnings =>
12681             GNAT_Pragma;
12682             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12683
12684          ----------------
12685          -- Reviewable --
12686          ----------------
12687
12688          --  pragma Reviewable;
12689
12690          when Pragma_Reviewable =>
12691             Check_Ada_83_Warning;
12692             Check_Arg_Count (0);
12693
12694             --  Call dummy debugging function rv. This is done to assist front
12695             --  end debugging. By placing a Reviewable pragma in the source
12696             --  program, a breakpoint on rv catches this place in the source,
12697             --  allowing convenient stepping to the point of interest.
12698
12699             rv;
12700
12701          --------------------------
12702          -- Short_Circuit_And_Or --
12703          --------------------------
12704
12705          when Pragma_Short_Circuit_And_Or =>
12706             GNAT_Pragma;
12707             Check_Arg_Count (0);
12708             Check_Valid_Configuration_Pragma;
12709             Short_Circuit_And_Or := True;
12710
12711          -------------------
12712          -- Share_Generic --
12713          -------------------
12714
12715          --  pragma Share_Generic (NAME {, NAME});
12716
12717          when Pragma_Share_Generic =>
12718             GNAT_Pragma;
12719             Process_Generic_List;
12720
12721          ------------
12722          -- Shared --
12723          ------------
12724
12725          --  pragma Shared (LOCAL_NAME);
12726
12727          when Pragma_Shared =>
12728             GNAT_Pragma;
12729             Process_Atomic_Shared_Volatile;
12730
12731          --------------------
12732          -- Shared_Passive --
12733          --------------------
12734
12735          --  pragma Shared_Passive [(library_unit_NAME)];
12736
12737          --  Set the flag Is_Shared_Passive of program unit name entity
12738
12739          when Pragma_Shared_Passive => Shared_Passive : declare
12740             Cunit_Node : Node_Id;
12741             Cunit_Ent  : Entity_Id;
12742
12743          begin
12744             Check_Ada_83_Warning;
12745             Check_Valid_Library_Unit_Pragma;
12746
12747             if Nkind (N) = N_Null_Statement then
12748                return;
12749             end if;
12750
12751             Cunit_Node := Cunit (Current_Sem_Unit);
12752             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12753
12754             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12755                                                 N_Generic_Package_Declaration)
12756             then
12757                Error_Pragma
12758                  ("pragma% can only apply to a package declaration");
12759             end if;
12760
12761             Set_Is_Shared_Passive (Cunit_Ent);
12762          end Shared_Passive;
12763
12764          -----------------------
12765          -- Short_Descriptors --
12766          -----------------------
12767
12768          --  pragma Short_Descriptors;
12769
12770          when Pragma_Short_Descriptors =>
12771             GNAT_Pragma;
12772             Check_Arg_Count (0);
12773             Check_Valid_Configuration_Pragma;
12774             Short_Descriptors := True;
12775
12776          ----------------------
12777          -- Source_File_Name --
12778          ----------------------
12779
12780          --  There are five forms for this pragma:
12781
12782          --  pragma Source_File_Name (
12783          --    [UNIT_NAME      =>] unit_NAME,
12784          --     BODY_FILE_NAME =>  STRING_LITERAL
12785          --    [, [INDEX =>] INTEGER_LITERAL]);
12786
12787          --  pragma Source_File_Name (
12788          --    [UNIT_NAME      =>] unit_NAME,
12789          --     SPEC_FILE_NAME =>  STRING_LITERAL
12790          --    [, [INDEX =>] INTEGER_LITERAL]);
12791
12792          --  pragma Source_File_Name (
12793          --     BODY_FILE_NAME  => STRING_LITERAL
12794          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12795          --  [, CASING          => CASING_SPEC]);
12796
12797          --  pragma Source_File_Name (
12798          --     SPEC_FILE_NAME  => STRING_LITERAL
12799          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12800          --  [, CASING          => CASING_SPEC]);
12801
12802          --  pragma Source_File_Name (
12803          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12804          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12805          --  [, CASING             => CASING_SPEC]);
12806
12807          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12808
12809          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12810          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12811          --  only be used when no project file is used, while SFNP can only be
12812          --  used when a project file is used.
12813
12814          --  No processing here. Processing was completed during parsing, since
12815          --  we need to have file names set as early as possible. Units are
12816          --  loaded well before semantic processing starts.
12817
12818          --  The only processing we defer to this point is the check for
12819          --  correct placement.
12820
12821          when Pragma_Source_File_Name =>
12822             GNAT_Pragma;
12823             Check_Valid_Configuration_Pragma;
12824
12825          ------------------------------
12826          -- Source_File_Name_Project --
12827          ------------------------------
12828
12829          --  See Source_File_Name for syntax
12830
12831          --  No processing here. Processing was completed during parsing, since
12832          --  we need to have file names set as early as possible. Units are
12833          --  loaded well before semantic processing starts.
12834
12835          --  The only processing we defer to this point is the check for
12836          --  correct placement.
12837
12838          when Pragma_Source_File_Name_Project =>
12839             GNAT_Pragma;
12840             Check_Valid_Configuration_Pragma;
12841
12842             --  Check that a pragma Source_File_Name_Project is used only in a
12843             --  configuration pragmas file.
12844
12845             --  Pragmas Source_File_Name_Project should only be generated by
12846             --  the Project Manager in configuration pragmas files.
12847
12848             --  This is really an ugly test. It seems to depend on some
12849             --  accidental and undocumented property. At the very least it
12850             --  needs to be documented, but it would be better to have a
12851             --  clean way of testing if we are in a configuration file???
12852
12853             if Present (Parent (N)) then
12854                Error_Pragma
12855                  ("pragma% can only appear in a configuration pragmas file");
12856             end if;
12857
12858          ----------------------
12859          -- Source_Reference --
12860          ----------------------
12861
12862          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12863
12864          --  Nothing to do, all processing completed in Par.Prag, since we need
12865          --  the information for possible parser messages that are output.
12866
12867          when Pragma_Source_Reference =>
12868             GNAT_Pragma;
12869
12870          --------------------------------
12871          -- Static_Elaboration_Desired --
12872          --------------------------------
12873
12874          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12875
12876          when Pragma_Static_Elaboration_Desired =>
12877             GNAT_Pragma;
12878             Check_At_Most_N_Arguments (1);
12879
12880             if Is_Compilation_Unit (Current_Scope)
12881               and then Ekind (Current_Scope) = E_Package
12882             then
12883                Set_Static_Elaboration_Desired (Current_Scope, True);
12884             else
12885                Error_Pragma ("pragma% must apply to a library-level package");
12886             end if;
12887
12888          ------------------
12889          -- Storage_Size --
12890          ------------------
12891
12892          --  pragma Storage_Size (EXPRESSION);
12893
12894          when Pragma_Storage_Size => Storage_Size : declare
12895             P   : constant Node_Id := Parent (N);
12896             Arg : Node_Id;
12897
12898          begin
12899             Check_No_Identifiers;
12900             Check_Arg_Count (1);
12901
12902             --  The expression must be analyzed in the special manner described
12903             --  in "Handling of Default Expressions" in sem.ads.
12904
12905             Arg := Get_Pragma_Arg (Arg1);
12906             Preanalyze_Spec_Expression (Arg, Any_Integer);
12907
12908             if not Is_Static_Expression (Arg) then
12909                Check_Restriction (Static_Storage_Size, Arg);
12910             end if;
12911
12912             if Nkind (P) /= N_Task_Definition then
12913                Pragma_Misplaced;
12914                return;
12915
12916             else
12917                if Has_Storage_Size_Pragma (P) then
12918                   Error_Pragma ("duplicate pragma% not allowed");
12919                else
12920                   Set_Has_Storage_Size_Pragma (P, True);
12921                end if;
12922
12923                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12924                --  ???  exp_ch9 should use this!
12925             end if;
12926          end Storage_Size;
12927
12928          ------------------
12929          -- Storage_Unit --
12930          ------------------
12931
12932          --  pragma Storage_Unit (NUMERIC_LITERAL);
12933
12934          --  Only permitted argument is System'Storage_Unit value
12935
12936          when Pragma_Storage_Unit =>
12937             Check_No_Identifiers;
12938             Check_Arg_Count (1);
12939             Check_Arg_Is_Integer_Literal (Arg1);
12940
12941             if Intval (Get_Pragma_Arg (Arg1)) /=
12942               UI_From_Int (Ttypes.System_Storage_Unit)
12943             then
12944                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12945                Error_Pragma_Arg
12946                  ("the only allowed argument for pragma% is ^", Arg1);
12947             end if;
12948
12949          --------------------
12950          -- Stream_Convert --
12951          --------------------
12952
12953          --  pragma Stream_Convert (
12954          --    [Entity =>] type_LOCAL_NAME,
12955          --    [Read   =>] function_NAME,
12956          --    [Write  =>] function NAME);
12957
12958          when Pragma_Stream_Convert => Stream_Convert : declare
12959
12960             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12961             --  Check that the given argument is the name of a local function
12962             --  of one argument that is not overloaded earlier in the current
12963             --  local scope. A check is also made that the argument is a
12964             --  function with one parameter.
12965
12966             --------------------------------------
12967             -- Check_OK_Stream_Convert_Function --
12968             --------------------------------------
12969
12970             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12971                Ent : Entity_Id;
12972
12973             begin
12974                Check_Arg_Is_Local_Name (Arg);
12975                Ent := Entity (Get_Pragma_Arg (Arg));
12976
12977                if Has_Homonym (Ent) then
12978                   Error_Pragma_Arg
12979                     ("argument for pragma% may not be overloaded", Arg);
12980                end if;
12981
12982                if Ekind (Ent) /= E_Function
12983                  or else No (First_Formal (Ent))
12984                  or else Present (Next_Formal (First_Formal (Ent)))
12985                then
12986                   Error_Pragma_Arg
12987                     ("argument for pragma% must be" &
12988                      " function of one argument", Arg);
12989                end if;
12990             end Check_OK_Stream_Convert_Function;
12991
12992          --  Start of processing for Stream_Convert
12993
12994          begin
12995             GNAT_Pragma;
12996             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12997             Check_Arg_Count (3);
12998             Check_Optional_Identifier (Arg1, Name_Entity);
12999             Check_Optional_Identifier (Arg2, Name_Read);
13000             Check_Optional_Identifier (Arg3, Name_Write);
13001             Check_Arg_Is_Local_Name (Arg1);
13002             Check_OK_Stream_Convert_Function (Arg2);
13003             Check_OK_Stream_Convert_Function (Arg3);
13004
13005             declare
13006                Typ   : constant Entity_Id :=
13007                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13008                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13009                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13010
13011             begin
13012                Check_First_Subtype (Arg1);
13013
13014                --  Check for too early or too late. Note that we don't enforce
13015                --  the rule about primitive operations in this case, since, as
13016                --  is the case for explicit stream attributes themselves, these
13017                --  restrictions are not appropriate. Note that the chaining of
13018                --  the pragma by Rep_Item_Too_Late is actually the critical
13019                --  processing done for this pragma.
13020
13021                if Rep_Item_Too_Early (Typ, N)
13022                     or else
13023                   Rep_Item_Too_Late (Typ, N, FOnly => True)
13024                then
13025                   return;
13026                end if;
13027
13028                --  Return if previous error
13029
13030                if Etype (Typ) = Any_Type
13031                     or else
13032                   Etype (Read) = Any_Type
13033                     or else
13034                   Etype (Write) = Any_Type
13035                then
13036                   return;
13037                end if;
13038
13039                --  Error checks
13040
13041                if Underlying_Type (Etype (Read)) /= Typ then
13042                   Error_Pragma_Arg
13043                     ("incorrect return type for function&", Arg2);
13044                end if;
13045
13046                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13047                   Error_Pragma_Arg
13048                     ("incorrect parameter type for function&", Arg3);
13049                end if;
13050
13051                if Underlying_Type (Etype (First_Formal (Read))) /=
13052                   Underlying_Type (Etype (Write))
13053                then
13054                   Error_Pragma_Arg
13055                     ("result type of & does not match Read parameter type",
13056                      Arg3);
13057                end if;
13058             end;
13059          end Stream_Convert;
13060
13061          -------------------------
13062          -- Style_Checks (GNAT) --
13063          -------------------------
13064
13065          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13066
13067          --  This is processed by the parser since some of the style checks
13068          --  take place during source scanning and parsing. This means that
13069          --  we don't need to issue error messages here.
13070
13071          when Pragma_Style_Checks => Style_Checks : declare
13072             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13073             S  : String_Id;
13074             C  : Char_Code;
13075
13076          begin
13077             GNAT_Pragma;
13078             Check_No_Identifiers;
13079
13080             --  Two argument form
13081
13082             if Arg_Count = 2 then
13083                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13084
13085                declare
13086                   E_Id : Node_Id;
13087                   E    : Entity_Id;
13088
13089                begin
13090                   E_Id := Get_Pragma_Arg (Arg2);
13091                   Analyze (E_Id);
13092
13093                   if not Is_Entity_Name (E_Id) then
13094                      Error_Pragma_Arg
13095                        ("second argument of pragma% must be entity name",
13096                         Arg2);
13097                   end if;
13098
13099                   E := Entity (E_Id);
13100
13101                   if E = Any_Id then
13102                      return;
13103                   else
13104                      loop
13105                         Set_Suppress_Style_Checks (E,
13106                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13107                         exit when No (Homonym (E));
13108                         E := Homonym (E);
13109                      end loop;
13110                   end if;
13111                end;
13112
13113             --  One argument form
13114
13115             else
13116                Check_Arg_Count (1);
13117
13118                if Nkind (A) = N_String_Literal then
13119                   S   := Strval (A);
13120
13121                   declare
13122                      Slen    : constant Natural := Natural (String_Length (S));
13123                      Options : String (1 .. Slen);
13124                      J       : Natural;
13125
13126                   begin
13127                      J := 1;
13128                      loop
13129                         C := Get_String_Char (S, Int (J));
13130                         exit when not In_Character_Range (C);
13131                         Options (J) := Get_Character (C);
13132
13133                         --  If at end of string, set options. As per discussion
13134                         --  above, no need to check for errors, since we issued
13135                         --  them in the parser.
13136
13137                         if J = Slen then
13138                            Set_Style_Check_Options (Options);
13139                            exit;
13140                         end if;
13141
13142                         J := J + 1;
13143                      end loop;
13144                   end;
13145
13146                elsif Nkind (A) = N_Identifier then
13147                   if Chars (A) = Name_All_Checks then
13148                      if GNAT_Mode then
13149                         Set_GNAT_Style_Check_Options;
13150                      else
13151                         Set_Default_Style_Check_Options;
13152                      end if;
13153
13154                   elsif Chars (A) = Name_On then
13155                      Style_Check := True;
13156
13157                   elsif Chars (A) = Name_Off then
13158                      Style_Check := False;
13159                   end if;
13160                end if;
13161             end if;
13162          end Style_Checks;
13163
13164          --------------
13165          -- Subtitle --
13166          --------------
13167
13168          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13169
13170          when Pragma_Subtitle =>
13171             GNAT_Pragma;
13172             Check_Arg_Count (1);
13173             Check_Optional_Identifier (Arg1, Name_Subtitle);
13174             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13175             Store_Note (N);
13176
13177          --------------
13178          -- Suppress --
13179          --------------
13180
13181          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13182
13183          when Pragma_Suppress =>
13184             Process_Suppress_Unsuppress (True);
13185
13186          ------------------
13187          -- Suppress_All --
13188          ------------------
13189
13190          --  pragma Suppress_All;
13191
13192          --  The only check made here is that the pragma has no arguments.
13193          --  There are no placement rules, and the processing required (setting
13194          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
13195          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
13196          --  then creates and inserts a pragma Suppress (All_Checks).
13197
13198          when Pragma_Suppress_All =>
13199             GNAT_Pragma;
13200             Check_Arg_Count (0);
13201
13202          -------------------------
13203          -- Suppress_Debug_Info --
13204          -------------------------
13205
13206          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13207
13208          when Pragma_Suppress_Debug_Info =>
13209             GNAT_Pragma;
13210             Check_Arg_Count (1);
13211             Check_Optional_Identifier (Arg1, Name_Entity);
13212             Check_Arg_Is_Local_Name (Arg1);
13213             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13214
13215          ----------------------------------
13216          -- Suppress_Exception_Locations --
13217          ----------------------------------
13218
13219          --  pragma Suppress_Exception_Locations;
13220
13221          when Pragma_Suppress_Exception_Locations =>
13222             GNAT_Pragma;
13223             Check_Arg_Count (0);
13224             Check_Valid_Configuration_Pragma;
13225             Exception_Locations_Suppressed := True;
13226
13227          -----------------------------
13228          -- Suppress_Initialization --
13229          -----------------------------
13230
13231          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13232
13233          when Pragma_Suppress_Initialization => Suppress_Init : declare
13234             E_Id : Node_Id;
13235             E    : Entity_Id;
13236
13237          begin
13238             GNAT_Pragma;
13239             Check_Arg_Count (1);
13240             Check_Optional_Identifier (Arg1, Name_Entity);
13241             Check_Arg_Is_Local_Name (Arg1);
13242
13243             E_Id := Get_Pragma_Arg (Arg1);
13244
13245             if Etype (E_Id) = Any_Type then
13246                return;
13247             end if;
13248
13249             E := Entity (E_Id);
13250
13251             if not Is_Type (E) then
13252                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13253             end if;
13254
13255             if Rep_Item_Too_Early (E, N)
13256                  or else
13257                Rep_Item_Too_Late (E, N, FOnly => True)
13258             then
13259                return;
13260             end if;
13261
13262             --  For incomplete/private type, set flag on full view
13263
13264             if Is_Incomplete_Or_Private_Type (E) then
13265                if No (Full_View (Base_Type (E))) then
13266                   Error_Pragma_Arg
13267                     ("argument of pragma% cannot be an incomplete type", Arg1);
13268                else
13269                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13270                end if;
13271
13272             --  For first subtype, set flag on base type
13273
13274             elsif Is_First_Subtype (E) then
13275                Set_Suppress_Initialization (Base_Type (E));
13276
13277             --  For other than first subtype, set flag on subtype itself
13278
13279             else
13280                Set_Suppress_Initialization (E);
13281             end if;
13282          end Suppress_Init;
13283
13284          -----------------
13285          -- System_Name --
13286          -----------------
13287
13288          --  pragma System_Name (DIRECT_NAME);
13289
13290          --  Syntax check: one argument, which must be the identifier GNAT or
13291          --  the identifier GCC, no other identifiers are acceptable.
13292
13293          when Pragma_System_Name =>
13294             GNAT_Pragma;
13295             Check_No_Identifiers;
13296             Check_Arg_Count (1);
13297             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13298
13299          -----------------------------
13300          -- Task_Dispatching_Policy --
13301          -----------------------------
13302
13303          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13304
13305          when Pragma_Task_Dispatching_Policy => declare
13306             DP : Character;
13307
13308          begin
13309             Check_Ada_83_Warning;
13310             Check_Arg_Count (1);
13311             Check_No_Identifiers;
13312             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13313             Check_Valid_Configuration_Pragma;
13314             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13315             DP := Fold_Upper (Name_Buffer (1));
13316
13317             if Task_Dispatching_Policy /= ' '
13318               and then Task_Dispatching_Policy /= DP
13319             then
13320                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13321                Error_Pragma
13322                  ("task dispatching policy incompatible with policy#");
13323
13324             --  Set new policy, but always preserve System_Location since we
13325             --  like the error message with the run time name.
13326
13327             else
13328                Task_Dispatching_Policy := DP;
13329
13330                if Task_Dispatching_Policy_Sloc /= System_Location then
13331                   Task_Dispatching_Policy_Sloc := Loc;
13332                end if;
13333             end if;
13334          end;
13335
13336          ---------------
13337          -- Task_Info --
13338          ---------------
13339
13340          --  pragma Task_Info (EXPRESSION);
13341
13342          when Pragma_Task_Info => Task_Info : declare
13343             P : constant Node_Id := Parent (N);
13344
13345          begin
13346             GNAT_Pragma;
13347
13348             if Nkind (P) /= N_Task_Definition then
13349                Error_Pragma ("pragma% must appear in task definition");
13350             end if;
13351
13352             Check_No_Identifiers;
13353             Check_Arg_Count (1);
13354
13355             Analyze_And_Resolve
13356               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13357
13358             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13359                return;
13360             end if;
13361
13362             if Has_Task_Info_Pragma (P) then
13363                Error_Pragma ("duplicate pragma% not allowed");
13364             else
13365                Set_Has_Task_Info_Pragma (P, True);
13366             end if;
13367          end Task_Info;
13368
13369          ---------------
13370          -- Task_Name --
13371          ---------------
13372
13373          --  pragma Task_Name (string_EXPRESSION);
13374
13375          when Pragma_Task_Name => Task_Name : declare
13376             P   : constant Node_Id := Parent (N);
13377             Arg : Node_Id;
13378
13379          begin
13380             Check_No_Identifiers;
13381             Check_Arg_Count (1);
13382
13383             Arg := Get_Pragma_Arg (Arg1);
13384
13385             --  The expression is used in the call to Create_Task, and must be
13386             --  expanded there, not in the context of the current spec. It must
13387             --  however be analyzed to capture global references, in case it
13388             --  appears in a generic context.
13389
13390             Preanalyze_And_Resolve (Arg, Standard_String);
13391
13392             if Nkind (P) /= N_Task_Definition then
13393                Pragma_Misplaced;
13394             end if;
13395
13396             if Has_Task_Name_Pragma (P) then
13397                Error_Pragma ("duplicate pragma% not allowed");
13398             else
13399                Set_Has_Task_Name_Pragma (P, True);
13400                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13401             end if;
13402          end Task_Name;
13403
13404          ------------------
13405          -- Task_Storage --
13406          ------------------
13407
13408          --  pragma Task_Storage (
13409          --     [Task_Type =>] LOCAL_NAME,
13410          --     [Top_Guard =>] static_integer_EXPRESSION);
13411
13412          when Pragma_Task_Storage => Task_Storage : declare
13413             Args  : Args_List (1 .. 2);
13414             Names : constant Name_List (1 .. 2) := (
13415                       Name_Task_Type,
13416                       Name_Top_Guard);
13417
13418             Task_Type : Node_Id renames Args (1);
13419             Top_Guard : Node_Id renames Args (2);
13420
13421             Ent : Entity_Id;
13422
13423          begin
13424             GNAT_Pragma;
13425             Gather_Associations (Names, Args);
13426
13427             if No (Task_Type) then
13428                Error_Pragma
13429                  ("missing task_type argument for pragma%");
13430             end if;
13431
13432             Check_Arg_Is_Local_Name (Task_Type);
13433
13434             Ent := Entity (Task_Type);
13435
13436             if not Is_Task_Type (Ent) then
13437                Error_Pragma_Arg
13438                  ("argument for pragma% must be task type", Task_Type);
13439             end if;
13440
13441             if No (Top_Guard) then
13442                Error_Pragma_Arg
13443                  ("pragma% takes two arguments", Task_Type);
13444             else
13445                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13446             end if;
13447
13448             Check_First_Subtype (Task_Type);
13449
13450             if Rep_Item_Too_Late (Ent, N) then
13451                raise Pragma_Exit;
13452             end if;
13453          end Task_Storage;
13454
13455          ---------------
13456          -- Test_Case --
13457          ---------------
13458
13459          --  pragma Test_Case ([Name     =>] Static_String_EXPRESSION
13460          --                   ,[Mode     =>] MODE_TYPE
13461          --                  [, Requires =>  Boolean_EXPRESSION]
13462          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13463
13464          --  MODE_TYPE ::= Nominal | Robustness
13465
13466          when Pragma_Test_Case => Test_Case : declare
13467          begin
13468             GNAT_Pragma;
13469             Check_At_Least_N_Arguments (2);
13470             Check_At_Most_N_Arguments (4);
13471             Check_Arg_Order
13472                  ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13473
13474             Check_Optional_Identifier (Arg1, Name_Name);
13475             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13476             Check_Optional_Identifier (Arg2, Name_Mode);
13477             Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13478
13479             if Arg_Count = 4 then
13480                Check_Identifier (Arg3, Name_Requires);
13481                Check_Identifier (Arg4, Name_Ensures);
13482
13483             elsif Arg_Count = 3 then
13484                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13485             end if;
13486
13487             Check_Test_Case;
13488          end Test_Case;
13489
13490          --------------------------
13491          -- Thread_Local_Storage --
13492          --------------------------
13493
13494          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13495
13496          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13497             Id : Node_Id;
13498             E  : Entity_Id;
13499
13500          begin
13501             GNAT_Pragma;
13502             Check_Arg_Count (1);
13503             Check_Optional_Identifier (Arg1, Name_Entity);
13504             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13505
13506             Id := Get_Pragma_Arg (Arg1);
13507             Analyze (Id);
13508
13509             if not Is_Entity_Name (Id)
13510               or else Ekind (Entity (Id)) /= E_Variable
13511             then
13512                Error_Pragma_Arg ("local variable name required", Arg1);
13513             end if;
13514
13515             E := Entity (Id);
13516
13517             if Rep_Item_Too_Early (E, N)
13518               or else Rep_Item_Too_Late (E, N)
13519             then
13520                raise Pragma_Exit;
13521             end if;
13522
13523             Set_Has_Pragma_Thread_Local_Storage (E);
13524             Set_Has_Gigi_Rep_Item (E);
13525          end Thread_Local_Storage;
13526
13527          ----------------
13528          -- Time_Slice --
13529          ----------------
13530
13531          --  pragma Time_Slice (static_duration_EXPRESSION);
13532
13533          when Pragma_Time_Slice => Time_Slice : declare
13534             Val : Ureal;
13535             Nod : Node_Id;
13536
13537          begin
13538             GNAT_Pragma;
13539             Check_Arg_Count (1);
13540             Check_No_Identifiers;
13541             Check_In_Main_Program;
13542             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13543
13544             if not Error_Posted (Arg1) then
13545                Nod := Next (N);
13546                while Present (Nod) loop
13547                   if Nkind (Nod) = N_Pragma
13548                     and then Pragma_Name (Nod) = Name_Time_Slice
13549                   then
13550                      Error_Msg_Name_1 := Pname;
13551                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13552                   end if;
13553
13554                   Next (Nod);
13555                end loop;
13556             end if;
13557
13558             --  Process only if in main unit
13559
13560             if Get_Source_Unit (Loc) = Main_Unit then
13561                Opt.Time_Slice_Set := True;
13562                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13563
13564                if Val <= Ureal_0 then
13565                   Opt.Time_Slice_Value := 0;
13566
13567                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13568                   Opt.Time_Slice_Value := 1_000_000_000;
13569
13570                else
13571                   Opt.Time_Slice_Value :=
13572                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13573                end if;
13574             end if;
13575          end Time_Slice;
13576
13577          -----------
13578          -- Title --
13579          -----------
13580
13581          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13582
13583          --   TITLING_OPTION ::=
13584          --     [Title =>] STRING_LITERAL
13585          --   | [Subtitle =>] STRING_LITERAL
13586
13587          when Pragma_Title => Title : declare
13588             Args  : Args_List (1 .. 2);
13589             Names : constant Name_List (1 .. 2) := (
13590                       Name_Title,
13591                       Name_Subtitle);
13592
13593          begin
13594             GNAT_Pragma;
13595             Gather_Associations (Names, Args);
13596             Store_Note (N);
13597
13598             for J in 1 .. 2 loop
13599                if Present (Args (J)) then
13600                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13601                end if;
13602             end loop;
13603          end Title;
13604
13605          ---------------------
13606          -- Unchecked_Union --
13607          ---------------------
13608
13609          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13610
13611          when Pragma_Unchecked_Union => Unchecked_Union : declare
13612             Assoc   : constant Node_Id := Arg1;
13613             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13614             Typ     : Entity_Id;
13615             Discr   : Entity_Id;
13616             Tdef    : Node_Id;
13617             Clist   : Node_Id;
13618             Vpart   : Node_Id;
13619             Comp    : Node_Id;
13620             Variant : Node_Id;
13621
13622          begin
13623             Ada_2005_Pragma;
13624             Check_No_Identifiers;
13625             Check_Arg_Count (1);
13626             Check_Arg_Is_Local_Name (Arg1);
13627
13628             Find_Type (Type_Id);
13629             Typ := Entity (Type_Id);
13630
13631             if Typ = Any_Type
13632               or else Rep_Item_Too_Early (Typ, N)
13633             then
13634                return;
13635             else
13636                Typ := Underlying_Type (Typ);
13637             end if;
13638
13639             if Rep_Item_Too_Late (Typ, N) then
13640                return;
13641             end if;
13642
13643             Check_First_Subtype (Arg1);
13644
13645             --  Note remaining cases are references to a type in the current
13646             --  declarative part. If we find an error, we post the error on
13647             --  the relevant type declaration at an appropriate point.
13648
13649             if not Is_Record_Type (Typ) then
13650                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13651                return;
13652
13653             elsif Is_Tagged_Type (Typ) then
13654                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13655                return;
13656
13657             elsif Is_Limited_Type (Typ) then
13658                Error_Msg_N
13659                  ("Unchecked_Union must not be limited record type", Typ);
13660                Explain_Limited_Type (Typ, Typ);
13661                return;
13662
13663             else
13664                if not Has_Discriminants (Typ) then
13665                   Error_Msg_N
13666                     ("Unchecked_Union must have one discriminant", Typ);
13667                   return;
13668                end if;
13669
13670                Discr := First_Discriminant (Typ);
13671                while Present (Discr) loop
13672                   if No (Discriminant_Default_Value (Discr)) then
13673                      Error_Msg_N
13674                        ("Unchecked_Union discriminant must have default value",
13675                         Discr);
13676                   end if;
13677
13678                   Next_Discriminant (Discr);
13679                end loop;
13680
13681                Tdef  := Type_Definition (Declaration_Node (Typ));
13682                Clist := Component_List (Tdef);
13683
13684                Comp := First (Component_Items (Clist));
13685                while Present (Comp) loop
13686                   Check_Component (Comp, Typ);
13687                   Next (Comp);
13688                end loop;
13689
13690                if No (Clist) or else No (Variant_Part (Clist)) then
13691                   Error_Msg_N
13692                     ("Unchecked_Union must have variant part",
13693                      Tdef);
13694                   return;
13695                end if;
13696
13697                Vpart := Variant_Part (Clist);
13698
13699                Variant := First (Variants (Vpart));
13700                while Present (Variant) loop
13701                   Check_Variant (Variant, Typ);
13702                   Next (Variant);
13703                end loop;
13704             end if;
13705
13706             Set_Is_Unchecked_Union  (Typ);
13707             Set_Convention (Typ, Convention_C);
13708             Set_Has_Unchecked_Union (Base_Type (Typ));
13709             Set_Is_Unchecked_Union  (Base_Type (Typ));
13710          end Unchecked_Union;
13711
13712          ------------------------
13713          -- Unimplemented_Unit --
13714          ------------------------
13715
13716          --  pragma Unimplemented_Unit;
13717
13718          --  Note: this only gives an error if we are generating code, or if
13719          --  we are in a generic library unit (where the pragma appears in the
13720          --  body, not in the spec).
13721
13722          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13723             Cunitent : constant Entity_Id :=
13724                          Cunit_Entity (Get_Source_Unit (Loc));
13725             Ent_Kind : constant Entity_Kind :=
13726                          Ekind (Cunitent);
13727
13728          begin
13729             GNAT_Pragma;
13730             Check_Arg_Count (0);
13731
13732             if Operating_Mode = Generate_Code
13733               or else Ent_Kind = E_Generic_Function
13734               or else Ent_Kind = E_Generic_Procedure
13735               or else Ent_Kind = E_Generic_Package
13736             then
13737                Get_Name_String (Chars (Cunitent));
13738                Set_Casing (Mixed_Case);
13739                Write_Str (Name_Buffer (1 .. Name_Len));
13740                Write_Str (" is not supported in this configuration");
13741                Write_Eol;
13742                raise Unrecoverable_Error;
13743             end if;
13744          end Unimplemented_Unit;
13745
13746          ------------------------
13747          -- Universal_Aliasing --
13748          ------------------------
13749
13750          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13751
13752          when Pragma_Universal_Aliasing => Universal_Alias : declare
13753             E_Id : Entity_Id;
13754
13755          begin
13756             GNAT_Pragma;
13757             Check_Arg_Count (1);
13758             Check_Optional_Identifier (Arg2, Name_Entity);
13759             Check_Arg_Is_Local_Name (Arg1);
13760             E_Id := Entity (Get_Pragma_Arg (Arg1));
13761
13762             if E_Id = Any_Type then
13763                return;
13764             elsif No (E_Id) or else not Is_Type (E_Id) then
13765                Error_Pragma_Arg ("pragma% requires type", Arg1);
13766             end if;
13767
13768             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13769          end Universal_Alias;
13770
13771          --------------------
13772          -- Universal_Data --
13773          --------------------
13774
13775          --  pragma Universal_Data [(library_unit_NAME)];
13776
13777          when Pragma_Universal_Data =>
13778             GNAT_Pragma;
13779
13780             --  If this is a configuration pragma, then set the universal
13781             --  addressing option, otherwise confirm that the pragma satisfies
13782             --  the requirements of library unit pragma placement and leave it
13783             --  to the GNAAMP back end to detect the pragma (avoids transitive
13784             --  setting of the option due to withed units).
13785
13786             if Is_Configuration_Pragma then
13787                Universal_Addressing_On_AAMP := True;
13788             else
13789                Check_Valid_Library_Unit_Pragma;
13790             end if;
13791
13792             if not AAMP_On_Target then
13793                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13794             end if;
13795
13796          ----------------
13797          -- Unmodified --
13798          ----------------
13799
13800          --  pragma Unmodified (local_Name {, local_Name});
13801
13802          when Pragma_Unmodified => Unmodified : declare
13803             Arg_Node : Node_Id;
13804             Arg_Expr : Node_Id;
13805             Arg_Ent  : Entity_Id;
13806
13807          begin
13808             GNAT_Pragma;
13809             Check_At_Least_N_Arguments (1);
13810
13811             --  Loop through arguments
13812
13813             Arg_Node := Arg1;
13814             while Present (Arg_Node) loop
13815                Check_No_Identifier (Arg_Node);
13816
13817                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13818                --  in fact generate reference, so that the entity will have a
13819                --  reference, which will inhibit any warnings about it not
13820                --  being referenced, and also properly show up in the ali file
13821                --  as a reference. But this reference is recorded before the
13822                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13823                --  generated for this reference.
13824
13825                Check_Arg_Is_Local_Name (Arg_Node);
13826                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13827
13828                if Is_Entity_Name (Arg_Expr) then
13829                   Arg_Ent := Entity (Arg_Expr);
13830
13831                   if not Is_Assignable (Arg_Ent) then
13832                      Error_Pragma_Arg
13833                        ("pragma% can only be applied to a variable",
13834                         Arg_Expr);
13835                   else
13836                      Set_Has_Pragma_Unmodified (Arg_Ent);
13837                   end if;
13838                end if;
13839
13840                Next (Arg_Node);
13841             end loop;
13842          end Unmodified;
13843
13844          ------------------
13845          -- Unreferenced --
13846          ------------------
13847
13848          --  pragma Unreferenced (local_Name {, local_Name});
13849
13850          --    or when used in a context clause:
13851
13852          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13853
13854          when Pragma_Unreferenced => Unreferenced : declare
13855             Arg_Node : Node_Id;
13856             Arg_Expr : Node_Id;
13857             Arg_Ent  : Entity_Id;
13858             Citem    : Node_Id;
13859
13860          begin
13861             GNAT_Pragma;
13862             Check_At_Least_N_Arguments (1);
13863
13864             --  Check case of appearing within context clause
13865
13866             if Is_In_Context_Clause then
13867
13868                --  The arguments must all be units mentioned in a with clause
13869                --  in the same context clause. Note we already checked (in
13870                --  Par.Prag) that the arguments are either identifiers or
13871                --  selected components.
13872
13873                Arg_Node := Arg1;
13874                while Present (Arg_Node) loop
13875                   Citem := First (List_Containing (N));
13876                   while Citem /= N loop
13877                      if Nkind (Citem) = N_With_Clause
13878                        and then
13879                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13880                      then
13881                         Set_Has_Pragma_Unreferenced
13882                           (Cunit_Entity
13883                              (Get_Source_Unit
13884                                 (Library_Unit (Citem))));
13885                         Set_Unit_Name
13886                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
13887                         exit;
13888                      end if;
13889
13890                      Next (Citem);
13891                   end loop;
13892
13893                   if Citem = N then
13894                      Error_Pragma_Arg
13895                        ("argument of pragma% is not with'ed unit", Arg_Node);
13896                   end if;
13897
13898                   Next (Arg_Node);
13899                end loop;
13900
13901             --  Case of not in list of context items
13902
13903             else
13904                Arg_Node := Arg1;
13905                while Present (Arg_Node) loop
13906                   Check_No_Identifier (Arg_Node);
13907
13908                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
13909                   --  will in fact generate reference, so that the entity will
13910                   --  have a reference, which will inhibit any warnings about
13911                   --  it not being referenced, and also properly show up in the
13912                   --  ali file as a reference. But this reference is recorded
13913                   --  before the Has_Pragma_Unreferenced flag is set, so that
13914                   --  no warning is generated for this reference.
13915
13916                   Check_Arg_Is_Local_Name (Arg_Node);
13917                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
13918
13919                   if Is_Entity_Name (Arg_Expr) then
13920                      Arg_Ent := Entity (Arg_Expr);
13921
13922                      --  If the entity is overloaded, the pragma applies to the
13923                      --  most recent overloading, as documented. In this case,
13924                      --  name resolution does not generate a reference, so it
13925                      --  must be done here explicitly.
13926
13927                      if Is_Overloaded (Arg_Expr) then
13928                         Generate_Reference (Arg_Ent, N);
13929                      end if;
13930
13931                      Set_Has_Pragma_Unreferenced (Arg_Ent);
13932                   end if;
13933
13934                   Next (Arg_Node);
13935                end loop;
13936             end if;
13937          end Unreferenced;
13938
13939          --------------------------
13940          -- Unreferenced_Objects --
13941          --------------------------
13942
13943          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13944
13945          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13946             Arg_Node : Node_Id;
13947             Arg_Expr : Node_Id;
13948
13949          begin
13950             GNAT_Pragma;
13951             Check_At_Least_N_Arguments (1);
13952
13953             Arg_Node := Arg1;
13954             while Present (Arg_Node) loop
13955                Check_No_Identifier (Arg_Node);
13956                Check_Arg_Is_Local_Name (Arg_Node);
13957                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13958
13959                if not Is_Entity_Name (Arg_Expr)
13960                  or else not Is_Type (Entity (Arg_Expr))
13961                then
13962                   Error_Pragma_Arg
13963                     ("argument for pragma% must be type or subtype", Arg_Node);
13964                end if;
13965
13966                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13967                Next (Arg_Node);
13968             end loop;
13969          end Unreferenced_Objects;
13970
13971          ------------------------------
13972          -- Unreserve_All_Interrupts --
13973          ------------------------------
13974
13975          --  pragma Unreserve_All_Interrupts;
13976
13977          when Pragma_Unreserve_All_Interrupts =>
13978             GNAT_Pragma;
13979             Check_Arg_Count (0);
13980
13981             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13982                Unreserve_All_Interrupts := True;
13983             end if;
13984
13985          ----------------
13986          -- Unsuppress --
13987          ----------------
13988
13989          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13990
13991          when Pragma_Unsuppress =>
13992             Ada_2005_Pragma;
13993             Process_Suppress_Unsuppress (False);
13994
13995          -------------------
13996          -- Use_VADS_Size --
13997          -------------------
13998
13999          --  pragma Use_VADS_Size;
14000
14001          when Pragma_Use_VADS_Size =>
14002             GNAT_Pragma;
14003             Check_Arg_Count (0);
14004             Check_Valid_Configuration_Pragma;
14005             Use_VADS_Size := True;
14006
14007          ---------------------
14008          -- Validity_Checks --
14009          ---------------------
14010
14011          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14012
14013          when Pragma_Validity_Checks => Validity_Checks : declare
14014             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
14015             S  : String_Id;
14016             C  : Char_Code;
14017
14018          begin
14019             GNAT_Pragma;
14020             Check_Arg_Count (1);
14021             Check_No_Identifiers;
14022
14023             if Nkind (A) = N_String_Literal then
14024                S   := Strval (A);
14025
14026                declare
14027                   Slen    : constant Natural := Natural (String_Length (S));
14028                   Options : String (1 .. Slen);
14029                   J       : Natural;
14030
14031                begin
14032                   J := 1;
14033                   loop
14034                      C := Get_String_Char (S, Int (J));
14035                      exit when not In_Character_Range (C);
14036                      Options (J) := Get_Character (C);
14037
14038                      if J = Slen then
14039                         Set_Validity_Check_Options (Options);
14040                         exit;
14041                      else
14042                         J := J + 1;
14043                      end if;
14044                   end loop;
14045                end;
14046
14047             elsif Nkind (A) = N_Identifier then
14048
14049                if Chars (A) = Name_All_Checks then
14050                   Set_Validity_Check_Options ("a");
14051
14052                elsif Chars (A) = Name_On then
14053                   Validity_Checks_On := True;
14054
14055                elsif Chars (A) = Name_Off then
14056                   Validity_Checks_On := False;
14057
14058                end if;
14059             end if;
14060          end Validity_Checks;
14061
14062          --------------
14063          -- Volatile --
14064          --------------
14065
14066          --  pragma Volatile (LOCAL_NAME);
14067
14068          when Pragma_Volatile =>
14069             Process_Atomic_Shared_Volatile;
14070
14071          -------------------------
14072          -- Volatile_Components --
14073          -------------------------
14074
14075          --  pragma Volatile_Components (array_LOCAL_NAME);
14076
14077          --  Volatile is handled by the same circuit as Atomic_Components
14078
14079          --------------
14080          -- Warnings --
14081          --------------
14082
14083          --  pragma Warnings (On | Off);
14084          --  pragma Warnings (On | Off, LOCAL_NAME);
14085          --  pragma Warnings (static_string_EXPRESSION);
14086          --  pragma Warnings (On | Off, STRING_LITERAL);
14087
14088          when Pragma_Warnings => Warnings : begin
14089             GNAT_Pragma;
14090             Check_At_Least_N_Arguments (1);
14091             Check_No_Identifiers;
14092
14093             --  If debug flag -gnatd.i is set, pragma is ignored
14094
14095             if Debug_Flag_Dot_I then
14096                return;
14097             end if;
14098
14099             --  Process various forms of the pragma
14100
14101             declare
14102                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14103
14104             begin
14105                --  One argument case
14106
14107                if Arg_Count = 1 then
14108
14109                   --  On/Off one argument case was processed by parser
14110
14111                   if Nkind (Argx) = N_Identifier
14112                     and then
14113                       (Chars (Argx) = Name_On
14114                          or else
14115                        Chars (Argx) = Name_Off)
14116                   then
14117                      null;
14118
14119                   --  One argument case must be ON/OFF or static string expr
14120
14121                   elsif not Is_Static_String_Expression (Arg1) then
14122                      Error_Pragma_Arg
14123                        ("argument of pragma% must be On/Off or " &
14124                         "static string expression", Arg1);
14125
14126                   --  One argument string expression case
14127
14128                   else
14129                      declare
14130                         Lit : constant Node_Id   := Expr_Value_S (Argx);
14131                         Str : constant String_Id := Strval (Lit);
14132                         Len : constant Nat       := String_Length (Str);
14133                         C   : Char_Code;
14134                         J   : Nat;
14135                         OK  : Boolean;
14136                         Chr : Character;
14137
14138                      begin
14139                         J := 1;
14140                         while J <= Len loop
14141                            C := Get_String_Char (Str, J);
14142                            OK := In_Character_Range (C);
14143
14144                            if OK then
14145                               Chr := Get_Character (C);
14146
14147                               --  Dot case
14148
14149                               if J < Len and then Chr = '.' then
14150                                  J := J + 1;
14151                                  C := Get_String_Char (Str, J);
14152                                  Chr := Get_Character (C);
14153
14154                                  if not Set_Dot_Warning_Switch (Chr) then
14155                                     Error_Pragma_Arg
14156                                       ("invalid warning switch character " &
14157                                        '.' & Chr, Arg1);
14158                                  end if;
14159
14160                               --  Non-Dot case
14161
14162                               else
14163                                  OK := Set_Warning_Switch (Chr);
14164                               end if;
14165                            end if;
14166
14167                            if not OK then
14168                               Error_Pragma_Arg
14169                                 ("invalid warning switch character " & Chr,
14170                                  Arg1);
14171                            end if;
14172
14173                            J := J + 1;
14174                         end loop;
14175                      end;
14176                   end if;
14177
14178                   --  Two or more arguments (must be two)
14179
14180                else
14181                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14182                   Check_At_Most_N_Arguments (2);
14183
14184                   declare
14185                      E_Id : Node_Id;
14186                      E    : Entity_Id;
14187                      Err  : Boolean;
14188
14189                   begin
14190                      E_Id := Get_Pragma_Arg (Arg2);
14191                      Analyze (E_Id);
14192
14193                      --  In the expansion of an inlined body, a reference to
14194                      --  the formal may be wrapped in a conversion if the
14195                      --  actual is a conversion. Retrieve the real entity name.
14196
14197                      if (In_Instance_Body
14198                          or else In_Inlined_Body)
14199                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14200                      then
14201                         E_Id := Expression (E_Id);
14202                      end if;
14203
14204                      --  Entity name case
14205
14206                      if Is_Entity_Name (E_Id) then
14207                         E := Entity (E_Id);
14208
14209                         if E = Any_Id then
14210                            return;
14211                         else
14212                            loop
14213                               Set_Warnings_Off
14214                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14215                                                               Name_Off));
14216
14217                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14218                                 and then Warn_On_Warnings_Off
14219                               then
14220                                  Warnings_Off_Pragmas.Append ((N, E));
14221                               end if;
14222
14223                               if Is_Enumeration_Type (E) then
14224                                  declare
14225                                     Lit : Entity_Id;
14226                                  begin
14227                                     Lit := First_Literal (E);
14228                                     while Present (Lit) loop
14229                                        Set_Warnings_Off (Lit);
14230                                        Next_Literal (Lit);
14231                                     end loop;
14232                                  end;
14233                               end if;
14234
14235                               exit when No (Homonym (E));
14236                               E := Homonym (E);
14237                            end loop;
14238                         end if;
14239
14240                      --  Error if not entity or static string literal case
14241
14242                      elsif not Is_Static_String_Expression (Arg2) then
14243                         Error_Pragma_Arg
14244                           ("second argument of pragma% must be entity " &
14245                            "name or static string expression", Arg2);
14246
14247                      --  String literal case
14248
14249                      else
14250                         String_To_Name_Buffer
14251                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14252
14253                         --  Note on configuration pragma case: If this is a
14254                         --  configuration pragma, then for an OFF pragma, we
14255                         --  just set Config True in the call, which is all
14256                         --  that needs to be done. For the case of ON, this
14257                         --  is normally an error, unless it is canceling the
14258                         --  effect of a previous OFF pragma in the same file.
14259                         --  In any other case, an error will be signalled (ON
14260                         --  with no matching OFF).
14261
14262                         if Chars (Argx) = Name_Off then
14263                            Set_Specific_Warning_Off
14264                              (Loc, Name_Buffer (1 .. Name_Len),
14265                               Config => Is_Configuration_Pragma);
14266
14267                         elsif Chars (Argx) = Name_On then
14268                            Set_Specific_Warning_On
14269                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14270
14271                            if Err then
14272                               Error_Msg
14273                                 ("?pragma Warnings On with no " &
14274                                  "matching Warnings Off",
14275                                  Loc);
14276                            end if;
14277                         end if;
14278                      end if;
14279                   end;
14280                end if;
14281             end;
14282          end Warnings;
14283
14284          -------------------
14285          -- Weak_External --
14286          -------------------
14287
14288          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14289
14290          when Pragma_Weak_External => Weak_External : declare
14291             Ent : Entity_Id;
14292
14293          begin
14294             GNAT_Pragma;
14295             Check_Arg_Count (1);
14296             Check_Optional_Identifier (Arg1, Name_Entity);
14297             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14298             Ent := Entity (Get_Pragma_Arg (Arg1));
14299
14300             if Rep_Item_Too_Early (Ent, N) then
14301                return;
14302             else
14303                Ent := Underlying_Type (Ent);
14304             end if;
14305
14306             --  The only processing required is to link this item on to the
14307             --  list of rep items for the given entity. This is accomplished
14308             --  by the call to Rep_Item_Too_Late (when no error is detected
14309             --  and False is returned).
14310
14311             if Rep_Item_Too_Late (Ent, N) then
14312                return;
14313             else
14314                Set_Has_Gigi_Rep_Item (Ent);
14315             end if;
14316          end Weak_External;
14317
14318          -----------------------------
14319          -- Wide_Character_Encoding --
14320          -----------------------------
14321
14322          --  pragma Wide_Character_Encoding (IDENTIFIER);
14323
14324          when Pragma_Wide_Character_Encoding =>
14325             GNAT_Pragma;
14326
14327             --  Nothing to do, handled in parser. Note that we do not enforce
14328             --  configuration pragma placement, this pragma can appear at any
14329             --  place in the source, allowing mixed encodings within a single
14330             --  source program.
14331
14332             null;
14333
14334          --------------------
14335          -- Unknown_Pragma --
14336          --------------------
14337
14338          --  Should be impossible, since the case of an unknown pragma is
14339          --  separately processed before the case statement is entered.
14340
14341          when Unknown_Pragma =>
14342             raise Program_Error;
14343       end case;
14344
14345       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14346       --  until AI is formally approved.
14347
14348       --  Check_Order_Dependence;
14349
14350    exception
14351       when Pragma_Exit => null;
14352    end Analyze_Pragma;
14353
14354    -----------------------------
14355    -- Analyze_TC_In_Decl_Part --
14356    -----------------------------
14357
14358    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14359    begin
14360       --  Install formals and push subprogram spec onto scope stack so that we
14361       --  can see the formals from the pragma.
14362
14363       Install_Formals (S);
14364       Push_Scope (S);
14365
14366       --  Preanalyze the boolean expressions, we treat these as spec
14367       --  expressions (i.e. similar to a default expression).
14368
14369       Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14370                           Get_Ensures_From_Test_Case_Pragma (N));
14371
14372       --  Remove the subprogram from the scope stack now that the pre-analysis
14373       --  of the expressions in the test-case is done.
14374
14375       End_Scope;
14376    end Analyze_TC_In_Decl_Part;
14377
14378    --------------------
14379    -- Check_Disabled --
14380    --------------------
14381
14382    function Check_Disabled (Nam : Name_Id) return Boolean is
14383       PP : Node_Id;
14384
14385    begin
14386       --  Loop through entries in check policy list
14387
14388       PP := Opt.Check_Policy_List;
14389       loop
14390          --  If there are no specific entries that matched, then nothing is
14391          --  disabled, so return False.
14392
14393          if No (PP) then
14394             return False;
14395
14396          --  Here we have an entry see if it matches
14397
14398          else
14399             declare
14400                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14401             begin
14402                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14403                   return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14404                else
14405                   PP := Next_Pragma (PP);
14406                end if;
14407             end;
14408          end if;
14409       end loop;
14410    end Check_Disabled;
14411
14412    -------------------
14413    -- Check_Enabled --
14414    -------------------
14415
14416    function Check_Enabled (Nam : Name_Id) return Boolean is
14417       PP : Node_Id;
14418
14419    begin
14420       --  Loop through entries in check policy list
14421
14422       PP := Opt.Check_Policy_List;
14423       loop
14424          --  If there are no specific entries that matched, then we let the
14425          --  setting of assertions govern. Note that this provides the needed
14426          --  compatibility with the RM for the cases of assertion, invariant,
14427          --  precondition, predicate, and postcondition.
14428
14429          if No (PP) then
14430             return Assertions_Enabled;
14431
14432          --  Here we have an entry see if it matches
14433
14434          else
14435             declare
14436                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14437
14438             begin
14439                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14440                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14441                      when Name_On | Name_Check =>
14442                         return True;
14443                      when Name_Off | Name_Ignore =>
14444                         return False;
14445                      when others =>
14446                         raise Program_Error;
14447                   end case;
14448
14449                else
14450                   PP := Next_Pragma (PP);
14451                end if;
14452             end;
14453          end if;
14454       end loop;
14455    end Check_Enabled;
14456
14457    ---------------------------------
14458    -- Delay_Config_Pragma_Analyze --
14459    ---------------------------------
14460
14461    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14462    begin
14463       return Pragma_Name (N) = Name_Interrupt_State
14464                or else
14465              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14466    end Delay_Config_Pragma_Analyze;
14467
14468    -------------------------
14469    -- Get_Base_Subprogram --
14470    -------------------------
14471
14472    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14473       Result : Entity_Id;
14474
14475    begin
14476       --  Follow subprogram renaming chain
14477
14478       Result := Def_Id;
14479       while Is_Subprogram (Result)
14480         and then
14481           Nkind (Parent (Declaration_Node (Result))) =
14482                                          N_Subprogram_Renaming_Declaration
14483         and then Present (Alias (Result))
14484       loop
14485          Result := Alias (Result);
14486       end loop;
14487
14488       return Result;
14489    end Get_Base_Subprogram;
14490
14491    ----------------
14492    -- Initialize --
14493    ----------------
14494
14495    procedure Initialize is
14496    begin
14497       Externals.Init;
14498    end Initialize;
14499
14500    -----------------------------
14501    -- Is_Config_Static_String --
14502    -----------------------------
14503
14504    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14505
14506       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14507       --  This is an internal recursive function that is just like the outer
14508       --  function except that it adds the string to the name buffer rather
14509       --  than placing the string in the name buffer.
14510
14511       ------------------------------
14512       -- Add_Config_Static_String --
14513       ------------------------------
14514
14515       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14516          N : Node_Id;
14517          C : Char_Code;
14518
14519       begin
14520          N := Arg;
14521
14522          if Nkind (N) = N_Op_Concat then
14523             if Add_Config_Static_String (Left_Opnd (N)) then
14524                N := Right_Opnd (N);
14525             else
14526                return False;
14527             end if;
14528          end if;
14529
14530          if Nkind (N) /= N_String_Literal then
14531             Error_Msg_N ("string literal expected for pragma argument", N);
14532             return False;
14533
14534          else
14535             for J in 1 .. String_Length (Strval (N)) loop
14536                C := Get_String_Char (Strval (N), J);
14537
14538                if not In_Character_Range (C) then
14539                   Error_Msg
14540                     ("string literal contains invalid wide character",
14541                      Sloc (N) + 1 + Source_Ptr (J));
14542                   return False;
14543                end if;
14544
14545                Add_Char_To_Name_Buffer (Get_Character (C));
14546             end loop;
14547          end if;
14548
14549          return True;
14550       end Add_Config_Static_String;
14551
14552    --  Start of processing for Is_Config_Static_String
14553
14554    begin
14555
14556       Name_Len := 0;
14557       return Add_Config_Static_String (Arg);
14558    end Is_Config_Static_String;
14559
14560    -----------------------------------------
14561    -- Is_Non_Significant_Pragma_Reference --
14562    -----------------------------------------
14563
14564    --  This function makes use of the following static table which indicates
14565    --  whether a given pragma is significant.
14566
14567    --  -1  indicates that references in any argument position are significant
14568    --  0   indicates that appearance in any argument is not significant
14569    --  +n  indicates that appearance as argument n is significant, but all
14570    --      other arguments are not significant
14571    --  99  special processing required (e.g. for pragma Check)
14572
14573    Sig_Flags : constant array (Pragma_Id) of Int :=
14574      (Pragma_AST_Entry                     => -1,
14575       Pragma_Abort_Defer                   => -1,
14576       Pragma_Ada_83                        => -1,
14577       Pragma_Ada_95                        => -1,
14578       Pragma_Ada_05                        => -1,
14579       Pragma_Ada_2005                      => -1,
14580       Pragma_Ada_12                        => -1,
14581       Pragma_Ada_2012                      => -1,
14582       Pragma_All_Calls_Remote              => -1,
14583       Pragma_Annotate                      => -1,
14584       Pragma_Assert                        => -1,
14585       Pragma_Assertion_Policy              =>  0,
14586       Pragma_Assume_No_Invalid_Values      =>  0,
14587       Pragma_Asynchronous                  => -1,
14588       Pragma_Atomic                        =>  0,
14589       Pragma_Atomic_Components             =>  0,
14590       Pragma_Attach_Handler                => -1,
14591       Pragma_Check                         => 99,
14592       Pragma_Check_Name                    =>  0,
14593       Pragma_Check_Policy                  =>  0,
14594       Pragma_CIL_Constructor               => -1,
14595       Pragma_CPP_Class                     =>  0,
14596       Pragma_CPP_Constructor               =>  0,
14597       Pragma_CPP_Virtual                   =>  0,
14598       Pragma_CPP_Vtable                    =>  0,
14599       Pragma_CPU                           => -1,
14600       Pragma_C_Pass_By_Copy                =>  0,
14601       Pragma_Comment                       =>  0,
14602       Pragma_Common_Object                 => -1,
14603       Pragma_Compile_Time_Error            => -1,
14604       Pragma_Compile_Time_Warning          => -1,
14605       Pragma_Compiler_Unit                 =>  0,
14606       Pragma_Complete_Representation       =>  0,
14607       Pragma_Complex_Representation        =>  0,
14608       Pragma_Component_Alignment           => -1,
14609       Pragma_Controlled                    =>  0,
14610       Pragma_Convention                    =>  0,
14611       Pragma_Convention_Identifier         =>  0,
14612       Pragma_Debug                         => -1,
14613       Pragma_Debug_Policy                  =>  0,
14614       Pragma_Detect_Blocking               => -1,
14615       Pragma_Default_Storage_Pool          => -1,
14616       Pragma_Dimension                     => -1,
14617       Pragma_Discard_Names                 =>  0,
14618       Pragma_Dispatching_Domain            => -1,
14619       Pragma_Elaborate                     => -1,
14620       Pragma_Elaborate_All                 => -1,
14621       Pragma_Elaborate_Body                => -1,
14622       Pragma_Elaboration_Checks            => -1,
14623       Pragma_Eliminate                     => -1,
14624       Pragma_Export                        => -1,
14625       Pragma_Export_Exception              => -1,
14626       Pragma_Export_Function               => -1,
14627       Pragma_Export_Object                 => -1,
14628       Pragma_Export_Procedure              => -1,
14629       Pragma_Export_Value                  => -1,
14630       Pragma_Export_Valued_Procedure       => -1,
14631       Pragma_Extend_System                 => -1,
14632       Pragma_Extensions_Allowed            => -1,
14633       Pragma_External                      => -1,
14634       Pragma_Favor_Top_Level               => -1,
14635       Pragma_External_Name_Casing          => -1,
14636       Pragma_Fast_Math                     => -1,
14637       Pragma_Finalize_Storage_Only         =>  0,
14638       Pragma_Float_Representation          =>  0,
14639       Pragma_Ident                         => -1,
14640       Pragma_Implemented                   => -1,
14641       Pragma_Implicit_Packing              =>  0,
14642       Pragma_Import                        => +2,
14643       Pragma_Import_Exception              =>  0,
14644       Pragma_Import_Function               =>  0,
14645       Pragma_Import_Object                 =>  0,
14646       Pragma_Import_Procedure              =>  0,
14647       Pragma_Import_Valued_Procedure       =>  0,
14648       Pragma_Independent                   =>  0,
14649       Pragma_Independent_Components        =>  0,
14650       Pragma_Initialize_Scalars            => -1,
14651       Pragma_Inline                        =>  0,
14652       Pragma_Inline_Always                 =>  0,
14653       Pragma_Inline_Generic                =>  0,
14654       Pragma_Inspection_Point              => -1,
14655       Pragma_Interface                     => +2,
14656       Pragma_Interface_Name                => +2,
14657       Pragma_Interrupt_Handler             => -1,
14658       Pragma_Interrupt_Priority            => -1,
14659       Pragma_Interrupt_State               => -1,
14660       Pragma_Invariant                     => -1,
14661       Pragma_Java_Constructor              => -1,
14662       Pragma_Java_Interface                => -1,
14663       Pragma_Keep_Names                    =>  0,
14664       Pragma_License                       => -1,
14665       Pragma_Link_With                     => -1,
14666       Pragma_Linker_Alias                  => -1,
14667       Pragma_Linker_Constructor            => -1,
14668       Pragma_Linker_Destructor             => -1,
14669       Pragma_Linker_Options                => -1,
14670       Pragma_Linker_Section                => -1,
14671       Pragma_List                          => -1,
14672       Pragma_Locking_Policy                => -1,
14673       Pragma_Long_Float                    => -1,
14674       Pragma_Machine_Attribute             => -1,
14675       Pragma_Main                          => -1,
14676       Pragma_Main_Storage                  => -1,
14677       Pragma_Memory_Size                   => -1,
14678       Pragma_No_Return                     =>  0,
14679       Pragma_No_Body                       =>  0,
14680       Pragma_No_Run_Time                   => -1,
14681       Pragma_No_Strict_Aliasing            => -1,
14682       Pragma_Normalize_Scalars             => -1,
14683       Pragma_Obsolescent                   =>  0,
14684       Pragma_Optimize                      => -1,
14685       Pragma_Optimize_Alignment            => -1,
14686       Pragma_Ordered                       =>  0,
14687       Pragma_Pack                          =>  0,
14688       Pragma_Page                          => -1,
14689       Pragma_Passive                       => -1,
14690       Pragma_Preelaborable_Initialization  => -1,
14691       Pragma_Polling                       => -1,
14692       Pragma_Persistent_BSS                =>  0,
14693       Pragma_Postcondition                 => -1,
14694       Pragma_Precondition                  => -1,
14695       Pragma_Predicate                     => -1,
14696       Pragma_Preelaborate                  => -1,
14697       Pragma_Preelaborate_05               => -1,
14698       Pragma_Priority                      => -1,
14699       Pragma_Priority_Specific_Dispatching => -1,
14700       Pragma_Profile                       =>  0,
14701       Pragma_Profile_Warnings              =>  0,
14702       Pragma_Propagate_Exceptions          => -1,
14703       Pragma_Psect_Object                  => -1,
14704       Pragma_Pure                          => -1,
14705       Pragma_Pure_05                       => -1,
14706       Pragma_Pure_Function                 => -1,
14707       Pragma_Queuing_Policy                => -1,
14708       Pragma_Ravenscar                     => -1,
14709       Pragma_Relative_Deadline             => -1,
14710       Pragma_Remote_Call_Interface         => -1,
14711       Pragma_Remote_Types                  => -1,
14712       Pragma_Restricted_Run_Time           => -1,
14713       Pragma_Restriction_Warnings          => -1,
14714       Pragma_Restrictions                  => -1,
14715       Pragma_Reviewable                    => -1,
14716       Pragma_Short_Circuit_And_Or          => -1,
14717       Pragma_Share_Generic                 => -1,
14718       Pragma_Shared                        => -1,
14719       Pragma_Shared_Passive                => -1,
14720       Pragma_Short_Descriptors             =>  0,
14721       Pragma_Source_File_Name              => -1,
14722       Pragma_Source_File_Name_Project      => -1,
14723       Pragma_Source_Reference              => -1,
14724       Pragma_Storage_Size                  => -1,
14725       Pragma_Storage_Unit                  => -1,
14726       Pragma_Static_Elaboration_Desired    => -1,
14727       Pragma_Stream_Convert                => -1,
14728       Pragma_Style_Checks                  => -1,
14729       Pragma_Subtitle                      => -1,
14730       Pragma_Suppress                      =>  0,
14731       Pragma_Suppress_Exception_Locations  =>  0,
14732       Pragma_Suppress_All                  => -1,
14733       Pragma_Suppress_Debug_Info           =>  0,
14734       Pragma_Suppress_Initialization       =>  0,
14735       Pragma_System_Name                   => -1,
14736       Pragma_Task_Dispatching_Policy       => -1,
14737       Pragma_Task_Info                     => -1,
14738       Pragma_Task_Name                     => -1,
14739       Pragma_Task_Storage                  =>  0,
14740       Pragma_Test_Case                     => -1,
14741       Pragma_Thread_Local_Storage          =>  0,
14742       Pragma_Time_Slice                    => -1,
14743       Pragma_Title                         => -1,
14744       Pragma_Unchecked_Union               =>  0,
14745       Pragma_Unimplemented_Unit            => -1,
14746       Pragma_Universal_Aliasing            => -1,
14747       Pragma_Universal_Data                => -1,
14748       Pragma_Unmodified                    => -1,
14749       Pragma_Unreferenced                  => -1,
14750       Pragma_Unreferenced_Objects          => -1,
14751       Pragma_Unreserve_All_Interrupts      => -1,
14752       Pragma_Unsuppress                    =>  0,
14753       Pragma_Use_VADS_Size                 => -1,
14754       Pragma_Validity_Checks               => -1,
14755       Pragma_Volatile                      =>  0,
14756       Pragma_Volatile_Components           =>  0,
14757       Pragma_Warnings                      => -1,
14758       Pragma_Weak_External                 => -1,
14759       Pragma_Wide_Character_Encoding       =>  0,
14760       Unknown_Pragma                       =>  0);
14761
14762    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14763       Id : Pragma_Id;
14764       P  : Node_Id;
14765       C  : Int;
14766       A  : Node_Id;
14767
14768    begin
14769       P := Parent (N);
14770
14771       if Nkind (P) /= N_Pragma_Argument_Association then
14772          return False;
14773
14774       else
14775          Id := Get_Pragma_Id (Parent (P));
14776          C := Sig_Flags (Id);
14777
14778          case C is
14779             when -1 =>
14780                return False;
14781
14782             when 0 =>
14783                return True;
14784
14785             when 99 =>
14786                case Id is
14787
14788                   --  For pragma Check, the first argument is not significant,
14789                   --  the second and the third (if present) arguments are
14790                   --  significant.
14791
14792                   when Pragma_Check =>
14793                      return
14794                        P = First (Pragma_Argument_Associations (Parent (P)));
14795
14796                   when others =>
14797                      raise Program_Error;
14798                end case;
14799
14800             when others =>
14801                A := First (Pragma_Argument_Associations (Parent (P)));
14802                for J in 1 .. C - 1 loop
14803                   if No (A) then
14804                      return False;
14805                   end if;
14806
14807                   Next (A);
14808                end loop;
14809
14810                return A = P; -- is this wrong way round ???
14811          end case;
14812       end if;
14813    end Is_Non_Significant_Pragma_Reference;
14814
14815    ------------------------------
14816    -- Is_Pragma_String_Literal --
14817    ------------------------------
14818
14819    --  This function returns true if the corresponding pragma argument is a
14820    --  static string expression. These are the only cases in which string
14821    --  literals can appear as pragma arguments. We also allow a string literal
14822    --  as the first argument to pragma Assert (although it will of course
14823    --  always generate a type error).
14824
14825    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14826       Pragn : constant Node_Id := Parent (Par);
14827       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14828       Pname : constant Name_Id := Pragma_Name (Pragn);
14829       Argn  : Natural;
14830       N     : Node_Id;
14831
14832    begin
14833       Argn := 1;
14834       N := First (Assoc);
14835       loop
14836          exit when N = Par;
14837          Argn := Argn + 1;
14838          Next (N);
14839       end loop;
14840
14841       if Pname = Name_Assert then
14842          return True;
14843
14844       elsif Pname = Name_Export then
14845          return Argn > 2;
14846
14847       elsif Pname = Name_Ident then
14848          return Argn = 1;
14849
14850       elsif Pname = Name_Import then
14851          return Argn > 2;
14852
14853       elsif Pname = Name_Interface_Name then
14854          return Argn > 1;
14855
14856       elsif Pname = Name_Linker_Alias then
14857          return Argn = 2;
14858
14859       elsif Pname = Name_Linker_Section then
14860          return Argn = 2;
14861
14862       elsif Pname = Name_Machine_Attribute then
14863          return Argn = 2;
14864
14865       elsif Pname = Name_Source_File_Name then
14866          return True;
14867
14868       elsif Pname = Name_Source_Reference then
14869          return Argn = 2;
14870
14871       elsif Pname = Name_Title then
14872          return True;
14873
14874       elsif Pname = Name_Subtitle then
14875          return True;
14876
14877       else
14878          return False;
14879       end if;
14880    end Is_Pragma_String_Literal;
14881
14882    ------------------------
14883    -- Preanalyze_TC_Args --
14884    ------------------------
14885
14886    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14887    begin
14888       --  Preanalyze the boolean expressions, we treat these as spec
14889       --  expressions (i.e. similar to a default expression).
14890
14891       if Present (Arg_Req) then
14892          Preanalyze_Spec_Expression
14893            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14894       end if;
14895
14896       if Present (Arg_Ens) then
14897          Preanalyze_Spec_Expression
14898            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14899       end if;
14900    end Preanalyze_TC_Args;
14901
14902    --------------------------------------
14903    -- Process_Compilation_Unit_Pragmas --
14904    --------------------------------------
14905
14906    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14907    begin
14908       --  A special check for pragma Suppress_All, a very strange DEC pragma,
14909       --  strange because it comes at the end of the unit. Rational has the
14910       --  same name for a pragma, but treats it as a program unit pragma, In
14911       --  GNAT we just decide to allow it anywhere at all. If it appeared then
14912       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
14913       --  node, and we insert a pragma Suppress (All_Checks) at the start of
14914       --  the context clause to ensure the correct processing.
14915
14916       if Has_Pragma_Suppress_All (N) then
14917          Prepend_To (Context_Items (N),
14918            Make_Pragma (Sloc (N),
14919              Chars                        => Name_Suppress,
14920              Pragma_Argument_Associations => New_List (
14921                Make_Pragma_Argument_Association (Sloc (N),
14922                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14923       end if;
14924
14925       --  Nothing else to do at the current time!
14926
14927    end Process_Compilation_Unit_Pragmas;
14928
14929    --------
14930    -- rv --
14931    --------
14932
14933    procedure rv is
14934    begin
14935       null;
14936    end rv;
14937
14938    --------------------------------
14939    -- Set_Encoded_Interface_Name --
14940    --------------------------------
14941
14942    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14943       Str : constant String_Id := Strval (S);
14944       Len : constant Int       := String_Length (Str);
14945       CC  : Char_Code;
14946       C   : Character;
14947       J   : Int;
14948
14949       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14950
14951       procedure Encode;
14952       --  Stores encoded value of character code CC. The encoding we use an
14953       --  underscore followed by four lower case hex digits.
14954
14955       ------------
14956       -- Encode --
14957       ------------
14958
14959       procedure Encode is
14960       begin
14961          Store_String_Char (Get_Char_Code ('_'));
14962          Store_String_Char
14963            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14964          Store_String_Char
14965            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14966          Store_String_Char
14967            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14968          Store_String_Char
14969            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14970       end Encode;
14971
14972    --  Start of processing for Set_Encoded_Interface_Name
14973
14974    begin
14975       --  If first character is asterisk, this is a link name, and we leave it
14976       --  completely unmodified. We also ignore null strings (the latter case
14977       --  happens only in error cases) and no encoding should occur for Java or
14978       --  AAMP interface names.
14979
14980       if Len = 0
14981         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14982         or else VM_Target /= No_VM
14983         or else AAMP_On_Target
14984       then
14985          Set_Interface_Name (E, S);
14986
14987       else
14988          J := 1;
14989          loop
14990             CC := Get_String_Char (Str, J);
14991
14992             exit when not In_Character_Range (CC);
14993
14994             C := Get_Character (CC);
14995
14996             exit when C /= '_' and then C /= '$'
14997               and then C not in '0' .. '9'
14998               and then C not in 'a' .. 'z'
14999               and then C not in 'A' .. 'Z';
15000
15001             if J = Len then
15002                Set_Interface_Name (E, S);
15003                return;
15004
15005             else
15006                J := J + 1;
15007             end if;
15008          end loop;
15009
15010          --  Here we need to encode. The encoding we use as follows:
15011          --     three underscores  + four hex digits (lower case)
15012
15013          Start_String;
15014
15015          for J in 1 .. String_Length (Str) loop
15016             CC := Get_String_Char (Str, J);
15017
15018             if not In_Character_Range (CC) then
15019                Encode;
15020             else
15021                C := Get_Character (CC);
15022
15023                if C = '_' or else C = '$'
15024                  or else C in '0' .. '9'
15025                  or else C in 'a' .. 'z'
15026                  or else C in 'A' .. 'Z'
15027                then
15028                   Store_String_Char (CC);
15029                else
15030                   Encode;
15031                end if;
15032             end if;
15033          end loop;
15034
15035          Set_Interface_Name (E,
15036            Make_String_Literal (Sloc (S),
15037              Strval => End_String));
15038       end if;
15039    end Set_Encoded_Interface_Name;
15040
15041    -------------------
15042    -- Set_Unit_Name --
15043    -------------------
15044
15045    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15046       Pref : Node_Id;
15047       Scop : Entity_Id;
15048
15049    begin
15050       if Nkind (N) = N_Identifier
15051         and then Nkind (With_Item) = N_Identifier
15052       then
15053          Set_Entity (N, Entity (With_Item));
15054
15055       elsif Nkind (N) = N_Selected_Component then
15056          Change_Selected_Component_To_Expanded_Name (N);
15057          Set_Entity (N, Entity (With_Item));
15058          Set_Entity (Selector_Name (N), Entity (N));
15059
15060          Pref := Prefix (N);
15061          Scop := Scope (Entity (N));
15062          while Nkind (Pref) = N_Selected_Component loop
15063             Change_Selected_Component_To_Expanded_Name (Pref);
15064             Set_Entity (Selector_Name (Pref), Scop);
15065             Set_Entity (Pref, Scop);
15066             Pref := Prefix (Pref);
15067             Scop := Scope (Scop);
15068          end loop;
15069
15070          Set_Entity (Pref, Scop);
15071       end if;
15072    end Set_Unit_Name;
15073
15074 end Sem_Prag;