OSDN Git Service

2011-09-06 Ed Schonberg <schonberg@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 System.Case_Util;
33
34 with Atree;            use Atree;
35 with Casing;           use Casing;
36 with Checks;           use Checks;
37 with Csets;            use Csets;
38 with Debug;            use Debug;
39 with Einfo;            use Einfo;
40 with Elists;           use Elists;
41 with Errout;           use Errout;
42 with Exp_Dist;         use Exp_Dist;
43 with Exp_Util;         use Exp_Util;
44 with Freeze;           use Freeze;
45 with Lib;              use Lib;
46 with Lib.Writ;         use Lib.Writ;
47 with Lib.Xref;         use Lib.Xref;
48 with Namet.Sp;         use Namet.Sp;
49 with Nlists;           use Nlists;
50 with Nmake;            use Nmake;
51 with Opt;              use Opt;
52 with Output;           use Output;
53 with Par_SCO;          use Par_SCO;
54 with Restrict;         use Restrict;
55 with Rident;           use Rident;
56 with Rtsfind;          use Rtsfind;
57 with Sem;              use Sem;
58 with Sem_Aux;          use Sem_Aux;
59 with Sem_Ch3;          use Sem_Ch3;
60 with Sem_Ch6;          use Sem_Ch6;
61 with Sem_Ch8;          use Sem_Ch8;
62 with Sem_Ch12;         use Sem_Ch12;
63 with Sem_Ch13;         use Sem_Ch13;
64 with Sem_Disp;         use Sem_Disp;
65 with Sem_Dist;         use Sem_Dist;
66 with Sem_Elim;         use Sem_Elim;
67 with Sem_Eval;         use Sem_Eval;
68 with Sem_Intr;         use Sem_Intr;
69 with Sem_Mech;         use Sem_Mech;
70 with Sem_Res;          use Sem_Res;
71 with Sem_Type;         use Sem_Type;
72 with Sem_Util;         use Sem_Util;
73 with Sem_VFpt;         use Sem_VFpt;
74 with Sem_Warn;         use Sem_Warn;
75 with Stand;            use Stand;
76 with Sinfo;            use Sinfo;
77 with Sinfo.CN;         use Sinfo.CN;
78 with Sinput;           use Sinput;
79 with Snames;           use Snames;
80 with Stringt;          use Stringt;
81 with Stylesw;          use Stylesw;
82 with Table;
83 with Targparm;         use Targparm;
84 with Tbuild;           use Tbuild;
85 with Ttypes;
86 with Uintp;            use Uintp;
87 with Uname;            use Uname;
88 with Urealp;           use Urealp;
89 with Validsw;          use Validsw;
90 with Warnsw;           use Warnsw;
91
92 package body Sem_Prag is
93
94    ----------------------------------------------
95    -- Common Handling of Import-Export Pragmas --
96    ----------------------------------------------
97
98    --  In the following section, a number of Import_xxx and Export_xxx pragmas
99    --  are defined by GNAT. These are compatible with the DEC pragmas of the
100    --  same name, and all have the following common form and processing:
101
102    --  pragma Export_xxx
103    --        [Internal                 =>] LOCAL_NAME
104    --     [, [External                 =>] EXTERNAL_SYMBOL]
105    --     [, other optional parameters   ]);
106
107    --  pragma Import_xxx
108    --        [Internal                 =>] LOCAL_NAME
109    --     [, [External                 =>] EXTERNAL_SYMBOL]
110    --     [, other optional parameters   ]);
111
112    --   EXTERNAL_SYMBOL ::=
113    --     IDENTIFIER
114    --   | static_string_EXPRESSION
115
116    --  The internal LOCAL_NAME designates the entity that is imported or
117    --  exported, and must refer to an entity in the current declarative
118    --  part (as required by the rules for LOCAL_NAME).
119
120    --  The external linker name is designated by the External parameter if
121    --  given, or the Internal parameter if not (if there is no External
122    --  parameter, the External parameter is a copy of the Internal name).
123
124    --  If the External parameter is given as a string, then this string is
125    --  treated as an external name (exactly as though it had been given as an
126    --  External_Name parameter for a normal Import pragma).
127
128    --  If the External parameter is given as an identifier (or there is no
129    --  External parameter, so that the Internal identifier is used), then
130    --  the external name is the characters of the identifier, translated
131    --  to all upper case letters for OpenVMS versions of GNAT, and to all
132    --  lower case letters for all other versions
133
134    --  Note: the external name specified or implied by any of these special
135    --  Import_xxx or Export_xxx pragmas override an external or link name
136    --  specified in a previous Import or Export pragma.
137
138    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
139    --  named notation, following the standard rules for subprogram calls, i.e.
140    --  parameters can be given in any order if named notation is used, and
141    --  positional and named notation can be mixed, subject to the rule that all
142    --  positional parameters must appear first.
143
144    --  Note: All these pragmas are implemented exactly following the DEC design
145    --  and implementation and are intended to be fully compatible with the use
146    --  of these pragmas in the DEC Ada compiler.
147
148    --------------------------------------------
149    -- Checking for Duplicated External Names --
150    --------------------------------------------
151
152    --  It is suspicious if two separate Export pragmas use the same external
153    --  name. The following table is used to diagnose this situation so that
154    --  an appropriate warning can be issued.
155
156    --  The Node_Id stored is for the N_String_Literal node created to hold
157    --  the value of the external name. The Sloc of this node is used to
158    --  cross-reference the location of the duplication.
159
160    package Externals is new Table.Table (
161      Table_Component_Type => Node_Id,
162      Table_Index_Type     => Int,
163      Table_Low_Bound      => 0,
164      Table_Initial        => 100,
165      Table_Increment      => 100,
166      Table_Name           => "Name_Externals");
167
168    -------------------------------------
169    -- Local Subprograms and Variables --
170    -------------------------------------
171
172    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
173    --  This routine is used for possible casing adjustment of an explicit
174    --  external name supplied as a string literal (the node N), according to
175    --  the casing requirement of Opt.External_Name_Casing. If this is set to
176    --  As_Is, then the string literal is returned unchanged, but if it is set
177    --  to Uppercase or Lowercase, then a new string literal with appropriate
178    --  casing is constructed.
179
180    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
181    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
182    --  original one, following the renaming chain) is returned. Otherwise the
183    --  entity is returned unchanged. Should be in Einfo???
184
185    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id);
186    --  Preanalyze the boolean expressions in the Requires and Ensures arguments
187    --  of a Test_Case pragma if present (possibly Empty). We treat these as
188    --  spec expressions (i.e. similar to a default expression).
189
190    procedure rv;
191    --  This is a dummy function called by the processing for pragma Reviewable.
192    --  It is there for assisting front end debugging. By placing a Reviewable
193    --  pragma in the source program, a breakpoint on rv catches this place in
194    --  the source, allowing convenient stepping to the point of interest.
195
196    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
197    --  Place semantic information on the argument of an Elaborate/Elaborate_All
198    --  pragma. Entity name for unit and its parents is taken from item in
199    --  previous with_clause that mentions the unit.
200
201    -------------------------------
202    -- Adjust_External_Name_Case --
203    -------------------------------
204
205    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
206       CC : Char_Code;
207
208    begin
209       --  Adjust case of literal if required
210
211       if Opt.External_Name_Exp_Casing = As_Is then
212          return N;
213
214       else
215          --  Copy existing string
216
217          Start_String;
218
219          --  Set proper casing
220
221          for J in 1 .. String_Length (Strval (N)) loop
222             CC := Get_String_Char (Strval (N), J);
223
224             if Opt.External_Name_Exp_Casing = Uppercase
225               and then CC >= Get_Char_Code ('a')
226               and then CC <= Get_Char_Code ('z')
227             then
228                Store_String_Char (CC - 32);
229
230             elsif Opt.External_Name_Exp_Casing = Lowercase
231               and then CC >= Get_Char_Code ('A')
232               and then CC <= Get_Char_Code ('Z')
233             then
234                Store_String_Char (CC + 32);
235
236             else
237                Store_String_Char (CC);
238             end if;
239          end loop;
240
241          return
242            Make_String_Literal (Sloc (N),
243              Strval => End_String);
244       end if;
245    end Adjust_External_Name_Case;
246
247    ------------------------------
248    -- Analyze_PPC_In_Decl_Part --
249    ------------------------------
250
251    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
252       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
253
254    begin
255       --  Install formals and push subprogram spec onto scope stack so that we
256       --  can see the formals from the pragma.
257
258       Install_Formals (S);
259       Push_Scope (S);
260
261       --  Preanalyze the boolean expression, we treat this as a spec expression
262       --  (i.e. similar to a default expression).
263
264       Preanalyze_Spec_Expression
265         (Get_Pragma_Arg (Arg1), Standard_Boolean);
266
267       --  For a class-wide condition, a reference to a controlling formal must
268       --  be interpreted as having the class-wide type (or an access to such)
269       --  so that the inherited condition can be properly applied to any
270       --  overriding operation (see ARM12 6.6.1 (7)).
271
272       if Class_Present (N) then
273          declare
274             T   : constant Entity_Id := Find_Dispatching_Type (S);
275
276             ACW : Entity_Id := Empty;
277             --  Access to T'class, created if there is a controlling formal
278             --  that is an access parameter.
279
280             function Get_ACW return Entity_Id;
281             --  If the expression has a reference to an controlling access
282             --  parameter, create an access to T'class for the necessary
283             --  conversions if one does not exist.
284
285             function Process (N : Node_Id) return Traverse_Result;
286             --  ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
287             --  aspect for a primitive subprogram of a tagged type T, a name
288             --  that denotes a formal parameter of type T is interpreted as
289             --  having type T'Class. Similarly, a name that denotes a formal
290             --  accessparameter of type access-to-T is interpreted as having
291             --  type access-to-T'Class. This ensures the expression is well-
292             --  defined for a primitive subprogram of a type descended from T.
293
294             -------------
295             -- Get_ACW --
296             -------------
297
298             function Get_ACW return Entity_Id is
299                Loc  : constant Source_Ptr := Sloc (N);
300                Decl : Node_Id;
301
302             begin
303                if No (ACW) then
304                   Decl := Make_Full_Type_Declaration (Loc,
305                     Defining_Identifier => Make_Temporary (Loc, 'T'),
306                     Type_Definition =>
307                        Make_Access_To_Object_Definition (Loc,
308                        Subtype_Indication =>
309                          New_Occurrence_Of (Class_Wide_Type (T), Loc),
310                        All_Present => True));
311
312                   Insert_Before (Unit_Declaration_Node (S), Decl);
313                   Analyze (Decl);
314                   ACW := Defining_Identifier (Decl);
315                   Freeze_Before (Unit_Declaration_Node (S), ACW);
316                end if;
317
318                return ACW;
319             end Get_ACW;
320
321             -------------
322             -- Process --
323             -------------
324
325             function Process (N : Node_Id) return Traverse_Result is
326                Loc : constant Source_Ptr := Sloc (N);
327                Typ : Entity_Id;
328
329             begin
330                if Is_Entity_Name (N)
331                  and then Is_Formal (Entity (N))
332                  and then Nkind (Parent (N)) /= N_Type_Conversion
333                then
334                   if Etype (Entity (N)) = T then
335                      Typ := Class_Wide_Type (T);
336
337                   elsif Is_Access_Type (Etype (Entity (N)))
338                     and then Designated_Type (Etype (Entity (N))) = T
339                   then
340                      Typ := Get_ACW;
341                   else
342                      Typ := Empty;
343                   end if;
344
345                   if Present (Typ) then
346                      Rewrite (N,
347                        Make_Type_Conversion (Loc,
348                          Subtype_Mark =>
349                            New_Occurrence_Of (Typ, Loc),
350                          Expression  => New_Occurrence_Of (Entity (N), Loc)));
351                      Set_Etype (N, Typ);
352                   end if;
353                end if;
354
355                return OK;
356             end Process;
357
358             procedure Replace_Type is new Traverse_Proc (Process);
359
360          begin
361             Replace_Type (Get_Pragma_Arg (Arg1));
362          end;
363       end if;
364
365       --  Remove the subprogram from the scope stack now that the pre-analysis
366       --  of the precondition/postcondition is done.
367
368       End_Scope;
369    end Analyze_PPC_In_Decl_Part;
370
371    --------------------
372    -- Analyze_Pragma --
373    --------------------
374
375    procedure Analyze_Pragma (N : Node_Id) is
376       Loc     : constant Source_Ptr := Sloc (N);
377       Pname   : constant Name_Id    := Pragma_Name (N);
378       Prag_Id : Pragma_Id;
379
380       Pragma_Exit : exception;
381       --  This exception is used to exit pragma processing completely. It is
382       --  used when an error is detected, and no further processing is
383       --  required. It is also used if an earlier error has left the tree in
384       --  a state where the pragma should not be processed.
385
386       Arg_Count : Nat;
387       --  Number of pragma argument associations
388
389       Arg1 : Node_Id;
390       Arg2 : Node_Id;
391       Arg3 : Node_Id;
392       Arg4 : Node_Id;
393       --  First four pragma arguments (pragma argument association nodes, or
394       --  Empty if the corresponding argument does not exist).
395
396       type Name_List is array (Natural range <>) of Name_Id;
397       type Args_List is array (Natural range <>) of Node_Id;
398       --  Types used for arguments to Check_Arg_Order and Gather_Associations
399
400       procedure Ada_2005_Pragma;
401       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
402       --  Ada 95 mode, these are implementation defined pragmas, so should be
403       --  caught by the No_Implementation_Pragmas restriction.
404
405       procedure Ada_2012_Pragma;
406       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
407       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
408       --  should be caught by the No_Implementation_Pragmas restriction.
409
410       procedure Check_Ada_83_Warning;
411       --  Issues a warning message for the current pragma if operating in Ada
412       --  83 mode (used for language pragmas that are not a standard part of
413       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
414       --  of 95 pragma.
415
416       procedure Check_Arg_Count (Required : Nat);
417       --  Check argument count for pragma is equal to given parameter. If not,
418       --  then issue an error message and raise Pragma_Exit.
419
420       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
421       --  Arg which can either be a pragma argument association, in which case
422       --  the check is applied to the expression of the association or an
423       --  expression directly.
424
425       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
426       --  Check that an argument has the right form for an EXTERNAL_NAME
427       --  parameter of an extended import/export pragma. The rule is that the
428       --  name must be an identifier or string literal (in Ada 83 mode) or a
429       --  static string expression (in Ada 95 mode).
430
431       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
432       --  Check the specified argument Arg to make sure that it is an
433       --  identifier. If not give error and raise Pragma_Exit.
434
435       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
436       --  Check the specified argument Arg to make sure that it is an integer
437       --  literal. If not give error and raise Pragma_Exit.
438
439       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
440       --  Check the specified argument Arg to make sure that it has the proper
441       --  syntactic form for a local name and meets the semantic requirements
442       --  for a local name. The local name is analyzed as part of the
443       --  processing for this call. In addition, the local name is required
444       --  to represent an entity at the library level.
445
446       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
447       --  Check the specified argument Arg to make sure that it has the proper
448       --  syntactic form for a local name and meets the semantic requirements
449       --  for a local name. The local name is analyzed as part of the
450       --  processing for this call.
451
452       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
453       --  Check the specified argument Arg to make sure that it is a valid
454       --  locking policy name. If not give error and raise Pragma_Exit.
455
456       procedure Check_Arg_Is_One_Of
457         (Arg                : Node_Id;
458          N1, N2             : Name_Id);
459       procedure Check_Arg_Is_One_Of
460         (Arg                : Node_Id;
461          N1, N2, N3         : Name_Id);
462       procedure Check_Arg_Is_One_Of
463         (Arg                : Node_Id;
464          N1, N2, N3, N4, N5 : Name_Id);
465       --  Check the specified argument Arg to make sure that it is an
466       --  identifier whose name matches either N1 or N2 (or N3, N4, N5 if
467       --  present). If not then give error and raise Pragma_Exit.
468
469       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
470       --  Check the specified argument Arg to make sure that it is a valid
471       --  queuing policy name. If not give error and raise Pragma_Exit.
472
473       procedure Check_Arg_Is_Static_Expression
474         (Arg : Node_Id;
475          Typ : Entity_Id := Empty);
476       --  Check the specified argument Arg to make sure that it is a static
477       --  expression of the given type (i.e. it will be analyzed and resolved
478       --  using this type, which can be any valid argument to Resolve, e.g.
479       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
480       --  Typ is left Empty, then any static expression is allowed.
481
482       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
483       --  Check the specified argument Arg to make sure that it is a valid task
484       --  dispatching policy name. If not give error and raise Pragma_Exit.
485
486       procedure Check_Arg_Order (Names : Name_List);
487       --  Checks for an instance of two arguments with identifiers for the
488       --  current pragma which are not in the sequence indicated by Names,
489       --  and if so, generates a fatal message about bad order of arguments.
490
491       procedure Check_At_Least_N_Arguments (N : Nat);
492       --  Check there are at least N arguments present
493
494       procedure Check_At_Most_N_Arguments (N : Nat);
495       --  Check there are no more than N arguments present
496
497       procedure Check_Component
498         (Comp            : Node_Id;
499          UU_Typ          : Entity_Id;
500          In_Variant_Part : Boolean := False);
501       --  Examine an Unchecked_Union component for correct use of per-object
502       --  constrained subtypes, and for restrictions on finalizable components.
503       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
504       --  should be set when Comp comes from a record variant.
505
506       procedure Check_Duplicate_Pragma (E : Entity_Id);
507       --  Check if a pragma of the same name as the current pragma is already
508       --  chained as a rep pragma to the given entity. If so give a message
509       --  about the duplicate, and then raise Pragma_Exit so does not return.
510       --  Also checks for delayed aspect specification node in the chain.
511
512       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
513       --  Nam is an N_String_Literal node containing the external name set by
514       --  an Import or Export pragma (or extended Import or Export pragma).
515       --  This procedure checks for possible duplications if this is the export
516       --  case, and if found, issues an appropriate error message.
517
518       procedure Check_First_Subtype (Arg : Node_Id);
519       --  Checks that Arg, whose expression is an entity name, references a
520       --  first subtype.
521
522       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
523       --  Checks that the given argument has an identifier, and if so, requires
524       --  it to match the given identifier name. If there is no identifier, or
525       --  a non-matching identifier, then an error message is given and
526       --  Pragma_Exit is raised.
527
528       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
529       --  Checks that the given argument has an identifier, and if so, requires
530       --  it to match one of the given identifier names. If there is no
531       --  identifier, or a non-matching identifier, then an error message is
532       --  given and Pragma_Exit is raised.
533
534       procedure Check_In_Main_Program;
535       --  Common checks for pragmas that appear within a main program
536       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
537
538       procedure Check_Interrupt_Or_Attach_Handler;
539       --  Common processing for first argument of pragma Interrupt_Handler or
540       --  pragma Attach_Handler.
541
542       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
543       --  Check that pragma appears in a declarative part, or in a package
544       --  specification, i.e. that it does not occur in a statement sequence
545       --  in a body.
546
547       procedure Check_No_Identifier (Arg : Node_Id);
548       --  Checks that the given argument does not have an identifier. If
549       --  an identifier is present, then an error message is issued, and
550       --  Pragma_Exit is raised.
551
552       procedure Check_No_Identifiers;
553       --  Checks that none of the arguments to the pragma has an identifier.
554       --  If any argument has an identifier, then an error message is issued,
555       --  and Pragma_Exit is raised.
556
557       procedure Check_No_Link_Name;
558       --  Checks that no link name is specified
559
560       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
561       --  Checks if the given argument has an identifier, and if so, requires
562       --  it to match the given identifier name. If there is a non-matching
563       --  identifier, then an error message is given and Pragma_Exit is raised.
564
565       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
566       --  Checks if the given argument has an identifier, and if so, requires
567       --  it to match the given identifier name. If there is a non-matching
568       --  identifier, then an error message is given and Pragma_Exit is raised.
569       --  In this version of the procedure, the identifier name is given as
570       --  a string with lower case letters.
571
572       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
573       --  Called to process a precondition or postcondition pragma. There are
574       --  three cases:
575       --
576       --    The pragma appears after a subprogram spec
577       --
578       --      If the corresponding check is not enabled, the pragma is analyzed
579       --      but otherwise ignored and control returns with In_Body set False.
580       --
581       --      If the check is enabled, then the first step is to analyze the
582       --      pragma, but this is skipped if the subprogram spec appears within
583       --      a package specification (because this is the case where we delay
584       --      analysis till the end of the spec). Then (whether or not it was
585       --      analyzed), the pragma is chained to the subprogram in question
586       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
587       --      caller with In_Body set False.
588       --
589       --    The pragma appears at the start of subprogram body declarations
590       --
591       --      In this case an immediate return to the caller is made with
592       --      In_Body set True, and the pragma is NOT analyzed.
593       --
594       --    In all other cases, an error message for bad placement is given
595
596       procedure Check_Static_Constraint (Constr : Node_Id);
597       --  Constr is a constraint from an N_Subtype_Indication node from a
598       --  component constraint in an Unchecked_Union type. This routine checks
599       --  that the constraint is static as required by the restrictions for
600       --  Unchecked_Union.
601
602       procedure Check_Test_Case;
603       --  Called to process a test-case pragma. The treatment is similar to the
604       --  one for pre- and postcondition in Check_Precondition_Postcondition,
605       --  except the placement rules for the test-case pragma are stricter.
606       --  This pragma may only occur after a subprogram spec declared directly
607       --  in a package spec unit. In this case, the pragma is chained to the
608       --  subprogram in question (using Spec_TC_List and Next_Pragma) and
609       --  analysis of the pragma is delayed till the end of the spec. In
610       --  all other cases, an error message for bad placement is given.
611
612       procedure Check_Valid_Configuration_Pragma;
613       --  Legality checks for placement of a configuration pragma
614
615       procedure Check_Valid_Library_Unit_Pragma;
616       --  Legality checks for library unit pragmas. A special case arises for
617       --  pragmas in generic instances that come from copies of the original
618       --  library unit pragmas in the generic templates. In the case of other
619       --  than library level instantiations these can appear in contexts which
620       --  would normally be invalid (they only apply to the original template
621       --  and to library level instantiations), and they are simply ignored,
622       --  which is implemented by rewriting them as null statements.
623
624       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
625       --  Check an Unchecked_Union variant for lack of nested variants and
626       --  presence of at least one component. UU_Typ is the related Unchecked_
627       --  Union type.
628
629       procedure Error_Pragma (Msg : String);
630       pragma No_Return (Error_Pragma);
631       --  Outputs error message for current pragma. The message contains a %
632       --  that will be replaced with the pragma name, and the flag is placed
633       --  on the pragma itself. Pragma_Exit is then raised.
634
635       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
636       pragma No_Return (Error_Pragma_Arg);
637       --  Outputs error message for current pragma. The message may contain
638       --  a % that will be replaced with the pragma name. The parameter Arg
639       --  may either be a pragma argument association, in which case the flag
640       --  is placed on the expression of this association, or an expression,
641       --  in which case the flag is placed directly on the expression. The
642       --  message is placed using Error_Msg_N, so the message may also contain
643       --  an & insertion character which will reference the given Arg value.
644       --  After placing the message, Pragma_Exit is raised.
645
646       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
647       pragma No_Return (Error_Pragma_Arg);
648       --  Similar to above form of Error_Pragma_Arg except that two messages
649       --  are provided, the second is a continuation comment starting with \.
650
651       procedure Error_Pragma_Arg_Alternate_Name
652         (Msg      : String;
653          Arg      : Node_Id;
654          Alt_Name : Name_Id);
655       pragma No_Return (Error_Pragma_Arg_Alternate_Name);
656       --  Outputs error message for current pragma, similar to
657       --  Error_Pragma_Arg, except the source name of the aspect/pragma to use
658       --  in warnings may be equal to Alt_Name (which should be equivalent to
659       --  the name used in pragma). The location for the source name should be
660       --  pointed to by Arg.
661
662       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
663       pragma No_Return (Error_Pragma_Arg_Ident);
664       --  Outputs error message for current pragma. The message may contain
665       --  a % that will be replaced with the pragma name. The parameter Arg
666       --  must be a pragma argument association with a non-empty identifier
667       --  (i.e. its Chars field must be set), and the error message is placed
668       --  on the identifier. The message is placed using Error_Msg_N so
669       --  the message may also contain an & insertion character which will
670       --  reference the identifier. After placing the message, Pragma_Exit
671       --  is raised.
672
673       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
674       pragma No_Return (Error_Pragma_Ref);
675       --  Outputs error message for current pragma. The message may contain
676       --  a % that will be replaced with the pragma name. The parameter Ref
677       --  must be an entity whose name can be referenced by & and sloc by #.
678       --  After placing the message, Pragma_Exit is raised.
679
680       function Find_Lib_Unit_Name return Entity_Id;
681       --  Used for a library unit pragma to find the entity to which the
682       --  library unit pragma applies, returns the entity found.
683
684       procedure Find_Program_Unit_Name (Id : Node_Id);
685       --  If the pragma is a compilation unit pragma, the id must denote the
686       --  compilation unit in the same compilation, and the pragma must appear
687       --  in the list of preceding or trailing pragmas. If it is a program
688       --  unit pragma that is not a compilation unit pragma, then the
689       --  identifier must be visible.
690
691       function Find_Unique_Parameterless_Procedure
692         (Name : Entity_Id;
693          Arg  : Node_Id) return Entity_Id;
694       --  Used for a procedure pragma to find the unique parameterless
695       --  procedure identified by Name, returns it if it exists, otherwise
696       --  errors out and uses Arg as the pragma argument for the message.
697
698       procedure Fix_Error (Msg : in out String);
699       --  This is called prior to issuing an error message. Msg is a string
700       --  which typically contains the substring pragma. If the current pragma
701       --  comes from an aspect, each such "pragma" substring is replaced with
702       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
703       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
704
705       procedure Gather_Associations
706         (Names : Name_List;
707          Args  : out Args_List);
708       --  This procedure is used to gather the arguments for a pragma that
709       --  permits arbitrary ordering of parameters using the normal rules
710       --  for named and positional parameters. The Names argument is a list
711       --  of Name_Id values that corresponds to the allowed pragma argument
712       --  association identifiers in order. The result returned in Args is
713       --  a list of corresponding expressions that are the pragma arguments.
714       --  Note that this is a list of expressions, not of pragma argument
715       --  associations (Gather_Associations has completely checked all the
716       --  optional identifiers when it returns). An entry in Args is Empty
717       --  on return if the corresponding argument is not present.
718
719       procedure GNAT_Pragma;
720       --  Called for all GNAT defined pragmas to check the relevant restriction
721       --  (No_Implementation_Pragmas).
722
723       function Is_Before_First_Decl
724         (Pragma_Node : Node_Id;
725          Decls       : List_Id) return Boolean;
726       --  Return True if Pragma_Node is before the first declarative item in
727       --  Decls where Decls is the list of declarative items.
728
729       function Is_Configuration_Pragma return Boolean;
730       --  Determines if the placement of the current pragma is appropriate
731       --  for a configuration pragma.
732
733       function Is_In_Context_Clause return Boolean;
734       --  Returns True if pragma appears within the context clause of a unit,
735       --  and False for any other placement (does not generate any messages).
736
737       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
738       --  Analyzes the argument, and determines if it is a static string
739       --  expression, returns True if so, False if non-static or not String.
740
741       procedure Pragma_Misplaced;
742       pragma No_Return (Pragma_Misplaced);
743       --  Issue fatal error message for misplaced pragma
744
745       procedure Process_Atomic_Shared_Volatile;
746       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
747       --  Shared is an obsolete Ada 83 pragma, treated as being identical
748       --  in effect to pragma Atomic.
749
750       procedure Process_Compile_Time_Warning_Or_Error;
751       --  Common processing for Compile_Time_Error and Compile_Time_Warning
752
753       procedure Process_Convention
754         (C   : out Convention_Id;
755          Ent : out Entity_Id);
756       --  Common processing for Convention, Interface, Import and Export.
757       --  Checks first two arguments of pragma, and sets the appropriate
758       --  convention value in the specified entity or entities. On return
759       --  C is the convention, Ent is the referenced entity.
760
761       procedure Process_Extended_Import_Export_Exception_Pragma
762         (Arg_Internal : Node_Id;
763          Arg_External : Node_Id;
764          Arg_Form     : Node_Id;
765          Arg_Code     : Node_Id);
766       --  Common processing for the pragmas Import/Export_Exception. The three
767       --  arguments correspond to the three named parameters of the pragma. An
768       --  argument is empty if the corresponding parameter is not present in
769       --  the pragma.
770
771       procedure Process_Extended_Import_Export_Object_Pragma
772         (Arg_Internal : Node_Id;
773          Arg_External : Node_Id;
774          Arg_Size     : Node_Id);
775       --  Common processing for the pragmas Import/Export_Object. The three
776       --  arguments correspond to the three named parameters of the pragmas. An
777       --  argument is empty if the corresponding parameter is not present in
778       --  the pragma.
779
780       procedure Process_Extended_Import_Export_Internal_Arg
781         (Arg_Internal : Node_Id := Empty);
782       --  Common processing for all extended Import and Export pragmas. The
783       --  argument is the pragma parameter for the Internal argument. If
784       --  Arg_Internal is empty or inappropriate, an error message is posted.
785       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
786       --  set to identify the referenced entity.
787
788       procedure Process_Extended_Import_Export_Subprogram_Pragma
789         (Arg_Internal                 : Node_Id;
790          Arg_External                 : Node_Id;
791          Arg_Parameter_Types          : Node_Id;
792          Arg_Result_Type              : Node_Id := Empty;
793          Arg_Mechanism                : Node_Id;
794          Arg_Result_Mechanism         : Node_Id := Empty;
795          Arg_First_Optional_Parameter : Node_Id := Empty);
796       --  Common processing for all extended Import and Export pragmas applying
797       --  to subprograms. The caller omits any arguments that do not apply to
798       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
799       --  only in the Import_Function and Export_Function cases). The argument
800       --  names correspond to the allowed pragma association identifiers.
801
802       procedure Process_Generic_List;
803       --  Common processing for Share_Generic and Inline_Generic
804
805       procedure Process_Import_Or_Interface;
806       --  Common processing for Import of Interface
807
808       procedure Process_Import_Predefined_Type;
809       --  Processing for completing a type with pragma Import. This is used
810       --  to declare types that match predefined C types, especially for cases
811       --  without corresponding Ada predefined type.
812
813       procedure Process_Inline (Active : Boolean);
814       --  Common processing for Inline and Inline_Always. The parameter
815       --  indicates if the inline pragma is active, i.e. if it should actually
816       --  cause inlining to occur.
817
818       procedure Process_Interface_Name
819         (Subprogram_Def : Entity_Id;
820          Ext_Arg        : Node_Id;
821          Link_Arg       : Node_Id);
822       --  Given the last two arguments of pragma Import, pragma Export, or
823       --  pragma Interface_Name, performs validity checks and sets the
824       --  Interface_Name field of the given subprogram entity to the
825       --  appropriate external or link name, depending on the arguments given.
826       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
827       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
828       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
829       --  nor Link_Arg is present, the interface name is set to the default
830       --  from the subprogram name.
831
832       procedure Process_Interrupt_Or_Attach_Handler;
833       --  Common processing for Interrupt and Attach_Handler pragmas
834
835       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
836       --  Common processing for Restrictions and Restriction_Warnings pragmas.
837       --  Warn is True for Restriction_Warnings, or for Restrictions if the
838       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
839       --  is not set in the Restrictions case.
840
841       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
842       --  Common processing for Suppress and Unsuppress. The boolean parameter
843       --  Suppress_Case is True for the Suppress case, and False for the
844       --  Unsuppress case.
845
846       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
847       --  This procedure sets the Is_Exported flag for the given entity,
848       --  checking that the entity was not previously imported. Arg is
849       --  the argument that specified the entity. A check is also made
850       --  for exporting inappropriate entities.
851
852       procedure Set_Extended_Import_Export_External_Name
853         (Internal_Ent : Entity_Id;
854          Arg_External : Node_Id);
855       --  Common processing for all extended import export pragmas. The first
856       --  argument, Internal_Ent, is the internal entity, which has already
857       --  been checked for validity by the caller. Arg_External is from the
858       --  Import or Export pragma, and may be null if no External parameter
859       --  was present. If Arg_External is present and is a non-null string
860       --  (a null string is treated as the default), then the Interface_Name
861       --  field of Internal_Ent is set appropriately.
862
863       procedure Set_Imported (E : Entity_Id);
864       --  This procedure sets the Is_Imported flag for the given entity,
865       --  checking that it is not previously exported or imported.
866
867       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
868       --  Mech is a parameter passing mechanism (see Import_Function syntax
869       --  for MECHANISM_NAME). This routine checks that the mechanism argument
870       --  has the right form, and if not issues an error message. If the
871       --  argument has the right form then the Mechanism field of Ent is
872       --  set appropriately.
873
874       procedure Set_Ravenscar_Profile (N : Node_Id);
875       --  Activate the set of configuration pragmas and restrictions that make
876       --  up the Ravenscar Profile. N is the corresponding pragma node, which
877       --  is used for error messages on any constructs that violate the
878       --  profile.
879
880       ---------------------
881       -- Ada_2005_Pragma --
882       ---------------------
883
884       procedure Ada_2005_Pragma is
885       begin
886          if Ada_Version <= Ada_95 then
887             Check_Restriction (No_Implementation_Pragmas, N);
888          end if;
889       end Ada_2005_Pragma;
890
891       ---------------------
892       -- Ada_2012_Pragma --
893       ---------------------
894
895       procedure Ada_2012_Pragma is
896       begin
897          if Ada_Version <= Ada_2005 then
898             Check_Restriction (No_Implementation_Pragmas, N);
899          end if;
900       end Ada_2012_Pragma;
901
902       --------------------------
903       -- Check_Ada_83_Warning --
904       --------------------------
905
906       procedure Check_Ada_83_Warning is
907       begin
908          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
909             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
910          end if;
911       end Check_Ada_83_Warning;
912
913       ---------------------
914       -- Check_Arg_Count --
915       ---------------------
916
917       procedure Check_Arg_Count (Required : Nat) is
918       begin
919          if Arg_Count /= Required then
920             Error_Pragma ("wrong number of arguments for pragma%");
921          end if;
922       end Check_Arg_Count;
923
924       --------------------------------
925       -- Check_Arg_Is_External_Name --
926       --------------------------------
927
928       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
929          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
930
931       begin
932          if Nkind (Argx) = N_Identifier then
933             return;
934
935          else
936             Analyze_And_Resolve (Argx, Standard_String);
937
938             if Is_OK_Static_Expression (Argx) then
939                return;
940
941             elsif Etype (Argx) = Any_Type then
942                raise Pragma_Exit;
943
944             --  An interesting special case, if we have a string literal and
945             --  we are in Ada 83 mode, then we allow it even though it will
946             --  not be flagged as static. This allows expected Ada 83 mode
947             --  use of external names which are string literals, even though
948             --  technically these are not static in Ada 83.
949
950             elsif Ada_Version = Ada_83
951               and then Nkind (Argx) = N_String_Literal
952             then
953                return;
954
955             --  Static expression that raises Constraint_Error. This has
956             --  already been flagged, so just exit from pragma processing.
957
958             elsif Is_Static_Expression (Argx) then
959                raise Pragma_Exit;
960
961             --  Here we have a real error (non-static expression)
962
963             else
964                Error_Msg_Name_1 := Pname;
965
966                declare
967                   Msg : String :=
968                           "argument for pragma% must be a identifier or "
969                           & "static string expression!";
970                begin
971                   Fix_Error (Msg);
972                   Flag_Non_Static_Expr (Msg, Argx);
973                   raise Pragma_Exit;
974                end;
975             end if;
976          end if;
977       end Check_Arg_Is_External_Name;
978
979       -----------------------------
980       -- Check_Arg_Is_Identifier --
981       -----------------------------
982
983       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
984          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
985       begin
986          if Nkind (Argx) /= N_Identifier then
987             Error_Pragma_Arg
988               ("argument for pragma% must be identifier", Argx);
989          end if;
990       end Check_Arg_Is_Identifier;
991
992       ----------------------------------
993       -- Check_Arg_Is_Integer_Literal --
994       ----------------------------------
995
996       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
997          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
998       begin
999          if Nkind (Argx) /= N_Integer_Literal then
1000             Error_Pragma_Arg
1001               ("argument for pragma% must be integer literal", Argx);
1002          end if;
1003       end Check_Arg_Is_Integer_Literal;
1004
1005       -------------------------------------------
1006       -- Check_Arg_Is_Library_Level_Local_Name --
1007       -------------------------------------------
1008
1009       --  LOCAL_NAME ::=
1010       --    DIRECT_NAME
1011       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1012       --  | library_unit_NAME
1013
1014       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
1015       begin
1016          Check_Arg_Is_Local_Name (Arg);
1017
1018          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
1019            and then Comes_From_Source (N)
1020          then
1021             Error_Pragma_Arg
1022               ("argument for pragma% must be library level entity", Arg);
1023          end if;
1024       end Check_Arg_Is_Library_Level_Local_Name;
1025
1026       -----------------------------
1027       -- Check_Arg_Is_Local_Name --
1028       -----------------------------
1029
1030       --  LOCAL_NAME ::=
1031       --    DIRECT_NAME
1032       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1033       --  | library_unit_NAME
1034
1035       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
1036          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1037
1038       begin
1039          Analyze (Argx);
1040
1041          if Nkind (Argx) not in N_Direct_Name
1042            and then (Nkind (Argx) /= N_Attribute_Reference
1043                       or else Present (Expressions (Argx))
1044                       or else Nkind (Prefix (Argx)) /= N_Identifier)
1045            and then (not Is_Entity_Name (Argx)
1046                       or else not Is_Compilation_Unit (Entity (Argx)))
1047          then
1048             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
1049          end if;
1050
1051          --  No further check required if not an entity name
1052
1053          if not Is_Entity_Name (Argx) then
1054             null;
1055
1056          else
1057             declare
1058                OK   : Boolean;
1059                Ent  : constant Entity_Id := Entity (Argx);
1060                Scop : constant Entity_Id := Scope (Ent);
1061             begin
1062                --  Case of a pragma applied to a compilation unit: pragma must
1063                --  occur immediately after the program unit in the compilation.
1064
1065                if Is_Compilation_Unit (Ent) then
1066                   declare
1067                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1068
1069                   begin
1070                      --  Case of pragma placed immediately after spec
1071
1072                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
1073                         OK := True;
1074
1075                      --  Case of pragma placed immediately after body
1076
1077                      elsif Nkind (Decl) = N_Subprogram_Declaration
1078                              and then Present (Corresponding_Body (Decl))
1079                      then
1080                         OK := Parent (N) =
1081                                 Aux_Decls_Node
1082                                   (Parent (Unit_Declaration_Node
1083                                              (Corresponding_Body (Decl))));
1084
1085                      --  All other cases are illegal
1086
1087                      else
1088                         OK := False;
1089                      end if;
1090                   end;
1091
1092                --  Special restricted placement rule from 10.2.1(11.8/2)
1093
1094                elsif Is_Generic_Formal (Ent)
1095                        and then Prag_Id = Pragma_Preelaborable_Initialization
1096                then
1097                   OK := List_Containing (N) =
1098                           Generic_Formal_Declarations
1099                             (Unit_Declaration_Node (Scop));
1100
1101                --  Default case, just check that the pragma occurs in the scope
1102                --  of the entity denoted by the name.
1103
1104                else
1105                   OK := Current_Scope = Scop;
1106                end if;
1107
1108                if not OK then
1109                   Error_Pragma_Arg
1110                     ("pragma% argument must be in same declarative part", Arg);
1111                end if;
1112             end;
1113          end if;
1114       end Check_Arg_Is_Local_Name;
1115
1116       ---------------------------------
1117       -- Check_Arg_Is_Locking_Policy --
1118       ---------------------------------
1119
1120       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1121          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1122
1123       begin
1124          Check_Arg_Is_Identifier (Argx);
1125
1126          if not Is_Locking_Policy_Name (Chars (Argx)) then
1127             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1128          end if;
1129       end Check_Arg_Is_Locking_Policy;
1130
1131       -------------------------
1132       -- Check_Arg_Is_One_Of --
1133       -------------------------
1134
1135       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1136          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1137
1138       begin
1139          Check_Arg_Is_Identifier (Argx);
1140
1141          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1142             Error_Msg_Name_2 := N1;
1143             Error_Msg_Name_3 := N2;
1144             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1145          end if;
1146       end Check_Arg_Is_One_Of;
1147
1148       procedure Check_Arg_Is_One_Of
1149         (Arg        : Node_Id;
1150          N1, N2, N3 : Name_Id)
1151       is
1152          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1153
1154       begin
1155          Check_Arg_Is_Identifier (Argx);
1156
1157          if Chars (Argx) /= N1
1158            and then Chars (Argx) /= N2
1159            and then Chars (Argx) /= N3
1160          then
1161             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1162          end if;
1163       end Check_Arg_Is_One_Of;
1164
1165       procedure Check_Arg_Is_One_Of
1166         (Arg                : Node_Id;
1167          N1, N2, N3, N4, N5 : Name_Id)
1168       is
1169          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1170
1171       begin
1172          Check_Arg_Is_Identifier (Argx);
1173
1174          if Chars (Argx) /= N1
1175            and then Chars (Argx) /= N2
1176            and then Chars (Argx) /= N3
1177            and then Chars (Argx) /= N4
1178            and then Chars (Argx) /= N5
1179          then
1180             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1181          end if;
1182       end Check_Arg_Is_One_Of;
1183       ---------------------------------
1184       -- Check_Arg_Is_Queuing_Policy --
1185       ---------------------------------
1186
1187       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1188          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1189
1190       begin
1191          Check_Arg_Is_Identifier (Argx);
1192
1193          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1194             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1195          end if;
1196       end Check_Arg_Is_Queuing_Policy;
1197
1198       ------------------------------------
1199       -- Check_Arg_Is_Static_Expression --
1200       ------------------------------------
1201
1202       procedure Check_Arg_Is_Static_Expression
1203         (Arg : Node_Id;
1204          Typ : Entity_Id := Empty)
1205       is
1206          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1207
1208       begin
1209          if Present (Typ) then
1210             Analyze_And_Resolve (Argx, Typ);
1211          else
1212             Analyze_And_Resolve (Argx);
1213          end if;
1214
1215          if Is_OK_Static_Expression (Argx) then
1216             return;
1217
1218          elsif Etype (Argx) = Any_Type then
1219             raise Pragma_Exit;
1220
1221          --  An interesting special case, if we have a string literal and we
1222          --  are in Ada 83 mode, then we allow it even though it will not be
1223          --  flagged as static. This allows the use of Ada 95 pragmas like
1224          --  Import in Ada 83 mode. They will of course be flagged with
1225          --  warnings as usual, but will not cause errors.
1226
1227          elsif Ada_Version = Ada_83
1228            and then Nkind (Argx) = N_String_Literal
1229          then
1230             return;
1231
1232          --  Static expression that raises Constraint_Error. This has already
1233          --  been flagged, so just exit from pragma processing.
1234
1235          elsif Is_Static_Expression (Argx) then
1236             raise Pragma_Exit;
1237
1238          --  Finally, we have a real error
1239
1240          else
1241             Error_Msg_Name_1 := Pname;
1242
1243             declare
1244                Msg : String :=
1245                        "argument for pragma% must be a static expression!";
1246             begin
1247                Fix_Error (Msg);
1248                Flag_Non_Static_Expr (Msg, Argx);
1249             end;
1250
1251             raise Pragma_Exit;
1252          end if;
1253       end Check_Arg_Is_Static_Expression;
1254
1255       ------------------------------------------
1256       -- Check_Arg_Is_Task_Dispatching_Policy --
1257       ------------------------------------------
1258
1259       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1260          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1261
1262       begin
1263          Check_Arg_Is_Identifier (Argx);
1264
1265          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1266             Error_Pragma_Arg
1267               ("& is not a valid task dispatching policy name", Argx);
1268          end if;
1269       end Check_Arg_Is_Task_Dispatching_Policy;
1270
1271       ---------------------
1272       -- Check_Arg_Order --
1273       ---------------------
1274
1275       procedure Check_Arg_Order (Names : Name_List) is
1276          Arg : Node_Id;
1277
1278          Highest_So_Far : Natural := 0;
1279          --  Highest index in Names seen do far
1280
1281       begin
1282          Arg := Arg1;
1283          for J in 1 .. Arg_Count loop
1284             if Chars (Arg) /= No_Name then
1285                for K in Names'Range loop
1286                   if Chars (Arg) = Names (K) then
1287                      if K < Highest_So_Far then
1288                         Error_Msg_Name_1 := Pname;
1289                         Error_Msg_N
1290                           ("parameters out of order for pragma%", Arg);
1291                         Error_Msg_Name_1 := Names (K);
1292                         Error_Msg_Name_2 := Names (Highest_So_Far);
1293                         Error_Msg_N ("\% must appear before %", Arg);
1294                         raise Pragma_Exit;
1295
1296                      else
1297                         Highest_So_Far := K;
1298                      end if;
1299                   end if;
1300                end loop;
1301             end if;
1302
1303             Arg := Next (Arg);
1304          end loop;
1305       end Check_Arg_Order;
1306
1307       --------------------------------
1308       -- Check_At_Least_N_Arguments --
1309       --------------------------------
1310
1311       procedure Check_At_Least_N_Arguments (N : Nat) is
1312       begin
1313          if Arg_Count < N then
1314             Error_Pragma ("too few arguments for pragma%");
1315          end if;
1316       end Check_At_Least_N_Arguments;
1317
1318       -------------------------------
1319       -- Check_At_Most_N_Arguments --
1320       -------------------------------
1321
1322       procedure Check_At_Most_N_Arguments (N : Nat) is
1323          Arg : Node_Id;
1324       begin
1325          if Arg_Count > N then
1326             Arg := Arg1;
1327             for J in 1 .. N loop
1328                Next (Arg);
1329                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1330             end loop;
1331          end if;
1332       end Check_At_Most_N_Arguments;
1333
1334       ---------------------
1335       -- Check_Component --
1336       ---------------------
1337
1338       procedure Check_Component
1339         (Comp            : Node_Id;
1340          UU_Typ          : Entity_Id;
1341          In_Variant_Part : Boolean := False)
1342       is
1343          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1344          Sindic  : constant Node_Id :=
1345                      Subtype_Indication (Component_Definition (Comp));
1346          Typ     : constant Entity_Id := Etype (Comp_Id);
1347
1348          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1349          --  Determine whether entity Id appears inside a generic body.
1350          --  Shouldn't this be in a more general place ???
1351
1352          -------------------------
1353          -- Inside_Generic_Body --
1354          -------------------------
1355
1356          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1357             S : Entity_Id;
1358
1359          begin
1360             S := Id;
1361             while Present (S) and then S /= Standard_Standard loop
1362                if Ekind (S) = E_Generic_Package
1363                  and then In_Package_Body (S)
1364                then
1365                   return True;
1366                end if;
1367
1368                S := Scope (S);
1369             end loop;
1370
1371             return False;
1372          end Inside_Generic_Body;
1373
1374       --  Start of processing for Check_Component
1375
1376       begin
1377          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1378          --  object constraint, then the component type shall be an Unchecked_
1379          --  Union.
1380
1381          if Nkind (Sindic) = N_Subtype_Indication
1382            and then Has_Per_Object_Constraint (Comp_Id)
1383            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1384          then
1385             Error_Msg_N
1386               ("component subtype subject to per-object constraint " &
1387                "must be an Unchecked_Union", Comp);
1388
1389          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1390          --  the body of a generic unit, or within the body of any of its
1391          --  descendant library units, no part of the type of a component
1392          --  declared in a variant_part of the unchecked union type shall be of
1393          --  a formal private type or formal private extension declared within
1394          --  the formal part of the generic unit.
1395
1396          elsif Ada_Version >= Ada_2012
1397            and then Inside_Generic_Body (UU_Typ)
1398            and then In_Variant_Part
1399            and then Is_Private_Type (Typ)
1400            and then Is_Generic_Type (Typ)
1401          then
1402             Error_Msg_N
1403               ("component of Unchecked_Union cannot be of generic type", Comp);
1404
1405          elsif Needs_Finalization (Typ) then
1406             Error_Msg_N
1407               ("component of Unchecked_Union cannot be controlled", Comp);
1408
1409          elsif Has_Task (Typ) then
1410             Error_Msg_N
1411               ("component of Unchecked_Union cannot have tasks", Comp);
1412          end if;
1413       end Check_Component;
1414
1415       ----------------------------
1416       -- Check_Duplicate_Pragma --
1417       ----------------------------
1418
1419       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1420          P : Node_Id;
1421
1422       begin
1423          --  Nothing to do if this pragma comes from an aspect specification,
1424          --  since we could not be duplicating a pragma, and we dealt with the
1425          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1426
1427          if From_Aspect_Specification (N) then
1428             return;
1429          end if;
1430
1431          --  Otherwise current pragma may duplicate previous pragma or a
1432          --  previously given aspect specification for the same pragma.
1433
1434          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1435
1436          if Present (P) then
1437             Error_Msg_Name_1 := Pragma_Name (N);
1438             Error_Msg_Sloc := Sloc (P);
1439
1440             if Nkind (P) = N_Aspect_Specification
1441               or else From_Aspect_Specification (P)
1442             then
1443                Error_Msg_NE ("aspect% for & previously given#", N, E);
1444             else
1445                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1446             end if;
1447
1448             raise Pragma_Exit;
1449          end if;
1450       end Check_Duplicate_Pragma;
1451
1452       ----------------------------------
1453       -- Check_Duplicated_Export_Name --
1454       ----------------------------------
1455
1456       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1457          String_Val : constant String_Id := Strval (Nam);
1458
1459       begin
1460          --  We are only interested in the export case, and in the case of
1461          --  generics, it is the instance, not the template, that is the
1462          --  problem (the template will generate a warning in any case).
1463
1464          if not Inside_A_Generic
1465            and then (Prag_Id = Pragma_Export
1466                        or else
1467                      Prag_Id = Pragma_Export_Procedure
1468                        or else
1469                      Prag_Id = Pragma_Export_Valued_Procedure
1470                        or else
1471                      Prag_Id = Pragma_Export_Function)
1472          then
1473             for J in Externals.First .. Externals.Last loop
1474                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1475                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1476                   Error_Msg_N ("external name duplicates name given#", Nam);
1477                   exit;
1478                end if;
1479             end loop;
1480
1481             Externals.Append (Nam);
1482          end if;
1483       end Check_Duplicated_Export_Name;
1484
1485       -------------------------
1486       -- Check_First_Subtype --
1487       -------------------------
1488
1489       procedure Check_First_Subtype (Arg : Node_Id) is
1490          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1491          Ent  : constant Entity_Id := Entity (Argx);
1492
1493       begin
1494          if Is_First_Subtype (Ent) then
1495             null;
1496
1497          elsif Is_Type (Ent) then
1498             Error_Pragma_Arg
1499               ("pragma% cannot apply to subtype", Argx);
1500
1501          elsif Is_Object (Ent) then
1502             Error_Pragma_Arg
1503               ("pragma% cannot apply to object, requires a type", Argx);
1504
1505          else
1506             Error_Pragma_Arg
1507               ("pragma% cannot apply to&, requires a type", Argx);
1508          end if;
1509       end Check_First_Subtype;
1510
1511       ----------------------
1512       -- Check_Identifier --
1513       ----------------------
1514
1515       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1516       begin
1517          if Present (Arg)
1518            and then Nkind (Arg) = N_Pragma_Argument_Association
1519          then
1520             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1521                Error_Msg_Name_1 := Pname;
1522                Error_Msg_Name_2 := Id;
1523                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1524                raise Pragma_Exit;
1525             end if;
1526          end if;
1527       end Check_Identifier;
1528
1529       --------------------------------
1530       -- Check_Identifier_Is_One_Of --
1531       --------------------------------
1532
1533       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1534       begin
1535          if Present (Arg)
1536            and then Nkind (Arg) = N_Pragma_Argument_Association
1537          then
1538             if Chars (Arg) = No_Name then
1539                Error_Msg_Name_1 := Pname;
1540                Error_Msg_N ("pragma% argument expects an identifier", Arg);
1541                raise Pragma_Exit;
1542
1543             elsif Chars (Arg) /= N1
1544               and then Chars (Arg) /= N2
1545             then
1546                Error_Msg_Name_1 := Pname;
1547                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1548                raise Pragma_Exit;
1549             end if;
1550          end if;
1551       end Check_Identifier_Is_One_Of;
1552
1553       ---------------------------
1554       -- Check_In_Main_Program --
1555       ---------------------------
1556
1557       procedure Check_In_Main_Program is
1558          P : constant Node_Id := Parent (N);
1559
1560       begin
1561          --  Must be at in subprogram body
1562
1563          if Nkind (P) /= N_Subprogram_Body then
1564             Error_Pragma ("% pragma allowed only in subprogram");
1565
1566          --  Otherwise warn if obviously not main program
1567
1568          elsif Present (Parameter_Specifications (Specification (P)))
1569            or else not Is_Compilation_Unit (Defining_Entity (P))
1570          then
1571             Error_Msg_Name_1 := Pname;
1572             Error_Msg_N
1573               ("?pragma% is only effective in main program", N);
1574          end if;
1575       end Check_In_Main_Program;
1576
1577       ---------------------------------------
1578       -- Check_Interrupt_Or_Attach_Handler --
1579       ---------------------------------------
1580
1581       procedure Check_Interrupt_Or_Attach_Handler is
1582          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1583          Handler_Proc, Proc_Scope : Entity_Id;
1584
1585       begin
1586          Analyze (Arg1_X);
1587
1588          if Prag_Id = Pragma_Interrupt_Handler then
1589             Check_Restriction (No_Dynamic_Attachment, N);
1590          end if;
1591
1592          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1593          Proc_Scope := Scope (Handler_Proc);
1594
1595          --  On AAMP only, a pragma Interrupt_Handler is supported for
1596          --  nonprotected parameterless procedures.
1597
1598          if not AAMP_On_Target
1599            or else Prag_Id = Pragma_Attach_Handler
1600          then
1601             if Ekind (Proc_Scope) /= E_Protected_Type then
1602                Error_Pragma_Arg
1603                  ("argument of pragma% must be protected procedure", Arg1);
1604             end if;
1605
1606             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1607                Error_Pragma ("pragma% must be in protected definition");
1608             end if;
1609          end if;
1610
1611          if not Is_Library_Level_Entity (Proc_Scope)
1612            or else (AAMP_On_Target
1613                      and then not Is_Library_Level_Entity (Handler_Proc))
1614          then
1615             Error_Pragma_Arg
1616               ("argument for pragma% must be library level entity", Arg1);
1617          end if;
1618
1619          --  AI05-0033: A pragma cannot appear within a generic body, because
1620          --  instance can be in a nested scope. The check that protected type
1621          --  is itself a library-level declaration is done elsewhere.
1622
1623          --  Note: we omit this check in Codepeer mode to properly handle code
1624          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1625
1626          if Inside_A_Generic then
1627             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1628               and then In_Package_Body (Scope (Current_Scope))
1629               and then not CodePeer_Mode
1630             then
1631                Error_Pragma ("pragma% cannot be used inside a generic");
1632             end if;
1633          end if;
1634       end Check_Interrupt_Or_Attach_Handler;
1635
1636       -------------------------------------------
1637       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1638       -------------------------------------------
1639
1640       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1641          P : Node_Id;
1642
1643       begin
1644          P := Parent (N);
1645          loop
1646             if No (P) then
1647                exit;
1648
1649             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1650                exit;
1651
1652             elsif Nkind_In (P, N_Package_Specification,
1653                                N_Block_Statement)
1654             then
1655                return;
1656
1657             --  Note: the following tests seem a little peculiar, because
1658             --  they test for bodies, but if we were in the statement part
1659             --  of the body, we would already have hit the handled statement
1660             --  sequence, so the only way we get here is by being in the
1661             --  declarative part of the body.
1662
1663             elsif Nkind_In (P, N_Subprogram_Body,
1664                                N_Package_Body,
1665                                N_Task_Body,
1666                                N_Entry_Body)
1667             then
1668                return;
1669             end if;
1670
1671             P := Parent (P);
1672          end loop;
1673
1674          Error_Pragma ("pragma% is not in declarative part or package spec");
1675       end Check_Is_In_Decl_Part_Or_Package_Spec;
1676
1677       -------------------------
1678       -- Check_No_Identifier --
1679       -------------------------
1680
1681       procedure Check_No_Identifier (Arg : Node_Id) is
1682       begin
1683          if Nkind (Arg) = N_Pragma_Argument_Association
1684            and then Chars (Arg) /= No_Name
1685          then
1686             Error_Pragma_Arg_Ident
1687               ("pragma% does not permit identifier& here", Arg);
1688          end if;
1689       end Check_No_Identifier;
1690
1691       --------------------------
1692       -- Check_No_Identifiers --
1693       --------------------------
1694
1695       procedure Check_No_Identifiers is
1696          Arg_Node : Node_Id;
1697       begin
1698          if Arg_Count > 0 then
1699             Arg_Node := Arg1;
1700             while Present (Arg_Node) loop
1701                Check_No_Identifier (Arg_Node);
1702                Next (Arg_Node);
1703             end loop;
1704          end if;
1705       end Check_No_Identifiers;
1706
1707       ------------------------
1708       -- Check_No_Link_Name --
1709       ------------------------
1710
1711       procedure Check_No_Link_Name is
1712       begin
1713          if Present (Arg3)
1714            and then Chars (Arg3) = Name_Link_Name
1715          then
1716             Arg4 := Arg3;
1717          end if;
1718
1719          if Present (Arg4) then
1720             Error_Pragma_Arg
1721               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1722          end if;
1723       end Check_No_Link_Name;
1724
1725       -------------------------------
1726       -- Check_Optional_Identifier --
1727       -------------------------------
1728
1729       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1730       begin
1731          if Present (Arg)
1732            and then Nkind (Arg) = N_Pragma_Argument_Association
1733            and then Chars (Arg) /= No_Name
1734          then
1735             if Chars (Arg) /= Id then
1736                Error_Msg_Name_1 := Pname;
1737                Error_Msg_Name_2 := Id;
1738                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1739                raise Pragma_Exit;
1740             end if;
1741          end if;
1742       end Check_Optional_Identifier;
1743
1744       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1745       begin
1746          Name_Buffer (1 .. Id'Length) := Id;
1747          Name_Len := Id'Length;
1748          Check_Optional_Identifier (Arg, Name_Find);
1749       end Check_Optional_Identifier;
1750
1751       --------------------------------------
1752       -- Check_Precondition_Postcondition --
1753       --------------------------------------
1754
1755       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1756          P  : Node_Id;
1757          PO : Node_Id;
1758
1759          procedure Chain_PPC (PO : Node_Id);
1760          --  If PO is an entry or a [generic] subprogram declaration node, then
1761          --  the precondition/postcondition applies to this subprogram and the
1762          --  processing for the pragma is completed. Otherwise the pragma is
1763          --  misplaced.
1764
1765          ---------------
1766          -- Chain_PPC --
1767          ---------------
1768
1769          procedure Chain_PPC (PO : Node_Id) is
1770             S   : Entity_Id;
1771             P   : Node_Id;
1772
1773          begin
1774             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1775                if not From_Aspect_Specification (N) then
1776                   Error_Pragma
1777                     ("pragma% cannot be applied to abstract subprogram");
1778
1779                elsif Class_Present (N) then
1780                   null;
1781
1782                else
1783                   Error_Pragma
1784                     ("aspect % requires ''Class for abstract subprogram");
1785                end if;
1786
1787             --  AI05-0230: The same restriction applies to null procedures. For
1788             --  compatibility with earlier uses of the Ada pragma, apply this
1789             --  rule only to aspect specifications.
1790
1791             --  The above discrpency needs documentation. Robert is dubious
1792             --  about whether it is a good idea ???
1793
1794             elsif Nkind (PO) = N_Subprogram_Declaration
1795               and then Nkind (Specification (PO)) = N_Procedure_Specification
1796               and then Null_Present (Specification (PO))
1797               and then From_Aspect_Specification (N)
1798               and then not Class_Present (N)
1799             then
1800                Error_Pragma
1801                  ("aspect % requires ''Class for null procedure");
1802
1803             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1804                                     N_Generic_Subprogram_Declaration,
1805                                     N_Entry_Declaration)
1806             then
1807                Pragma_Misplaced;
1808             end if;
1809
1810             --  Here if we have [generic] subprogram or entry declaration
1811
1812             if Nkind (PO) = N_Entry_Declaration then
1813                S := Defining_Entity (PO);
1814             else
1815                S := Defining_Unit_Name (Specification (PO));
1816             end if;
1817
1818             --  Make sure we do not have the case of a precondition pragma when
1819             --  the Pre'Class aspect is present.
1820
1821             --  We do this by looking at pragmas already chained to the entity
1822             --  since the aspect derived pragma will be put on this list first.
1823
1824             if Pragma_Name (N) = Name_Precondition then
1825                if not From_Aspect_Specification (N) then
1826                   P := Spec_PPC_List (Contract (S));
1827                   while Present (P) loop
1828                      if Pragma_Name (P) = Name_Precondition
1829                        and then From_Aspect_Specification (P)
1830                        and then Class_Present (P)
1831                      then
1832                         Error_Msg_Sloc := Sloc (P);
1833                         Error_Pragma
1834                           ("pragma% not allowed, `Pre''Class` aspect given#");
1835                      end if;
1836
1837                      P := Next_Pragma (P);
1838                   end loop;
1839                end if;
1840             end if;
1841
1842             --  Similarly check for Pre with inherited Pre'Class. Note that
1843             --  we cover the aspect case as well here.
1844
1845             if Pragma_Name (N) = Name_Precondition
1846               and then not Class_Present (N)
1847             then
1848                declare
1849                   Inherited : constant Subprogram_List :=
1850                                 Inherited_Subprograms (S);
1851                   P         : Node_Id;
1852
1853                begin
1854                   for J in Inherited'Range loop
1855                      P := Spec_PPC_List (Contract (Inherited (J)));
1856                      while Present (P) loop
1857                         if Pragma_Name (P) = Name_Precondition
1858                           and then Class_Present (P)
1859                         then
1860                            Error_Msg_Sloc := Sloc (P);
1861                            Error_Pragma
1862                              ("pragma% not allowed, `Pre''Class` "
1863                               & "aspect inherited from#");
1864                         end if;
1865
1866                         P := Next_Pragma (P);
1867                      end loop;
1868                   end loop;
1869                end;
1870             end if;
1871
1872             --  Note: we do not analyze the pragma at this point. Instead we
1873             --  delay this analysis until the end of the declarative part in
1874             --  which the pragma appears. This implements the required delay
1875             --  in this analysis, allowing forward references. The analysis
1876             --  happens at the end of Analyze_Declarations.
1877
1878             --  Chain spec PPC pragma to list for subprogram
1879
1880             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1881             Set_Spec_PPC_List (Contract (S), N);
1882
1883             --  Return indicating spec case
1884
1885             In_Body := False;
1886             return;
1887          end Chain_PPC;
1888
1889       --  Start of processing for Check_Precondition_Postcondition
1890
1891       begin
1892          if not Is_List_Member (N) then
1893             Pragma_Misplaced;
1894          end if;
1895
1896          --  Preanalyze message argument if present. Visibility in this
1897          --  argument is established at the point of pragma occurrence.
1898
1899          if Arg_Count = 2 then
1900             Check_Optional_Identifier (Arg2, Name_Message);
1901             Preanalyze_Spec_Expression
1902               (Get_Pragma_Arg (Arg2), Standard_String);
1903          end if;
1904
1905          --  Record if pragma is disabled
1906
1907          if Check_Enabled (Pname) then
1908             Set_SCO_Pragma_Enabled (Loc);
1909          end if;
1910
1911          --  If we are within an inlined body, the legality of the pragma
1912          --  has been checked already.
1913
1914          if In_Inlined_Body then
1915             In_Body := True;
1916             return;
1917          end if;
1918
1919          --  Search prior declarations
1920
1921          P := N;
1922          while Present (Prev (P)) loop
1923             P := Prev (P);
1924
1925             --  If the previous node is a generic subprogram, do not go to to
1926             --  the original node, which is the unanalyzed tree: we need to
1927             --  attach the pre/postconditions to the analyzed version at this
1928             --  point. They get propagated to the original tree when analyzing
1929             --  the corresponding body.
1930
1931             if Nkind (P) not in N_Generic_Declaration then
1932                PO := Original_Node (P);
1933             else
1934                PO := P;
1935             end if;
1936
1937             --  Skip past prior pragma
1938
1939             if Nkind (PO) = N_Pragma then
1940                null;
1941
1942             --  Skip stuff not coming from source
1943
1944             elsif not Comes_From_Source (PO) then
1945
1946                --  The condition may apply to a subprogram instantiation
1947
1948                if Nkind (PO) = N_Subprogram_Declaration
1949                  and then Present (Generic_Parent (Specification (PO)))
1950                then
1951                   Chain_PPC (PO);
1952                   return;
1953
1954                elsif Nkind (PO) = N_Subprogram_Declaration
1955                  and then In_Instance
1956                then
1957                   Chain_PPC (PO);
1958                   return;
1959
1960                --  For all other cases of non source code, do nothing
1961
1962                else
1963                   null;
1964                end if;
1965
1966             --  Only remaining possibility is subprogram declaration
1967
1968             else
1969                Chain_PPC (PO);
1970                return;
1971             end if;
1972          end loop;
1973
1974          --  If we fall through loop, pragma is at start of list, so see if it
1975          --  is at the start of declarations of a subprogram body.
1976
1977          if Nkind (Parent (N)) = N_Subprogram_Body
1978            and then List_Containing (N) = Declarations (Parent (N))
1979          then
1980             if Operating_Mode /= Generate_Code
1981               or else Inside_A_Generic
1982             then
1983                --  Analyze pragma expression for correctness and for ASIS use
1984
1985                Preanalyze_Spec_Expression
1986                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
1987             end if;
1988
1989             In_Body := True;
1990             return;
1991
1992          --  See if it is in the pragmas after a library level subprogram
1993
1994          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1995
1996             --  In formal verification mode, analyze pragma expression for
1997             --  correctness, as it is not expanded later.
1998
1999             if Alfa_Mode then
2000                Analyze_PPC_In_Decl_Part
2001                  (N, Defining_Entity (Unit (Parent (Parent (N)))));
2002             end if;
2003
2004             Chain_PPC (Unit (Parent (Parent (N))));
2005             return;
2006          end if;
2007
2008          --  If we fall through, pragma was misplaced
2009
2010          Pragma_Misplaced;
2011       end Check_Precondition_Postcondition;
2012
2013       -----------------------------
2014       -- Check_Static_Constraint --
2015       -----------------------------
2016
2017       --  Note: for convenience in writing this procedure, in addition to
2018       --  the officially (i.e. by spec) allowed argument which is always a
2019       --  constraint, it also allows ranges and discriminant associations.
2020       --  Above is not clear ???
2021
2022       procedure Check_Static_Constraint (Constr : Node_Id) is
2023
2024          procedure Require_Static (E : Node_Id);
2025          --  Require given expression to be static expression
2026
2027          --------------------
2028          -- Require_Static --
2029          --------------------
2030
2031          procedure Require_Static (E : Node_Id) is
2032          begin
2033             if not Is_OK_Static_Expression (E) then
2034                Flag_Non_Static_Expr
2035                  ("non-static constraint not allowed in Unchecked_Union!", E);
2036                raise Pragma_Exit;
2037             end if;
2038          end Require_Static;
2039
2040       --  Start of processing for Check_Static_Constraint
2041
2042       begin
2043          case Nkind (Constr) is
2044             when N_Discriminant_Association =>
2045                Require_Static (Expression (Constr));
2046
2047             when N_Range =>
2048                Require_Static (Low_Bound (Constr));
2049                Require_Static (High_Bound (Constr));
2050
2051             when N_Attribute_Reference =>
2052                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
2053                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
2054
2055             when N_Range_Constraint =>
2056                Check_Static_Constraint (Range_Expression (Constr));
2057
2058             when N_Index_Or_Discriminant_Constraint =>
2059                declare
2060                   IDC : Entity_Id;
2061                begin
2062                   IDC := First (Constraints (Constr));
2063                   while Present (IDC) loop
2064                      Check_Static_Constraint (IDC);
2065                      Next (IDC);
2066                   end loop;
2067                end;
2068
2069             when others =>
2070                null;
2071          end case;
2072       end Check_Static_Constraint;
2073
2074       ---------------------
2075       -- Check_Test_Case --
2076       ---------------------
2077
2078       procedure Check_Test_Case is
2079          P  : Node_Id;
2080          PO : Node_Id;
2081
2082          procedure Chain_TC (PO : Node_Id);
2083          --  If PO is a [generic] subprogram declaration node, then the
2084          --  test-case applies to this subprogram and the processing for the
2085          --  pragma is completed. Otherwise the pragma is misplaced.
2086
2087          --------------
2088          -- Chain_TC --
2089          --------------
2090
2091          procedure Chain_TC (PO : Node_Id) is
2092             S   : Entity_Id;
2093
2094          begin
2095             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
2096                if From_Aspect_Specification (N) then
2097                   Error_Pragma
2098                     ("aspect% cannot be applied to abstract subprogram");
2099                else
2100                   Error_Pragma
2101                     ("pragma% cannot be applied to abstract subprogram");
2102                end if;
2103
2104             elsif Nkind (PO) = N_Entry_Declaration then
2105                if From_Aspect_Specification (N) then
2106                   Error_Pragma ("aspect% cannot be applied to entry");
2107                else
2108                   Error_Pragma ("pragma% cannot be applied to entry");
2109                end if;
2110
2111             elsif not Nkind_In (PO, N_Subprogram_Declaration,
2112                                     N_Generic_Subprogram_Declaration)
2113             then
2114                Pragma_Misplaced;
2115             end if;
2116
2117             --  Here if we have [generic] subprogram declaration
2118
2119             S := Defining_Unit_Name (Specification (PO));
2120
2121             --  Note: we do not analyze the pragma at this point. Instead we
2122             --  delay this analysis until the end of the declarative part in
2123             --  which the pragma appears. This implements the required delay
2124             --  in this analysis, allowing forward references. The analysis
2125             --  happens at the end of Analyze_Declarations.
2126
2127             --  There should not be another test case with the same name
2128             --  associated to this subprogram.
2129
2130             declare
2131                Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2132                TC   : Node_Id;
2133
2134             begin
2135                TC := Spec_TC_List (Contract (S));
2136                while Present (TC) loop
2137
2138                   if String_Equal
2139                     (Name, Get_Name_From_Test_Case_Pragma (TC))
2140                   then
2141                      Error_Msg_Sloc := Sloc (TC);
2142
2143                      if From_Aspect_Specification (N) then
2144                         Error_Pragma ("name for aspect% is already used#");
2145                      else
2146                         Error_Pragma ("name for pragma% is already used#");
2147                      end if;
2148                   end if;
2149
2150                   TC := Next_Pragma (TC);
2151                end loop;
2152             end;
2153
2154             --  Chain spec TC pragma to list for subprogram
2155
2156             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2157             Set_Spec_TC_List (Contract (S), N);
2158          end Chain_TC;
2159
2160       --  Start of processing for Check_Test_Case
2161
2162       begin
2163          if not Is_List_Member (N) then
2164             Pragma_Misplaced;
2165          end if;
2166
2167          --  Test cases should only appear in package spec unit
2168
2169          if Get_Source_Unit (N) = No_Unit
2170            or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2171                                  N_Package_Declaration,
2172                                  N_Generic_Package_Declaration)
2173          then
2174             Pragma_Misplaced;
2175          end if;
2176
2177          --  Search prior declarations
2178
2179          P := N;
2180          while Present (Prev (P)) loop
2181             P := Prev (P);
2182
2183             --  If the previous node is a generic subprogram, do not go to to
2184             --  the original node, which is the unanalyzed tree: we need to
2185             --  attach the test-case to the analyzed version at this point.
2186             --  They get propagated to the original tree when analyzing the
2187             --  corresponding body.
2188
2189             if Nkind (P) not in N_Generic_Declaration then
2190                PO := Original_Node (P);
2191             else
2192                PO := P;
2193             end if;
2194
2195             --  Skip past prior pragma
2196
2197             if Nkind (PO) = N_Pragma then
2198                null;
2199
2200             --  Skip stuff not coming from source
2201
2202             elsif not Comes_From_Source (PO) then
2203                null;
2204
2205             --  Only remaining possibility is subprogram declaration. First
2206             --  check that it is declared directly in a package declaration.
2207             --  This may be either the package declaration for the current unit
2208             --  being defined or a local package declaration.
2209
2210             elsif not Present (Parent (Parent (PO)))
2211               or else not Present (Parent (Parent (Parent (PO))))
2212               or else not Nkind_In (Parent (Parent (PO)),
2213                                     N_Package_Declaration,
2214                                     N_Generic_Package_Declaration)
2215             then
2216                Pragma_Misplaced;
2217
2218             else
2219                Chain_TC (PO);
2220                return;
2221             end if;
2222          end loop;
2223
2224          --  If we fall through, pragma was misplaced
2225
2226          Pragma_Misplaced;
2227       end Check_Test_Case;
2228
2229       --------------------------------------
2230       -- Check_Valid_Configuration_Pragma --
2231       --------------------------------------
2232
2233       --  A configuration pragma must appear in the context clause of a
2234       --  compilation unit, and only other pragmas may precede it. Note that
2235       --  the test also allows use in a configuration pragma file.
2236
2237       procedure Check_Valid_Configuration_Pragma is
2238       begin
2239          if not Is_Configuration_Pragma then
2240             Error_Pragma ("incorrect placement for configuration pragma%");
2241          end if;
2242       end Check_Valid_Configuration_Pragma;
2243
2244       -------------------------------------
2245       -- Check_Valid_Library_Unit_Pragma --
2246       -------------------------------------
2247
2248       procedure Check_Valid_Library_Unit_Pragma is
2249          Plist       : List_Id;
2250          Parent_Node : Node_Id;
2251          Unit_Name   : Entity_Id;
2252          Unit_Kind   : Node_Kind;
2253          Unit_Node   : Node_Id;
2254          Sindex      : Source_File_Index;
2255
2256       begin
2257          if not Is_List_Member (N) then
2258             Pragma_Misplaced;
2259
2260          else
2261             Plist := List_Containing (N);
2262             Parent_Node := Parent (Plist);
2263
2264             if Parent_Node = Empty then
2265                Pragma_Misplaced;
2266
2267             --  Case of pragma appearing after a compilation unit. In this case
2268             --  it must have an argument with the corresponding name and must
2269             --  be part of the following pragmas of its parent.
2270
2271             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2272                if Plist /= Pragmas_After (Parent_Node) then
2273                   Pragma_Misplaced;
2274
2275                elsif Arg_Count = 0 then
2276                   Error_Pragma
2277                     ("argument required if outside compilation unit");
2278
2279                else
2280                   Check_No_Identifiers;
2281                   Check_Arg_Count (1);
2282                   Unit_Node := Unit (Parent (Parent_Node));
2283                   Unit_Kind := Nkind (Unit_Node);
2284
2285                   Analyze (Get_Pragma_Arg (Arg1));
2286
2287                   if Unit_Kind = N_Generic_Subprogram_Declaration
2288                     or else Unit_Kind = N_Subprogram_Declaration
2289                   then
2290                      Unit_Name := Defining_Entity (Unit_Node);
2291
2292                   elsif Unit_Kind in N_Generic_Instantiation then
2293                      Unit_Name := Defining_Entity (Unit_Node);
2294
2295                   else
2296                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2297                   end if;
2298
2299                   if Chars (Unit_Name) /=
2300                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2301                   then
2302                      Error_Pragma_Arg
2303                        ("pragma% argument is not current unit name", Arg1);
2304                   end if;
2305
2306                   if Ekind (Unit_Name) = E_Package
2307                     and then Present (Renamed_Entity (Unit_Name))
2308                   then
2309                      Error_Pragma ("pragma% not allowed for renamed package");
2310                   end if;
2311                end if;
2312
2313             --  Pragma appears other than after a compilation unit
2314
2315             else
2316                --  Here we check for the generic instantiation case and also
2317                --  for the case of processing a generic formal package. We
2318                --  detect these cases by noting that the Sloc on the node
2319                --  does not belong to the current compilation unit.
2320
2321                Sindex := Source_Index (Current_Sem_Unit);
2322
2323                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2324                   Rewrite (N, Make_Null_Statement (Loc));
2325                   return;
2326
2327                --  If before first declaration, the pragma applies to the
2328                --  enclosing unit, and the name if present must be this name.
2329
2330                elsif Is_Before_First_Decl (N, Plist) then
2331                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2332                   Unit_Kind := Nkind (Unit_Node);
2333
2334                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2335                      Pragma_Misplaced;
2336
2337                   elsif Unit_Kind = N_Subprogram_Body
2338                     and then not Acts_As_Spec (Unit_Node)
2339                   then
2340                      Pragma_Misplaced;
2341
2342                   elsif Nkind (Parent_Node) = N_Package_Body then
2343                      Pragma_Misplaced;
2344
2345                   elsif Nkind (Parent_Node) = N_Package_Specification
2346                     and then Plist = Private_Declarations (Parent_Node)
2347                   then
2348                      Pragma_Misplaced;
2349
2350                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2351                            or else Nkind (Parent_Node) =
2352                                              N_Generic_Subprogram_Declaration)
2353                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2354                   then
2355                      Pragma_Misplaced;
2356
2357                   elsif Arg_Count > 0 then
2358                      Analyze (Get_Pragma_Arg (Arg1));
2359
2360                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2361                         Error_Pragma_Arg
2362                           ("name in pragma% must be enclosing unit", Arg1);
2363                      end if;
2364
2365                   --  It is legal to have no argument in this context
2366
2367                   else
2368                      return;
2369                   end if;
2370
2371                --  Error if not before first declaration. This is because a
2372                --  library unit pragma argument must be the name of a library
2373                --  unit (RM 10.1.5(7)), but the only names permitted in this
2374                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2375                --  generic subprogram declarations or generic instantiations.
2376
2377                else
2378                   Error_Pragma
2379                     ("pragma% misplaced, must be before first declaration");
2380                end if;
2381             end if;
2382          end if;
2383       end Check_Valid_Library_Unit_Pragma;
2384
2385       -------------------
2386       -- Check_Variant --
2387       -------------------
2388
2389       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2390          Clist : constant Node_Id := Component_List (Variant);
2391          Comp  : Node_Id;
2392
2393       begin
2394          if not Is_Non_Empty_List (Component_Items (Clist)) then
2395             Error_Msg_N
2396               ("Unchecked_Union may not have empty component list",
2397                Variant);
2398             return;
2399          end if;
2400
2401          Comp := First (Component_Items (Clist));
2402          while Present (Comp) loop
2403             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2404             Next (Comp);
2405          end loop;
2406       end Check_Variant;
2407
2408       ------------------
2409       -- Error_Pragma --
2410       ------------------
2411
2412       procedure Error_Pragma (Msg : String) is
2413          MsgF : String := Msg;
2414       begin
2415          Error_Msg_Name_1 := Pname;
2416          Fix_Error (MsgF);
2417          Error_Msg_N (MsgF, N);
2418          raise Pragma_Exit;
2419       end Error_Pragma;
2420
2421       ----------------------
2422       -- Error_Pragma_Arg --
2423       ----------------------
2424
2425       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2426          MsgF : String := Msg;
2427       begin
2428          Error_Msg_Name_1 := Pname;
2429          Fix_Error (MsgF);
2430          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2431          raise Pragma_Exit;
2432       end Error_Pragma_Arg;
2433
2434       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2435          MsgF : String := Msg1;
2436       begin
2437          Error_Msg_Name_1 := Pname;
2438          Fix_Error (MsgF);
2439          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2440          Error_Pragma_Arg (Msg2, Arg);
2441       end Error_Pragma_Arg;
2442
2443       -------------------------------------
2444       -- Error_Pragma_Arg_Alternate_Name --
2445       -------------------------------------
2446
2447       procedure Error_Pragma_Arg_Alternate_Name
2448         (Msg      : String;
2449          Arg      : Node_Id;
2450          Alt_Name : Name_Id)
2451       is
2452          MsgF        : String := Msg;
2453          Source_Name : String := Exact_Source_Name (Sloc (Arg));
2454          Alter_Name  : String := Get_Name_String (Alt_Name);
2455
2456       begin
2457          System.Case_Util.To_Lower (Source_Name);
2458          System.Case_Util.To_Lower (Alter_Name);
2459
2460          if Source_Name = Alter_Name then
2461             Error_Msg_Name_1 := Alt_Name;
2462          else
2463             Error_Msg_Name_1 := Pname;
2464          end if;
2465
2466          Fix_Error (MsgF);
2467          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2468          raise Pragma_Exit;
2469       end Error_Pragma_Arg_Alternate_Name;
2470
2471       ----------------------------
2472       -- Error_Pragma_Arg_Ident --
2473       ----------------------------
2474
2475       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2476          MsgF : String := Msg;
2477       begin
2478          Error_Msg_Name_1 := Pname;
2479          Fix_Error (MsgF);
2480          Error_Msg_N (MsgF, Arg);
2481          raise Pragma_Exit;
2482       end Error_Pragma_Arg_Ident;
2483
2484       ----------------------
2485       -- Error_Pragma_Ref --
2486       ----------------------
2487
2488       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2489          MsgF : String := Msg;
2490       begin
2491          Error_Msg_Name_1 := Pname;
2492          Fix_Error (MsgF);
2493          Error_Msg_Sloc   := Sloc (Ref);
2494          Error_Msg_NE (MsgF, N, Ref);
2495          raise Pragma_Exit;
2496       end Error_Pragma_Ref;
2497
2498       ------------------------
2499       -- Find_Lib_Unit_Name --
2500       ------------------------
2501
2502       function Find_Lib_Unit_Name return Entity_Id is
2503       begin
2504          --  Return inner compilation unit entity, for case of nested
2505          --  categorization pragmas. This happens in generic unit.
2506
2507          if Nkind (Parent (N)) = N_Package_Specification
2508            and then Defining_Entity (Parent (N)) /= Current_Scope
2509          then
2510             return Defining_Entity (Parent (N));
2511          else
2512             return Current_Scope;
2513          end if;
2514       end Find_Lib_Unit_Name;
2515
2516       ----------------------------
2517       -- Find_Program_Unit_Name --
2518       ----------------------------
2519
2520       procedure Find_Program_Unit_Name (Id : Node_Id) is
2521          Unit_Name : Entity_Id;
2522          Unit_Kind : Node_Kind;
2523          P         : constant Node_Id := Parent (N);
2524
2525       begin
2526          if Nkind (P) = N_Compilation_Unit then
2527             Unit_Kind := Nkind (Unit (P));
2528
2529             if Unit_Kind = N_Subprogram_Declaration
2530               or else Unit_Kind = N_Package_Declaration
2531               or else Unit_Kind in N_Generic_Declaration
2532             then
2533                Unit_Name := Defining_Entity (Unit (P));
2534
2535                if Chars (Id) = Chars (Unit_Name) then
2536                   Set_Entity (Id, Unit_Name);
2537                   Set_Etype (Id, Etype (Unit_Name));
2538                else
2539                   Set_Etype (Id, Any_Type);
2540                   Error_Pragma
2541                     ("cannot find program unit referenced by pragma%");
2542                end if;
2543
2544             else
2545                Set_Etype (Id, Any_Type);
2546                Error_Pragma ("pragma% inapplicable to this unit");
2547             end if;
2548
2549          else
2550             Analyze (Id);
2551          end if;
2552       end Find_Program_Unit_Name;
2553
2554       -----------------------------------------
2555       -- Find_Unique_Parameterless_Procedure --
2556       -----------------------------------------
2557
2558       function Find_Unique_Parameterless_Procedure
2559         (Name : Entity_Id;
2560          Arg  : Node_Id) return Entity_Id
2561       is
2562          Proc : Entity_Id := Empty;
2563
2564       begin
2565          --  The body of this procedure needs some comments ???
2566
2567          if not Is_Entity_Name (Name) then
2568             Error_Pragma_Arg
2569               ("argument of pragma% must be entity name", Arg);
2570
2571          elsif not Is_Overloaded (Name) then
2572             Proc := Entity (Name);
2573
2574             if Ekind (Proc) /= E_Procedure
2575               or else Present (First_Formal (Proc))
2576             then
2577                Error_Pragma_Arg
2578                  ("argument of pragma% must be parameterless procedure", Arg);
2579             end if;
2580
2581          else
2582             declare
2583                Found : Boolean := False;
2584                It    : Interp;
2585                Index : Interp_Index;
2586
2587             begin
2588                Get_First_Interp (Name, Index, It);
2589                while Present (It.Nam) loop
2590                   Proc := It.Nam;
2591
2592                   if Ekind (Proc) = E_Procedure
2593                     and then No (First_Formal (Proc))
2594                   then
2595                      if not Found then
2596                         Found := True;
2597                         Set_Entity (Name, Proc);
2598                         Set_Is_Overloaded (Name, False);
2599                      else
2600                         Error_Pragma_Arg
2601                           ("ambiguous handler name for pragma% ", Arg);
2602                      end if;
2603                   end if;
2604
2605                   Get_Next_Interp (Index, It);
2606                end loop;
2607
2608                if not Found then
2609                   Error_Pragma_Arg
2610                     ("argument of pragma% must be parameterless procedure",
2611                      Arg);
2612                else
2613                   Proc := Entity (Name);
2614                end if;
2615             end;
2616          end if;
2617
2618          return Proc;
2619       end Find_Unique_Parameterless_Procedure;
2620
2621       ---------------
2622       -- Fix_Error --
2623       ---------------
2624
2625       procedure Fix_Error (Msg : in out String) is
2626       begin
2627          if From_Aspect_Specification (N) then
2628             for J in Msg'First .. Msg'Last - 5 loop
2629                if Msg (J .. J + 5) = "pragma" then
2630                   Msg (J .. J + 5) := "aspect";
2631                end if;
2632             end loop;
2633
2634             if Error_Msg_Name_1 = Name_Precondition then
2635                Error_Msg_Name_1 := Name_Pre;
2636             elsif Error_Msg_Name_1 = Name_Postcondition then
2637                Error_Msg_Name_1 := Name_Post;
2638             end if;
2639          end if;
2640       end Fix_Error;
2641
2642       -------------------------
2643       -- Gather_Associations --
2644       -------------------------
2645
2646       procedure Gather_Associations
2647         (Names : Name_List;
2648          Args  : out Args_List)
2649       is
2650          Arg : Node_Id;
2651
2652       begin
2653          --  Initialize all parameters to Empty
2654
2655          for J in Args'Range loop
2656             Args (J) := Empty;
2657          end loop;
2658
2659          --  That's all we have to do if there are no argument associations
2660
2661          if No (Pragma_Argument_Associations (N)) then
2662             return;
2663          end if;
2664
2665          --  Otherwise first deal with any positional parameters present
2666
2667          Arg := First (Pragma_Argument_Associations (N));
2668          for Index in Args'Range loop
2669             exit when No (Arg) or else Chars (Arg) /= No_Name;
2670             Args (Index) := Get_Pragma_Arg (Arg);
2671             Next (Arg);
2672          end loop;
2673
2674          --  Positional parameters all processed, if any left, then we
2675          --  have too many positional parameters.
2676
2677          if Present (Arg) and then Chars (Arg) = No_Name then
2678             Error_Pragma_Arg
2679               ("too many positional associations for pragma%", Arg);
2680          end if;
2681
2682          --  Process named parameters if any are present
2683
2684          while Present (Arg) loop
2685             if Chars (Arg) = No_Name then
2686                Error_Pragma_Arg
2687                  ("positional association cannot follow named association",
2688                   Arg);
2689
2690             else
2691                for Index in Names'Range loop
2692                   if Names (Index) = Chars (Arg) then
2693                      if Present (Args (Index)) then
2694                         Error_Pragma_Arg
2695                           ("duplicate argument association for pragma%", Arg);
2696                      else
2697                         Args (Index) := Get_Pragma_Arg (Arg);
2698                         exit;
2699                      end if;
2700                   end if;
2701
2702                   if Index = Names'Last then
2703                      Error_Msg_Name_1 := Pname;
2704                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2705
2706                      --  Check for possible misspelling
2707
2708                      for Index1 in Names'Range loop
2709                         if Is_Bad_Spelling_Of
2710                              (Chars (Arg), Names (Index1))
2711                         then
2712                            Error_Msg_Name_1 := Names (Index1);
2713                            Error_Msg_N -- CODEFIX
2714                              ("\possible misspelling of%", Arg);
2715                            exit;
2716                         end if;
2717                      end loop;
2718
2719                      raise Pragma_Exit;
2720                   end if;
2721                end loop;
2722             end if;
2723
2724             Next (Arg);
2725          end loop;
2726       end Gather_Associations;
2727
2728       -----------------
2729       -- GNAT_Pragma --
2730       -----------------
2731
2732       procedure GNAT_Pragma is
2733       begin
2734          Check_Restriction (No_Implementation_Pragmas, N);
2735       end GNAT_Pragma;
2736
2737       --------------------------
2738       -- Is_Before_First_Decl --
2739       --------------------------
2740
2741       function Is_Before_First_Decl
2742         (Pragma_Node : Node_Id;
2743          Decls       : List_Id) return Boolean
2744       is
2745          Item : Node_Id := First (Decls);
2746
2747       begin
2748          --  Only other pragmas can come before this pragma
2749
2750          loop
2751             if No (Item) or else Nkind (Item) /= N_Pragma then
2752                return False;
2753
2754             elsif Item = Pragma_Node then
2755                return True;
2756             end if;
2757
2758             Next (Item);
2759          end loop;
2760       end Is_Before_First_Decl;
2761
2762       -----------------------------
2763       -- Is_Configuration_Pragma --
2764       -----------------------------
2765
2766       --  A configuration pragma must appear in the context clause of a
2767       --  compilation unit, and only other pragmas may precede it. Note that
2768       --  the test below also permits use in a configuration pragma file.
2769
2770       function Is_Configuration_Pragma return Boolean is
2771          Lis : constant List_Id := List_Containing (N);
2772          Par : constant Node_Id := Parent (N);
2773          Prg : Node_Id;
2774
2775       begin
2776          --  If no parent, then we are in the configuration pragma file,
2777          --  so the placement is definitely appropriate.
2778
2779          if No (Par) then
2780             return True;
2781
2782          --  Otherwise we must be in the context clause of a compilation unit
2783          --  and the only thing allowed before us in the context list is more
2784          --  configuration pragmas.
2785
2786          elsif Nkind (Par) = N_Compilation_Unit
2787            and then Context_Items (Par) = Lis
2788          then
2789             Prg := First (Lis);
2790
2791             loop
2792                if Prg = N then
2793                   return True;
2794                elsif Nkind (Prg) /= N_Pragma then
2795                   return False;
2796                end if;
2797
2798                Next (Prg);
2799             end loop;
2800
2801          else
2802             return False;
2803          end if;
2804       end Is_Configuration_Pragma;
2805
2806       --------------------------
2807       -- Is_In_Context_Clause --
2808       --------------------------
2809
2810       function Is_In_Context_Clause return Boolean is
2811          Plist       : List_Id;
2812          Parent_Node : Node_Id;
2813
2814       begin
2815          if not Is_List_Member (N) then
2816             return False;
2817
2818          else
2819             Plist := List_Containing (N);
2820             Parent_Node := Parent (Plist);
2821
2822             if Parent_Node = Empty
2823               or else Nkind (Parent_Node) /= N_Compilation_Unit
2824               or else Context_Items (Parent_Node) /= Plist
2825             then
2826                return False;
2827             end if;
2828          end if;
2829
2830          return True;
2831       end Is_In_Context_Clause;
2832
2833       ---------------------------------
2834       -- Is_Static_String_Expression --
2835       ---------------------------------
2836
2837       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2838          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2839
2840       begin
2841          Analyze_And_Resolve (Argx);
2842          return Is_OK_Static_Expression (Argx)
2843            and then Nkind (Argx) = N_String_Literal;
2844       end Is_Static_String_Expression;
2845
2846       ----------------------
2847       -- Pragma_Misplaced --
2848       ----------------------
2849
2850       procedure Pragma_Misplaced is
2851       begin
2852          Error_Pragma ("incorrect placement of pragma%");
2853       end Pragma_Misplaced;
2854
2855       ------------------------------------
2856       -- Process Atomic_Shared_Volatile --
2857       ------------------------------------
2858
2859       procedure Process_Atomic_Shared_Volatile is
2860          E_Id : Node_Id;
2861          E    : Entity_Id;
2862          D    : Node_Id;
2863          K    : Node_Kind;
2864          Utyp : Entity_Id;
2865
2866          procedure Set_Atomic (E : Entity_Id);
2867          --  Set given type as atomic, and if no explicit alignment was given,
2868          --  set alignment to unknown, since back end knows what the alignment
2869          --  requirements are for atomic arrays. Note: this step is necessary
2870          --  for derived types.
2871
2872          ----------------
2873          -- Set_Atomic --
2874          ----------------
2875
2876          procedure Set_Atomic (E : Entity_Id) is
2877          begin
2878             Set_Is_Atomic (E);
2879
2880             if not Has_Alignment_Clause (E) then
2881                Set_Alignment (E, Uint_0);
2882             end if;
2883          end Set_Atomic;
2884
2885       --  Start of processing for Process_Atomic_Shared_Volatile
2886
2887       begin
2888          Check_Ada_83_Warning;
2889          Check_No_Identifiers;
2890          Check_Arg_Count (1);
2891          Check_Arg_Is_Local_Name (Arg1);
2892          E_Id := Get_Pragma_Arg (Arg1);
2893
2894          if Etype (E_Id) = Any_Type then
2895             return;
2896          end if;
2897
2898          E := Entity (E_Id);
2899          D := Declaration_Node (E);
2900          K := Nkind (D);
2901
2902          --  Check duplicate before we chain ourselves!
2903
2904          Check_Duplicate_Pragma (E);
2905
2906          --  Now check appropriateness of the entity
2907
2908          if Is_Type (E) then
2909             if Rep_Item_Too_Early (E, N)
2910                  or else
2911                Rep_Item_Too_Late (E, N)
2912             then
2913                return;
2914             else
2915                Check_First_Subtype (Arg1);
2916             end if;
2917
2918             if Prag_Id /= Pragma_Volatile then
2919                Set_Atomic (E);
2920                Set_Atomic (Underlying_Type (E));
2921                Set_Atomic (Base_Type (E));
2922             end if;
2923
2924             --  Attribute belongs on the base type. If the view of the type is
2925             --  currently private, it also belongs on the underlying type.
2926
2927             Set_Is_Volatile (Base_Type (E));
2928             Set_Is_Volatile (Underlying_Type (E));
2929
2930             Set_Treat_As_Volatile (E);
2931             Set_Treat_As_Volatile (Underlying_Type (E));
2932
2933          elsif K = N_Object_Declaration
2934            or else (K = N_Component_Declaration
2935                      and then Original_Record_Component (E) = E)
2936          then
2937             if Rep_Item_Too_Late (E, N) then
2938                return;
2939             end if;
2940
2941             if Prag_Id /= Pragma_Volatile then
2942                Set_Is_Atomic (E);
2943
2944                --  If the object declaration has an explicit initialization, a
2945                --  temporary may have to be created to hold the expression, to
2946                --  ensure that access to the object remain atomic.
2947
2948                if Nkind (Parent (E)) = N_Object_Declaration
2949                  and then Present (Expression (Parent (E)))
2950                then
2951                   Set_Has_Delayed_Freeze (E);
2952                end if;
2953
2954                --  An interesting improvement here. If an object of type X is
2955                --  declared atomic, and the type X is not atomic, that's a
2956                --  pity, since it may not have appropriate alignment etc. We
2957                --  can rescue this in the special case where the object and
2958                --  type are in the same unit by just setting the type as
2959                --  atomic, so that the back end will process it as atomic.
2960
2961                Utyp := Underlying_Type (Etype (E));
2962
2963                if Present (Utyp)
2964                  and then Sloc (E) > No_Location
2965                  and then Sloc (Utyp) > No_Location
2966                  and then
2967                    Get_Source_File_Index (Sloc (E)) =
2968                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2969                then
2970                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2971                end if;
2972             end if;
2973
2974             Set_Is_Volatile (E);
2975             Set_Treat_As_Volatile (E);
2976
2977          else
2978             Error_Pragma_Arg
2979               ("inappropriate entity for pragma%", Arg1);
2980          end if;
2981       end Process_Atomic_Shared_Volatile;
2982
2983       -------------------------------------------
2984       -- Process_Compile_Time_Warning_Or_Error --
2985       -------------------------------------------
2986
2987       procedure Process_Compile_Time_Warning_Or_Error is
2988          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2989
2990       begin
2991          Check_Arg_Count (2);
2992          Check_No_Identifiers;
2993          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2994          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2995
2996          if Compile_Time_Known_Value (Arg1x) then
2997             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2998                declare
2999                   Str   : constant String_Id :=
3000                             Strval (Get_Pragma_Arg (Arg2));
3001                   Len   : constant Int := String_Length (Str);
3002                   Cont  : Boolean;
3003                   Ptr   : Nat;
3004                   CC    : Char_Code;
3005                   C     : Character;
3006                   Cent  : constant Entity_Id :=
3007                             Cunit_Entity (Current_Sem_Unit);
3008
3009                   Force : constant Boolean :=
3010                             Prag_Id = Pragma_Compile_Time_Warning
3011                               and then
3012                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
3013                               and then (Ekind (Cent) /= E_Package
3014                                           or else not In_Private_Part (Cent));
3015                   --  Set True if this is the warning case, and we are in the
3016                   --  visible part of a package spec, or in a subprogram spec,
3017                   --  in which case we want to force the client to see the
3018                   --  warning, even though it is not in the main unit.
3019
3020                begin
3021                   --  Loop through segments of message separated by line feeds.
3022                   --  We output these segments as separate messages with
3023                   --  continuation marks for all but the first.
3024
3025                   Cont := False;
3026                   Ptr := 1;
3027                   loop
3028                      Error_Msg_Strlen := 0;
3029
3030                      --  Loop to copy characters from argument to error message
3031                      --  string buffer.
3032
3033                      loop
3034                         exit when Ptr > Len;
3035                         CC := Get_String_Char (Str, Ptr);
3036                         Ptr := Ptr + 1;
3037
3038                         --  Ignore wide chars ??? else store character
3039
3040                         if In_Character_Range (CC) then
3041                            C := Get_Character (CC);
3042                            exit when C = ASCII.LF;
3043                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
3044                            Error_Msg_String (Error_Msg_Strlen) := C;
3045                         end if;
3046                      end loop;
3047
3048                      --  Here with one line ready to go
3049
3050                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
3051
3052                      --  If this is a warning in a spec, then we want clients
3053                      --  to see the warning, so mark the message with the
3054                      --  special sequence !! to force the warning. In the case
3055                      --  of a package spec, we do not force this if we are in
3056                      --  the private part of the spec.
3057
3058                      if Force then
3059                         if Cont = False then
3060                            Error_Msg_N ("<~!!", Arg1);
3061                            Cont := True;
3062                         else
3063                            Error_Msg_N ("\<~!!", Arg1);
3064                         end if;
3065
3066                      --  Error, rather than warning, or in a body, so we do not
3067                      --  need to force visibility for client (error will be
3068                      --  output in any case, and this is the situation in which
3069                      --  we do not want a client to get a warning, since the
3070                      --  warning is in the body or the spec private part).
3071
3072                      else
3073                         if Cont = False then
3074                            Error_Msg_N ("<~", Arg1);
3075                            Cont := True;
3076                         else
3077                            Error_Msg_N ("\<~", Arg1);
3078                         end if;
3079                      end if;
3080
3081                      exit when Ptr > Len;
3082                   end loop;
3083                end;
3084             end if;
3085          end if;
3086       end Process_Compile_Time_Warning_Or_Error;
3087
3088       ------------------------
3089       -- Process_Convention --
3090       ------------------------
3091
3092       procedure Process_Convention
3093         (C   : out Convention_Id;
3094          Ent : out Entity_Id)
3095       is
3096          Id        : Node_Id;
3097          E         : Entity_Id;
3098          E1        : Entity_Id;
3099          Cname     : Name_Id;
3100          Comp_Unit : Unit_Number_Type;
3101
3102          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
3103          --  Called if we have more than one Export/Import/Convention pragma.
3104          --  This is generally illegal, but we have a special case of allowing
3105          --  Import and Interface to coexist if they specify the convention in
3106          --  a consistent manner. We are allowed to do this, since Interface is
3107          --  an implementation defined pragma, and we choose to do it since we
3108          --  know Rational allows this combination. S is the entity id of the
3109          --  subprogram in question. This procedure also sets the special flag
3110          --  Import_Interface_Present in both pragmas in the case where we do
3111          --  have matching Import and Interface pragmas.
3112
3113          procedure Set_Convention_From_Pragma (E : Entity_Id);
3114          --  Set convention in entity E, and also flag that the entity has a
3115          --  convention pragma. If entity is for a private or incomplete type,
3116          --  also set convention and flag on underlying type. This procedure
3117          --  also deals with the special case of C_Pass_By_Copy convention.
3118
3119          -------------------------------
3120          -- Diagnose_Multiple_Pragmas --
3121          -------------------------------
3122
3123          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
3124             Pdec : constant Node_Id := Declaration_Node (S);
3125             Decl : Node_Id;
3126             Err  : Boolean;
3127
3128             function Same_Convention (Decl : Node_Id) return Boolean;
3129             --  Decl is a pragma node. This function returns True if this
3130             --  pragma has a first argument that is an identifier with a
3131             --  Chars field corresponding to the Convention_Id C.
3132
3133             function Same_Name (Decl : Node_Id) return Boolean;
3134             --  Decl is a pragma node. This function returns True if this
3135             --  pragma has a second argument that is an identifier with a
3136             --  Chars field that matches the Chars of the current subprogram.
3137
3138             ---------------------
3139             -- Same_Convention --
3140             ---------------------
3141
3142             function Same_Convention (Decl : Node_Id) return Boolean is
3143                Arg1 : constant Node_Id :=
3144                         First (Pragma_Argument_Associations (Decl));
3145
3146             begin
3147                if Present (Arg1) then
3148                   declare
3149                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3150                   begin
3151                      if Nkind (Arg) = N_Identifier
3152                        and then Is_Convention_Name (Chars (Arg))
3153                        and then Get_Convention_Id (Chars (Arg)) = C
3154                      then
3155                         return True;
3156                      end if;
3157                   end;
3158                end if;
3159
3160                return False;
3161             end Same_Convention;
3162
3163             ---------------
3164             -- Same_Name --
3165             ---------------
3166
3167             function Same_Name (Decl : Node_Id) return Boolean is
3168                Arg1 : constant Node_Id :=
3169                         First (Pragma_Argument_Associations (Decl));
3170                Arg2 : Node_Id;
3171
3172             begin
3173                if No (Arg1) then
3174                   return False;
3175                end if;
3176
3177                Arg2 := Next (Arg1);
3178
3179                if No (Arg2) then
3180                   return False;
3181                end if;
3182
3183                declare
3184                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3185                begin
3186                   if Nkind (Arg) = N_Identifier
3187                     and then Chars (Arg) = Chars (S)
3188                   then
3189                      return True;
3190                   end if;
3191                end;
3192
3193                return False;
3194             end Same_Name;
3195
3196          --  Start of processing for Diagnose_Multiple_Pragmas
3197
3198          begin
3199             Err := True;
3200
3201             --  Definitely give message if we have Convention/Export here
3202
3203             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3204                null;
3205
3206                --  If we have an Import or Export, scan back from pragma to
3207                --  find any previous pragma applying to the same procedure.
3208                --  The scan will be terminated by the start of the list, or
3209                --  hitting the subprogram declaration. This won't allow one
3210                --  pragma to appear in the public part and one in the private
3211                --  part, but that seems very unlikely in practice.
3212
3213             else
3214                Decl := Prev (N);
3215                while Present (Decl) and then Decl /= Pdec loop
3216
3217                   --  Look for pragma with same name as us
3218
3219                   if Nkind (Decl) = N_Pragma
3220                     and then Same_Name (Decl)
3221                   then
3222                      --  Give error if same as our pragma or Export/Convention
3223
3224                      if Pragma_Name (Decl) = Name_Export
3225                           or else
3226                         Pragma_Name (Decl) = Name_Convention
3227                           or else
3228                         Pragma_Name (Decl) = Pragma_Name (N)
3229                      then
3230                         exit;
3231
3232                      --  Case of Import/Interface or the other way round
3233
3234                      elsif Pragma_Name (Decl) = Name_Interface
3235                              or else
3236                            Pragma_Name (Decl) = Name_Import
3237                      then
3238                         --  Here we know that we have Import and Interface. It
3239                         --  doesn't matter which way round they are. See if
3240                         --  they specify the same convention. If so, all OK,
3241                         --  and set special flags to stop other messages
3242
3243                         if Same_Convention (Decl) then
3244                            Set_Import_Interface_Present (N);
3245                            Set_Import_Interface_Present (Decl);
3246                            Err := False;
3247
3248                         --  If different conventions, special message
3249
3250                         else
3251                            Error_Msg_Sloc := Sloc (Decl);
3252                            Error_Pragma_Arg
3253                              ("convention differs from that given#", Arg1);
3254                            return;
3255                         end if;
3256                      end if;
3257                   end if;
3258
3259                   Next (Decl);
3260                end loop;
3261             end if;
3262
3263             --  Give message if needed if we fall through those tests
3264
3265             if Err then
3266                Error_Pragma_Arg
3267                  ("at most one Convention/Export/Import pragma is allowed",
3268                   Arg2);
3269             end if;
3270          end Diagnose_Multiple_Pragmas;
3271
3272          --------------------------------
3273          -- Set_Convention_From_Pragma --
3274          --------------------------------
3275
3276          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3277          begin
3278             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3279             --  for an overridden dispatching operation. Technically this is
3280             --  an amendment and should only be done in Ada 2005 mode. However,
3281             --  this is clearly a mistake, since the problem that is addressed
3282             --  by this AI is that there is a clear gap in the RM!
3283
3284             if Is_Dispatching_Operation (E)
3285               and then Present (Overridden_Operation (E))
3286               and then C /= Convention (Overridden_Operation (E))
3287             then
3288                Error_Pragma_Arg
3289                  ("cannot change convention for " &
3290                   "overridden dispatching operation",
3291                   Arg1);
3292             end if;
3293
3294             --  Set the convention
3295
3296             Set_Convention (E, C);
3297             Set_Has_Convention_Pragma (E);
3298
3299             if Is_Incomplete_Or_Private_Type (E)
3300               and then Present (Underlying_Type (E))
3301             then
3302                Set_Convention            (Underlying_Type (E), C);
3303                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3304             end if;
3305
3306             --  A class-wide type should inherit the convention of the specific
3307             --  root type (although this isn't specified clearly by the RM).
3308
3309             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3310                Set_Convention (Class_Wide_Type (E), C);
3311             end if;
3312
3313             --  If the entity is a record type, then check for special case of
3314             --  C_Pass_By_Copy, which is treated the same as C except that the
3315             --  special record flag is set. This convention is only permitted
3316             --  on record types (see AI95-00131).
3317
3318             if Cname = Name_C_Pass_By_Copy then
3319                if Is_Record_Type (E) then
3320                   Set_C_Pass_By_Copy (Base_Type (E));
3321                elsif Is_Incomplete_Or_Private_Type (E)
3322                  and then Is_Record_Type (Underlying_Type (E))
3323                then
3324                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3325                else
3326                   Error_Pragma_Arg
3327                     ("C_Pass_By_Copy convention allowed only for record type",
3328                      Arg2);
3329                end if;
3330             end if;
3331
3332             --  If the entity is a derived boolean type, check for the special
3333             --  case of convention C, C++, or Fortran, where we consider any
3334             --  nonzero value to represent true.
3335
3336             if Is_Discrete_Type (E)
3337               and then Root_Type (Etype (E)) = Standard_Boolean
3338               and then
3339                 (C = Convention_C
3340                    or else
3341                  C = Convention_CPP
3342                    or else
3343                  C = Convention_Fortran)
3344             then
3345                Set_Nonzero_Is_True (Base_Type (E));
3346             end if;
3347          end Set_Convention_From_Pragma;
3348
3349       --  Start of processing for Process_Convention
3350
3351       begin
3352          Check_At_Least_N_Arguments (2);
3353          Check_Optional_Identifier (Arg1, Name_Convention);
3354          Check_Arg_Is_Identifier (Arg1);
3355          Cname := Chars (Get_Pragma_Arg (Arg1));
3356
3357          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3358          --  tested again below to set the critical flag).
3359
3360          if Cname = Name_C_Pass_By_Copy then
3361             C := Convention_C;
3362
3363          --  Otherwise we must have something in the standard convention list
3364
3365          elsif Is_Convention_Name (Cname) then
3366             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3367
3368          --  In DEC VMS, it seems that there is an undocumented feature that
3369          --  any unrecognized convention is treated as the default, which for
3370          --  us is convention C. It does not seem so terrible to do this
3371          --  unconditionally, silently in the VMS case, and with a warning
3372          --  in the non-VMS case.
3373
3374          else
3375             if Warn_On_Export_Import and not OpenVMS_On_Target then
3376                Error_Msg_N
3377                  ("?unrecognized convention name, C assumed",
3378                   Get_Pragma_Arg (Arg1));
3379             end if;
3380
3381             C := Convention_C;
3382          end if;
3383
3384          Check_Optional_Identifier (Arg2, Name_Entity);
3385          Check_Arg_Is_Local_Name (Arg2);
3386
3387          Id := Get_Pragma_Arg (Arg2);
3388          Analyze (Id);
3389
3390          if not Is_Entity_Name (Id) then
3391             Error_Pragma_Arg ("entity name required", Arg2);
3392          end if;
3393
3394          E := Entity (Id);
3395
3396          --  Set entity to return
3397
3398          Ent := E;
3399
3400          --  Ada_Pass_By_Copy special checking
3401
3402          if C = Convention_Ada_Pass_By_Copy then
3403             if not Is_First_Subtype (E) then
3404                Error_Pragma_Arg
3405                  ("convention `Ada_Pass_By_Copy` only "
3406                   & "allowed for types", Arg2);
3407             end if;
3408
3409             if Is_By_Reference_Type (E) then
3410                Error_Pragma_Arg
3411                  ("convention `Ada_Pass_By_Copy` not allowed for "
3412                   & "by-reference type", Arg1);
3413             end if;
3414          end if;
3415
3416          --  Ada_Pass_By_Reference special checking
3417
3418          if C = Convention_Ada_Pass_By_Reference then
3419             if not Is_First_Subtype (E) then
3420                Error_Pragma_Arg
3421                  ("convention `Ada_Pass_By_Reference` only "
3422                   & "allowed for types", Arg2);
3423             end if;
3424
3425             if Is_By_Copy_Type (E) then
3426                Error_Pragma_Arg
3427                  ("convention `Ada_Pass_By_Reference` not allowed for "
3428                   & "by-copy type", Arg1);
3429             end if;
3430          end if;
3431
3432          --  Go to renamed subprogram if present, since convention applies to
3433          --  the actual renamed entity, not to the renaming entity. If the
3434          --  subprogram is inherited, go to parent subprogram.
3435
3436          if Is_Subprogram (E)
3437            and then Present (Alias (E))
3438          then
3439             if Nkind (Parent (Declaration_Node (E))) =
3440                                        N_Subprogram_Renaming_Declaration
3441             then
3442                if Scope (E) /= Scope (Alias (E)) then
3443                   Error_Pragma_Ref
3444                     ("cannot apply pragma% to non-local entity&#", E);
3445                end if;
3446
3447                E := Alias (E);
3448
3449             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3450                                         N_Private_Extension_Declaration)
3451               and then Scope (E) = Scope (Alias (E))
3452             then
3453                E := Alias (E);
3454
3455                --  Return the parent subprogram the entity was inherited from
3456
3457                Ent := E;
3458             end if;
3459          end if;
3460
3461          --  Check that we are not applying this to a specless body
3462
3463          if Is_Subprogram (E)
3464            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3465          then
3466             Error_Pragma
3467               ("pragma% requires separate spec and must come before body");
3468          end if;
3469
3470          --  Check that we are not applying this to a named constant
3471
3472          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3473             Error_Msg_Name_1 := Pname;
3474             Error_Msg_N
3475               ("cannot apply pragma% to named constant!",
3476                Get_Pragma_Arg (Arg2));
3477             Error_Pragma_Arg
3478               ("\supply appropriate type for&!", Arg2);
3479          end if;
3480
3481          if Ekind (E) = E_Enumeration_Literal then
3482             Error_Pragma ("enumeration literal not allowed for pragma%");
3483          end if;
3484
3485          --  Check for rep item appearing too early or too late
3486
3487          if Etype (E) = Any_Type
3488            or else Rep_Item_Too_Early (E, N)
3489          then
3490             raise Pragma_Exit;
3491
3492          elsif Present (Underlying_Type (E)) then
3493             E := Underlying_Type (E);
3494          end if;
3495
3496          if Rep_Item_Too_Late (E, N) then
3497             raise Pragma_Exit;
3498          end if;
3499
3500          if Has_Convention_Pragma (E) then
3501             Diagnose_Multiple_Pragmas (E);
3502
3503          elsif Convention (E) = Convention_Protected
3504            or else Ekind (Scope (E)) = E_Protected_Type
3505          then
3506             Error_Pragma_Arg
3507               ("a protected operation cannot be given a different convention",
3508                 Arg2);
3509          end if;
3510
3511          --  For Intrinsic, a subprogram is required
3512
3513          if C = Convention_Intrinsic
3514            and then not Is_Subprogram (E)
3515            and then not Is_Generic_Subprogram (E)
3516          then
3517             Error_Pragma_Arg
3518               ("second argument of pragma% must be a subprogram", Arg2);
3519          end if;
3520
3521          --  For Stdcall, a subprogram, variable or subprogram type is required
3522
3523          if C = Convention_Stdcall
3524            and then not Is_Subprogram (E)
3525            and then not Is_Generic_Subprogram (E)
3526            and then Ekind (E) /= E_Variable
3527            and then not
3528              (Is_Access_Type (E)
3529                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3530          then
3531             Error_Pragma_Arg
3532               ("second argument of pragma% must be subprogram (type)",
3533                Arg2);
3534          end if;
3535
3536          if not Is_Subprogram (E)
3537            and then not Is_Generic_Subprogram (E)
3538          then
3539             Set_Convention_From_Pragma (E);
3540
3541             if Is_Type (E) then
3542                Check_First_Subtype (Arg2);
3543                Set_Convention_From_Pragma (Base_Type (E));
3544
3545                --  For subprograms, we must set the convention on the
3546                --  internally generated directly designated type as well.
3547
3548                if Ekind (E) = E_Access_Subprogram_Type then
3549                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3550                end if;
3551             end if;
3552
3553          --  For the subprogram case, set proper convention for all homonyms
3554          --  in same scope and the same declarative part, i.e. the same
3555          --  compilation unit.
3556
3557          else
3558             Comp_Unit := Get_Source_Unit (E);
3559             Set_Convention_From_Pragma (E);
3560
3561             --  Treat a pragma Import as an implicit body, for GPS use
3562
3563             if Prag_Id = Pragma_Import then
3564                Generate_Reference (E, Id, 'b');
3565             end if;
3566
3567             --  Loop through the homonyms of the pragma argument's entity
3568
3569             E1 := Ent;
3570             loop
3571                E1 := Homonym (E1);
3572                exit when No (E1) or else Scope (E1) /= Current_Scope;
3573
3574                --  Do not set the pragma on inherited operations or on formal
3575                --  subprograms.
3576
3577                if Comes_From_Source (E1)
3578                  and then Comp_Unit = Get_Source_Unit (E1)
3579                  and then not Is_Formal_Subprogram (E1)
3580                  and then Nkind (Original_Node (Parent (E1))) /=
3581                                                     N_Full_Type_Declaration
3582                then
3583                   if Present (Alias (E1))
3584                     and then Scope (E1) /= Scope (Alias (E1))
3585                   then
3586                      Error_Pragma_Ref
3587                        ("cannot apply pragma% to non-local entity& declared#",
3588                         E1);
3589                   end if;
3590
3591                   Set_Convention_From_Pragma (E1);
3592
3593                   if Prag_Id = Pragma_Import then
3594                      Generate_Reference (E1, Id, 'b');
3595                   end if;
3596                end if;
3597
3598                --  For aspect case, do NOT apply to homonyms
3599
3600                exit when From_Aspect_Specification (N);
3601             end loop;
3602          end if;
3603       end Process_Convention;
3604
3605       -----------------------------------------------------
3606       -- Process_Extended_Import_Export_Exception_Pragma --
3607       -----------------------------------------------------
3608
3609       procedure Process_Extended_Import_Export_Exception_Pragma
3610         (Arg_Internal : Node_Id;
3611          Arg_External : Node_Id;
3612          Arg_Form     : Node_Id;
3613          Arg_Code     : Node_Id)
3614       is
3615          Def_Id   : Entity_Id;
3616          Code_Val : Uint;
3617
3618       begin
3619          if not OpenVMS_On_Target then
3620             Error_Pragma
3621               ("?pragma% ignored (applies only to Open'V'M'S)");
3622          end if;
3623
3624          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3625          Def_Id := Entity (Arg_Internal);
3626
3627          if Ekind (Def_Id) /= E_Exception then
3628             Error_Pragma_Arg
3629               ("pragma% must refer to declared exception", Arg_Internal);
3630          end if;
3631
3632          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3633
3634          if Present (Arg_Form) then
3635             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3636          end if;
3637
3638          if Present (Arg_Form)
3639            and then Chars (Arg_Form) = Name_Ada
3640          then
3641             null;
3642          else
3643             Set_Is_VMS_Exception (Def_Id);
3644             Set_Exception_Code (Def_Id, No_Uint);
3645          end if;
3646
3647          if Present (Arg_Code) then
3648             if not Is_VMS_Exception (Def_Id) then
3649                Error_Pragma_Arg
3650                  ("Code option for pragma% not allowed for Ada case",
3651                   Arg_Code);
3652             end if;
3653
3654             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3655             Code_Val := Expr_Value (Arg_Code);
3656
3657             if not UI_Is_In_Int_Range (Code_Val) then
3658                Error_Pragma_Arg
3659                  ("Code option for pragma% must be in 32-bit range",
3660                   Arg_Code);
3661
3662             else
3663                Set_Exception_Code (Def_Id, Code_Val);
3664             end if;
3665          end if;
3666       end Process_Extended_Import_Export_Exception_Pragma;
3667
3668       -------------------------------------------------
3669       -- Process_Extended_Import_Export_Internal_Arg --
3670       -------------------------------------------------
3671
3672       procedure Process_Extended_Import_Export_Internal_Arg
3673         (Arg_Internal : Node_Id := Empty)
3674       is
3675       begin
3676          if No (Arg_Internal) then
3677             Error_Pragma ("Internal parameter required for pragma%");
3678          end if;
3679
3680          if Nkind (Arg_Internal) = N_Identifier then
3681             null;
3682
3683          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3684            and then (Prag_Id = Pragma_Import_Function
3685                        or else
3686                      Prag_Id = Pragma_Export_Function)
3687          then
3688             null;
3689
3690          else
3691             Error_Pragma_Arg
3692               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3693          end if;
3694
3695          Check_Arg_Is_Local_Name (Arg_Internal);
3696       end Process_Extended_Import_Export_Internal_Arg;
3697
3698       --------------------------------------------------
3699       -- Process_Extended_Import_Export_Object_Pragma --
3700       --------------------------------------------------
3701
3702       procedure Process_Extended_Import_Export_Object_Pragma
3703         (Arg_Internal : Node_Id;
3704          Arg_External : Node_Id;
3705          Arg_Size     : Node_Id)
3706       is
3707          Def_Id : Entity_Id;
3708
3709       begin
3710          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3711          Def_Id := Entity (Arg_Internal);
3712
3713          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3714             Error_Pragma_Arg
3715               ("pragma% must designate an object", Arg_Internal);
3716          end if;
3717
3718          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3719               or else
3720             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3721          then
3722             Error_Pragma_Arg
3723               ("previous Common/Psect_Object applies, pragma % not permitted",
3724                Arg_Internal);
3725          end if;
3726
3727          if Rep_Item_Too_Late (Def_Id, N) then
3728             raise Pragma_Exit;
3729          end if;
3730
3731          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3732
3733          if Present (Arg_Size) then
3734             Check_Arg_Is_External_Name (Arg_Size);
3735          end if;
3736
3737          --  Export_Object case
3738
3739          if Prag_Id = Pragma_Export_Object then
3740             if not Is_Library_Level_Entity (Def_Id) then
3741                Error_Pragma_Arg
3742                  ("argument for pragma% must be library level entity",
3743                   Arg_Internal);
3744             end if;
3745
3746             if Ekind (Current_Scope) = E_Generic_Package then
3747                Error_Pragma ("pragma& cannot appear in a generic unit");
3748             end if;
3749
3750             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3751                Error_Pragma_Arg
3752                  ("exported object must have compile time known size",
3753                   Arg_Internal);
3754             end if;
3755
3756             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3757                Error_Msg_N ("?duplicate Export_Object pragma", N);
3758             else
3759                Set_Exported (Def_Id, Arg_Internal);
3760             end if;
3761
3762          --  Import_Object case
3763
3764          else
3765             if Is_Concurrent_Type (Etype (Def_Id)) then
3766                Error_Pragma_Arg
3767                  ("cannot use pragma% for task/protected object",
3768                   Arg_Internal);
3769             end if;
3770
3771             if Ekind (Def_Id) = E_Constant then
3772                Error_Pragma_Arg
3773                  ("cannot import a constant", Arg_Internal);
3774             end if;
3775
3776             if Warn_On_Export_Import
3777               and then Has_Discriminants (Etype (Def_Id))
3778             then
3779                Error_Msg_N
3780                  ("imported value must be initialized?", Arg_Internal);
3781             end if;
3782
3783             if Warn_On_Export_Import
3784               and then Is_Access_Type (Etype (Def_Id))
3785             then
3786                Error_Pragma_Arg
3787                  ("cannot import object of an access type?", Arg_Internal);
3788             end if;
3789
3790             if Warn_On_Export_Import
3791               and then Is_Imported (Def_Id)
3792             then
3793                Error_Msg_N
3794                  ("?duplicate Import_Object pragma", N);
3795
3796             --  Check for explicit initialization present. Note that an
3797             --  initialization generated by the code generator, e.g. for an
3798             --  access type, does not count here.
3799
3800             elsif Present (Expression (Parent (Def_Id)))
3801                and then
3802                  Comes_From_Source
3803                    (Original_Node (Expression (Parent (Def_Id))))
3804             then
3805                Error_Msg_Sloc := Sloc (Def_Id);
3806                Error_Pragma_Arg
3807                  ("imported entities cannot be initialized (RM B.1(24))",
3808                   "\no initialization allowed for & declared#", Arg1);
3809             else
3810                Set_Imported (Def_Id);
3811                Note_Possible_Modification (Arg_Internal, Sure => False);
3812             end if;
3813          end if;
3814       end Process_Extended_Import_Export_Object_Pragma;
3815
3816       ------------------------------------------------------
3817       -- Process_Extended_Import_Export_Subprogram_Pragma --
3818       ------------------------------------------------------
3819
3820       procedure Process_Extended_Import_Export_Subprogram_Pragma
3821         (Arg_Internal                 : Node_Id;
3822          Arg_External                 : Node_Id;
3823          Arg_Parameter_Types          : Node_Id;
3824          Arg_Result_Type              : Node_Id := Empty;
3825          Arg_Mechanism                : Node_Id;
3826          Arg_Result_Mechanism         : Node_Id := Empty;
3827          Arg_First_Optional_Parameter : Node_Id := Empty)
3828       is
3829          Ent       : Entity_Id;
3830          Def_Id    : Entity_Id;
3831          Hom_Id    : Entity_Id;
3832          Formal    : Entity_Id;
3833          Ambiguous : Boolean;
3834          Match     : Boolean;
3835          Dval      : Node_Id;
3836
3837          function Same_Base_Type
3838           (Ptype  : Node_Id;
3839            Formal : Entity_Id) return Boolean;
3840          --  Determines if Ptype references the type of Formal. Note that only
3841          --  the base types need to match according to the spec. Ptype here is
3842          --  the argument from the pragma, which is either a type name, or an
3843          --  access attribute.
3844
3845          --------------------
3846          -- Same_Base_Type --
3847          --------------------
3848
3849          function Same_Base_Type
3850            (Ptype  : Node_Id;
3851             Formal : Entity_Id) return Boolean
3852          is
3853             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3854             Pref : Node_Id;
3855
3856          begin
3857             --  Case where pragma argument is typ'Access
3858
3859             if Nkind (Ptype) = N_Attribute_Reference
3860               and then Attribute_Name (Ptype) = Name_Access
3861             then
3862                Pref := Prefix (Ptype);
3863                Find_Type (Pref);
3864
3865                if not Is_Entity_Name (Pref)
3866                  or else Entity (Pref) = Any_Type
3867                then
3868                   raise Pragma_Exit;
3869                end if;
3870
3871                --  We have a match if the corresponding argument is of an
3872                --  anonymous access type, and its designated type matches the
3873                --  type of the prefix of the access attribute
3874
3875                return Ekind (Ftyp) = E_Anonymous_Access_Type
3876                  and then Base_Type (Entity (Pref)) =
3877                             Base_Type (Etype (Designated_Type (Ftyp)));
3878
3879             --  Case where pragma argument is a type name
3880
3881             else
3882                Find_Type (Ptype);
3883
3884                if not Is_Entity_Name (Ptype)
3885                  or else Entity (Ptype) = Any_Type
3886                then
3887                   raise Pragma_Exit;
3888                end if;
3889
3890                --  We have a match if the corresponding argument is of the type
3891                --  given in the pragma (comparing base types)
3892
3893                return Base_Type (Entity (Ptype)) = Ftyp;
3894             end if;
3895          end Same_Base_Type;
3896
3897       --  Start of processing for
3898       --  Process_Extended_Import_Export_Subprogram_Pragma
3899
3900       begin
3901          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3902          Ent := Empty;
3903          Ambiguous := False;
3904
3905          --  Loop through homonyms (overloadings) of the entity
3906
3907          Hom_Id := Entity (Arg_Internal);
3908          while Present (Hom_Id) loop
3909             Def_Id := Get_Base_Subprogram (Hom_Id);
3910
3911             --  We need a subprogram in the current scope
3912
3913             if not Is_Subprogram (Def_Id)
3914               or else Scope (Def_Id) /= Current_Scope
3915             then
3916                null;
3917
3918             else
3919                Match := True;
3920
3921                --  Pragma cannot apply to subprogram body
3922
3923                if Is_Subprogram (Def_Id)
3924                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3925                                                              N_Subprogram_Body
3926                then
3927                   Error_Pragma
3928                     ("pragma% requires separate spec"
3929                       & " and must come before body");
3930                end if;
3931
3932                --  Test result type if given, note that the result type
3933                --  parameter can only be present for the function cases.
3934
3935                if Present (Arg_Result_Type)
3936                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3937                then
3938                   Match := False;
3939
3940                elsif Etype (Def_Id) /= Standard_Void_Type
3941                  and then
3942                    (Pname = Name_Export_Procedure
3943                       or else
3944                     Pname = Name_Import_Procedure)
3945                then
3946                   Match := False;
3947
3948                --  Test parameter types if given. Note that this parameter
3949                --  has not been analyzed (and must not be, since it is
3950                --  semantic nonsense), so we get it as the parser left it.
3951
3952                elsif Present (Arg_Parameter_Types) then
3953                   Check_Matching_Types : declare
3954                      Formal : Entity_Id;
3955                      Ptype  : Node_Id;
3956
3957                   begin
3958                      Formal := First_Formal (Def_Id);
3959
3960                      if Nkind (Arg_Parameter_Types) = N_Null then
3961                         if Present (Formal) then
3962                            Match := False;
3963                         end if;
3964
3965                      --  A list of one type, e.g. (List) is parsed as
3966                      --  a parenthesized expression.
3967
3968                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3969                        and then Paren_Count (Arg_Parameter_Types) = 1
3970                      then
3971                         if No (Formal)
3972                           or else Present (Next_Formal (Formal))
3973                         then
3974                            Match := False;
3975                         else
3976                            Match :=
3977                              Same_Base_Type (Arg_Parameter_Types, Formal);
3978                         end if;
3979
3980                      --  A list of more than one type is parsed as a aggregate
3981
3982                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3983                        and then Paren_Count (Arg_Parameter_Types) = 0
3984                      then
3985                         Ptype := First (Expressions (Arg_Parameter_Types));
3986                         while Present (Ptype) or else Present (Formal) loop
3987                            if No (Ptype)
3988                              or else No (Formal)
3989                              or else not Same_Base_Type (Ptype, Formal)
3990                            then
3991                               Match := False;
3992                               exit;
3993                            else
3994                               Next_Formal (Formal);
3995                               Next (Ptype);
3996                            end if;
3997                         end loop;
3998
3999                      --  Anything else is of the wrong form
4000
4001                      else
4002                         Error_Pragma_Arg
4003                           ("wrong form for Parameter_Types parameter",
4004                            Arg_Parameter_Types);
4005                      end if;
4006                   end Check_Matching_Types;
4007                end if;
4008
4009                --  Match is now False if the entry we found did not match
4010                --  either a supplied Parameter_Types or Result_Types argument
4011
4012                if Match then
4013                   if No (Ent) then
4014                      Ent := Def_Id;
4015
4016                   --  Ambiguous case, the flag Ambiguous shows if we already
4017                   --  detected this and output the initial messages.
4018
4019                   else
4020                      if not Ambiguous then
4021                         Ambiguous := True;
4022                         Error_Msg_Name_1 := Pname;
4023                         Error_Msg_N
4024                           ("pragma% does not uniquely identify subprogram!",
4025                            N);
4026                         Error_Msg_Sloc := Sloc (Ent);
4027                         Error_Msg_N ("matching subprogram #!", N);
4028                         Ent := Empty;
4029                      end if;
4030
4031                      Error_Msg_Sloc := Sloc (Def_Id);
4032                      Error_Msg_N ("matching subprogram #!", N);
4033                   end if;
4034                end if;
4035             end if;
4036
4037             Hom_Id := Homonym (Hom_Id);
4038          end loop;
4039
4040          --  See if we found an entry
4041
4042          if No (Ent) then
4043             if not Ambiguous then
4044                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
4045                   Error_Pragma
4046                     ("pragma% cannot be given for generic subprogram");
4047                else
4048                   Error_Pragma
4049                     ("pragma% does not identify local subprogram");
4050                end if;
4051             end if;
4052
4053             return;
4054          end if;
4055
4056          --  Import pragmas must be for imported entities
4057
4058          if Prag_Id = Pragma_Import_Function
4059               or else
4060             Prag_Id = Pragma_Import_Procedure
4061               or else
4062             Prag_Id = Pragma_Import_Valued_Procedure
4063          then
4064             if not Is_Imported (Ent) then
4065                Error_Pragma
4066                  ("pragma Import or Interface must precede pragma%");
4067             end if;
4068
4069          --  Here we have the Export case which can set the entity as exported
4070
4071          --  But does not do so if the specified external name is null, since
4072          --  that is taken as a signal in DEC Ada 83 (with which we want to be
4073          --  compatible) to request no external name.
4074
4075          elsif Nkind (Arg_External) = N_String_Literal
4076            and then String_Length (Strval (Arg_External)) = 0
4077          then
4078             null;
4079
4080          --  In all other cases, set entity as exported
4081
4082          else
4083             Set_Exported (Ent, Arg_Internal);
4084          end if;
4085
4086          --  Special processing for Valued_Procedure cases
4087
4088          if Prag_Id = Pragma_Import_Valued_Procedure
4089            or else
4090             Prag_Id = Pragma_Export_Valued_Procedure
4091          then
4092             Formal := First_Formal (Ent);
4093
4094             if No (Formal) then
4095                Error_Pragma ("at least one parameter required for pragma%");
4096
4097             elsif Ekind (Formal) /= E_Out_Parameter then
4098                Error_Pragma ("first parameter must have mode out for pragma%");
4099
4100             else
4101                Set_Is_Valued_Procedure (Ent);
4102             end if;
4103          end if;
4104
4105          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
4106
4107          --  Process Result_Mechanism argument if present. We have already
4108          --  checked that this is only allowed for the function case.
4109
4110          if Present (Arg_Result_Mechanism) then
4111             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
4112          end if;
4113
4114          --  Process Mechanism parameter if present. Note that this parameter
4115          --  is not analyzed, and must not be analyzed since it is semantic
4116          --  nonsense, so we get it in exactly as the parser left it.
4117
4118          if Present (Arg_Mechanism) then
4119             declare
4120                Formal : Entity_Id;
4121                Massoc : Node_Id;
4122                Mname  : Node_Id;
4123                Choice : Node_Id;
4124
4125             begin
4126                --  A single mechanism association without a formal parameter
4127                --  name is parsed as a parenthesized expression. All other
4128                --  cases are parsed as aggregates, so we rewrite the single
4129                --  parameter case as an aggregate for consistency.
4130
4131                if Nkind (Arg_Mechanism) /= N_Aggregate
4132                  and then Paren_Count (Arg_Mechanism) = 1
4133                then
4134                   Rewrite (Arg_Mechanism,
4135                     Make_Aggregate (Sloc (Arg_Mechanism),
4136                       Expressions => New_List (
4137                         Relocate_Node (Arg_Mechanism))));
4138                end if;
4139
4140                --  Case of only mechanism name given, applies to all formals
4141
4142                if Nkind (Arg_Mechanism) /= N_Aggregate then
4143                   Formal := First_Formal (Ent);
4144                   while Present (Formal) loop
4145                      Set_Mechanism_Value (Formal, Arg_Mechanism);
4146                      Next_Formal (Formal);
4147                   end loop;
4148
4149                --  Case of list of mechanism associations given
4150
4151                else
4152                   if Null_Record_Present (Arg_Mechanism) then
4153                      Error_Pragma_Arg
4154                        ("inappropriate form for Mechanism parameter",
4155                         Arg_Mechanism);
4156                   end if;
4157
4158                   --  Deal with positional ones first
4159
4160                   Formal := First_Formal (Ent);
4161
4162                   if Present (Expressions (Arg_Mechanism)) then
4163                      Mname := First (Expressions (Arg_Mechanism));
4164                      while Present (Mname) loop
4165                         if No (Formal) then
4166                            Error_Pragma_Arg
4167                              ("too many mechanism associations", Mname);
4168                         end if;
4169
4170                         Set_Mechanism_Value (Formal, Mname);
4171                         Next_Formal (Formal);
4172                         Next (Mname);
4173                      end loop;
4174                   end if;
4175
4176                   --  Deal with named entries
4177
4178                   if Present (Component_Associations (Arg_Mechanism)) then
4179                      Massoc := First (Component_Associations (Arg_Mechanism));
4180                      while Present (Massoc) loop
4181                         Choice := First (Choices (Massoc));
4182
4183                         if Nkind (Choice) /= N_Identifier
4184                           or else Present (Next (Choice))
4185                         then
4186                            Error_Pragma_Arg
4187                              ("incorrect form for mechanism association",
4188                               Massoc);
4189                         end if;
4190
4191                         Formal := First_Formal (Ent);
4192                         loop
4193                            if No (Formal) then
4194                               Error_Pragma_Arg
4195                                 ("parameter name & not present", Choice);
4196                            end if;
4197
4198                            if Chars (Choice) = Chars (Formal) then
4199                               Set_Mechanism_Value
4200                                 (Formal, Expression (Massoc));
4201
4202                               --  Set entity on identifier (needed by ASIS)
4203
4204                               Set_Entity (Choice, Formal);
4205
4206                               exit;
4207                            end if;
4208
4209                            Next_Formal (Formal);
4210                         end loop;
4211
4212                         Next (Massoc);
4213                      end loop;
4214                   end if;
4215                end if;
4216             end;
4217          end if;
4218
4219          --  Process First_Optional_Parameter argument if present. We have
4220          --  already checked that this is only allowed for the Import case.
4221
4222          if Present (Arg_First_Optional_Parameter) then
4223             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4224                Error_Pragma_Arg
4225                  ("first optional parameter must be formal parameter name",
4226                   Arg_First_Optional_Parameter);
4227             end if;
4228
4229             Formal := First_Formal (Ent);
4230             loop
4231                if No (Formal) then
4232                   Error_Pragma_Arg
4233                     ("specified formal parameter& not found",
4234                      Arg_First_Optional_Parameter);
4235                end if;
4236
4237                exit when Chars (Formal) =
4238                          Chars (Arg_First_Optional_Parameter);
4239
4240                Next_Formal (Formal);
4241             end loop;
4242
4243             Set_First_Optional_Parameter (Ent, Formal);
4244
4245             --  Check specified and all remaining formals have right form
4246
4247             while Present (Formal) loop
4248                if Ekind (Formal) /= E_In_Parameter then
4249                   Error_Msg_NE
4250                     ("optional formal& is not of mode in!",
4251                      Arg_First_Optional_Parameter, Formal);
4252
4253                else
4254                   Dval := Default_Value (Formal);
4255
4256                   if No (Dval) then
4257                      Error_Msg_NE
4258                        ("optional formal& does not have default value!",
4259                         Arg_First_Optional_Parameter, Formal);
4260
4261                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4262                      null;
4263
4264                   else
4265                      Error_Msg_FE
4266                        ("default value for optional formal& is non-static!",
4267                         Arg_First_Optional_Parameter, Formal);
4268                   end if;
4269                end if;
4270
4271                Set_Is_Optional_Parameter (Formal);
4272                Next_Formal (Formal);
4273             end loop;
4274          end if;
4275       end Process_Extended_Import_Export_Subprogram_Pragma;
4276
4277       --------------------------
4278       -- Process_Generic_List --
4279       --------------------------
4280
4281       procedure Process_Generic_List is
4282          Arg : Node_Id;
4283          Exp : Node_Id;
4284
4285       begin
4286          Check_No_Identifiers;
4287          Check_At_Least_N_Arguments (1);
4288
4289          Arg := Arg1;
4290          while Present (Arg) loop
4291             Exp := Get_Pragma_Arg (Arg);
4292             Analyze (Exp);
4293
4294             if not Is_Entity_Name (Exp)
4295               or else
4296                 (not Is_Generic_Instance (Entity (Exp))
4297                   and then
4298                  not Is_Generic_Unit (Entity (Exp)))
4299             then
4300                Error_Pragma_Arg
4301                  ("pragma% argument must be name of generic unit/instance",
4302                   Arg);
4303             end if;
4304
4305             Next (Arg);
4306          end loop;
4307       end Process_Generic_List;
4308
4309       ------------------------------------
4310       -- Process_Import_Predefined_Type --
4311       ------------------------------------
4312
4313       procedure Process_Import_Predefined_Type is
4314          Loc  : constant Source_Ptr := Sloc (N);
4315          Elmt : Elmt_Id;
4316          Ftyp : Node_Id := Empty;
4317          Decl : Node_Id;
4318          Def  : Node_Id;
4319          Nam  : Name_Id;
4320
4321       begin
4322          String_To_Name_Buffer (Strval (Expression (Arg3)));
4323          Nam := Name_Find;
4324
4325          Elmt := First_Elmt (Predefined_Float_Types);
4326          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4327             Next_Elmt (Elmt);
4328          end loop;
4329
4330          Ftyp := Node (Elmt);
4331
4332          if Present (Ftyp) then
4333
4334             --  Don't build a derived type declaration, because predefined C
4335             --  types have no declaration anywhere, so cannot really be named.
4336             --  Instead build a full type declaration, starting with an
4337             --  appropriate type definition is built
4338
4339             if Is_Floating_Point_Type (Ftyp) then
4340                Def := Make_Floating_Point_Definition (Loc,
4341                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4342                  Make_Real_Range_Specification (Loc,
4343                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4344                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4345
4346             --  Should never have a predefined type we cannot handle
4347
4348             else
4349                raise Program_Error;
4350             end if;
4351
4352             --  Build and insert a Full_Type_Declaration, which will be
4353             --  analyzed as soon as this list entry has been analyzed.
4354
4355             Decl := Make_Full_Type_Declaration (Loc,
4356               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4357               Type_Definition => Def);
4358
4359             Insert_After (N, Decl);
4360             Mark_Rewrite_Insertion (Decl);
4361
4362          else
4363             Error_Pragma_Arg ("no matching type found for pragma%",
4364             Arg2);
4365          end if;
4366       end Process_Import_Predefined_Type;
4367
4368       ---------------------------------
4369       -- Process_Import_Or_Interface --
4370       ---------------------------------
4371
4372       procedure Process_Import_Or_Interface is
4373          C      : Convention_Id;
4374          Def_Id : Entity_Id;
4375          Hom_Id : Entity_Id;
4376
4377       begin
4378          Process_Convention (C, Def_Id);
4379          Kill_Size_Check_Code (Def_Id);
4380          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4381
4382          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4383
4384             --  We do not permit Import to apply to a renaming declaration
4385
4386             if Present (Renamed_Object (Def_Id)) then
4387                Error_Pragma_Arg
4388                  ("pragma% not allowed for object renaming", Arg2);
4389
4390             --  User initialization is not allowed for imported object, but
4391             --  the object declaration may contain a default initialization,
4392             --  that will be discarded. Note that an explicit initialization
4393             --  only counts if it comes from source, otherwise it is simply
4394             --  the code generator making an implicit initialization explicit.
4395
4396             elsif Present (Expression (Parent (Def_Id)))
4397               and then Comes_From_Source (Expression (Parent (Def_Id)))
4398             then
4399                Error_Msg_Sloc := Sloc (Def_Id);
4400                Error_Pragma_Arg
4401                  ("no initialization allowed for declaration of& #",
4402                   "\imported entities cannot be initialized (RM B.1(24))",
4403                   Arg2);
4404
4405             else
4406                Set_Imported (Def_Id);
4407                Process_Interface_Name (Def_Id, Arg3, Arg4);
4408
4409                --  Note that we do not set Is_Public here. That's because we
4410                --  only want to set it if there is no address clause, and we
4411                --  don't know that yet, so we delay that processing till
4412                --  freeze time.
4413
4414                --  pragma Import completes deferred constants
4415
4416                if Ekind (Def_Id) = E_Constant then
4417                   Set_Has_Completion (Def_Id);
4418                end if;
4419
4420                --  It is not possible to import a constant of an unconstrained
4421                --  array type (e.g. string) because there is no simple way to
4422                --  write a meaningful subtype for it.
4423
4424                if Is_Array_Type (Etype (Def_Id))
4425                  and then not Is_Constrained (Etype (Def_Id))
4426                then
4427                   Error_Msg_NE
4428                     ("imported constant& must have a constrained subtype",
4429                       N, Def_Id);
4430                end if;
4431             end if;
4432
4433          elsif Is_Subprogram (Def_Id)
4434            or else Is_Generic_Subprogram (Def_Id)
4435          then
4436             --  If the name is overloaded, pragma applies to all of the denoted
4437             --  entities in the same declarative part.
4438
4439             Hom_Id := Def_Id;
4440             while Present (Hom_Id) loop
4441                Def_Id := Get_Base_Subprogram (Hom_Id);
4442
4443                --  Ignore inherited subprograms because the pragma will apply
4444                --  to the parent operation, which is the one called.
4445
4446                if Is_Overloadable (Def_Id)
4447                  and then Present (Alias (Def_Id))
4448                then
4449                   null;
4450
4451                --  If it is not a subprogram, it must be in an outer scope and
4452                --  pragma does not apply.
4453
4454                elsif not Is_Subprogram (Def_Id)
4455                  and then not Is_Generic_Subprogram (Def_Id)
4456                then
4457                   null;
4458
4459                --  The pragma does not apply to primitives of interfaces
4460
4461                elsif Is_Dispatching_Operation (Def_Id)
4462                  and then Present (Find_Dispatching_Type (Def_Id))
4463                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4464                then
4465                   null;
4466
4467                --  Verify that the homonym is in the same declarative part (not
4468                --  just the same scope).
4469
4470                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4471                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4472                then
4473                   exit;
4474
4475                else
4476                   Set_Imported (Def_Id);
4477
4478                   --  Reject an Import applied to an abstract subprogram
4479
4480                   if Is_Subprogram (Def_Id)
4481                     and then Is_Abstract_Subprogram (Def_Id)
4482                   then
4483                      Error_Msg_Sloc := Sloc (Def_Id);
4484                      Error_Msg_NE
4485                        ("cannot import abstract subprogram& declared#",
4486                         Arg2, Def_Id);
4487                   end if;
4488
4489                   --  Special processing for Convention_Intrinsic
4490
4491                   if C = Convention_Intrinsic then
4492
4493                      --  Link_Name argument not allowed for intrinsic
4494
4495                      Check_No_Link_Name;
4496
4497                      Set_Is_Intrinsic_Subprogram (Def_Id);
4498
4499                      --  If no external name is present, then check that this
4500                      --  is a valid intrinsic subprogram. If an external name
4501                      --  is present, then this is handled by the back end.
4502
4503                      if No (Arg3) then
4504                         Check_Intrinsic_Subprogram
4505                           (Def_Id, Get_Pragma_Arg (Arg2));
4506                      end if;
4507                   end if;
4508
4509                   --  All interfaced procedures need an external symbol created
4510                   --  for them since they are always referenced from another
4511                   --  object file.
4512
4513                   Set_Is_Public (Def_Id);
4514
4515                   --  Verify that the subprogram does not have a completion
4516                   --  through a renaming declaration. For other completions the
4517                   --  pragma appears as a too late representation.
4518
4519                   declare
4520                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4521
4522                   begin
4523                      if Present (Decl)
4524                        and then Nkind (Decl) = N_Subprogram_Declaration
4525                        and then Present (Corresponding_Body (Decl))
4526                        and then Nkind (Unit_Declaration_Node
4527                                         (Corresponding_Body (Decl))) =
4528                                              N_Subprogram_Renaming_Declaration
4529                      then
4530                         Error_Msg_Sloc := Sloc (Def_Id);
4531                         Error_Msg_NE
4532                           ("cannot import&, renaming already provided for " &
4533                            "declaration #", N, Def_Id);
4534                      end if;
4535                   end;
4536
4537                   Set_Has_Completion (Def_Id);
4538                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4539                end if;
4540
4541                if Is_Compilation_Unit (Hom_Id) then
4542
4543                   --  Its possible homonyms are not affected by the pragma.
4544                   --  Such homonyms might be present in the context of other
4545                   --  units being compiled.
4546
4547                   exit;
4548
4549                else
4550                   Hom_Id := Homonym (Hom_Id);
4551                end if;
4552             end loop;
4553
4554          --  When the convention is Java or CIL, we also allow Import to be
4555          --  given for packages, generic packages, exceptions, record
4556          --  components, and access to subprograms.
4557
4558          elsif (C = Convention_Java or else C = Convention_CIL)
4559            and then
4560              (Is_Package_Or_Generic_Package (Def_Id)
4561                or else Ekind (Def_Id) = E_Exception
4562                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4563                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4564          then
4565             Set_Imported (Def_Id);
4566             Set_Is_Public (Def_Id);
4567             Process_Interface_Name (Def_Id, Arg3, Arg4);
4568
4569          --  Import a CPP class
4570
4571          elsif Is_Record_Type (Def_Id)
4572            and then C = Convention_CPP
4573          then
4574             --  Types treated as CPP classes must be declared limited (note:
4575             --  this used to be a warning but there is no real benefit to it
4576             --  since we did effectively intend to treat the type as limited
4577             --  anyway).
4578
4579             if not Is_Limited_Type (Def_Id) then
4580                Error_Msg_N
4581                  ("imported 'C'P'P type must be limited",
4582                   Get_Pragma_Arg (Arg2));
4583             end if;
4584
4585             Set_Is_CPP_Class (Def_Id);
4586
4587             --  Imported CPP types must not have discriminants (because C++
4588             --  classes do not have discriminants).
4589
4590             if Has_Discriminants (Def_Id) then
4591                Error_Msg_N
4592                  ("imported 'C'P'P type cannot have discriminants",
4593                   First (Discriminant_Specifications
4594                           (Declaration_Node (Def_Id))));
4595             end if;
4596
4597             --  Components of imported CPP types must not have default
4598             --  expressions because the constructor (if any) is on the
4599             --  C++ side.
4600
4601             declare
4602                Tdef  : constant Node_Id :=
4603                          Type_Definition (Declaration_Node (Def_Id));
4604                Clist : Node_Id;
4605                Comp  : Node_Id;
4606
4607             begin
4608                if Nkind (Tdef) = N_Record_Definition then
4609                   Clist := Component_List (Tdef);
4610
4611                else
4612                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4613                   Clist := Component_List (Record_Extension_Part (Tdef));
4614                end if;
4615
4616                if Present (Clist) then
4617                   Comp := First (Component_Items (Clist));
4618                   while Present (Comp) loop
4619                      if Present (Expression (Comp)) then
4620                         Error_Msg_N
4621                           ("component of imported 'C'P'P type cannot have" &
4622                            " default expression", Expression (Comp));
4623                      end if;
4624
4625                      Next (Comp);
4626                   end loop;
4627                end if;
4628             end;
4629
4630          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4631             Check_No_Link_Name;
4632             Check_Arg_Count (3);
4633             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4634
4635             Process_Import_Predefined_Type;
4636
4637          else
4638             Error_Pragma_Arg
4639               ("second argument of pragma% must be object, subprogram" &
4640                " or incomplete type",
4641                Arg2);
4642          end if;
4643
4644          --  If this pragma applies to a compilation unit, then the unit, which
4645          --  is a subprogram, does not require (or allow) a body. We also do
4646          --  not need to elaborate imported procedures.
4647
4648          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4649             declare
4650                Cunit : constant Node_Id := Parent (Parent (N));
4651             begin
4652                Set_Body_Required (Cunit, False);
4653             end;
4654          end if;
4655       end Process_Import_Or_Interface;
4656
4657       --------------------
4658       -- Process_Inline --
4659       --------------------
4660
4661       procedure Process_Inline (Active : Boolean) is
4662          Assoc     : Node_Id;
4663          Decl      : Node_Id;
4664          Subp_Id   : Node_Id;
4665          Subp      : Entity_Id;
4666          Applies   : Boolean;
4667
4668          Effective : Boolean := False;
4669          --  Set True if inline has some effect, i.e. if there is at least one
4670          --  subprogram set as inlined as a result of the use of the pragma.
4671
4672          procedure Make_Inline (Subp : Entity_Id);
4673          --  Subp is the defining unit name of the subprogram declaration. Set
4674          --  the flag, as well as the flag in the corresponding body, if there
4675          --  is one present.
4676
4677          procedure Set_Inline_Flags (Subp : Entity_Id);
4678          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4679          --  Has_Pragma_Inline_Always for the Inline_Always case.
4680
4681          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4682          --  Returns True if it can be determined at this stage that inlining
4683          --  is not possible, for example if the body is available and contains
4684          --  exception handlers, we prevent inlining, since otherwise we can
4685          --  get undefined symbols at link time. This function also emits a
4686          --  warning if front-end inlining is enabled and the pragma appears
4687          --  too late.
4688          --
4689          --  ??? is business with link symbols still valid, or does it relate
4690          --  to front end ZCX which is being phased out ???
4691
4692          ---------------------------
4693          -- Inlining_Not_Possible --
4694          ---------------------------
4695
4696          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4697             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4698             Stats : Node_Id;
4699
4700          begin
4701             if Nkind (Decl) = N_Subprogram_Body then
4702                Stats := Handled_Statement_Sequence (Decl);
4703                return Present (Exception_Handlers (Stats))
4704                  or else Present (At_End_Proc (Stats));
4705
4706             elsif Nkind (Decl) = N_Subprogram_Declaration
4707               and then Present (Corresponding_Body (Decl))
4708             then
4709                if Front_End_Inlining
4710                  and then Analyzed (Corresponding_Body (Decl))
4711                then
4712                   Error_Msg_N ("pragma appears too late, ignored?", N);
4713                   return True;
4714
4715                --  If the subprogram is a renaming as body, the body is just a
4716                --  call to the renamed subprogram, and inlining is trivially
4717                --  possible.
4718
4719                elsif
4720                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4721                                              N_Subprogram_Renaming_Declaration
4722                then
4723                   return False;
4724
4725                else
4726                   Stats :=
4727                     Handled_Statement_Sequence
4728                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4729
4730                   return
4731                     Present (Exception_Handlers (Stats))
4732                       or else Present (At_End_Proc (Stats));
4733                end if;
4734
4735             else
4736                --  If body is not available, assume the best, the check is
4737                --  performed again when compiling enclosing package bodies.
4738
4739                return False;
4740             end if;
4741          end Inlining_Not_Possible;
4742
4743          -----------------
4744          -- Make_Inline --
4745          -----------------
4746
4747          procedure Make_Inline (Subp : Entity_Id) is
4748             Kind       : constant Entity_Kind := Ekind (Subp);
4749             Inner_Subp : Entity_Id   := Subp;
4750
4751          begin
4752             --  Ignore if bad type, avoid cascaded error
4753
4754             if Etype (Subp) = Any_Type then
4755                Applies := True;
4756                return;
4757
4758             --  Ignore if all inlining is suppressed
4759
4760             elsif Suppress_All_Inlining then
4761                Applies := True;
4762                return;
4763
4764             --  If inlining is not possible, for now do not treat as an error
4765
4766             elsif Inlining_Not_Possible (Subp) then
4767                Applies := True;
4768                return;
4769
4770             --  Here we have a candidate for inlining, but we must exclude
4771             --  derived operations. Otherwise we would end up trying to inline
4772             --  a phantom declaration, and the result would be to drag in a
4773             --  body which has no direct inlining associated with it. That
4774             --  would not only be inefficient but would also result in the
4775             --  backend doing cross-unit inlining in cases where it was
4776             --  definitely inappropriate to do so.
4777
4778             --  However, a simple Comes_From_Source test is insufficient, since
4779             --  we do want to allow inlining of generic instances which also do
4780             --  not come from source. We also need to recognize specs generated
4781             --  by the front-end for bodies that carry the pragma. Finally,
4782             --  predefined operators do not come from source but are not
4783             --  inlineable either.
4784
4785             elsif Is_Generic_Instance (Subp)
4786               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4787             then
4788                null;
4789
4790             elsif not Comes_From_Source (Subp)
4791               and then Scope (Subp) /= Standard_Standard
4792             then
4793                Applies := True;
4794                return;
4795             end if;
4796
4797             --  The referenced entity must either be the enclosing entity, or
4798             --  an entity declared within the current open scope.
4799
4800             if Present (Scope (Subp))
4801               and then Scope (Subp) /= Current_Scope
4802               and then Subp /= Current_Scope
4803             then
4804                Error_Pragma_Arg
4805                  ("argument of% must be entity in current scope", Assoc);
4806                return;
4807             end if;
4808
4809             --  Processing for procedure, operator or function. If subprogram
4810             --  is aliased (as for an instance) indicate that the renamed
4811             --  entity (if declared in the same unit) is inlined.
4812
4813             if Is_Subprogram (Subp) then
4814                Inner_Subp := Ultimate_Alias (Inner_Subp);
4815
4816                if In_Same_Source_Unit (Subp, Inner_Subp) then
4817                   Set_Inline_Flags (Inner_Subp);
4818
4819                   Decl := Parent (Parent (Inner_Subp));
4820
4821                   if Nkind (Decl) = N_Subprogram_Declaration
4822                     and then Present (Corresponding_Body (Decl))
4823                   then
4824                      Set_Inline_Flags (Corresponding_Body (Decl));
4825
4826                   elsif Is_Generic_Instance (Subp) then
4827
4828                      --  Indicate that the body needs to be created for
4829                      --  inlining subsequent calls. The instantiation node
4830                      --  follows the declaration of the wrapper package
4831                      --  created for it.
4832
4833                      if Scope (Subp) /= Standard_Standard
4834                        and then
4835                          Need_Subprogram_Instance_Body
4836                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4837                               Subp)
4838                      then
4839                         null;
4840                      end if;
4841
4842                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
4843                   --  appear in a formal part to apply to a formal subprogram.
4844                   --  Do not apply check within an instance or a formal package
4845                   --  the test will have been applied to the original generic.
4846
4847                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4848                     and then List_Containing (Decl) = List_Containing (N)
4849                     and then not In_Instance
4850                   then
4851                      Error_Msg_N
4852                        ("Inline cannot apply to a formal subprogram", N);
4853                   end if;
4854                end if;
4855
4856                Applies := True;
4857
4858             --  For a generic subprogram set flag as well, for use at the point
4859             --  of instantiation, to determine whether the body should be
4860             --  generated.
4861
4862             elsif Is_Generic_Subprogram (Subp) then
4863                Set_Inline_Flags (Subp);
4864                Applies := True;
4865
4866             --  Literals are by definition inlined
4867
4868             elsif Kind = E_Enumeration_Literal then
4869                null;
4870
4871             --  Anything else is an error
4872
4873             else
4874                Error_Pragma_Arg
4875                  ("expect subprogram name for pragma%", Assoc);
4876             end if;
4877          end Make_Inline;
4878
4879          ----------------------
4880          -- Set_Inline_Flags --
4881          ----------------------
4882
4883          procedure Set_Inline_Flags (Subp : Entity_Id) is
4884          begin
4885             if Active then
4886                Set_Is_Inlined (Subp);
4887             end if;
4888
4889             if not Has_Pragma_Inline (Subp) then
4890                Set_Has_Pragma_Inline (Subp);
4891                Effective := True;
4892             end if;
4893
4894             if Prag_Id = Pragma_Inline_Always then
4895                Set_Has_Pragma_Inline_Always (Subp);
4896             end if;
4897          end Set_Inline_Flags;
4898
4899       --  Start of processing for Process_Inline
4900
4901       begin
4902          Check_No_Identifiers;
4903          Check_At_Least_N_Arguments (1);
4904
4905          if Active then
4906             Inline_Processing_Required := True;
4907          end if;
4908
4909          Assoc := Arg1;
4910          while Present (Assoc) loop
4911             Subp_Id := Get_Pragma_Arg (Assoc);
4912             Analyze (Subp_Id);
4913             Applies := False;
4914
4915             if Is_Entity_Name (Subp_Id) then
4916                Subp := Entity (Subp_Id);
4917
4918                if Subp = Any_Id then
4919
4920                   --  If previous error, avoid cascaded errors
4921
4922                   Applies := True;
4923                   Effective := True;
4924
4925                else
4926                   Make_Inline (Subp);
4927
4928                   --  For the pragma case, climb homonym chain. This is
4929                   --  what implements allowing the pragma in the renaming
4930                   --  case, with the result applying to the ancestors, and
4931                   --  also allows Inline to apply to all previous homonyms.
4932
4933                   if not From_Aspect_Specification (N) then
4934                      while Present (Homonym (Subp))
4935                        and then Scope (Homonym (Subp)) = Current_Scope
4936                      loop
4937                         Make_Inline (Homonym (Subp));
4938                         Subp := Homonym (Subp);
4939                      end loop;
4940                   end if;
4941                end if;
4942             end if;
4943
4944             if not Applies then
4945                Error_Pragma_Arg
4946                  ("inappropriate argument for pragma%", Assoc);
4947
4948             elsif not Effective
4949               and then Warn_On_Redundant_Constructs
4950               and then not Suppress_All_Inlining
4951             then
4952                if Inlining_Not_Possible (Subp) then
4953                   Error_Msg_NE
4954                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4955                else
4956                   Error_Msg_NE
4957                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4958                end if;
4959             end if;
4960
4961             Next (Assoc);
4962          end loop;
4963       end Process_Inline;
4964
4965       ----------------------------
4966       -- Process_Interface_Name --
4967       ----------------------------
4968
4969       procedure Process_Interface_Name
4970         (Subprogram_Def : Entity_Id;
4971          Ext_Arg        : Node_Id;
4972          Link_Arg       : Node_Id)
4973       is
4974          Ext_Nam    : Node_Id;
4975          Link_Nam   : Node_Id;
4976          String_Val : String_Id;
4977
4978          procedure Check_Form_Of_Interface_Name
4979            (SN            : Node_Id;
4980             Ext_Name_Case : Boolean);
4981          --  SN is a string literal node for an interface name. This routine
4982          --  performs some minimal checks that the name is reasonable. In
4983          --  particular that no spaces or other obviously incorrect characters
4984          --  appear. This is only a warning, since any characters are allowed.
4985          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4986
4987          ----------------------------------
4988          -- Check_Form_Of_Interface_Name --
4989          ----------------------------------
4990
4991          procedure Check_Form_Of_Interface_Name
4992            (SN            : Node_Id;
4993             Ext_Name_Case : Boolean)
4994          is
4995             S  : constant String_Id := Strval (Expr_Value_S (SN));
4996             SL : constant Nat       := String_Length (S);
4997             C  : Char_Code;
4998
4999          begin
5000             if SL = 0 then
5001                Error_Msg_N ("interface name cannot be null string", SN);
5002             end if;
5003
5004             for J in 1 .. SL loop
5005                C := Get_String_Char (S, J);
5006
5007                --  Look for dubious character and issue unconditional warning.
5008                --  Definitely dubious if not in character range.
5009
5010                if not In_Character_Range (C)
5011
5012                   --  For all cases except CLI target,
5013                   --  commas, spaces and slashes are dubious (in CLI, we use
5014                   --  commas and backslashes in external names to specify
5015                   --  assembly version and public key, while slashes and spaces
5016                   --  can be used in names to mark nested classes and
5017                   --  valuetypes).
5018
5019                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
5020                              and then (Get_Character (C) = ','
5021                                          or else
5022                                        Get_Character (C) = '\'))
5023                  or else (VM_Target /= CLI_Target
5024                             and then (Get_Character (C) = ' '
5025                                         or else
5026                                       Get_Character (C) = '/'))
5027                then
5028                   Error_Msg
5029                     ("?interface name contains illegal character",
5030                      Sloc (SN) + Source_Ptr (J));
5031                end if;
5032             end loop;
5033          end Check_Form_Of_Interface_Name;
5034
5035       --  Start of processing for Process_Interface_Name
5036
5037       begin
5038          if No (Link_Arg) then
5039             if No (Ext_Arg) then
5040                if VM_Target = CLI_Target
5041                  and then Ekind (Subprogram_Def) = E_Package
5042                  and then Nkind (Parent (Subprogram_Def)) =
5043                                                  N_Package_Specification
5044                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
5045                then
5046                   Set_Interface_Name
5047                      (Subprogram_Def,
5048                       Interface_Name
5049                         (Generic_Parent (Parent (Subprogram_Def))));
5050                end if;
5051
5052                return;
5053
5054             elsif Chars (Ext_Arg) = Name_Link_Name then
5055                Ext_Nam  := Empty;
5056                Link_Nam := Expression (Ext_Arg);
5057
5058             else
5059                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
5060                Ext_Nam  := Expression (Ext_Arg);
5061                Link_Nam := Empty;
5062             end if;
5063
5064          else
5065             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
5066             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
5067             Ext_Nam  := Expression (Ext_Arg);
5068             Link_Nam := Expression (Link_Arg);
5069          end if;
5070
5071          --  Check expressions for external name and link name are static
5072
5073          if Present (Ext_Nam) then
5074             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
5075             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
5076
5077             --  Verify that external name is not the name of a local entity,
5078             --  which would hide the imported one and could lead to run-time
5079             --  surprises. The problem can only arise for entities declared in
5080             --  a package body (otherwise the external name is fully qualified
5081             --  and will not conflict).
5082
5083             declare
5084                Nam : Name_Id;
5085                E   : Entity_Id;
5086                Par : Node_Id;
5087
5088             begin
5089                if Prag_Id = Pragma_Import then
5090                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
5091                   Nam := Name_Find;
5092                   E   := Entity_Id (Get_Name_Table_Info (Nam));
5093
5094                   if Nam /= Chars (Subprogram_Def)
5095                     and then Present (E)
5096                     and then not Is_Overloadable (E)
5097                     and then Is_Immediately_Visible (E)
5098                     and then not Is_Imported (E)
5099                     and then Ekind (Scope (E)) = E_Package
5100                   then
5101                      Par := Parent (E);
5102                      while Present (Par) loop
5103                         if Nkind (Par) = N_Package_Body then
5104                            Error_Msg_Sloc := Sloc (E);
5105                            Error_Msg_NE
5106                              ("imported entity is hidden by & declared#",
5107                               Ext_Arg, E);
5108                            exit;
5109                         end if;
5110
5111                         Par := Parent (Par);
5112                      end loop;
5113                   end if;
5114                end if;
5115             end;
5116          end if;
5117
5118          if Present (Link_Nam) then
5119             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
5120             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
5121          end if;
5122
5123          --  If there is no link name, just set the external name
5124
5125          if No (Link_Nam) then
5126             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
5127
5128          --  For the Link_Name case, the given literal is preceded by an
5129          --  asterisk, which indicates to GCC that the given name should be
5130          --  taken literally, and in particular that no prepending of
5131          --  underlines should occur, even in systems where this is the
5132          --  normal default.
5133
5134          else
5135             Start_String;
5136
5137             if VM_Target = No_VM then
5138                Store_String_Char (Get_Char_Code ('*'));
5139             end if;
5140
5141             String_Val := Strval (Expr_Value_S (Link_Nam));
5142             Store_String_Chars (String_Val);
5143             Link_Nam :=
5144               Make_String_Literal (Sloc (Link_Nam),
5145                 Strval => End_String);
5146          end if;
5147
5148          --  Set the interface name. If the entity is a generic instance, use
5149          --  its alias, which is the callable entity.
5150
5151          if Is_Generic_Instance (Subprogram_Def) then
5152             Set_Encoded_Interface_Name
5153               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5154          else
5155             Set_Encoded_Interface_Name
5156               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5157          end if;
5158
5159          --  We allow duplicated export names in CIL/Java, as they are always
5160          --  enclosed in a namespace that differentiates them, and overloaded
5161          --  entities are supported by the VM.
5162
5163          if Convention (Subprogram_Def) /= Convention_CIL
5164               and then
5165             Convention (Subprogram_Def) /= Convention_Java
5166          then
5167             Check_Duplicated_Export_Name (Link_Nam);
5168          end if;
5169       end Process_Interface_Name;
5170
5171       -----------------------------------------
5172       -- Process_Interrupt_Or_Attach_Handler --
5173       -----------------------------------------
5174
5175       procedure Process_Interrupt_Or_Attach_Handler is
5176          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5177          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5178          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5179
5180       begin
5181          Set_Is_Interrupt_Handler (Handler_Proc);
5182
5183          --  If the pragma is not associated with a handler procedure within a
5184          --  protected type, then it must be for a nonprotected procedure for
5185          --  the AAMP target, in which case we don't associate a representation
5186          --  item with the procedure's scope.
5187
5188          if Ekind (Proc_Scope) = E_Protected_Type then
5189             if Prag_Id = Pragma_Interrupt_Handler
5190                  or else
5191                Prag_Id = Pragma_Attach_Handler
5192             then
5193                Record_Rep_Item (Proc_Scope, N);
5194             end if;
5195          end if;
5196       end Process_Interrupt_Or_Attach_Handler;
5197
5198       --------------------------------------------------
5199       -- Process_Restrictions_Or_Restriction_Warnings --
5200       --------------------------------------------------
5201
5202       --  Note: some of the simple identifier cases were handled in par-prag,
5203       --  but it is harmless (and more straightforward) to simply handle all
5204       --  cases here, even if it means we repeat a bit of work in some cases.
5205
5206       procedure Process_Restrictions_Or_Restriction_Warnings
5207         (Warn : Boolean)
5208       is
5209          Arg   : Node_Id;
5210          R_Id  : Restriction_Id;
5211          Id    : Name_Id;
5212          Expr  : Node_Id;
5213          Val   : Uint;
5214
5215          procedure Check_Unit_Name (N : Node_Id);
5216          --  Checks unit name parameter for No_Dependence. Returns if it has
5217          --  an appropriate form, otherwise raises pragma argument error.
5218
5219          ---------------------
5220          -- Check_Unit_Name --
5221          ---------------------
5222
5223          procedure Check_Unit_Name (N : Node_Id) is
5224          begin
5225             if Nkind (N) = N_Selected_Component then
5226                Check_Unit_Name (Prefix (N));
5227                Check_Unit_Name (Selector_Name (N));
5228
5229             elsif Nkind (N) = N_Identifier then
5230                return;
5231
5232             else
5233                Error_Pragma_Arg
5234                  ("wrong form for unit name for No_Dependence", N);
5235             end if;
5236          end Check_Unit_Name;
5237
5238       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5239
5240       begin
5241          --  Ignore all Restrictions pragma in CodePeer mode
5242
5243          if CodePeer_Mode then
5244             return;
5245          end if;
5246
5247          Check_Ada_83_Warning;
5248          Check_At_Least_N_Arguments (1);
5249          Check_Valid_Configuration_Pragma;
5250
5251          Arg := Arg1;
5252          while Present (Arg) loop
5253             Id := Chars (Arg);
5254             Expr := Get_Pragma_Arg (Arg);
5255
5256             --  Case of no restriction identifier present
5257
5258             if Id = No_Name then
5259                if Nkind (Expr) /= N_Identifier then
5260                   Error_Pragma_Arg
5261                     ("invalid form for restriction", Arg);
5262                end if;
5263
5264                R_Id :=
5265                  Get_Restriction_Id
5266                    (Process_Restriction_Synonyms (Expr));
5267
5268                if R_Id not in All_Boolean_Restrictions then
5269                   Error_Msg_Name_1 := Pname;
5270                   Error_Msg_N
5271                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5272
5273                   --  Check for possible misspelling
5274
5275                   for J in Restriction_Id loop
5276                      declare
5277                         Rnm : constant String := Restriction_Id'Image (J);
5278
5279                      begin
5280                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5281                         Name_Len := Rnm'Length;
5282                         Set_Casing (All_Lower_Case);
5283
5284                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5285                            Set_Casing
5286                              (Identifier_Casing (Current_Source_File));
5287                            Error_Msg_String (1 .. Rnm'Length) :=
5288                              Name_Buffer (1 .. Name_Len);
5289                            Error_Msg_Strlen := Rnm'Length;
5290                            Error_Msg_N -- CODEFIX
5291                              ("\possible misspelling of ""~""",
5292                               Get_Pragma_Arg (Arg));
5293                            exit;
5294                         end if;
5295                      end;
5296                   end loop;
5297
5298                   raise Pragma_Exit;
5299                end if;
5300
5301                if Implementation_Restriction (R_Id) then
5302                   Check_Restriction (No_Implementation_Restrictions, Arg);
5303                end if;
5304
5305                --  If this is a warning, then set the warning unless we already
5306                --  have a real restriction active (we never want a warning to
5307                --  override a real restriction).
5308
5309                if Warn then
5310                   if not Restriction_Active (R_Id) then
5311                      Set_Restriction (R_Id, N);
5312                      Restriction_Warnings (R_Id) := True;
5313                   end if;
5314
5315                --  If real restriction case, then set it and make sure that the
5316                --  restriction warning flag is off, since a real restriction
5317                --  always overrides a warning.
5318
5319                else
5320                   Set_Restriction (R_Id, N);
5321                   Restriction_Warnings (R_Id) := False;
5322                end if;
5323
5324                --  Check for obsolescent restrictions in Ada 2005 mode
5325
5326                if not Warn
5327                  and then Ada_Version >= Ada_2005
5328                  and then (R_Id = No_Asynchronous_Control
5329                             or else
5330                            R_Id = No_Unchecked_Deallocation
5331                             or else
5332                            R_Id = No_Unchecked_Conversion)
5333                then
5334                   Check_Restriction (No_Obsolescent_Features, N);
5335                end if;
5336
5337                --  A very special case that must be processed here: pragma
5338                --  Restrictions (No_Exceptions) turns off all run-time
5339                --  checking. This is a bit dubious in terms of the formal
5340                --  language definition, but it is what is intended by RM
5341                --  H.4(12). Restriction_Warnings never affects generated code
5342                --  so this is done only in the real restriction case.
5343
5344                if R_Id = No_Exceptions and then not Warn then
5345                   Scope_Suppress := (others => True);
5346                end if;
5347
5348             --  Case of No_Dependence => unit-name. Note that the parser
5349             --  already made the necessary entry in the No_Dependence table.
5350
5351             elsif Id = Name_No_Dependence then
5352                Check_Unit_Name (Expr);
5353
5354             --  All other cases of restriction identifier present
5355
5356             else
5357                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5358                Analyze_And_Resolve (Expr, Any_Integer);
5359
5360                if R_Id not in All_Parameter_Restrictions then
5361                   Error_Pragma_Arg
5362                     ("invalid restriction parameter identifier", Arg);
5363
5364                elsif not Is_OK_Static_Expression (Expr) then
5365                   Flag_Non_Static_Expr
5366                     ("value must be static expression!", Expr);
5367                   raise Pragma_Exit;
5368
5369                elsif not Is_Integer_Type (Etype (Expr))
5370                  or else Expr_Value (Expr) < 0
5371                then
5372                   Error_Pragma_Arg
5373                     ("value must be non-negative integer", Arg);
5374                end if;
5375
5376                --  Restriction pragma is active
5377
5378                Val := Expr_Value (Expr);
5379
5380                if not UI_Is_In_Int_Range (Val) then
5381                   Error_Pragma_Arg
5382                     ("pragma ignored, value too large?", Arg);
5383                end if;
5384
5385                --  Warning case. If the real restriction is active, then we
5386                --  ignore the request, since warning never overrides a real
5387                --  restriction. Otherwise we set the proper warning. Note that
5388                --  this circuit sets the warning again if it is already set,
5389                --  which is what we want, since the constant may have changed.
5390
5391                if Warn then
5392                   if not Restriction_Active (R_Id) then
5393                      Set_Restriction
5394                        (R_Id, N, Integer (UI_To_Int (Val)));
5395                      Restriction_Warnings (R_Id) := True;
5396                   end if;
5397
5398                --  Real restriction case, set restriction and make sure warning
5399                --  flag is off since real restriction always overrides warning.
5400
5401                else
5402                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5403                   Restriction_Warnings (R_Id) := False;
5404                end if;
5405             end if;
5406
5407             Next (Arg);
5408          end loop;
5409       end Process_Restrictions_Or_Restriction_Warnings;
5410
5411       ---------------------------------
5412       -- Process_Suppress_Unsuppress --
5413       ---------------------------------
5414
5415       --  Note: this procedure makes entries in the check suppress data
5416       --  structures managed by Sem. See spec of package Sem for full
5417       --  details on how we handle recording of check suppression.
5418
5419       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5420          C    : Check_Id;
5421          E_Id : Node_Id;
5422          E    : Entity_Id;
5423
5424          In_Package_Spec : constant Boolean :=
5425                              Is_Package_Or_Generic_Package (Current_Scope)
5426                                and then not In_Package_Body (Current_Scope);
5427
5428          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5429          --  Used to suppress a single check on the given entity
5430
5431          --------------------------------
5432          -- Suppress_Unsuppress_Echeck --
5433          --------------------------------
5434
5435          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5436          begin
5437             Set_Checks_May_Be_Suppressed (E);
5438
5439             if In_Package_Spec then
5440                Push_Global_Suppress_Stack_Entry
5441                  (Entity   => E,
5442                   Check    => C,
5443                   Suppress => Suppress_Case);
5444
5445             else
5446                Push_Local_Suppress_Stack_Entry
5447                  (Entity   => E,
5448                   Check    => C,
5449                   Suppress => Suppress_Case);
5450             end if;
5451
5452             --  If this is a first subtype, and the base type is distinct,
5453             --  then also set the suppress flags on the base type.
5454
5455             if Is_First_Subtype (E)
5456               and then Etype (E) /= E
5457             then
5458                Suppress_Unsuppress_Echeck (Etype (E), C);
5459             end if;
5460          end Suppress_Unsuppress_Echeck;
5461
5462       --  Start of processing for Process_Suppress_Unsuppress
5463
5464       begin
5465          --  Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5466          --  user code: we want to generate checks for analysis purposes, as
5467          --  set respectively by -gnatC and -gnatd.F
5468
5469          if (CodePeer_Mode or Alfa_Mode)
5470            and then Comes_From_Source (N)
5471          then
5472             return;
5473          end if;
5474
5475          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5476          --  declarative part or a package spec (RM 11.5(5)).
5477
5478          if not Is_Configuration_Pragma then
5479             Check_Is_In_Decl_Part_Or_Package_Spec;
5480          end if;
5481
5482          Check_At_Least_N_Arguments (1);
5483          Check_At_Most_N_Arguments (2);
5484          Check_No_Identifier (Arg1);
5485          Check_Arg_Is_Identifier (Arg1);
5486
5487          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5488
5489          if C = No_Check_Id then
5490             Error_Pragma_Arg
5491               ("argument of pragma% is not valid check name", Arg1);
5492          end if;
5493
5494          if not Suppress_Case
5495            and then (C = All_Checks or else C = Overflow_Check)
5496          then
5497             Opt.Overflow_Checks_Unsuppressed := True;
5498          end if;
5499
5500          if Arg_Count = 1 then
5501
5502             --  Make an entry in the local scope suppress table. This is the
5503             --  table that directly shows the current value of the scope
5504             --  suppress check for any check id value.
5505
5506             if C = All_Checks then
5507
5508                --  For All_Checks, we set all specific predefined checks with
5509                --  the exception of Elaboration_Check, which is handled
5510                --  specially because of not wanting All_Checks to have the
5511                --  effect of deactivating static elaboration order processing.
5512
5513                for J in Scope_Suppress'Range loop
5514                   if J /= Elaboration_Check then
5515                      Scope_Suppress (J) := Suppress_Case;
5516                   end if;
5517                end loop;
5518
5519             --  If not All_Checks, and predefined check, then set appropriate
5520             --  scope entry. Note that we will set Elaboration_Check if this
5521             --  is explicitly specified.
5522
5523             elsif C in Predefined_Check_Id then
5524                Scope_Suppress (C) := Suppress_Case;
5525             end if;
5526
5527             --  Also make an entry in the Local_Entity_Suppress table
5528
5529             Push_Local_Suppress_Stack_Entry
5530               (Entity   => Empty,
5531                Check    => C,
5532                Suppress => Suppress_Case);
5533
5534          --  Case of two arguments present, where the check is suppressed for
5535          --  a specified entity (given as the second argument of the pragma)
5536
5537          else
5538             --  This is obsolescent in Ada 2005 mode
5539
5540             if Ada_Version >= Ada_2005 then
5541                Check_Restriction (No_Obsolescent_Features, Arg2);
5542             end if;
5543
5544             Check_Optional_Identifier (Arg2, Name_On);
5545             E_Id := Get_Pragma_Arg (Arg2);
5546             Analyze (E_Id);
5547
5548             if not Is_Entity_Name (E_Id) then
5549                Error_Pragma_Arg
5550                  ("second argument of pragma% must be entity name", Arg2);
5551             end if;
5552
5553             E := Entity (E_Id);
5554
5555             if E = Any_Id then
5556                return;
5557             end if;
5558
5559             --  Enforce RM 11.5(7) which requires that for a pragma that
5560             --  appears within a package spec, the named entity must be
5561             --  within the package spec. We allow the package name itself
5562             --  to be mentioned since that makes sense, although it is not
5563             --  strictly allowed by 11.5(7).
5564
5565             if In_Package_Spec
5566               and then E /= Current_Scope
5567               and then Scope (E) /= Current_Scope
5568             then
5569                Error_Pragma_Arg
5570                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5571                   Arg2);
5572             end if;
5573
5574             --  Loop through homonyms. As noted below, in the case of a package
5575             --  spec, only homonyms within the package spec are considered.
5576
5577             loop
5578                Suppress_Unsuppress_Echeck (E, C);
5579
5580                if Is_Generic_Instance (E)
5581                  and then Is_Subprogram (E)
5582                  and then Present (Alias (E))
5583                then
5584                   Suppress_Unsuppress_Echeck (Alias (E), C);
5585                end if;
5586
5587                --  Move to next homonym if not aspect spec case
5588
5589                exit when From_Aspect_Specification (N);
5590                E := Homonym (E);
5591                exit when No (E);
5592
5593                --  If we are within a package specification, the pragma only
5594                --  applies to homonyms in the same scope.
5595
5596                exit when In_Package_Spec
5597                  and then Scope (E) /= Current_Scope;
5598             end loop;
5599          end if;
5600       end Process_Suppress_Unsuppress;
5601
5602       ------------------
5603       -- Set_Exported --
5604       ------------------
5605
5606       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5607       begin
5608          if Is_Imported (E) then
5609             Error_Pragma_Arg
5610               ("cannot export entity& that was previously imported", Arg);
5611
5612          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5613             Error_Pragma_Arg
5614               ("cannot export entity& that has an address clause", Arg);
5615          end if;
5616
5617          Set_Is_Exported (E);
5618
5619          --  Generate a reference for entity explicitly, because the
5620          --  identifier may be overloaded and name resolution will not
5621          --  generate one.
5622
5623          Generate_Reference (E, Arg);
5624
5625          --  Deal with exporting non-library level entity
5626
5627          if not Is_Library_Level_Entity (E) then
5628
5629             --  Not allowed at all for subprograms
5630
5631             if Is_Subprogram (E) then
5632                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5633
5634             --  Otherwise set public and statically allocated
5635
5636             else
5637                Set_Is_Public (E);
5638                Set_Is_Statically_Allocated (E);
5639
5640                --  Warn if the corresponding W flag is set and the pragma comes
5641                --  from source. The latter may not be true e.g. on VMS where we
5642                --  expand export pragmas for exception codes associated with
5643                --  imported or exported exceptions. We do not want to generate
5644                --  a warning for something that the user did not write.
5645
5646                if Warn_On_Export_Import
5647                  and then Comes_From_Source (Arg)
5648                then
5649                   Error_Msg_NE
5650                     ("?& has been made static as a result of Export", Arg, E);
5651                   Error_Msg_N
5652                     ("\this usage is non-standard and non-portable", Arg);
5653                end if;
5654             end if;
5655          end if;
5656
5657          if Warn_On_Export_Import and then Is_Type (E) then
5658             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5659          end if;
5660
5661          if Warn_On_Export_Import and Inside_A_Generic then
5662             Error_Msg_NE
5663               ("all instances of& will have the same external name?", Arg, E);
5664          end if;
5665       end Set_Exported;
5666
5667       ----------------------------------------------
5668       -- Set_Extended_Import_Export_External_Name --
5669       ----------------------------------------------
5670
5671       procedure Set_Extended_Import_Export_External_Name
5672         (Internal_Ent : Entity_Id;
5673          Arg_External : Node_Id)
5674       is
5675          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5676          New_Name : Node_Id;
5677
5678       begin
5679          if No (Arg_External) then
5680             return;
5681          end if;
5682
5683          Check_Arg_Is_External_Name (Arg_External);
5684
5685          if Nkind (Arg_External) = N_String_Literal then
5686             if String_Length (Strval (Arg_External)) = 0 then
5687                return;
5688             else
5689                New_Name := Adjust_External_Name_Case (Arg_External);
5690             end if;
5691
5692          elsif Nkind (Arg_External) = N_Identifier then
5693             New_Name := Get_Default_External_Name (Arg_External);
5694
5695          --  Check_Arg_Is_External_Name should let through only identifiers and
5696          --  string literals or static string expressions (which are folded to
5697          --  string literals).
5698
5699          else
5700             raise Program_Error;
5701          end if;
5702
5703          --  If we already have an external name set (by a prior normal Import
5704          --  or Export pragma), then the external names must match
5705
5706          if Present (Interface_Name (Internal_Ent)) then
5707             Check_Matching_Internal_Names : declare
5708                S1 : constant String_Id := Strval (Old_Name);
5709                S2 : constant String_Id := Strval (New_Name);
5710
5711                procedure Mismatch;
5712                --  Called if names do not match
5713
5714                --------------
5715                -- Mismatch --
5716                --------------
5717
5718                procedure Mismatch is
5719                begin
5720                   Error_Msg_Sloc := Sloc (Old_Name);
5721                   Error_Pragma_Arg
5722                     ("external name does not match that given #",
5723                      Arg_External);
5724                end Mismatch;
5725
5726             --  Start of processing for Check_Matching_Internal_Names
5727
5728             begin
5729                if String_Length (S1) /= String_Length (S2) then
5730                   Mismatch;
5731
5732                else
5733                   for J in 1 .. String_Length (S1) loop
5734                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5735                         Mismatch;
5736                      end if;
5737                   end loop;
5738                end if;
5739             end Check_Matching_Internal_Names;
5740
5741          --  Otherwise set the given name
5742
5743          else
5744             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5745             Check_Duplicated_Export_Name (New_Name);
5746          end if;
5747       end Set_Extended_Import_Export_External_Name;
5748
5749       ------------------
5750       -- Set_Imported --
5751       ------------------
5752
5753       procedure Set_Imported (E : Entity_Id) is
5754       begin
5755          --  Error message if already imported or exported
5756
5757          if Is_Exported (E) or else Is_Imported (E) then
5758
5759             --  Error if being set Exported twice
5760
5761             if Is_Exported (E) then
5762                Error_Msg_NE ("entity& was previously exported", N, E);
5763
5764             --  OK if Import/Interface case
5765
5766             elsif Import_Interface_Present (N) then
5767                goto OK;
5768
5769             --  Error if being set Imported twice
5770
5771             else
5772                Error_Msg_NE ("entity& was previously imported", N, E);
5773             end if;
5774
5775             Error_Msg_Name_1 := Pname;
5776             Error_Msg_N
5777               ("\(pragma% applies to all previous entities)", N);
5778
5779             Error_Msg_Sloc  := Sloc (E);
5780             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5781
5782          --  Here if not previously imported or exported, OK to import
5783
5784          else
5785             Set_Is_Imported (E);
5786
5787             --  If the entity is an object that is not at the library level,
5788             --  then it is statically allocated. We do not worry about objects
5789             --  with address clauses in this context since they are not really
5790             --  imported in the linker sense.
5791
5792             if Is_Object (E)
5793               and then not Is_Library_Level_Entity (E)
5794               and then No (Address_Clause (E))
5795             then
5796                Set_Is_Statically_Allocated (E);
5797             end if;
5798          end if;
5799
5800          <<OK>> null;
5801       end Set_Imported;
5802
5803       -------------------------
5804       -- Set_Mechanism_Value --
5805       -------------------------
5806
5807       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5808       --  analyzed, since it is semantic nonsense), so we get it in the exact
5809       --  form created by the parser.
5810
5811       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5812          Class        : Node_Id;
5813          Param        : Node_Id;
5814          Mech_Name_Id : Name_Id;
5815
5816          procedure Bad_Class;
5817          --  Signal bad descriptor class name
5818
5819          procedure Bad_Mechanism;
5820          --  Signal bad mechanism name
5821
5822          ---------------
5823          -- Bad_Class --
5824          ---------------
5825
5826          procedure Bad_Class is
5827          begin
5828             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5829          end Bad_Class;
5830
5831          -------------------------
5832          -- Bad_Mechanism_Value --
5833          -------------------------
5834
5835          procedure Bad_Mechanism is
5836          begin
5837             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5838          end Bad_Mechanism;
5839
5840       --  Start of processing for Set_Mechanism_Value
5841
5842       begin
5843          if Mechanism (Ent) /= Default_Mechanism then
5844             Error_Msg_NE
5845               ("mechanism for & has already been set", Mech_Name, Ent);
5846          end if;
5847
5848          --  MECHANISM_NAME ::= value | reference | descriptor |
5849          --                     short_descriptor
5850
5851          if Nkind (Mech_Name) = N_Identifier then
5852             if Chars (Mech_Name) = Name_Value then
5853                Set_Mechanism (Ent, By_Copy);
5854                return;
5855
5856             elsif Chars (Mech_Name) = Name_Reference then
5857                Set_Mechanism (Ent, By_Reference);
5858                return;
5859
5860             elsif Chars (Mech_Name) = Name_Descriptor then
5861                Check_VMS (Mech_Name);
5862
5863                --  Descriptor => Short_Descriptor if pragma was given
5864
5865                if Short_Descriptors then
5866                   Set_Mechanism (Ent, By_Short_Descriptor);
5867                else
5868                   Set_Mechanism (Ent, By_Descriptor);
5869                end if;
5870
5871                return;
5872
5873             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5874                Check_VMS (Mech_Name);
5875                Set_Mechanism (Ent, By_Short_Descriptor);
5876                return;
5877
5878             elsif Chars (Mech_Name) = Name_Copy then
5879                Error_Pragma_Arg
5880                  ("bad mechanism name, Value assumed", Mech_Name);
5881
5882             else
5883                Bad_Mechanism;
5884             end if;
5885
5886          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5887          --                     short_descriptor (CLASS_NAME)
5888          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5889
5890          --  Note: this form is parsed as an indexed component
5891
5892          elsif Nkind (Mech_Name) = N_Indexed_Component then
5893             Class := First (Expressions (Mech_Name));
5894
5895             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5896              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5897                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5898              or else Present (Next (Class))
5899             then
5900                Bad_Mechanism;
5901             else
5902                Mech_Name_Id := Chars (Prefix (Mech_Name));
5903
5904                --  Change Descriptor => Short_Descriptor if pragma was given
5905
5906                if Mech_Name_Id = Name_Descriptor
5907                  and then Short_Descriptors
5908                then
5909                   Mech_Name_Id := Name_Short_Descriptor;
5910                end if;
5911             end if;
5912
5913          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5914          --                     short_descriptor (Class => CLASS_NAME)
5915          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5916
5917          --  Note: this form is parsed as a function call
5918
5919          elsif Nkind (Mech_Name) = N_Function_Call then
5920             Param := First (Parameter_Associations (Mech_Name));
5921
5922             if Nkind (Name (Mech_Name)) /= N_Identifier
5923               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5924                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5925               or else Present (Next (Param))
5926               or else No (Selector_Name (Param))
5927               or else Chars (Selector_Name (Param)) /= Name_Class
5928             then
5929                Bad_Mechanism;
5930             else
5931                Class := Explicit_Actual_Parameter (Param);
5932                Mech_Name_Id := Chars (Name (Mech_Name));
5933             end if;
5934
5935          else
5936             Bad_Mechanism;
5937          end if;
5938
5939          --  Fall through here with Class set to descriptor class name
5940
5941          Check_VMS (Mech_Name);
5942
5943          if Nkind (Class) /= N_Identifier then
5944             Bad_Class;
5945
5946          elsif Mech_Name_Id = Name_Descriptor
5947            and then Chars (Class) = Name_UBS
5948          then
5949             Set_Mechanism (Ent, By_Descriptor_UBS);
5950
5951          elsif Mech_Name_Id = Name_Descriptor
5952            and then Chars (Class) = Name_UBSB
5953          then
5954             Set_Mechanism (Ent, By_Descriptor_UBSB);
5955
5956          elsif Mech_Name_Id = Name_Descriptor
5957            and then Chars (Class) = Name_UBA
5958          then
5959             Set_Mechanism (Ent, By_Descriptor_UBA);
5960
5961          elsif Mech_Name_Id = Name_Descriptor
5962            and then Chars (Class) = Name_S
5963          then
5964             Set_Mechanism (Ent, By_Descriptor_S);
5965
5966          elsif Mech_Name_Id = Name_Descriptor
5967            and then Chars (Class) = Name_SB
5968          then
5969             Set_Mechanism (Ent, By_Descriptor_SB);
5970
5971          elsif Mech_Name_Id = Name_Descriptor
5972            and then Chars (Class) = Name_A
5973          then
5974             Set_Mechanism (Ent, By_Descriptor_A);
5975
5976          elsif Mech_Name_Id = Name_Descriptor
5977            and then Chars (Class) = Name_NCA
5978          then
5979             Set_Mechanism (Ent, By_Descriptor_NCA);
5980
5981          elsif Mech_Name_Id = Name_Short_Descriptor
5982            and then Chars (Class) = Name_UBS
5983          then
5984             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5985
5986          elsif Mech_Name_Id = Name_Short_Descriptor
5987            and then Chars (Class) = Name_UBSB
5988          then
5989             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5990
5991          elsif Mech_Name_Id = Name_Short_Descriptor
5992            and then Chars (Class) = Name_UBA
5993          then
5994             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5995
5996          elsif Mech_Name_Id = Name_Short_Descriptor
5997            and then Chars (Class) = Name_S
5998          then
5999             Set_Mechanism (Ent, By_Short_Descriptor_S);
6000
6001          elsif Mech_Name_Id = Name_Short_Descriptor
6002            and then Chars (Class) = Name_SB
6003          then
6004             Set_Mechanism (Ent, By_Short_Descriptor_SB);
6005
6006          elsif Mech_Name_Id = Name_Short_Descriptor
6007            and then Chars (Class) = Name_A
6008          then
6009             Set_Mechanism (Ent, By_Short_Descriptor_A);
6010
6011          elsif Mech_Name_Id = Name_Short_Descriptor
6012            and then Chars (Class) = Name_NCA
6013          then
6014             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
6015
6016          else
6017             Bad_Class;
6018          end if;
6019       end Set_Mechanism_Value;
6020
6021       ---------------------------
6022       -- Set_Ravenscar_Profile --
6023       ---------------------------
6024
6025       --  The tasks to be done here are
6026
6027       --    Set required policies
6028
6029       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6030       --      pragma Locking_Policy (Ceiling_Locking)
6031
6032       --    Set Detect_Blocking mode
6033
6034       --    Set required restrictions (see System.Rident for detailed list)
6035
6036       --    Set the No_Dependence rules
6037       --      No_Dependence => Ada.Asynchronous_Task_Control
6038       --      No_Dependence => Ada.Calendar
6039       --      No_Dependence => Ada.Execution_Time.Group_Budget
6040       --      No_Dependence => Ada.Execution_Time.Timers
6041       --      No_Dependence => Ada.Task_Attributes
6042       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
6043
6044       procedure Set_Ravenscar_Profile (N : Node_Id) is
6045          Prefix_Entity   : Entity_Id;
6046          Selector_Entity : Entity_Id;
6047          Prefix_Node     : Node_Id;
6048          Node            : Node_Id;
6049
6050       begin
6051          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
6052
6053          if Task_Dispatching_Policy /= ' '
6054            and then Task_Dispatching_Policy /= 'F'
6055          then
6056             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
6057             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6058
6059          --  Set the FIFO_Within_Priorities policy, but always preserve
6060          --  System_Location since we like the error message with the run time
6061          --  name.
6062
6063          else
6064             Task_Dispatching_Policy := 'F';
6065
6066             if Task_Dispatching_Policy_Sloc /= System_Location then
6067                Task_Dispatching_Policy_Sloc := Loc;
6068             end if;
6069          end if;
6070
6071          --  pragma Locking_Policy (Ceiling_Locking)
6072
6073          if Locking_Policy /= ' '
6074            and then Locking_Policy /= 'C'
6075          then
6076             Error_Msg_Sloc := Locking_Policy_Sloc;
6077             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
6078
6079          --  Set the Ceiling_Locking policy, but preserve System_Location since
6080          --  we like the error message with the run time name.
6081
6082          else
6083             Locking_Policy := 'C';
6084
6085             if Locking_Policy_Sloc /= System_Location then
6086                Locking_Policy_Sloc := Loc;
6087             end if;
6088          end if;
6089
6090          --  pragma Detect_Blocking
6091
6092          Detect_Blocking := True;
6093
6094          --  Set the corresponding restrictions
6095
6096          Set_Profile_Restrictions
6097            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
6098
6099          --  Set the No_Dependence restrictions
6100
6101          --  The following No_Dependence restrictions:
6102          --    No_Dependence => Ada.Asynchronous_Task_Control
6103          --    No_Dependence => Ada.Calendar
6104          --    No_Dependence => Ada.Task_Attributes
6105          --  are already set by previous call to Set_Profile_Restrictions.
6106
6107          --  Set the following restrictions which were added to Ada 2005:
6108          --    No_Dependence => Ada.Execution_Time.Group_Budget
6109          --    No_Dependence => Ada.Execution_Time.Timers
6110
6111          if Ada_Version >= Ada_2005 then
6112             Name_Buffer (1 .. 3) := "ada";
6113             Name_Len := 3;
6114
6115             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6116
6117             Name_Buffer (1 .. 14) := "execution_time";
6118             Name_Len := 14;
6119
6120             Selector_Entity := Make_Identifier (Loc, Name_Find);
6121
6122             Prefix_Node :=
6123               Make_Selected_Component
6124                 (Sloc          => Loc,
6125                  Prefix        => Prefix_Entity,
6126                  Selector_Name => Selector_Entity);
6127
6128             Name_Buffer (1 .. 13) := "group_budgets";
6129             Name_Len := 13;
6130
6131             Selector_Entity := Make_Identifier (Loc, Name_Find);
6132
6133             Node :=
6134               Make_Selected_Component
6135                 (Sloc          => Loc,
6136                  Prefix        => Prefix_Node,
6137                  Selector_Name => Selector_Entity);
6138
6139             Set_Restriction_No_Dependence
6140               (Unit    => Node,
6141                Warn    => Treat_Restrictions_As_Warnings,
6142                Profile => Ravenscar);
6143
6144             Name_Buffer (1 .. 6) := "timers";
6145             Name_Len := 6;
6146
6147             Selector_Entity := Make_Identifier (Loc, Name_Find);
6148
6149             Node :=
6150               Make_Selected_Component
6151                 (Sloc          => Loc,
6152                  Prefix        => Prefix_Node,
6153                  Selector_Name => Selector_Entity);
6154
6155             Set_Restriction_No_Dependence
6156               (Unit    => Node,
6157                Warn    => Treat_Restrictions_As_Warnings,
6158                Profile => Ravenscar);
6159          end if;
6160
6161          --  Set the following restrictions which was added to Ada 2012 (see
6162          --  AI-0171):
6163          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
6164
6165          if Ada_Version >= Ada_2012 then
6166             Name_Buffer (1 .. 6) := "system";
6167             Name_Len := 6;
6168
6169             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6170
6171             Name_Buffer (1 .. 15) := "multiprocessors";
6172             Name_Len := 15;
6173
6174             Selector_Entity := Make_Identifier (Loc, Name_Find);
6175
6176             Prefix_Node :=
6177               Make_Selected_Component
6178                 (Sloc          => Loc,
6179                  Prefix        => Prefix_Entity,
6180                  Selector_Name => Selector_Entity);
6181
6182             Name_Buffer (1 .. 19) := "dispatching_domains";
6183             Name_Len := 19;
6184
6185             Selector_Entity := Make_Identifier (Loc, Name_Find);
6186
6187             Node :=
6188               Make_Selected_Component
6189                 (Sloc          => Loc,
6190                  Prefix        => Prefix_Node,
6191                  Selector_Name => Selector_Entity);
6192
6193             Set_Restriction_No_Dependence
6194               (Unit    => Node,
6195                Warn    => Treat_Restrictions_As_Warnings,
6196                Profile => Ravenscar);
6197          end if;
6198       end Set_Ravenscar_Profile;
6199
6200    --  Start of processing for Analyze_Pragma
6201
6202    begin
6203       --  The following code is a defense against recursion. Not clear that
6204       --  this can happen legitimately, but perhaps some error situations
6205       --  can cause it, and we did see this recursion during testing.
6206
6207       if Analyzed (N) then
6208          return;
6209       else
6210          Set_Analyzed (N, True);
6211       end if;
6212
6213       --  Deal with unrecognized pragma
6214
6215       if not Is_Pragma_Name (Pname) then
6216          if Warn_On_Unrecognized_Pragma then
6217             Error_Msg_Name_1 := Pname;
6218             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6219
6220             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6221                if Is_Bad_Spelling_Of (Pname, PN) then
6222                   Error_Msg_Name_1 := PN;
6223                   Error_Msg_N -- CODEFIX
6224                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6225                   exit;
6226                end if;
6227             end loop;
6228          end if;
6229
6230          return;
6231       end if;
6232
6233       --  Here to start processing for recognized pragma
6234
6235       Prag_Id := Get_Pragma_Id (Pname);
6236
6237       --  Preset arguments
6238
6239       Arg_Count := 0;
6240       Arg1      := Empty;
6241       Arg2      := Empty;
6242       Arg3      := Empty;
6243       Arg4      := Empty;
6244
6245       if Present (Pragma_Argument_Associations (N)) then
6246          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6247          Arg1 := First (Pragma_Argument_Associations (N));
6248
6249          if Present (Arg1) then
6250             Arg2 := Next (Arg1);
6251
6252             if Present (Arg2) then
6253                Arg3 := Next (Arg2);
6254
6255                if Present (Arg3) then
6256                   Arg4 := Next (Arg3);
6257                end if;
6258             end if;
6259          end if;
6260       end if;
6261
6262       --  An enumeration type defines the pragmas that are supported by the
6263       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6264       --  into the corresponding enumeration value for the following case.
6265
6266       case Prag_Id is
6267
6268          -----------------
6269          -- Abort_Defer --
6270          -----------------
6271
6272          --  pragma Abort_Defer;
6273
6274          when Pragma_Abort_Defer =>
6275             GNAT_Pragma;
6276             Check_Arg_Count (0);
6277
6278             --  The only required semantic processing is to check the
6279             --  placement. This pragma must appear at the start of the
6280             --  statement sequence of a handled sequence of statements.
6281
6282             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6283               or else N /= First (Statements (Parent (N)))
6284             then
6285                Pragma_Misplaced;
6286             end if;
6287
6288          ------------
6289          -- Ada_83 --
6290          ------------
6291
6292          --  pragma Ada_83;
6293
6294          --  Note: this pragma also has some specific processing in Par.Prag
6295          --  because we want to set the Ada version mode during parsing.
6296
6297          when Pragma_Ada_83 =>
6298             GNAT_Pragma;
6299             Check_Arg_Count (0);
6300
6301             --  We really should check unconditionally for proper configuration
6302             --  pragma placement, since we really don't want mixed Ada modes
6303             --  within a single unit, and the GNAT reference manual has always
6304             --  said this was a configuration pragma, but we did not check and
6305             --  are hesitant to add the check now.
6306
6307             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6308             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6309             --  or Ada 2012 mode.
6310
6311             if Ada_Version >= Ada_2005 then
6312                Check_Valid_Configuration_Pragma;
6313             end if;
6314
6315             --  Now set Ada 83 mode
6316
6317             Ada_Version := Ada_83;
6318             Ada_Version_Explicit := Ada_Version;
6319
6320          ------------
6321          -- Ada_95 --
6322          ------------
6323
6324          --  pragma Ada_95;
6325
6326          --  Note: this pragma also has some specific processing in Par.Prag
6327          --  because we want to set the Ada 83 version mode during parsing.
6328
6329          when Pragma_Ada_95 =>
6330             GNAT_Pragma;
6331             Check_Arg_Count (0);
6332
6333             --  We really should check unconditionally for proper configuration
6334             --  pragma placement, since we really don't want mixed Ada modes
6335             --  within a single unit, and the GNAT reference manual has always
6336             --  said this was a configuration pragma, but we did not check and
6337             --  are hesitant to add the check now.
6338
6339             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6340             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6341
6342             if Ada_Version >= Ada_2005 then
6343                Check_Valid_Configuration_Pragma;
6344             end if;
6345
6346             --  Now set Ada 95 mode
6347
6348             Ada_Version := Ada_95;
6349             Ada_Version_Explicit := Ada_Version;
6350
6351          ---------------------
6352          -- Ada_05/Ada_2005 --
6353          ---------------------
6354
6355          --  pragma Ada_05;
6356          --  pragma Ada_05 (LOCAL_NAME);
6357
6358          --  pragma Ada_2005;
6359          --  pragma Ada_2005 (LOCAL_NAME):
6360
6361          --  Note: these pragmas also have some specific processing in Par.Prag
6362          --  because we want to set the Ada 2005 version mode during parsing.
6363
6364          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6365             E_Id : Node_Id;
6366
6367          begin
6368             GNAT_Pragma;
6369
6370             if Arg_Count = 1 then
6371                Check_Arg_Is_Local_Name (Arg1);
6372                E_Id := Get_Pragma_Arg (Arg1);
6373
6374                if Etype (E_Id) = Any_Type then
6375                   return;
6376                end if;
6377
6378                Set_Is_Ada_2005_Only (Entity (E_Id));
6379
6380             else
6381                Check_Arg_Count (0);
6382
6383                --  For Ada_2005 we unconditionally enforce the documented
6384                --  configuration pragma placement, since we do not want to
6385                --  tolerate mixed modes in a unit involving Ada 2005. That
6386                --  would cause real difficulties for those cases where there
6387                --  are incompatibilities between Ada 95 and Ada 2005.
6388
6389                Check_Valid_Configuration_Pragma;
6390
6391                --  Now set appropriate Ada mode
6392
6393                Ada_Version          := Ada_2005;
6394                Ada_Version_Explicit := Ada_2005;
6395             end if;
6396          end;
6397
6398          ---------------------
6399          -- Ada_12/Ada_2012 --
6400          ---------------------
6401
6402          --  pragma Ada_12;
6403          --  pragma Ada_12 (LOCAL_NAME);
6404
6405          --  pragma Ada_2012;
6406          --  pragma Ada_2012 (LOCAL_NAME):
6407
6408          --  Note: these pragmas also have some specific processing in Par.Prag
6409          --  because we want to set the Ada 2012 version mode during parsing.
6410
6411          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6412             E_Id : Node_Id;
6413
6414          begin
6415             GNAT_Pragma;
6416
6417             if Arg_Count = 1 then
6418                Check_Arg_Is_Local_Name (Arg1);
6419                E_Id := Get_Pragma_Arg (Arg1);
6420
6421                if Etype (E_Id) = Any_Type then
6422                   return;
6423                end if;
6424
6425                Set_Is_Ada_2012_Only (Entity (E_Id));
6426
6427             else
6428                Check_Arg_Count (0);
6429
6430                --  For Ada_2012 we unconditionally enforce the documented
6431                --  configuration pragma placement, since we do not want to
6432                --  tolerate mixed modes in a unit involving Ada 2012. That
6433                --  would cause real difficulties for those cases where there
6434                --  are incompatibilities between Ada 95 and Ada 2012. We could
6435                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6436
6437                Check_Valid_Configuration_Pragma;
6438
6439                --  Now set appropriate Ada mode
6440
6441                Ada_Version          := Ada_2012;
6442                Ada_Version_Explicit := Ada_2012;
6443             end if;
6444          end;
6445
6446          ----------------------
6447          -- All_Calls_Remote --
6448          ----------------------
6449
6450          --  pragma All_Calls_Remote [(library_package_NAME)];
6451
6452          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6453             Lib_Entity : Entity_Id;
6454
6455          begin
6456             Check_Ada_83_Warning;
6457             Check_Valid_Library_Unit_Pragma;
6458
6459             if Nkind (N) = N_Null_Statement then
6460                return;
6461             end if;
6462
6463             Lib_Entity := Find_Lib_Unit_Name;
6464
6465             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6466
6467             if Present (Lib_Entity)
6468               and then not Debug_Flag_U
6469             then
6470                if not Is_Remote_Call_Interface (Lib_Entity) then
6471                   Error_Pragma ("pragma% only apply to rci unit");
6472
6473                --  Set flag for entity of the library unit
6474
6475                else
6476                   Set_Has_All_Calls_Remote (Lib_Entity);
6477                end if;
6478
6479             end if;
6480          end All_Calls_Remote;
6481
6482          --------------
6483          -- Annotate --
6484          --------------
6485
6486          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6487          --  ARG ::= NAME | EXPRESSION
6488
6489          --  The first two arguments are by convention intended to refer to an
6490          --  external tool and a tool-specific function. These arguments are
6491          --  not analyzed.
6492
6493          when Pragma_Annotate => Annotate : declare
6494             Arg : Node_Id;
6495             Exp : Node_Id;
6496
6497          begin
6498             GNAT_Pragma;
6499             Check_At_Least_N_Arguments (1);
6500             Check_Arg_Is_Identifier (Arg1);
6501             Check_No_Identifiers;
6502             Store_Note (N);
6503
6504             --  Second parameter is optional, it is never analyzed
6505
6506             if No (Arg2) then
6507                null;
6508
6509             --  Here if we have a second parameter
6510
6511             else
6512                --  Second parameter must be identifier
6513
6514                Check_Arg_Is_Identifier (Arg2);
6515
6516                --  Process remaining parameters if any
6517
6518                Arg := Next (Arg2);
6519                while Present (Arg) loop
6520                   Exp := Get_Pragma_Arg (Arg);
6521                   Analyze (Exp);
6522
6523                   if Is_Entity_Name (Exp) then
6524                      null;
6525
6526                   --  For string literals, we assume Standard_String as the
6527                   --  type, unless the string contains wide or wide_wide
6528                   --  characters.
6529
6530                   elsif Nkind (Exp) = N_String_Literal then
6531                      if Has_Wide_Wide_Character (Exp) then
6532                         Resolve (Exp, Standard_Wide_Wide_String);
6533                      elsif Has_Wide_Character (Exp) then
6534                         Resolve (Exp, Standard_Wide_String);
6535                      else
6536                         Resolve (Exp, Standard_String);
6537                      end if;
6538
6539                   elsif Is_Overloaded (Exp) then
6540                         Error_Pragma_Arg
6541                           ("ambiguous argument for pragma%", Exp);
6542
6543                   else
6544                      Resolve (Exp);
6545                   end if;
6546
6547                   Next (Arg);
6548                end loop;
6549             end if;
6550          end Annotate;
6551
6552          ------------
6553          -- Assert --
6554          ------------
6555
6556          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6557          --                 [, [Message =>] Static_String_EXPRESSION]);
6558
6559          when Pragma_Assert => Assert : declare
6560             Expr : Node_Id;
6561             Newa : List_Id;
6562
6563          begin
6564             Ada_2005_Pragma;
6565             Check_At_Least_N_Arguments (1);
6566             Check_At_Most_N_Arguments (2);
6567             Check_Arg_Order ((Name_Check, Name_Message));
6568             Check_Optional_Identifier (Arg1, Name_Check);
6569
6570             --  We treat pragma Assert as equivalent to:
6571
6572             --    pragma Check (Assertion, condition [, msg]);
6573
6574             --  So rewrite pragma in this manner, and analyze the result
6575
6576             Expr := Get_Pragma_Arg (Arg1);
6577             Newa := New_List (
6578               Make_Pragma_Argument_Association (Loc,
6579                 Expression => Make_Identifier (Loc, Name_Assertion)),
6580
6581               Make_Pragma_Argument_Association (Sloc (Expr),
6582                 Expression => Expr));
6583
6584             if Arg_Count > 1 then
6585                Check_Optional_Identifier (Arg2, Name_Message);
6586                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6587                Append_To (Newa, Relocate_Node (Arg2));
6588             end if;
6589
6590             Rewrite (N,
6591               Make_Pragma (Loc,
6592                 Chars                        => Name_Check,
6593                 Pragma_Argument_Associations => Newa));
6594             Analyze (N);
6595          end Assert;
6596
6597          ----------------------
6598          -- Assertion_Policy --
6599          ----------------------
6600
6601          --  pragma Assertion_Policy (Check | Disable |Ignore)
6602
6603          when Pragma_Assertion_Policy => Assertion_Policy : declare
6604             Policy : Node_Id;
6605
6606          begin
6607             Ada_2005_Pragma;
6608             Check_Valid_Configuration_Pragma;
6609             Check_Arg_Count (1);
6610             Check_No_Identifiers;
6611             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6612
6613             --  We treat pragma Assertion_Policy as equivalent to:
6614
6615             --    pragma Check_Policy (Assertion, policy)
6616
6617             --  So rewrite the pragma in that manner and link on to the chain
6618             --  of Check_Policy pragmas, marking the pragma as analyzed.
6619
6620             Policy := Get_Pragma_Arg (Arg1);
6621
6622             Rewrite (N,
6623               Make_Pragma (Loc,
6624                 Chars => Name_Check_Policy,
6625
6626                 Pragma_Argument_Associations => New_List (
6627                   Make_Pragma_Argument_Association (Loc,
6628                     Expression => Make_Identifier (Loc, Name_Assertion)),
6629
6630                   Make_Pragma_Argument_Association (Loc,
6631                     Expression =>
6632                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6633
6634             Set_Analyzed (N);
6635             Set_Next_Pragma (N, Opt.Check_Policy_List);
6636             Opt.Check_Policy_List := N;
6637          end Assertion_Policy;
6638
6639          ------------------------------
6640          -- Assume_No_Invalid_Values --
6641          ------------------------------
6642
6643          --  pragma Assume_No_Invalid_Values (On | Off);
6644
6645          when Pragma_Assume_No_Invalid_Values =>
6646             GNAT_Pragma;
6647             Check_Valid_Configuration_Pragma;
6648             Check_Arg_Count (1);
6649             Check_No_Identifiers;
6650             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6651
6652             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6653                Assume_No_Invalid_Values := True;
6654             else
6655                Assume_No_Invalid_Values := False;
6656             end if;
6657
6658          ---------------
6659          -- AST_Entry --
6660          ---------------
6661
6662          --  pragma AST_Entry (entry_IDENTIFIER);
6663
6664          when Pragma_AST_Entry => AST_Entry : declare
6665             Ent : Node_Id;
6666
6667          begin
6668             GNAT_Pragma;
6669             Check_VMS (N);
6670             Check_Arg_Count (1);
6671             Check_No_Identifiers;
6672             Check_Arg_Is_Local_Name (Arg1);
6673             Ent := Entity (Get_Pragma_Arg (Arg1));
6674
6675             --  Note: the implementation of the AST_Entry pragma could handle
6676             --  the entry family case fine, but for now we are consistent with
6677             --  the DEC rules, and do not allow the pragma, which of course
6678             --  has the effect of also forbidding the attribute.
6679
6680             if Ekind (Ent) /= E_Entry then
6681                Error_Pragma_Arg
6682                  ("pragma% argument must be simple entry name", Arg1);
6683
6684             elsif Is_AST_Entry (Ent) then
6685                Error_Pragma_Arg
6686                  ("duplicate % pragma for entry", Arg1);
6687
6688             elsif Has_Homonym (Ent) then
6689                Error_Pragma_Arg
6690                  ("pragma% argument cannot specify overloaded entry", Arg1);
6691
6692             else
6693                declare
6694                   FF : constant Entity_Id := First_Formal (Ent);
6695
6696                begin
6697                   if Present (FF) then
6698                      if Present (Next_Formal (FF)) then
6699                         Error_Pragma_Arg
6700                           ("entry for pragma% can have only one argument",
6701                            Arg1);
6702
6703                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6704                         Error_Pragma_Arg
6705                           ("entry parameter for pragma% must have mode IN",
6706                            Arg1);
6707                      end if;
6708                   end if;
6709                end;
6710
6711                Set_Is_AST_Entry (Ent);
6712             end if;
6713          end AST_Entry;
6714
6715          ------------------
6716          -- Asynchronous --
6717          ------------------
6718
6719          --  pragma Asynchronous (LOCAL_NAME);
6720
6721          when Pragma_Asynchronous => Asynchronous : declare
6722             Nm     : Entity_Id;
6723             C_Ent  : Entity_Id;
6724             L      : List_Id;
6725             S      : Node_Id;
6726             N      : Node_Id;
6727             Formal : Entity_Id;
6728
6729             procedure Process_Async_Pragma;
6730             --  Common processing for procedure and access-to-procedure case
6731
6732             --------------------------
6733             -- Process_Async_Pragma --
6734             --------------------------
6735
6736             procedure Process_Async_Pragma is
6737             begin
6738                if No (L) then
6739                   Set_Is_Asynchronous (Nm);
6740                   return;
6741                end if;
6742
6743                --  The formals should be of mode IN (RM E.4.1(6))
6744
6745                S := First (L);
6746                while Present (S) loop
6747                   Formal := Defining_Identifier (S);
6748
6749                   if Nkind (Formal) = N_Defining_Identifier
6750                     and then Ekind (Formal) /= E_In_Parameter
6751                   then
6752                      Error_Pragma_Arg
6753                        ("pragma% procedure can only have IN parameter",
6754                         Arg1);
6755                   end if;
6756
6757                   Next (S);
6758                end loop;
6759
6760                Set_Is_Asynchronous (Nm);
6761             end Process_Async_Pragma;
6762
6763          --  Start of processing for pragma Asynchronous
6764
6765          begin
6766             Check_Ada_83_Warning;
6767             Check_No_Identifiers;
6768             Check_Arg_Count (1);
6769             Check_Arg_Is_Local_Name (Arg1);
6770
6771             if Debug_Flag_U then
6772                return;
6773             end if;
6774
6775             C_Ent := Cunit_Entity (Current_Sem_Unit);
6776             Analyze (Get_Pragma_Arg (Arg1));
6777             Nm := Entity (Get_Pragma_Arg (Arg1));
6778
6779             if not Is_Remote_Call_Interface (C_Ent)
6780               and then not Is_Remote_Types (C_Ent)
6781             then
6782                --  This pragma should only appear in an RCI or Remote Types
6783                --  unit (RM E.4.1(4)).
6784
6785                Error_Pragma
6786                  ("pragma% not in Remote_Call_Interface or " &
6787                   "Remote_Types unit");
6788             end if;
6789
6790             if Ekind (Nm) = E_Procedure
6791               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6792             then
6793                if not Is_Remote_Call_Interface (Nm) then
6794                   Error_Pragma_Arg
6795                     ("pragma% cannot be applied on non-remote procedure",
6796                      Arg1);
6797                end if;
6798
6799                L := Parameter_Specifications (Parent (Nm));
6800                Process_Async_Pragma;
6801                return;
6802
6803             elsif Ekind (Nm) = E_Function then
6804                Error_Pragma_Arg
6805                  ("pragma% cannot be applied to function", Arg1);
6806
6807             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6808                   if Is_Record_Type (Nm) then
6809
6810                   --  A record type that is the Equivalent_Type for a remote
6811                   --  access-to-subprogram type.
6812
6813                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6814
6815                   else
6816                      --  A non-expanded RAS type (distribution is not enabled)
6817
6818                      N := Declaration_Node (Nm);
6819                   end if;
6820
6821                if Nkind (N) = N_Full_Type_Declaration
6822                  and then Nkind (Type_Definition (N)) =
6823                                      N_Access_Procedure_Definition
6824                then
6825                   L := Parameter_Specifications (Type_Definition (N));
6826                   Process_Async_Pragma;
6827
6828                   if Is_Asynchronous (Nm)
6829                     and then Expander_Active
6830                     and then Get_PCS_Name /= Name_No_DSA
6831                   then
6832                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6833                   end if;
6834
6835                else
6836                   Error_Pragma_Arg
6837                     ("pragma% cannot reference access-to-function type",
6838                     Arg1);
6839                end if;
6840
6841             --  Only other possibility is Access-to-class-wide type
6842
6843             elsif Is_Access_Type (Nm)
6844               and then Is_Class_Wide_Type (Designated_Type (Nm))
6845             then
6846                Check_First_Subtype (Arg1);
6847                Set_Is_Asynchronous (Nm);
6848                if Expander_Active then
6849                   RACW_Type_Is_Asynchronous (Nm);
6850                end if;
6851
6852             else
6853                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6854             end if;
6855          end Asynchronous;
6856
6857          ------------
6858          -- Atomic --
6859          ------------
6860
6861          --  pragma Atomic (LOCAL_NAME);
6862
6863          when Pragma_Atomic =>
6864             Process_Atomic_Shared_Volatile;
6865
6866          -----------------------
6867          -- Atomic_Components --
6868          -----------------------
6869
6870          --  pragma Atomic_Components (array_LOCAL_NAME);
6871
6872          --  This processing is shared by Volatile_Components
6873
6874          when Pragma_Atomic_Components   |
6875               Pragma_Volatile_Components =>
6876
6877          Atomic_Components : declare
6878             E_Id : Node_Id;
6879             E    : Entity_Id;
6880             D    : Node_Id;
6881             K    : Node_Kind;
6882
6883          begin
6884             Check_Ada_83_Warning;
6885             Check_No_Identifiers;
6886             Check_Arg_Count (1);
6887             Check_Arg_Is_Local_Name (Arg1);
6888             E_Id := Get_Pragma_Arg (Arg1);
6889
6890             if Etype (E_Id) = Any_Type then
6891                return;
6892             end if;
6893
6894             E := Entity (E_Id);
6895
6896             Check_Duplicate_Pragma (E);
6897
6898             if Rep_Item_Too_Early (E, N)
6899                  or else
6900                Rep_Item_Too_Late (E, N)
6901             then
6902                return;
6903             end if;
6904
6905             D := Declaration_Node (E);
6906             K := Nkind (D);
6907
6908             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6909               or else
6910                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6911                    and then Nkind (D) = N_Object_Declaration
6912                    and then Nkind (Object_Definition (D)) =
6913                                        N_Constrained_Array_Definition)
6914             then
6915                --  The flag is set on the object, or on the base type
6916
6917                if Nkind (D) /= N_Object_Declaration then
6918                   E := Base_Type (E);
6919                end if;
6920
6921                Set_Has_Volatile_Components (E);
6922
6923                if Prag_Id = Pragma_Atomic_Components then
6924                   Set_Has_Atomic_Components (E);
6925                end if;
6926
6927             else
6928                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6929             end if;
6930          end Atomic_Components;
6931
6932          --------------------
6933          -- Attach_Handler --
6934          --------------------
6935
6936          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6937
6938          when Pragma_Attach_Handler =>
6939             Check_Ada_83_Warning;
6940             Check_No_Identifiers;
6941             Check_Arg_Count (2);
6942
6943             if No_Run_Time_Mode then
6944                Error_Msg_CRT ("Attach_Handler pragma", N);
6945             else
6946                Check_Interrupt_Or_Attach_Handler;
6947
6948                --  The expression that designates the attribute may depend on a
6949                --  discriminant, and is therefore a per- object expression, to
6950                --  be expanded in the init proc. If expansion is enabled, then
6951                --  perform semantic checks on a copy only.
6952
6953                if Expander_Active then
6954                   declare
6955                      Temp : constant Node_Id :=
6956                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6957                   begin
6958                      Set_Parent (Temp, N);
6959                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6960                   end;
6961
6962                else
6963                   Analyze (Get_Pragma_Arg (Arg2));
6964                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6965                end if;
6966
6967                Process_Interrupt_Or_Attach_Handler;
6968             end if;
6969
6970          --------------------
6971          -- C_Pass_By_Copy --
6972          --------------------
6973
6974          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6975
6976          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6977             Arg : Node_Id;
6978             Val : Uint;
6979
6980          begin
6981             GNAT_Pragma;
6982             Check_Valid_Configuration_Pragma;
6983             Check_Arg_Count (1);
6984             Check_Optional_Identifier (Arg1, "max_size");
6985
6986             Arg := Get_Pragma_Arg (Arg1);
6987             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6988
6989             Val := Expr_Value (Arg);
6990
6991             if Val <= 0 then
6992                Error_Pragma_Arg
6993                  ("maximum size for pragma% must be positive", Arg1);
6994
6995             elsif UI_Is_In_Int_Range (Val) then
6996                Default_C_Record_Mechanism := UI_To_Int (Val);
6997
6998             --  If a giant value is given, Int'Last will do well enough.
6999             --  If sometime someone complains that a record larger than
7000             --  two gigabytes is not copied, we will worry about it then!
7001
7002             else
7003                Default_C_Record_Mechanism := Mechanism_Type'Last;
7004             end if;
7005          end C_Pass_By_Copy;
7006
7007          -----------
7008          -- Check --
7009          -----------
7010
7011          --  pragma Check ([Name    =>] IDENTIFIER,
7012          --                [Check   =>] Boolean_EXPRESSION
7013          --              [,[Message =>] String_EXPRESSION]);
7014
7015          when Pragma_Check => Check : declare
7016             Expr : Node_Id;
7017             Eloc : Source_Ptr;
7018
7019             Check_On : Boolean;
7020             --  Set True if category of assertions referenced by Name enabled
7021
7022          begin
7023             GNAT_Pragma;
7024             Check_At_Least_N_Arguments (2);
7025             Check_At_Most_N_Arguments (3);
7026             Check_Optional_Identifier (Arg1, Name_Name);
7027             Check_Optional_Identifier (Arg2, Name_Check);
7028
7029             if Arg_Count = 3 then
7030                Check_Optional_Identifier (Arg3, Name_Message);
7031                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
7032             end if;
7033
7034             Check_Arg_Is_Identifier (Arg1);
7035
7036             --  Completely ignore if disabled
7037
7038             if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
7039                Rewrite (N, Make_Null_Statement (Loc));
7040                Analyze (N);
7041                return;
7042             end if;
7043
7044             --  Indicate if pragma is enabled. The Original_Node reference here
7045             --  is to deal with pragma Assert rewritten as a Check pragma.
7046
7047             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
7048
7049             if Check_On then
7050                Set_SCO_Pragma_Enabled (Loc);
7051             end if;
7052
7053             --  If expansion is active and the check is not enabled then we
7054             --  rewrite the Check as:
7055
7056             --    if False and then condition then
7057             --       null;
7058             --    end if;
7059
7060             --  The reason we do this rewriting during semantic analysis rather
7061             --  than as part of normal expansion is that we cannot analyze and
7062             --  expand the code for the boolean expression directly, or it may
7063             --  cause insertion of actions that would escape the attempt to
7064             --  suppress the check code.
7065
7066             --  Note that the Sloc for the if statement corresponds to the
7067             --  argument condition, not the pragma itself. The reason for this
7068             --  is that we may generate a warning if the condition is False at
7069             --  compile time, and we do not want to delete this warning when we
7070             --  delete the if statement.
7071
7072             Expr := Get_Pragma_Arg (Arg2);
7073
7074             if Expander_Active and then not Check_On then
7075                Eloc := Sloc (Expr);
7076
7077                Rewrite (N,
7078                  Make_If_Statement (Eloc,
7079                    Condition =>
7080                      Make_And_Then (Eloc,
7081                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
7082                        Right_Opnd => Expr),
7083                    Then_Statements => New_List (
7084                      Make_Null_Statement (Eloc))));
7085
7086                Analyze (N);
7087
7088             --  Check is active
7089
7090             else
7091                Analyze_And_Resolve (Expr, Any_Boolean);
7092             end if;
7093          end Check;
7094
7095          ----------------
7096          -- Check_Name --
7097          ----------------
7098
7099          --  pragma Check_Name (check_IDENTIFIER);
7100
7101          when Pragma_Check_Name =>
7102             Check_No_Identifiers;
7103             GNAT_Pragma;
7104             Check_Valid_Configuration_Pragma;
7105             Check_Arg_Count (1);
7106             Check_Arg_Is_Identifier (Arg1);
7107
7108             declare
7109                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
7110
7111             begin
7112                for J in Check_Names.First .. Check_Names.Last loop
7113                   if Check_Names.Table (J) = Nam then
7114                      return;
7115                   end if;
7116                end loop;
7117
7118                Check_Names.Append (Nam);
7119             end;
7120
7121          ------------------
7122          -- Check_Policy --
7123          ------------------
7124
7125          --  pragma Check_Policy (
7126          --    [Name   =>] IDENTIFIER,
7127          --    [Policy =>] POLICY_IDENTIFIER);
7128
7129          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
7130
7131          --  Note: this is a configuration pragma, but it is allowed to appear
7132          --  anywhere else.
7133
7134          when Pragma_Check_Policy =>
7135             GNAT_Pragma;
7136             Check_Arg_Count (2);
7137             Check_Optional_Identifier (Arg1, Name_Name);
7138             Check_Optional_Identifier (Arg2, Name_Policy);
7139             Check_Arg_Is_One_Of
7140               (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
7141
7142             --  A Check_Policy pragma can appear either as a configuration
7143             --  pragma, or in a declarative part or a package spec (see RM
7144             --  11.5(5) for rules for Suppress/Unsuppress which are also
7145             --  followed for Check_Policy).
7146
7147             if not Is_Configuration_Pragma then
7148                Check_Is_In_Decl_Part_Or_Package_Spec;
7149             end if;
7150
7151             Set_Next_Pragma (N, Opt.Check_Policy_List);
7152             Opt.Check_Policy_List := N;
7153
7154          ---------------------
7155          -- CIL_Constructor --
7156          ---------------------
7157
7158          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7159
7160          --  Processing for this pragma is shared with Java_Constructor
7161
7162          -------------
7163          -- Comment --
7164          -------------
7165
7166          --  pragma Comment (static_string_EXPRESSION)
7167
7168          --  Processing for pragma Comment shares the circuitry for pragma
7169          --  Ident. The only differences are that Ident enforces a limit of 31
7170          --  characters on its argument, and also enforces limitations on
7171          --  placement for DEC compatibility. Pragma Comment shares neither of
7172          --  these restrictions.
7173
7174          -------------------
7175          -- Common_Object --
7176          -------------------
7177
7178          --  pragma Common_Object (
7179          --        [Internal =>] LOCAL_NAME
7180          --     [, [External =>] EXTERNAL_SYMBOL]
7181          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7182
7183          --  Processing for this pragma is shared with Psect_Object
7184
7185          ------------------------
7186          -- Compile_Time_Error --
7187          ------------------------
7188
7189          --  pragma Compile_Time_Error
7190          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7191
7192          when Pragma_Compile_Time_Error =>
7193             GNAT_Pragma;
7194             Process_Compile_Time_Warning_Or_Error;
7195
7196          --------------------------
7197          -- Compile_Time_Warning --
7198          --------------------------
7199
7200          --  pragma Compile_Time_Warning
7201          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7202
7203          when Pragma_Compile_Time_Warning =>
7204             GNAT_Pragma;
7205             Process_Compile_Time_Warning_Or_Error;
7206
7207          -------------------
7208          -- Compiler_Unit --
7209          -------------------
7210
7211          when Pragma_Compiler_Unit =>
7212             GNAT_Pragma;
7213             Check_Arg_Count (0);
7214             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7215
7216          -----------------------------
7217          -- Complete_Representation --
7218          -----------------------------
7219
7220          --  pragma Complete_Representation;
7221
7222          when Pragma_Complete_Representation =>
7223             GNAT_Pragma;
7224             Check_Arg_Count (0);
7225
7226             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7227                Error_Pragma
7228                  ("pragma & must appear within record representation clause");
7229             end if;
7230
7231          ----------------------------
7232          -- Complex_Representation --
7233          ----------------------------
7234
7235          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7236
7237          when Pragma_Complex_Representation => Complex_Representation : declare
7238             E_Id : Entity_Id;
7239             E    : Entity_Id;
7240             Ent  : Entity_Id;
7241
7242          begin
7243             GNAT_Pragma;
7244             Check_Arg_Count (1);
7245             Check_Optional_Identifier (Arg1, Name_Entity);
7246             Check_Arg_Is_Local_Name (Arg1);
7247             E_Id := Get_Pragma_Arg (Arg1);
7248
7249             if Etype (E_Id) = Any_Type then
7250                return;
7251             end if;
7252
7253             E := Entity (E_Id);
7254
7255             if not Is_Record_Type (E) then
7256                Error_Pragma_Arg
7257                  ("argument for pragma% must be record type", Arg1);
7258             end if;
7259
7260             Ent := First_Entity (E);
7261
7262             if No (Ent)
7263               or else No (Next_Entity (Ent))
7264               or else Present (Next_Entity (Next_Entity (Ent)))
7265               or else not Is_Floating_Point_Type (Etype (Ent))
7266               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7267             then
7268                Error_Pragma_Arg
7269                  ("record for pragma% must have two fields of the same "
7270                   & "floating-point type", Arg1);
7271
7272             else
7273                Set_Has_Complex_Representation (Base_Type (E));
7274
7275                --  We need to treat the type has having a non-standard
7276                --  representation, for back-end purposes, even though in
7277                --  general a complex will have the default representation
7278                --  of a record with two real components.
7279
7280                Set_Has_Non_Standard_Rep (Base_Type (E));
7281             end if;
7282          end Complex_Representation;
7283
7284          -------------------------
7285          -- Component_Alignment --
7286          -------------------------
7287
7288          --  pragma Component_Alignment (
7289          --        [Form =>] ALIGNMENT_CHOICE
7290          --     [, [Name =>] type_LOCAL_NAME]);
7291          --
7292          --   ALIGNMENT_CHOICE ::=
7293          --     Component_Size
7294          --   | Component_Size_4
7295          --   | Storage_Unit
7296          --   | Default
7297
7298          when Pragma_Component_Alignment => Component_AlignmentP : declare
7299             Args  : Args_List (1 .. 2);
7300             Names : constant Name_List (1 .. 2) := (
7301                       Name_Form,
7302                       Name_Name);
7303
7304             Form  : Node_Id renames Args (1);
7305             Name  : Node_Id renames Args (2);
7306
7307             Atype : Component_Alignment_Kind;
7308             Typ   : Entity_Id;
7309
7310          begin
7311             GNAT_Pragma;
7312             Gather_Associations (Names, Args);
7313
7314             if No (Form) then
7315                Error_Pragma ("missing Form argument for pragma%");
7316             end if;
7317
7318             Check_Arg_Is_Identifier (Form);
7319
7320             --  Get proper alignment, note that Default = Component_Size on all
7321             --  machines we have so far, and we want to set this value rather
7322             --  than the default value to indicate that it has been explicitly
7323             --  set (and thus will not get overridden by the default component
7324             --  alignment for the current scope)
7325
7326             if Chars (Form) = Name_Component_Size then
7327                Atype := Calign_Component_Size;
7328
7329             elsif Chars (Form) = Name_Component_Size_4 then
7330                Atype := Calign_Component_Size_4;
7331
7332             elsif Chars (Form) = Name_Default then
7333                Atype := Calign_Component_Size;
7334
7335             elsif Chars (Form) = Name_Storage_Unit then
7336                Atype := Calign_Storage_Unit;
7337
7338             else
7339                Error_Pragma_Arg
7340                  ("invalid Form parameter for pragma%", Form);
7341             end if;
7342
7343             --  Case with no name, supplied, affects scope table entry
7344
7345             if No (Name) then
7346                Scope_Stack.Table
7347                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7348
7349             --  Case of name supplied
7350
7351             else
7352                Check_Arg_Is_Local_Name (Name);
7353                Find_Type (Name);
7354                Typ := Entity (Name);
7355
7356                if Typ = Any_Type
7357                  or else Rep_Item_Too_Early (Typ, N)
7358                then
7359                   return;
7360                else
7361                   Typ := Underlying_Type (Typ);
7362                end if;
7363
7364                if not Is_Record_Type (Typ)
7365                  and then not Is_Array_Type (Typ)
7366                then
7367                   Error_Pragma_Arg
7368                     ("Name parameter of pragma% must identify record or " &
7369                      "array type", Name);
7370                end if;
7371
7372                --  An explicit Component_Alignment pragma overrides an
7373                --  implicit pragma Pack, but not an explicit one.
7374
7375                if not Has_Pragma_Pack (Base_Type (Typ)) then
7376                   Set_Is_Packed (Base_Type (Typ), False);
7377                   Set_Component_Alignment (Base_Type (Typ), Atype);
7378                end if;
7379             end if;
7380          end Component_AlignmentP;
7381
7382          ----------------
7383          -- Controlled --
7384          ----------------
7385
7386          --  pragma Controlled (first_subtype_LOCAL_NAME);
7387
7388          when Pragma_Controlled => Controlled : declare
7389             Arg : Node_Id;
7390
7391          begin
7392             Check_No_Identifiers;
7393             Check_Arg_Count (1);
7394             Check_Arg_Is_Local_Name (Arg1);
7395             Arg := Get_Pragma_Arg (Arg1);
7396
7397             if not Is_Entity_Name (Arg)
7398               or else not Is_Access_Type (Entity (Arg))
7399             then
7400                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7401             else
7402                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7403             end if;
7404          end Controlled;
7405
7406          ----------------
7407          -- Convention --
7408          ----------------
7409
7410          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7411          --    [Entity =>] LOCAL_NAME);
7412
7413          when Pragma_Convention => Convention : declare
7414             C : Convention_Id;
7415             E : Entity_Id;
7416             pragma Warnings (Off, C);
7417             pragma Warnings (Off, E);
7418          begin
7419             Check_Arg_Order ((Name_Convention, Name_Entity));
7420             Check_Ada_83_Warning;
7421             Check_Arg_Count (2);
7422             Process_Convention (C, E);
7423          end Convention;
7424
7425          ---------------------------
7426          -- Convention_Identifier --
7427          ---------------------------
7428
7429          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7430          --    [Convention =>] convention_IDENTIFIER);
7431
7432          when Pragma_Convention_Identifier => Convention_Identifier : declare
7433             Idnam : Name_Id;
7434             Cname : Name_Id;
7435
7436          begin
7437             GNAT_Pragma;
7438             Check_Arg_Order ((Name_Name, Name_Convention));
7439             Check_Arg_Count (2);
7440             Check_Optional_Identifier (Arg1, Name_Name);
7441             Check_Optional_Identifier (Arg2, Name_Convention);
7442             Check_Arg_Is_Identifier (Arg1);
7443             Check_Arg_Is_Identifier (Arg2);
7444             Idnam := Chars (Get_Pragma_Arg (Arg1));
7445             Cname := Chars (Get_Pragma_Arg (Arg2));
7446
7447             if Is_Convention_Name (Cname) then
7448                Record_Convention_Identifier
7449                  (Idnam, Get_Convention_Id (Cname));
7450             else
7451                Error_Pragma_Arg
7452                  ("second arg for % pragma must be convention", Arg2);
7453             end if;
7454          end Convention_Identifier;
7455
7456          ---------------
7457          -- CPP_Class --
7458          ---------------
7459
7460          --  pragma CPP_Class ([Entity =>] local_NAME)
7461
7462          when Pragma_CPP_Class => CPP_Class : declare
7463             Arg : Node_Id;
7464             Typ : Entity_Id;
7465
7466          begin
7467             if Warn_On_Obsolescent_Feature then
7468                Error_Msg_N
7469                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7470                   " by pragma import?", N);
7471             end if;
7472
7473             GNAT_Pragma;
7474             Check_Arg_Count (1);
7475             Check_Optional_Identifier (Arg1, Name_Entity);
7476             Check_Arg_Is_Local_Name (Arg1);
7477
7478             Arg := Get_Pragma_Arg (Arg1);
7479             Analyze (Arg);
7480
7481             if Etype (Arg) = Any_Type then
7482                return;
7483             end if;
7484
7485             if not Is_Entity_Name (Arg)
7486               or else not Is_Type (Entity (Arg))
7487             then
7488                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7489             end if;
7490
7491             Typ := Entity (Arg);
7492
7493             if not Is_Tagged_Type (Typ) then
7494                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7495             end if;
7496
7497             --  Types treated as CPP classes must be declared limited (note:
7498             --  this used to be a warning but there is no real benefit to it
7499             --  since we did effectively intend to treat the type as limited
7500             --  anyway).
7501
7502             if not Is_Limited_Type (Typ) then
7503                Error_Msg_N
7504                  ("imported 'C'P'P type must be limited",
7505                   Get_Pragma_Arg (Arg1));
7506             end if;
7507
7508             Set_Is_CPP_Class      (Typ);
7509             Set_Convention        (Typ, Convention_CPP);
7510
7511             --  Imported CPP types must not have discriminants (because C++
7512             --  classes do not have discriminants).
7513
7514             if Has_Discriminants (Typ) then
7515                Error_Msg_N
7516                  ("imported 'C'P'P type cannot have discriminants",
7517                   First (Discriminant_Specifications
7518                           (Declaration_Node (Typ))));
7519             end if;
7520
7521             --  Components of imported CPP types must not have default
7522             --  expressions because the constructor (if any) is in the
7523             --  C++ side.
7524
7525             if Is_Incomplete_Or_Private_Type (Typ)
7526               and then No (Underlying_Type (Typ))
7527             then
7528                --  It should be an error to apply pragma CPP to a private
7529                --  type if the underlying type is not visible (as it is
7530                --  for any representation item). For now, for backward
7531                --  compatibility we do nothing but we cannot check components
7532                --  because they are not available at this stage. All this code
7533                --  will be removed when we cleanup this obsolete GNAT pragma???
7534
7535                null;
7536
7537             else
7538                declare
7539                   Tdef  : constant Node_Id :=
7540                             Type_Definition (Declaration_Node (Typ));
7541                   Clist : Node_Id;
7542                   Comp  : Node_Id;
7543
7544                begin
7545                   if Nkind (Tdef) = N_Record_Definition then
7546                      Clist := Component_List (Tdef);
7547                   else
7548                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7549                      Clist := Component_List (Record_Extension_Part (Tdef));
7550                   end if;
7551
7552                   if Present (Clist) then
7553                      Comp := First (Component_Items (Clist));
7554                      while Present (Comp) loop
7555                         if Present (Expression (Comp)) then
7556                            Error_Msg_N
7557                              ("component of imported 'C'P'P type cannot have" &
7558                               " default expression", Expression (Comp));
7559                         end if;
7560
7561                         Next (Comp);
7562                      end loop;
7563                   end if;
7564                end;
7565             end if;
7566          end CPP_Class;
7567
7568          ---------------------
7569          -- CPP_Constructor --
7570          ---------------------
7571
7572          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7573          --    [, [External_Name =>] static_string_EXPRESSION ]
7574          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7575
7576          when Pragma_CPP_Constructor => CPP_Constructor : declare
7577             Elmt    : Elmt_Id;
7578             Id      : Entity_Id;
7579             Def_Id  : Entity_Id;
7580             Tag_Typ : Entity_Id;
7581
7582          begin
7583             GNAT_Pragma;
7584             Check_At_Least_N_Arguments (1);
7585             Check_At_Most_N_Arguments (3);
7586             Check_Optional_Identifier (Arg1, Name_Entity);
7587             Check_Arg_Is_Local_Name (Arg1);
7588
7589             Id := Get_Pragma_Arg (Arg1);
7590             Find_Program_Unit_Name (Id);
7591
7592             --  If we did not find the name, we are done
7593
7594             if Etype (Id) = Any_Type then
7595                return;
7596             end if;
7597
7598             Def_Id := Entity (Id);
7599
7600             --  Check if already defined as constructor
7601
7602             if Is_Constructor (Def_Id) then
7603                Error_Msg_N
7604                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7605                return;
7606             end if;
7607
7608             if Ekind (Def_Id) = E_Function
7609               and then (Is_CPP_Class (Etype (Def_Id))
7610                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7611                                    and then
7612                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7613             then
7614                if Arg_Count >= 2 then
7615                   Set_Imported (Def_Id);
7616                   Set_Is_Public (Def_Id);
7617                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7618                end if;
7619
7620                Set_Has_Completion (Def_Id);
7621                Set_Is_Constructor (Def_Id);
7622
7623                --  Imported C++ constructors are not dispatching primitives
7624                --  because in C++ they don't have a dispatch table slot.
7625                --  However, in Ada the constructor has the profile of a
7626                --  function that returns a tagged type and therefore it has
7627                --  been treated as a primitive operation during semantic
7628                --  analysis. We now remove it from the list of primitive
7629                --  operations of the type.
7630
7631                if Is_Tagged_Type (Etype (Def_Id))
7632                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7633                then
7634                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7635                   Tag_Typ := Etype (Def_Id);
7636
7637                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7638                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7639                      Next_Elmt (Elmt);
7640                   end loop;
7641
7642                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7643                   Set_Is_Dispatching_Operation (Def_Id, False);
7644                end if;
7645
7646                --  For backward compatibility, if the constructor returns a
7647                --  class wide type, and we internally change the return type to
7648                --  the corresponding root type.
7649
7650                if Is_Class_Wide_Type (Etype (Def_Id)) then
7651                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7652                end if;
7653             else
7654                Error_Pragma_Arg
7655                  ("pragma% requires function returning a 'C'P'P_Class type",
7656                    Arg1);
7657             end if;
7658          end CPP_Constructor;
7659
7660          -----------------
7661          -- CPP_Virtual --
7662          -----------------
7663
7664          when Pragma_CPP_Virtual => CPP_Virtual : declare
7665          begin
7666             GNAT_Pragma;
7667
7668             if Warn_On_Obsolescent_Feature then
7669                Error_Msg_N
7670                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7671                   "no effect?", N);
7672             end if;
7673          end CPP_Virtual;
7674
7675          ----------------
7676          -- CPP_Vtable --
7677          ----------------
7678
7679          when Pragma_CPP_Vtable => CPP_Vtable : declare
7680          begin
7681             GNAT_Pragma;
7682
7683             if Warn_On_Obsolescent_Feature then
7684                Error_Msg_N
7685                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7686                   "no effect?", N);
7687             end if;
7688          end CPP_Vtable;
7689
7690          ---------
7691          -- CPU --
7692          ---------
7693
7694          --  pragma CPU (EXPRESSION);
7695
7696          when Pragma_CPU => CPU : declare
7697             P   : constant Node_Id := Parent (N);
7698             Arg : Node_Id;
7699
7700          begin
7701             Ada_2012_Pragma;
7702             Check_No_Identifiers;
7703             Check_Arg_Count (1);
7704
7705             --  Subprogram case
7706
7707             if Nkind (P) = N_Subprogram_Body then
7708                Check_In_Main_Program;
7709
7710                Arg := Get_Pragma_Arg (Arg1);
7711                Analyze_And_Resolve (Arg, Any_Integer);
7712
7713                --  Must be static
7714
7715                if not Is_Static_Expression (Arg) then
7716                   Flag_Non_Static_Expr
7717                     ("main subprogram affinity is not static!", Arg);
7718                   raise Pragma_Exit;
7719
7720                --  If constraint error, then we already signalled an error
7721
7722                elsif Raises_Constraint_Error (Arg) then
7723                   null;
7724
7725                --  Otherwise check in range
7726
7727                else
7728                   declare
7729                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7730                      --  This is the entity System.Multiprocessors.CPU_Range;
7731
7732                      Val : constant Uint := Expr_Value (Arg);
7733
7734                   begin
7735                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7736                           or else
7737                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7738                      then
7739                         Error_Pragma_Arg
7740                           ("main subprogram CPU is out of range", Arg1);
7741                      end if;
7742                   end;
7743                end if;
7744
7745                Set_Main_CPU
7746                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7747
7748             --  Task case
7749
7750             elsif Nkind (P) = N_Task_Definition then
7751                Arg := Get_Pragma_Arg (Arg1);
7752
7753                --  The expression must be analyzed in the special manner
7754                --  described in "Handling of Default and Per-Object
7755                --  Expressions" in sem.ads.
7756
7757                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7758
7759             --  Anything else is incorrect
7760
7761             else
7762                Pragma_Misplaced;
7763             end if;
7764
7765             if Has_Pragma_CPU (P) then
7766                Error_Pragma ("duplicate pragma% not allowed");
7767             else
7768                Set_Has_Pragma_CPU (P, True);
7769
7770                if Nkind (P) = N_Task_Definition then
7771                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7772                end if;
7773             end if;
7774          end CPU;
7775
7776          -----------
7777          -- Debug --
7778          -----------
7779
7780          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7781
7782          when Pragma_Debug => Debug : declare
7783             Cond : Node_Id;
7784             Call : Node_Id;
7785
7786          begin
7787             GNAT_Pragma;
7788
7789             --  Skip analysis if disabled
7790
7791             if Debug_Pragmas_Disabled then
7792                Rewrite (N, Make_Null_Statement (Loc));
7793                Analyze (N);
7794                return;
7795             end if;
7796
7797             Cond :=
7798               New_Occurrence_Of
7799                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7800                  Loc);
7801
7802             if Debug_Pragmas_Enabled then
7803                Set_SCO_Pragma_Enabled (Loc);
7804             end if;
7805
7806             if Arg_Count = 2 then
7807                Cond :=
7808                  Make_And_Then (Loc,
7809                    Left_Opnd  => Relocate_Node (Cond),
7810                    Right_Opnd => Get_Pragma_Arg (Arg1));
7811                Call := Get_Pragma_Arg (Arg2);
7812             else
7813                Call := Get_Pragma_Arg (Arg1);
7814             end if;
7815
7816             if Nkind_In (Call,
7817                  N_Indexed_Component,
7818                  N_Function_Call,
7819                  N_Identifier,
7820                  N_Selected_Component)
7821             then
7822                --  If this pragma Debug comes from source, its argument was
7823                --  parsed as a name form (which is syntactically identical).
7824                --  Change it to a procedure call statement now.
7825
7826                Change_Name_To_Procedure_Call_Statement (Call);
7827
7828             elsif Nkind (Call) = N_Procedure_Call_Statement then
7829
7830                --  Already in the form of a procedure call statement: nothing
7831                --  to do (could happen in case of an internally generated
7832                --  pragma Debug).
7833
7834                null;
7835
7836             else
7837                --  All other cases: diagnose error
7838
7839                Error_Msg
7840                  ("argument of pragma% is not procedure call", Sloc (Call));
7841                return;
7842             end if;
7843
7844             --  Rewrite into a conditional with an appropriate condition. We
7845             --  wrap the procedure call in a block so that overhead from e.g.
7846             --  use of the secondary stack does not generate execution overhead
7847             --  for suppressed conditions.
7848
7849             Rewrite (N, Make_Implicit_If_Statement (N,
7850               Condition => Cond,
7851                  Then_Statements => New_List (
7852                    Make_Block_Statement (Loc,
7853                      Handled_Statement_Sequence =>
7854                        Make_Handled_Sequence_Of_Statements (Loc,
7855                          Statements => New_List (Relocate_Node (Call)))))));
7856             Analyze (N);
7857          end Debug;
7858
7859          ------------------
7860          -- Debug_Policy --
7861          ------------------
7862
7863          --  pragma Debug_Policy (Check | Ignore)
7864
7865          when Pragma_Debug_Policy =>
7866             GNAT_Pragma;
7867             Check_Arg_Count (1);
7868             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7869             Debug_Pragmas_Enabled :=
7870               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7871             Debug_Pragmas_Disabled :=
7872               Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7873
7874          ---------------------
7875          -- Detect_Blocking --
7876          ---------------------
7877
7878          --  pragma Detect_Blocking;
7879
7880          when Pragma_Detect_Blocking =>
7881             Ada_2005_Pragma;
7882             Check_Arg_Count (0);
7883             Check_Valid_Configuration_Pragma;
7884             Detect_Blocking := True;
7885
7886          --------------------------
7887          -- Default_Storage_Pool --
7888          --------------------------
7889
7890          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7891
7892          when Pragma_Default_Storage_Pool =>
7893             Ada_2012_Pragma;
7894             Check_Arg_Count (1);
7895
7896             --  Default_Storage_Pool can appear as a configuration pragma, or
7897             --  in a declarative part or a package spec.
7898
7899             if not Is_Configuration_Pragma then
7900                Check_Is_In_Decl_Part_Or_Package_Spec;
7901             end if;
7902
7903             --  Case of Default_Storage_Pool (null);
7904
7905             if Nkind (Expression (Arg1)) = N_Null then
7906                Analyze (Expression (Arg1));
7907
7908                --  This is an odd case, this is not really an expression, so
7909                --  we don't have a type for it. So just set the type to Empty.
7910
7911                Set_Etype (Expression (Arg1), Empty);
7912
7913             --  Case of Default_Storage_Pool (storage_pool_NAME);
7914
7915             else
7916                --  If it's a configuration pragma, then the only allowed
7917                --  argument is "null".
7918
7919                if Is_Configuration_Pragma then
7920                   Error_Pragma_Arg ("NULL expected", Arg1);
7921                end if;
7922
7923                --  The expected type for a non-"null" argument is
7924                --  Root_Storage_Pool'Class.
7925
7926                Analyze_And_Resolve
7927                  (Get_Pragma_Arg (Arg1),
7928                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7929             end if;
7930
7931             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7932             --  for an access type will use this information to set the
7933             --  appropriate attributes of the access type.
7934
7935             Default_Pool := Expression (Arg1);
7936
7937          ---------------
7938          -- Dimension --
7939          ---------------
7940
7941          when Pragma_Dimension =>
7942             GNAT_Pragma;
7943             Check_Arg_Count (4);
7944             Check_No_Identifiers;
7945             Check_Arg_Is_Local_Name (Arg1);
7946
7947             if not Is_Type (Arg1) then
7948                Error_Pragma ("first argument for pragma% must be subtype");
7949             end if;
7950
7951             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7952             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7953             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7954
7955          -------------------
7956          -- Discard_Names --
7957          -------------------
7958
7959          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7960
7961          when Pragma_Discard_Names => Discard_Names : declare
7962             E    : Entity_Id;
7963             E_Id : Entity_Id;
7964
7965          begin
7966             Check_Ada_83_Warning;
7967
7968             --  Deal with configuration pragma case
7969
7970             if Arg_Count = 0 and then Is_Configuration_Pragma then
7971                Global_Discard_Names := True;
7972                return;
7973
7974             --  Otherwise, check correct appropriate context
7975
7976             else
7977                Check_Is_In_Decl_Part_Or_Package_Spec;
7978
7979                if Arg_Count = 0 then
7980
7981                   --  If there is no parameter, then from now on this pragma
7982                   --  applies to any enumeration, exception or tagged type
7983                   --  defined in the current declarative part, and recursively
7984                   --  to any nested scope.
7985
7986                   Set_Discard_Names (Current_Scope);
7987                   return;
7988
7989                else
7990                   Check_Arg_Count (1);
7991                   Check_Optional_Identifier (Arg1, Name_On);
7992                   Check_Arg_Is_Local_Name (Arg1);
7993
7994                   E_Id := Get_Pragma_Arg (Arg1);
7995
7996                   if Etype (E_Id) = Any_Type then
7997                      return;
7998                   else
7999                      E := Entity (E_Id);
8000                   end if;
8001
8002                   if (Is_First_Subtype (E)
8003                       and then
8004                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
8005                     or else Ekind (E) = E_Exception
8006                   then
8007                      Set_Discard_Names (E);
8008                   else
8009                      Error_Pragma_Arg
8010                        ("inappropriate entity for pragma%", Arg1);
8011                   end if;
8012
8013                end if;
8014             end if;
8015          end Discard_Names;
8016
8017          ------------------------
8018          -- Dispatching_Domain --
8019          ------------------------
8020
8021          --  pragma Dispatching_Domain (EXPRESSION);
8022
8023          when Pragma_Dispatching_Domain => Dispatching_Domain : declare
8024             P   : constant Node_Id := Parent (N);
8025             Arg : Node_Id;
8026
8027          begin
8028             Ada_2012_Pragma;
8029             Check_No_Identifiers;
8030             Check_Arg_Count (1);
8031
8032             --  This pragma is born obsolete, but not the aspect
8033
8034             if not From_Aspect_Specification (N) then
8035                Check_Restriction
8036                  (No_Obsolescent_Features, Pragma_Identifier (N));
8037             end if;
8038
8039             if Nkind (P) = N_Task_Definition then
8040                Arg := Get_Pragma_Arg (Arg1);
8041
8042                --  The expression must be analyzed in the special manner
8043                --  described in "Handling of Default and Per-Object
8044                --  Expressions" in sem.ads.
8045
8046                Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
8047
8048             --  Anything else is incorrect
8049
8050             else
8051                Pragma_Misplaced;
8052             end if;
8053
8054             if Has_Pragma_Dispatching_Domain (P) then
8055                Error_Pragma ("duplicate pragma% not allowed");
8056             else
8057                Set_Has_Pragma_Dispatching_Domain (P, True);
8058
8059                if Nkind (P) = N_Task_Definition then
8060                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
8061                end if;
8062             end if;
8063          end Dispatching_Domain;
8064
8065          ---------------
8066          -- Elaborate --
8067          ---------------
8068
8069          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
8070
8071          when Pragma_Elaborate => Elaborate : declare
8072             Arg   : Node_Id;
8073             Citem : Node_Id;
8074
8075          begin
8076             --  Pragma must be in context items list of a compilation unit
8077
8078             if not Is_In_Context_Clause then
8079                Pragma_Misplaced;
8080             end if;
8081
8082             --  Must be at least one argument
8083
8084             if Arg_Count = 0 then
8085                Error_Pragma ("pragma% requires at least one argument");
8086             end if;
8087
8088             --  In Ada 83 mode, there can be no items following it in the
8089             --  context list except other pragmas and implicit with clauses
8090             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
8091             --  placement rule does not apply.
8092
8093             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
8094                Citem := Next (N);
8095                while Present (Citem) loop
8096                   if Nkind (Citem) = N_Pragma
8097                     or else (Nkind (Citem) = N_With_Clause
8098                               and then Implicit_With (Citem))
8099                   then
8100                      null;
8101                   else
8102                      Error_Pragma
8103                        ("(Ada 83) pragma% must be at end of context clause");
8104                   end if;
8105
8106                   Next (Citem);
8107                end loop;
8108             end if;
8109
8110             --  Finally, the arguments must all be units mentioned in a with
8111             --  clause in the same context clause. Note we already checked (in
8112             --  Par.Prag) that the arguments are all identifiers or selected
8113             --  components.
8114
8115             Arg := Arg1;
8116             Outer : while Present (Arg) loop
8117                Citem := First (List_Containing (N));
8118                Inner : while Citem /= N loop
8119                   if Nkind (Citem) = N_With_Clause
8120                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8121                   then
8122                      Set_Elaborate_Present (Citem, True);
8123                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8124                      Generate_Reference (Entity (Name (Citem)), Citem);
8125
8126                      --  With the pragma present, elaboration calls on
8127                      --  subprograms from the named unit need no further
8128                      --  checks, as long as the pragma appears in the current
8129                      --  compilation unit. If the pragma appears in some unit
8130                      --  in the context, there might still be a need for an
8131                      --  Elaborate_All_Desirable from the current compilation
8132                      --  to the named unit, so we keep the check enabled.
8133
8134                      if In_Extended_Main_Source_Unit (N) then
8135                         Set_Suppress_Elaboration_Warnings
8136                           (Entity (Name (Citem)));
8137                      end if;
8138
8139                      exit Inner;
8140                   end if;
8141
8142                   Next (Citem);
8143                end loop Inner;
8144
8145                if Citem = N then
8146                   Error_Pragma_Arg
8147                     ("argument of pragma% is not with'ed unit", Arg);
8148                end if;
8149
8150                Next (Arg);
8151             end loop Outer;
8152
8153             --  Give a warning if operating in static mode with -gnatwl
8154             --  (elaboration warnings enabled) switch set.
8155
8156             if Elab_Warnings and not Dynamic_Elaboration_Checks then
8157                Error_Msg_N
8158                  ("?use of pragma Elaborate may not be safe", N);
8159                Error_Msg_N
8160                  ("?use pragma Elaborate_All instead if possible", N);
8161             end if;
8162          end Elaborate;
8163
8164          -------------------
8165          -- Elaborate_All --
8166          -------------------
8167
8168          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
8169
8170          when Pragma_Elaborate_All => Elaborate_All : declare
8171             Arg   : Node_Id;
8172             Citem : Node_Id;
8173
8174          begin
8175             Check_Ada_83_Warning;
8176
8177             --  Pragma must be in context items list of a compilation unit
8178
8179             if not Is_In_Context_Clause then
8180                Pragma_Misplaced;
8181             end if;
8182
8183             --  Must be at least one argument
8184
8185             if Arg_Count = 0 then
8186                Error_Pragma ("pragma% requires at least one argument");
8187             end if;
8188
8189             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
8190             --  have to appear at the end of the context clause, but may
8191             --  appear mixed in with other items, even in Ada 83 mode.
8192
8193             --  Final check: the arguments must all be units mentioned in
8194             --  a with clause in the same context clause. Note that we
8195             --  already checked (in Par.Prag) that all the arguments are
8196             --  either identifiers or selected components.
8197
8198             Arg := Arg1;
8199             Outr : while Present (Arg) loop
8200                Citem := First (List_Containing (N));
8201                Innr : while Citem /= N loop
8202                   if Nkind (Citem) = N_With_Clause
8203                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8204                   then
8205                      Set_Elaborate_All_Present (Citem, True);
8206                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8207
8208                      --  Suppress warnings and elaboration checks on the named
8209                      --  unit if the pragma is in the current compilation, as
8210                      --  for pragma Elaborate.
8211
8212                      if In_Extended_Main_Source_Unit (N) then
8213                         Set_Suppress_Elaboration_Warnings
8214                           (Entity (Name (Citem)));
8215                      end if;
8216                      exit Innr;
8217                   end if;
8218
8219                   Next (Citem);
8220                end loop Innr;
8221
8222                if Citem = N then
8223                   Set_Error_Posted (N);
8224                   Error_Pragma_Arg
8225                     ("argument of pragma% is not with'ed unit", Arg);
8226                end if;
8227
8228                Next (Arg);
8229             end loop Outr;
8230          end Elaborate_All;
8231
8232          --------------------
8233          -- Elaborate_Body --
8234          --------------------
8235
8236          --  pragma Elaborate_Body [( library_unit_NAME )];
8237
8238          when Pragma_Elaborate_Body => Elaborate_Body : declare
8239             Cunit_Node : Node_Id;
8240             Cunit_Ent  : Entity_Id;
8241
8242          begin
8243             Check_Ada_83_Warning;
8244             Check_Valid_Library_Unit_Pragma;
8245
8246             if Nkind (N) = N_Null_Statement then
8247                return;
8248             end if;
8249
8250             Cunit_Node := Cunit (Current_Sem_Unit);
8251             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8252
8253             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8254                                             N_Subprogram_Body)
8255             then
8256                Error_Pragma ("pragma% must refer to a spec, not a body");
8257             else
8258                Set_Body_Required (Cunit_Node, True);
8259                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8260
8261                --  If we are in dynamic elaboration mode, then we suppress
8262                --  elaboration warnings for the unit, since it is definitely
8263                --  fine NOT to do dynamic checks at the first level (and such
8264                --  checks will be suppressed because no elaboration boolean
8265                --  is created for Elaborate_Body packages).
8266
8267                --  But in the static model of elaboration, Elaborate_Body is
8268                --  definitely NOT good enough to ensure elaboration safety on
8269                --  its own, since the body may WITH other units that are not
8270                --  safe from an elaboration point of view, so a client must
8271                --  still do an Elaborate_All on such units.
8272
8273                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8274                --  Elaborate_Body always suppressed elab warnings.
8275
8276                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8277                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8278                end if;
8279             end if;
8280          end Elaborate_Body;
8281
8282          ------------------------
8283          -- Elaboration_Checks --
8284          ------------------------
8285
8286          --  pragma Elaboration_Checks (Static | Dynamic);
8287
8288          when Pragma_Elaboration_Checks =>
8289             GNAT_Pragma;
8290             Check_Arg_Count (1);
8291             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8292             Dynamic_Elaboration_Checks :=
8293               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8294
8295          ---------------
8296          -- Eliminate --
8297          ---------------
8298
8299          --  pragma Eliminate (
8300          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8301          --    [,[Entity     =>] IDENTIFIER |
8302          --                      SELECTED_COMPONENT |
8303          --                      STRING_LITERAL]
8304          --    [,                OVERLOADING_RESOLUTION]);
8305
8306          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8307          --                             SOURCE_LOCATION
8308
8309          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8310          --                                        FUNCTION_PROFILE
8311
8312          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8313
8314          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8315          --                       Result_Type => result_SUBTYPE_NAME]
8316
8317          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8318          --  SUBTYPE_NAME    ::= STRING_LITERAL
8319
8320          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8321          --  SOURCE_TRACE    ::= STRING_LITERAL
8322
8323          when Pragma_Eliminate => Eliminate : declare
8324             Args  : Args_List (1 .. 5);
8325             Names : constant Name_List (1 .. 5) := (
8326                       Name_Unit_Name,
8327                       Name_Entity,
8328                       Name_Parameter_Types,
8329                       Name_Result_Type,
8330                       Name_Source_Location);
8331
8332             Unit_Name       : Node_Id renames Args (1);
8333             Entity          : Node_Id renames Args (2);
8334             Parameter_Types : Node_Id renames Args (3);
8335             Result_Type     : Node_Id renames Args (4);
8336             Source_Location : Node_Id renames Args (5);
8337
8338          begin
8339             GNAT_Pragma;
8340             Check_Valid_Configuration_Pragma;
8341             Gather_Associations (Names, Args);
8342
8343             if No (Unit_Name) then
8344                Error_Pragma ("missing Unit_Name argument for pragma%");
8345             end if;
8346
8347             if No (Entity)
8348               and then (Present (Parameter_Types)
8349                           or else
8350                         Present (Result_Type)
8351                           or else
8352                         Present (Source_Location))
8353             then
8354                Error_Pragma ("missing Entity argument for pragma%");
8355             end if;
8356
8357             if (Present (Parameter_Types)
8358                   or else
8359                 Present (Result_Type))
8360               and then
8361                 Present (Source_Location)
8362             then
8363                Error_Pragma
8364                  ("parameter profile and source location cannot " &
8365                   "be used together in pragma%");
8366             end if;
8367
8368             Process_Eliminate_Pragma
8369               (N,
8370                Unit_Name,
8371                Entity,
8372                Parameter_Types,
8373                Result_Type,
8374                Source_Location);
8375          end Eliminate;
8376
8377          ------------
8378          -- Export --
8379          ------------
8380
8381          --  pragma Export (
8382          --    [   Convention    =>] convention_IDENTIFIER,
8383          --    [   Entity        =>] local_NAME
8384          --    [, [External_Name =>] static_string_EXPRESSION ]
8385          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8386
8387          when Pragma_Export => Export : declare
8388             C      : Convention_Id;
8389             Def_Id : Entity_Id;
8390
8391             pragma Warnings (Off, C);
8392
8393          begin
8394             Check_Ada_83_Warning;
8395             Check_Arg_Order
8396               ((Name_Convention,
8397                 Name_Entity,
8398                 Name_External_Name,
8399                 Name_Link_Name));
8400             Check_At_Least_N_Arguments (2);
8401             Check_At_Most_N_Arguments  (4);
8402             Process_Convention (C, Def_Id);
8403
8404             if Ekind (Def_Id) /= E_Constant then
8405                Note_Possible_Modification
8406                  (Get_Pragma_Arg (Arg2), Sure => False);
8407             end if;
8408
8409             Process_Interface_Name (Def_Id, Arg3, Arg4);
8410             Set_Exported (Def_Id, Arg2);
8411
8412             --  If the entity is a deferred constant, propagate the information
8413             --  to the full view, because gigi elaborates the full view only.
8414
8415             if Ekind (Def_Id) = E_Constant
8416               and then Present (Full_View (Def_Id))
8417             then
8418                declare
8419                   Id2 : constant Entity_Id := Full_View (Def_Id);
8420                begin
8421                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8422                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8423                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8424                end;
8425             end if;
8426          end Export;
8427
8428          ----------------------
8429          -- Export_Exception --
8430          ----------------------
8431
8432          --  pragma Export_Exception (
8433          --        [Internal         =>] LOCAL_NAME
8434          --     [, [External         =>] EXTERNAL_SYMBOL]
8435          --     [, [Form     =>] Ada | VMS]
8436          --     [, [Code     =>] static_integer_EXPRESSION]);
8437
8438          when Pragma_Export_Exception => Export_Exception : declare
8439             Args  : Args_List (1 .. 4);
8440             Names : constant Name_List (1 .. 4) := (
8441                       Name_Internal,
8442                       Name_External,
8443                       Name_Form,
8444                       Name_Code);
8445
8446             Internal : Node_Id renames Args (1);
8447             External : Node_Id renames Args (2);
8448             Form     : Node_Id renames Args (3);
8449             Code     : Node_Id renames Args (4);
8450
8451          begin
8452             GNAT_Pragma;
8453
8454             if Inside_A_Generic then
8455                Error_Pragma ("pragma% cannot be used for generic entities");
8456             end if;
8457
8458             Gather_Associations (Names, Args);
8459             Process_Extended_Import_Export_Exception_Pragma (
8460               Arg_Internal => Internal,
8461               Arg_External => External,
8462               Arg_Form     => Form,
8463               Arg_Code     => Code);
8464
8465             if not Is_VMS_Exception (Entity (Internal)) then
8466                Set_Exported (Entity (Internal), Internal);
8467             end if;
8468          end Export_Exception;
8469
8470          ---------------------
8471          -- Export_Function --
8472          ---------------------
8473
8474          --  pragma Export_Function (
8475          --        [Internal         =>] LOCAL_NAME
8476          --     [, [External         =>] EXTERNAL_SYMBOL]
8477          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8478          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8479          --     [, [Mechanism        =>] MECHANISM]
8480          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8481
8482          --  EXTERNAL_SYMBOL ::=
8483          --    IDENTIFIER
8484          --  | static_string_EXPRESSION
8485
8486          --  PARAMETER_TYPES ::=
8487          --    null
8488          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8489
8490          --  TYPE_DESIGNATOR ::=
8491          --    subtype_NAME
8492          --  | subtype_Name ' Access
8493
8494          --  MECHANISM ::=
8495          --    MECHANISM_NAME
8496          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8497
8498          --  MECHANISM_ASSOCIATION ::=
8499          --    [formal_parameter_NAME =>] MECHANISM_NAME
8500
8501          --  MECHANISM_NAME ::=
8502          --    Value
8503          --  | Reference
8504          --  | Descriptor [([Class =>] CLASS_NAME)]
8505
8506          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8507
8508          when Pragma_Export_Function => Export_Function : declare
8509             Args  : Args_List (1 .. 6);
8510             Names : constant Name_List (1 .. 6) := (
8511                       Name_Internal,
8512                       Name_External,
8513                       Name_Parameter_Types,
8514                       Name_Result_Type,
8515                       Name_Mechanism,
8516                       Name_Result_Mechanism);
8517
8518             Internal         : Node_Id renames Args (1);
8519             External         : Node_Id renames Args (2);
8520             Parameter_Types  : Node_Id renames Args (3);
8521             Result_Type      : Node_Id renames Args (4);
8522             Mechanism        : Node_Id renames Args (5);
8523             Result_Mechanism : Node_Id renames Args (6);
8524
8525          begin
8526             GNAT_Pragma;
8527             Gather_Associations (Names, Args);
8528             Process_Extended_Import_Export_Subprogram_Pragma (
8529               Arg_Internal         => Internal,
8530               Arg_External         => External,
8531               Arg_Parameter_Types  => Parameter_Types,
8532               Arg_Result_Type      => Result_Type,
8533               Arg_Mechanism        => Mechanism,
8534               Arg_Result_Mechanism => Result_Mechanism);
8535          end Export_Function;
8536
8537          -------------------
8538          -- Export_Object --
8539          -------------------
8540
8541          --  pragma Export_Object (
8542          --        [Internal =>] LOCAL_NAME
8543          --     [, [External =>] EXTERNAL_SYMBOL]
8544          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8545
8546          --  EXTERNAL_SYMBOL ::=
8547          --    IDENTIFIER
8548          --  | static_string_EXPRESSION
8549
8550          --  PARAMETER_TYPES ::=
8551          --    null
8552          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8553
8554          --  TYPE_DESIGNATOR ::=
8555          --    subtype_NAME
8556          --  | subtype_Name ' Access
8557
8558          --  MECHANISM ::=
8559          --    MECHANISM_NAME
8560          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8561
8562          --  MECHANISM_ASSOCIATION ::=
8563          --    [formal_parameter_NAME =>] MECHANISM_NAME
8564
8565          --  MECHANISM_NAME ::=
8566          --    Value
8567          --  | Reference
8568          --  | Descriptor [([Class =>] CLASS_NAME)]
8569
8570          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8571
8572          when Pragma_Export_Object => Export_Object : declare
8573             Args  : Args_List (1 .. 3);
8574             Names : constant Name_List (1 .. 3) := (
8575                       Name_Internal,
8576                       Name_External,
8577                       Name_Size);
8578
8579             Internal : Node_Id renames Args (1);
8580             External : Node_Id renames Args (2);
8581             Size     : Node_Id renames Args (3);
8582
8583          begin
8584             GNAT_Pragma;
8585             Gather_Associations (Names, Args);
8586             Process_Extended_Import_Export_Object_Pragma (
8587               Arg_Internal => Internal,
8588               Arg_External => External,
8589               Arg_Size     => Size);
8590          end Export_Object;
8591
8592          ----------------------
8593          -- Export_Procedure --
8594          ----------------------
8595
8596          --  pragma Export_Procedure (
8597          --        [Internal         =>] LOCAL_NAME
8598          --     [, [External         =>] EXTERNAL_SYMBOL]
8599          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8600          --     [, [Mechanism        =>] MECHANISM]);
8601
8602          --  EXTERNAL_SYMBOL ::=
8603          --    IDENTIFIER
8604          --  | static_string_EXPRESSION
8605
8606          --  PARAMETER_TYPES ::=
8607          --    null
8608          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8609
8610          --  TYPE_DESIGNATOR ::=
8611          --    subtype_NAME
8612          --  | subtype_Name ' Access
8613
8614          --  MECHANISM ::=
8615          --    MECHANISM_NAME
8616          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8617
8618          --  MECHANISM_ASSOCIATION ::=
8619          --    [formal_parameter_NAME =>] MECHANISM_NAME
8620
8621          --  MECHANISM_NAME ::=
8622          --    Value
8623          --  | Reference
8624          --  | Descriptor [([Class =>] CLASS_NAME)]
8625
8626          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8627
8628          when Pragma_Export_Procedure => Export_Procedure : declare
8629             Args  : Args_List (1 .. 4);
8630             Names : constant Name_List (1 .. 4) := (
8631                       Name_Internal,
8632                       Name_External,
8633                       Name_Parameter_Types,
8634                       Name_Mechanism);
8635
8636             Internal        : Node_Id renames Args (1);
8637             External        : Node_Id renames Args (2);
8638             Parameter_Types : Node_Id renames Args (3);
8639             Mechanism       : Node_Id renames Args (4);
8640
8641          begin
8642             GNAT_Pragma;
8643             Gather_Associations (Names, Args);
8644             Process_Extended_Import_Export_Subprogram_Pragma (
8645               Arg_Internal        => Internal,
8646               Arg_External        => External,
8647               Arg_Parameter_Types => Parameter_Types,
8648               Arg_Mechanism       => Mechanism);
8649          end Export_Procedure;
8650
8651          ------------------
8652          -- Export_Value --
8653          ------------------
8654
8655          --  pragma Export_Value (
8656          --     [Value     =>] static_integer_EXPRESSION,
8657          --     [Link_Name =>] static_string_EXPRESSION);
8658
8659          when Pragma_Export_Value =>
8660             GNAT_Pragma;
8661             Check_Arg_Order ((Name_Value, Name_Link_Name));
8662             Check_Arg_Count (2);
8663
8664             Check_Optional_Identifier (Arg1, Name_Value);
8665             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8666
8667             Check_Optional_Identifier (Arg2, Name_Link_Name);
8668             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8669
8670          -----------------------------
8671          -- Export_Valued_Procedure --
8672          -----------------------------
8673
8674          --  pragma Export_Valued_Procedure (
8675          --        [Internal         =>] LOCAL_NAME
8676          --     [, [External         =>] EXTERNAL_SYMBOL,]
8677          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8678          --     [, [Mechanism        =>] MECHANISM]);
8679
8680          --  EXTERNAL_SYMBOL ::=
8681          --    IDENTIFIER
8682          --  | static_string_EXPRESSION
8683
8684          --  PARAMETER_TYPES ::=
8685          --    null
8686          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8687
8688          --  TYPE_DESIGNATOR ::=
8689          --    subtype_NAME
8690          --  | subtype_Name ' Access
8691
8692          --  MECHANISM ::=
8693          --    MECHANISM_NAME
8694          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8695
8696          --  MECHANISM_ASSOCIATION ::=
8697          --    [formal_parameter_NAME =>] MECHANISM_NAME
8698
8699          --  MECHANISM_NAME ::=
8700          --    Value
8701          --  | Reference
8702          --  | Descriptor [([Class =>] CLASS_NAME)]
8703
8704          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8705
8706          when Pragma_Export_Valued_Procedure =>
8707          Export_Valued_Procedure : declare
8708             Args  : Args_List (1 .. 4);
8709             Names : constant Name_List (1 .. 4) := (
8710                       Name_Internal,
8711                       Name_External,
8712                       Name_Parameter_Types,
8713                       Name_Mechanism);
8714
8715             Internal        : Node_Id renames Args (1);
8716             External        : Node_Id renames Args (2);
8717             Parameter_Types : Node_Id renames Args (3);
8718             Mechanism       : Node_Id renames Args (4);
8719
8720          begin
8721             GNAT_Pragma;
8722             Gather_Associations (Names, Args);
8723             Process_Extended_Import_Export_Subprogram_Pragma (
8724               Arg_Internal        => Internal,
8725               Arg_External        => External,
8726               Arg_Parameter_Types => Parameter_Types,
8727               Arg_Mechanism       => Mechanism);
8728          end Export_Valued_Procedure;
8729
8730          -------------------
8731          -- Extend_System --
8732          -------------------
8733
8734          --  pragma Extend_System ([Name =>] Identifier);
8735
8736          when Pragma_Extend_System => Extend_System : declare
8737          begin
8738             GNAT_Pragma;
8739             Check_Valid_Configuration_Pragma;
8740             Check_Arg_Count (1);
8741             Check_Optional_Identifier (Arg1, Name_Name);
8742             Check_Arg_Is_Identifier (Arg1);
8743
8744             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8745
8746             if Name_Len > 4
8747               and then Name_Buffer (1 .. 4) = "aux_"
8748             then
8749                if Present (System_Extend_Pragma_Arg) then
8750                   if Chars (Get_Pragma_Arg (Arg1)) =
8751                      Chars (Expression (System_Extend_Pragma_Arg))
8752                   then
8753                      null;
8754                   else
8755                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8756                      Error_Pragma ("pragma% conflicts with that #");
8757                   end if;
8758
8759                else
8760                   System_Extend_Pragma_Arg := Arg1;
8761
8762                   if not GNAT_Mode then
8763                      System_Extend_Unit := Arg1;
8764                   end if;
8765                end if;
8766             else
8767                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8768             end if;
8769          end Extend_System;
8770
8771          ------------------------
8772          -- Extensions_Allowed --
8773          ------------------------
8774
8775          --  pragma Extensions_Allowed (ON | OFF);
8776
8777          when Pragma_Extensions_Allowed =>
8778             GNAT_Pragma;
8779             Check_Arg_Count (1);
8780             Check_No_Identifiers;
8781             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8782
8783             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8784                Extensions_Allowed := True;
8785                Ada_Version := Ada_Version_Type'Last;
8786
8787             else
8788                Extensions_Allowed := False;
8789                Ada_Version := Ada_Version_Explicit;
8790             end if;
8791
8792          --------------
8793          -- External --
8794          --------------
8795
8796          --  pragma External (
8797          --    [   Convention    =>] convention_IDENTIFIER,
8798          --    [   Entity        =>] local_NAME
8799          --    [, [External_Name =>] static_string_EXPRESSION ]
8800          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8801
8802          when Pragma_External => External : declare
8803                Def_Id : Entity_Id;
8804
8805                C : Convention_Id;
8806                pragma Warnings (Off, C);
8807
8808          begin
8809             GNAT_Pragma;
8810             Check_Arg_Order
8811               ((Name_Convention,
8812                 Name_Entity,
8813                 Name_External_Name,
8814                 Name_Link_Name));
8815             Check_At_Least_N_Arguments (2);
8816             Check_At_Most_N_Arguments  (4);
8817             Process_Convention (C, Def_Id);
8818             Note_Possible_Modification
8819               (Get_Pragma_Arg (Arg2), Sure => False);
8820             Process_Interface_Name (Def_Id, Arg3, Arg4);
8821             Set_Exported (Def_Id, Arg2);
8822          end External;
8823
8824          --------------------------
8825          -- External_Name_Casing --
8826          --------------------------
8827
8828          --  pragma External_Name_Casing (
8829          --    UPPERCASE | LOWERCASE
8830          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8831
8832          when Pragma_External_Name_Casing => External_Name_Casing : declare
8833          begin
8834             GNAT_Pragma;
8835             Check_No_Identifiers;
8836
8837             if Arg_Count = 2 then
8838                Check_Arg_Is_One_Of
8839                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8840
8841                case Chars (Get_Pragma_Arg (Arg2)) is
8842                   when Name_As_Is     =>
8843                      Opt.External_Name_Exp_Casing := As_Is;
8844
8845                   when Name_Uppercase =>
8846                      Opt.External_Name_Exp_Casing := Uppercase;
8847
8848                   when Name_Lowercase =>
8849                      Opt.External_Name_Exp_Casing := Lowercase;
8850
8851                   when others =>
8852                      null;
8853                end case;
8854
8855             else
8856                Check_Arg_Count (1);
8857             end if;
8858
8859             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8860
8861             case Chars (Get_Pragma_Arg (Arg1)) is
8862                when Name_Uppercase =>
8863                   Opt.External_Name_Imp_Casing := Uppercase;
8864
8865                when Name_Lowercase =>
8866                   Opt.External_Name_Imp_Casing := Lowercase;
8867
8868                when others =>
8869                   null;
8870             end case;
8871          end External_Name_Casing;
8872
8873          --------------------------
8874          -- Favor_Top_Level --
8875          --------------------------
8876
8877          --  pragma Favor_Top_Level (type_NAME);
8878
8879          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8880                Named_Entity : Entity_Id;
8881
8882          begin
8883             GNAT_Pragma;
8884             Check_No_Identifiers;
8885             Check_Arg_Count (1);
8886             Check_Arg_Is_Local_Name (Arg1);
8887             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8888
8889             --  If it's an access-to-subprogram type (in particular, not a
8890             --  subtype), set the flag on that type.
8891
8892             if Is_Access_Subprogram_Type (Named_Entity) then
8893                Set_Can_Use_Internal_Rep (Named_Entity, False);
8894
8895             --  Otherwise it's an error (name denotes the wrong sort of entity)
8896
8897             else
8898                Error_Pragma_Arg
8899                  ("access-to-subprogram type expected",
8900                   Get_Pragma_Arg (Arg1));
8901             end if;
8902          end Favor_Top_Level;
8903
8904          ---------------
8905          -- Fast_Math --
8906          ---------------
8907
8908          --  pragma Fast_Math;
8909
8910          when Pragma_Fast_Math =>
8911             GNAT_Pragma;
8912             Check_No_Identifiers;
8913             Check_Valid_Configuration_Pragma;
8914             Fast_Math := True;
8915
8916          ---------------------------
8917          -- Finalize_Storage_Only --
8918          ---------------------------
8919
8920          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8921
8922          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8923             Assoc   : constant Node_Id := Arg1;
8924             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8925             Typ     : Entity_Id;
8926
8927          begin
8928             GNAT_Pragma;
8929             Check_No_Identifiers;
8930             Check_Arg_Count (1);
8931             Check_Arg_Is_Local_Name (Arg1);
8932
8933             Find_Type (Type_Id);
8934             Typ := Entity (Type_Id);
8935
8936             if Typ = Any_Type
8937               or else Rep_Item_Too_Early (Typ, N)
8938             then
8939                return;
8940             else
8941                Typ := Underlying_Type (Typ);
8942             end if;
8943
8944             if not Is_Controlled (Typ) then
8945                Error_Pragma ("pragma% must specify controlled type");
8946             end if;
8947
8948             Check_First_Subtype (Arg1);
8949
8950             if Finalize_Storage_Only (Typ) then
8951                Error_Pragma ("duplicate pragma%, only one allowed");
8952
8953             elsif not Rep_Item_Too_Late (Typ, N) then
8954                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8955             end if;
8956          end Finalize_Storage;
8957
8958          --------------------------
8959          -- Float_Representation --
8960          --------------------------
8961
8962          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8963
8964          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8965
8966          when Pragma_Float_Representation => Float_Representation : declare
8967             Argx : Node_Id;
8968             Digs : Nat;
8969             Ent  : Entity_Id;
8970
8971          begin
8972             GNAT_Pragma;
8973
8974             if Arg_Count = 1 then
8975                Check_Valid_Configuration_Pragma;
8976             else
8977                Check_Arg_Count (2);
8978                Check_Optional_Identifier (Arg2, Name_Entity);
8979                Check_Arg_Is_Local_Name (Arg2);
8980             end if;
8981
8982             Check_No_Identifier (Arg1);
8983             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8984
8985             if not OpenVMS_On_Target then
8986                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8987                   Error_Pragma
8988                     ("?pragma% ignored (applies only to Open'V'M'S)");
8989                end if;
8990
8991                return;
8992             end if;
8993
8994             --  One argument case
8995
8996             if Arg_Count = 1 then
8997                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8998                   if Opt.Float_Format = 'I' then
8999                      Error_Pragma ("'I'E'E'E format previously specified");
9000                   end if;
9001
9002                   Opt.Float_Format := 'V';
9003
9004                else
9005                   if Opt.Float_Format = 'V' then
9006                      Error_Pragma ("'V'A'X format previously specified");
9007                   end if;
9008
9009                   Opt.Float_Format := 'I';
9010                end if;
9011
9012                Set_Standard_Fpt_Formats;
9013
9014             --  Two argument case
9015
9016             else
9017                Argx := Get_Pragma_Arg (Arg2);
9018
9019                if not Is_Entity_Name (Argx)
9020                  or else not Is_Floating_Point_Type (Entity (Argx))
9021                then
9022                   Error_Pragma_Arg
9023                     ("second argument of% pragma must be floating-point type",
9024                      Arg2);
9025                end if;
9026
9027                Ent  := Entity (Argx);
9028                Digs := UI_To_Int (Digits_Value (Ent));
9029
9030                --  Two arguments, VAX_Float case
9031
9032                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
9033                   case Digs is
9034                      when  6 => Set_F_Float (Ent);
9035                      when  9 => Set_D_Float (Ent);
9036                      when 15 => Set_G_Float (Ent);
9037
9038                      when others =>
9039                         Error_Pragma_Arg
9040                           ("wrong digits value, must be 6,9 or 15", Arg2);
9041                   end case;
9042
9043                --  Two arguments, IEEE_Float case
9044
9045                else
9046                   case Digs is
9047                      when  6 => Set_IEEE_Short (Ent);
9048                      when 15 => Set_IEEE_Long  (Ent);
9049
9050                      when others =>
9051                         Error_Pragma_Arg
9052                           ("wrong digits value, must be 6 or 15", Arg2);
9053                   end case;
9054                end if;
9055             end if;
9056          end Float_Representation;
9057
9058          -----------
9059          -- Ident --
9060          -----------
9061
9062          --  pragma Ident (static_string_EXPRESSION)
9063
9064          --  Note: pragma Comment shares this processing. Pragma Comment is
9065          --  identical to Ident, except that the restriction of the argument to
9066          --  31 characters and the placement restrictions are not enforced for
9067          --  pragma Comment.
9068
9069          when Pragma_Ident | Pragma_Comment => Ident : declare
9070             Str : Node_Id;
9071
9072          begin
9073             GNAT_Pragma;
9074             Check_Arg_Count (1);
9075             Check_No_Identifiers;
9076             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
9077             Store_Note (N);
9078
9079             --  For pragma Ident, preserve DEC compatibility by requiring the
9080             --  pragma to appear in a declarative part or package spec.
9081
9082             if Prag_Id = Pragma_Ident then
9083                Check_Is_In_Decl_Part_Or_Package_Spec;
9084             end if;
9085
9086             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
9087
9088             declare
9089                CS : Node_Id;
9090                GP : Node_Id;
9091
9092             begin
9093                GP := Parent (Parent (N));
9094
9095                if Nkind_In (GP, N_Package_Declaration,
9096                                 N_Generic_Package_Declaration)
9097                then
9098                   GP := Parent (GP);
9099                end if;
9100
9101                --  If we have a compilation unit, then record the ident value,
9102                --  checking for improper duplication.
9103
9104                if Nkind (GP) = N_Compilation_Unit then
9105                   CS := Ident_String (Current_Sem_Unit);
9106
9107                   if Present (CS) then
9108
9109                      --  For Ident, we do not permit multiple instances
9110
9111                      if Prag_Id = Pragma_Ident then
9112                         Error_Pragma ("duplicate% pragma not permitted");
9113
9114                      --  For Comment, we concatenate the string, unless we want
9115                      --  to preserve the tree structure for ASIS.
9116
9117                      elsif not ASIS_Mode then
9118                         Start_String (Strval (CS));
9119                         Store_String_Char (' ');
9120                         Store_String_Chars (Strval (Str));
9121                         Set_Strval (CS, End_String);
9122                      end if;
9123
9124                   else
9125                      --  In VMS, the effect of IDENT is achieved by passing
9126                      --  --identification=name as a --for-linker switch.
9127
9128                      if OpenVMS_On_Target then
9129                         Start_String;
9130                         Store_String_Chars
9131                           ("--for-linker=--identification=");
9132                         String_To_Name_Buffer (Strval (Str));
9133                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
9134
9135                         --  Only the last processed IDENT is saved. The main
9136                         --  purpose is so an IDENT associated with a main
9137                         --  procedure will be used in preference to an IDENT
9138                         --  associated with a with'd package.
9139
9140                         Replace_Linker_Option_String
9141                           (End_String, "--for-linker=--identification=");
9142                      end if;
9143
9144                      Set_Ident_String (Current_Sem_Unit, Str);
9145                   end if;
9146
9147                --  For subunits, we just ignore the Ident, since in GNAT these
9148                --  are not separate object files, and hence not separate units
9149                --  in the unit table.
9150
9151                elsif Nkind (GP) = N_Subunit then
9152                   null;
9153
9154                --  Otherwise we have a misplaced pragma Ident, but we ignore
9155                --  this if we are in an instantiation, since it comes from
9156                --  a generic, and has no relevance to the instantiation.
9157
9158                elsif Prag_Id = Pragma_Ident then
9159                   if Instantiation_Location (Loc) = No_Location then
9160                      Error_Pragma ("pragma% only allowed at outer level");
9161                   end if;
9162                end if;
9163             end;
9164          end Ident;
9165
9166          ----------------------------
9167          -- Implementation_Defined --
9168          ----------------------------
9169
9170          --  pragma Implementation_Defined (local_NAME);
9171
9172          --  Marks previously declared entity as implementation defined. For
9173          --  an overloaded entity, applies to the most recent homonym.
9174
9175          --  pragma Implementation_Defined;
9176
9177          --  The form with no arguments appears anywhere within a scope, most
9178          --  typically a package spec, and indicates that all entities that are
9179          --  defined within the package spec are Implementation_Defined.
9180
9181          when Pragma_Implementation_Defined => Implementation_Defined : declare
9182             Ent : Entity_Id;
9183
9184          begin
9185             Check_No_Identifiers;
9186
9187             --  Form with no arguments
9188
9189             if Arg_Count = 0 then
9190                Set_Is_Implementation_Defined (Current_Scope);
9191
9192             --  Form with one argument
9193
9194             else
9195                Check_Arg_Count (1);
9196                Check_Arg_Is_Local_Name (Arg1);
9197                Ent := Entity (Get_Pragma_Arg (Arg1));
9198                Set_Is_Implementation_Defined (Ent);
9199             end if;
9200          end Implementation_Defined;
9201
9202          -----------------
9203          -- Implemented --
9204          -----------------
9205
9206          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
9207          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
9208
9209          when Pragma_Implemented => Implemented : declare
9210             Proc_Id : Entity_Id;
9211             Typ     : Entity_Id;
9212
9213          begin
9214             Ada_2012_Pragma;
9215             Check_Arg_Count (2);
9216             Check_No_Identifiers;
9217             Check_Arg_Is_Identifier (Arg1);
9218             Check_Arg_Is_Local_Name (Arg1);
9219             Check_Arg_Is_One_Of
9220               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
9221
9222             --  Extract the name of the local procedure
9223
9224             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
9225
9226             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
9227             --  primitive procedure of a synchronized tagged type.
9228
9229             if Ekind (Proc_Id) = E_Procedure
9230               and then Is_Primitive (Proc_Id)
9231               and then Present (First_Formal (Proc_Id))
9232             then
9233                Typ := Etype (First_Formal (Proc_Id));
9234
9235                if Is_Tagged_Type (Typ)
9236                  and then
9237
9238                   --  Check for a protected, a synchronized or a task interface
9239
9240                    ((Is_Interface (Typ)
9241                        and then Is_Synchronized_Interface (Typ))
9242
9243                   --  Check for a protected type or a task type that implements
9244                   --  an interface.
9245
9246                    or else
9247                     (Is_Concurrent_Record_Type (Typ)
9248                        and then Present (Interfaces (Typ)))
9249
9250                   --  Check for a private record extension with keyword
9251                   --  "synchronized".
9252
9253                    or else
9254                     (Ekind_In (Typ, E_Record_Type_With_Private,
9255                                     E_Record_Subtype_With_Private)
9256                        and then Synchronized_Present (Parent (Typ))))
9257                then
9258                   null;
9259                else
9260                   Error_Pragma_Arg
9261                     ("controlling formal must be of synchronized " &
9262                      "tagged type", Arg1);
9263                   return;
9264                end if;
9265
9266             --  Procedures declared inside a protected type must be accepted
9267
9268             elsif Ekind (Proc_Id) = E_Procedure
9269               and then Is_Protected_Type (Scope (Proc_Id))
9270             then
9271                null;
9272
9273             --  The first argument is not a primitive procedure
9274
9275             else
9276                Error_Pragma_Arg
9277                  ("pragma % must be applied to a primitive procedure", Arg1);
9278                return;
9279             end if;
9280
9281             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9282             --  By_Protected_Procedure to the primitive procedure of a task
9283             --  interface.
9284
9285             if Chars (Arg2) = Name_By_Protected_Procedure
9286               and then Is_Interface (Typ)
9287               and then Is_Task_Interface (Typ)
9288             then
9289                Error_Pragma_Arg
9290                  ("implementation kind By_Protected_Procedure cannot be " &
9291                   "applied to a task interface primitive", Arg2);
9292                return;
9293             end if;
9294
9295             Record_Rep_Item (Proc_Id, N);
9296          end Implemented;
9297
9298          ----------------------
9299          -- Implicit_Packing --
9300          ----------------------
9301
9302          --  pragma Implicit_Packing;
9303
9304          when Pragma_Implicit_Packing =>
9305             GNAT_Pragma;
9306             Check_Arg_Count (0);
9307             Implicit_Packing := True;
9308
9309          ------------
9310          -- Import --
9311          ------------
9312
9313          --  pragma Import (
9314          --       [Convention    =>] convention_IDENTIFIER,
9315          --       [Entity        =>] local_NAME
9316          --    [, [External_Name =>] static_string_EXPRESSION ]
9317          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9318
9319          when Pragma_Import =>
9320             Check_Ada_83_Warning;
9321             Check_Arg_Order
9322               ((Name_Convention,
9323                 Name_Entity,
9324                 Name_External_Name,
9325                 Name_Link_Name));
9326             Check_At_Least_N_Arguments (2);
9327             Check_At_Most_N_Arguments  (4);
9328             Process_Import_Or_Interface;
9329
9330          ----------------------
9331          -- Import_Exception --
9332          ----------------------
9333
9334          --  pragma Import_Exception (
9335          --        [Internal         =>] LOCAL_NAME
9336          --     [, [External         =>] EXTERNAL_SYMBOL]
9337          --     [, [Form     =>] Ada | VMS]
9338          --     [, [Code     =>] static_integer_EXPRESSION]);
9339
9340          when Pragma_Import_Exception => Import_Exception : declare
9341             Args  : Args_List (1 .. 4);
9342             Names : constant Name_List (1 .. 4) := (
9343                       Name_Internal,
9344                       Name_External,
9345                       Name_Form,
9346                       Name_Code);
9347
9348             Internal : Node_Id renames Args (1);
9349             External : Node_Id renames Args (2);
9350             Form     : Node_Id renames Args (3);
9351             Code     : Node_Id renames Args (4);
9352
9353          begin
9354             GNAT_Pragma;
9355             Gather_Associations (Names, Args);
9356
9357             if Present (External) and then Present (Code) then
9358                Error_Pragma
9359                  ("cannot give both External and Code options for pragma%");
9360             end if;
9361
9362             Process_Extended_Import_Export_Exception_Pragma (
9363               Arg_Internal => Internal,
9364               Arg_External => External,
9365               Arg_Form     => Form,
9366               Arg_Code     => Code);
9367
9368             if not Is_VMS_Exception (Entity (Internal)) then
9369                Set_Imported (Entity (Internal));
9370             end if;
9371          end Import_Exception;
9372
9373          ---------------------
9374          -- Import_Function --
9375          ---------------------
9376
9377          --  pragma Import_Function (
9378          --        [Internal                 =>] LOCAL_NAME,
9379          --     [, [External                 =>] EXTERNAL_SYMBOL]
9380          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9381          --     [, [Result_Type              =>] SUBTYPE_MARK]
9382          --     [, [Mechanism                =>] MECHANISM]
9383          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9384          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9385
9386          --  EXTERNAL_SYMBOL ::=
9387          --    IDENTIFIER
9388          --  | static_string_EXPRESSION
9389
9390          --  PARAMETER_TYPES ::=
9391          --    null
9392          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9393
9394          --  TYPE_DESIGNATOR ::=
9395          --    subtype_NAME
9396          --  | subtype_Name ' Access
9397
9398          --  MECHANISM ::=
9399          --    MECHANISM_NAME
9400          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9401
9402          --  MECHANISM_ASSOCIATION ::=
9403          --    [formal_parameter_NAME =>] MECHANISM_NAME
9404
9405          --  MECHANISM_NAME ::=
9406          --    Value
9407          --  | Reference
9408          --  | Descriptor [([Class =>] CLASS_NAME)]
9409
9410          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9411
9412          when Pragma_Import_Function => Import_Function : declare
9413             Args  : Args_List (1 .. 7);
9414             Names : constant Name_List (1 .. 7) := (
9415                       Name_Internal,
9416                       Name_External,
9417                       Name_Parameter_Types,
9418                       Name_Result_Type,
9419                       Name_Mechanism,
9420                       Name_Result_Mechanism,
9421                       Name_First_Optional_Parameter);
9422
9423             Internal                 : Node_Id renames Args (1);
9424             External                 : Node_Id renames Args (2);
9425             Parameter_Types          : Node_Id renames Args (3);
9426             Result_Type              : Node_Id renames Args (4);
9427             Mechanism                : Node_Id renames Args (5);
9428             Result_Mechanism         : Node_Id renames Args (6);
9429             First_Optional_Parameter : Node_Id renames Args (7);
9430
9431          begin
9432             GNAT_Pragma;
9433             Gather_Associations (Names, Args);
9434             Process_Extended_Import_Export_Subprogram_Pragma (
9435               Arg_Internal                 => Internal,
9436               Arg_External                 => External,
9437               Arg_Parameter_Types          => Parameter_Types,
9438               Arg_Result_Type              => Result_Type,
9439               Arg_Mechanism                => Mechanism,
9440               Arg_Result_Mechanism         => Result_Mechanism,
9441               Arg_First_Optional_Parameter => First_Optional_Parameter);
9442          end Import_Function;
9443
9444          -------------------
9445          -- Import_Object --
9446          -------------------
9447
9448          --  pragma Import_Object (
9449          --        [Internal =>] LOCAL_NAME
9450          --     [, [External =>] EXTERNAL_SYMBOL]
9451          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9452
9453          --  EXTERNAL_SYMBOL ::=
9454          --    IDENTIFIER
9455          --  | static_string_EXPRESSION
9456
9457          when Pragma_Import_Object => Import_Object : declare
9458             Args  : Args_List (1 .. 3);
9459             Names : constant Name_List (1 .. 3) := (
9460                       Name_Internal,
9461                       Name_External,
9462                       Name_Size);
9463
9464             Internal : Node_Id renames Args (1);
9465             External : Node_Id renames Args (2);
9466             Size     : Node_Id renames Args (3);
9467
9468          begin
9469             GNAT_Pragma;
9470             Gather_Associations (Names, Args);
9471             Process_Extended_Import_Export_Object_Pragma (
9472               Arg_Internal => Internal,
9473               Arg_External => External,
9474               Arg_Size     => Size);
9475          end Import_Object;
9476
9477          ----------------------
9478          -- Import_Procedure --
9479          ----------------------
9480
9481          --  pragma Import_Procedure (
9482          --        [Internal                 =>] LOCAL_NAME
9483          --     [, [External                 =>] EXTERNAL_SYMBOL]
9484          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9485          --     [, [Mechanism                =>] MECHANISM]
9486          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9487
9488          --  EXTERNAL_SYMBOL ::=
9489          --    IDENTIFIER
9490          --  | static_string_EXPRESSION
9491
9492          --  PARAMETER_TYPES ::=
9493          --    null
9494          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9495
9496          --  TYPE_DESIGNATOR ::=
9497          --    subtype_NAME
9498          --  | subtype_Name ' Access
9499
9500          --  MECHANISM ::=
9501          --    MECHANISM_NAME
9502          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9503
9504          --  MECHANISM_ASSOCIATION ::=
9505          --    [formal_parameter_NAME =>] MECHANISM_NAME
9506
9507          --  MECHANISM_NAME ::=
9508          --    Value
9509          --  | Reference
9510          --  | Descriptor [([Class =>] CLASS_NAME)]
9511
9512          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9513
9514          when Pragma_Import_Procedure => Import_Procedure : declare
9515             Args  : Args_List (1 .. 5);
9516             Names : constant Name_List (1 .. 5) := (
9517                       Name_Internal,
9518                       Name_External,
9519                       Name_Parameter_Types,
9520                       Name_Mechanism,
9521                       Name_First_Optional_Parameter);
9522
9523             Internal                 : Node_Id renames Args (1);
9524             External                 : Node_Id renames Args (2);
9525             Parameter_Types          : Node_Id renames Args (3);
9526             Mechanism                : Node_Id renames Args (4);
9527             First_Optional_Parameter : Node_Id renames Args (5);
9528
9529          begin
9530             GNAT_Pragma;
9531             Gather_Associations (Names, Args);
9532             Process_Extended_Import_Export_Subprogram_Pragma (
9533               Arg_Internal                 => Internal,
9534               Arg_External                 => External,
9535               Arg_Parameter_Types          => Parameter_Types,
9536               Arg_Mechanism                => Mechanism,
9537               Arg_First_Optional_Parameter => First_Optional_Parameter);
9538          end Import_Procedure;
9539
9540          -----------------------------
9541          -- Import_Valued_Procedure --
9542          -----------------------------
9543
9544          --  pragma Import_Valued_Procedure (
9545          --        [Internal                 =>] LOCAL_NAME
9546          --     [, [External                 =>] EXTERNAL_SYMBOL]
9547          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9548          --     [, [Mechanism                =>] MECHANISM]
9549          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9550
9551          --  EXTERNAL_SYMBOL ::=
9552          --    IDENTIFIER
9553          --  | static_string_EXPRESSION
9554
9555          --  PARAMETER_TYPES ::=
9556          --    null
9557          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9558
9559          --  TYPE_DESIGNATOR ::=
9560          --    subtype_NAME
9561          --  | subtype_Name ' Access
9562
9563          --  MECHANISM ::=
9564          --    MECHANISM_NAME
9565          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9566
9567          --  MECHANISM_ASSOCIATION ::=
9568          --    [formal_parameter_NAME =>] MECHANISM_NAME
9569
9570          --  MECHANISM_NAME ::=
9571          --    Value
9572          --  | Reference
9573          --  | Descriptor [([Class =>] CLASS_NAME)]
9574
9575          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9576
9577          when Pragma_Import_Valued_Procedure =>
9578          Import_Valued_Procedure : declare
9579             Args  : Args_List (1 .. 5);
9580             Names : constant Name_List (1 .. 5) := (
9581                       Name_Internal,
9582                       Name_External,
9583                       Name_Parameter_Types,
9584                       Name_Mechanism,
9585                       Name_First_Optional_Parameter);
9586
9587             Internal                 : Node_Id renames Args (1);
9588             External                 : Node_Id renames Args (2);
9589             Parameter_Types          : Node_Id renames Args (3);
9590             Mechanism                : Node_Id renames Args (4);
9591             First_Optional_Parameter : Node_Id renames Args (5);
9592
9593          begin
9594             GNAT_Pragma;
9595             Gather_Associations (Names, Args);
9596             Process_Extended_Import_Export_Subprogram_Pragma (
9597               Arg_Internal                 => Internal,
9598               Arg_External                 => External,
9599               Arg_Parameter_Types          => Parameter_Types,
9600               Arg_Mechanism                => Mechanism,
9601               Arg_First_Optional_Parameter => First_Optional_Parameter);
9602          end Import_Valued_Procedure;
9603
9604          -----------------
9605          -- Independent --
9606          -----------------
9607
9608          --  pragma Independent (LOCAL_NAME);
9609
9610          when Pragma_Independent => Independent : declare
9611             E_Id : Node_Id;
9612             E    : Entity_Id;
9613             D    : Node_Id;
9614             K    : Node_Kind;
9615
9616          begin
9617             Check_Ada_83_Warning;
9618             Ada_2012_Pragma;
9619             Check_No_Identifiers;
9620             Check_Arg_Count (1);
9621             Check_Arg_Is_Local_Name (Arg1);
9622             E_Id := Get_Pragma_Arg (Arg1);
9623
9624             if Etype (E_Id) = Any_Type then
9625                return;
9626             end if;
9627
9628             E := Entity (E_Id);
9629             D := Declaration_Node (E);
9630             K := Nkind (D);
9631
9632             --  Check duplicate before we chain ourselves!
9633
9634             Check_Duplicate_Pragma (E);
9635
9636             --  Check appropriate entity
9637
9638             if Is_Type (E) then
9639                if Rep_Item_Too_Early (E, N)
9640                     or else
9641                   Rep_Item_Too_Late (E, N)
9642                then
9643                   return;
9644                else
9645                   Check_First_Subtype (Arg1);
9646                end if;
9647
9648             elsif K = N_Object_Declaration
9649               or else (K = N_Component_Declaration
9650                        and then Original_Record_Component (E) = E)
9651             then
9652                if Rep_Item_Too_Late (E, N) then
9653                   return;
9654                end if;
9655
9656             else
9657                Error_Pragma_Arg
9658                  ("inappropriate entity for pragma%", Arg1);
9659             end if;
9660
9661             Independence_Checks.Append ((N, E));
9662          end Independent;
9663
9664          ----------------------------
9665          -- Independent_Components --
9666          ----------------------------
9667
9668          --  pragma Atomic_Components (array_LOCAL_NAME);
9669
9670          --  This processing is shared by Volatile_Components
9671
9672          when Pragma_Independent_Components => Independent_Components : declare
9673             E_Id : Node_Id;
9674             E    : Entity_Id;
9675             D    : Node_Id;
9676             K    : Node_Kind;
9677
9678          begin
9679             Check_Ada_83_Warning;
9680             Ada_2012_Pragma;
9681             Check_No_Identifiers;
9682             Check_Arg_Count (1);
9683             Check_Arg_Is_Local_Name (Arg1);
9684             E_Id := Get_Pragma_Arg (Arg1);
9685
9686             if Etype (E_Id) = Any_Type then
9687                return;
9688             end if;
9689
9690             E := Entity (E_Id);
9691
9692             --  Check duplicate before we chain ourselves!
9693
9694             Check_Duplicate_Pragma (E);
9695
9696             --  Check appropriate entity
9697
9698             if Rep_Item_Too_Early (E, N)
9699                  or else
9700                Rep_Item_Too_Late (E, N)
9701             then
9702                return;
9703             end if;
9704
9705             D := Declaration_Node (E);
9706             K := Nkind (D);
9707
9708             if (K = N_Full_Type_Declaration
9709                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9710               or else
9711                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9712                    and then Nkind (D) = N_Object_Declaration
9713                    and then Nkind (Object_Definition (D)) =
9714                                        N_Constrained_Array_Definition)
9715             then
9716                Independence_Checks.Append ((N, E));
9717
9718             else
9719                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9720             end if;
9721          end Independent_Components;
9722
9723          ------------------------
9724          -- Initialize_Scalars --
9725          ------------------------
9726
9727          --  pragma Initialize_Scalars;
9728
9729          when Pragma_Initialize_Scalars =>
9730             GNAT_Pragma;
9731             Check_Arg_Count (0);
9732             Check_Valid_Configuration_Pragma;
9733             Check_Restriction (No_Initialize_Scalars, N);
9734
9735             --  Initialize_Scalars creates false positives in CodePeer, and
9736             --  incorrect negative results in Alfa mode, so ignore this pragma
9737             --  in these modes.
9738
9739             if not Restriction_Active (No_Initialize_Scalars)
9740               and then not (CodePeer_Mode or Alfa_Mode)
9741             then
9742                Init_Or_Norm_Scalars := True;
9743                Initialize_Scalars := True;
9744             end if;
9745
9746          ------------
9747          -- Inline --
9748          ------------
9749
9750          --  pragma Inline ( NAME {, NAME} );
9751
9752          when Pragma_Inline =>
9753
9754             --  Pragma is active if inlining option is active
9755
9756             Process_Inline (Inline_Active);
9757
9758          -------------------
9759          -- Inline_Always --
9760          -------------------
9761
9762          --  pragma Inline_Always ( NAME {, NAME} );
9763
9764          when Pragma_Inline_Always =>
9765             GNAT_Pragma;
9766
9767             --  Pragma always active unless in CodePeer or Alfa mode, since
9768             --  this causes walk order issues.
9769
9770             if not (CodePeer_Mode or Alfa_Mode) then
9771                Process_Inline (True);
9772             end if;
9773
9774          --------------------
9775          -- Inline_Generic --
9776          --------------------
9777
9778          --  pragma Inline_Generic (NAME {, NAME});
9779
9780          when Pragma_Inline_Generic =>
9781             GNAT_Pragma;
9782             Process_Generic_List;
9783
9784          ----------------------
9785          -- Inspection_Point --
9786          ----------------------
9787
9788          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9789
9790          when Pragma_Inspection_Point => Inspection_Point : declare
9791             Arg : Node_Id;
9792             Exp : Node_Id;
9793
9794          begin
9795             if Arg_Count > 0 then
9796                Arg := Arg1;
9797                loop
9798                   Exp := Get_Pragma_Arg (Arg);
9799                   Analyze (Exp);
9800
9801                   if not Is_Entity_Name (Exp)
9802                     or else not Is_Object (Entity (Exp))
9803                   then
9804                      Error_Pragma_Arg ("object name required", Arg);
9805                   end if;
9806
9807                   Next (Arg);
9808                   exit when No (Arg);
9809                end loop;
9810             end if;
9811          end Inspection_Point;
9812
9813          ---------------
9814          -- Interface --
9815          ---------------
9816
9817          --  pragma Interface (
9818          --    [   Convention    =>] convention_IDENTIFIER,
9819          --    [   Entity        =>] local_NAME
9820          --    [, [External_Name =>] static_string_EXPRESSION ]
9821          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9822
9823          when Pragma_Interface =>
9824             GNAT_Pragma;
9825             Check_Arg_Order
9826               ((Name_Convention,
9827                 Name_Entity,
9828                 Name_External_Name,
9829                 Name_Link_Name));
9830             Check_At_Least_N_Arguments (2);
9831             Check_At_Most_N_Arguments  (4);
9832             Process_Import_Or_Interface;
9833
9834             --  In Ada 2005, the permission to use Interface (a reserved word)
9835             --  as a pragma name is considered an obsolescent feature.
9836
9837             if Ada_Version >= Ada_2005 then
9838                Check_Restriction
9839                  (No_Obsolescent_Features, Pragma_Identifier (N));
9840             end if;
9841
9842          --------------------
9843          -- Interface_Name --
9844          --------------------
9845
9846          --  pragma Interface_Name (
9847          --    [  Entity        =>] local_NAME
9848          --    [,[External_Name =>] static_string_EXPRESSION ]
9849          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9850
9851          when Pragma_Interface_Name => Interface_Name : declare
9852             Id     : Node_Id;
9853             Def_Id : Entity_Id;
9854             Hom_Id : Entity_Id;
9855             Found  : Boolean;
9856
9857          begin
9858             GNAT_Pragma;
9859             Check_Arg_Order
9860               ((Name_Entity, Name_External_Name, Name_Link_Name));
9861             Check_At_Least_N_Arguments (2);
9862             Check_At_Most_N_Arguments  (3);
9863             Id := Get_Pragma_Arg (Arg1);
9864             Analyze (Id);
9865
9866             if not Is_Entity_Name (Id) then
9867                Error_Pragma_Arg
9868                  ("first argument for pragma% must be entity name", Arg1);
9869             elsif Etype (Id) = Any_Type then
9870                return;
9871             else
9872                Def_Id := Entity (Id);
9873             end if;
9874
9875             --  Special DEC-compatible processing for the object case, forces
9876             --  object to be imported.
9877
9878             if Ekind (Def_Id) = E_Variable then
9879                Kill_Size_Check_Code (Def_Id);
9880                Note_Possible_Modification (Id, Sure => False);
9881
9882                --  Initialization is not allowed for imported variable
9883
9884                if Present (Expression (Parent (Def_Id)))
9885                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9886                then
9887                   Error_Msg_Sloc := Sloc (Def_Id);
9888                   Error_Pragma_Arg
9889                     ("no initialization allowed for declaration of& #",
9890                      Arg2);
9891
9892                else
9893                   --  For compatibility, support VADS usage of providing both
9894                   --  pragmas Interface and Interface_Name to obtain the effect
9895                   --  of a single Import pragma.
9896
9897                   if Is_Imported (Def_Id)
9898                     and then Present (First_Rep_Item (Def_Id))
9899                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9900                     and then
9901                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9902                   then
9903                      null;
9904                   else
9905                      Set_Imported (Def_Id);
9906                   end if;
9907
9908                   Set_Is_Public (Def_Id);
9909                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9910                end if;
9911
9912             --  Otherwise must be subprogram
9913
9914             elsif not Is_Subprogram (Def_Id) then
9915                Error_Pragma_Arg
9916                  ("argument of pragma% is not subprogram", Arg1);
9917
9918             else
9919                Check_At_Most_N_Arguments (3);
9920                Hom_Id := Def_Id;
9921                Found := False;
9922
9923                --  Loop through homonyms
9924
9925                loop
9926                   Def_Id := Get_Base_Subprogram (Hom_Id);
9927
9928                   if Is_Imported (Def_Id) then
9929                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9930                      Found := True;
9931                   end if;
9932
9933                   exit when From_Aspect_Specification (N);
9934                   Hom_Id := Homonym (Hom_Id);
9935
9936                   exit when No (Hom_Id)
9937                     or else Scope (Hom_Id) /= Current_Scope;
9938                end loop;
9939
9940                if not Found then
9941                   Error_Pragma_Arg
9942                     ("argument of pragma% is not imported subprogram",
9943                      Arg1);
9944                end if;
9945             end if;
9946          end Interface_Name;
9947
9948          -----------------------
9949          -- Interrupt_Handler --
9950          -----------------------
9951
9952          --  pragma Interrupt_Handler (handler_NAME);
9953
9954          when Pragma_Interrupt_Handler =>
9955             Check_Ada_83_Warning;
9956             Check_Arg_Count (1);
9957             Check_No_Identifiers;
9958
9959             if No_Run_Time_Mode then
9960                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9961             else
9962                Check_Interrupt_Or_Attach_Handler;
9963                Process_Interrupt_Or_Attach_Handler;
9964             end if;
9965
9966          ------------------------
9967          -- Interrupt_Priority --
9968          ------------------------
9969
9970          --  pragma Interrupt_Priority [(EXPRESSION)];
9971
9972          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9973             P   : constant Node_Id := Parent (N);
9974             Arg : Node_Id;
9975
9976          begin
9977             Check_Ada_83_Warning;
9978
9979             if Arg_Count /= 0 then
9980                Arg := Get_Pragma_Arg (Arg1);
9981                Check_Arg_Count (1);
9982                Check_No_Identifiers;
9983
9984                --  The expression must be analyzed in the special manner
9985                --  described in "Handling of Default and Per-Object
9986                --  Expressions" in sem.ads.
9987
9988                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9989             end if;
9990
9991             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9992                Pragma_Misplaced;
9993                return;
9994
9995             elsif Has_Pragma_Priority (P) then
9996                Error_Pragma ("duplicate pragma% not allowed");
9997
9998             else
9999                Set_Has_Pragma_Priority (P, True);
10000                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
10001             end if;
10002          end Interrupt_Priority;
10003
10004          ---------------------
10005          -- Interrupt_State --
10006          ---------------------
10007
10008          --  pragma Interrupt_State (
10009          --    [Name  =>] INTERRUPT_ID,
10010          --    [State =>] INTERRUPT_STATE);
10011
10012          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
10013          --  INTERRUPT_STATE => System | Runtime | User
10014
10015          --  Note: if the interrupt id is given as an identifier, then it must
10016          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
10017          --  given as a static integer expression which must be in the range of
10018          --  Ada.Interrupts.Interrupt_ID.
10019
10020          when Pragma_Interrupt_State => Interrupt_State : declare
10021
10022             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
10023             --  This is the entity Ada.Interrupts.Interrupt_ID;
10024
10025             State_Type : Character;
10026             --  Set to 's'/'r'/'u' for System/Runtime/User
10027
10028             IST_Num : Pos;
10029             --  Index to entry in Interrupt_States table
10030
10031             Int_Val : Uint;
10032             --  Value of interrupt
10033
10034             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
10035             --  The first argument to the pragma
10036
10037             Int_Ent : Entity_Id;
10038             --  Interrupt entity in Ada.Interrupts.Names
10039
10040          begin
10041             GNAT_Pragma;
10042             Check_Arg_Order ((Name_Name, Name_State));
10043             Check_Arg_Count (2);
10044
10045             Check_Optional_Identifier (Arg1, Name_Name);
10046             Check_Optional_Identifier (Arg2, Name_State);
10047             Check_Arg_Is_Identifier (Arg2);
10048
10049             --  First argument is identifier
10050
10051             if Nkind (Arg1X) = N_Identifier then
10052
10053                --  Search list of names in Ada.Interrupts.Names
10054
10055                Int_Ent := First_Entity (RTE (RE_Names));
10056                loop
10057                   if No (Int_Ent) then
10058                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
10059
10060                   elsif Chars (Int_Ent) = Chars (Arg1X) then
10061                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
10062                      exit;
10063                   end if;
10064
10065                   Next_Entity (Int_Ent);
10066                end loop;
10067
10068             --  First argument is not an identifier, so it must be a static
10069             --  expression of type Ada.Interrupts.Interrupt_ID.
10070
10071             else
10072                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
10073                Int_Val := Expr_Value (Arg1X);
10074
10075                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
10076                     or else
10077                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
10078                then
10079                   Error_Pragma_Arg
10080                     ("value not in range of type " &
10081                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
10082                end if;
10083             end if;
10084
10085             --  Check OK state
10086
10087             case Chars (Get_Pragma_Arg (Arg2)) is
10088                when Name_Runtime => State_Type := 'r';
10089                when Name_System  => State_Type := 's';
10090                when Name_User    => State_Type := 'u';
10091
10092                when others =>
10093                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
10094             end case;
10095
10096             --  Check if entry is already stored
10097
10098             IST_Num := Interrupt_States.First;
10099             loop
10100                --  If entry not found, add it
10101
10102                if IST_Num > Interrupt_States.Last then
10103                   Interrupt_States.Append
10104                     ((Interrupt_Number => UI_To_Int (Int_Val),
10105                       Interrupt_State  => State_Type,
10106                       Pragma_Loc       => Loc));
10107                   exit;
10108
10109                --  Case of entry for the same entry
10110
10111                elsif Int_Val = Interrupt_States.Table (IST_Num).
10112                                                            Interrupt_Number
10113                then
10114                   --  If state matches, done, no need to make redundant entry
10115
10116                   exit when
10117                     State_Type = Interrupt_States.Table (IST_Num).
10118                                                            Interrupt_State;
10119
10120                   --  Otherwise if state does not match, error
10121
10122                   Error_Msg_Sloc :=
10123                     Interrupt_States.Table (IST_Num).Pragma_Loc;
10124                   Error_Pragma_Arg
10125                     ("state conflicts with that given #", Arg2);
10126                   exit;
10127                end if;
10128
10129                IST_Num := IST_Num + 1;
10130             end loop;
10131          end Interrupt_State;
10132
10133          ---------------
10134          -- Invariant --
10135          ---------------
10136
10137          --  pragma Invariant
10138          --    ([Entity =>]    type_LOCAL_NAME,
10139          --     [Check  =>]    EXPRESSION
10140          --     [,[Message =>] String_Expression]);
10141
10142          when Pragma_Invariant => Invariant : declare
10143             Type_Id : Node_Id;
10144             Typ     : Entity_Id;
10145
10146             Discard : Boolean;
10147             pragma Unreferenced (Discard);
10148
10149          begin
10150             GNAT_Pragma;
10151             Check_At_Least_N_Arguments (2);
10152             Check_At_Most_N_Arguments (3);
10153             Check_Optional_Identifier (Arg1, Name_Entity);
10154             Check_Optional_Identifier (Arg2, Name_Check);
10155
10156             if Arg_Count = 3 then
10157                Check_Optional_Identifier (Arg3, Name_Message);
10158                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
10159             end if;
10160
10161             Check_Arg_Is_Local_Name (Arg1);
10162
10163             Type_Id := Get_Pragma_Arg (Arg1);
10164             Find_Type (Type_Id);
10165             Typ := Entity (Type_Id);
10166
10167             if Typ = Any_Type then
10168                return;
10169
10170             --  An invariant must apply to a private type, or appear in the
10171             --  private part of a package spec and apply to a completion.
10172
10173             elsif Ekind_In (Typ, E_Private_Type,
10174                                  E_Record_Type_With_Private,
10175                                  E_Limited_Private_Type)
10176             then
10177                null;
10178
10179             elsif In_Private_Part (Current_Scope)
10180               and then Has_Private_Declaration (Typ)
10181             then
10182                null;
10183
10184             elsif In_Private_Part (Current_Scope) then
10185                Error_Pragma_Arg_Alternate_Name
10186                  ("pragma% only allowed for private type " &
10187                   "declared in visible part", Arg1,
10188                   Alt_Name => Name_Type_Invariant);
10189
10190             else
10191                Error_Pragma_Arg_Alternate_Name
10192                  ("pragma% only allowed for private type", Arg1,
10193                   Alt_Name => Name_Type_Invariant);
10194             end if;
10195
10196             --  Note that the type has at least one invariant, and also that
10197             --  it has inheritable invariants if we have Invariant'Class.
10198
10199             Set_Has_Invariants (Typ);
10200
10201             if Class_Present (N) then
10202                Set_Has_Inheritable_Invariants (Typ);
10203             end if;
10204
10205             --  The remaining processing is simply to link the pragma on to
10206             --  the rep item chain, for processing when the type is frozen.
10207             --  This is accomplished by a call to Rep_Item_Too_Late.
10208
10209             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
10210          end Invariant;
10211
10212          ----------------------
10213          -- Java_Constructor --
10214          ----------------------
10215
10216          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
10217
10218          --  Also handles pragma CIL_Constructor
10219
10220          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
10221          Java_Constructor : declare
10222             Convention  : Convention_Id;
10223             Def_Id      : Entity_Id;
10224             Hom_Id      : Entity_Id;
10225             Id          : Entity_Id;
10226             This_Formal : Entity_Id;
10227
10228          begin
10229             GNAT_Pragma;
10230             Check_Arg_Count (1);
10231             Check_Optional_Identifier (Arg1, Name_Entity);
10232             Check_Arg_Is_Local_Name (Arg1);
10233
10234             Id := Get_Pragma_Arg (Arg1);
10235             Find_Program_Unit_Name (Id);
10236
10237             --  If we did not find the name, we are done
10238
10239             if Etype (Id) = Any_Type then
10240                return;
10241             end if;
10242
10243             --  Check wrong use of pragma in wrong VM target
10244
10245             if VM_Target = No_VM then
10246                return;
10247
10248             elsif VM_Target = CLI_Target
10249               and then Prag_Id = Pragma_Java_Constructor
10250             then
10251                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10252
10253             elsif VM_Target = JVM_Target
10254               and then Prag_Id = Pragma_CIL_Constructor
10255             then
10256                Error_Pragma ("must use pragma 'Java_'Constructor");
10257             end if;
10258
10259             case Prag_Id is
10260                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
10261                when Pragma_Java_Constructor => Convention := Convention_Java;
10262                when others                  => null;
10263             end case;
10264
10265             Hom_Id := Entity (Id);
10266
10267             --  Loop through homonyms
10268
10269             loop
10270                Def_Id := Get_Base_Subprogram (Hom_Id);
10271
10272                --  The constructor is required to be a function
10273
10274                if Ekind (Def_Id) /= E_Function then
10275                   if VM_Target = JVM_Target then
10276                      Error_Pragma_Arg
10277                        ("pragma% requires function returning a " &
10278                         "'Java access type", Def_Id);
10279                   else
10280                      Error_Pragma_Arg
10281                        ("pragma% requires function returning a " &
10282                         "'C'I'L access type", Def_Id);
10283                   end if;
10284                end if;
10285
10286                --  Check arguments: For tagged type the first formal must be
10287                --  named "this" and its type must be a named access type
10288                --  designating a class-wide tagged type that has convention
10289                --  CIL/Java. The first formal must also have a null default
10290                --  value. For example:
10291
10292                --      type Typ is tagged ...
10293                --      type Ref is access all Typ;
10294                --      pragma Convention (CIL, Typ);
10295
10296                --      function New_Typ (This : Ref) return Ref;
10297                --      function New_Typ (This : Ref; I : Integer) return Ref;
10298                --      pragma Cil_Constructor (New_Typ);
10299
10300                --  Reason: The first formal must NOT be a primitive of the
10301                --  tagged type.
10302
10303                --  This rule also applies to constructors of delegates used
10304                --  to interface with standard target libraries. For example:
10305
10306                --      type Delegate is access procedure ...
10307                --      pragma Import (CIL, Delegate, ...);
10308
10309                --      function new_Delegate
10310                --        (This : Delegate := null; ... ) return Delegate;
10311
10312                --  For value-types this rule does not apply.
10313
10314                if not Is_Value_Type (Etype (Def_Id)) then
10315                   if No (First_Formal (Def_Id)) then
10316                      Error_Msg_Name_1 := Pname;
10317                      Error_Msg_N ("% function must have parameters", Def_Id);
10318                      return;
10319                   end if;
10320
10321                   --  In the JRE library we have several occurrences in which
10322                   --  the "this" parameter is not the first formal.
10323
10324                   This_Formal := First_Formal (Def_Id);
10325
10326                   --  In the JRE library we have several occurrences in which
10327                   --  the "this" parameter is not the first formal. Search for
10328                   --  it.
10329
10330                   if VM_Target = JVM_Target then
10331                      while Present (This_Formal)
10332                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10333                      loop
10334                         Next_Formal (This_Formal);
10335                      end loop;
10336
10337                      if No (This_Formal) then
10338                         This_Formal := First_Formal (Def_Id);
10339                      end if;
10340                   end if;
10341
10342                   --  Warning: The first parameter should be named "this".
10343                   --  We temporarily allow it because we have the following
10344                   --  case in the Java runtime (file s-osinte.ads) ???
10345
10346                   --    function new_Thread
10347                   --      (Self_Id : System.Address) return Thread_Id;
10348                   --    pragma Java_Constructor (new_Thread);
10349
10350                   if VM_Target = JVM_Target
10351                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10352                                = "self_id"
10353                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10354                   then
10355                      null;
10356
10357                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10358                      Error_Msg_Name_1 := Pname;
10359                      Error_Msg_N
10360                        ("first formal of % function must be named `this`",
10361                         Parent (This_Formal));
10362
10363                   elsif not Is_Access_Type (Etype (This_Formal)) then
10364                      Error_Msg_Name_1 := Pname;
10365                      Error_Msg_N
10366                        ("first formal of % function must be an access type",
10367                         Parameter_Type (Parent (This_Formal)));
10368
10369                   --  For delegates the type of the first formal must be a
10370                   --  named access-to-subprogram type (see previous example)
10371
10372                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10373                     and then Ekind (Etype (This_Formal))
10374                                /= E_Access_Subprogram_Type
10375                   then
10376                      Error_Msg_Name_1 := Pname;
10377                      Error_Msg_N
10378                        ("first formal of % function must be a named access" &
10379                         " to subprogram type",
10380                         Parameter_Type (Parent (This_Formal)));
10381
10382                   --  Warning: We should reject anonymous access types because
10383                   --  the constructor must not be handled as a primitive of the
10384                   --  tagged type. We temporarily allow it because this profile
10385                   --  is currently generated by cil2ada???
10386
10387                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10388                     and then not Ekind_In (Etype (This_Formal),
10389                                              E_Access_Type,
10390                                              E_General_Access_Type,
10391                                              E_Anonymous_Access_Type)
10392                   then
10393                      Error_Msg_Name_1 := Pname;
10394                      Error_Msg_N
10395                        ("first formal of % function must be a named access" &
10396                         " type",
10397                         Parameter_Type (Parent (This_Formal)));
10398
10399                   elsif Atree.Convention
10400                          (Designated_Type (Etype (This_Formal))) /= Convention
10401                   then
10402                      Error_Msg_Name_1 := Pname;
10403
10404                      if Convention = Convention_Java then
10405                         Error_Msg_N
10406                           ("pragma% requires convention 'Cil in designated" &
10407                            " type",
10408                            Parameter_Type (Parent (This_Formal)));
10409                      else
10410                         Error_Msg_N
10411                           ("pragma% requires convention 'Java in designated" &
10412                            " type",
10413                            Parameter_Type (Parent (This_Formal)));
10414                      end if;
10415
10416                   elsif No (Expression (Parent (This_Formal)))
10417                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10418                   then
10419                      Error_Msg_Name_1 := Pname;
10420                      Error_Msg_N
10421                        ("pragma% requires first formal with default `null`",
10422                         Parameter_Type (Parent (This_Formal)));
10423                   end if;
10424                end if;
10425
10426                --  Check result type: the constructor must be a function
10427                --  returning:
10428                --   * a value type (only allowed in the CIL compiler)
10429                --   * an access-to-subprogram type with convention Java/CIL
10430                --   * an access-type designating a type that has convention
10431                --     Java/CIL.
10432
10433                if Is_Value_Type (Etype (Def_Id)) then
10434                   null;
10435
10436                --  Access-to-subprogram type with convention Java/CIL
10437
10438                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10439                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10440                      if Convention = Convention_Java then
10441                         Error_Pragma_Arg
10442                           ("pragma% requires function returning a " &
10443                            "'Java access type", Arg1);
10444                      else
10445                         pragma Assert (Convention = Convention_CIL);
10446                         Error_Pragma_Arg
10447                           ("pragma% requires function returning a " &
10448                            "'C'I'L access type", Arg1);
10449                      end if;
10450                   end if;
10451
10452                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10453                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10454                                                    E_General_Access_Type)
10455                     or else
10456                       Atree.Convention
10457                         (Designated_Type (Etype (Def_Id))) /= Convention
10458                   then
10459                      Error_Msg_Name_1 := Pname;
10460
10461                      if Convention = Convention_Java then
10462                         Error_Pragma_Arg
10463                           ("pragma% requires function returning a named" &
10464                            "'Java access type", Arg1);
10465                      else
10466                         Error_Pragma_Arg
10467                           ("pragma% requires function returning a named" &
10468                            "'C'I'L access type", Arg1);
10469                      end if;
10470                   end if;
10471                end if;
10472
10473                Set_Is_Constructor (Def_Id);
10474                Set_Convention     (Def_Id, Convention);
10475                Set_Is_Imported    (Def_Id);
10476
10477                exit when From_Aspect_Specification (N);
10478                Hom_Id := Homonym (Hom_Id);
10479
10480                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10481             end loop;
10482          end Java_Constructor;
10483
10484          ----------------------
10485          -- Java_Interface --
10486          ----------------------
10487
10488          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10489
10490          when Pragma_Java_Interface => Java_Interface : declare
10491             Arg : Node_Id;
10492             Typ : Entity_Id;
10493
10494          begin
10495             GNAT_Pragma;
10496             Check_Arg_Count (1);
10497             Check_Optional_Identifier (Arg1, Name_Entity);
10498             Check_Arg_Is_Local_Name (Arg1);
10499
10500             Arg := Get_Pragma_Arg (Arg1);
10501             Analyze (Arg);
10502
10503             if Etype (Arg) = Any_Type then
10504                return;
10505             end if;
10506
10507             if not Is_Entity_Name (Arg)
10508               or else not Is_Type (Entity (Arg))
10509             then
10510                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10511             end if;
10512
10513             Typ := Underlying_Type (Entity (Arg));
10514
10515             --  For now simply check some of the semantic constraints on the
10516             --  type. This currently leaves out some restrictions on interface
10517             --  types, namely that the parent type must be java.lang.Object.Typ
10518             --  and that all primitives of the type should be declared
10519             --  abstract. ???
10520
10521             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10522                Error_Pragma_Arg ("pragma% requires an abstract "
10523                  & "tagged type", Arg1);
10524
10525             elsif not Has_Discriminants (Typ)
10526               or else Ekind (Etype (First_Discriminant (Typ)))
10527                         /= E_Anonymous_Access_Type
10528               or else
10529                 not Is_Class_Wide_Type
10530                       (Designated_Type (Etype (First_Discriminant (Typ))))
10531             then
10532                Error_Pragma_Arg
10533                  ("type must have a class-wide access discriminant", Arg1);
10534             end if;
10535          end Java_Interface;
10536
10537          ----------------
10538          -- Keep_Names --
10539          ----------------
10540
10541          --  pragma Keep_Names ([On => ] local_NAME);
10542
10543          when Pragma_Keep_Names => Keep_Names : declare
10544             Arg : Node_Id;
10545
10546          begin
10547             GNAT_Pragma;
10548             Check_Arg_Count (1);
10549             Check_Optional_Identifier (Arg1, Name_On);
10550             Check_Arg_Is_Local_Name (Arg1);
10551
10552             Arg := Get_Pragma_Arg (Arg1);
10553             Analyze (Arg);
10554
10555             if Etype (Arg) = Any_Type then
10556                return;
10557             end if;
10558
10559             if not Is_Entity_Name (Arg)
10560               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10561             then
10562                Error_Pragma_Arg
10563                  ("pragma% requires a local enumeration type", Arg1);
10564             end if;
10565
10566             Set_Discard_Names (Entity (Arg), False);
10567          end Keep_Names;
10568
10569          -------------
10570          -- License --
10571          -------------
10572
10573          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10574
10575          when Pragma_License =>
10576             GNAT_Pragma;
10577             Check_Arg_Count (1);
10578             Check_No_Identifiers;
10579             Check_Valid_Configuration_Pragma;
10580             Check_Arg_Is_Identifier (Arg1);
10581
10582             declare
10583                Sind : constant Source_File_Index :=
10584                         Source_Index (Current_Sem_Unit);
10585
10586             begin
10587                case Chars (Get_Pragma_Arg (Arg1)) is
10588                   when Name_GPL =>
10589                      Set_License (Sind, GPL);
10590
10591                   when Name_Modified_GPL =>
10592                      Set_License (Sind, Modified_GPL);
10593
10594                   when Name_Restricted =>
10595                      Set_License (Sind, Restricted);
10596
10597                   when Name_Unrestricted =>
10598                      Set_License (Sind, Unrestricted);
10599
10600                   when others =>
10601                      Error_Pragma_Arg ("invalid license name", Arg1);
10602                end case;
10603             end;
10604
10605          ---------------
10606          -- Link_With --
10607          ---------------
10608
10609          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10610
10611          when Pragma_Link_With => Link_With : declare
10612             Arg : Node_Id;
10613
10614          begin
10615             GNAT_Pragma;
10616
10617             if Operating_Mode = Generate_Code
10618               and then In_Extended_Main_Source_Unit (N)
10619             then
10620                Check_At_Least_N_Arguments (1);
10621                Check_No_Identifiers;
10622                Check_Is_In_Decl_Part_Or_Package_Spec;
10623                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10624                Start_String;
10625
10626                Arg := Arg1;
10627                while Present (Arg) loop
10628                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10629
10630                   --  Store argument, converting sequences of spaces to a
10631                   --  single null character (this is one of the differences
10632                   --  in processing between Link_With and Linker_Options).
10633
10634                   Arg_Store : declare
10635                      C : constant Char_Code := Get_Char_Code (' ');
10636                      S : constant String_Id :=
10637                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10638                      L : constant Nat := String_Length (S);
10639                      F : Nat := 1;
10640
10641                      procedure Skip_Spaces;
10642                      --  Advance F past any spaces
10643
10644                      -----------------
10645                      -- Skip_Spaces --
10646                      -----------------
10647
10648                      procedure Skip_Spaces is
10649                      begin
10650                         while F <= L and then Get_String_Char (S, F) = C loop
10651                            F := F + 1;
10652                         end loop;
10653                      end Skip_Spaces;
10654
10655                   --  Start of processing for Arg_Store
10656
10657                   begin
10658                      Skip_Spaces; -- skip leading spaces
10659
10660                      --  Loop through characters, changing any embedded
10661                      --  sequence of spaces to a single null character (this
10662                      --  is how Link_With/Linker_Options differ)
10663
10664                      while F <= L loop
10665                         if Get_String_Char (S, F) = C then
10666                            Skip_Spaces;
10667                            exit when F > L;
10668                            Store_String_Char (ASCII.NUL);
10669
10670                         else
10671                            Store_String_Char (Get_String_Char (S, F));
10672                            F := F + 1;
10673                         end if;
10674                      end loop;
10675                   end Arg_Store;
10676
10677                   Arg := Next (Arg);
10678
10679                   if Present (Arg) then
10680                      Store_String_Char (ASCII.NUL);
10681                   end if;
10682                end loop;
10683
10684                Store_Linker_Option_String (End_String);
10685             end if;
10686          end Link_With;
10687
10688          ------------------
10689          -- Linker_Alias --
10690          ------------------
10691
10692          --  pragma Linker_Alias (
10693          --      [Entity =>]  LOCAL_NAME
10694          --      [Target =>]  static_string_EXPRESSION);
10695
10696          when Pragma_Linker_Alias =>
10697             GNAT_Pragma;
10698             Check_Arg_Order ((Name_Entity, Name_Target));
10699             Check_Arg_Count (2);
10700             Check_Optional_Identifier (Arg1, Name_Entity);
10701             Check_Optional_Identifier (Arg2, Name_Target);
10702             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10703             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10704
10705             --  The only processing required is to link this item on to the
10706             --  list of rep items for the given entity. This is accomplished
10707             --  by the call to Rep_Item_Too_Late (when no error is detected
10708             --  and False is returned).
10709
10710             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10711                return;
10712             else
10713                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10714             end if;
10715
10716          ------------------------
10717          -- Linker_Constructor --
10718          ------------------------
10719
10720          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10721
10722          --  Code is shared with Linker_Destructor
10723
10724          -----------------------
10725          -- Linker_Destructor --
10726          -----------------------
10727
10728          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10729
10730          when Pragma_Linker_Constructor |
10731               Pragma_Linker_Destructor =>
10732          Linker_Constructor : declare
10733             Arg1_X : Node_Id;
10734             Proc   : Entity_Id;
10735
10736          begin
10737             GNAT_Pragma;
10738             Check_Arg_Count (1);
10739             Check_No_Identifiers;
10740             Check_Arg_Is_Local_Name (Arg1);
10741             Arg1_X := Get_Pragma_Arg (Arg1);
10742             Analyze (Arg1_X);
10743             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10744
10745             if not Is_Library_Level_Entity (Proc) then
10746                Error_Pragma_Arg
10747                 ("argument for pragma% must be library level entity", Arg1);
10748             end if;
10749
10750             --  The only processing required is to link this item on to the
10751             --  list of rep items for the given entity. This is accomplished
10752             --  by the call to Rep_Item_Too_Late (when no error is detected
10753             --  and False is returned).
10754
10755             if Rep_Item_Too_Late (Proc, N) then
10756                return;
10757             else
10758                Set_Has_Gigi_Rep_Item (Proc);
10759             end if;
10760          end Linker_Constructor;
10761
10762          --------------------
10763          -- Linker_Options --
10764          --------------------
10765
10766          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10767
10768          when Pragma_Linker_Options => Linker_Options : declare
10769             Arg : Node_Id;
10770
10771          begin
10772             Check_Ada_83_Warning;
10773             Check_No_Identifiers;
10774             Check_Arg_Count (1);
10775             Check_Is_In_Decl_Part_Or_Package_Spec;
10776             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10777             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10778
10779             Arg := Arg2;
10780             while Present (Arg) loop
10781                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10782                Store_String_Char (ASCII.NUL);
10783                Store_String_Chars
10784                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10785                Arg := Next (Arg);
10786             end loop;
10787
10788             if Operating_Mode = Generate_Code
10789               and then In_Extended_Main_Source_Unit (N)
10790             then
10791                Store_Linker_Option_String (End_String);
10792             end if;
10793          end Linker_Options;
10794
10795          --------------------
10796          -- Linker_Section --
10797          --------------------
10798
10799          --  pragma Linker_Section (
10800          --      [Entity  =>]  LOCAL_NAME
10801          --      [Section =>]  static_string_EXPRESSION);
10802
10803          when Pragma_Linker_Section =>
10804             GNAT_Pragma;
10805             Check_Arg_Order ((Name_Entity, Name_Section));
10806             Check_Arg_Count (2);
10807             Check_Optional_Identifier (Arg1, Name_Entity);
10808             Check_Optional_Identifier (Arg2, Name_Section);
10809             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10810             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10811
10812             --  This pragma applies only to objects
10813
10814             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10815                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10816             end if;
10817
10818             --  The only processing required is to link this item on to the
10819             --  list of rep items for the given entity. This is accomplished
10820             --  by the call to Rep_Item_Too_Late (when no error is detected
10821             --  and False is returned).
10822
10823             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10824                return;
10825             else
10826                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10827             end if;
10828
10829          ----------
10830          -- List --
10831          ----------
10832
10833          --  pragma List (On | Off)
10834
10835          --  There is nothing to do here, since we did all the processing for
10836          --  this pragma in Par.Prag (so that it works properly even in syntax
10837          --  only mode).
10838
10839          when Pragma_List =>
10840             null;
10841
10842          --------------------
10843          -- Locking_Policy --
10844          --------------------
10845
10846          --  pragma Locking_Policy (policy_IDENTIFIER);
10847
10848          when Pragma_Locking_Policy => declare
10849             LP : Character;
10850
10851          begin
10852             Check_Ada_83_Warning;
10853             Check_Arg_Count (1);
10854             Check_No_Identifiers;
10855             Check_Arg_Is_Locking_Policy (Arg1);
10856             Check_Valid_Configuration_Pragma;
10857             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10858             LP := Fold_Upper (Name_Buffer (1));
10859
10860             if Locking_Policy /= ' '
10861               and then Locking_Policy /= LP
10862             then
10863                Error_Msg_Sloc := Locking_Policy_Sloc;
10864                Error_Pragma ("locking policy incompatible with policy#");
10865
10866             --  Set new policy, but always preserve System_Location since we
10867             --  like the error message with the run time name.
10868
10869             else
10870                Locking_Policy := LP;
10871
10872                if Locking_Policy_Sloc /= System_Location then
10873                   Locking_Policy_Sloc := Loc;
10874                end if;
10875             end if;
10876          end;
10877
10878          ----------------
10879          -- Long_Float --
10880          ----------------
10881
10882          --  pragma Long_Float (D_Float | G_Float);
10883
10884          when Pragma_Long_Float =>
10885             GNAT_Pragma;
10886             Check_Valid_Configuration_Pragma;
10887             Check_Arg_Count (1);
10888             Check_No_Identifier (Arg1);
10889             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10890
10891             if not OpenVMS_On_Target then
10892                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10893             end if;
10894
10895             --  D_Float case
10896
10897             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10898                if Opt.Float_Format_Long = 'G' then
10899                   Error_Pragma ("G_Float previously specified");
10900                end if;
10901
10902                Opt.Float_Format_Long := 'D';
10903
10904             --  G_Float case (this is the default, does not need overriding)
10905
10906             else
10907                if Opt.Float_Format_Long = 'D' then
10908                   Error_Pragma ("D_Float previously specified");
10909                end if;
10910
10911                Opt.Float_Format_Long := 'G';
10912             end if;
10913
10914             Set_Standard_Fpt_Formats;
10915
10916          -----------------------
10917          -- Machine_Attribute --
10918          -----------------------
10919
10920          --  pragma Machine_Attribute (
10921          --       [Entity         =>] LOCAL_NAME,
10922          --       [Attribute_Name =>] static_string_EXPRESSION
10923          --    [, [Info           =>] static_EXPRESSION] );
10924
10925          when Pragma_Machine_Attribute => Machine_Attribute : declare
10926             Def_Id : Entity_Id;
10927
10928          begin
10929             GNAT_Pragma;
10930             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10931
10932             if Arg_Count = 3 then
10933                Check_Optional_Identifier (Arg3, Name_Info);
10934                Check_Arg_Is_Static_Expression (Arg3);
10935             else
10936                Check_Arg_Count (2);
10937             end if;
10938
10939             Check_Optional_Identifier (Arg1, Name_Entity);
10940             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10941             Check_Arg_Is_Local_Name (Arg1);
10942             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10943             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10944
10945             if Is_Access_Type (Def_Id) then
10946                Def_Id := Designated_Type (Def_Id);
10947             end if;
10948
10949             if Rep_Item_Too_Early (Def_Id, N) then
10950                return;
10951             end if;
10952
10953             Def_Id := Underlying_Type (Def_Id);
10954
10955             --  The only processing required is to link this item on to the
10956             --  list of rep items for the given entity. This is accomplished
10957             --  by the call to Rep_Item_Too_Late (when no error is detected
10958             --  and False is returned).
10959
10960             if Rep_Item_Too_Late (Def_Id, N) then
10961                return;
10962             else
10963                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10964             end if;
10965          end Machine_Attribute;
10966
10967          ----------
10968          -- Main --
10969          ----------
10970
10971          --  pragma Main
10972          --   (MAIN_OPTION [, MAIN_OPTION]);
10973
10974          --  MAIN_OPTION ::=
10975          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10976          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10977          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10978
10979          when Pragma_Main => Main : declare
10980             Args  : Args_List (1 .. 3);
10981             Names : constant Name_List (1 .. 3) := (
10982                       Name_Stack_Size,
10983                       Name_Task_Stack_Size_Default,
10984                       Name_Time_Slicing_Enabled);
10985
10986             Nod : Node_Id;
10987
10988          begin
10989             GNAT_Pragma;
10990             Gather_Associations (Names, Args);
10991
10992             for J in 1 .. 2 loop
10993                if Present (Args (J)) then
10994                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10995                end if;
10996             end loop;
10997
10998             if Present (Args (3)) then
10999                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
11000             end if;
11001
11002             Nod := Next (N);
11003             while Present (Nod) loop
11004                if Nkind (Nod) = N_Pragma
11005                  and then Pragma_Name (Nod) = Name_Main
11006                then
11007                   Error_Msg_Name_1 := Pname;
11008                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11009                end if;
11010
11011                Next (Nod);
11012             end loop;
11013          end Main;
11014
11015          ------------------
11016          -- Main_Storage --
11017          ------------------
11018
11019          --  pragma Main_Storage
11020          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
11021
11022          --  MAIN_STORAGE_OPTION ::=
11023          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
11024          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
11025
11026          when Pragma_Main_Storage => Main_Storage : declare
11027             Args  : Args_List (1 .. 2);
11028             Names : constant Name_List (1 .. 2) := (
11029                       Name_Working_Storage,
11030                       Name_Top_Guard);
11031
11032             Nod : Node_Id;
11033
11034          begin
11035             GNAT_Pragma;
11036             Gather_Associations (Names, Args);
11037
11038             for J in 1 .. 2 loop
11039                if Present (Args (J)) then
11040                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
11041                end if;
11042             end loop;
11043
11044             Check_In_Main_Program;
11045
11046             Nod := Next (N);
11047             while Present (Nod) loop
11048                if Nkind (Nod) = N_Pragma
11049                  and then Pragma_Name (Nod) = Name_Main_Storage
11050                then
11051                   Error_Msg_Name_1 := Pname;
11052                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
11053                end if;
11054
11055                Next (Nod);
11056             end loop;
11057          end Main_Storage;
11058
11059          -----------------
11060          -- Memory_Size --
11061          -----------------
11062
11063          --  pragma Memory_Size (NUMERIC_LITERAL)
11064
11065          when Pragma_Memory_Size =>
11066             GNAT_Pragma;
11067
11068             --  Memory size is simply ignored
11069
11070             Check_No_Identifiers;
11071             Check_Arg_Count (1);
11072             Check_Arg_Is_Integer_Literal (Arg1);
11073
11074          -------------
11075          -- No_Body --
11076          -------------
11077
11078          --  pragma No_Body;
11079
11080          --  The only correct use of this pragma is on its own in a file, in
11081          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
11082          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
11083          --  check for a file containing nothing but a No_Body pragma). If we
11084          --  attempt to process it during normal semantics processing, it means
11085          --  it was misplaced.
11086
11087          when Pragma_No_Body =>
11088             GNAT_Pragma;
11089             Pragma_Misplaced;
11090
11091          ---------------
11092          -- No_Return --
11093          ---------------
11094
11095          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
11096
11097          when Pragma_No_Return => No_Return : declare
11098             Id    : Node_Id;
11099             E     : Entity_Id;
11100             Found : Boolean;
11101             Arg   : Node_Id;
11102
11103          begin
11104             Ada_2005_Pragma;
11105             Check_At_Least_N_Arguments (1);
11106
11107             --  Loop through arguments of pragma
11108
11109             Arg := Arg1;
11110             while Present (Arg) loop
11111                Check_Arg_Is_Local_Name (Arg);
11112                Id := Get_Pragma_Arg (Arg);
11113                Analyze (Id);
11114
11115                if not Is_Entity_Name (Id) then
11116                   Error_Pragma_Arg ("entity name required", Arg);
11117                end if;
11118
11119                if Etype (Id) = Any_Type then
11120                   raise Pragma_Exit;
11121                end if;
11122
11123                --  Loop to find matching procedures
11124
11125                E := Entity (Id);
11126                Found := False;
11127                while Present (E)
11128                  and then Scope (E) = Current_Scope
11129                loop
11130                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
11131                      Set_No_Return (E);
11132
11133                      --  Set flag on any alias as well
11134
11135                      if Is_Overloadable (E) and then Present (Alias (E)) then
11136                         Set_No_Return (Alias (E));
11137                      end if;
11138
11139                      Found := True;
11140                   end if;
11141
11142                   exit when From_Aspect_Specification (N);
11143                   E := Homonym (E);
11144                end loop;
11145
11146                if not Found then
11147                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
11148                end if;
11149
11150                Next (Arg);
11151             end loop;
11152          end No_Return;
11153
11154          -----------------
11155          -- No_Run_Time --
11156          -----------------
11157
11158          --  pragma No_Run_Time;
11159
11160          --  Note: this pragma is retained for backwards compatibility. See
11161          --  body of Rtsfind for full details on its handling.
11162
11163          when Pragma_No_Run_Time =>
11164             GNAT_Pragma;
11165             Check_Valid_Configuration_Pragma;
11166             Check_Arg_Count (0);
11167
11168             No_Run_Time_Mode           := True;
11169             Configurable_Run_Time_Mode := True;
11170
11171             --  Set Duration to 32 bits if word size is 32
11172
11173             if Ttypes.System_Word_Size = 32 then
11174                Duration_32_Bits_On_Target := True;
11175             end if;
11176
11177             --  Set appropriate restrictions
11178
11179             Set_Restriction (No_Finalization, N);
11180             Set_Restriction (No_Exception_Handlers, N);
11181             Set_Restriction (Max_Tasks, N, 0);
11182             Set_Restriction (No_Tasking, N);
11183
11184          ------------------------
11185          -- No_Strict_Aliasing --
11186          ------------------------
11187
11188          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
11189
11190          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
11191             E_Id : Entity_Id;
11192
11193          begin
11194             GNAT_Pragma;
11195             Check_At_Most_N_Arguments (1);
11196
11197             if Arg_Count = 0 then
11198                Check_Valid_Configuration_Pragma;
11199                Opt.No_Strict_Aliasing := True;
11200
11201             else
11202                Check_Optional_Identifier (Arg2, Name_Entity);
11203                Check_Arg_Is_Local_Name (Arg1);
11204                E_Id := Entity (Get_Pragma_Arg (Arg1));
11205
11206                if E_Id = Any_Type then
11207                   return;
11208                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
11209                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
11210                end if;
11211
11212                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
11213             end if;
11214          end No_Strict_Aliasing;
11215
11216          -----------------------
11217          -- Normalize_Scalars --
11218          -----------------------
11219
11220          --  pragma Normalize_Scalars;
11221
11222          when Pragma_Normalize_Scalars =>
11223             Check_Ada_83_Warning;
11224             Check_Arg_Count (0);
11225             Check_Valid_Configuration_Pragma;
11226
11227             --  Normalize_Scalars creates false positives in CodePeer, and
11228             --  incorrect negative results in Alfa mode, so ignore this pragma
11229             --  in these modes.
11230
11231             if not (CodePeer_Mode or Alfa_Mode) then
11232                Normalize_Scalars := True;
11233                Init_Or_Norm_Scalars := True;
11234             end if;
11235
11236          -----------------
11237          -- Obsolescent --
11238          -----------------
11239
11240          --  pragma Obsolescent;
11241
11242          --  pragma Obsolescent (
11243          --    [Message =>] static_string_EXPRESSION
11244          --  [,[Version =>] Ada_05]]);
11245
11246          --  pragma Obsolescent (
11247          --    [Entity  =>] NAME
11248          --  [,[Message =>] static_string_EXPRESSION
11249          --  [,[Version =>] Ada_05]] );
11250
11251          when Pragma_Obsolescent => Obsolescent : declare
11252             Ename : Node_Id;
11253             Decl  : Node_Id;
11254
11255             procedure Set_Obsolescent (E : Entity_Id);
11256             --  Given an entity Ent, mark it as obsolescent if appropriate
11257
11258             ---------------------
11259             -- Set_Obsolescent --
11260             ---------------------
11261
11262             procedure Set_Obsolescent (E : Entity_Id) is
11263                Active : Boolean;
11264                Ent    : Entity_Id;
11265                S      : String_Id;
11266
11267             begin
11268                Active := True;
11269                Ent    := E;
11270
11271                --  Entity name was given
11272
11273                if Present (Ename) then
11274
11275                   --  If entity name matches, we are fine. Save entity in
11276                   --  pragma argument, for ASIS use.
11277
11278                   if Chars (Ename) = Chars (Ent) then
11279                      Set_Entity (Ename, Ent);
11280                      Generate_Reference (Ent, Ename);
11281
11282                   --  If entity name does not match, only possibility is an
11283                   --  enumeration literal from an enumeration type declaration.
11284
11285                   elsif Ekind (Ent) /= E_Enumeration_Type then
11286                      Error_Pragma
11287                        ("pragma % entity name does not match declaration");
11288
11289                   else
11290                      Ent := First_Literal (E);
11291                      loop
11292                         if No (Ent) then
11293                            Error_Pragma
11294                              ("pragma % entity name does not match any " &
11295                               "enumeration literal");
11296
11297                         elsif Chars (Ent) = Chars (Ename) then
11298                            Set_Entity (Ename, Ent);
11299                            Generate_Reference (Ent, Ename);
11300                            exit;
11301
11302                         else
11303                            Ent := Next_Literal (Ent);
11304                         end if;
11305                      end loop;
11306                   end if;
11307                end if;
11308
11309                --  Ent points to entity to be marked
11310
11311                if Arg_Count >= 1 then
11312
11313                   --  Deal with static string argument
11314
11315                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11316                   S := Strval (Get_Pragma_Arg (Arg1));
11317
11318                   for J in 1 .. String_Length (S) loop
11319                      if not In_Character_Range (Get_String_Char (S, J)) then
11320                         Error_Pragma_Arg
11321                           ("pragma% argument does not allow wide characters",
11322                            Arg1);
11323                      end if;
11324                   end loop;
11325
11326                   Obsolescent_Warnings.Append
11327                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11328
11329                   --  Check for Ada_05 parameter
11330
11331                   if Arg_Count /= 1 then
11332                      Check_Arg_Count (2);
11333
11334                      declare
11335                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11336
11337                      begin
11338                         Check_Arg_Is_Identifier (Argx);
11339
11340                         if Chars (Argx) /= Name_Ada_05 then
11341                            Error_Msg_Name_2 := Name_Ada_05;
11342                            Error_Pragma_Arg
11343                              ("only allowed argument for pragma% is %", Argx);
11344                         end if;
11345
11346                         if Ada_Version_Explicit < Ada_2005
11347                           or else not Warn_On_Ada_2005_Compatibility
11348                         then
11349                            Active := False;
11350                         end if;
11351                      end;
11352                   end if;
11353                end if;
11354
11355                --  Set flag if pragma active
11356
11357                if Active then
11358                   Set_Is_Obsolescent (Ent);
11359                end if;
11360
11361                return;
11362             end Set_Obsolescent;
11363
11364          --  Start of processing for pragma Obsolescent
11365
11366          begin
11367             GNAT_Pragma;
11368
11369             Check_At_Most_N_Arguments (3);
11370
11371             --  See if first argument specifies an entity name
11372
11373             if Arg_Count >= 1
11374               and then
11375                 (Chars (Arg1) = Name_Entity
11376                    or else
11377                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11378                                                       N_Identifier,
11379                                                       N_Operator_Symbol))
11380             then
11381                Ename := Get_Pragma_Arg (Arg1);
11382
11383                --  Eliminate first argument, so we can share processing
11384
11385                Arg1 := Arg2;
11386                Arg2 := Arg3;
11387                Arg_Count := Arg_Count - 1;
11388
11389             --  No Entity name argument given
11390
11391             else
11392                Ename := Empty;
11393             end if;
11394
11395             if Arg_Count >= 1 then
11396                Check_Optional_Identifier (Arg1, Name_Message);
11397
11398                if Arg_Count = 2 then
11399                   Check_Optional_Identifier (Arg2, Name_Version);
11400                end if;
11401             end if;
11402
11403             --  Get immediately preceding declaration
11404
11405             Decl := Prev (N);
11406             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11407                Prev (Decl);
11408             end loop;
11409
11410             --  Cases where we do not follow anything other than another pragma
11411
11412             if No (Decl) then
11413
11414                --  First case: library level compilation unit declaration with
11415                --  the pragma immediately following the declaration.
11416
11417                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11418                   Set_Obsolescent
11419                     (Defining_Entity (Unit (Parent (Parent (N)))));
11420                   return;
11421
11422                --  Case 2: library unit placement for package
11423
11424                else
11425                   declare
11426                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11427                   begin
11428                      if Is_Package_Or_Generic_Package (Ent) then
11429                         Set_Obsolescent (Ent);
11430                         return;
11431                      end if;
11432                   end;
11433                end if;
11434
11435             --  Cases where we must follow a declaration
11436
11437             else
11438                if         Nkind (Decl) not in N_Declaration
11439                  and then Nkind (Decl) not in N_Later_Decl_Item
11440                  and then Nkind (Decl) not in N_Generic_Declaration
11441                  and then Nkind (Decl) not in N_Renaming_Declaration
11442                then
11443                   Error_Pragma
11444                     ("pragma% misplaced, "
11445                      & "must immediately follow a declaration");
11446
11447                else
11448                   Set_Obsolescent (Defining_Entity (Decl));
11449                   return;
11450                end if;
11451             end if;
11452          end Obsolescent;
11453
11454          --------------
11455          -- Optimize --
11456          --------------
11457
11458          --  pragma Optimize (Time | Space | Off);
11459
11460          --  The actual check for optimize is done in Gigi. Note that this
11461          --  pragma does not actually change the optimization setting, it
11462          --  simply checks that it is consistent with the pragma.
11463
11464          when Pragma_Optimize =>
11465             Check_No_Identifiers;
11466             Check_Arg_Count (1);
11467             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11468
11469          ------------------------
11470          -- Optimize_Alignment --
11471          ------------------------
11472
11473          --  pragma Optimize_Alignment (Time | Space | Off);
11474
11475          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11476             GNAT_Pragma;
11477             Check_No_Identifiers;
11478             Check_Arg_Count (1);
11479             Check_Valid_Configuration_Pragma;
11480
11481             declare
11482                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11483             begin
11484                case Nam is
11485                   when Name_Time =>
11486                      Opt.Optimize_Alignment := 'T';
11487                   when Name_Space =>
11488                      Opt.Optimize_Alignment := 'S';
11489                   when Name_Off =>
11490                      Opt.Optimize_Alignment := 'O';
11491                   when others =>
11492                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11493                end case;
11494             end;
11495
11496             --  Set indication that mode is set locally. If we are in fact in a
11497             --  configuration pragma file, this setting is harmless since the
11498             --  switch will get reset anyway at the start of each unit.
11499
11500             Optimize_Alignment_Local := True;
11501          end Optimize_Alignment;
11502
11503          -------------
11504          -- Ordered --
11505          -------------
11506
11507          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11508
11509          when Pragma_Ordered => Ordered : declare
11510             Assoc   : constant Node_Id := Arg1;
11511             Type_Id : Node_Id;
11512             Typ     : Entity_Id;
11513
11514          begin
11515             GNAT_Pragma;
11516             Check_No_Identifiers;
11517             Check_Arg_Count (1);
11518             Check_Arg_Is_Local_Name (Arg1);
11519
11520             Type_Id := Get_Pragma_Arg (Assoc);
11521             Find_Type (Type_Id);
11522             Typ := Entity (Type_Id);
11523
11524             if Typ = Any_Type then
11525                return;
11526             else
11527                Typ := Underlying_Type (Typ);
11528             end if;
11529
11530             if not Is_Enumeration_Type (Typ) then
11531                Error_Pragma ("pragma% must specify enumeration type");
11532             end if;
11533
11534             Check_First_Subtype (Arg1);
11535             Set_Has_Pragma_Ordered (Base_Type (Typ));
11536          end Ordered;
11537
11538          ----------
11539          -- Pack --
11540          ----------
11541
11542          --  pragma Pack (first_subtype_LOCAL_NAME);
11543
11544          when Pragma_Pack => Pack : declare
11545             Assoc   : constant Node_Id := Arg1;
11546             Type_Id : Node_Id;
11547             Typ     : Entity_Id;
11548             Ctyp    : Entity_Id;
11549             Ignore  : Boolean := False;
11550
11551          begin
11552             Check_No_Identifiers;
11553             Check_Arg_Count (1);
11554             Check_Arg_Is_Local_Name (Arg1);
11555
11556             Type_Id := Get_Pragma_Arg (Assoc);
11557             Find_Type (Type_Id);
11558             Typ := Entity (Type_Id);
11559
11560             if Typ = Any_Type
11561               or else Rep_Item_Too_Early (Typ, N)
11562             then
11563                return;
11564             else
11565                Typ := Underlying_Type (Typ);
11566             end if;
11567
11568             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11569                Error_Pragma ("pragma% must specify array or record type");
11570             end if;
11571
11572             Check_First_Subtype (Arg1);
11573             Check_Duplicate_Pragma (Typ);
11574
11575             --  Array type
11576
11577             if Is_Array_Type (Typ) then
11578                Ctyp := Component_Type (Typ);
11579
11580                --  Ignore pack that does nothing
11581
11582                if Known_Static_Esize (Ctyp)
11583                  and then Known_Static_RM_Size (Ctyp)
11584                  and then Esize (Ctyp) = RM_Size (Ctyp)
11585                  and then Addressable (Esize (Ctyp))
11586                then
11587                   Ignore := True;
11588                end if;
11589
11590                --  Process OK pragma Pack. Note that if there is a separate
11591                --  component clause present, the Pack will be cancelled. This
11592                --  processing is in Freeze.
11593
11594                if not Rep_Item_Too_Late (Typ, N) then
11595
11596                   --  In the context of static code analysis, we do not need
11597                   --  complex front-end expansions related to pragma Pack,
11598                   --  so disable handling of pragma Pack in these cases.
11599
11600                   if CodePeer_Mode or Alfa_Mode then
11601                      null;
11602
11603                   --  Don't attempt any packing for VM targets. We possibly
11604                   --  could deal with some cases of array bit-packing, but we
11605                   --  don't bother, since this is not a typical kind of
11606                   --  representation in the VM context anyway (and would not
11607                   --  for example work nicely with the debugger).
11608
11609                   elsif VM_Target /= No_VM then
11610                      if not GNAT_Mode then
11611                         Error_Pragma
11612                           ("?pragma% ignored in this configuration");
11613                      end if;
11614
11615                   --  Normal case where we do the pack action
11616
11617                   else
11618                      if not Ignore then
11619                         Set_Is_Packed            (Base_Type (Typ));
11620                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11621                      end if;
11622
11623                      Set_Has_Pragma_Pack (Base_Type (Typ));
11624                   end if;
11625                end if;
11626
11627             --  For record types, the pack is always effective
11628
11629             else pragma Assert (Is_Record_Type (Typ));
11630                if not Rep_Item_Too_Late (Typ, N) then
11631
11632                   --  Ignore pack request with warning in VM mode (skip warning
11633                   --  if we are compiling GNAT run time library).
11634
11635                   if VM_Target /= No_VM then
11636                      if not GNAT_Mode then
11637                         Error_Pragma
11638                           ("?pragma% ignored in this configuration");
11639                      end if;
11640
11641                   --  Normal case of pack request active
11642
11643                   else
11644                      Set_Is_Packed            (Base_Type (Typ));
11645                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11646                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11647                   end if;
11648                end if;
11649             end if;
11650          end Pack;
11651
11652          ----------
11653          -- Page --
11654          ----------
11655
11656          --  pragma Page;
11657
11658          --  There is nothing to do here, since we did all the processing for
11659          --  this pragma in Par.Prag (so that it works properly even in syntax
11660          --  only mode).
11661
11662          when Pragma_Page =>
11663             null;
11664
11665          -------------
11666          -- Passive --
11667          -------------
11668
11669          --  pragma Passive [(PASSIVE_FORM)];
11670
11671          --  PASSIVE_FORM ::= Semaphore | No
11672
11673          when Pragma_Passive =>
11674             GNAT_Pragma;
11675
11676             if Nkind (Parent (N)) /= N_Task_Definition then
11677                Error_Pragma ("pragma% must be within task definition");
11678             end if;
11679
11680             if Arg_Count /= 0 then
11681                Check_Arg_Count (1);
11682                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11683             end if;
11684
11685          ----------------------------------
11686          -- Preelaborable_Initialization --
11687          ----------------------------------
11688
11689          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11690
11691          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11692             Ent : Entity_Id;
11693
11694          begin
11695             Ada_2005_Pragma;
11696             Check_Arg_Count (1);
11697             Check_No_Identifiers;
11698             Check_Arg_Is_Identifier (Arg1);
11699             Check_Arg_Is_Local_Name (Arg1);
11700             Check_First_Subtype (Arg1);
11701             Ent := Entity (Get_Pragma_Arg (Arg1));
11702
11703             if not (Is_Private_Type (Ent)
11704                       or else
11705                     Is_Protected_Type (Ent)
11706                       or else
11707                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11708             then
11709                Error_Pragma_Arg
11710                  ("pragma % can only be applied to private, formal derived or "
11711                   & "protected type",
11712                   Arg1);
11713             end if;
11714
11715             --  Give an error if the pragma is applied to a protected type that
11716             --  does not qualify (due to having entries, or due to components
11717             --  that do not qualify).
11718
11719             if Is_Protected_Type (Ent)
11720               and then not Has_Preelaborable_Initialization (Ent)
11721             then
11722                Error_Msg_N
11723                  ("protected type & does not have preelaborable " &
11724                   "initialization", Ent);
11725
11726             --  Otherwise mark the type as definitely having preelaborable
11727             --  initialization.
11728
11729             else
11730                Set_Known_To_Have_Preelab_Init (Ent);
11731             end if;
11732
11733             if Has_Pragma_Preelab_Init (Ent)
11734               and then Warn_On_Redundant_Constructs
11735             then
11736                Error_Pragma ("?duplicate pragma%!");
11737             else
11738                Set_Has_Pragma_Preelab_Init (Ent);
11739             end if;
11740          end Preelab_Init;
11741
11742          --------------------
11743          -- Persistent_BSS --
11744          --------------------
11745
11746          --  pragma Persistent_BSS [(object_NAME)];
11747
11748          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11749             Decl : Node_Id;
11750             Ent  : Entity_Id;
11751             Prag : Node_Id;
11752
11753          begin
11754             GNAT_Pragma;
11755             Check_At_Most_N_Arguments (1);
11756
11757             --  Case of application to specific object (one argument)
11758
11759             if Arg_Count = 1 then
11760                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11761
11762                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11763                  or else not
11764                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11765                                                             E_Constant)
11766                then
11767                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11768                end if;
11769
11770                Ent := Entity (Get_Pragma_Arg (Arg1));
11771                Decl := Parent (Ent);
11772
11773                if Rep_Item_Too_Late (Ent, N) then
11774                   return;
11775                end if;
11776
11777                if Present (Expression (Decl)) then
11778                   Error_Pragma_Arg
11779                     ("object for pragma% cannot have initialization", Arg1);
11780                end if;
11781
11782                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11783                   Error_Pragma_Arg
11784                     ("object type for pragma% is not potentially persistent",
11785                      Arg1);
11786                end if;
11787
11788                Check_Duplicate_Pragma (Ent);
11789
11790                Prag :=
11791                  Make_Linker_Section_Pragma
11792                    (Ent, Sloc (N), ".persistent.bss");
11793                Insert_After (N, Prag);
11794                Analyze (Prag);
11795
11796             --  Case of use as configuration pragma with no arguments
11797
11798             else
11799                Check_Valid_Configuration_Pragma;
11800                Persistent_BSS_Mode := True;
11801             end if;
11802          end Persistent_BSS;
11803
11804          -------------
11805          -- Polling --
11806          -------------
11807
11808          --  pragma Polling (ON | OFF);
11809
11810          when Pragma_Polling =>
11811             GNAT_Pragma;
11812             Check_Arg_Count (1);
11813             Check_No_Identifiers;
11814             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11815             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11816
11817          -------------------
11818          -- Postcondition --
11819          -------------------
11820
11821          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11822          --                      [,[Message =>] String_EXPRESSION]);
11823
11824          when Pragma_Postcondition => Postcondition : declare
11825             In_Body : Boolean;
11826             pragma Warnings (Off, In_Body);
11827
11828          begin
11829             GNAT_Pragma;
11830             Check_At_Least_N_Arguments (1);
11831             Check_At_Most_N_Arguments (2);
11832             Check_Optional_Identifier (Arg1, Name_Check);
11833
11834             --  All we need to do here is call the common check procedure,
11835             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11836
11837             Check_Precondition_Postcondition (In_Body);
11838          end Postcondition;
11839
11840          ------------------
11841          -- Precondition --
11842          ------------------
11843
11844          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11845          --                     [,[Message =>] String_EXPRESSION]);
11846
11847          when Pragma_Precondition => Precondition : declare
11848             In_Body : Boolean;
11849
11850          begin
11851             GNAT_Pragma;
11852             Check_At_Least_N_Arguments (1);
11853             Check_At_Most_N_Arguments (2);
11854             Check_Optional_Identifier (Arg1, Name_Check);
11855             Check_Precondition_Postcondition (In_Body);
11856
11857             --  If in spec, nothing more to do. If in body, then we convert the
11858             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11859             --  this whether or not precondition checks are enabled. That works
11860             --  fine since pragma Check will do this check, and will also
11861             --  analyze the condition itself in the proper context.
11862
11863             if In_Body then
11864                Rewrite (N,
11865                  Make_Pragma (Loc,
11866                    Chars => Name_Check,
11867                    Pragma_Argument_Associations => New_List (
11868                      Make_Pragma_Argument_Association (Loc,
11869                        Expression => Make_Identifier (Loc, Name_Precondition)),
11870
11871                      Make_Pragma_Argument_Association (Sloc (Arg1),
11872                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11873
11874                if Arg_Count = 2 then
11875                   Append_To (Pragma_Argument_Associations (N),
11876                     Make_Pragma_Argument_Association (Sloc (Arg2),
11877                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11878                end if;
11879
11880                Analyze (N);
11881             end if;
11882          end Precondition;
11883
11884          ---------------
11885          -- Predicate --
11886          ---------------
11887
11888          --  pragma Predicate
11889          --    ([Entity =>] type_LOCAL_NAME,
11890          --     [Check  =>] EXPRESSION);
11891
11892          when Pragma_Predicate => Predicate : declare
11893             Type_Id : Node_Id;
11894             Typ     : Entity_Id;
11895
11896             Discard : Boolean;
11897             pragma Unreferenced (Discard);
11898
11899          begin
11900             GNAT_Pragma;
11901             Check_Arg_Count (2);
11902             Check_Optional_Identifier (Arg1, Name_Entity);
11903             Check_Optional_Identifier (Arg2, Name_Check);
11904
11905             Check_Arg_Is_Local_Name (Arg1);
11906
11907             Type_Id := Get_Pragma_Arg (Arg1);
11908             Find_Type (Type_Id);
11909             Typ := Entity (Type_Id);
11910
11911             if Typ = Any_Type then
11912                return;
11913             end if;
11914
11915             --  The remaining processing is simply to link the pragma on to
11916             --  the rep item chain, for processing when the type is frozen.
11917             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11918             --  mark the type as having predicates.
11919
11920             Set_Has_Predicates (Typ);
11921             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11922          end Predicate;
11923
11924          ------------------
11925          -- Preelaborate --
11926          ------------------
11927
11928          --  pragma Preelaborate [(library_unit_NAME)];
11929
11930          --  Set the flag Is_Preelaborated of program unit name entity
11931
11932          when Pragma_Preelaborate => Preelaborate : declare
11933             Pa  : constant Node_Id   := Parent (N);
11934             Pk  : constant Node_Kind := Nkind (Pa);
11935             Ent : Entity_Id;
11936
11937          begin
11938             Check_Ada_83_Warning;
11939             Check_Valid_Library_Unit_Pragma;
11940
11941             if Nkind (N) = N_Null_Statement then
11942                return;
11943             end if;
11944
11945             Ent := Find_Lib_Unit_Name;
11946             Check_Duplicate_Pragma (Ent);
11947
11948             --  This filters out pragmas inside generic parent then
11949             --  show up inside instantiation
11950
11951             if Present (Ent)
11952               and then not (Pk = N_Package_Specification
11953                              and then Present (Generic_Parent (Pa)))
11954             then
11955                if not Debug_Flag_U then
11956                   Set_Is_Preelaborated (Ent);
11957                   Set_Suppress_Elaboration_Warnings (Ent);
11958                end if;
11959             end if;
11960          end Preelaborate;
11961
11962          ---------------------
11963          -- Preelaborate_05 --
11964          ---------------------
11965
11966          --  pragma Preelaborate_05 [(library_unit_NAME)];
11967
11968          --  This pragma is useable only in GNAT_Mode, where it is used like
11969          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11970          --  (otherwise it is ignored). This is used to implement AI-362 which
11971          --  recategorizes some run-time packages in Ada 2005 mode.
11972
11973          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11974             Ent : Entity_Id;
11975
11976          begin
11977             GNAT_Pragma;
11978             Check_Valid_Library_Unit_Pragma;
11979
11980             if not GNAT_Mode then
11981                Error_Pragma ("pragma% only available in GNAT mode");
11982             end if;
11983
11984             if Nkind (N) = N_Null_Statement then
11985                return;
11986             end if;
11987
11988             --  This is one of the few cases where we need to test the value of
11989             --  Ada_Version_Explicit rather than Ada_Version (which is always
11990             --  set to Ada_2012 in a predefined unit), we need to know the
11991             --  explicit version set to know if this pragma is active.
11992
11993             if Ada_Version_Explicit >= Ada_2005 then
11994                Ent := Find_Lib_Unit_Name;
11995                Set_Is_Preelaborated (Ent);
11996                Set_Suppress_Elaboration_Warnings (Ent);
11997             end if;
11998          end Preelaborate_05;
11999
12000          --------------
12001          -- Priority --
12002          --------------
12003
12004          --  pragma Priority (EXPRESSION);
12005
12006          when Pragma_Priority => Priority : declare
12007             P   : constant Node_Id := Parent (N);
12008             Arg : Node_Id;
12009
12010          begin
12011             Check_No_Identifiers;
12012             Check_Arg_Count (1);
12013
12014             --  Subprogram case
12015
12016             if Nkind (P) = N_Subprogram_Body then
12017                Check_In_Main_Program;
12018
12019                Arg := Get_Pragma_Arg (Arg1);
12020                Analyze_And_Resolve (Arg, Standard_Integer);
12021
12022                --  Must be static
12023
12024                if not Is_Static_Expression (Arg) then
12025                   Flag_Non_Static_Expr
12026                     ("main subprogram priority is not static!", Arg);
12027                   raise Pragma_Exit;
12028
12029                --  If constraint error, then we already signalled an error
12030
12031                elsif Raises_Constraint_Error (Arg) then
12032                   null;
12033
12034                --  Otherwise check in range
12035
12036                else
12037                   declare
12038                      Val : constant Uint := Expr_Value (Arg);
12039
12040                   begin
12041                      if Val < 0
12042                        or else Val > Expr_Value (Expression
12043                                        (Parent (RTE (RE_Max_Priority))))
12044                      then
12045                         Error_Pragma_Arg
12046                           ("main subprogram priority is out of range", Arg1);
12047                      end if;
12048                   end;
12049                end if;
12050
12051                Set_Main_Priority
12052                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
12053
12054                --  Load an arbitrary entity from System.Tasking to make sure
12055                --  this package is implicitly with'ed, since we need to have
12056                --  the tasking run-time active for the pragma Priority to have
12057                --  any effect.
12058
12059                declare
12060                   Discard : Entity_Id;
12061                   pragma Warnings (Off, Discard);
12062                begin
12063                   Discard := RTE (RE_Task_List);
12064                end;
12065
12066             --  Task or Protected, must be of type Integer
12067
12068             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12069                Arg := Get_Pragma_Arg (Arg1);
12070
12071                --  The expression must be analyzed in the special manner
12072                --  described in "Handling of Default and Per-Object
12073                --  Expressions" in sem.ads.
12074
12075                Preanalyze_Spec_Expression (Arg, Standard_Integer);
12076
12077                if not Is_Static_Expression (Arg) then
12078                   Check_Restriction (Static_Priorities, Arg);
12079                end if;
12080
12081             --  Anything else is incorrect
12082
12083             else
12084                Pragma_Misplaced;
12085             end if;
12086
12087             if Has_Pragma_Priority (P) then
12088                Error_Pragma ("duplicate pragma% not allowed");
12089             else
12090                Set_Has_Pragma_Priority (P, True);
12091
12092                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
12093                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12094                   --  exp_ch9 should use this ???
12095                end if;
12096             end if;
12097          end Priority;
12098
12099          -----------------------------------
12100          -- Priority_Specific_Dispatching --
12101          -----------------------------------
12102
12103          --  pragma Priority_Specific_Dispatching (
12104          --    policy_IDENTIFIER,
12105          --    first_priority_EXPRESSION,
12106          --    last_priority_EXPRESSION);
12107
12108          when Pragma_Priority_Specific_Dispatching =>
12109          Priority_Specific_Dispatching : declare
12110             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
12111             --  This is the entity System.Any_Priority;
12112
12113             DP          : Character;
12114             Lower_Bound : Node_Id;
12115             Upper_Bound : Node_Id;
12116             Lower_Val   : Uint;
12117             Upper_Val   : Uint;
12118
12119          begin
12120             Ada_2005_Pragma;
12121             Check_Arg_Count (3);
12122             Check_No_Identifiers;
12123             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
12124             Check_Valid_Configuration_Pragma;
12125             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12126             DP := Fold_Upper (Name_Buffer (1));
12127
12128             Lower_Bound := Get_Pragma_Arg (Arg2);
12129             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
12130             Lower_Val := Expr_Value (Lower_Bound);
12131
12132             Upper_Bound := Get_Pragma_Arg (Arg3);
12133             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
12134             Upper_Val := Expr_Value (Upper_Bound);
12135
12136             --  It is not allowed to use Task_Dispatching_Policy and
12137             --  Priority_Specific_Dispatching in the same partition.
12138
12139             if Task_Dispatching_Policy /= ' ' then
12140                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12141                Error_Pragma
12142                  ("pragma% incompatible with Task_Dispatching_Policy#");
12143
12144             --  Check lower bound in range
12145
12146             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12147                     or else
12148                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
12149             then
12150                Error_Pragma_Arg
12151                  ("first_priority is out of range", Arg2);
12152
12153             --  Check upper bound in range
12154
12155             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
12156                     or else
12157                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
12158             then
12159                Error_Pragma_Arg
12160                  ("last_priority is out of range", Arg3);
12161
12162             --  Check that the priority range is valid
12163
12164             elsif Lower_Val > Upper_Val then
12165                Error_Pragma
12166                  ("last_priority_expression must be greater than" &
12167                   " or equal to first_priority_expression");
12168
12169             --  Store the new policy, but always preserve System_Location since
12170             --  we like the error message with the run-time name.
12171
12172             else
12173                --  Check overlapping in the priority ranges specified in other
12174                --  Priority_Specific_Dispatching pragmas within the same
12175                --  partition. We can only check those we know about!
12176
12177                for J in
12178                   Specific_Dispatching.First .. Specific_Dispatching.Last
12179                loop
12180                   if Specific_Dispatching.Table (J).First_Priority in
12181                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12182                   or else Specific_Dispatching.Table (J).Last_Priority in
12183                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
12184                   then
12185                      Error_Msg_Sloc :=
12186                        Specific_Dispatching.Table (J).Pragma_Loc;
12187                         Error_Pragma
12188                           ("priority range overlaps with "
12189                            & "Priority_Specific_Dispatching#");
12190                   end if;
12191                end loop;
12192
12193                --  The use of Priority_Specific_Dispatching is incompatible
12194                --  with Task_Dispatching_Policy.
12195
12196                if Task_Dispatching_Policy /= ' ' then
12197                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
12198                      Error_Pragma
12199                        ("Priority_Specific_Dispatching incompatible "
12200                         & "with Task_Dispatching_Policy#");
12201                end if;
12202
12203                --  The use of Priority_Specific_Dispatching forces ceiling
12204                --  locking policy.
12205
12206                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
12207                   Error_Msg_Sloc := Locking_Policy_Sloc;
12208                      Error_Pragma
12209                        ("Priority_Specific_Dispatching incompatible "
12210                         & "with Locking_Policy#");
12211
12212                --  Set the Ceiling_Locking policy, but preserve System_Location
12213                --  since we like the error message with the run time name.
12214
12215                else
12216                   Locking_Policy := 'C';
12217
12218                   if Locking_Policy_Sloc /= System_Location then
12219                      Locking_Policy_Sloc := Loc;
12220                   end if;
12221                end if;
12222
12223                --  Add entry in the table
12224
12225                Specific_Dispatching.Append
12226                     ((Dispatching_Policy => DP,
12227                       First_Priority     => UI_To_Int (Lower_Val),
12228                       Last_Priority      => UI_To_Int (Upper_Val),
12229                       Pragma_Loc         => Loc));
12230             end if;
12231          end Priority_Specific_Dispatching;
12232
12233          -------------
12234          -- Profile --
12235          -------------
12236
12237          --  pragma Profile (profile_IDENTIFIER);
12238
12239          --  profile_IDENTIFIER => Restricted | Ravenscar
12240
12241          when Pragma_Profile =>
12242             Ada_2005_Pragma;
12243             Check_Arg_Count (1);
12244             Check_Valid_Configuration_Pragma;
12245             Check_No_Identifiers;
12246
12247             declare
12248                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12249
12250             begin
12251                if Chars (Argx) = Name_Ravenscar then
12252                   Set_Ravenscar_Profile (N);
12253
12254                elsif Chars (Argx) = Name_Restricted then
12255                   Set_Profile_Restrictions
12256                     (Restricted,
12257                      N, Warn => Treat_Restrictions_As_Warnings);
12258
12259                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12260                   Set_Profile_Restrictions
12261                     (No_Implementation_Extensions,
12262                      N, Warn => Treat_Restrictions_As_Warnings);
12263
12264                else
12265                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12266                end if;
12267             end;
12268
12269          ----------------------
12270          -- Profile_Warnings --
12271          ----------------------
12272
12273          --  pragma Profile_Warnings (profile_IDENTIFIER);
12274
12275          --  profile_IDENTIFIER => Restricted | Ravenscar
12276
12277          when Pragma_Profile_Warnings =>
12278             GNAT_Pragma;
12279             Check_Arg_Count (1);
12280             Check_Valid_Configuration_Pragma;
12281             Check_No_Identifiers;
12282
12283             declare
12284                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12285
12286             begin
12287                if Chars (Argx) = Name_Ravenscar then
12288                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12289
12290                elsif Chars (Argx) = Name_Restricted then
12291                   Set_Profile_Restrictions (Restricted, N, Warn => True);
12292
12293                elsif Chars (Argx) = Name_No_Implementation_Extensions then
12294                   Set_Profile_Restrictions
12295                     (No_Implementation_Extensions, N, Warn => True);
12296
12297                else
12298                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12299                end if;
12300             end;
12301
12302          --------------------------
12303          -- Propagate_Exceptions --
12304          --------------------------
12305
12306          --  pragma Propagate_Exceptions;
12307
12308          --  Note: this pragma is obsolete and has no effect
12309
12310          when Pragma_Propagate_Exceptions =>
12311             GNAT_Pragma;
12312             Check_Arg_Count (0);
12313
12314             if In_Extended_Main_Source_Unit (N) then
12315                Propagate_Exceptions := True;
12316             end if;
12317
12318          ------------------
12319          -- Psect_Object --
12320          ------------------
12321
12322          --  pragma Psect_Object (
12323          --        [Internal =>] LOCAL_NAME,
12324          --     [, [External =>] EXTERNAL_SYMBOL]
12325          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12326
12327          when Pragma_Psect_Object | Pragma_Common_Object =>
12328          Psect_Object : declare
12329             Args  : Args_List (1 .. 3);
12330             Names : constant Name_List (1 .. 3) := (
12331                       Name_Internal,
12332                       Name_External,
12333                       Name_Size);
12334
12335             Internal : Node_Id renames Args (1);
12336             External : Node_Id renames Args (2);
12337             Size     : Node_Id renames Args (3);
12338
12339             Def_Id : Entity_Id;
12340
12341             procedure Check_Too_Long (Arg : Node_Id);
12342             --  Posts message if the argument is an identifier with more
12343             --  than 31 characters, or a string literal with more than
12344             --  31 characters, and we are operating under VMS
12345
12346             --------------------
12347             -- Check_Too_Long --
12348             --------------------
12349
12350             procedure Check_Too_Long (Arg : Node_Id) is
12351                X : constant Node_Id := Original_Node (Arg);
12352
12353             begin
12354                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12355                   Error_Pragma_Arg
12356                     ("inappropriate argument for pragma %", Arg);
12357                end if;
12358
12359                if OpenVMS_On_Target then
12360                   if (Nkind (X) = N_String_Literal
12361                        and then String_Length (Strval (X)) > 31)
12362                     or else
12363                      (Nkind (X) = N_Identifier
12364                        and then Length_Of_Name (Chars (X)) > 31)
12365                   then
12366                      Error_Pragma_Arg
12367                        ("argument for pragma % is longer than 31 characters",
12368                         Arg);
12369                   end if;
12370                end if;
12371             end Check_Too_Long;
12372
12373          --  Start of processing for Common_Object/Psect_Object
12374
12375          begin
12376             GNAT_Pragma;
12377             Gather_Associations (Names, Args);
12378             Process_Extended_Import_Export_Internal_Arg (Internal);
12379
12380             Def_Id := Entity (Internal);
12381
12382             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12383                Error_Pragma_Arg
12384                  ("pragma% must designate an object", Internal);
12385             end if;
12386
12387             Check_Too_Long (Internal);
12388
12389             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12390                Error_Pragma_Arg
12391                  ("cannot use pragma% for imported/exported object",
12392                   Internal);
12393             end if;
12394
12395             if Is_Concurrent_Type (Etype (Internal)) then
12396                Error_Pragma_Arg
12397                  ("cannot specify pragma % for task/protected object",
12398                   Internal);
12399             end if;
12400
12401             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12402                  or else
12403                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12404             then
12405                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12406             end if;
12407
12408             if Ekind (Def_Id) = E_Constant then
12409                Error_Pragma_Arg
12410                  ("cannot specify pragma % for a constant", Internal);
12411             end if;
12412
12413             if Is_Record_Type (Etype (Internal)) then
12414                declare
12415                   Ent  : Entity_Id;
12416                   Decl : Entity_Id;
12417
12418                begin
12419                   Ent := First_Entity (Etype (Internal));
12420                   while Present (Ent) loop
12421                      Decl := Declaration_Node (Ent);
12422
12423                      if Ekind (Ent) = E_Component
12424                        and then Nkind (Decl) = N_Component_Declaration
12425                        and then Present (Expression (Decl))
12426                        and then Warn_On_Export_Import
12427                      then
12428                         Error_Msg_N
12429                           ("?object for pragma % has defaults", Internal);
12430                         exit;
12431
12432                      else
12433                         Next_Entity (Ent);
12434                      end if;
12435                   end loop;
12436                end;
12437             end if;
12438
12439             if Present (Size) then
12440                Check_Too_Long (Size);
12441             end if;
12442
12443             if Present (External) then
12444                Check_Arg_Is_External_Name (External);
12445                Check_Too_Long (External);
12446             end if;
12447
12448             --  If all error tests pass, link pragma on to the rep item chain
12449
12450             Record_Rep_Item (Def_Id, N);
12451          end Psect_Object;
12452
12453          ----------
12454          -- Pure --
12455          ----------
12456
12457          --  pragma Pure [(library_unit_NAME)];
12458
12459          when Pragma_Pure => Pure : declare
12460             Ent : Entity_Id;
12461
12462          begin
12463             Check_Ada_83_Warning;
12464             Check_Valid_Library_Unit_Pragma;
12465
12466             if Nkind (N) = N_Null_Statement then
12467                return;
12468             end if;
12469
12470             Ent := Find_Lib_Unit_Name;
12471             Set_Is_Pure (Ent);
12472             Set_Has_Pragma_Pure (Ent);
12473             Set_Suppress_Elaboration_Warnings (Ent);
12474          end Pure;
12475
12476          -------------
12477          -- Pure_05 --
12478          -------------
12479
12480          --  pragma Pure_05 [(library_unit_NAME)];
12481
12482          --  This pragma is useable only in GNAT_Mode, where it is used like
12483          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12484          --  it is ignored). It may be used after a pragma Preelaborate, in
12485          --  which case it overrides the effect of the pragma Preelaborate.
12486          --  This is used to implement AI-362 which recategorizes some run-time
12487          --  packages in Ada 2005 mode.
12488
12489          when Pragma_Pure_05 => Pure_05 : declare
12490             Ent : Entity_Id;
12491
12492          begin
12493             GNAT_Pragma;
12494             Check_Valid_Library_Unit_Pragma;
12495
12496             if not GNAT_Mode then
12497                Error_Pragma ("pragma% only available in GNAT mode");
12498             end if;
12499
12500             if Nkind (N) = N_Null_Statement then
12501                return;
12502             end if;
12503
12504             --  This is one of the few cases where we need to test the value of
12505             --  Ada_Version_Explicit rather than Ada_Version (which is always
12506             --  set to Ada_2012 in a predefined unit), we need to know the
12507             --  explicit version set to know if this pragma is active.
12508
12509             if Ada_Version_Explicit >= Ada_2005 then
12510                Ent := Find_Lib_Unit_Name;
12511                Set_Is_Preelaborated (Ent, False);
12512                Set_Is_Pure (Ent);
12513                Set_Suppress_Elaboration_Warnings (Ent);
12514             end if;
12515          end Pure_05;
12516
12517          -------------------
12518          -- Pure_Function --
12519          -------------------
12520
12521          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12522
12523          when Pragma_Pure_Function => Pure_Function : declare
12524             E_Id      : Node_Id;
12525             E         : Entity_Id;
12526             Def_Id    : Entity_Id;
12527             Effective : Boolean := False;
12528
12529          begin
12530             GNAT_Pragma;
12531             Check_Arg_Count (1);
12532             Check_Optional_Identifier (Arg1, Name_Entity);
12533             Check_Arg_Is_Local_Name (Arg1);
12534             E_Id := Get_Pragma_Arg (Arg1);
12535
12536             if Error_Posted (E_Id) then
12537                return;
12538             end if;
12539
12540             --  Loop through homonyms (overloadings) of referenced entity
12541
12542             E := Entity (E_Id);
12543
12544             if Present (E) then
12545                loop
12546                   Def_Id := Get_Base_Subprogram (E);
12547
12548                   if not Ekind_In (Def_Id, E_Function,
12549                                            E_Generic_Function,
12550                                            E_Operator)
12551                   then
12552                      Error_Pragma_Arg
12553                        ("pragma% requires a function name", Arg1);
12554                   end if;
12555
12556                   Set_Is_Pure (Def_Id);
12557
12558                   if not Has_Pragma_Pure_Function (Def_Id) then
12559                      Set_Has_Pragma_Pure_Function (Def_Id);
12560                      Effective := True;
12561                   end if;
12562
12563                   exit when From_Aspect_Specification (N);
12564                   E := Homonym (E);
12565                   exit when No (E) or else Scope (E) /= Current_Scope;
12566                end loop;
12567
12568                if not Effective
12569                  and then Warn_On_Redundant_Constructs
12570                then
12571                   Error_Msg_NE
12572                     ("pragma Pure_Function on& is redundant?",
12573                      N, Entity (E_Id));
12574                end if;
12575             end if;
12576          end Pure_Function;
12577
12578          --------------------
12579          -- Queuing_Policy --
12580          --------------------
12581
12582          --  pragma Queuing_Policy (policy_IDENTIFIER);
12583
12584          when Pragma_Queuing_Policy => declare
12585             QP : Character;
12586
12587          begin
12588             Check_Ada_83_Warning;
12589             Check_Arg_Count (1);
12590             Check_No_Identifiers;
12591             Check_Arg_Is_Queuing_Policy (Arg1);
12592             Check_Valid_Configuration_Pragma;
12593             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12594             QP := Fold_Upper (Name_Buffer (1));
12595
12596             if Queuing_Policy /= ' '
12597               and then Queuing_Policy /= QP
12598             then
12599                Error_Msg_Sloc := Queuing_Policy_Sloc;
12600                Error_Pragma ("queuing policy incompatible with policy#");
12601
12602             --  Set new policy, but always preserve System_Location since we
12603             --  like the error message with the run time name.
12604
12605             else
12606                Queuing_Policy := QP;
12607
12608                if Queuing_Policy_Sloc /= System_Location then
12609                   Queuing_Policy_Sloc := Loc;
12610                end if;
12611             end if;
12612          end;
12613
12614          -----------------------
12615          -- Relative_Deadline --
12616          -----------------------
12617
12618          --  pragma Relative_Deadline (time_span_EXPRESSION);
12619
12620          when Pragma_Relative_Deadline => Relative_Deadline : declare
12621             P   : constant Node_Id := Parent (N);
12622             Arg : Node_Id;
12623
12624          begin
12625             Ada_2005_Pragma;
12626             Check_No_Identifiers;
12627             Check_Arg_Count (1);
12628
12629             Arg := Get_Pragma_Arg (Arg1);
12630
12631             --  The expression must be analyzed in the special manner described
12632             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12633
12634             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12635
12636             --  Subprogram case
12637
12638             if Nkind (P) = N_Subprogram_Body then
12639                Check_In_Main_Program;
12640
12641             --  Tasks
12642
12643             elsif Nkind (P) = N_Task_Definition then
12644                null;
12645
12646             --  Anything else is incorrect
12647
12648             else
12649                Pragma_Misplaced;
12650             end if;
12651
12652             if Has_Relative_Deadline_Pragma (P) then
12653                Error_Pragma ("duplicate pragma% not allowed");
12654             else
12655                Set_Has_Relative_Deadline_Pragma (P, True);
12656
12657                if Nkind (P) = N_Task_Definition then
12658                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12659                end if;
12660             end if;
12661          end Relative_Deadline;
12662
12663          ---------------------------
12664          -- Remote_Call_Interface --
12665          ---------------------------
12666
12667          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12668
12669          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12670             Cunit_Node : Node_Id;
12671             Cunit_Ent  : Entity_Id;
12672             K          : Node_Kind;
12673
12674          begin
12675             Check_Ada_83_Warning;
12676             Check_Valid_Library_Unit_Pragma;
12677
12678             if Nkind (N) = N_Null_Statement then
12679                return;
12680             end if;
12681
12682             Cunit_Node := Cunit (Current_Sem_Unit);
12683             K          := Nkind (Unit (Cunit_Node));
12684             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12685
12686             if K = N_Package_Declaration
12687               or else K = N_Generic_Package_Declaration
12688               or else K = N_Subprogram_Declaration
12689               or else K = N_Generic_Subprogram_Declaration
12690               or else (K = N_Subprogram_Body
12691                          and then Acts_As_Spec (Unit (Cunit_Node)))
12692             then
12693                null;
12694             else
12695                Error_Pragma (
12696                  "pragma% must apply to package or subprogram declaration");
12697             end if;
12698
12699             Set_Is_Remote_Call_Interface (Cunit_Ent);
12700          end Remote_Call_Interface;
12701
12702          ------------------
12703          -- Remote_Types --
12704          ------------------
12705
12706          --  pragma Remote_Types [(library_unit_NAME)];
12707
12708          when Pragma_Remote_Types => Remote_Types : declare
12709             Cunit_Node : Node_Id;
12710             Cunit_Ent  : Entity_Id;
12711
12712          begin
12713             Check_Ada_83_Warning;
12714             Check_Valid_Library_Unit_Pragma;
12715
12716             if Nkind (N) = N_Null_Statement then
12717                return;
12718             end if;
12719
12720             Cunit_Node := Cunit (Current_Sem_Unit);
12721             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12722
12723             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12724                                                 N_Generic_Package_Declaration)
12725             then
12726                Error_Pragma
12727                  ("pragma% can only apply to a package declaration");
12728             end if;
12729
12730             Set_Is_Remote_Types (Cunit_Ent);
12731          end Remote_Types;
12732
12733          ---------------
12734          -- Ravenscar --
12735          ---------------
12736
12737          --  pragma Ravenscar;
12738
12739          when Pragma_Ravenscar =>
12740             GNAT_Pragma;
12741             Check_Arg_Count (0);
12742             Check_Valid_Configuration_Pragma;
12743             Set_Ravenscar_Profile (N);
12744
12745             if Warn_On_Obsolescent_Feature then
12746                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12747                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12748             end if;
12749
12750          -------------------------
12751          -- Restricted_Run_Time --
12752          -------------------------
12753
12754          --  pragma Restricted_Run_Time;
12755
12756          when Pragma_Restricted_Run_Time =>
12757             GNAT_Pragma;
12758             Check_Arg_Count (0);
12759             Check_Valid_Configuration_Pragma;
12760             Set_Profile_Restrictions
12761               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12762
12763             if Warn_On_Obsolescent_Feature then
12764                Error_Msg_N
12765                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12766                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12767             end if;
12768
12769          ------------------
12770          -- Restrictions --
12771          ------------------
12772
12773          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12774
12775          --  RESTRICTION ::=
12776          --    restriction_IDENTIFIER
12777          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12778
12779          when Pragma_Restrictions =>
12780             Process_Restrictions_Or_Restriction_Warnings
12781               (Warn => Treat_Restrictions_As_Warnings);
12782
12783          --------------------------
12784          -- Restriction_Warnings --
12785          --------------------------
12786
12787          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12788
12789          --  RESTRICTION ::=
12790          --    restriction_IDENTIFIER
12791          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12792
12793          when Pragma_Restriction_Warnings =>
12794             GNAT_Pragma;
12795             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12796
12797          ----------------
12798          -- Reviewable --
12799          ----------------
12800
12801          --  pragma Reviewable;
12802
12803          when Pragma_Reviewable =>
12804             Check_Ada_83_Warning;
12805             Check_Arg_Count (0);
12806
12807             --  Call dummy debugging function rv. This is done to assist front
12808             --  end debugging. By placing a Reviewable pragma in the source
12809             --  program, a breakpoint on rv catches this place in the source,
12810             --  allowing convenient stepping to the point of interest.
12811
12812             rv;
12813
12814          --------------------------
12815          -- Short_Circuit_And_Or --
12816          --------------------------
12817
12818          when Pragma_Short_Circuit_And_Or =>
12819             GNAT_Pragma;
12820             Check_Arg_Count (0);
12821             Check_Valid_Configuration_Pragma;
12822             Short_Circuit_And_Or := True;
12823
12824          -------------------
12825          -- Share_Generic --
12826          -------------------
12827
12828          --  pragma Share_Generic (NAME {, NAME});
12829
12830          when Pragma_Share_Generic =>
12831             GNAT_Pragma;
12832             Process_Generic_List;
12833
12834          ------------
12835          -- Shared --
12836          ------------
12837
12838          --  pragma Shared (LOCAL_NAME);
12839
12840          when Pragma_Shared =>
12841             GNAT_Pragma;
12842             Process_Atomic_Shared_Volatile;
12843
12844          --------------------
12845          -- Shared_Passive --
12846          --------------------
12847
12848          --  pragma Shared_Passive [(library_unit_NAME)];
12849
12850          --  Set the flag Is_Shared_Passive of program unit name entity
12851
12852          when Pragma_Shared_Passive => Shared_Passive : declare
12853             Cunit_Node : Node_Id;
12854             Cunit_Ent  : Entity_Id;
12855
12856          begin
12857             Check_Ada_83_Warning;
12858             Check_Valid_Library_Unit_Pragma;
12859
12860             if Nkind (N) = N_Null_Statement then
12861                return;
12862             end if;
12863
12864             Cunit_Node := Cunit (Current_Sem_Unit);
12865             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12866
12867             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12868                                                 N_Generic_Package_Declaration)
12869             then
12870                Error_Pragma
12871                  ("pragma% can only apply to a package declaration");
12872             end if;
12873
12874             Set_Is_Shared_Passive (Cunit_Ent);
12875          end Shared_Passive;
12876
12877          -----------------------
12878          -- Short_Descriptors --
12879          -----------------------
12880
12881          --  pragma Short_Descriptors;
12882
12883          when Pragma_Short_Descriptors =>
12884             GNAT_Pragma;
12885             Check_Arg_Count (0);
12886             Check_Valid_Configuration_Pragma;
12887             Short_Descriptors := True;
12888
12889          ----------------------
12890          -- Source_File_Name --
12891          ----------------------
12892
12893          --  There are five forms for this pragma:
12894
12895          --  pragma Source_File_Name (
12896          --    [UNIT_NAME      =>] unit_NAME,
12897          --     BODY_FILE_NAME =>  STRING_LITERAL
12898          --    [, [INDEX =>] INTEGER_LITERAL]);
12899
12900          --  pragma Source_File_Name (
12901          --    [UNIT_NAME      =>] unit_NAME,
12902          --     SPEC_FILE_NAME =>  STRING_LITERAL
12903          --    [, [INDEX =>] INTEGER_LITERAL]);
12904
12905          --  pragma Source_File_Name (
12906          --     BODY_FILE_NAME  => STRING_LITERAL
12907          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12908          --  [, CASING          => CASING_SPEC]);
12909
12910          --  pragma Source_File_Name (
12911          --     SPEC_FILE_NAME  => STRING_LITERAL
12912          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12913          --  [, CASING          => CASING_SPEC]);
12914
12915          --  pragma Source_File_Name (
12916          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12917          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12918          --  [, CASING             => CASING_SPEC]);
12919
12920          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12921
12922          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12923          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12924          --  only be used when no project file is used, while SFNP can only be
12925          --  used when a project file is used.
12926
12927          --  No processing here. Processing was completed during parsing, since
12928          --  we need to have file names set as early as possible. Units are
12929          --  loaded well before semantic processing starts.
12930
12931          --  The only processing we defer to this point is the check for
12932          --  correct placement.
12933
12934          when Pragma_Source_File_Name =>
12935             GNAT_Pragma;
12936             Check_Valid_Configuration_Pragma;
12937
12938          ------------------------------
12939          -- Source_File_Name_Project --
12940          ------------------------------
12941
12942          --  See Source_File_Name for syntax
12943
12944          --  No processing here. Processing was completed during parsing, since
12945          --  we need to have file names set as early as possible. Units are
12946          --  loaded well before semantic processing starts.
12947
12948          --  The only processing we defer to this point is the check for
12949          --  correct placement.
12950
12951          when Pragma_Source_File_Name_Project =>
12952             GNAT_Pragma;
12953             Check_Valid_Configuration_Pragma;
12954
12955             --  Check that a pragma Source_File_Name_Project is used only in a
12956             --  configuration pragmas file.
12957
12958             --  Pragmas Source_File_Name_Project should only be generated by
12959             --  the Project Manager in configuration pragmas files.
12960
12961             --  This is really an ugly test. It seems to depend on some
12962             --  accidental and undocumented property. At the very least it
12963             --  needs to be documented, but it would be better to have a
12964             --  clean way of testing if we are in a configuration file???
12965
12966             if Present (Parent (N)) then
12967                Error_Pragma
12968                  ("pragma% can only appear in a configuration pragmas file");
12969             end if;
12970
12971          ----------------------
12972          -- Source_Reference --
12973          ----------------------
12974
12975          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12976
12977          --  Nothing to do, all processing completed in Par.Prag, since we need
12978          --  the information for possible parser messages that are output.
12979
12980          when Pragma_Source_Reference =>
12981             GNAT_Pragma;
12982
12983          --------------------------------
12984          -- Static_Elaboration_Desired --
12985          --------------------------------
12986
12987          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12988
12989          when Pragma_Static_Elaboration_Desired =>
12990             GNAT_Pragma;
12991             Check_At_Most_N_Arguments (1);
12992
12993             if Is_Compilation_Unit (Current_Scope)
12994               and then Ekind (Current_Scope) = E_Package
12995             then
12996                Set_Static_Elaboration_Desired (Current_Scope, True);
12997             else
12998                Error_Pragma ("pragma% must apply to a library-level package");
12999             end if;
13000
13001          ------------------
13002          -- Storage_Size --
13003          ------------------
13004
13005          --  pragma Storage_Size (EXPRESSION);
13006
13007          when Pragma_Storage_Size => Storage_Size : declare
13008             P   : constant Node_Id := Parent (N);
13009             Arg : Node_Id;
13010
13011          begin
13012             Check_No_Identifiers;
13013             Check_Arg_Count (1);
13014
13015             --  The expression must be analyzed in the special manner described
13016             --  in "Handling of Default Expressions" in sem.ads.
13017
13018             Arg := Get_Pragma_Arg (Arg1);
13019             Preanalyze_Spec_Expression (Arg, Any_Integer);
13020
13021             if not Is_Static_Expression (Arg) then
13022                Check_Restriction (Static_Storage_Size, Arg);
13023             end if;
13024
13025             if Nkind (P) /= N_Task_Definition then
13026                Pragma_Misplaced;
13027                return;
13028
13029             else
13030                if Has_Storage_Size_Pragma (P) then
13031                   Error_Pragma ("duplicate pragma% not allowed");
13032                else
13033                   Set_Has_Storage_Size_Pragma (P, True);
13034                end if;
13035
13036                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13037                --  ???  exp_ch9 should use this!
13038             end if;
13039          end Storage_Size;
13040
13041          ------------------
13042          -- Storage_Unit --
13043          ------------------
13044
13045          --  pragma Storage_Unit (NUMERIC_LITERAL);
13046
13047          --  Only permitted argument is System'Storage_Unit value
13048
13049          when Pragma_Storage_Unit =>
13050             Check_No_Identifiers;
13051             Check_Arg_Count (1);
13052             Check_Arg_Is_Integer_Literal (Arg1);
13053
13054             if Intval (Get_Pragma_Arg (Arg1)) /=
13055               UI_From_Int (Ttypes.System_Storage_Unit)
13056             then
13057                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
13058                Error_Pragma_Arg
13059                  ("the only allowed argument for pragma% is ^", Arg1);
13060             end if;
13061
13062          --------------------
13063          -- Stream_Convert --
13064          --------------------
13065
13066          --  pragma Stream_Convert (
13067          --    [Entity =>] type_LOCAL_NAME,
13068          --    [Read   =>] function_NAME,
13069          --    [Write  =>] function NAME);
13070
13071          when Pragma_Stream_Convert => Stream_Convert : declare
13072
13073             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
13074             --  Check that the given argument is the name of a local function
13075             --  of one argument that is not overloaded earlier in the current
13076             --  local scope. A check is also made that the argument is a
13077             --  function with one parameter.
13078
13079             --------------------------------------
13080             -- Check_OK_Stream_Convert_Function --
13081             --------------------------------------
13082
13083             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
13084                Ent : Entity_Id;
13085
13086             begin
13087                Check_Arg_Is_Local_Name (Arg);
13088                Ent := Entity (Get_Pragma_Arg (Arg));
13089
13090                if Has_Homonym (Ent) then
13091                   Error_Pragma_Arg
13092                     ("argument for pragma% may not be overloaded", Arg);
13093                end if;
13094
13095                if Ekind (Ent) /= E_Function
13096                  or else No (First_Formal (Ent))
13097                  or else Present (Next_Formal (First_Formal (Ent)))
13098                then
13099                   Error_Pragma_Arg
13100                     ("argument for pragma% must be" &
13101                      " function of one argument", Arg);
13102                end if;
13103             end Check_OK_Stream_Convert_Function;
13104
13105          --  Start of processing for Stream_Convert
13106
13107          begin
13108             GNAT_Pragma;
13109             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
13110             Check_Arg_Count (3);
13111             Check_Optional_Identifier (Arg1, Name_Entity);
13112             Check_Optional_Identifier (Arg2, Name_Read);
13113             Check_Optional_Identifier (Arg3, Name_Write);
13114             Check_Arg_Is_Local_Name (Arg1);
13115             Check_OK_Stream_Convert_Function (Arg2);
13116             Check_OK_Stream_Convert_Function (Arg3);
13117
13118             declare
13119                Typ   : constant Entity_Id :=
13120                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
13121                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
13122                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
13123
13124             begin
13125                Check_First_Subtype (Arg1);
13126
13127                --  Check for too early or too late. Note that we don't enforce
13128                --  the rule about primitive operations in this case, since, as
13129                --  is the case for explicit stream attributes themselves, these
13130                --  restrictions are not appropriate. Note that the chaining of
13131                --  the pragma by Rep_Item_Too_Late is actually the critical
13132                --  processing done for this pragma.
13133
13134                if Rep_Item_Too_Early (Typ, N)
13135                     or else
13136                   Rep_Item_Too_Late (Typ, N, FOnly => True)
13137                then
13138                   return;
13139                end if;
13140
13141                --  Return if previous error
13142
13143                if Etype (Typ) = Any_Type
13144                     or else
13145                   Etype (Read) = Any_Type
13146                     or else
13147                   Etype (Write) = Any_Type
13148                then
13149                   return;
13150                end if;
13151
13152                --  Error checks
13153
13154                if Underlying_Type (Etype (Read)) /= Typ then
13155                   Error_Pragma_Arg
13156                     ("incorrect return type for function&", Arg2);
13157                end if;
13158
13159                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
13160                   Error_Pragma_Arg
13161                     ("incorrect parameter type for function&", Arg3);
13162                end if;
13163
13164                if Underlying_Type (Etype (First_Formal (Read))) /=
13165                   Underlying_Type (Etype (Write))
13166                then
13167                   Error_Pragma_Arg
13168                     ("result type of & does not match Read parameter type",
13169                      Arg3);
13170                end if;
13171             end;
13172          end Stream_Convert;
13173
13174          -------------------------
13175          -- Style_Checks (GNAT) --
13176          -------------------------
13177
13178          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13179
13180          --  This is processed by the parser since some of the style checks
13181          --  take place during source scanning and parsing. This means that
13182          --  we don't need to issue error messages here.
13183
13184          when Pragma_Style_Checks => Style_Checks : declare
13185             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13186             S  : String_Id;
13187             C  : Char_Code;
13188
13189          begin
13190             GNAT_Pragma;
13191             Check_No_Identifiers;
13192
13193             --  Two argument form
13194
13195             if Arg_Count = 2 then
13196                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13197
13198                declare
13199                   E_Id : Node_Id;
13200                   E    : Entity_Id;
13201
13202                begin
13203                   E_Id := Get_Pragma_Arg (Arg2);
13204                   Analyze (E_Id);
13205
13206                   if not Is_Entity_Name (E_Id) then
13207                      Error_Pragma_Arg
13208                        ("second argument of pragma% must be entity name",
13209                         Arg2);
13210                   end if;
13211
13212                   E := Entity (E_Id);
13213
13214                   if E = Any_Id then
13215                      return;
13216                   else
13217                      loop
13218                         Set_Suppress_Style_Checks (E,
13219                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
13220                         exit when No (Homonym (E));
13221                         E := Homonym (E);
13222                      end loop;
13223                   end if;
13224                end;
13225
13226             --  One argument form
13227
13228             else
13229                Check_Arg_Count (1);
13230
13231                if Nkind (A) = N_String_Literal then
13232                   S   := Strval (A);
13233
13234                   declare
13235                      Slen    : constant Natural := Natural (String_Length (S));
13236                      Options : String (1 .. Slen);
13237                      J       : Natural;
13238
13239                   begin
13240                      J := 1;
13241                      loop
13242                         C := Get_String_Char (S, Int (J));
13243                         exit when not In_Character_Range (C);
13244                         Options (J) := Get_Character (C);
13245
13246                         --  If at end of string, set options. As per discussion
13247                         --  above, no need to check for errors, since we issued
13248                         --  them in the parser.
13249
13250                         if J = Slen then
13251                            Set_Style_Check_Options (Options);
13252                            exit;
13253                         end if;
13254
13255                         J := J + 1;
13256                      end loop;
13257                   end;
13258
13259                elsif Nkind (A) = N_Identifier then
13260                   if Chars (A) = Name_All_Checks then
13261                      if GNAT_Mode then
13262                         Set_GNAT_Style_Check_Options;
13263                      else
13264                         Set_Default_Style_Check_Options;
13265                      end if;
13266
13267                   elsif Chars (A) = Name_On then
13268                      Style_Check := True;
13269
13270                   elsif Chars (A) = Name_Off then
13271                      Style_Check := False;
13272                   end if;
13273                end if;
13274             end if;
13275          end Style_Checks;
13276
13277          --------------
13278          -- Subtitle --
13279          --------------
13280
13281          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13282
13283          when Pragma_Subtitle =>
13284             GNAT_Pragma;
13285             Check_Arg_Count (1);
13286             Check_Optional_Identifier (Arg1, Name_Subtitle);
13287             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13288             Store_Note (N);
13289
13290          --------------
13291          -- Suppress --
13292          --------------
13293
13294          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13295
13296          when Pragma_Suppress =>
13297             Process_Suppress_Unsuppress (True);
13298
13299          ------------------
13300          -- Suppress_All --
13301          ------------------
13302
13303          --  pragma Suppress_All;
13304
13305          --  The only check made here is that the pragma has no arguments.
13306          --  There are no placement rules, and the processing required (setting
13307          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
13308          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
13309          --  then creates and inserts a pragma Suppress (All_Checks).
13310
13311          when Pragma_Suppress_All =>
13312             GNAT_Pragma;
13313             Check_Arg_Count (0);
13314
13315          -------------------------
13316          -- Suppress_Debug_Info --
13317          -------------------------
13318
13319          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13320
13321          when Pragma_Suppress_Debug_Info =>
13322             GNAT_Pragma;
13323             Check_Arg_Count (1);
13324             Check_Optional_Identifier (Arg1, Name_Entity);
13325             Check_Arg_Is_Local_Name (Arg1);
13326             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13327
13328          ----------------------------------
13329          -- Suppress_Exception_Locations --
13330          ----------------------------------
13331
13332          --  pragma Suppress_Exception_Locations;
13333
13334          when Pragma_Suppress_Exception_Locations =>
13335             GNAT_Pragma;
13336             Check_Arg_Count (0);
13337             Check_Valid_Configuration_Pragma;
13338             Exception_Locations_Suppressed := True;
13339
13340          -----------------------------
13341          -- Suppress_Initialization --
13342          -----------------------------
13343
13344          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13345
13346          when Pragma_Suppress_Initialization => Suppress_Init : declare
13347             E_Id : Node_Id;
13348             E    : Entity_Id;
13349
13350          begin
13351             GNAT_Pragma;
13352             Check_Arg_Count (1);
13353             Check_Optional_Identifier (Arg1, Name_Entity);
13354             Check_Arg_Is_Local_Name (Arg1);
13355
13356             E_Id := Get_Pragma_Arg (Arg1);
13357
13358             if Etype (E_Id) = Any_Type then
13359                return;
13360             end if;
13361
13362             E := Entity (E_Id);
13363
13364             if not Is_Type (E) then
13365                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13366             end if;
13367
13368             if Rep_Item_Too_Early (E, N)
13369                  or else
13370                Rep_Item_Too_Late (E, N, FOnly => True)
13371             then
13372                return;
13373             end if;
13374
13375             --  For incomplete/private type, set flag on full view
13376
13377             if Is_Incomplete_Or_Private_Type (E) then
13378                if No (Full_View (Base_Type (E))) then
13379                   Error_Pragma_Arg
13380                     ("argument of pragma% cannot be an incomplete type", Arg1);
13381                else
13382                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13383                end if;
13384
13385             --  For first subtype, set flag on base type
13386
13387             elsif Is_First_Subtype (E) then
13388                Set_Suppress_Initialization (Base_Type (E));
13389
13390             --  For other than first subtype, set flag on subtype itself
13391
13392             else
13393                Set_Suppress_Initialization (E);
13394             end if;
13395          end Suppress_Init;
13396
13397          -----------------
13398          -- System_Name --
13399          -----------------
13400
13401          --  pragma System_Name (DIRECT_NAME);
13402
13403          --  Syntax check: one argument, which must be the identifier GNAT or
13404          --  the identifier GCC, no other identifiers are acceptable.
13405
13406          when Pragma_System_Name =>
13407             GNAT_Pragma;
13408             Check_No_Identifiers;
13409             Check_Arg_Count (1);
13410             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13411
13412          -----------------------------
13413          -- Task_Dispatching_Policy --
13414          -----------------------------
13415
13416          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13417
13418          when Pragma_Task_Dispatching_Policy => declare
13419             DP : Character;
13420
13421          begin
13422             Check_Ada_83_Warning;
13423             Check_Arg_Count (1);
13424             Check_No_Identifiers;
13425             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13426             Check_Valid_Configuration_Pragma;
13427             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13428             DP := Fold_Upper (Name_Buffer (1));
13429
13430             if Task_Dispatching_Policy /= ' '
13431               and then Task_Dispatching_Policy /= DP
13432             then
13433                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13434                Error_Pragma
13435                  ("task dispatching policy incompatible with policy#");
13436
13437             --  Set new policy, but always preserve System_Location since we
13438             --  like the error message with the run time name.
13439
13440             else
13441                Task_Dispatching_Policy := DP;
13442
13443                if Task_Dispatching_Policy_Sloc /= System_Location then
13444                   Task_Dispatching_Policy_Sloc := Loc;
13445                end if;
13446             end if;
13447          end;
13448
13449          ---------------
13450          -- Task_Info --
13451          ---------------
13452
13453          --  pragma Task_Info (EXPRESSION);
13454
13455          when Pragma_Task_Info => Task_Info : declare
13456             P : constant Node_Id := Parent (N);
13457
13458          begin
13459             GNAT_Pragma;
13460
13461             if Nkind (P) /= N_Task_Definition then
13462                Error_Pragma ("pragma% must appear in task definition");
13463             end if;
13464
13465             Check_No_Identifiers;
13466             Check_Arg_Count (1);
13467
13468             Analyze_And_Resolve
13469               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13470
13471             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13472                return;
13473             end if;
13474
13475             if Has_Task_Info_Pragma (P) then
13476                Error_Pragma ("duplicate pragma% not allowed");
13477             else
13478                Set_Has_Task_Info_Pragma (P, True);
13479             end if;
13480          end Task_Info;
13481
13482          ---------------
13483          -- Task_Name --
13484          ---------------
13485
13486          --  pragma Task_Name (string_EXPRESSION);
13487
13488          when Pragma_Task_Name => Task_Name : declare
13489             P   : constant Node_Id := Parent (N);
13490             Arg : Node_Id;
13491
13492          begin
13493             Check_No_Identifiers;
13494             Check_Arg_Count (1);
13495
13496             Arg := Get_Pragma_Arg (Arg1);
13497
13498             --  The expression is used in the call to Create_Task, and must be
13499             --  expanded there, not in the context of the current spec. It must
13500             --  however be analyzed to capture global references, in case it
13501             --  appears in a generic context.
13502
13503             Preanalyze_And_Resolve (Arg, Standard_String);
13504
13505             if Nkind (P) /= N_Task_Definition then
13506                Pragma_Misplaced;
13507             end if;
13508
13509             if Has_Task_Name_Pragma (P) then
13510                Error_Pragma ("duplicate pragma% not allowed");
13511             else
13512                Set_Has_Task_Name_Pragma (P, True);
13513                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13514             end if;
13515          end Task_Name;
13516
13517          ------------------
13518          -- Task_Storage --
13519          ------------------
13520
13521          --  pragma Task_Storage (
13522          --     [Task_Type =>] LOCAL_NAME,
13523          --     [Top_Guard =>] static_integer_EXPRESSION);
13524
13525          when Pragma_Task_Storage => Task_Storage : declare
13526             Args  : Args_List (1 .. 2);
13527             Names : constant Name_List (1 .. 2) := (
13528                       Name_Task_Type,
13529                       Name_Top_Guard);
13530
13531             Task_Type : Node_Id renames Args (1);
13532             Top_Guard : Node_Id renames Args (2);
13533
13534             Ent : Entity_Id;
13535
13536          begin
13537             GNAT_Pragma;
13538             Gather_Associations (Names, Args);
13539
13540             if No (Task_Type) then
13541                Error_Pragma
13542                  ("missing task_type argument for pragma%");
13543             end if;
13544
13545             Check_Arg_Is_Local_Name (Task_Type);
13546
13547             Ent := Entity (Task_Type);
13548
13549             if not Is_Task_Type (Ent) then
13550                Error_Pragma_Arg
13551                  ("argument for pragma% must be task type", Task_Type);
13552             end if;
13553
13554             if No (Top_Guard) then
13555                Error_Pragma_Arg
13556                  ("pragma% takes two arguments", Task_Type);
13557             else
13558                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13559             end if;
13560
13561             Check_First_Subtype (Task_Type);
13562
13563             if Rep_Item_Too_Late (Ent, N) then
13564                raise Pragma_Exit;
13565             end if;
13566          end Task_Storage;
13567
13568          ---------------
13569          -- Test_Case --
13570          ---------------
13571
13572          --  pragma Test_Case ([Name     =>] Static_String_EXPRESSION
13573          --                   ,[Mode     =>] MODE_TYPE
13574          --                  [, Requires =>  Boolean_EXPRESSION]
13575          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13576
13577          --  MODE_TYPE ::= Nominal | Robustness
13578
13579          when Pragma_Test_Case => Test_Case : declare
13580          begin
13581             GNAT_Pragma;
13582             Check_At_Least_N_Arguments (2);
13583             Check_At_Most_N_Arguments (4);
13584             Check_Arg_Order
13585                  ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13586
13587             Check_Optional_Identifier (Arg1, Name_Name);
13588             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13589             Check_Optional_Identifier (Arg2, Name_Mode);
13590             Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13591
13592             if Arg_Count = 4 then
13593                Check_Identifier (Arg3, Name_Requires);
13594                Check_Identifier (Arg4, Name_Ensures);
13595
13596             elsif Arg_Count = 3 then
13597                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13598             end if;
13599
13600             Check_Test_Case;
13601          end Test_Case;
13602
13603          --------------------------
13604          -- Thread_Local_Storage --
13605          --------------------------
13606
13607          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13608
13609          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13610             Id : Node_Id;
13611             E  : Entity_Id;
13612
13613          begin
13614             GNAT_Pragma;
13615             Check_Arg_Count (1);
13616             Check_Optional_Identifier (Arg1, Name_Entity);
13617             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13618
13619             Id := Get_Pragma_Arg (Arg1);
13620             Analyze (Id);
13621
13622             if not Is_Entity_Name (Id)
13623               or else Ekind (Entity (Id)) /= E_Variable
13624             then
13625                Error_Pragma_Arg ("local variable name required", Arg1);
13626             end if;
13627
13628             E := Entity (Id);
13629
13630             if Rep_Item_Too_Early (E, N)
13631               or else Rep_Item_Too_Late (E, N)
13632             then
13633                raise Pragma_Exit;
13634             end if;
13635
13636             Set_Has_Pragma_Thread_Local_Storage (E);
13637             Set_Has_Gigi_Rep_Item (E);
13638          end Thread_Local_Storage;
13639
13640          ----------------
13641          -- Time_Slice --
13642          ----------------
13643
13644          --  pragma Time_Slice (static_duration_EXPRESSION);
13645
13646          when Pragma_Time_Slice => Time_Slice : declare
13647             Val : Ureal;
13648             Nod : Node_Id;
13649
13650          begin
13651             GNAT_Pragma;
13652             Check_Arg_Count (1);
13653             Check_No_Identifiers;
13654             Check_In_Main_Program;
13655             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13656
13657             if not Error_Posted (Arg1) then
13658                Nod := Next (N);
13659                while Present (Nod) loop
13660                   if Nkind (Nod) = N_Pragma
13661                     and then Pragma_Name (Nod) = Name_Time_Slice
13662                   then
13663                      Error_Msg_Name_1 := Pname;
13664                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13665                   end if;
13666
13667                   Next (Nod);
13668                end loop;
13669             end if;
13670
13671             --  Process only if in main unit
13672
13673             if Get_Source_Unit (Loc) = Main_Unit then
13674                Opt.Time_Slice_Set := True;
13675                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13676
13677                if Val <= Ureal_0 then
13678                   Opt.Time_Slice_Value := 0;
13679
13680                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13681                   Opt.Time_Slice_Value := 1_000_000_000;
13682
13683                else
13684                   Opt.Time_Slice_Value :=
13685                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13686                end if;
13687             end if;
13688          end Time_Slice;
13689
13690          -----------
13691          -- Title --
13692          -----------
13693
13694          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13695
13696          --   TITLING_OPTION ::=
13697          --     [Title =>] STRING_LITERAL
13698          --   | [Subtitle =>] STRING_LITERAL
13699
13700          when Pragma_Title => Title : declare
13701             Args  : Args_List (1 .. 2);
13702             Names : constant Name_List (1 .. 2) := (
13703                       Name_Title,
13704                       Name_Subtitle);
13705
13706          begin
13707             GNAT_Pragma;
13708             Gather_Associations (Names, Args);
13709             Store_Note (N);
13710
13711             for J in 1 .. 2 loop
13712                if Present (Args (J)) then
13713                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13714                end if;
13715             end loop;
13716          end Title;
13717
13718          ---------------------
13719          -- Unchecked_Union --
13720          ---------------------
13721
13722          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13723
13724          when Pragma_Unchecked_Union => Unchecked_Union : declare
13725             Assoc   : constant Node_Id := Arg1;
13726             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13727             Typ     : Entity_Id;
13728             Discr   : Entity_Id;
13729             Tdef    : Node_Id;
13730             Clist   : Node_Id;
13731             Vpart   : Node_Id;
13732             Comp    : Node_Id;
13733             Variant : Node_Id;
13734
13735          begin
13736             Ada_2005_Pragma;
13737             Check_No_Identifiers;
13738             Check_Arg_Count (1);
13739             Check_Arg_Is_Local_Name (Arg1);
13740
13741             Find_Type (Type_Id);
13742             Typ := Entity (Type_Id);
13743
13744             if Typ = Any_Type
13745               or else Rep_Item_Too_Early (Typ, N)
13746             then
13747                return;
13748             else
13749                Typ := Underlying_Type (Typ);
13750             end if;
13751
13752             if Rep_Item_Too_Late (Typ, N) then
13753                return;
13754             end if;
13755
13756             Check_First_Subtype (Arg1);
13757
13758             --  Note remaining cases are references to a type in the current
13759             --  declarative part. If we find an error, we post the error on
13760             --  the relevant type declaration at an appropriate point.
13761
13762             if not Is_Record_Type (Typ) then
13763                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13764                return;
13765
13766             elsif Is_Tagged_Type (Typ) then
13767                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13768                return;
13769
13770             elsif Is_Limited_Type (Typ) then
13771                Error_Msg_N
13772                  ("Unchecked_Union must not be limited record type", Typ);
13773                Explain_Limited_Type (Typ, Typ);
13774                return;
13775
13776             else
13777                if not Has_Discriminants (Typ) then
13778                   Error_Msg_N
13779                     ("Unchecked_Union must have one discriminant", Typ);
13780                   return;
13781                end if;
13782
13783                Discr := First_Discriminant (Typ);
13784                while Present (Discr) loop
13785                   if No (Discriminant_Default_Value (Discr)) then
13786                      Error_Msg_N
13787                        ("Unchecked_Union discriminant must have default value",
13788                         Discr);
13789                   end if;
13790
13791                   Next_Discriminant (Discr);
13792                end loop;
13793
13794                Tdef  := Type_Definition (Declaration_Node (Typ));
13795                Clist := Component_List (Tdef);
13796
13797                Comp := First (Component_Items (Clist));
13798                while Present (Comp) loop
13799                   Check_Component (Comp, Typ);
13800                   Next (Comp);
13801                end loop;
13802
13803                if No (Clist) or else No (Variant_Part (Clist)) then
13804                   Error_Msg_N
13805                     ("Unchecked_Union must have variant part",
13806                      Tdef);
13807                   return;
13808                end if;
13809
13810                Vpart := Variant_Part (Clist);
13811
13812                Variant := First (Variants (Vpart));
13813                while Present (Variant) loop
13814                   Check_Variant (Variant, Typ);
13815                   Next (Variant);
13816                end loop;
13817             end if;
13818
13819             Set_Is_Unchecked_Union  (Typ);
13820             Set_Convention (Typ, Convention_C);
13821             Set_Has_Unchecked_Union (Base_Type (Typ));
13822             Set_Is_Unchecked_Union  (Base_Type (Typ));
13823          end Unchecked_Union;
13824
13825          ------------------------
13826          -- Unimplemented_Unit --
13827          ------------------------
13828
13829          --  pragma Unimplemented_Unit;
13830
13831          --  Note: this only gives an error if we are generating code, or if
13832          --  we are in a generic library unit (where the pragma appears in the
13833          --  body, not in the spec).
13834
13835          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13836             Cunitent : constant Entity_Id :=
13837                          Cunit_Entity (Get_Source_Unit (Loc));
13838             Ent_Kind : constant Entity_Kind :=
13839                          Ekind (Cunitent);
13840
13841          begin
13842             GNAT_Pragma;
13843             Check_Arg_Count (0);
13844
13845             if Operating_Mode = Generate_Code
13846               or else Ent_Kind = E_Generic_Function
13847               or else Ent_Kind = E_Generic_Procedure
13848               or else Ent_Kind = E_Generic_Package
13849             then
13850                Get_Name_String (Chars (Cunitent));
13851                Set_Casing (Mixed_Case);
13852                Write_Str (Name_Buffer (1 .. Name_Len));
13853                Write_Str (" is not supported in this configuration");
13854                Write_Eol;
13855                raise Unrecoverable_Error;
13856             end if;
13857          end Unimplemented_Unit;
13858
13859          ------------------------
13860          -- Universal_Aliasing --
13861          ------------------------
13862
13863          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13864
13865          when Pragma_Universal_Aliasing => Universal_Alias : declare
13866             E_Id : Entity_Id;
13867
13868          begin
13869             GNAT_Pragma;
13870             Check_Arg_Count (1);
13871             Check_Optional_Identifier (Arg2, Name_Entity);
13872             Check_Arg_Is_Local_Name (Arg1);
13873             E_Id := Entity (Get_Pragma_Arg (Arg1));
13874
13875             if E_Id = Any_Type then
13876                return;
13877             elsif No (E_Id) or else not Is_Type (E_Id) then
13878                Error_Pragma_Arg ("pragma% requires type", Arg1);
13879             end if;
13880
13881             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13882          end Universal_Alias;
13883
13884          --------------------
13885          -- Universal_Data --
13886          --------------------
13887
13888          --  pragma Universal_Data [(library_unit_NAME)];
13889
13890          when Pragma_Universal_Data =>
13891             GNAT_Pragma;
13892
13893             --  If this is a configuration pragma, then set the universal
13894             --  addressing option, otherwise confirm that the pragma satisfies
13895             --  the requirements of library unit pragma placement and leave it
13896             --  to the GNAAMP back end to detect the pragma (avoids transitive
13897             --  setting of the option due to withed units).
13898
13899             if Is_Configuration_Pragma then
13900                Universal_Addressing_On_AAMP := True;
13901             else
13902                Check_Valid_Library_Unit_Pragma;
13903             end if;
13904
13905             if not AAMP_On_Target then
13906                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13907             end if;
13908
13909          ----------------
13910          -- Unmodified --
13911          ----------------
13912
13913          --  pragma Unmodified (local_Name {, local_Name});
13914
13915          when Pragma_Unmodified => Unmodified : declare
13916             Arg_Node : Node_Id;
13917             Arg_Expr : Node_Id;
13918             Arg_Ent  : Entity_Id;
13919
13920          begin
13921             GNAT_Pragma;
13922             Check_At_Least_N_Arguments (1);
13923
13924             --  Loop through arguments
13925
13926             Arg_Node := Arg1;
13927             while Present (Arg_Node) loop
13928                Check_No_Identifier (Arg_Node);
13929
13930                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13931                --  in fact generate reference, so that the entity will have a
13932                --  reference, which will inhibit any warnings about it not
13933                --  being referenced, and also properly show up in the ali file
13934                --  as a reference. But this reference is recorded before the
13935                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13936                --  generated for this reference.
13937
13938                Check_Arg_Is_Local_Name (Arg_Node);
13939                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13940
13941                if Is_Entity_Name (Arg_Expr) then
13942                   Arg_Ent := Entity (Arg_Expr);
13943
13944                   if not Is_Assignable (Arg_Ent) then
13945                      Error_Pragma_Arg
13946                        ("pragma% can only be applied to a variable",
13947                         Arg_Expr);
13948                   else
13949                      Set_Has_Pragma_Unmodified (Arg_Ent);
13950                   end if;
13951                end if;
13952
13953                Next (Arg_Node);
13954             end loop;
13955          end Unmodified;
13956
13957          ------------------
13958          -- Unreferenced --
13959          ------------------
13960
13961          --  pragma Unreferenced (local_Name {, local_Name});
13962
13963          --    or when used in a context clause:
13964
13965          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13966
13967          when Pragma_Unreferenced => Unreferenced : declare
13968             Arg_Node : Node_Id;
13969             Arg_Expr : Node_Id;
13970             Arg_Ent  : Entity_Id;
13971             Citem    : Node_Id;
13972
13973          begin
13974             GNAT_Pragma;
13975             Check_At_Least_N_Arguments (1);
13976
13977             --  Check case of appearing within context clause
13978
13979             if Is_In_Context_Clause then
13980
13981                --  The arguments must all be units mentioned in a with clause
13982                --  in the same context clause. Note we already checked (in
13983                --  Par.Prag) that the arguments are either identifiers or
13984                --  selected components.
13985
13986                Arg_Node := Arg1;
13987                while Present (Arg_Node) loop
13988                   Citem := First (List_Containing (N));
13989                   while Citem /= N loop
13990                      if Nkind (Citem) = N_With_Clause
13991                        and then
13992                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13993                      then
13994                         Set_Has_Pragma_Unreferenced
13995                           (Cunit_Entity
13996                              (Get_Source_Unit
13997                                 (Library_Unit (Citem))));
13998                         Set_Unit_Name
13999                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
14000                         exit;
14001                      end if;
14002
14003                      Next (Citem);
14004                   end loop;
14005
14006                   if Citem = N then
14007                      Error_Pragma_Arg
14008                        ("argument of pragma% is not with'ed unit", Arg_Node);
14009                   end if;
14010
14011                   Next (Arg_Node);
14012                end loop;
14013
14014             --  Case of not in list of context items
14015
14016             else
14017                Arg_Node := Arg1;
14018                while Present (Arg_Node) loop
14019                   Check_No_Identifier (Arg_Node);
14020
14021                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
14022                   --  will in fact generate reference, so that the entity will
14023                   --  have a reference, which will inhibit any warnings about
14024                   --  it not being referenced, and also properly show up in the
14025                   --  ali file as a reference. But this reference is recorded
14026                   --  before the Has_Pragma_Unreferenced flag is set, so that
14027                   --  no warning is generated for this reference.
14028
14029                   Check_Arg_Is_Local_Name (Arg_Node);
14030                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
14031
14032                   if Is_Entity_Name (Arg_Expr) then
14033                      Arg_Ent := Entity (Arg_Expr);
14034
14035                      --  If the entity is overloaded, the pragma applies to the
14036                      --  most recent overloading, as documented. In this case,
14037                      --  name resolution does not generate a reference, so it
14038                      --  must be done here explicitly.
14039
14040                      if Is_Overloaded (Arg_Expr) then
14041                         Generate_Reference (Arg_Ent, N);
14042                      end if;
14043
14044                      Set_Has_Pragma_Unreferenced (Arg_Ent);
14045                   end if;
14046
14047                   Next (Arg_Node);
14048                end loop;
14049             end if;
14050          end Unreferenced;
14051
14052          --------------------------
14053          -- Unreferenced_Objects --
14054          --------------------------
14055
14056          --  pragma Unreferenced_Objects (local_Name {, local_Name});
14057
14058          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
14059             Arg_Node : Node_Id;
14060             Arg_Expr : Node_Id;
14061
14062          begin
14063             GNAT_Pragma;
14064             Check_At_Least_N_Arguments (1);
14065
14066             Arg_Node := Arg1;
14067             while Present (Arg_Node) loop
14068                Check_No_Identifier (Arg_Node);
14069                Check_Arg_Is_Local_Name (Arg_Node);
14070                Arg_Expr := Get_Pragma_Arg (Arg_Node);
14071
14072                if not Is_Entity_Name (Arg_Expr)
14073                  or else not Is_Type (Entity (Arg_Expr))
14074                then
14075                   Error_Pragma_Arg
14076                     ("argument for pragma% must be type or subtype", Arg_Node);
14077                end if;
14078
14079                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
14080                Next (Arg_Node);
14081             end loop;
14082          end Unreferenced_Objects;
14083
14084          ------------------------------
14085          -- Unreserve_All_Interrupts --
14086          ------------------------------
14087
14088          --  pragma Unreserve_All_Interrupts;
14089
14090          when Pragma_Unreserve_All_Interrupts =>
14091             GNAT_Pragma;
14092             Check_Arg_Count (0);
14093
14094             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
14095                Unreserve_All_Interrupts := True;
14096             end if;
14097
14098          ----------------
14099          -- Unsuppress --
14100          ----------------
14101
14102          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
14103
14104          when Pragma_Unsuppress =>
14105             Ada_2005_Pragma;
14106             Process_Suppress_Unsuppress (False);
14107
14108          -------------------
14109          -- Use_VADS_Size --
14110          -------------------
14111
14112          --  pragma Use_VADS_Size;
14113
14114          when Pragma_Use_VADS_Size =>
14115             GNAT_Pragma;
14116             Check_Arg_Count (0);
14117             Check_Valid_Configuration_Pragma;
14118             Use_VADS_Size := True;
14119
14120          ---------------------
14121          -- Validity_Checks --
14122          ---------------------
14123
14124          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
14125
14126          when Pragma_Validity_Checks => Validity_Checks : declare
14127             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
14128             S  : String_Id;
14129             C  : Char_Code;
14130
14131          begin
14132             GNAT_Pragma;
14133             Check_Arg_Count (1);
14134             Check_No_Identifiers;
14135
14136             if Nkind (A) = N_String_Literal then
14137                S   := Strval (A);
14138
14139                declare
14140                   Slen    : constant Natural := Natural (String_Length (S));
14141                   Options : String (1 .. Slen);
14142                   J       : Natural;
14143
14144                begin
14145                   J := 1;
14146                   loop
14147                      C := Get_String_Char (S, Int (J));
14148                      exit when not In_Character_Range (C);
14149                      Options (J) := Get_Character (C);
14150
14151                      if J = Slen then
14152                         Set_Validity_Check_Options (Options);
14153                         exit;
14154                      else
14155                         J := J + 1;
14156                      end if;
14157                   end loop;
14158                end;
14159
14160             elsif Nkind (A) = N_Identifier then
14161
14162                if Chars (A) = Name_All_Checks then
14163                   Set_Validity_Check_Options ("a");
14164
14165                elsif Chars (A) = Name_On then
14166                   Validity_Checks_On := True;
14167
14168                elsif Chars (A) = Name_Off then
14169                   Validity_Checks_On := False;
14170
14171                end if;
14172             end if;
14173          end Validity_Checks;
14174
14175          --------------
14176          -- Volatile --
14177          --------------
14178
14179          --  pragma Volatile (LOCAL_NAME);
14180
14181          when Pragma_Volatile =>
14182             Process_Atomic_Shared_Volatile;
14183
14184          -------------------------
14185          -- Volatile_Components --
14186          -------------------------
14187
14188          --  pragma Volatile_Components (array_LOCAL_NAME);
14189
14190          --  Volatile is handled by the same circuit as Atomic_Components
14191
14192          --------------
14193          -- Warnings --
14194          --------------
14195
14196          --  pragma Warnings (On | Off);
14197          --  pragma Warnings (On | Off, LOCAL_NAME);
14198          --  pragma Warnings (static_string_EXPRESSION);
14199          --  pragma Warnings (On | Off, STRING_LITERAL);
14200
14201          when Pragma_Warnings => Warnings : begin
14202             GNAT_Pragma;
14203             Check_At_Least_N_Arguments (1);
14204             Check_No_Identifiers;
14205
14206             --  If debug flag -gnatd.i is set, pragma is ignored
14207
14208             if Debug_Flag_Dot_I then
14209                return;
14210             end if;
14211
14212             --  Process various forms of the pragma
14213
14214             declare
14215                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
14216
14217             begin
14218                --  One argument case
14219
14220                if Arg_Count = 1 then
14221
14222                   --  On/Off one argument case was processed by parser
14223
14224                   if Nkind (Argx) = N_Identifier
14225                     and then
14226                       (Chars (Argx) = Name_On
14227                          or else
14228                        Chars (Argx) = Name_Off)
14229                   then
14230                      null;
14231
14232                   --  One argument case must be ON/OFF or static string expr
14233
14234                   elsif not Is_Static_String_Expression (Arg1) then
14235                      Error_Pragma_Arg
14236                        ("argument of pragma% must be On/Off or " &
14237                         "static string expression", Arg1);
14238
14239                   --  One argument string expression case
14240
14241                   else
14242                      declare
14243                         Lit : constant Node_Id   := Expr_Value_S (Argx);
14244                         Str : constant String_Id := Strval (Lit);
14245                         Len : constant Nat       := String_Length (Str);
14246                         C   : Char_Code;
14247                         J   : Nat;
14248                         OK  : Boolean;
14249                         Chr : Character;
14250
14251                      begin
14252                         J := 1;
14253                         while J <= Len loop
14254                            C := Get_String_Char (Str, J);
14255                            OK := In_Character_Range (C);
14256
14257                            if OK then
14258                               Chr := Get_Character (C);
14259
14260                               --  Dot case
14261
14262                               if J < Len and then Chr = '.' then
14263                                  J := J + 1;
14264                                  C := Get_String_Char (Str, J);
14265                                  Chr := Get_Character (C);
14266
14267                                  if not Set_Dot_Warning_Switch (Chr) then
14268                                     Error_Pragma_Arg
14269                                       ("invalid warning switch character " &
14270                                        '.' & Chr, Arg1);
14271                                  end if;
14272
14273                               --  Non-Dot case
14274
14275                               else
14276                                  OK := Set_Warning_Switch (Chr);
14277                               end if;
14278                            end if;
14279
14280                            if not OK then
14281                               Error_Pragma_Arg
14282                                 ("invalid warning switch character " & Chr,
14283                                  Arg1);
14284                            end if;
14285
14286                            J := J + 1;
14287                         end loop;
14288                      end;
14289                   end if;
14290
14291                   --  Two or more arguments (must be two)
14292
14293                else
14294                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14295                   Check_At_Most_N_Arguments (2);
14296
14297                   declare
14298                      E_Id : Node_Id;
14299                      E    : Entity_Id;
14300                      Err  : Boolean;
14301
14302                   begin
14303                      E_Id := Get_Pragma_Arg (Arg2);
14304                      Analyze (E_Id);
14305
14306                      --  In the expansion of an inlined body, a reference to
14307                      --  the formal may be wrapped in a conversion if the
14308                      --  actual is a conversion. Retrieve the real entity name.
14309
14310                      if (In_Instance_Body
14311                          or else In_Inlined_Body)
14312                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14313                      then
14314                         E_Id := Expression (E_Id);
14315                      end if;
14316
14317                      --  Entity name case
14318
14319                      if Is_Entity_Name (E_Id) then
14320                         E := Entity (E_Id);
14321
14322                         if E = Any_Id then
14323                            return;
14324                         else
14325                            loop
14326                               Set_Warnings_Off
14327                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14328                                                               Name_Off));
14329
14330                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14331                                 and then Warn_On_Warnings_Off
14332                               then
14333                                  Warnings_Off_Pragmas.Append ((N, E));
14334                               end if;
14335
14336                               if Is_Enumeration_Type (E) then
14337                                  declare
14338                                     Lit : Entity_Id;
14339                                  begin
14340                                     Lit := First_Literal (E);
14341                                     while Present (Lit) loop
14342                                        Set_Warnings_Off (Lit);
14343                                        Next_Literal (Lit);
14344                                     end loop;
14345                                  end;
14346                               end if;
14347
14348                               exit when No (Homonym (E));
14349                               E := Homonym (E);
14350                            end loop;
14351                         end if;
14352
14353                      --  Error if not entity or static string literal case
14354
14355                      elsif not Is_Static_String_Expression (Arg2) then
14356                         Error_Pragma_Arg
14357                           ("second argument of pragma% must be entity " &
14358                            "name or static string expression", Arg2);
14359
14360                      --  String literal case
14361
14362                      else
14363                         String_To_Name_Buffer
14364                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14365
14366                         --  Note on configuration pragma case: If this is a
14367                         --  configuration pragma, then for an OFF pragma, we
14368                         --  just set Config True in the call, which is all
14369                         --  that needs to be done. For the case of ON, this
14370                         --  is normally an error, unless it is canceling the
14371                         --  effect of a previous OFF pragma in the same file.
14372                         --  In any other case, an error will be signalled (ON
14373                         --  with no matching OFF).
14374
14375                         if Chars (Argx) = Name_Off then
14376                            Set_Specific_Warning_Off
14377                              (Loc, Name_Buffer (1 .. Name_Len),
14378                               Config => Is_Configuration_Pragma);
14379
14380                         elsif Chars (Argx) = Name_On then
14381                            Set_Specific_Warning_On
14382                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14383
14384                            if Err then
14385                               Error_Msg
14386                                 ("?pragma Warnings On with no " &
14387                                  "matching Warnings Off",
14388                                  Loc);
14389                            end if;
14390                         end if;
14391                      end if;
14392                   end;
14393                end if;
14394             end;
14395          end Warnings;
14396
14397          -------------------
14398          -- Weak_External --
14399          -------------------
14400
14401          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14402
14403          when Pragma_Weak_External => Weak_External : declare
14404             Ent : Entity_Id;
14405
14406          begin
14407             GNAT_Pragma;
14408             Check_Arg_Count (1);
14409             Check_Optional_Identifier (Arg1, Name_Entity);
14410             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14411             Ent := Entity (Get_Pragma_Arg (Arg1));
14412
14413             if Rep_Item_Too_Early (Ent, N) then
14414                return;
14415             else
14416                Ent := Underlying_Type (Ent);
14417             end if;
14418
14419             --  The only processing required is to link this item on to the
14420             --  list of rep items for the given entity. This is accomplished
14421             --  by the call to Rep_Item_Too_Late (when no error is detected
14422             --  and False is returned).
14423
14424             if Rep_Item_Too_Late (Ent, N) then
14425                return;
14426             else
14427                Set_Has_Gigi_Rep_Item (Ent);
14428             end if;
14429          end Weak_External;
14430
14431          -----------------------------
14432          -- Wide_Character_Encoding --
14433          -----------------------------
14434
14435          --  pragma Wide_Character_Encoding (IDENTIFIER);
14436
14437          when Pragma_Wide_Character_Encoding =>
14438             GNAT_Pragma;
14439
14440             --  Nothing to do, handled in parser. Note that we do not enforce
14441             --  configuration pragma placement, this pragma can appear at any
14442             --  place in the source, allowing mixed encodings within a single
14443             --  source program.
14444
14445             null;
14446
14447          --------------------
14448          -- Unknown_Pragma --
14449          --------------------
14450
14451          --  Should be impossible, since the case of an unknown pragma is
14452          --  separately processed before the case statement is entered.
14453
14454          when Unknown_Pragma =>
14455             raise Program_Error;
14456       end case;
14457
14458       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14459       --  until AI is formally approved.
14460
14461       --  Check_Order_Dependence;
14462
14463    exception
14464       when Pragma_Exit => null;
14465    end Analyze_Pragma;
14466
14467    -----------------------------
14468    -- Analyze_TC_In_Decl_Part --
14469    -----------------------------
14470
14471    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14472    begin
14473       --  Install formals and push subprogram spec onto scope stack so that we
14474       --  can see the formals from the pragma.
14475
14476       Install_Formals (S);
14477       Push_Scope (S);
14478
14479       --  Preanalyze the boolean expressions, we treat these as spec
14480       --  expressions (i.e. similar to a default expression).
14481
14482       Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14483                           Get_Ensures_From_Test_Case_Pragma (N));
14484
14485       --  Remove the subprogram from the scope stack now that the pre-analysis
14486       --  of the expressions in the test-case is done.
14487
14488       End_Scope;
14489    end Analyze_TC_In_Decl_Part;
14490
14491    --------------------
14492    -- Check_Disabled --
14493    --------------------
14494
14495    function Check_Disabled (Nam : Name_Id) return Boolean is
14496       PP : Node_Id;
14497
14498    begin
14499       --  Loop through entries in check policy list
14500
14501       PP := Opt.Check_Policy_List;
14502       loop
14503          --  If there are no specific entries that matched, then nothing is
14504          --  disabled, so return False.
14505
14506          if No (PP) then
14507             return False;
14508
14509          --  Here we have an entry see if it matches
14510
14511          else
14512             declare
14513                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14514             begin
14515                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14516                   return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14517                else
14518                   PP := Next_Pragma (PP);
14519                end if;
14520             end;
14521          end if;
14522       end loop;
14523    end Check_Disabled;
14524
14525    -------------------
14526    -- Check_Enabled --
14527    -------------------
14528
14529    function Check_Enabled (Nam : Name_Id) return Boolean is
14530       PP : Node_Id;
14531
14532    begin
14533       --  Loop through entries in check policy list
14534
14535       PP := Opt.Check_Policy_List;
14536       loop
14537          --  If there are no specific entries that matched, then we let the
14538          --  setting of assertions govern. Note that this provides the needed
14539          --  compatibility with the RM for the cases of assertion, invariant,
14540          --  precondition, predicate, and postcondition.
14541
14542          if No (PP) then
14543             return Assertions_Enabled;
14544
14545          --  Here we have an entry see if it matches
14546
14547          else
14548             declare
14549                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14550
14551             begin
14552                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14553                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14554                      when Name_On | Name_Check =>
14555                         return True;
14556                      when Name_Off | Name_Ignore =>
14557                         return False;
14558                      when others =>
14559                         raise Program_Error;
14560                   end case;
14561
14562                else
14563                   PP := Next_Pragma (PP);
14564                end if;
14565             end;
14566          end if;
14567       end loop;
14568    end Check_Enabled;
14569
14570    ---------------------------------
14571    -- Delay_Config_Pragma_Analyze --
14572    ---------------------------------
14573
14574    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14575    begin
14576       return Pragma_Name (N) = Name_Interrupt_State
14577                or else
14578              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14579    end Delay_Config_Pragma_Analyze;
14580
14581    -------------------------
14582    -- Get_Base_Subprogram --
14583    -------------------------
14584
14585    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14586       Result : Entity_Id;
14587
14588    begin
14589       --  Follow subprogram renaming chain
14590
14591       Result := Def_Id;
14592       while Is_Subprogram (Result)
14593         and then
14594           Nkind (Parent (Declaration_Node (Result))) =
14595                                          N_Subprogram_Renaming_Declaration
14596         and then Present (Alias (Result))
14597       loop
14598          Result := Alias (Result);
14599       end loop;
14600
14601       return Result;
14602    end Get_Base_Subprogram;
14603
14604    ----------------
14605    -- Initialize --
14606    ----------------
14607
14608    procedure Initialize is
14609    begin
14610       Externals.Init;
14611    end Initialize;
14612
14613    -----------------------------
14614    -- Is_Config_Static_String --
14615    -----------------------------
14616
14617    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14618
14619       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14620       --  This is an internal recursive function that is just like the outer
14621       --  function except that it adds the string to the name buffer rather
14622       --  than placing the string in the name buffer.
14623
14624       ------------------------------
14625       -- Add_Config_Static_String --
14626       ------------------------------
14627
14628       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14629          N : Node_Id;
14630          C : Char_Code;
14631
14632       begin
14633          N := Arg;
14634
14635          if Nkind (N) = N_Op_Concat then
14636             if Add_Config_Static_String (Left_Opnd (N)) then
14637                N := Right_Opnd (N);
14638             else
14639                return False;
14640             end if;
14641          end if;
14642
14643          if Nkind (N) /= N_String_Literal then
14644             Error_Msg_N ("string literal expected for pragma argument", N);
14645             return False;
14646
14647          else
14648             for J in 1 .. String_Length (Strval (N)) loop
14649                C := Get_String_Char (Strval (N), J);
14650
14651                if not In_Character_Range (C) then
14652                   Error_Msg
14653                     ("string literal contains invalid wide character",
14654                      Sloc (N) + 1 + Source_Ptr (J));
14655                   return False;
14656                end if;
14657
14658                Add_Char_To_Name_Buffer (Get_Character (C));
14659             end loop;
14660          end if;
14661
14662          return True;
14663       end Add_Config_Static_String;
14664
14665    --  Start of processing for Is_Config_Static_String
14666
14667    begin
14668
14669       Name_Len := 0;
14670       return Add_Config_Static_String (Arg);
14671    end Is_Config_Static_String;
14672
14673    -----------------------------------------
14674    -- Is_Non_Significant_Pragma_Reference --
14675    -----------------------------------------
14676
14677    --  This function makes use of the following static table which indicates
14678    --  whether a given pragma is significant.
14679
14680    --  -1  indicates that references in any argument position are significant
14681    --  0   indicates that appearance in any argument is not significant
14682    --  +n  indicates that appearance as argument n is significant, but all
14683    --      other arguments are not significant
14684    --  99  special processing required (e.g. for pragma Check)
14685
14686    Sig_Flags : constant array (Pragma_Id) of Int :=
14687      (Pragma_AST_Entry                     => -1,
14688       Pragma_Abort_Defer                   => -1,
14689       Pragma_Ada_83                        => -1,
14690       Pragma_Ada_95                        => -1,
14691       Pragma_Ada_05                        => -1,
14692       Pragma_Ada_2005                      => -1,
14693       Pragma_Ada_12                        => -1,
14694       Pragma_Ada_2012                      => -1,
14695       Pragma_All_Calls_Remote              => -1,
14696       Pragma_Annotate                      => -1,
14697       Pragma_Assert                        => -1,
14698       Pragma_Assertion_Policy              =>  0,
14699       Pragma_Assume_No_Invalid_Values      =>  0,
14700       Pragma_Asynchronous                  => -1,
14701       Pragma_Atomic                        =>  0,
14702       Pragma_Atomic_Components             =>  0,
14703       Pragma_Attach_Handler                => -1,
14704       Pragma_Check                         => 99,
14705       Pragma_Check_Name                    =>  0,
14706       Pragma_Check_Policy                  =>  0,
14707       Pragma_CIL_Constructor               => -1,
14708       Pragma_CPP_Class                     =>  0,
14709       Pragma_CPP_Constructor               =>  0,
14710       Pragma_CPP_Virtual                   =>  0,
14711       Pragma_CPP_Vtable                    =>  0,
14712       Pragma_CPU                           => -1,
14713       Pragma_C_Pass_By_Copy                =>  0,
14714       Pragma_Comment                       =>  0,
14715       Pragma_Common_Object                 => -1,
14716       Pragma_Compile_Time_Error            => -1,
14717       Pragma_Compile_Time_Warning          => -1,
14718       Pragma_Compiler_Unit                 =>  0,
14719       Pragma_Complete_Representation       =>  0,
14720       Pragma_Complex_Representation        =>  0,
14721       Pragma_Component_Alignment           => -1,
14722       Pragma_Controlled                    =>  0,
14723       Pragma_Convention                    =>  0,
14724       Pragma_Convention_Identifier         =>  0,
14725       Pragma_Debug                         => -1,
14726       Pragma_Debug_Policy                  =>  0,
14727       Pragma_Detect_Blocking               => -1,
14728       Pragma_Default_Storage_Pool          => -1,
14729       Pragma_Dimension                     => -1,
14730       Pragma_Discard_Names                 =>  0,
14731       Pragma_Dispatching_Domain            => -1,
14732       Pragma_Elaborate                     => -1,
14733       Pragma_Elaborate_All                 => -1,
14734       Pragma_Elaborate_Body                => -1,
14735       Pragma_Elaboration_Checks            => -1,
14736       Pragma_Eliminate                     => -1,
14737       Pragma_Export                        => -1,
14738       Pragma_Export_Exception              => -1,
14739       Pragma_Export_Function               => -1,
14740       Pragma_Export_Object                 => -1,
14741       Pragma_Export_Procedure              => -1,
14742       Pragma_Export_Value                  => -1,
14743       Pragma_Export_Valued_Procedure       => -1,
14744       Pragma_Extend_System                 => -1,
14745       Pragma_Extensions_Allowed            => -1,
14746       Pragma_External                      => -1,
14747       Pragma_Favor_Top_Level               => -1,
14748       Pragma_External_Name_Casing          => -1,
14749       Pragma_Fast_Math                     => -1,
14750       Pragma_Finalize_Storage_Only         =>  0,
14751       Pragma_Float_Representation          =>  0,
14752       Pragma_Ident                         => -1,
14753       Pragma_Implementation_Defined        => -1,
14754       Pragma_Implemented                   => -1,
14755       Pragma_Implicit_Packing              =>  0,
14756       Pragma_Import                        => +2,
14757       Pragma_Import_Exception              =>  0,
14758       Pragma_Import_Function               =>  0,
14759       Pragma_Import_Object                 =>  0,
14760       Pragma_Import_Procedure              =>  0,
14761       Pragma_Import_Valued_Procedure       =>  0,
14762       Pragma_Independent                   =>  0,
14763       Pragma_Independent_Components        =>  0,
14764       Pragma_Initialize_Scalars            => -1,
14765       Pragma_Inline                        =>  0,
14766       Pragma_Inline_Always                 =>  0,
14767       Pragma_Inline_Generic                =>  0,
14768       Pragma_Inspection_Point              => -1,
14769       Pragma_Interface                     => +2,
14770       Pragma_Interface_Name                => +2,
14771       Pragma_Interrupt_Handler             => -1,
14772       Pragma_Interrupt_Priority            => -1,
14773       Pragma_Interrupt_State               => -1,
14774       Pragma_Invariant                     => -1,
14775       Pragma_Java_Constructor              => -1,
14776       Pragma_Java_Interface                => -1,
14777       Pragma_Keep_Names                    =>  0,
14778       Pragma_License                       => -1,
14779       Pragma_Link_With                     => -1,
14780       Pragma_Linker_Alias                  => -1,
14781       Pragma_Linker_Constructor            => -1,
14782       Pragma_Linker_Destructor             => -1,
14783       Pragma_Linker_Options                => -1,
14784       Pragma_Linker_Section                => -1,
14785       Pragma_List                          => -1,
14786       Pragma_Locking_Policy                => -1,
14787       Pragma_Long_Float                    => -1,
14788       Pragma_Machine_Attribute             => -1,
14789       Pragma_Main                          => -1,
14790       Pragma_Main_Storage                  => -1,
14791       Pragma_Memory_Size                   => -1,
14792       Pragma_No_Return                     =>  0,
14793       Pragma_No_Body                       =>  0,
14794       Pragma_No_Run_Time                   => -1,
14795       Pragma_No_Strict_Aliasing            => -1,
14796       Pragma_Normalize_Scalars             => -1,
14797       Pragma_Obsolescent                   =>  0,
14798       Pragma_Optimize                      => -1,
14799       Pragma_Optimize_Alignment            => -1,
14800       Pragma_Ordered                       =>  0,
14801       Pragma_Pack                          =>  0,
14802       Pragma_Page                          => -1,
14803       Pragma_Passive                       => -1,
14804       Pragma_Preelaborable_Initialization  => -1,
14805       Pragma_Polling                       => -1,
14806       Pragma_Persistent_BSS                =>  0,
14807       Pragma_Postcondition                 => -1,
14808       Pragma_Precondition                  => -1,
14809       Pragma_Predicate                     => -1,
14810       Pragma_Preelaborate                  => -1,
14811       Pragma_Preelaborate_05               => -1,
14812       Pragma_Priority                      => -1,
14813       Pragma_Priority_Specific_Dispatching => -1,
14814       Pragma_Profile                       =>  0,
14815       Pragma_Profile_Warnings              =>  0,
14816       Pragma_Propagate_Exceptions          => -1,
14817       Pragma_Psect_Object                  => -1,
14818       Pragma_Pure                          => -1,
14819       Pragma_Pure_05                       => -1,
14820       Pragma_Pure_Function                 => -1,
14821       Pragma_Queuing_Policy                => -1,
14822       Pragma_Ravenscar                     => -1,
14823       Pragma_Relative_Deadline             => -1,
14824       Pragma_Remote_Call_Interface         => -1,
14825       Pragma_Remote_Types                  => -1,
14826       Pragma_Restricted_Run_Time           => -1,
14827       Pragma_Restriction_Warnings          => -1,
14828       Pragma_Restrictions                  => -1,
14829       Pragma_Reviewable                    => -1,
14830       Pragma_Short_Circuit_And_Or          => -1,
14831       Pragma_Share_Generic                 => -1,
14832       Pragma_Shared                        => -1,
14833       Pragma_Shared_Passive                => -1,
14834       Pragma_Short_Descriptors             =>  0,
14835       Pragma_Source_File_Name              => -1,
14836       Pragma_Source_File_Name_Project      => -1,
14837       Pragma_Source_Reference              => -1,
14838       Pragma_Storage_Size                  => -1,
14839       Pragma_Storage_Unit                  => -1,
14840       Pragma_Static_Elaboration_Desired    => -1,
14841       Pragma_Stream_Convert                => -1,
14842       Pragma_Style_Checks                  => -1,
14843       Pragma_Subtitle                      => -1,
14844       Pragma_Suppress                      =>  0,
14845       Pragma_Suppress_Exception_Locations  =>  0,
14846       Pragma_Suppress_All                  => -1,
14847       Pragma_Suppress_Debug_Info           =>  0,
14848       Pragma_Suppress_Initialization       =>  0,
14849       Pragma_System_Name                   => -1,
14850       Pragma_Task_Dispatching_Policy       => -1,
14851       Pragma_Task_Info                     => -1,
14852       Pragma_Task_Name                     => -1,
14853       Pragma_Task_Storage                  =>  0,
14854       Pragma_Test_Case                     => -1,
14855       Pragma_Thread_Local_Storage          =>  0,
14856       Pragma_Time_Slice                    => -1,
14857       Pragma_Title                         => -1,
14858       Pragma_Unchecked_Union               =>  0,
14859       Pragma_Unimplemented_Unit            => -1,
14860       Pragma_Universal_Aliasing            => -1,
14861       Pragma_Universal_Data                => -1,
14862       Pragma_Unmodified                    => -1,
14863       Pragma_Unreferenced                  => -1,
14864       Pragma_Unreferenced_Objects          => -1,
14865       Pragma_Unreserve_All_Interrupts      => -1,
14866       Pragma_Unsuppress                    =>  0,
14867       Pragma_Use_VADS_Size                 => -1,
14868       Pragma_Validity_Checks               => -1,
14869       Pragma_Volatile                      =>  0,
14870       Pragma_Volatile_Components           =>  0,
14871       Pragma_Warnings                      => -1,
14872       Pragma_Weak_External                 => -1,
14873       Pragma_Wide_Character_Encoding       =>  0,
14874       Unknown_Pragma                       =>  0);
14875
14876    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14877       Id : Pragma_Id;
14878       P  : Node_Id;
14879       C  : Int;
14880       A  : Node_Id;
14881
14882    begin
14883       P := Parent (N);
14884
14885       if Nkind (P) /= N_Pragma_Argument_Association then
14886          return False;
14887
14888       else
14889          Id := Get_Pragma_Id (Parent (P));
14890          C := Sig_Flags (Id);
14891
14892          case C is
14893             when -1 =>
14894                return False;
14895
14896             when 0 =>
14897                return True;
14898
14899             when 99 =>
14900                case Id is
14901
14902                   --  For pragma Check, the first argument is not significant,
14903                   --  the second and the third (if present) arguments are
14904                   --  significant.
14905
14906                   when Pragma_Check =>
14907                      return
14908                        P = First (Pragma_Argument_Associations (Parent (P)));
14909
14910                   when others =>
14911                      raise Program_Error;
14912                end case;
14913
14914             when others =>
14915                A := First (Pragma_Argument_Associations (Parent (P)));
14916                for J in 1 .. C - 1 loop
14917                   if No (A) then
14918                      return False;
14919                   end if;
14920
14921                   Next (A);
14922                end loop;
14923
14924                return A = P; -- is this wrong way round ???
14925          end case;
14926       end if;
14927    end Is_Non_Significant_Pragma_Reference;
14928
14929    ------------------------------
14930    -- Is_Pragma_String_Literal --
14931    ------------------------------
14932
14933    --  This function returns true if the corresponding pragma argument is a
14934    --  static string expression. These are the only cases in which string
14935    --  literals can appear as pragma arguments. We also allow a string literal
14936    --  as the first argument to pragma Assert (although it will of course
14937    --  always generate a type error).
14938
14939    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14940       Pragn : constant Node_Id := Parent (Par);
14941       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14942       Pname : constant Name_Id := Pragma_Name (Pragn);
14943       Argn  : Natural;
14944       N     : Node_Id;
14945
14946    begin
14947       Argn := 1;
14948       N := First (Assoc);
14949       loop
14950          exit when N = Par;
14951          Argn := Argn + 1;
14952          Next (N);
14953       end loop;
14954
14955       if Pname = Name_Assert then
14956          return True;
14957
14958       elsif Pname = Name_Export then
14959          return Argn > 2;
14960
14961       elsif Pname = Name_Ident then
14962          return Argn = 1;
14963
14964       elsif Pname = Name_Import then
14965          return Argn > 2;
14966
14967       elsif Pname = Name_Interface_Name then
14968          return Argn > 1;
14969
14970       elsif Pname = Name_Linker_Alias then
14971          return Argn = 2;
14972
14973       elsif Pname = Name_Linker_Section then
14974          return Argn = 2;
14975
14976       elsif Pname = Name_Machine_Attribute then
14977          return Argn = 2;
14978
14979       elsif Pname = Name_Source_File_Name then
14980          return True;
14981
14982       elsif Pname = Name_Source_Reference then
14983          return Argn = 2;
14984
14985       elsif Pname = Name_Title then
14986          return True;
14987
14988       elsif Pname = Name_Subtitle then
14989          return True;
14990
14991       else
14992          return False;
14993       end if;
14994    end Is_Pragma_String_Literal;
14995
14996    ------------------------
14997    -- Preanalyze_TC_Args --
14998    ------------------------
14999
15000    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
15001    begin
15002       --  Preanalyze the boolean expressions, we treat these as spec
15003       --  expressions (i.e. similar to a default expression).
15004
15005       if Present (Arg_Req) then
15006          Preanalyze_Spec_Expression
15007            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
15008       end if;
15009
15010       if Present (Arg_Ens) then
15011          Preanalyze_Spec_Expression
15012            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
15013       end if;
15014    end Preanalyze_TC_Args;
15015
15016    --------------------------------------
15017    -- Process_Compilation_Unit_Pragmas --
15018    --------------------------------------
15019
15020    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
15021    begin
15022       --  A special check for pragma Suppress_All, a very strange DEC pragma,
15023       --  strange because it comes at the end of the unit. Rational has the
15024       --  same name for a pragma, but treats it as a program unit pragma, In
15025       --  GNAT we just decide to allow it anywhere at all. If it appeared then
15026       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
15027       --  node, and we insert a pragma Suppress (All_Checks) at the start of
15028       --  the context clause to ensure the correct processing.
15029
15030       if Has_Pragma_Suppress_All (N) then
15031          Prepend_To (Context_Items (N),
15032            Make_Pragma (Sloc (N),
15033              Chars                        => Name_Suppress,
15034              Pragma_Argument_Associations => New_List (
15035                Make_Pragma_Argument_Association (Sloc (N),
15036                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
15037       end if;
15038
15039       --  Nothing else to do at the current time!
15040
15041    end Process_Compilation_Unit_Pragmas;
15042
15043    --------
15044    -- rv --
15045    --------
15046
15047    procedure rv is
15048    begin
15049       null;
15050    end rv;
15051
15052    --------------------------------
15053    -- Set_Encoded_Interface_Name --
15054    --------------------------------
15055
15056    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
15057       Str : constant String_Id := Strval (S);
15058       Len : constant Int       := String_Length (Str);
15059       CC  : Char_Code;
15060       C   : Character;
15061       J   : Int;
15062
15063       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
15064
15065       procedure Encode;
15066       --  Stores encoded value of character code CC. The encoding we use an
15067       --  underscore followed by four lower case hex digits.
15068
15069       ------------
15070       -- Encode --
15071       ------------
15072
15073       procedure Encode is
15074       begin
15075          Store_String_Char (Get_Char_Code ('_'));
15076          Store_String_Char
15077            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
15078          Store_String_Char
15079            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
15080          Store_String_Char
15081            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
15082          Store_String_Char
15083            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
15084       end Encode;
15085
15086    --  Start of processing for Set_Encoded_Interface_Name
15087
15088    begin
15089       --  If first character is asterisk, this is a link name, and we leave it
15090       --  completely unmodified. We also ignore null strings (the latter case
15091       --  happens only in error cases) and no encoding should occur for Java or
15092       --  AAMP interface names.
15093
15094       if Len = 0
15095         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
15096         or else VM_Target /= No_VM
15097         or else AAMP_On_Target
15098       then
15099          Set_Interface_Name (E, S);
15100
15101       else
15102          J := 1;
15103          loop
15104             CC := Get_String_Char (Str, J);
15105
15106             exit when not In_Character_Range (CC);
15107
15108             C := Get_Character (CC);
15109
15110             exit when C /= '_' and then C /= '$'
15111               and then C not in '0' .. '9'
15112               and then C not in 'a' .. 'z'
15113               and then C not in 'A' .. 'Z';
15114
15115             if J = Len then
15116                Set_Interface_Name (E, S);
15117                return;
15118
15119             else
15120                J := J + 1;
15121             end if;
15122          end loop;
15123
15124          --  Here we need to encode. The encoding we use as follows:
15125          --     three underscores  + four hex digits (lower case)
15126
15127          Start_String;
15128
15129          for J in 1 .. String_Length (Str) loop
15130             CC := Get_String_Char (Str, J);
15131
15132             if not In_Character_Range (CC) then
15133                Encode;
15134             else
15135                C := Get_Character (CC);
15136
15137                if C = '_' or else C = '$'
15138                  or else C in '0' .. '9'
15139                  or else C in 'a' .. 'z'
15140                  or else C in 'A' .. 'Z'
15141                then
15142                   Store_String_Char (CC);
15143                else
15144                   Encode;
15145                end if;
15146             end if;
15147          end loop;
15148
15149          Set_Interface_Name (E,
15150            Make_String_Literal (Sloc (S),
15151              Strval => End_String));
15152       end if;
15153    end Set_Encoded_Interface_Name;
15154
15155    -------------------
15156    -- Set_Unit_Name --
15157    -------------------
15158
15159    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
15160       Pref : Node_Id;
15161       Scop : Entity_Id;
15162
15163    begin
15164       if Nkind (N) = N_Identifier
15165         and then Nkind (With_Item) = N_Identifier
15166       then
15167          Set_Entity (N, Entity (With_Item));
15168
15169       elsif Nkind (N) = N_Selected_Component then
15170          Change_Selected_Component_To_Expanded_Name (N);
15171          Set_Entity (N, Entity (With_Item));
15172          Set_Entity (Selector_Name (N), Entity (N));
15173
15174          Pref := Prefix (N);
15175          Scop := Scope (Entity (N));
15176          while Nkind (Pref) = N_Selected_Component loop
15177             Change_Selected_Component_To_Expanded_Name (Pref);
15178             Set_Entity (Selector_Name (Pref), Scop);
15179             Set_Entity (Pref, Scop);
15180             Pref := Prefix (Pref);
15181             Scop := Scope (Scop);
15182          end loop;
15183
15184          Set_Entity (Pref, Scop);
15185       end if;
15186    end Set_Unit_Name;
15187
15188 end Sem_Prag;