08d6f9a30d5e3cd0899f6a0c145d3beda0ddf954
[platform/upstream/gcc.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-2013, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with Aspects;  use Aspects;
33 with Atree;    use Atree;
34 with Casing;   use Casing;
35 with Checks;   use Checks;
36 with Csets;    use Csets;
37 with Debug;    use Debug;
38 with Einfo;    use Einfo;
39 with Elists;   use Elists;
40 with Errout;   use Errout;
41 with Exp_Dist; use Exp_Dist;
42 with Exp_Util; use Exp_Util;
43 with Freeze;   use Freeze;
44 with Lib;      use Lib;
45 with Lib.Writ; use Lib.Writ;
46 with Lib.Xref; use Lib.Xref;
47 with Namet.Sp; use Namet.Sp;
48 with Nlists;   use Nlists;
49 with Nmake;    use Nmake;
50 with Opt;      use Opt;
51 with Output;   use Output;
52 with Par_SCO;  use Par_SCO;
53 with Restrict; use Restrict;
54 with Rident;   use Rident;
55 with Rtsfind;  use Rtsfind;
56 with Sem;      use Sem;
57 with Sem_Aux;  use Sem_Aux;
58 with Sem_Ch3;  use Sem_Ch3;
59 with Sem_Ch6;  use Sem_Ch6;
60 with Sem_Ch8;  use Sem_Ch8;
61 with Sem_Ch12; use Sem_Ch12;
62 with Sem_Ch13; use Sem_Ch13;
63 with Sem_Disp; use Sem_Disp;
64 with Sem_Dist; use Sem_Dist;
65 with Sem_Elim; use Sem_Elim;
66 with Sem_Eval; use Sem_Eval;
67 with Sem_Intr; use Sem_Intr;
68 with Sem_Mech; use Sem_Mech;
69 with Sem_Res;  use Sem_Res;
70 with Sem_Type; use Sem_Type;
71 with Sem_Util; use Sem_Util;
72 with Sem_VFpt; use Sem_VFpt;
73 with Sem_Warn; use Sem_Warn;
74 with Stand;    use Stand;
75 with Sinfo;    use Sinfo;
76 with Sinfo.CN; use Sinfo.CN;
77 with Sinput;   use Sinput;
78 with Snames;   use Snames;
79 with Stringt;  use Stringt;
80 with Stylesw;  use Stylesw;
81 with Table;
82 with Targparm; use Targparm;
83 with Tbuild;   use Tbuild;
84 with Ttypes;
85 with Uintp;    use Uintp;
86 with Uname;    use Uname;
87 with Urealp;   use Urealp;
88 with Validsw;  use Validsw;
89 with Warnsw;   use Warnsw;
90
91 package body Sem_Prag is
92
93    ----------------------------------------------
94    -- Common Handling of Import-Export Pragmas --
95    ----------------------------------------------
96
97    --  In the following section, a number of Import_xxx and Export_xxx pragmas
98    --  are defined by GNAT. These are compatible with the DEC pragmas of the
99    --  same name, and all have the following common form and processing:
100
101    --  pragma Export_xxx
102    --        [Internal                 =>] LOCAL_NAME
103    --     [, [External                 =>] EXTERNAL_SYMBOL]
104    --     [, other optional parameters   ]);
105
106    --  pragma Import_xxx
107    --        [Internal                 =>] LOCAL_NAME
108    --     [, [External                 =>] EXTERNAL_SYMBOL]
109    --     [, other optional parameters   ]);
110
111    --   EXTERNAL_SYMBOL ::=
112    --     IDENTIFIER
113    --   | static_string_EXPRESSION
114
115    --  The internal LOCAL_NAME designates the entity that is imported or
116    --  exported, and must refer to an entity in the current declarative
117    --  part (as required by the rules for LOCAL_NAME).
118
119    --  The external linker name is designated by the External parameter if
120    --  given, or the Internal parameter if not (if there is no External
121    --  parameter, the External parameter is a copy of the Internal name).
122
123    --  If the External parameter is given as a string, then this string is
124    --  treated as an external name (exactly as though it had been given as an
125    --  External_Name parameter for a normal Import pragma).
126
127    --  If the External parameter is given as an identifier (or there is no
128    --  External parameter, so that the Internal identifier is used), then
129    --  the external name is the characters of the identifier, translated
130    --  to all upper case letters for OpenVMS versions of GNAT, and to all
131    --  lower case letters for all other versions
132
133    --  Note: the external name specified or implied by any of these special
134    --  Import_xxx or Export_xxx pragmas override an external or link name
135    --  specified in a previous Import or Export pragma.
136
137    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
138    --  named notation, following the standard rules for subprogram calls, i.e.
139    --  parameters can be given in any order if named notation is used, and
140    --  positional and named notation can be mixed, subject to the rule that all
141    --  positional parameters must appear first.
142
143    --  Note: All these pragmas are implemented exactly following the DEC design
144    --  and implementation and are intended to be fully compatible with the use
145    --  of these pragmas in the DEC Ada compiler.
146
147    --------------------------------------------
148    -- Checking for Duplicated External Names --
149    --------------------------------------------
150
151    --  It is suspicious if two separate Export pragmas use the same external
152    --  name. The following table is used to diagnose this situation so that
153    --  an appropriate warning can be issued.
154
155    --  The Node_Id stored is for the N_String_Literal node created to hold
156    --  the value of the external name. The Sloc of this node is used to
157    --  cross-reference the location of the duplication.
158
159    package Externals is new Table.Table (
160      Table_Component_Type => Node_Id,
161      Table_Index_Type     => Int,
162      Table_Low_Bound      => 0,
163      Table_Initial        => 100,
164      Table_Increment      => 100,
165      Table_Name           => "Name_Externals");
166
167    -------------------------------------
168    -- Local Subprograms and Variables --
169    -------------------------------------
170
171    procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id);
172    --  Subsidiary routine to the analysis of pragmas Depends and Global. Append
173    --  an input or output item to a list. If the list is empty, a new one is
174    --  created.
175
176    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
177    --  This routine is used for possible casing adjustment of an explicit
178    --  external name supplied as a string literal (the node N), according to
179    --  the casing requirement of Opt.External_Name_Casing. If this is set to
180    --  As_Is, then the string literal is returned unchanged, but if it is set
181    --  to Uppercase or Lowercase, then a new string literal with appropriate
182    --  casing is constructed.
183
184    function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean;
185    --  Subsidiary to the analysis of pragma Global and pragma Depends. Query
186    --  whether a particular item appears in a mixed list of nodes and entities.
187    --  It is assumed that all nodes in the list have entities.
188
189    procedure Collect_Subprogram_Inputs_Outputs
190      (Subp_Id      : Entity_Id;
191       Subp_Inputs  : in out Elist_Id;
192       Subp_Outputs : in out Elist_Id;
193       Global_Seen  : out Boolean);
194    --  Subsidiary to the analysis of pragma Global and pragma Depends. Gather
195    --  all inputs and outputs of subprogram Subp_Id in lists Subp_Inputs and
196    --  Subp_Outputs. If the case where the subprogram has no inputs and/or
197    --  outputs, the corresponding returned list is No_Elist. Flag Global_Seen
198    --  is set when the related subprogram has aspect/pragma Global.
199
200    function Find_Related_Subprogram
201      (Prag             : Node_Id;
202       Check_Duplicates : Boolean := False) return Node_Id;
203    --  Find the declaration of the related subprogram subject to pragma Prag.
204    --  If flag Check_Duplicates is set, the routine emits errors concerning
205    --  duplicate pragmas. If a related subprogram is found, then either the
206    --  corresponding N_Subprogram_Declaration node is returned, or, if the
207    --  pragma applies to a subprogram body, then the N_Subprogram_Body node
208    --  is returned. Note that in the latter case, no check is made to ensure
209    --  that there is no separate declaration of the subprogram.
210
211    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
212    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
213    --  original one, following the renaming chain) is returned. Otherwise the
214    --  entity is returned unchanged. Should be in Einfo???
215
216    function Original_Name (N : Node_Id) return Name_Id;
217    --  N is a pragma node or aspect specification node. This function returns
218    --  the name of the pragma or aspect in original source form, taking into
219    --  account possible rewrites, and also cases where a pragma comes from an
220    --  aspect (in such cases, the name can be different from the pragma name,
221    --  e.g. a Pre aspect generates a Precondition pragma). This also deals with
222    --  the presence of 'Class, which results in one of the special names
223    --  Name_uPre, Name_uPost, Name_uInvariant, or Name_uType_Invariant being
224    --  returned to represent the corresponding aspects with x'Class names.
225
226    procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id);
227    --  Preanalyze the boolean expressions in the Requires and Ensures arguments
228    --  of a Test_Case pragma if present (possibly Empty). We treat these as
229    --  spec expressions (i.e. similar to a default expression).
230
231    procedure Rewrite_Assertion_Kind (N : Node_Id);
232    --  If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
233    --  then it is rewritten as an identifier with the corresponding special
234    --  name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas
235    --  Check, Check_Policy.
236
237    procedure rv;
238    --  This is a dummy function called by the processing for pragma Reviewable.
239    --  It is there for assisting front end debugging. By placing a Reviewable
240    --  pragma in the source program, a breakpoint on rv catches this place in
241    --  the source, allowing convenient stepping to the point of interest.
242
243    function Requires_Profile_Installation
244      (Prag : Node_Id;
245       Subp : Node_Id) return Boolean;
246    --  Subsidiary routine to the analysis of pragma Depends and pragma Global.
247    --  Determine whether the profile of subprogram Subp must be installed into
248    --  visibility to access its formals from pragma Prag.
249
250    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
251    --  Place semantic information on the argument of an Elaborate/Elaborate_All
252    --  pragma. Entity name for unit and its parents is taken from item in
253    --  previous with_clause that mentions the unit.
254
255    --------------
256    -- Add_Item --
257    --------------
258
259    procedure Add_Item (Item : Entity_Id; To_List : in out Elist_Id) is
260    begin
261       if No (To_List) then
262          To_List := New_Elmt_List;
263       end if;
264
265       Append_Unique_Elmt (Item, To_List);
266    end Add_Item;
267
268    -------------------------------
269    -- Adjust_External_Name_Case --
270    -------------------------------
271
272    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
273       CC : Char_Code;
274
275    begin
276       --  Adjust case of literal if required
277
278       if Opt.External_Name_Exp_Casing = As_Is then
279          return N;
280
281       else
282          --  Copy existing string
283
284          Start_String;
285
286          --  Set proper casing
287
288          for J in 1 .. String_Length (Strval (N)) loop
289             CC := Get_String_Char (Strval (N), J);
290
291             if Opt.External_Name_Exp_Casing = Uppercase
292               and then CC >= Get_Char_Code ('a')
293               and then CC <= Get_Char_Code ('z')
294             then
295                Store_String_Char (CC - 32);
296
297             elsif Opt.External_Name_Exp_Casing = Lowercase
298               and then CC >= Get_Char_Code ('A')
299               and then CC <= Get_Char_Code ('Z')
300             then
301                Store_String_Char (CC + 32);
302
303             else
304                Store_String_Char (CC);
305             end if;
306          end loop;
307
308          return
309            Make_String_Literal (Sloc (N),
310              Strval => End_String);
311       end if;
312    end Adjust_External_Name_Case;
313
314    -----------------------------------------
315    -- Analyze_Contract_Cases_In_Decl_Part --
316    -----------------------------------------
317
318    procedure Analyze_Contract_Cases_In_Decl_Part (N : Node_Id) is
319       Others_Seen : Boolean := False;
320
321       procedure Analyze_Contract_Case (CCase : Node_Id);
322       --  Verify the legality of a single contract case
323
324       ---------------------------
325       -- Analyze_Contract_Case --
326       ---------------------------
327
328       procedure Analyze_Contract_Case (CCase : Node_Id) is
329          Case_Guard  : Node_Id;
330          Conseq      : Node_Id;
331          Extra_Guard : Node_Id;
332
333       begin
334          if Nkind (CCase) = N_Component_Association then
335             Case_Guard := First (Choices (CCase));
336             Conseq     := Expression (CCase);
337
338             --  Each contract case must have exactly one case guard
339
340             Extra_Guard := Next (Case_Guard);
341
342             if Present (Extra_Guard) then
343                Error_Msg_N
344                  ("contract case may have only one case guard", Extra_Guard);
345             end if;
346
347             --  Check the placement of "others" (if available)
348
349             if Nkind (Case_Guard) = N_Others_Choice then
350                if Others_Seen then
351                   Error_Msg_N
352                     ("only one others choice allowed in aspect Contract_Cases",
353                      Case_Guard);
354                else
355                   Others_Seen := True;
356                end if;
357
358             elsif Others_Seen then
359                Error_Msg_N
360                  ("others must be the last choice in aspect Contract_Cases",
361                   N);
362             end if;
363
364             --  Preanalyze the case guard and consequence
365
366             if Nkind (Case_Guard) /= N_Others_Choice then
367                Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean);
368             end if;
369
370             Preanalyze_Assert_Expression (Conseq, Standard_Boolean);
371
372          --  The contract case is malformed
373
374          else
375             Error_Msg_N ("wrong syntax in contract case", CCase);
376          end if;
377       end Analyze_Contract_Case;
378
379       --  Local variables
380
381       Arg1      : constant Node_Id := First (Pragma_Argument_Associations (N));
382       All_Cases : Node_Id;
383       CCase     : Node_Id;
384       Subp_Decl : Node_Id;
385       Subp_Id   : Entity_Id;
386
387    --  Start of processing for Analyze_Contract_Cases_In_Decl_Part
388
389    begin
390       Set_Analyzed (N);
391
392       Subp_Decl := Find_Related_Subprogram (N);
393       Subp_Id   := Defining_Unit_Name (Specification (Subp_Decl));
394       All_Cases := Expression (Arg1);
395
396       --  Multiple contract cases appear in aggregate form
397
398       if Nkind (All_Cases) = N_Aggregate then
399          if No (Component_Associations (All_Cases)) then
400             Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
401
402          --  Individual contract cases appear as component associations
403
404          else
405             --  Ensure that the formal parameters are visible when analyzing
406             --  all clauses. This falls out of the general rule of aspects
407             --  pertaining to subprogram declarations. Skip the installation
408             --  for subprogram bodies because the formals are already visible.
409
410             if Requires_Profile_Installation (N, Subp_Decl) then
411                Push_Scope (Subp_Id);
412                Install_Formals (Subp_Id);
413             end if;
414
415             CCase := First (Component_Associations (All_Cases));
416             while Present (CCase) loop
417                Analyze_Contract_Case (CCase);
418                Next (CCase);
419             end loop;
420
421             if Requires_Profile_Installation (N, Subp_Decl) then
422                End_Scope;
423             end if;
424          end if;
425
426       else
427          Error_Msg_N ("wrong syntax for aspect Contract_Cases", N);
428       end if;
429    end Analyze_Contract_Cases_In_Decl_Part;
430
431    ----------------------------------
432    -- Analyze_Depends_In_Decl_Part --
433    ----------------------------------
434
435    procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is
436       Arg1 : constant Node_Id    := First (Pragma_Argument_Associations (N));
437       Loc  : constant Source_Ptr := Sloc (N);
438
439       All_Inputs_Seen : Elist_Id := No_Elist;
440       --  A list containing the entities of all the inputs processed so far.
441       --  This Elist is populated with unique entities because the same input
442       --  may appear in multiple input lists.
443
444       Global_Seen : Boolean := False;
445       --  A flag set when pragma Global has been processed
446
447       Outputs_Seen : Elist_Id := No_Elist;
448       --  A list containing the entities of all the outputs processed so far.
449       --  The elements of this list may come from different output lists.
450
451       Null_Output_Seen : Boolean := False;
452       --  A flag used to track the legality of a null output
453
454       Result_Seen : Boolean := False;
455       --  A flag set when Subp_Id'Result is processed
456
457       Subp_Id : Entity_Id;
458       --  The entity of the subprogram subject to pragma Depends
459
460       Subp_Inputs  : Elist_Id := No_Elist;
461       Subp_Outputs : Elist_Id := No_Elist;
462       --  Two lists containing the full set of inputs and output of the related
463       --  subprograms. Note that these lists contain both nodes and entities.
464
465       procedure Analyze_Dependency_Clause
466         (Clause  : Node_Id;
467          Is_Last : Boolean);
468       --  Verify the legality of a single dependency clause. Flag Is_Last
469       --  denotes whether Clause is the last clause in the relation.
470
471       procedure Check_Function_Return;
472       --  Verify that Funtion'Result appears as one of the outputs
473
474       procedure Check_Mode
475         (Item     : Node_Id;
476          Item_Id  : Entity_Id;
477          Is_Input : Boolean;
478          Self_Ref : Boolean);
479       --  Ensure that an item has a proper "in", "in out" or "out" mode
480       --  depending on its function. If this is not the case, emit an error.
481       --  Item and Item_Id denote the attributes of an item. Flag Is_Input
482       --  should be set when item comes from an input list. Flag Self_Ref
483       --  should be set when the item is an output and the dependency clause
484       --  has operator "+".
485
486       procedure Check_Usage
487         (Subp_Items : Elist_Id;
488          Used_Items : Elist_Id;
489          Is_Input   : Boolean);
490       --  Verify that all items from Subp_Items appear in Used_Items. Emit an
491       --  error if this is not the case.
492
493       procedure Normalize_Clause (Clause : Node_Id);
494       --  Remove a self-dependency "+" from the input list of a clause.
495       --  Depending on the contents of the relation, either split the the
496       --  clause into multiple smaller clauses or perform the normalization in
497       --  place.
498
499       -------------------------------
500       -- Analyze_Dependency_Clause --
501       -------------------------------
502
503       procedure Analyze_Dependency_Clause
504         (Clause  : Node_Id;
505          Is_Last : Boolean)
506       is
507          procedure Analyze_Input_List (Inputs : Node_Id);
508          --  Verify the legality of a single input list
509
510          procedure Analyze_Input_Output
511            (Item      : Node_Id;
512             Is_Input  : Boolean;
513             Self_Ref  : Boolean;
514             Top_Level : Boolean;
515             Seen      : in out Elist_Id;
516             Null_Seen : in out Boolean);
517          --  Verify the legality of a single input or output item. Flag
518          --  Is_Input should be set whenever Item is an input, False when it
519          --  denotes an output. Flag Self_Ref should be set when the item is an
520          --  output and the dependency clause has a "+". Flag Top_Level should
521          --  be set whenever Item appears immediately within an input or output
522          --  list. Seen is a collection of all abstract states, variables and
523          --  formals processed so far. Flag Null_Seen denotes whether a null
524          --  input or output has been encountered.
525
526          ------------------------
527          -- Analyze_Input_List --
528          ------------------------
529
530          procedure Analyze_Input_List (Inputs : Node_Id) is
531             Inputs_Seen : Elist_Id := No_Elist;
532             --  A list containing the entities of all inputs that appear in the
533             --  current input list.
534
535             Null_Input_Seen : Boolean := False;
536             --  A flag used to track the legality of a null input
537
538             Input : Node_Id;
539
540          begin
541             --  Multiple inputs appear as an aggregate
542
543             if Nkind (Inputs) = N_Aggregate then
544                if Present (Component_Associations (Inputs)) then
545                   Error_Msg_N
546                     ("nested dependency relations not allowed", Inputs);
547
548                elsif Present (Expressions (Inputs)) then
549                   Input := First (Expressions (Inputs));
550                   while Present (Input) loop
551                      Analyze_Input_Output
552                        (Item      => Input,
553                         Is_Input  => True,
554                         Self_Ref  => False,
555                         Top_Level => False,
556                         Seen      => Inputs_Seen,
557                         Null_Seen => Null_Input_Seen);
558
559                      Next (Input);
560                   end loop;
561
562                else
563                   Error_Msg_N ("malformed input dependency list", Inputs);
564                end if;
565
566             --  Process a solitary input
567
568             else
569                Analyze_Input_Output
570                  (Item      => Inputs,
571                   Is_Input  => True,
572                   Self_Ref  => False,
573                   Top_Level => False,
574                   Seen      => Inputs_Seen,
575                   Null_Seen => Null_Input_Seen);
576             end if;
577
578             --  Detect an illegal dependency clause of the form
579
580             --    (null =>[+] null)
581
582             if Null_Output_Seen and then Null_Input_Seen then
583                Error_Msg_N
584                  ("null dependency clause cannot have a null input list",
585                   Inputs);
586             end if;
587          end Analyze_Input_List;
588
589          --------------------------
590          -- Analyze_Input_Output --
591          --------------------------
592
593          procedure Analyze_Input_Output
594            (Item      : Node_Id;
595             Is_Input  : Boolean;
596             Self_Ref  : Boolean;
597             Top_Level : Boolean;
598             Seen      : in out Elist_Id;
599             Null_Seen : in out Boolean)
600          is
601             Is_Output : constant Boolean := not Is_Input;
602             Grouped   : Node_Id;
603             Item_Id   : Entity_Id;
604
605          begin
606             --  Multiple input or output items appear as an aggregate
607
608             if Nkind (Item) = N_Aggregate then
609                if not Top_Level then
610                   Error_Msg_N ("nested grouping of items not allowed", Item);
611
612                elsif Present (Component_Associations (Item)) then
613                   Error_Msg_N
614                     ("nested dependency relations not allowed", Item);
615
616                --  Recursively analyze the grouped items
617
618                elsif Present (Expressions (Item)) then
619                   Grouped := First (Expressions (Item));
620                   while Present (Grouped) loop
621                      Analyze_Input_Output
622                        (Item      => Grouped,
623                         Is_Input  => Is_Input,
624                         Self_Ref  => Self_Ref,
625                         Top_Level => False,
626                         Seen      => Seen,
627                         Null_Seen => Null_Seen);
628
629                      Next (Grouped);
630                   end loop;
631
632                else
633                   Error_Msg_N ("malformed dependency list", Item);
634                end if;
635
636             --  Process Function'Result in the context of a dependency clause
637
638             elsif Nkind (Item) = N_Attribute_Reference
639               and then Attribute_Name (Item) = Name_Result
640             then
641                --  It is sufficent to analyze the prefix of 'Result in order to
642                --  establish legality of the attribute.
643
644                Analyze (Prefix (Item));
645
646                --  The prefix of 'Result must denote the function for which
647                --  aspect/pragma Depends applies.
648
649                if not Is_Entity_Name (Prefix (Item))
650                  or else Ekind (Subp_Id) /= E_Function
651                  or else Entity (Prefix (Item)) /= Subp_Id
652                then
653                   Error_Msg_Name_1 := Name_Result;
654                   Error_Msg_N
655                     ("prefix of attribute % must denote the enclosing "
656                      & "function", Item);
657
658                --  Function'Result is allowed to appear on the output side of a
659                --  dependency clause.
660
661                elsif Is_Input then
662                   Error_Msg_N ("function result cannot act as input", Item);
663
664                else
665                   Result_Seen := True;
666                end if;
667
668             --  Detect multiple uses of null in a single dependency list or
669             --  throughout the whole relation. Verify the placement of a null
670             --  output list relative to the other clauses.
671
672             elsif Nkind (Item) = N_Null then
673                if Null_Seen then
674                   Error_Msg_N
675                     ("multiple null dependency relations not allowed", Item);
676                else
677                   Null_Seen := True;
678
679                   if Is_Output and then not Is_Last then
680                      Error_Msg_N
681                        ("null output list must be the last clause in a "
682                         & "dependency relation", Item);
683                   end if;
684                end if;
685
686             --  Default case
687
688             else
689                Analyze (Item);
690
691                --  Find the entity of the item. If this is a renaming, climb
692                --  the renaming chain to reach the root object. Renamings of
693                --  non-entire objects do not yield an entity (Empty).
694
695                Item_Id := Entity_Of (Item);
696
697                if Present (Item_Id) then
698                   if Ekind_In (Item_Id, E_Abstract_State,
699                                         E_In_Parameter,
700                                         E_In_Out_Parameter,
701                                         E_Out_Parameter,
702                                         E_Variable)
703                   then
704                      --  Ensure that the item is of the correct mode depending
705                      --  on its function.
706
707                      Check_Mode (Item, Item_Id, Is_Input, Self_Ref);
708
709                      --  Detect multiple uses of the same state, variable or
710                      --  formal parameter. If this is not the case, add the
711                      --  item to the list of processed relations.
712
713                      if Contains (Seen, Item_Id) then
714                         Error_Msg_N ("duplicate use of item", Item);
715                      else
716                         Add_Item (Item_Id, Seen);
717                      end if;
718
719                      --  Detect an illegal use of an input related to a null
720                      --  output. Such input items cannot appear in other input
721                      --  lists.
722
723                      if Null_Output_Seen
724                        and then Contains (All_Inputs_Seen, Item_Id)
725                      then
726                         Error_Msg_N
727                           ("input of a null output list appears in multiple "
728                            & "input lists", Item);
729                      else
730                         Add_Item (Item_Id, All_Inputs_Seen);
731                      end if;
732
733                      --  When the item renames an entire object, replace the
734                      --  item with a reference to the object.
735
736                      if Present (Renamed_Object (Entity (Item))) then
737                         Rewrite (Item,
738                           New_Reference_To (Item_Id, Sloc (Item)));
739                         Analyze (Item);
740                      end if;
741
742                   --  All other input/output items are illegal
743
744                   else
745                      Error_Msg_N
746                         ("item must denote variable, state or formal "
747                          & "parameter", Item);
748                   end if;
749
750                --  All other input/output items are illegal
751
752                else
753                   Error_Msg_N
754                     ("item must denote variable, state or formal parameter",
755                      Item);
756                end if;
757             end if;
758          end Analyze_Input_Output;
759
760          --  Local variables
761
762          Inputs   : Node_Id;
763          Output   : Node_Id;
764          Self_Ref : Boolean;
765
766       --  Start of processing for Analyze_Dependency_Clause
767
768       begin
769          Inputs   := Expression (Clause);
770          Self_Ref := False;
771
772          --  An input list with a self-dependency appears as operator "+" where
773          --  the actuals inputs are the right operand.
774
775          if Nkind (Inputs) = N_Op_Plus then
776             Inputs   := Right_Opnd (Inputs);
777             Self_Ref := True;
778          end if;
779
780          --  Process the output_list of a dependency_clause
781
782          Output := First (Choices (Clause));
783          while Present (Output) loop
784             Analyze_Input_Output
785               (Item      => Output,
786                Is_Input  => False,
787                Self_Ref  => Self_Ref,
788                Top_Level => True,
789                Seen      => Outputs_Seen,
790                Null_Seen => Null_Output_Seen);
791
792             Next (Output);
793          end loop;
794
795          --  Process the input_list of a dependency_clause
796
797          Analyze_Input_List (Inputs);
798       end Analyze_Dependency_Clause;
799
800       ----------------------------
801       --  Check_Function_Return --
802       ----------------------------
803
804       procedure Check_Function_Return is
805       begin
806          if Ekind (Subp_Id) = E_Function and then not Result_Seen then
807             Error_Msg_NE
808               ("result of & must appear in exactly one output list",
809                N, Subp_Id);
810          end if;
811       end Check_Function_Return;
812
813       ----------------
814       -- Check_Mode --
815       ----------------
816
817       procedure Check_Mode
818         (Item     : Node_Id;
819          Item_Id  : Entity_Id;
820          Is_Input : Boolean;
821          Self_Ref : Boolean)
822       is
823       begin
824          --  Input
825
826          if Is_Input then
827             if Ekind (Item_Id) = E_Out_Parameter
828               or else (Global_Seen
829                          and then not Appears_In (Subp_Inputs, Item_Id))
830             then
831                Error_Msg_NE
832                  ("item & must have mode in or in out", Item, Item_Id);
833             end if;
834
835          --  Self-referential output
836
837          elsif Self_Ref then
838
839             --  A self-referential state or variable must appear in both input
840             --  and output lists of a subprogram.
841
842             if Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
843                if Global_Seen
844                  and then not
845                    (Appears_In (Subp_Inputs, Item_Id)
846                       and then
847                     Appears_In (Subp_Outputs, Item_Id))
848                then
849                   Error_Msg_NE ("item & must have mode in out", Item, Item_Id);
850                end if;
851
852             --  Self-referential parameter
853
854             elsif Ekind (Item_Id) /= E_In_Out_Parameter then
855                Error_Msg_NE ("item & must have mode in out", Item, Item_Id);
856             end if;
857
858          --  Regular output
859
860          elsif Ekind (Item_Id) = E_In_Parameter
861            or else
862              (Global_Seen and then not Appears_In (Subp_Outputs, Item_Id))
863          then
864             Error_Msg_NE
865               ("item & must have mode out or in out", Item, Item_Id);
866          end if;
867       end Check_Mode;
868
869       -----------------
870       -- Check_Usage --
871       -----------------
872
873       procedure Check_Usage
874         (Subp_Items : Elist_Id;
875          Used_Items : Elist_Id;
876          Is_Input   : Boolean)
877       is
878          procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id);
879          --  Emit an error concerning the erroneous usage of an item
880
881          -----------------
882          -- Usage_Error --
883          -----------------
884
885          procedure Usage_Error (Item : Node_Id; Item_Id : Entity_Id) is
886          begin
887             if Is_Input then
888                Error_Msg_NE
889                  ("item & must appear in at least one input list of aspect "
890                   & "Depends", Item, Item_Id);
891             else
892                Error_Msg_NE
893                  ("item & must appear in exactly one output list of aspect "
894                   & "Depends", Item, Item_Id);
895             end if;
896          end Usage_Error;
897
898          --  Local variables
899
900          Elmt    : Elmt_Id;
901          Item    : Node_Id;
902          Item_Id : Entity_Id;
903
904       --  Start of processing for Check_Usage
905
906       begin
907          if No (Subp_Items) then
908             return;
909          end if;
910
911          --  Each input or output of the subprogram must appear in a dependency
912          --  relation.
913
914          Elmt := First_Elmt (Subp_Items);
915          while Present (Elmt) loop
916             Item := Node (Elmt);
917
918             if Nkind (Item) = N_Defining_Identifier then
919                Item_Id := Item;
920             else
921                Item_Id := Entity (Item);
922             end if;
923
924             --  The item does not appear in a dependency
925
926             if not Contains (Used_Items, Item_Id) then
927                if Is_Formal (Item_Id) then
928                   Usage_Error (Item, Item_Id);
929
930                --  States and global variables are not used properly only when
931                --  the subprogram is subject to pragma Global.
932
933                elsif Global_Seen then
934                   Usage_Error (Item, Item_Id);
935                end if;
936             end if;
937
938             Next_Elmt (Elmt);
939          end loop;
940       end Check_Usage;
941
942       ----------------------
943       -- Normalize_Clause --
944       ----------------------
945
946       procedure Normalize_Clause (Clause : Node_Id) is
947          procedure Create_Or_Modify_Clause
948            (Output   : Node_Id;
949             Outputs  : Node_Id;
950             Inputs   : Node_Id;
951             After    : Node_Id;
952             In_Place : Boolean;
953             Multiple : Boolean);
954          --  Create a brand new clause to represent the self-reference or
955          --  modify the input and/or output lists of an existing clause. Output
956          --  denotes a self-referencial output. Outputs is the output list of a
957          --  clause. Inputs is the input list of a clause. After denotes the
958          --  clause after which the new clause is to be inserted. Flag In_Place
959          --  should be set when normalizing the last output of an output list.
960          --  Flag Multiple should be set when Output comes from a list with
961          --  multiple items.
962
963          -----------------------------
964          -- Create_Or_Modify_Clause --
965          -----------------------------
966
967          procedure Create_Or_Modify_Clause
968            (Output   : Node_Id;
969             Outputs  : Node_Id;
970             Inputs   : Node_Id;
971             After    : Node_Id;
972             In_Place : Boolean;
973             Multiple : Boolean)
974          is
975             procedure Propagate_Output
976               (Output : Node_Id;
977                Inputs : Node_Id);
978             --  Handle the various cases of output propagation to the input
979             --  list. Output denotes a self-referencial output item. Inputs is
980             --  the input list of a clause.
981
982             ----------------------
983             -- Propagate_Output --
984             ----------------------
985
986             procedure Propagate_Output
987               (Output : Node_Id;
988                Inputs : Node_Id)
989             is
990                function In_Input_List
991                  (Item   : Entity_Id;
992                   Inputs : List_Id) return Boolean;
993                --  Determine whether a particulat item appears in the input
994                --  list of a clause.
995
996                -------------------
997                -- In_Input_List --
998                -------------------
999
1000                function In_Input_List
1001                  (Item   : Entity_Id;
1002                   Inputs : List_Id) return Boolean
1003                is
1004                   Elmt : Node_Id;
1005
1006                begin
1007                   Elmt := First (Inputs);
1008                   while Present (Elmt) loop
1009                      if Entity_Of (Elmt) = Item then
1010                         return True;
1011                      end if;
1012
1013                      Next (Elmt);
1014                   end loop;
1015
1016                   return False;
1017                end In_Input_List;
1018
1019                --  Local variables
1020
1021                Output_Id : constant Entity_Id := Entity_Of (Output);
1022                Grouped   : List_Id;
1023
1024             --  Start of processing for Propagate_Output
1025
1026             begin
1027                --  The clause is of the form:
1028
1029                --    (Output =>+ null)
1030
1031                --  Remove the null input and replace it with a copy of the
1032                --  output:
1033
1034                --    (Output => Output)
1035
1036                if Nkind (Inputs) = N_Null then
1037                   Rewrite (Inputs, New_Copy_Tree (Output));
1038
1039                --  The clause is of the form:
1040
1041                --    (Output =>+ (Input1, ..., InputN))
1042
1043                --  Determine whether the output is not already mentioned in the
1044                --  input list and if not, add it to the list of inputs:
1045
1046                --    (Output => (Output, Input1, ..., InputN))
1047
1048                elsif Nkind (Inputs) = N_Aggregate then
1049                   Grouped := Expressions (Inputs);
1050
1051                   if not In_Input_List
1052                            (Item   => Output_Id,
1053                             Inputs => Grouped)
1054                   then
1055                      Prepend_To (Grouped, New_Copy_Tree (Output));
1056                   end if;
1057
1058                --  The clause is of the form:
1059
1060                --    (Output =>+ Input)
1061
1062                --  If the input does not mention the output, group the two
1063                --  together:
1064
1065                --    (Output => (Output, Input))
1066
1067                elsif Entity_Of (Inputs) /= Output_Id then
1068                   Rewrite (Inputs,
1069                     Make_Aggregate (Loc,
1070                       Expressions => New_List (
1071                         New_Copy_Tree (Output),
1072                         New_Copy_Tree (Inputs))));
1073                end if;
1074             end Propagate_Output;
1075
1076             --  Local variables
1077
1078             Loc    : constant Source_Ptr := Sloc (Output);
1079             Clause : Node_Id;
1080
1081          --  Start of processing for Create_Or_Modify_Clause
1082
1083          begin
1084             --  A function result cannot depend on itself because it cannot
1085             --  appear in the input list of a relation.
1086
1087             if Nkind (Output) = N_Attribute_Reference
1088               and then Attribute_Name (Output) = Name_Result
1089             then
1090                Error_Msg_N ("function result cannot depend on itself", Output);
1091                return;
1092
1093             --  A null output depending on itself does not require any
1094             --  normalization.
1095
1096             elsif Nkind (Output) = N_Null then
1097                return;
1098             end if;
1099
1100             --  When performing the transformation in place, simply add the
1101             --  output to the list of inputs (if not already there). This case
1102             --  arises when dealing with the last output of an output list -
1103             --  we perform the normalization in place to avoid generating a
1104             --  malformed tree.
1105
1106             if In_Place then
1107                Propagate_Output (Output, Inputs);
1108
1109                --  A list with multiple outputs is slowly trimmed until only
1110                --  one element remains. When this happens, replace the
1111                --  aggregate with the element itself.
1112
1113                if Multiple then
1114                   Remove  (Output);
1115                   Rewrite (Outputs, Output);
1116                end if;
1117
1118             --  Default case
1119
1120             else
1121                --  Unchain the output from its output list as it will appear in
1122                --  a new clause. Note that we cannot simply rewrite the output
1123                --  as null because this will violate the semantics of aspect or
1124                --  pragma Depends.
1125
1126                Remove (Output);
1127
1128                --  Create a new clause of the form:
1129
1130                --    (Output => Inputs)
1131
1132                Clause :=
1133                  Make_Component_Association (Loc,
1134                    Choices    => New_List (Output),
1135                    Expression => New_Copy_Tree (Inputs));
1136
1137                --  The new clause contains replicated content that has already
1138                --  been analyzed. There is not need to reanalyze it or
1139                --  renormalize it again.
1140
1141                Set_Analyzed (Clause);
1142
1143                Propagate_Output
1144                  (Output => First (Choices (Clause)),
1145                   Inputs => Expression (Clause));
1146
1147                Insert_After (After, Clause);
1148             end if;
1149          end Create_Or_Modify_Clause;
1150
1151          --  Local variables
1152
1153          Outputs     : constant Node_Id := First (Choices (Clause));
1154          Inputs      : Node_Id;
1155          Last_Output : Node_Id;
1156          Next_Output : Node_Id;
1157          Output      : Node_Id;
1158
1159       --  Start of processing for Normalize_Clause
1160
1161       begin
1162          --  A self-dependency appears as operator "+". Remove the "+" from the
1163          --  tree by moving the real inputs to their proper place.
1164
1165          if Nkind (Expression (Clause)) = N_Op_Plus then
1166             Rewrite (Expression (Clause), Right_Opnd (Expression (Clause)));
1167             Inputs := Expression (Clause);
1168
1169             --  Multiple outputs appear as an aggregate
1170
1171             if Nkind (Outputs) = N_Aggregate then
1172                Last_Output := Last (Expressions (Outputs));
1173
1174                Output := First (Expressions (Outputs));
1175                while Present (Output) loop
1176
1177                   --  Normalization may remove an output from its list,
1178                   --  preserve the subsequent output now.
1179
1180                   Next_Output := Next (Output);
1181
1182                   Create_Or_Modify_Clause
1183                     (Output   => Output,
1184                      Outputs  => Outputs,
1185                      Inputs   => Inputs,
1186                      After    => Clause,
1187                      In_Place => Output = Last_Output,
1188                      Multiple => True);
1189
1190                   Output := Next_Output;
1191                end loop;
1192
1193             --  Solitary output
1194
1195             else
1196                Create_Or_Modify_Clause
1197                  (Output   => Outputs,
1198                   Outputs  => Empty,
1199                   Inputs   => Inputs,
1200                   After    => Empty,
1201                   In_Place => True,
1202                   Multiple => False);
1203             end if;
1204          end if;
1205       end Normalize_Clause;
1206
1207       --  Local variables
1208
1209       Clause      : Node_Id;
1210       Errors      : Nat;
1211       Last_Clause : Node_Id;
1212       Subp_Decl   : Node_Id;
1213
1214    --  Start of processing for Analyze_Depends_In_Decl_Part
1215
1216    begin
1217       Set_Analyzed (N);
1218
1219       Subp_Decl := Find_Related_Subprogram (N);
1220       Subp_Id   := Defining_Unit_Name (Specification (Subp_Decl));
1221       Clause    := Expression (Arg1);
1222
1223       --  Empty dependency list
1224
1225       if Nkind (Clause) = N_Null then
1226
1227          --  Gather all states, variables and formal parameters that the
1228          --  subprogram may depend on. These items are obtained from the
1229          --  parameter profile or pragma Global (if available).
1230
1231          Collect_Subprogram_Inputs_Outputs
1232            (Subp_Id      => Subp_Id,
1233             Subp_Inputs  => Subp_Inputs,
1234             Subp_Outputs => Subp_Outputs,
1235             Global_Seen  => Global_Seen);
1236
1237          --  Verify that every input or output of the subprogram appear in a
1238          --  dependency.
1239
1240          Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1241          Check_Usage (Subp_Outputs, Outputs_Seen, False);
1242          Check_Function_Return;
1243
1244       --  Dependency clauses appear as component associations of an aggregate
1245
1246       elsif Nkind (Clause) = N_Aggregate
1247         and then Present (Component_Associations (Clause))
1248       then
1249          Last_Clause := Last (Component_Associations (Clause));
1250
1251          --  Gather all states, variables and formal parameters that the
1252          --  subprogram may depend on. These items are obtained from the
1253          --  parameter profile or pragma Global (if available).
1254
1255          Collect_Subprogram_Inputs_Outputs
1256            (Subp_Id      => Subp_Id,
1257             Subp_Inputs  => Subp_Inputs,
1258             Subp_Outputs => Subp_Outputs,
1259             Global_Seen  => Global_Seen);
1260
1261          --  Ensure that the formal parameters are visible when analyzing all
1262          --  clauses. This falls out of the general rule of aspects pertaining
1263          --  to subprogram declarations. Skip the installation for subprogram
1264          --  bodies because the formals are already visible.
1265
1266          if Requires_Profile_Installation (N, Subp_Decl) then
1267             Push_Scope (Subp_Id);
1268             Install_Formals (Subp_Id);
1269          end if;
1270
1271          Clause := First (Component_Associations (Clause));
1272          while Present (Clause) loop
1273             Errors := Serious_Errors_Detected;
1274
1275             --  Normalization may create extra clauses that contain replicated
1276             --  input and output names. There is no need to reanalyze or
1277             --  renormalize these extra clauses.
1278
1279             if not Analyzed (Clause) then
1280                Set_Analyzed (Clause);
1281
1282                Analyze_Dependency_Clause
1283                  (Clause  => Clause,
1284                   Is_Last => Clause = Last_Clause);
1285
1286                --  Do not normalize an erroneous clause because the inputs or
1287                --  outputs may denote illegal items.
1288
1289                if Errors = Serious_Errors_Detected then
1290                   Normalize_Clause (Clause);
1291                end if;
1292             end if;
1293
1294             Next (Clause);
1295          end loop;
1296
1297          if Requires_Profile_Installation (N, Subp_Decl) then
1298             End_Scope;
1299          end if;
1300
1301          --  Verify that every input or output of the subprogram appear in a
1302          --  dependency.
1303
1304          Check_Usage (Subp_Inputs, All_Inputs_Seen, True);
1305          Check_Usage (Subp_Outputs, Outputs_Seen, False);
1306          Check_Function_Return;
1307
1308       --  The top level dependency relation is malformed
1309
1310       else
1311          Error_Msg_N ("malformed dependency relation", Clause);
1312       end if;
1313    end Analyze_Depends_In_Decl_Part;
1314
1315    ---------------------------------
1316    -- Analyze_Global_In_Decl_Part --
1317    ---------------------------------
1318
1319    procedure Analyze_Global_In_Decl_Part (N : Node_Id) is
1320       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1321
1322       Seen : Elist_Id := No_Elist;
1323       --  A list containing the entities of all the items processed so far. It
1324       --  plays a role in detecting distinct entities.
1325
1326       Subp_Id : Entity_Id;
1327       --  The entity of the subprogram subject to pragma Global
1328
1329       Contract_Seen : Boolean := False;
1330       In_Out_Seen   : Boolean := False;
1331       Input_Seen    : Boolean := False;
1332       Output_Seen   : Boolean := False;
1333       --  Flags used to verify the consistency of modes
1334
1335       procedure Analyze_Global_List
1336         (List        : Node_Id;
1337          Global_Mode : Name_Id := Name_Input);
1338       --  Verify the legality of a single global list declaration. Global_Mode
1339       --  denotes the current mode in effect.
1340
1341       -------------------------
1342       -- Analyze_Global_List --
1343       -------------------------
1344
1345       procedure Analyze_Global_List
1346         (List        : Node_Id;
1347          Global_Mode : Name_Id := Name_Input)
1348       is
1349          procedure Analyze_Global_Item
1350            (Item        : Node_Id;
1351             Global_Mode : Name_Id);
1352          --  Verify the legality of a single global item declaration.
1353          --  Global_Mode denotes the current mode in effect.
1354
1355          procedure Check_Duplicate_Mode
1356            (Mode   : Node_Id;
1357             Status : in out Boolean);
1358          --  Flag Status denotes whether a particular mode has been seen while
1359          --  processing a global list. This routine verifies that Mode is not a
1360          --  duplicate mode and sets the flag Status.
1361
1362          procedure Check_Mode_Restriction_In_Enclosing_Context
1363            (Item    : Node_Id;
1364             Item_Id : Entity_Id);
1365          --  Verify that an item of mode In_Out or Output does not appear as an
1366          --  input in the Global aspect of an enclosing subprogram. If this is
1367          --  the case, emit an error. Item and Item_Id are respectively the
1368          --  item and its entity.
1369
1370          procedure Check_Mode_Restriction_In_Function (Mode : Node_Id);
1371          --  Mode denotes either In_Out or Output. Depending on the kind of the
1372          --  related subprogram, emit an error if those two modes apply to a
1373          --  function.
1374
1375          -------------------------
1376          -- Analyze_Global_Item --
1377          -------------------------
1378
1379          procedure Analyze_Global_Item
1380            (Item        : Node_Id;
1381             Global_Mode : Name_Id)
1382          is
1383             Item_Id : Entity_Id;
1384
1385          begin
1386             --  Detect one of the following cases
1387
1388             --    with Global => (null, Name)
1389             --    with Global => (Name_1, null, Name_2)
1390             --    with Global => (Name, null)
1391
1392             if Nkind (Item) = N_Null then
1393                Error_Msg_N ("cannot mix null and non-null global items", Item);
1394                return;
1395             end if;
1396
1397             Analyze (Item);
1398
1399             --  Find the entity of the item. If this is a renaming, climb the
1400             --  renaming chain to reach the root object. Renamings of non-
1401             --  entire objects do not yield an entity (Empty).
1402
1403             Item_Id := Entity_Of (Item);
1404
1405             if Present (Item_Id) then
1406
1407                --  A global item cannot reference a formal parameter. Do this
1408                --  check first to provide a better error diagnostic.
1409
1410                if Is_Formal (Item_Id) then
1411                   Error_Msg_N
1412                     ("global item cannot reference formal parameter", Item);
1413                   return;
1414
1415                --  The only legal references are those to abstract states and
1416                --  variables.
1417
1418                elsif not Ekind_In (Item_Id, E_Abstract_State, E_Variable) then
1419                   Error_Msg_N
1420                     ("global item must denote variable or state", Item);
1421                   return;
1422                end if;
1423
1424                --  When the item renames an entire object, replace the item
1425                --  with a reference to the object.
1426
1427                if Present (Renamed_Object (Entity (Item))) then
1428                   Rewrite (Item, New_Reference_To (Item_Id, Sloc (Item)));
1429                   Analyze (Item);
1430                end if;
1431
1432             --  Some form of illegal construct masquerading as a name
1433
1434             else
1435                Error_Msg_N ("global item must denote variable or state", Item);
1436                return;
1437             end if;
1438
1439             --  At this point we know that the global item is one of the two
1440             --  valid choices. Perform mode- and usage-specific checks.
1441
1442             if Ekind (Item_Id) = E_Abstract_State
1443               and then Is_Volatile_State (Item_Id)
1444             then
1445                --  A global item of mode In_Out or Output cannot denote a
1446                --  volatile Input state.
1447
1448                if Is_Input_State (Item_Id)
1449                  and then Nam_In (Global_Mode, Name_In_Out, Name_Output)
1450                then
1451                   Error_Msg_N
1452                     ("global item of mode In_Out or Output cannot reference "
1453                      & "Volatile Input state", Item);
1454
1455                --  A global item of mode In_Out or Input cannot reference a
1456                --  volatile Output state.
1457
1458                elsif Is_Output_State (Item_Id)
1459                  and then Nam_In (Global_Mode, Name_In_Out, Name_Input)
1460                then
1461                   Error_Msg_N
1462                     ("global item of mode In_Out or Input cannot reference "
1463                      & "Volatile Output state", Item);
1464                end if;
1465             end if;
1466
1467             --  Verify that an output does not appear as an input in an
1468             --  enclosing subprogram.
1469
1470             if Nam_In (Global_Mode, Name_In_Out, Name_Output) then
1471                Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id);
1472             end if;
1473
1474             --  The same entity might be referenced through various way. Check
1475             --  the entity of the item rather than the item itself.
1476
1477             if Contains (Seen, Item_Id) then
1478                Error_Msg_N ("duplicate global item", Item);
1479
1480             --  Add the entity of the current item to the list of processed
1481             --  items.
1482
1483             else
1484                Add_Item (Item_Id, Seen);
1485             end if;
1486          end Analyze_Global_Item;
1487
1488          --------------------------
1489          -- Check_Duplicate_Mode --
1490          --------------------------
1491
1492          procedure Check_Duplicate_Mode
1493            (Mode   : Node_Id;
1494             Status : in out Boolean)
1495          is
1496          begin
1497             if Status then
1498                Error_Msg_N ("duplicate global mode", Mode);
1499             end if;
1500
1501             Status := True;
1502          end Check_Duplicate_Mode;
1503
1504          -------------------------------------------------
1505          -- Check_Mode_Restriction_In_Enclosing_Context --
1506          -------------------------------------------------
1507
1508          procedure Check_Mode_Restriction_In_Enclosing_Context
1509            (Item    : Node_Id;
1510             Item_Id : Entity_Id)
1511          is
1512             Dummy   : Boolean;
1513             Inputs  : Elist_Id := No_Elist;
1514             Outputs : Elist_Id := No_Elist;
1515             Subp_Id : Entity_Id;
1516
1517          begin
1518             --  Traverse the scope stack looking for enclosing subprograms
1519             --  subject to aspect/pragma Global.
1520
1521             Subp_Id := Scope (Current_Scope);
1522             while Present (Subp_Id) and then Subp_Id /= Standard_Standard loop
1523                if Is_Subprogram (Subp_Id)
1524                  and then Has_Aspect (Subp_Id, Aspect_Global)
1525                then
1526                   Collect_Subprogram_Inputs_Outputs
1527                     (Subp_Id      => Subp_Id,
1528                      Subp_Inputs  => Inputs,
1529                      Subp_Outputs => Outputs,
1530                      Global_Seen  => Dummy);
1531
1532                   --  The item is classified as In_Out or Output but appears as
1533                   --  an Input in an enclosing subprogram.
1534
1535                   if Appears_In (Inputs, Item_Id)
1536                     and then not Appears_In (Outputs, Item_Id)
1537                   then
1538                      Error_Msg_NE
1539                        ("global item & cannot have mode In_Out or Output",
1540                         Item, Item_Id);
1541                      Error_Msg_NE
1542                        ("\item already appears as input of subprogram &",
1543                         Item, Subp_Id);
1544                   end if;
1545                end if;
1546
1547                Subp_Id := Scope (Subp_Id);
1548             end loop;
1549          end Check_Mode_Restriction_In_Enclosing_Context;
1550
1551          ----------------------------------------
1552          -- Check_Mode_Restriction_In_Function --
1553          ----------------------------------------
1554
1555          procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is
1556          begin
1557             if Ekind (Subp_Id) = E_Function then
1558                Error_Msg_N
1559                  ("global mode & not applicable to functions", Mode);
1560             end if;
1561          end Check_Mode_Restriction_In_Function;
1562
1563          --  Local variables
1564
1565          Assoc : Node_Id;
1566          Item  : Node_Id;
1567          Mode  : Node_Id;
1568
1569       --  Start of processing for Analyze_Global_List
1570
1571       begin
1572          --  Single global item declaration
1573
1574          if Nkind_In (List, N_Identifier, N_Selected_Component) then
1575             Analyze_Global_Item (List, Global_Mode);
1576
1577          --  Simple global list or moded global list declaration
1578
1579          elsif Nkind (List) = N_Aggregate then
1580
1581             --  The declaration of a simple global list appear as a collection
1582             --  of expressions.
1583
1584             if Present (Expressions (List)) then
1585                if Present (Component_Associations (List)) then
1586                   Error_Msg_N
1587                     ("cannot mix moded and non-moded global lists", List);
1588                end if;
1589
1590                Item := First (Expressions (List));
1591                while Present (Item) loop
1592                   Analyze_Global_Item (Item, Global_Mode);
1593
1594                   Next (Item);
1595                end loop;
1596
1597             --  The declaration of a moded global list appears as a collection
1598             --  of component associations where individual choices denote
1599             --  modes.
1600
1601             elsif Present (Component_Associations (List)) then
1602                if Present (Expressions (List)) then
1603                   Error_Msg_N
1604                     ("cannot mix moded and non-moded global lists", List);
1605                end if;
1606
1607                Assoc := First (Component_Associations (List));
1608                while Present (Assoc) loop
1609                   Mode := First (Choices (Assoc));
1610
1611                   if Nkind (Mode) = N_Identifier then
1612                      if Chars (Mode) = Name_Contract_In then
1613                         Check_Duplicate_Mode (Mode, Contract_Seen);
1614
1615                      elsif Chars (Mode) = Name_In_Out then
1616                         Check_Duplicate_Mode (Mode, In_Out_Seen);
1617                         Check_Mode_Restriction_In_Function (Mode);
1618
1619                      elsif Chars (Mode) = Name_Input then
1620                         Check_Duplicate_Mode (Mode, Input_Seen);
1621
1622                      elsif Chars (Mode) = Name_Output then
1623                         Check_Duplicate_Mode (Mode, Output_Seen);
1624                         Check_Mode_Restriction_In_Function (Mode);
1625
1626                      else
1627                         Error_Msg_N ("invalid mode selector", Mode);
1628                      end if;
1629
1630                   else
1631                      Error_Msg_N ("invalid mode selector", Mode);
1632                   end if;
1633
1634                   --  Items in a moded list appear as a collection of
1635                   --  expressions. Reuse the existing machinery to analyze
1636                   --  them.
1637
1638                   Analyze_Global_List
1639                     (List        => Expression (Assoc),
1640                      Global_Mode => Chars (Mode));
1641
1642                   Next (Assoc);
1643                end loop;
1644
1645             --  Something went horribly wrong, we have a malformed tree
1646
1647             else
1648                raise Program_Error;
1649             end if;
1650
1651          --  Any other attempt to declare a global item is erroneous
1652
1653          else
1654             Error_Msg_N ("malformed global list declaration", List);
1655          end if;
1656       end Analyze_Global_List;
1657
1658       --  Local variables
1659
1660       List      : Node_Id;
1661       Subp_Decl : Node_Id;
1662
1663    --  Start of processing for Analyze_Global_In_Decl_List
1664
1665    begin
1666       Set_Analyzed (N);
1667
1668       Subp_Decl := Find_Related_Subprogram (N);
1669       Subp_Id   := Defining_Unit_Name (Specification (Subp_Decl));
1670       List      := Expression (Arg1);
1671
1672       --  There is nothing to be done for a null global list
1673
1674       if Nkind (List) = N_Null then
1675          null;
1676
1677       --  Analyze the various forms of global lists and items. Note that some
1678       --  of these may be malformed in which case the analysis emits error
1679       --  messages.
1680
1681       else
1682          --  Ensure that the formal parameters are visible when processing an
1683          --  item. This falls out of the general rule of aspects pertaining to
1684          --  subprogram declarations.
1685
1686          if Requires_Profile_Installation (N, Subp_Decl) then
1687             Push_Scope (Subp_Id);
1688             Install_Formals (Subp_Id);
1689          end if;
1690
1691          Analyze_Global_List (List);
1692
1693          if Requires_Profile_Installation (N, Subp_Decl) then
1694             End_Scope;
1695          end if;
1696       end if;
1697    end Analyze_Global_In_Decl_Part;
1698
1699    ------------------------------
1700    -- Analyze_PPC_In_Decl_Part --
1701    ------------------------------
1702
1703    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
1704       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
1705
1706    begin
1707       --  Install formals and push subprogram spec onto scope stack so that we
1708       --  can see the formals from the pragma.
1709
1710       Install_Formals (S);
1711       Push_Scope (S);
1712
1713       --  Preanalyze the boolean expression, we treat this as a spec expression
1714       --  (i.e. similar to a default expression).
1715
1716       Preanalyze_Assert_Expression (Get_Pragma_Arg (Arg1), Standard_Boolean);
1717
1718       --  In ASIS mode, for a pragma generated from a source aspect, also
1719       --  analyze the original aspect expression.
1720
1721       if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
1722          Preanalyze_Assert_Expression
1723            (Expression (Corresponding_Aspect (N)), Standard_Boolean);
1724       end if;
1725
1726       --  For a class-wide condition, a reference to a controlling formal must
1727       --  be interpreted as having the class-wide type (or an access to such)
1728       --  so that the inherited condition can be properly applied to any
1729       --  overriding operation (see ARM12 6.6.1 (7)).
1730
1731       if Class_Present (N) then
1732          Class_Wide_Condition : declare
1733             T   : constant Entity_Id := Find_Dispatching_Type (S);
1734
1735             ACW : Entity_Id := Empty;
1736             --  Access to T'class, created if there is a controlling formal
1737             --  that is an access parameter.
1738
1739             function Get_ACW return Entity_Id;
1740             --  If the expression has a reference to an controlling access
1741             --  parameter, create an access to T'class for the necessary
1742             --  conversions if one does not exist.
1743
1744             function Process (N : Node_Id) return Traverse_Result;
1745             --  ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
1746             --  aspect for a primitive subprogram of a tagged type T, a name
1747             --  that denotes a formal parameter of type T is interpreted as
1748             --  having type T'Class. Similarly, a name that denotes a formal
1749             --  accessparameter of type access-to-T is interpreted as having
1750             --  type access-to-T'Class. This ensures the expression is well-
1751             --  defined for a primitive subprogram of a type descended from T.
1752             --  Note that this replacement is not done for selector names in
1753             --  parameter associations. These carry an entity for reference
1754             --  purposes, but semantically they are just identifiers.
1755
1756             -------------
1757             -- Get_ACW --
1758             -------------
1759
1760             function Get_ACW return Entity_Id is
1761                Loc  : constant Source_Ptr := Sloc (N);
1762                Decl : Node_Id;
1763
1764             begin
1765                if No (ACW) then
1766                   Decl := Make_Full_Type_Declaration (Loc,
1767                     Defining_Identifier => Make_Temporary (Loc, 'T'),
1768                     Type_Definition =>
1769                        Make_Access_To_Object_Definition (Loc,
1770                        Subtype_Indication =>
1771                          New_Occurrence_Of (Class_Wide_Type (T), Loc),
1772                        All_Present => True));
1773
1774                   Insert_Before (Unit_Declaration_Node (S), Decl);
1775                   Analyze (Decl);
1776                   ACW := Defining_Identifier (Decl);
1777                   Freeze_Before (Unit_Declaration_Node (S), ACW);
1778                end if;
1779
1780                return ACW;
1781             end Get_ACW;
1782
1783             -------------
1784             -- Process --
1785             -------------
1786
1787             function Process (N : Node_Id) return Traverse_Result is
1788                Loc : constant Source_Ptr := Sloc (N);
1789                Typ : Entity_Id;
1790
1791             begin
1792                if Is_Entity_Name (N)
1793                  and then Present (Entity (N))
1794                  and then Is_Formal (Entity (N))
1795                  and then Nkind (Parent (N)) /= N_Type_Conversion
1796                  and then
1797                    (Nkind (Parent (N)) /= N_Parameter_Association
1798                      or else N /= Selector_Name (Parent (N)))
1799                then
1800                   if Etype (Entity (N)) = T then
1801                      Typ := Class_Wide_Type (T);
1802
1803                   elsif Is_Access_Type (Etype (Entity (N)))
1804                     and then Designated_Type (Etype (Entity (N))) = T
1805                   then
1806                      Typ := Get_ACW;
1807                   else
1808                      Typ := Empty;
1809                   end if;
1810
1811                   if Present (Typ) then
1812                      Rewrite (N,
1813                        Make_Type_Conversion (Loc,
1814                          Subtype_Mark =>
1815                            New_Occurrence_Of (Typ, Loc),
1816                          Expression  => New_Occurrence_Of (Entity (N), Loc)));
1817                      Set_Etype (N, Typ);
1818                   end if;
1819                end if;
1820
1821                return OK;
1822             end Process;
1823
1824             procedure Replace_Type is new Traverse_Proc (Process);
1825
1826          --  Start of processing for Class_Wide_Condition
1827
1828          begin
1829             if not Present (T) then
1830                Error_Msg_Name_1 :=
1831                  Chars (Identifier (Corresponding_Aspect (N)));
1832
1833                Error_Msg_Name_2 := Name_Class;
1834
1835                Error_Msg_N
1836                  ("aspect `%''%` can only be specified for a primitive "
1837                   & "operation of a tagged type", Corresponding_Aspect (N));
1838             end if;
1839
1840             Replace_Type (Get_Pragma_Arg (Arg1));
1841          end Class_Wide_Condition;
1842       end if;
1843
1844       --  Remove the subprogram from the scope stack now that the pre-analysis
1845       --  of the precondition/postcondition is done.
1846
1847       End_Scope;
1848    end Analyze_PPC_In_Decl_Part;
1849
1850    --------------------
1851    -- Analyze_Pragma --
1852    --------------------
1853
1854    procedure Analyze_Pragma (N : Node_Id) is
1855       Loc     : constant Source_Ptr := Sloc (N);
1856       Prag_Id : Pragma_Id;
1857
1858       Pname : Name_Id;
1859       --  Name of the source pragma, or name of the corresponding aspect for
1860       --  pragmas which originate in a source aspect. In the latter case, the
1861       --  name may be different from the pragma name.
1862
1863       Pragma_Exit : exception;
1864       --  This exception is used to exit pragma processing completely. It is
1865       --  used when an error is detected, and no further processing is
1866       --  required. It is also used if an earlier error has left the tree in
1867       --  a state where the pragma should not be processed.
1868
1869       Arg_Count : Nat;
1870       --  Number of pragma argument associations
1871
1872       Arg1 : Node_Id;
1873       Arg2 : Node_Id;
1874       Arg3 : Node_Id;
1875       Arg4 : Node_Id;
1876       --  First four pragma arguments (pragma argument association nodes, or
1877       --  Empty if the corresponding argument does not exist).
1878
1879       type Name_List is array (Natural range <>) of Name_Id;
1880       type Args_List is array (Natural range <>) of Node_Id;
1881       --  Types used for arguments to Check_Arg_Order and Gather_Associations
1882
1883       procedure Ada_2005_Pragma;
1884       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
1885       --  Ada 95 mode, these are implementation defined pragmas, so should be
1886       --  caught by the No_Implementation_Pragmas restriction.
1887
1888       procedure Ada_2012_Pragma;
1889       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
1890       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
1891       --  should be caught by the No_Implementation_Pragmas restriction.
1892
1893       procedure Check_Ada_83_Warning;
1894       --  Issues a warning message for the current pragma if operating in Ada
1895       --  83 mode (used for language pragmas that are not a standard part of
1896       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
1897       --  of 95 pragma.
1898
1899       procedure Check_Arg_Count (Required : Nat);
1900       --  Check argument count for pragma is equal to given parameter. If not,
1901       --  then issue an error message and raise Pragma_Exit.
1902
1903       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
1904       --  Arg which can either be a pragma argument association, in which case
1905       --  the check is applied to the expression of the association or an
1906       --  expression directly.
1907
1908       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
1909       --  Check that an argument has the right form for an EXTERNAL_NAME
1910       --  parameter of an extended import/export pragma. The rule is that the
1911       --  name must be an identifier or string literal (in Ada 83 mode) or a
1912       --  static string expression (in Ada 95 mode).
1913
1914       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
1915       --  Check the specified argument Arg to make sure that it is an
1916       --  identifier. If not give error and raise Pragma_Exit.
1917
1918       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
1919       --  Check the specified argument Arg to make sure that it is an integer
1920       --  literal. If not give error and raise Pragma_Exit.
1921
1922       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
1923       --  Check the specified argument Arg to make sure that it has the proper
1924       --  syntactic form for a local name and meets the semantic requirements
1925       --  for a local name. The local name is analyzed as part of the
1926       --  processing for this call. In addition, the local name is required
1927       --  to represent an entity at the library level.
1928
1929       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
1930       --  Check the specified argument Arg to make sure that it has the proper
1931       --  syntactic form for a local name and meets the semantic requirements
1932       --  for a local name. The local name is analyzed as part of the
1933       --  processing for this call.
1934
1935       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
1936       --  Check the specified argument Arg to make sure that it is a valid
1937       --  locking policy name. If not give error and raise Pragma_Exit.
1938
1939       procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id);
1940       --  Check the specified argument Arg to make sure that it is a valid
1941       --  elaboration policy name. If not give error and raise Pragma_Exit.
1942
1943       procedure Check_Arg_Is_One_Of
1944         (Arg                : Node_Id;
1945          N1, N2             : Name_Id);
1946       procedure Check_Arg_Is_One_Of
1947         (Arg                : Node_Id;
1948          N1, N2, N3         : Name_Id);
1949       procedure Check_Arg_Is_One_Of
1950         (Arg                : Node_Id;
1951          N1, N2, N3, N4     : Name_Id);
1952       procedure Check_Arg_Is_One_Of
1953         (Arg                : Node_Id;
1954          N1, N2, N3, N4, N5 : Name_Id);
1955       --  Check the specified argument Arg to make sure that it is an
1956       --  identifier whose name matches either N1 or N2 (or N3, N4, N5 if
1957       --  present). If not then give error and raise Pragma_Exit.
1958
1959       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
1960       --  Check the specified argument Arg to make sure that it is a valid
1961       --  queuing policy name. If not give error and raise Pragma_Exit.
1962
1963       procedure Check_Arg_Is_Static_Expression
1964         (Arg : Node_Id;
1965          Typ : Entity_Id := Empty);
1966       --  Check the specified argument Arg to make sure that it is a static
1967       --  expression of the given type (i.e. it will be analyzed and resolved
1968       --  using this type, which can be any valid argument to Resolve, e.g.
1969       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
1970       --  Typ is left Empty, then any static expression is allowed.
1971
1972       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
1973       --  Check the specified argument Arg to make sure that it is a valid task
1974       --  dispatching policy name. If not give error and raise Pragma_Exit.
1975
1976       procedure Check_Arg_Order (Names : Name_List);
1977       --  Checks for an instance of two arguments with identifiers for the
1978       --  current pragma which are not in the sequence indicated by Names,
1979       --  and if so, generates a fatal message about bad order of arguments.
1980
1981       procedure Check_At_Least_N_Arguments (N : Nat);
1982       --  Check there are at least N arguments present
1983
1984       procedure Check_At_Most_N_Arguments (N : Nat);
1985       --  Check there are no more than N arguments present
1986
1987       procedure Check_Component
1988         (Comp            : Node_Id;
1989          UU_Typ          : Entity_Id;
1990          In_Variant_Part : Boolean := False);
1991       --  Examine an Unchecked_Union component for correct use of per-object
1992       --  constrained subtypes, and for restrictions on finalizable components.
1993       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
1994       --  should be set when Comp comes from a record variant.
1995
1996       procedure Check_Test_Case;
1997       --  Called to process a test-case pragma. It starts with checking pragma
1998       --  arguments, and the rest of the treatment is similar to the one for
1999       --  pre- and postcondition in Check_Precondition_Postcondition, except
2000       --  the placement rules for the test-case pragma are stricter. These
2001       --  pragmas may only occur after a subprogram spec declared directly
2002       --  in a package spec unit. In this case, the pragma is chained to the
2003       --  subprogram in question (using Contract_Test_Cases and Next_Pragma)
2004       --  and analysis of the pragma is delayed till the end of the spec. In
2005       --  all other cases, an error message for bad placement is given.
2006
2007       procedure Check_Duplicate_Pragma (E : Entity_Id);
2008       --  Check if a rep item of the same name as the current pragma is already
2009       --  chained as a rep pragma to the given entity. If so give a message
2010       --  about the duplicate, and then raise Pragma_Exit so does not return.
2011
2012       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
2013       --  Nam is an N_String_Literal node containing the external name set by
2014       --  an Import or Export pragma (or extended Import or Export pragma).
2015       --  This procedure checks for possible duplications if this is the export
2016       --  case, and if found, issues an appropriate error message.
2017
2018       procedure Check_Expr_Is_Static_Expression
2019         (Expr : Node_Id;
2020          Typ  : Entity_Id := Empty);
2021       --  Check the specified expression Expr to make sure that it is a static
2022       --  expression of the given type (i.e. it will be analyzed and resolved
2023       --  using this type, which can be any valid argument to Resolve, e.g.
2024       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2025       --  Typ is left Empty, then any static expression is allowed.
2026
2027       procedure Check_First_Subtype (Arg : Node_Id);
2028       --  Checks that Arg, whose expression is an entity name, references a
2029       --  first subtype.
2030
2031       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
2032       --  Checks that the given argument has an identifier, and if so, requires
2033       --  it to match the given identifier name. If there is no identifier, or
2034       --  a non-matching identifier, then an error message is given and
2035       --  Pragma_Exit is raised.
2036
2037       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
2038       --  Checks that the given argument has an identifier, and if so, requires
2039       --  it to match one of the given identifier names. If there is no
2040       --  identifier, or a non-matching identifier, then an error message is
2041       --  given and Pragma_Exit is raised.
2042
2043       procedure Check_In_Main_Program;
2044       --  Common checks for pragmas that appear within a main program
2045       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2046
2047       procedure Check_Interrupt_Or_Attach_Handler;
2048       --  Common processing for first argument of pragma Interrupt_Handler or
2049       --  pragma Attach_Handler.
2050
2051       procedure Check_Loop_Pragma_Placement;
2052       --  Verify whether pragma Loop_Invariant or Loop_Optimize or Loop_Variant
2053       --  appear immediately within a construct restricted to loops.
2054
2055       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
2056       --  Check that pragma appears in a declarative part, or in a package
2057       --  specification, i.e. that it does not occur in a statement sequence
2058       --  in a body.
2059
2060       procedure Check_No_Identifier (Arg : Node_Id);
2061       --  Checks that the given argument does not have an identifier. If
2062       --  an identifier is present, then an error message is issued, and
2063       --  Pragma_Exit is raised.
2064
2065       procedure Check_No_Identifiers;
2066       --  Checks that none of the arguments to the pragma has an identifier.
2067       --  If any argument has an identifier, then an error message is issued,
2068       --  and Pragma_Exit is raised.
2069
2070       procedure Check_No_Link_Name;
2071       --  Checks that no link name is specified
2072
2073       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
2074       --  Checks if the given argument has an identifier, and if so, requires
2075       --  it to match the given identifier name. If there is a non-matching
2076       --  identifier, then an error message is given and Pragma_Exit is raised.
2077
2078       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
2079       --  Checks if the given argument has an identifier, and if so, requires
2080       --  it to match the given identifier name. If there is a non-matching
2081       --  identifier, then an error message is given and Pragma_Exit is raised.
2082       --  In this version of the procedure, the identifier name is given as
2083       --  a string with lower case letters.
2084
2085       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
2086       --  Called to process a precondition or postcondition pragma. There are
2087       --  three cases:
2088       --
2089       --    The pragma appears after a subprogram spec
2090       --
2091       --      If the corresponding check is not enabled, the pragma is analyzed
2092       --      but otherwise ignored and control returns with In_Body set False.
2093       --
2094       --      If the check is enabled, then the first step is to analyze the
2095       --      pragma, but this is skipped if the subprogram spec appears within
2096       --      a package specification (because this is the case where we delay
2097       --      analysis till the end of the spec). Then (whether or not it was
2098       --      analyzed), the pragma is chained to the subprogram in question
2099       --      (using Pre_Post_Conditions and Next_Pragma) and control returns
2100       --      to the caller with In_Body set False.
2101       --
2102       --    The pragma appears at the start of subprogram body declarations
2103       --
2104       --      In this case an immediate return to the caller is made with
2105       --      In_Body set True, and the pragma is NOT analyzed.
2106       --
2107       --    In all other cases, an error message for bad placement is given
2108
2109       procedure Check_Static_Constraint (Constr : Node_Id);
2110       --  Constr is a constraint from an N_Subtype_Indication node from a
2111       --  component constraint in an Unchecked_Union type. This routine checks
2112       --  that the constraint is static as required by the restrictions for
2113       --  Unchecked_Union.
2114
2115       procedure Check_Valid_Configuration_Pragma;
2116       --  Legality checks for placement of a configuration pragma
2117
2118       procedure Check_Valid_Library_Unit_Pragma;
2119       --  Legality checks for library unit pragmas. A special case arises for
2120       --  pragmas in generic instances that come from copies of the original
2121       --  library unit pragmas in the generic templates. In the case of other
2122       --  than library level instantiations these can appear in contexts which
2123       --  would normally be invalid (they only apply to the original template
2124       --  and to library level instantiations), and they are simply ignored,
2125       --  which is implemented by rewriting them as null statements.
2126
2127       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
2128       --  Check an Unchecked_Union variant for lack of nested variants and
2129       --  presence of at least one component. UU_Typ is the related Unchecked_
2130       --  Union type.
2131
2132       procedure Error_Pragma (Msg : String);
2133       pragma No_Return (Error_Pragma);
2134       --  Outputs error message for current pragma. The message contains a %
2135       --  that will be replaced with the pragma name, and the flag is placed
2136       --  on the pragma itself. Pragma_Exit is then raised. Note: this routine
2137       --  calls Fix_Error (see spec of that procedure for details).
2138
2139       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
2140       pragma No_Return (Error_Pragma_Arg);
2141       --  Outputs error message for current pragma. The message may contain
2142       --  a % that will be replaced with the pragma name. The parameter Arg
2143       --  may either be a pragma argument association, in which case the flag
2144       --  is placed on the expression of this association, or an expression,
2145       --  in which case the flag is placed directly on the expression. The
2146       --  message is placed using Error_Msg_N, so the message may also contain
2147       --  an & insertion character which will reference the given Arg value.
2148       --  After placing the message, Pragma_Exit is raised. Note: this routine
2149       --  calls Fix_Error (see spec of that procedure for details).
2150
2151       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
2152       pragma No_Return (Error_Pragma_Arg);
2153       --  Similar to above form of Error_Pragma_Arg except that two messages
2154       --  are provided, the second is a continuation comment starting with \.
2155
2156       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
2157       pragma No_Return (Error_Pragma_Arg_Ident);
2158       --  Outputs error message for current pragma. The message may contain
2159       --  a % that will be replaced with the pragma name. The parameter Arg
2160       --  must be a pragma argument association with a non-empty identifier
2161       --  (i.e. its Chars field must be set), and the error message is placed
2162       --  on the identifier. The message is placed using Error_Msg_N so
2163       --  the message may also contain an & insertion character which will
2164       --  reference the identifier. After placing the message, Pragma_Exit
2165       --  is raised. Note: this routine calls Fix_Error (see spec of that
2166       --  procedure for details).
2167
2168       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
2169       pragma No_Return (Error_Pragma_Ref);
2170       --  Outputs error message for current pragma. The message may contain
2171       --  a % that will be replaced with the pragma name. The parameter Ref
2172       --  must be an entity whose name can be referenced by & and sloc by #.
2173       --  After placing the message, Pragma_Exit is raised. Note: this routine
2174       --  calls Fix_Error (see spec of that procedure for details).
2175
2176       function Find_Lib_Unit_Name return Entity_Id;
2177       --  Used for a library unit pragma to find the entity to which the
2178       --  library unit pragma applies, returns the entity found.
2179
2180       procedure Find_Program_Unit_Name (Id : Node_Id);
2181       --  If the pragma is a compilation unit pragma, the id must denote the
2182       --  compilation unit in the same compilation, and the pragma must appear
2183       --  in the list of preceding or trailing pragmas. If it is a program
2184       --  unit pragma that is not a compilation unit pragma, then the
2185       --  identifier must be visible.
2186
2187       function Find_Unique_Parameterless_Procedure
2188         (Name : Entity_Id;
2189          Arg  : Node_Id) return Entity_Id;
2190       --  Used for a procedure pragma to find the unique parameterless
2191       --  procedure identified by Name, returns it if it exists, otherwise
2192       --  errors out and uses Arg as the pragma argument for the message.
2193
2194       procedure Fix_Error (Msg : in out String);
2195       --  This is called prior to issuing an error message. Msg is a string
2196       --  that typically contains the substring "pragma". If the pragma comes
2197       --  from an aspect, each such "pragma" substring is replaced with the
2198       --  characters "aspect", and Error_Msg_Name_1 is set to the name of the
2199       --  aspect (which may be different from the pragma name). If the current
2200       --  pragma results from rewriting another pragma, then Error_Msg_Name_1
2201       --  is set to the original pragma name.
2202
2203       procedure Gather_Associations
2204         (Names : Name_List;
2205          Args  : out Args_List);
2206       --  This procedure is used to gather the arguments for a pragma that
2207       --  permits arbitrary ordering of parameters using the normal rules
2208       --  for named and positional parameters. The Names argument is a list
2209       --  of Name_Id values that corresponds to the allowed pragma argument
2210       --  association identifiers in order. The result returned in Args is
2211       --  a list of corresponding expressions that are the pragma arguments.
2212       --  Note that this is a list of expressions, not of pragma argument
2213       --  associations (Gather_Associations has completely checked all the
2214       --  optional identifiers when it returns). An entry in Args is Empty
2215       --  on return if the corresponding argument is not present.
2216
2217       procedure GNAT_Pragma;
2218       --  Called for all GNAT defined pragmas to check the relevant restriction
2219       --  (No_Implementation_Pragmas).
2220
2221       procedure S14_Pragma;
2222       --  Called for all pragmas defined for formal verification to check that
2223       --  the S14_Extensions flag is set.
2224       --  This name needs fixing ??? There is no such thing as an
2225       --  "S14_Extensions" flag ???
2226
2227       function Is_Before_First_Decl
2228         (Pragma_Node : Node_Id;
2229          Decls       : List_Id) return Boolean;
2230       --  Return True if Pragma_Node is before the first declarative item in
2231       --  Decls where Decls is the list of declarative items.
2232
2233       function Is_Configuration_Pragma return Boolean;
2234       --  Determines if the placement of the current pragma is appropriate
2235       --  for a configuration pragma.
2236
2237       function Is_In_Context_Clause return Boolean;
2238       --  Returns True if pragma appears within the context clause of a unit,
2239       --  and False for any other placement (does not generate any messages).
2240
2241       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
2242       --  Analyzes the argument, and determines if it is a static string
2243       --  expression, returns True if so, False if non-static or not String.
2244
2245       procedure Pragma_Misplaced;
2246       pragma No_Return (Pragma_Misplaced);
2247       --  Issue fatal error message for misplaced pragma
2248
2249       procedure Process_Atomic_Shared_Volatile;
2250       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
2251       --  Shared is an obsolete Ada 83 pragma, treated as being identical
2252       --  in effect to pragma Atomic.
2253
2254       procedure Process_Compile_Time_Warning_Or_Error;
2255       --  Common processing for Compile_Time_Error and Compile_Time_Warning
2256
2257       procedure Process_Convention
2258         (C   : out Convention_Id;
2259          Ent : out Entity_Id);
2260       --  Common processing for Convention, Interface, Import and Export.
2261       --  Checks first two arguments of pragma, and sets the appropriate
2262       --  convention value in the specified entity or entities. On return
2263       --  C is the convention, Ent is the referenced entity.
2264
2265       procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id);
2266       --  Common processing for Disable/Enable_Atomic_Synchronization. Nam is
2267       --  Name_Suppress for Disable and Name_Unsuppress for Enable.
2268
2269       procedure Process_Extended_Import_Export_Exception_Pragma
2270         (Arg_Internal : Node_Id;
2271          Arg_External : Node_Id;
2272          Arg_Form     : Node_Id;
2273          Arg_Code     : Node_Id);
2274       --  Common processing for the pragmas Import/Export_Exception. The three
2275       --  arguments correspond to the three named parameters of the pragma. An
2276       --  argument is empty if the corresponding parameter is not present in
2277       --  the pragma.
2278
2279       procedure Process_Extended_Import_Export_Object_Pragma
2280         (Arg_Internal : Node_Id;
2281          Arg_External : Node_Id;
2282          Arg_Size     : Node_Id);
2283       --  Common processing for the pragmas Import/Export_Object. The three
2284       --  arguments correspond to the three named parameters of the pragmas. An
2285       --  argument is empty if the corresponding parameter is not present in
2286       --  the pragma.
2287
2288       procedure Process_Extended_Import_Export_Internal_Arg
2289         (Arg_Internal : Node_Id := Empty);
2290       --  Common processing for all extended Import and Export pragmas. The
2291       --  argument is the pragma parameter for the Internal argument. If
2292       --  Arg_Internal is empty or inappropriate, an error message is posted.
2293       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
2294       --  set to identify the referenced entity.
2295
2296       procedure Process_Extended_Import_Export_Subprogram_Pragma
2297         (Arg_Internal                 : Node_Id;
2298          Arg_External                 : Node_Id;
2299          Arg_Parameter_Types          : Node_Id;
2300          Arg_Result_Type              : Node_Id := Empty;
2301          Arg_Mechanism                : Node_Id;
2302          Arg_Result_Mechanism         : Node_Id := Empty;
2303          Arg_First_Optional_Parameter : Node_Id := Empty);
2304       --  Common processing for all extended Import and Export pragmas applying
2305       --  to subprograms. The caller omits any arguments that do not apply to
2306       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
2307       --  only in the Import_Function and Export_Function cases). The argument
2308       --  names correspond to the allowed pragma association identifiers.
2309
2310       procedure Process_Generic_List;
2311       --  Common processing for Share_Generic and Inline_Generic
2312
2313       procedure Process_Import_Or_Interface;
2314       --  Common processing for Import of Interface
2315
2316       procedure Process_Import_Predefined_Type;
2317       --  Processing for completing a type with pragma Import. This is used
2318       --  to declare types that match predefined C types, especially for cases
2319       --  without corresponding Ada predefined type.
2320
2321       type Inline_Status is (Suppressed, Disabled, Enabled);
2322       --  Inline status of a subprogram, indicated as follows:
2323       --    Suppressed: inlining is suppressed for the subprogram
2324       --    Disabled:   no inlining is requested for the subprogram
2325       --    Enabled:    inlining is requested/required for the subprogram
2326
2327       procedure Process_Inline (Status : Inline_Status);
2328       --  Common processing for Inline, Inline_Always and No_Inline. Parameter
2329       --  indicates the inline status specified by the pragma.
2330
2331       procedure Process_Interface_Name
2332         (Subprogram_Def : Entity_Id;
2333          Ext_Arg        : Node_Id;
2334          Link_Arg       : Node_Id);
2335       --  Given the last two arguments of pragma Import, pragma Export, or
2336       --  pragma Interface_Name, performs validity checks and sets the
2337       --  Interface_Name field of the given subprogram entity to the
2338       --  appropriate external or link name, depending on the arguments given.
2339       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
2340       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
2341       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
2342       --  nor Link_Arg is present, the interface name is set to the default
2343       --  from the subprogram name.
2344
2345       procedure Process_Interrupt_Or_Attach_Handler;
2346       --  Common processing for Interrupt and Attach_Handler pragmas
2347
2348       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
2349       --  Common processing for Restrictions and Restriction_Warnings pragmas.
2350       --  Warn is True for Restriction_Warnings, or for Restrictions if the
2351       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
2352       --  is not set in the Restrictions case.
2353
2354       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
2355       --  Common processing for Suppress and Unsuppress. The boolean parameter
2356       --  Suppress_Case is True for the Suppress case, and False for the
2357       --  Unsuppress case.
2358
2359       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
2360       --  This procedure sets the Is_Exported flag for the given entity,
2361       --  checking that the entity was not previously imported. Arg is
2362       --  the argument that specified the entity. A check is also made
2363       --  for exporting inappropriate entities.
2364
2365       procedure Set_Extended_Import_Export_External_Name
2366         (Internal_Ent : Entity_Id;
2367          Arg_External : Node_Id);
2368       --  Common processing for all extended import export pragmas. The first
2369       --  argument, Internal_Ent, is the internal entity, which has already
2370       --  been checked for validity by the caller. Arg_External is from the
2371       --  Import or Export pragma, and may be null if no External parameter
2372       --  was present. If Arg_External is present and is a non-null string
2373       --  (a null string is treated as the default), then the Interface_Name
2374       --  field of Internal_Ent is set appropriately.
2375
2376       procedure Set_Imported (E : Entity_Id);
2377       --  This procedure sets the Is_Imported flag for the given entity,
2378       --  checking that it is not previously exported or imported.
2379
2380       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
2381       --  Mech is a parameter passing mechanism (see Import_Function syntax
2382       --  for MECHANISM_NAME). This routine checks that the mechanism argument
2383       --  has the right form, and if not issues an error message. If the
2384       --  argument has the right form then the Mechanism field of Ent is
2385       --  set appropriately.
2386
2387       procedure Set_Rational_Profile;
2388       --  Activate the set of configuration pragmas and permissions that make
2389       --  up the Rational profile.
2390
2391       procedure Set_Ravenscar_Profile (N : Node_Id);
2392       --  Activate the set of configuration pragmas and restrictions that make
2393       --  up the Ravenscar Profile. N is the corresponding pragma node, which
2394       --  is used for error messages on any constructs that violate the
2395       --  profile.
2396
2397       ---------------------
2398       -- Ada_2005_Pragma --
2399       ---------------------
2400
2401       procedure Ada_2005_Pragma is
2402       begin
2403          if Ada_Version <= Ada_95 then
2404             Check_Restriction (No_Implementation_Pragmas, N);
2405          end if;
2406       end Ada_2005_Pragma;
2407
2408       ---------------------
2409       -- Ada_2012_Pragma --
2410       ---------------------
2411
2412       procedure Ada_2012_Pragma is
2413       begin
2414          if Ada_Version <= Ada_2005 then
2415             Check_Restriction (No_Implementation_Pragmas, N);
2416          end if;
2417       end Ada_2012_Pragma;
2418
2419       --------------------------
2420       -- Check_Ada_83_Warning --
2421       --------------------------
2422
2423       procedure Check_Ada_83_Warning is
2424       begin
2425          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2426             Error_Msg_N ("(Ada 83) pragma& is non-standard??", N);
2427          end if;
2428       end Check_Ada_83_Warning;
2429
2430       ---------------------
2431       -- Check_Arg_Count --
2432       ---------------------
2433
2434       procedure Check_Arg_Count (Required : Nat) is
2435       begin
2436          if Arg_Count /= Required then
2437             Error_Pragma ("wrong number of arguments for pragma%");
2438          end if;
2439       end Check_Arg_Count;
2440
2441       --------------------------------
2442       -- Check_Arg_Is_External_Name --
2443       --------------------------------
2444
2445       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
2446          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2447
2448       begin
2449          if Nkind (Argx) = N_Identifier then
2450             return;
2451
2452          else
2453             Analyze_And_Resolve (Argx, Standard_String);
2454
2455             if Is_OK_Static_Expression (Argx) then
2456                return;
2457
2458             elsif Etype (Argx) = Any_Type then
2459                raise Pragma_Exit;
2460
2461             --  An interesting special case, if we have a string literal and
2462             --  we are in Ada 83 mode, then we allow it even though it will
2463             --  not be flagged as static. This allows expected Ada 83 mode
2464             --  use of external names which are string literals, even though
2465             --  technically these are not static in Ada 83.
2466
2467             elsif Ada_Version = Ada_83
2468               and then Nkind (Argx) = N_String_Literal
2469             then
2470                return;
2471
2472             --  Static expression that raises Constraint_Error. This has
2473             --  already been flagged, so just exit from pragma processing.
2474
2475             elsif Is_Static_Expression (Argx) then
2476                raise Pragma_Exit;
2477
2478             --  Here we have a real error (non-static expression)
2479
2480             else
2481                Error_Msg_Name_1 := Pname;
2482
2483                declare
2484                   Msg : String :=
2485                           "argument for pragma% must be a identifier or "
2486                           & "static string expression!";
2487                begin
2488                   Fix_Error (Msg);
2489                   Flag_Non_Static_Expr (Msg, Argx);
2490                   raise Pragma_Exit;
2491                end;
2492             end if;
2493          end if;
2494       end Check_Arg_Is_External_Name;
2495
2496       -----------------------------
2497       -- Check_Arg_Is_Identifier --
2498       -----------------------------
2499
2500       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
2501          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2502       begin
2503          if Nkind (Argx) /= N_Identifier then
2504             Error_Pragma_Arg
2505               ("argument for pragma% must be identifier", Argx);
2506          end if;
2507       end Check_Arg_Is_Identifier;
2508
2509       ----------------------------------
2510       -- Check_Arg_Is_Integer_Literal --
2511       ----------------------------------
2512
2513       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
2514          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2515       begin
2516          if Nkind (Argx) /= N_Integer_Literal then
2517             Error_Pragma_Arg
2518               ("argument for pragma% must be integer literal", Argx);
2519          end if;
2520       end Check_Arg_Is_Integer_Literal;
2521
2522       -------------------------------------------
2523       -- Check_Arg_Is_Library_Level_Local_Name --
2524       -------------------------------------------
2525
2526       --  LOCAL_NAME ::=
2527       --    DIRECT_NAME
2528       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
2529       --  | library_unit_NAME
2530
2531       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
2532       begin
2533          Check_Arg_Is_Local_Name (Arg);
2534
2535          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
2536            and then Comes_From_Source (N)
2537          then
2538             Error_Pragma_Arg
2539               ("argument for pragma% must be library level entity", Arg);
2540          end if;
2541       end Check_Arg_Is_Library_Level_Local_Name;
2542
2543       -----------------------------
2544       -- Check_Arg_Is_Local_Name --
2545       -----------------------------
2546
2547       --  LOCAL_NAME ::=
2548       --    DIRECT_NAME
2549       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
2550       --  | library_unit_NAME
2551
2552       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
2553          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2554
2555       begin
2556          Analyze (Argx);
2557
2558          if Nkind (Argx) not in N_Direct_Name
2559            and then (Nkind (Argx) /= N_Attribute_Reference
2560                       or else Present (Expressions (Argx))
2561                       or else Nkind (Prefix (Argx)) /= N_Identifier)
2562            and then (not Is_Entity_Name (Argx)
2563                       or else not Is_Compilation_Unit (Entity (Argx)))
2564          then
2565             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
2566          end if;
2567
2568          --  No further check required if not an entity name
2569
2570          if not Is_Entity_Name (Argx) then
2571             null;
2572
2573          else
2574             declare
2575                OK   : Boolean;
2576                Ent  : constant Entity_Id := Entity (Argx);
2577                Scop : constant Entity_Id := Scope (Ent);
2578
2579             begin
2580                --  Case of a pragma applied to a compilation unit: pragma must
2581                --  occur immediately after the program unit in the compilation.
2582
2583                if Is_Compilation_Unit (Ent) then
2584                   declare
2585                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
2586
2587                   begin
2588                      --  Case of pragma placed immediately after spec
2589
2590                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
2591                         OK := True;
2592
2593                      --  Case of pragma placed immediately after body
2594
2595                      elsif Nkind (Decl) = N_Subprogram_Declaration
2596                              and then Present (Corresponding_Body (Decl))
2597                      then
2598                         OK := Parent (N) =
2599                                 Aux_Decls_Node
2600                                   (Parent (Unit_Declaration_Node
2601                                              (Corresponding_Body (Decl))));
2602
2603                      --  All other cases are illegal
2604
2605                      else
2606                         OK := False;
2607                      end if;
2608                   end;
2609
2610                --  Special restricted placement rule from 10.2.1(11.8/2)
2611
2612                elsif Is_Generic_Formal (Ent)
2613                        and then Prag_Id = Pragma_Preelaborable_Initialization
2614                then
2615                   OK := List_Containing (N) =
2616                           Generic_Formal_Declarations
2617                             (Unit_Declaration_Node (Scop));
2618
2619                --  Default case, just check that the pragma occurs in the scope
2620                --  of the entity denoted by the name.
2621
2622                else
2623                   OK := Current_Scope = Scop;
2624                end if;
2625
2626                if not OK then
2627                   Error_Pragma_Arg
2628                     ("pragma% argument must be in same declarative part", Arg);
2629                end if;
2630             end;
2631          end if;
2632       end Check_Arg_Is_Local_Name;
2633
2634       ---------------------------------
2635       -- Check_Arg_Is_Locking_Policy --
2636       ---------------------------------
2637
2638       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
2639          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2640
2641       begin
2642          Check_Arg_Is_Identifier (Argx);
2643
2644          if not Is_Locking_Policy_Name (Chars (Argx)) then
2645             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
2646          end if;
2647       end Check_Arg_Is_Locking_Policy;
2648
2649       -----------------------------------------------
2650       -- Check_Arg_Is_Partition_Elaboration_Policy --
2651       -----------------------------------------------
2652
2653       procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is
2654          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2655
2656       begin
2657          Check_Arg_Is_Identifier (Argx);
2658
2659          if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then
2660             Error_Pragma_Arg
2661               ("& is not a valid partition elaboration policy name", Argx);
2662          end if;
2663       end Check_Arg_Is_Partition_Elaboration_Policy;
2664
2665       -------------------------
2666       -- Check_Arg_Is_One_Of --
2667       -------------------------
2668
2669       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
2670          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2671
2672       begin
2673          Check_Arg_Is_Identifier (Argx);
2674
2675          if not Nam_In (Chars (Argx), N1, N2) then
2676             Error_Msg_Name_2 := N1;
2677             Error_Msg_Name_3 := N2;
2678             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
2679          end if;
2680       end Check_Arg_Is_One_Of;
2681
2682       procedure Check_Arg_Is_One_Of
2683         (Arg        : Node_Id;
2684          N1, N2, N3 : Name_Id)
2685       is
2686          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2687
2688       begin
2689          Check_Arg_Is_Identifier (Argx);
2690
2691          if not Nam_In (Chars (Argx), N1, N2, N3) then
2692             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
2693          end if;
2694       end Check_Arg_Is_One_Of;
2695
2696       procedure Check_Arg_Is_One_Of
2697         (Arg                : Node_Id;
2698          N1, N2, N3, N4     : Name_Id)
2699       is
2700          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2701
2702       begin
2703          Check_Arg_Is_Identifier (Argx);
2704
2705          if not Nam_In (Chars (Argx), N1, N2, N3, N4) then
2706             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
2707          end if;
2708       end Check_Arg_Is_One_Of;
2709
2710       procedure Check_Arg_Is_One_Of
2711         (Arg                : Node_Id;
2712          N1, N2, N3, N4, N5 : Name_Id)
2713       is
2714          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2715
2716       begin
2717          Check_Arg_Is_Identifier (Argx);
2718
2719          if not Nam_In (Chars (Argx), N1, N2, N3, N4, N5) then
2720             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
2721          end if;
2722       end Check_Arg_Is_One_Of;
2723
2724       ---------------------------------
2725       -- Check_Arg_Is_Queuing_Policy --
2726       ---------------------------------
2727
2728       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
2729          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2730
2731       begin
2732          Check_Arg_Is_Identifier (Argx);
2733
2734          if not Is_Queuing_Policy_Name (Chars (Argx)) then
2735             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
2736          end if;
2737       end Check_Arg_Is_Queuing_Policy;
2738
2739       ------------------------------------
2740       -- Check_Arg_Is_Static_Expression --
2741       ------------------------------------
2742
2743       procedure Check_Arg_Is_Static_Expression
2744         (Arg : Node_Id;
2745          Typ : Entity_Id := Empty)
2746       is
2747       begin
2748          Check_Expr_Is_Static_Expression (Get_Pragma_Arg (Arg), Typ);
2749       end Check_Arg_Is_Static_Expression;
2750
2751       ------------------------------------------
2752       -- Check_Arg_Is_Task_Dispatching_Policy --
2753       ------------------------------------------
2754
2755       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
2756          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2757
2758       begin
2759          Check_Arg_Is_Identifier (Argx);
2760
2761          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
2762             Error_Pragma_Arg
2763               ("& is not a valid task dispatching policy name", Argx);
2764          end if;
2765       end Check_Arg_Is_Task_Dispatching_Policy;
2766
2767       ---------------------
2768       -- Check_Arg_Order --
2769       ---------------------
2770
2771       procedure Check_Arg_Order (Names : Name_List) is
2772          Arg : Node_Id;
2773
2774          Highest_So_Far : Natural := 0;
2775          --  Highest index in Names seen do far
2776
2777       begin
2778          Arg := Arg1;
2779          for J in 1 .. Arg_Count loop
2780             if Chars (Arg) /= No_Name then
2781                for K in Names'Range loop
2782                   if Chars (Arg) = Names (K) then
2783                      if K < Highest_So_Far then
2784                         Error_Msg_Name_1 := Pname;
2785                         Error_Msg_N
2786                           ("parameters out of order for pragma%", Arg);
2787                         Error_Msg_Name_1 := Names (K);
2788                         Error_Msg_Name_2 := Names (Highest_So_Far);
2789                         Error_Msg_N ("\% must appear before %", Arg);
2790                         raise Pragma_Exit;
2791
2792                      else
2793                         Highest_So_Far := K;
2794                      end if;
2795                   end if;
2796                end loop;
2797             end if;
2798
2799             Arg := Next (Arg);
2800          end loop;
2801       end Check_Arg_Order;
2802
2803       --------------------------------
2804       -- Check_At_Least_N_Arguments --
2805       --------------------------------
2806
2807       procedure Check_At_Least_N_Arguments (N : Nat) is
2808       begin
2809          if Arg_Count < N then
2810             Error_Pragma ("too few arguments for pragma%");
2811          end if;
2812       end Check_At_Least_N_Arguments;
2813
2814       -------------------------------
2815       -- Check_At_Most_N_Arguments --
2816       -------------------------------
2817
2818       procedure Check_At_Most_N_Arguments (N : Nat) is
2819          Arg : Node_Id;
2820       begin
2821          if Arg_Count > N then
2822             Arg := Arg1;
2823             for J in 1 .. N loop
2824                Next (Arg);
2825                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
2826             end loop;
2827          end if;
2828       end Check_At_Most_N_Arguments;
2829
2830       ---------------------
2831       -- Check_Component --
2832       ---------------------
2833
2834       procedure Check_Component
2835         (Comp            : Node_Id;
2836          UU_Typ          : Entity_Id;
2837          In_Variant_Part : Boolean := False)
2838       is
2839          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
2840          Sindic  : constant Node_Id :=
2841                      Subtype_Indication (Component_Definition (Comp));
2842          Typ     : constant Entity_Id := Etype (Comp_Id);
2843
2844       begin
2845          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
2846          --  object constraint, then the component type shall be an Unchecked_
2847          --  Union.
2848
2849          if Nkind (Sindic) = N_Subtype_Indication
2850            and then Has_Per_Object_Constraint (Comp_Id)
2851            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
2852          then
2853             Error_Msg_N
2854               ("component subtype subject to per-object constraint "
2855                & "must be an Unchecked_Union", Comp);
2856
2857          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
2858          --  the body of a generic unit, or within the body of any of its
2859          --  descendant library units, no part of the type of a component
2860          --  declared in a variant_part of the unchecked union type shall be of
2861          --  a formal private type or formal private extension declared within
2862          --  the formal part of the generic unit.
2863
2864          elsif Ada_Version >= Ada_2012
2865            and then In_Generic_Body (UU_Typ)
2866            and then In_Variant_Part
2867            and then Is_Private_Type (Typ)
2868            and then Is_Generic_Type (Typ)
2869          then
2870             Error_Msg_N
2871               ("component of unchecked union cannot be of generic type", Comp);
2872
2873          elsif Needs_Finalization (Typ) then
2874             Error_Msg_N
2875               ("component of unchecked union cannot be controlled", Comp);
2876
2877          elsif Has_Task (Typ) then
2878             Error_Msg_N
2879               ("component of unchecked union cannot have tasks", Comp);
2880          end if;
2881       end Check_Component;
2882
2883       ----------------------------
2884       -- Check_Duplicate_Pragma --
2885       ----------------------------
2886
2887       procedure Check_Duplicate_Pragma (E : Entity_Id) is
2888          Id : Entity_Id := E;
2889          P  : Node_Id;
2890
2891       begin
2892          --  Nothing to do if this pragma comes from an aspect specification,
2893          --  since we could not be duplicating a pragma, and we dealt with the
2894          --  case of duplicated aspects in Analyze_Aspect_Specifications.
2895
2896          if From_Aspect_Specification (N) then
2897             return;
2898          end if;
2899
2900          --  Otherwise current pragma may duplicate previous pragma or a
2901          --  previously given aspect specification or attribute definition
2902          --  clause for the same pragma.
2903
2904          P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False);
2905
2906          if Present (P) then
2907             Error_Msg_Name_1 := Pragma_Name (N);
2908             Error_Msg_Sloc := Sloc (P);
2909
2910             --  For a single protected or a single task object, the error is
2911             --  issued on the original entity.
2912
2913             if Ekind_In (Id, E_Task_Type, E_Protected_Type) then
2914                Id := Defining_Identifier (Original_Node (Parent (Id)));
2915             end if;
2916
2917             if Nkind (P) = N_Aspect_Specification
2918               or else From_Aspect_Specification (P)
2919             then
2920                Error_Msg_NE ("aspect% for & previously given#", N, Id);
2921             else
2922                Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id);
2923             end if;
2924
2925             raise Pragma_Exit;
2926          end if;
2927       end Check_Duplicate_Pragma;
2928
2929       ----------------------------------
2930       -- Check_Duplicated_Export_Name --
2931       ----------------------------------
2932
2933       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
2934          String_Val : constant String_Id := Strval (Nam);
2935
2936       begin
2937          --  We are only interested in the export case, and in the case of
2938          --  generics, it is the instance, not the template, that is the
2939          --  problem (the template will generate a warning in any case).
2940
2941          if not Inside_A_Generic
2942            and then (Prag_Id = Pragma_Export
2943                        or else
2944                      Prag_Id = Pragma_Export_Procedure
2945                        or else
2946                      Prag_Id = Pragma_Export_Valued_Procedure
2947                        or else
2948                      Prag_Id = Pragma_Export_Function)
2949          then
2950             for J in Externals.First .. Externals.Last loop
2951                if String_Equal (String_Val, Strval (Externals.Table (J))) then
2952                   Error_Msg_Sloc := Sloc (Externals.Table (J));
2953                   Error_Msg_N ("external name duplicates name given#", Nam);
2954                   exit;
2955                end if;
2956             end loop;
2957
2958             Externals.Append (Nam);
2959          end if;
2960       end Check_Duplicated_Export_Name;
2961
2962       -------------------------------------
2963       -- Check_Expr_Is_Static_Expression --
2964       -------------------------------------
2965
2966       procedure Check_Expr_Is_Static_Expression
2967         (Expr : Node_Id;
2968          Typ  : Entity_Id := Empty)
2969       is
2970       begin
2971          if Present (Typ) then
2972             Analyze_And_Resolve (Expr, Typ);
2973          else
2974             Analyze_And_Resolve (Expr);
2975          end if;
2976
2977          if Is_OK_Static_Expression (Expr) then
2978             return;
2979
2980          elsif Etype (Expr) = Any_Type then
2981             raise Pragma_Exit;
2982
2983          --  An interesting special case, if we have a string literal and we
2984          --  are in Ada 83 mode, then we allow it even though it will not be
2985          --  flagged as static. This allows the use of Ada 95 pragmas like
2986          --  Import in Ada 83 mode. They will of course be flagged with
2987          --  warnings as usual, but will not cause errors.
2988
2989          elsif Ada_Version = Ada_83
2990            and then Nkind (Expr) = N_String_Literal
2991          then
2992             return;
2993
2994          --  Static expression that raises Constraint_Error. This has already
2995          --  been flagged, so just exit from pragma processing.
2996
2997          elsif Is_Static_Expression (Expr) then
2998             raise Pragma_Exit;
2999
3000          --  Finally, we have a real error
3001
3002          else
3003             Error_Msg_Name_1 := Pname;
3004
3005             declare
3006                Msg : String :=
3007                        "argument for pragma% must be a static expression!";
3008             begin
3009                Fix_Error (Msg);
3010                Flag_Non_Static_Expr (Msg, Expr);
3011             end;
3012
3013             raise Pragma_Exit;
3014          end if;
3015       end Check_Expr_Is_Static_Expression;
3016
3017       -------------------------
3018       -- Check_First_Subtype --
3019       -------------------------
3020
3021       procedure Check_First_Subtype (Arg : Node_Id) is
3022          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
3023          Ent  : constant Entity_Id := Entity (Argx);
3024
3025       begin
3026          if Is_First_Subtype (Ent) then
3027             null;
3028
3029          elsif Is_Type (Ent) then
3030             Error_Pragma_Arg
3031               ("pragma% cannot apply to subtype", Argx);
3032
3033          elsif Is_Object (Ent) then
3034             Error_Pragma_Arg
3035               ("pragma% cannot apply to object, requires a type", Argx);
3036
3037          else
3038             Error_Pragma_Arg
3039               ("pragma% cannot apply to&, requires a type", Argx);
3040          end if;
3041       end Check_First_Subtype;
3042
3043       ----------------------
3044       -- Check_Identifier --
3045       ----------------------
3046
3047       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
3048       begin
3049          if Present (Arg)
3050            and then Nkind (Arg) = N_Pragma_Argument_Association
3051          then
3052             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
3053                Error_Msg_Name_1 := Pname;
3054                Error_Msg_Name_2 := Id;
3055                Error_Msg_N ("pragma% argument expects identifier%", Arg);
3056                raise Pragma_Exit;
3057             end if;
3058          end if;
3059       end Check_Identifier;
3060
3061       --------------------------------
3062       -- Check_Identifier_Is_One_Of --
3063       --------------------------------
3064
3065       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
3066       begin
3067          if Present (Arg)
3068            and then Nkind (Arg) = N_Pragma_Argument_Association
3069          then
3070             if Chars (Arg) = No_Name then
3071                Error_Msg_Name_1 := Pname;
3072                Error_Msg_N ("pragma% argument expects an identifier", Arg);
3073                raise Pragma_Exit;
3074
3075             elsif Chars (Arg) /= N1
3076               and then Chars (Arg) /= N2
3077             then
3078                Error_Msg_Name_1 := Pname;
3079                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
3080                raise Pragma_Exit;
3081             end if;
3082          end if;
3083       end Check_Identifier_Is_One_Of;
3084
3085       ---------------------------
3086       -- Check_In_Main_Program --
3087       ---------------------------
3088
3089       procedure Check_In_Main_Program is
3090          P : constant Node_Id := Parent (N);
3091
3092       begin
3093          --  Must be at in subprogram body
3094
3095          if Nkind (P) /= N_Subprogram_Body then
3096             Error_Pragma ("% pragma allowed only in subprogram");
3097
3098          --  Otherwise warn if obviously not main program
3099
3100          elsif Present (Parameter_Specifications (Specification (P)))
3101            or else not Is_Compilation_Unit (Defining_Entity (P))
3102          then
3103             Error_Msg_Name_1 := Pname;
3104             Error_Msg_N
3105               ("??pragma% is only effective in main program", N);
3106          end if;
3107       end Check_In_Main_Program;
3108
3109       ---------------------------------------
3110       -- Check_Interrupt_Or_Attach_Handler --
3111       ---------------------------------------
3112
3113       procedure Check_Interrupt_Or_Attach_Handler is
3114          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
3115          Handler_Proc, Proc_Scope : Entity_Id;
3116
3117       begin
3118          Analyze (Arg1_X);
3119
3120          if Prag_Id = Pragma_Interrupt_Handler then
3121             Check_Restriction (No_Dynamic_Attachment, N);
3122          end if;
3123
3124          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
3125          Proc_Scope := Scope (Handler_Proc);
3126
3127          --  On AAMP only, a pragma Interrupt_Handler is supported for
3128          --  nonprotected parameterless procedures.
3129
3130          if not AAMP_On_Target
3131            or else Prag_Id = Pragma_Attach_Handler
3132          then
3133             if Ekind (Proc_Scope) /= E_Protected_Type then
3134                Error_Pragma_Arg
3135                  ("argument of pragma% must be protected procedure", Arg1);
3136             end if;
3137
3138             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
3139                Error_Pragma ("pragma% must be in protected definition");
3140             end if;
3141          end if;
3142
3143          if not Is_Library_Level_Entity (Proc_Scope)
3144            or else (AAMP_On_Target
3145                      and then not Is_Library_Level_Entity (Handler_Proc))
3146          then
3147             Error_Pragma_Arg
3148               ("argument for pragma% must be library level entity", Arg1);
3149          end if;
3150
3151          --  AI05-0033: A pragma cannot appear within a generic body, because
3152          --  instance can be in a nested scope. The check that protected type
3153          --  is itself a library-level declaration is done elsewhere.
3154
3155          --  Note: we omit this check in Relaxed_RM_Semantics mode to properly
3156          --  handle code prior to AI-0033. Analysis tools typically are not
3157          --  interested in this pragma in any case, so no need to worry too
3158          --  much about its placement.
3159
3160          if Inside_A_Generic then
3161             if Ekind (Scope (Current_Scope)) = E_Generic_Package
3162               and then In_Package_Body (Scope (Current_Scope))
3163               and then not Relaxed_RM_Semantics
3164             then
3165                Error_Pragma ("pragma% cannot be used inside a generic");
3166             end if;
3167          end if;
3168       end Check_Interrupt_Or_Attach_Handler;
3169
3170       ---------------------------------
3171       -- Check_Loop_Pragma_Placement --
3172       ---------------------------------
3173
3174       procedure Check_Loop_Pragma_Placement is
3175          procedure Placement_Error (Constr : Node_Id);
3176          pragma No_Return (Placement_Error);
3177          --  Node Constr denotes the last loop restricted construct before we
3178          --  encountered an illegal relation between enclosing constructs. Emit
3179          --  an error depending on what Constr was.
3180
3181          ---------------------
3182          -- Placement_Error --
3183          ---------------------
3184
3185          procedure Placement_Error (Constr : Node_Id) is
3186          begin
3187             if Nkind (Constr) = N_Pragma then
3188                Error_Pragma
3189                  ("pragma % must appear immediately within the statements "
3190                   & "of a loop");
3191             else
3192                Error_Pragma_Arg
3193                  ("block containing pragma % must appear immediately within "
3194                   & "the statements of a loop", Constr);
3195             end if;
3196          end Placement_Error;
3197
3198          --  Local declarations
3199
3200          Prev : Node_Id;
3201          Stmt : Node_Id;
3202
3203       --  Start of processing for Check_Loop_Pragma_Placement
3204
3205       begin
3206          Prev := N;
3207          Stmt := Parent (N);
3208          while Present (Stmt) loop
3209
3210             --  The pragma or previous block must appear immediately within the
3211             --  current block's declarative or statement part.
3212
3213             if Nkind (Stmt) = N_Block_Statement then
3214                if (No (Declarations (Stmt))
3215                     or else List_Containing (Prev) /= Declarations (Stmt))
3216                  and then
3217                    List_Containing (Prev) /=
3218                      Statements (Handled_Statement_Sequence (Stmt))
3219                then
3220                   Placement_Error (Prev);
3221                   return;
3222
3223                --  Keep inspecting the parents because we are now within a
3224                --  chain of nested blocks.
3225
3226                else
3227                   Prev := Stmt;
3228                   Stmt := Parent (Stmt);
3229                end if;
3230
3231             --  The pragma or previous block must appear immediately within the
3232             --  statements of the loop.
3233
3234             elsif Nkind (Stmt) = N_Loop_Statement then
3235                if List_Containing (Prev) /= Statements (Stmt) then
3236                   Placement_Error (Prev);
3237                end if;
3238
3239                --  Stop the traversal because we reached the innermost loop
3240                --  regardless of whether we encountered an error or not.
3241
3242                return;
3243
3244             --  Ignore a handled statement sequence. Note that this node may
3245             --  be related to a subprogram body in which case we will emit an
3246             --  error on the next iteration of the search.
3247
3248             elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then
3249                Stmt := Parent (Stmt);
3250
3251             --  Any other statement breaks the chain from the pragma to the
3252             --  loop.
3253
3254             else
3255                Placement_Error (Prev);
3256                return;
3257             end if;
3258          end loop;
3259       end Check_Loop_Pragma_Placement;
3260
3261       -------------------------------------------
3262       -- Check_Is_In_Decl_Part_Or_Package_Spec --
3263       -------------------------------------------
3264
3265       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
3266          P : Node_Id;
3267
3268       begin
3269          P := Parent (N);
3270          loop
3271             if No (P) then
3272                exit;
3273
3274             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
3275                exit;
3276
3277             elsif Nkind_In (P, N_Package_Specification,
3278                                N_Block_Statement)
3279             then
3280                return;
3281
3282             --  Note: the following tests seem a little peculiar, because
3283             --  they test for bodies, but if we were in the statement part
3284             --  of the body, we would already have hit the handled statement
3285             --  sequence, so the only way we get here is by being in the
3286             --  declarative part of the body.
3287
3288             elsif Nkind_In (P, N_Subprogram_Body,
3289                                N_Package_Body,
3290                                N_Task_Body,
3291                                N_Entry_Body)
3292             then
3293                return;
3294             end if;
3295
3296             P := Parent (P);
3297          end loop;
3298
3299          Error_Pragma ("pragma% is not in declarative part or package spec");
3300       end Check_Is_In_Decl_Part_Or_Package_Spec;
3301
3302       -------------------------
3303       -- Check_No_Identifier --
3304       -------------------------
3305
3306       procedure Check_No_Identifier (Arg : Node_Id) is
3307       begin
3308          if Nkind (Arg) = N_Pragma_Argument_Association
3309            and then Chars (Arg) /= No_Name
3310          then
3311             Error_Pragma_Arg_Ident
3312               ("pragma% does not permit identifier& here", Arg);
3313          end if;
3314       end Check_No_Identifier;
3315
3316       --------------------------
3317       -- Check_No_Identifiers --
3318       --------------------------
3319
3320       procedure Check_No_Identifiers is
3321          Arg_Node : Node_Id;
3322       begin
3323          Arg_Node := Arg1;
3324          for J in 1 .. Arg_Count loop
3325             Check_No_Identifier (Arg_Node);
3326             Next (Arg_Node);
3327          end loop;
3328       end Check_No_Identifiers;
3329
3330       ------------------------
3331       -- Check_No_Link_Name --
3332       ------------------------
3333
3334       procedure Check_No_Link_Name is
3335       begin
3336          if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then
3337             Arg4 := Arg3;
3338          end if;
3339
3340          if Present (Arg4) then
3341             Error_Pragma_Arg
3342               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
3343          end if;
3344       end Check_No_Link_Name;
3345
3346       -------------------------------
3347       -- Check_Optional_Identifier --
3348       -------------------------------
3349
3350       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
3351       begin
3352          if Present (Arg)
3353            and then Nkind (Arg) = N_Pragma_Argument_Association
3354            and then Chars (Arg) /= No_Name
3355          then
3356             if Chars (Arg) /= Id then
3357                Error_Msg_Name_1 := Pname;
3358                Error_Msg_Name_2 := Id;
3359                Error_Msg_N ("pragma% argument expects identifier%", Arg);
3360                raise Pragma_Exit;
3361             end if;
3362          end if;
3363       end Check_Optional_Identifier;
3364
3365       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
3366       begin
3367          Name_Buffer (1 .. Id'Length) := Id;
3368          Name_Len := Id'Length;
3369          Check_Optional_Identifier (Arg, Name_Find);
3370       end Check_Optional_Identifier;
3371
3372       --------------------------------------
3373       -- Check_Precondition_Postcondition --
3374       --------------------------------------
3375
3376       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
3377          P  : Node_Id;
3378          PO : Node_Id;
3379
3380          procedure Chain_PPC (PO : Node_Id);
3381          --  If PO is an entry or a [generic] subprogram declaration node, then
3382          --  the precondition/postcondition applies to this subprogram and the
3383          --  processing for the pragma is completed. Otherwise the pragma is
3384          --  misplaced.
3385
3386          ---------------
3387          -- Chain_PPC --
3388          ---------------
3389
3390          procedure Chain_PPC (PO : Node_Id) is
3391             S : Entity_Id;
3392
3393          begin
3394             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
3395                if not From_Aspect_Specification (N) then
3396                   Error_Pragma
3397                     ("pragma% cannot be applied to abstract subprogram");
3398
3399                elsif Class_Present (N) then
3400                   null;
3401
3402                else
3403                   Error_Pragma
3404                     ("aspect % requires ''Class for abstract subprogram");
3405                end if;
3406
3407             --  AI05-0230: The same restriction applies to null procedures. For
3408             --  compatibility with earlier uses of the Ada pragma, apply this
3409             --  rule only to aspect specifications.
3410
3411             --  The above discrpency needs documentation. Robert is dubious
3412             --  about whether it is a good idea ???
3413
3414             elsif Nkind (PO) = N_Subprogram_Declaration
3415               and then Nkind (Specification (PO)) = N_Procedure_Specification
3416               and then Null_Present (Specification (PO))
3417               and then From_Aspect_Specification (N)
3418               and then not Class_Present (N)
3419             then
3420                Error_Pragma
3421                  ("aspect % requires ''Class for null procedure");
3422
3423             --  Pre/postconditions are legal on a subprogram body if it is not
3424             --  a completion of a declaration. They are also legal on a stub
3425             --  with no previous declarations (this is checked when processing
3426             --  the corresponding aspects).
3427
3428             elsif Nkind (PO) = N_Subprogram_Body
3429               and then Acts_As_Spec (PO)
3430             then
3431                null;
3432
3433             elsif Nkind (PO) = N_Subprogram_Body_Stub then
3434                null;
3435
3436             elsif not Nkind_In (PO, N_Subprogram_Declaration,
3437                                     N_Expression_Function,
3438                                     N_Generic_Subprogram_Declaration,
3439                                     N_Entry_Declaration)
3440             then
3441                Pragma_Misplaced;
3442             end if;
3443
3444             --  Here if we have [generic] subprogram or entry declaration
3445
3446             if Nkind (PO) = N_Entry_Declaration then
3447                S := Defining_Entity (PO);
3448             else
3449                S := Defining_Unit_Name (Specification (PO));
3450
3451                if Nkind (S) = N_Defining_Program_Unit_Name then
3452                   S := Defining_Identifier (S);
3453                end if;
3454             end if;
3455
3456             --  Note: we do not analyze the pragma at this point. Instead we
3457             --  delay this analysis until the end of the declarative part in
3458             --  which the pragma appears. This implements the required delay
3459             --  in this analysis, allowing forward references. The analysis
3460             --  happens at the end of Analyze_Declarations.
3461
3462             --  Chain spec PPC pragma to list for subprogram
3463
3464             Add_Contract_Item (N, S);
3465
3466             --  Return indicating spec case
3467
3468             In_Body := False;
3469             return;
3470          end Chain_PPC;
3471
3472       --  Start of processing for Check_Precondition_Postcondition
3473
3474       begin
3475          if not Is_List_Member (N) then
3476             Pragma_Misplaced;
3477          end if;
3478
3479          --  Preanalyze message argument if present. Visibility in this
3480          --  argument is established at the point of pragma occurrence.
3481
3482          if Arg_Count = 2 then
3483             Check_Optional_Identifier (Arg2, Name_Message);
3484             Preanalyze_Spec_Expression
3485               (Get_Pragma_Arg (Arg2), Standard_String);
3486          end if;
3487
3488          --  For a pragma PPC in the extended main source unit, record enabled
3489          --  status in SCO.
3490
3491          if not Is_Ignored (N) and then not Split_PPC (N) then
3492             Set_SCO_Pragma_Enabled (Loc);
3493          end if;
3494
3495          --  If we are within an inlined body, the legality of the pragma
3496          --  has been checked already.
3497
3498          if In_Inlined_Body then
3499             In_Body := True;
3500             return;
3501          end if;
3502
3503          --  Search prior declarations
3504
3505          P := N;
3506          while Present (Prev (P)) loop
3507             P := Prev (P);
3508
3509             --  If the previous node is a generic subprogram, do not go to to
3510             --  the original node, which is the unanalyzed tree: we need to
3511             --  attach the pre/postconditions to the analyzed version at this
3512             --  point. They get propagated to the original tree when analyzing
3513             --  the corresponding body.
3514
3515             if Nkind (P) not in N_Generic_Declaration then
3516                PO := Original_Node (P);
3517             else
3518                PO := P;
3519             end if;
3520
3521             --  Skip past prior pragma
3522
3523             if Nkind (PO) = N_Pragma then
3524                null;
3525
3526             --  Skip stuff not coming from source
3527
3528             elsif not Comes_From_Source (PO) then
3529
3530                --  The condition may apply to a subprogram instantiation
3531
3532                if Nkind (PO) = N_Subprogram_Declaration
3533                  and then Present (Generic_Parent (Specification (PO)))
3534                then
3535                   Chain_PPC (PO);
3536                   return;
3537
3538                elsif Nkind (PO) = N_Subprogram_Declaration
3539                  and then In_Instance
3540                then
3541                   Chain_PPC (PO);
3542                   return;
3543
3544                --  For all other cases of non source code, do nothing
3545
3546                else
3547                   null;
3548                end if;
3549
3550             --  Only remaining possibility is subprogram declaration
3551
3552             else
3553                Chain_PPC (PO);
3554                return;
3555             end if;
3556          end loop;
3557
3558          --  If we fall through loop, pragma is at start of list, so see if it
3559          --  is at the start of declarations of a subprogram body.
3560
3561          if Nkind (Parent (N)) = N_Subprogram_Body
3562            and then List_Containing (N) = Declarations (Parent (N))
3563          then
3564             if Operating_Mode /= Generate_Code
3565               or else Inside_A_Generic
3566             then
3567                --  Analyze pragma expression for correctness and for ASIS use
3568
3569                Preanalyze_Assert_Expression
3570                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
3571
3572                --  In ASIS mode, for a pragma generated from a source aspect,
3573                --  also analyze the original aspect expression.
3574
3575                if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
3576                   Preanalyze_Assert_Expression
3577                     (Expression (Corresponding_Aspect (N)), Standard_Boolean);
3578                end if;
3579             end if;
3580
3581             In_Body := True;
3582             return;
3583
3584          --  See if it is in the pragmas after a library level subprogram
3585
3586          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
3587
3588             --  In formal verification mode, analyze pragma expression for
3589             --  correctness, as it is not expanded later.
3590
3591             if SPARK_Mode then
3592                Analyze_PPC_In_Decl_Part
3593                  (N, Defining_Entity (Unit (Parent (Parent (N)))));
3594             end if;
3595
3596             Chain_PPC (Unit (Parent (Parent (N))));
3597             return;
3598          end if;
3599
3600          --  If we fall through, pragma was misplaced
3601
3602          Pragma_Misplaced;
3603       end Check_Precondition_Postcondition;
3604
3605       -----------------------------
3606       -- Check_Static_Constraint --
3607       -----------------------------
3608
3609       --  Note: for convenience in writing this procedure, in addition to
3610       --  the officially (i.e. by spec) allowed argument which is always a
3611       --  constraint, it also allows ranges and discriminant associations.
3612       --  Above is not clear ???
3613
3614       procedure Check_Static_Constraint (Constr : Node_Id) is
3615
3616          procedure Require_Static (E : Node_Id);
3617          --  Require given expression to be static expression
3618
3619          --------------------
3620          -- Require_Static --
3621          --------------------
3622
3623          procedure Require_Static (E : Node_Id) is
3624          begin
3625             if not Is_OK_Static_Expression (E) then
3626                Flag_Non_Static_Expr
3627                  ("non-static constraint not allowed in Unchecked_Union!", E);
3628                raise Pragma_Exit;
3629             end if;
3630          end Require_Static;
3631
3632       --  Start of processing for Check_Static_Constraint
3633
3634       begin
3635          case Nkind (Constr) is
3636             when N_Discriminant_Association =>
3637                Require_Static (Expression (Constr));
3638
3639             when N_Range =>
3640                Require_Static (Low_Bound (Constr));
3641                Require_Static (High_Bound (Constr));
3642
3643             when N_Attribute_Reference =>
3644                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
3645                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
3646
3647             when N_Range_Constraint =>
3648                Check_Static_Constraint (Range_Expression (Constr));
3649
3650             when N_Index_Or_Discriminant_Constraint =>
3651                declare
3652                   IDC : Entity_Id;
3653                begin
3654                   IDC := First (Constraints (Constr));
3655                   while Present (IDC) loop
3656                      Check_Static_Constraint (IDC);
3657                      Next (IDC);
3658                   end loop;
3659                end;
3660
3661             when others =>
3662                null;
3663          end case;
3664       end Check_Static_Constraint;
3665
3666       ---------------------
3667       -- Check_Test_Case --
3668       ---------------------
3669
3670       procedure Check_Test_Case is
3671          P  : Node_Id;
3672          PO : Node_Id;
3673
3674          procedure Chain_CTC (PO : Node_Id);
3675          --  If PO is a [generic] subprogram declaration node, then the
3676          --  test-case applies to this subprogram and the processing for
3677          --  the pragma is completed. Otherwise the pragma is misplaced.
3678
3679          ---------------
3680          -- Chain_CTC --
3681          ---------------
3682
3683          procedure Chain_CTC (PO : Node_Id) is
3684             S   : Entity_Id;
3685
3686          begin
3687             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
3688                Error_Pragma
3689                  ("pragma% cannot be applied to abstract subprogram");
3690
3691             elsif Nkind (PO) = N_Entry_Declaration then
3692                Error_Pragma ("pragma% cannot be applied to entry");
3693
3694             elsif not Nkind_In (PO, N_Subprogram_Declaration,
3695                                     N_Generic_Subprogram_Declaration)
3696             then
3697                Pragma_Misplaced;
3698             end if;
3699
3700             --  Here if we have [generic] subprogram declaration
3701
3702             S := Defining_Unit_Name (Specification (PO));
3703
3704             --  Note: we do not analyze the pragma at this point. Instead we
3705             --  delay this analysis until the end of the declarative part in
3706             --  which the pragma appears. This implements the required delay
3707             --  in this analysis, allowing forward references. The analysis
3708             --  happens at the end of Analyze_Declarations.
3709
3710             --  There should not be another test-case with the same name
3711             --  associated to this subprogram.
3712
3713             declare
3714                Name : constant String_Id := Get_Name_From_CTC_Pragma (N);
3715                CTC  : Node_Id;
3716
3717             begin
3718                CTC := Contract_Test_Cases (Contract (S));
3719                while Present (CTC) loop
3720
3721                   --  Omit pragma Contract_Cases because it does not introduce
3722                   --  a unique case name and it does not follow the syntax of
3723                   --  Test_Case.
3724
3725                   if Pragma_Name (CTC) = Name_Contract_Cases then
3726                      null;
3727
3728                   elsif String_Equal
3729                           (Name, Get_Name_From_CTC_Pragma (CTC))
3730                   then
3731                      Error_Msg_Sloc := Sloc (CTC);
3732                      Error_Pragma ("name for pragma% is already used#");
3733                   end if;
3734
3735                   CTC := Next_Pragma (CTC);
3736                end loop;
3737             end;
3738
3739             --  Chain spec CTC pragma to list for subprogram
3740
3741             Add_Contract_Item (N, S);
3742          end Chain_CTC;
3743
3744       --  Start of processing for Check_Test_Case
3745
3746       begin
3747          --  First check pragma arguments
3748
3749          Check_At_Least_N_Arguments (2);
3750          Check_At_Most_N_Arguments (4);
3751          Check_Arg_Order
3752            ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
3753
3754          Check_Optional_Identifier (Arg1, Name_Name);
3755          Check_Arg_Is_Static_Expression (Arg1, Standard_String);
3756
3757          --  In ASIS mode, for a pragma generated from a source aspect, also
3758          --  analyze the original aspect expression.
3759
3760          if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
3761             Check_Expr_Is_Static_Expression
3762               (Original_Node (Get_Pragma_Arg (Arg1)), Standard_String);
3763          end if;
3764
3765          Check_Optional_Identifier (Arg2, Name_Mode);
3766          Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
3767
3768          if Arg_Count = 4 then
3769             Check_Identifier (Arg3, Name_Requires);
3770             Check_Identifier (Arg4, Name_Ensures);
3771
3772          elsif Arg_Count = 3 then
3773             Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
3774          end if;
3775
3776          --  Check pragma placement
3777
3778          if not Is_List_Member (N) then
3779             Pragma_Misplaced;
3780          end if;
3781
3782          --  Test-case should only appear in package spec unit
3783
3784          if Get_Source_Unit (N) = No_Unit
3785            or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
3786                                  N_Package_Declaration,
3787                                  N_Generic_Package_Declaration)
3788          then
3789             Pragma_Misplaced;
3790          end if;
3791
3792          --  Search prior declarations
3793
3794          P := N;
3795          while Present (Prev (P)) loop
3796             P := Prev (P);
3797
3798             --  If the previous node is a generic subprogram, do not go to to
3799             --  the original node, which is the unanalyzed tree: we need to
3800             --  attach the test-case to the analyzed version at this point.
3801             --  They get propagated to the original tree when analyzing the
3802             --  corresponding body.
3803
3804             if Nkind (P) not in N_Generic_Declaration then
3805                PO := Original_Node (P);
3806             else
3807                PO := P;
3808             end if;
3809
3810             --  Skip past prior pragma
3811
3812             if Nkind (PO) = N_Pragma then
3813                null;
3814
3815             --  Skip stuff not coming from source
3816
3817             elsif not Comes_From_Source (PO) then
3818                null;
3819
3820             --  Only remaining possibility is subprogram declaration. First
3821             --  check that it is declared directly in a package declaration.
3822             --  This may be either the package declaration for the current unit
3823             --  being defined or a local package declaration.
3824
3825             elsif not Present (Parent (Parent (PO)))
3826               or else not Present (Parent (Parent (Parent (PO))))
3827               or else not Nkind_In (Parent (Parent (PO)),
3828                                     N_Package_Declaration,
3829                                     N_Generic_Package_Declaration)
3830             then
3831                Pragma_Misplaced;
3832
3833             else
3834                Chain_CTC (PO);
3835                return;
3836             end if;
3837          end loop;
3838
3839          --  If we fall through, pragma was misplaced
3840
3841          Pragma_Misplaced;
3842       end Check_Test_Case;
3843
3844       --------------------------------------
3845       -- Check_Valid_Configuration_Pragma --
3846       --------------------------------------
3847
3848       --  A configuration pragma must appear in the context clause of a
3849       --  compilation unit, and only other pragmas may precede it. Note that
3850       --  the test also allows use in a configuration pragma file.
3851
3852       procedure Check_Valid_Configuration_Pragma is
3853       begin
3854          if not Is_Configuration_Pragma then
3855             Error_Pragma ("incorrect placement for configuration pragma%");
3856          end if;
3857       end Check_Valid_Configuration_Pragma;
3858
3859       -------------------------------------
3860       -- Check_Valid_Library_Unit_Pragma --
3861       -------------------------------------
3862
3863       procedure Check_Valid_Library_Unit_Pragma is
3864          Plist       : List_Id;
3865          Parent_Node : Node_Id;
3866          Unit_Name   : Entity_Id;
3867          Unit_Kind   : Node_Kind;
3868          Unit_Node   : Node_Id;
3869          Sindex      : Source_File_Index;
3870
3871       begin
3872          if not Is_List_Member (N) then
3873             Pragma_Misplaced;
3874
3875          else
3876             Plist := List_Containing (N);
3877             Parent_Node := Parent (Plist);
3878
3879             if Parent_Node = Empty then
3880                Pragma_Misplaced;
3881
3882             --  Case of pragma appearing after a compilation unit. In this case
3883             --  it must have an argument with the corresponding name and must
3884             --  be part of the following pragmas of its parent.
3885
3886             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
3887                if Plist /= Pragmas_After (Parent_Node) then
3888                   Pragma_Misplaced;
3889
3890                elsif Arg_Count = 0 then
3891                   Error_Pragma
3892                     ("argument required if outside compilation unit");
3893
3894                else
3895                   Check_No_Identifiers;
3896                   Check_Arg_Count (1);
3897                   Unit_Node := Unit (Parent (Parent_Node));
3898                   Unit_Kind := Nkind (Unit_Node);
3899
3900                   Analyze (Get_Pragma_Arg (Arg1));
3901
3902                   if Unit_Kind = N_Generic_Subprogram_Declaration
3903                     or else Unit_Kind = N_Subprogram_Declaration
3904                   then
3905                      Unit_Name := Defining_Entity (Unit_Node);
3906
3907                   elsif Unit_Kind in N_Generic_Instantiation then
3908                      Unit_Name := Defining_Entity (Unit_Node);
3909
3910                   else
3911                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
3912                   end if;
3913
3914                   if Chars (Unit_Name) /=
3915                      Chars (Entity (Get_Pragma_Arg (Arg1)))
3916                   then
3917                      Error_Pragma_Arg
3918                        ("pragma% argument is not current unit name", Arg1);
3919                   end if;
3920
3921                   if Ekind (Unit_Name) = E_Package
3922                     and then Present (Renamed_Entity (Unit_Name))
3923                   then
3924                      Error_Pragma ("pragma% not allowed for renamed package");
3925                   end if;
3926                end if;
3927
3928             --  Pragma appears other than after a compilation unit
3929
3930             else
3931                --  Here we check for the generic instantiation case and also
3932                --  for the case of processing a generic formal package. We
3933                --  detect these cases by noting that the Sloc on the node
3934                --  does not belong to the current compilation unit.
3935
3936                Sindex := Source_Index (Current_Sem_Unit);
3937
3938                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
3939                   Rewrite (N, Make_Null_Statement (Loc));
3940                   return;
3941
3942                --  If before first declaration, the pragma applies to the
3943                --  enclosing unit, and the name if present must be this name.
3944
3945                elsif Is_Before_First_Decl (N, Plist) then
3946                   Unit_Node := Unit_Declaration_Node (Current_Scope);
3947                   Unit_Kind := Nkind (Unit_Node);
3948
3949                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
3950                      Pragma_Misplaced;
3951
3952                   elsif Unit_Kind = N_Subprogram_Body
3953                     and then not Acts_As_Spec (Unit_Node)
3954                   then
3955                      Pragma_Misplaced;
3956
3957                   elsif Nkind (Parent_Node) = N_Package_Body then
3958                      Pragma_Misplaced;
3959
3960                   elsif Nkind (Parent_Node) = N_Package_Specification
3961                     and then Plist = Private_Declarations (Parent_Node)
3962                   then
3963                      Pragma_Misplaced;
3964
3965                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
3966                            or else Nkind (Parent_Node) =
3967                                              N_Generic_Subprogram_Declaration)
3968                     and then Plist = Generic_Formal_Declarations (Parent_Node)
3969                   then
3970                      Pragma_Misplaced;
3971
3972                   elsif Arg_Count > 0 then
3973                      Analyze (Get_Pragma_Arg (Arg1));
3974
3975                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
3976                         Error_Pragma_Arg
3977                           ("name in pragma% must be enclosing unit", Arg1);
3978                      end if;
3979
3980                   --  It is legal to have no argument in this context
3981
3982                   else
3983                      return;
3984                   end if;
3985
3986                --  Error if not before first declaration. This is because a
3987                --  library unit pragma argument must be the name of a library
3988                --  unit (RM 10.1.5(7)), but the only names permitted in this
3989                --  context are (RM 10.1.5(6)) names of subprogram declarations,
3990                --  generic subprogram declarations or generic instantiations.
3991
3992                else
3993                   Error_Pragma
3994                     ("pragma% misplaced, must be before first declaration");
3995                end if;
3996             end if;
3997          end if;
3998       end Check_Valid_Library_Unit_Pragma;
3999
4000       -------------------
4001       -- Check_Variant --
4002       -------------------
4003
4004       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
4005          Clist : constant Node_Id := Component_List (Variant);
4006          Comp  : Node_Id;
4007
4008       begin
4009          Comp := First (Component_Items (Clist));
4010          while Present (Comp) loop
4011             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
4012             Next (Comp);
4013          end loop;
4014       end Check_Variant;
4015
4016       ------------------
4017       -- Error_Pragma --
4018       ------------------
4019
4020       procedure Error_Pragma (Msg : String) is
4021          MsgF : String := Msg;
4022       begin
4023          Error_Msg_Name_1 := Pname;
4024          Fix_Error (MsgF);
4025          Error_Msg_N (MsgF, N);
4026          raise Pragma_Exit;
4027       end Error_Pragma;
4028
4029       ----------------------
4030       -- Error_Pragma_Arg --
4031       ----------------------
4032
4033       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
4034          MsgF : String := Msg;
4035       begin
4036          Error_Msg_Name_1 := Pname;
4037          Fix_Error (MsgF);
4038          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
4039          raise Pragma_Exit;
4040       end Error_Pragma_Arg;
4041
4042       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
4043          MsgF : String := Msg1;
4044       begin
4045          Error_Msg_Name_1 := Pname;
4046          Fix_Error (MsgF);
4047          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
4048          Error_Pragma_Arg (Msg2, Arg);
4049       end Error_Pragma_Arg;
4050
4051       ----------------------------
4052       -- Error_Pragma_Arg_Ident --
4053       ----------------------------
4054
4055       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
4056          MsgF : String := Msg;
4057       begin
4058          Error_Msg_Name_1 := Pname;
4059          Fix_Error (MsgF);
4060          Error_Msg_N (MsgF, Arg);
4061          raise Pragma_Exit;
4062       end Error_Pragma_Arg_Ident;
4063
4064       ----------------------
4065       -- Error_Pragma_Ref --
4066       ----------------------
4067
4068       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
4069          MsgF : String := Msg;
4070       begin
4071          Error_Msg_Name_1 := Pname;
4072          Fix_Error (MsgF);
4073          Error_Msg_Sloc   := Sloc (Ref);
4074          Error_Msg_NE (MsgF, N, Ref);
4075          raise Pragma_Exit;
4076       end Error_Pragma_Ref;
4077
4078       ------------------------
4079       -- Find_Lib_Unit_Name --
4080       ------------------------
4081
4082       function Find_Lib_Unit_Name return Entity_Id is
4083       begin
4084          --  Return inner compilation unit entity, for case of nested
4085          --  categorization pragmas. This happens in generic unit.
4086
4087          if Nkind (Parent (N)) = N_Package_Specification
4088            and then Defining_Entity (Parent (N)) /= Current_Scope
4089          then
4090             return Defining_Entity (Parent (N));
4091          else
4092             return Current_Scope;
4093          end if;
4094       end Find_Lib_Unit_Name;
4095
4096       ----------------------------
4097       -- Find_Program_Unit_Name --
4098       ----------------------------
4099
4100       procedure Find_Program_Unit_Name (Id : Node_Id) is
4101          Unit_Name : Entity_Id;
4102          Unit_Kind : Node_Kind;
4103          P         : constant Node_Id := Parent (N);
4104
4105       begin
4106          if Nkind (P) = N_Compilation_Unit then
4107             Unit_Kind := Nkind (Unit (P));
4108
4109             if Unit_Kind = N_Subprogram_Declaration
4110               or else Unit_Kind = N_Package_Declaration
4111               or else Unit_Kind in N_Generic_Declaration
4112             then
4113                Unit_Name := Defining_Entity (Unit (P));
4114
4115                if Chars (Id) = Chars (Unit_Name) then
4116                   Set_Entity (Id, Unit_Name);
4117                   Set_Etype (Id, Etype (Unit_Name));
4118                else
4119                   Set_Etype (Id, Any_Type);
4120                   Error_Pragma
4121                     ("cannot find program unit referenced by pragma%");
4122                end if;
4123
4124             else
4125                Set_Etype (Id, Any_Type);
4126                Error_Pragma ("pragma% inapplicable to this unit");
4127             end if;
4128
4129          else
4130             Analyze (Id);
4131          end if;
4132       end Find_Program_Unit_Name;
4133
4134       -----------------------------------------
4135       -- Find_Unique_Parameterless_Procedure --
4136       -----------------------------------------
4137
4138       function Find_Unique_Parameterless_Procedure
4139         (Name : Entity_Id;
4140          Arg  : Node_Id) return Entity_Id
4141       is
4142          Proc : Entity_Id := Empty;
4143
4144       begin
4145          --  The body of this procedure needs some comments ???
4146
4147          if not Is_Entity_Name (Name) then
4148             Error_Pragma_Arg
4149               ("argument of pragma% must be entity name", Arg);
4150
4151          elsif not Is_Overloaded (Name) then
4152             Proc := Entity (Name);
4153
4154             if Ekind (Proc) /= E_Procedure
4155               or else Present (First_Formal (Proc))
4156             then
4157                Error_Pragma_Arg
4158                  ("argument of pragma% must be parameterless procedure", Arg);
4159             end if;
4160
4161          else
4162             declare
4163                Found : Boolean := False;
4164                It    : Interp;
4165                Index : Interp_Index;
4166
4167             begin
4168                Get_First_Interp (Name, Index, It);
4169                while Present (It.Nam) loop
4170                   Proc := It.Nam;
4171
4172                   if Ekind (Proc) = E_Procedure
4173                     and then No (First_Formal (Proc))
4174                   then
4175                      if not Found then
4176                         Found := True;
4177                         Set_Entity (Name, Proc);
4178                         Set_Is_Overloaded (Name, False);
4179                      else
4180                         Error_Pragma_Arg
4181                           ("ambiguous handler name for pragma% ", Arg);
4182                      end if;
4183                   end if;
4184
4185                   Get_Next_Interp (Index, It);
4186                end loop;
4187
4188                if not Found then
4189                   Error_Pragma_Arg
4190                     ("argument of pragma% must be parameterless procedure",
4191                      Arg);
4192                else
4193                   Proc := Entity (Name);
4194                end if;
4195             end;
4196          end if;
4197
4198          return Proc;
4199       end Find_Unique_Parameterless_Procedure;
4200
4201       ---------------
4202       -- Fix_Error --
4203       ---------------
4204
4205       procedure Fix_Error (Msg : in out String) is
4206       begin
4207          --  If we have a rewriting of another pragma, go to that pragma
4208
4209          if Is_Rewrite_Substitution (N)
4210            and then Nkind (Original_Node (N)) = N_Pragma
4211          then
4212             Error_Msg_Name_1 := Pragma_Name (Original_Node (N));
4213          end if;
4214
4215          --  Case where pragma comes from an aspect specification
4216
4217          if From_Aspect_Specification (N) then
4218
4219             --  Change appearence of "pragma" in message to "aspect"
4220
4221             for J in Msg'First .. Msg'Last - 5 loop
4222                if Msg (J .. J + 5) = "pragma" then
4223                   Msg (J .. J + 5) := "aspect";
4224                end if;
4225             end loop;
4226
4227             --  Get name from corresponding aspect
4228
4229             Error_Msg_Name_1 := Original_Name (N);
4230          end if;
4231       end Fix_Error;
4232
4233       -------------------------
4234       -- Gather_Associations --
4235       -------------------------
4236
4237       procedure Gather_Associations
4238         (Names : Name_List;
4239          Args  : out Args_List)
4240       is
4241          Arg : Node_Id;
4242
4243       begin
4244          --  Initialize all parameters to Empty
4245
4246          for J in Args'Range loop
4247             Args (J) := Empty;
4248          end loop;
4249
4250          --  That's all we have to do if there are no argument associations
4251
4252          if No (Pragma_Argument_Associations (N)) then
4253             return;
4254          end if;
4255
4256          --  Otherwise first deal with any positional parameters present
4257
4258          Arg := First (Pragma_Argument_Associations (N));
4259          for Index in Args'Range loop
4260             exit when No (Arg) or else Chars (Arg) /= No_Name;
4261             Args (Index) := Get_Pragma_Arg (Arg);
4262             Next (Arg);
4263          end loop;
4264
4265          --  Positional parameters all processed, if any left, then we
4266          --  have too many positional parameters.
4267
4268          if Present (Arg) and then Chars (Arg) = No_Name then
4269             Error_Pragma_Arg
4270               ("too many positional associations for pragma%", Arg);
4271          end if;
4272
4273          --  Process named parameters if any are present
4274
4275          while Present (Arg) loop
4276             if Chars (Arg) = No_Name then
4277                Error_Pragma_Arg
4278                  ("positional association cannot follow named association",
4279                   Arg);
4280
4281             else
4282                for Index in Names'Range loop
4283                   if Names (Index) = Chars (Arg) then
4284                      if Present (Args (Index)) then
4285                         Error_Pragma_Arg
4286                           ("duplicate argument association for pragma%", Arg);
4287                      else
4288                         Args (Index) := Get_Pragma_Arg (Arg);
4289                         exit;
4290                      end if;
4291                   end if;
4292
4293                   if Index = Names'Last then
4294                      Error_Msg_Name_1 := Pname;
4295                      Error_Msg_N ("pragma% does not allow & argument", Arg);
4296
4297                      --  Check for possible misspelling
4298
4299                      for Index1 in Names'Range loop
4300                         if Is_Bad_Spelling_Of
4301                              (Chars (Arg), Names (Index1))
4302                         then
4303                            Error_Msg_Name_1 := Names (Index1);
4304                            Error_Msg_N -- CODEFIX
4305                              ("\possible misspelling of%", Arg);
4306                            exit;
4307                         end if;
4308                      end loop;
4309
4310                      raise Pragma_Exit;
4311                   end if;
4312                end loop;
4313             end if;
4314
4315             Next (Arg);
4316          end loop;
4317       end Gather_Associations;
4318
4319       -----------------
4320       -- GNAT_Pragma --
4321       -----------------
4322
4323       procedure GNAT_Pragma is
4324       begin
4325          --  We need to check the No_Implementation_Pragmas restriction for
4326          --  the case of a pragma from source. Note that the case of aspects
4327          --  generating corresponding pragmas marks these pragmas as not being
4328          --  from source, so this test also catches that case.
4329
4330          if Comes_From_Source (N) then
4331             Check_Restriction (No_Implementation_Pragmas, N);
4332          end if;
4333       end GNAT_Pragma;
4334
4335       --------------------------
4336       -- Is_Before_First_Decl --
4337       --------------------------
4338
4339       function Is_Before_First_Decl
4340         (Pragma_Node : Node_Id;
4341          Decls       : List_Id) return Boolean
4342       is
4343          Item : Node_Id := First (Decls);
4344
4345       begin
4346          --  Only other pragmas can come before this pragma
4347
4348          loop
4349             if No (Item) or else Nkind (Item) /= N_Pragma then
4350                return False;
4351
4352             elsif Item = Pragma_Node then
4353                return True;
4354             end if;
4355
4356             Next (Item);
4357          end loop;
4358       end Is_Before_First_Decl;
4359
4360       -----------------------------
4361       -- Is_Configuration_Pragma --
4362       -----------------------------
4363
4364       --  A configuration pragma must appear in the context clause of a
4365       --  compilation unit, and only other pragmas may precede it. Note that
4366       --  the test below also permits use in a configuration pragma file.
4367
4368       function Is_Configuration_Pragma return Boolean is
4369          Lis : constant List_Id := List_Containing (N);
4370          Par : constant Node_Id := Parent (N);
4371          Prg : Node_Id;
4372
4373       begin
4374          --  If no parent, then we are in the configuration pragma file,
4375          --  so the placement is definitely appropriate.
4376
4377          if No (Par) then
4378             return True;
4379
4380          --  Otherwise we must be in the context clause of a compilation unit
4381          --  and the only thing allowed before us in the context list is more
4382          --  configuration pragmas.
4383
4384          elsif Nkind (Par) = N_Compilation_Unit
4385            and then Context_Items (Par) = Lis
4386          then
4387             Prg := First (Lis);
4388
4389             loop
4390                if Prg = N then
4391                   return True;
4392                elsif Nkind (Prg) /= N_Pragma then
4393                   return False;
4394                end if;
4395
4396                Next (Prg);
4397             end loop;
4398
4399          else
4400             return False;
4401          end if;
4402       end Is_Configuration_Pragma;
4403
4404       --------------------------
4405       -- Is_In_Context_Clause --
4406       --------------------------
4407
4408       function Is_In_Context_Clause return Boolean is
4409          Plist       : List_Id;
4410          Parent_Node : Node_Id;
4411
4412       begin
4413          if not Is_List_Member (N) then
4414             return False;
4415
4416          else
4417             Plist := List_Containing (N);
4418             Parent_Node := Parent (Plist);
4419
4420             if Parent_Node = Empty
4421               or else Nkind (Parent_Node) /= N_Compilation_Unit
4422               or else Context_Items (Parent_Node) /= Plist
4423             then
4424                return False;
4425             end if;
4426          end if;
4427
4428          return True;
4429       end Is_In_Context_Clause;
4430
4431       ---------------------------------
4432       -- Is_Static_String_Expression --
4433       ---------------------------------
4434
4435       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
4436          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
4437
4438       begin
4439          Analyze_And_Resolve (Argx);
4440          return Is_OK_Static_Expression (Argx)
4441            and then Nkind (Argx) = N_String_Literal;
4442       end Is_Static_String_Expression;
4443
4444       ----------------------
4445       -- Pragma_Misplaced --
4446       ----------------------
4447
4448       procedure Pragma_Misplaced is
4449       begin
4450          Error_Pragma ("incorrect placement of pragma%");
4451       end Pragma_Misplaced;
4452
4453       ------------------------------------
4454       -- Process_Atomic_Shared_Volatile --
4455       ------------------------------------
4456
4457       procedure Process_Atomic_Shared_Volatile is
4458          E_Id : Node_Id;
4459          E    : Entity_Id;
4460          D    : Node_Id;
4461          K    : Node_Kind;
4462          Utyp : Entity_Id;
4463
4464          procedure Set_Atomic (E : Entity_Id);
4465          --  Set given type as atomic, and if no explicit alignment was given,
4466          --  set alignment to unknown, since back end knows what the alignment
4467          --  requirements are for atomic arrays. Note: this step is necessary
4468          --  for derived types.
4469
4470          ----------------
4471          -- Set_Atomic --
4472          ----------------
4473
4474          procedure Set_Atomic (E : Entity_Id) is
4475          begin
4476             Set_Is_Atomic (E);
4477
4478             if not Has_Alignment_Clause (E) then
4479                Set_Alignment (E, Uint_0);
4480             end if;
4481          end Set_Atomic;
4482
4483       --  Start of processing for Process_Atomic_Shared_Volatile
4484
4485       begin
4486          Check_Ada_83_Warning;
4487          Check_No_Identifiers;
4488          Check_Arg_Count (1);
4489          Check_Arg_Is_Local_Name (Arg1);
4490          E_Id := Get_Pragma_Arg (Arg1);
4491
4492          if Etype (E_Id) = Any_Type then
4493             return;
4494          end if;
4495
4496          E := Entity (E_Id);
4497          D := Declaration_Node (E);
4498          K := Nkind (D);
4499
4500          --  Check duplicate before we chain ourselves!
4501
4502          Check_Duplicate_Pragma (E);
4503
4504          --  Now check appropriateness of the entity
4505
4506          if Is_Type (E) then
4507             if Rep_Item_Too_Early (E, N)
4508                  or else
4509                Rep_Item_Too_Late (E, N)
4510             then
4511                return;
4512             else
4513                Check_First_Subtype (Arg1);
4514             end if;
4515
4516             if Prag_Id /= Pragma_Volatile then
4517                Set_Atomic (E);
4518                Set_Atomic (Underlying_Type (E));
4519                Set_Atomic (Base_Type (E));
4520             end if;
4521
4522             --  Attribute belongs on the base type. If the view of the type is
4523             --  currently private, it also belongs on the underlying type.
4524
4525             Set_Is_Volatile (Base_Type (E));
4526             Set_Is_Volatile (Underlying_Type (E));
4527
4528             Set_Treat_As_Volatile (E);
4529             Set_Treat_As_Volatile (Underlying_Type (E));
4530
4531          elsif K = N_Object_Declaration
4532            or else (K = N_Component_Declaration
4533                      and then Original_Record_Component (E) = E)
4534          then
4535             if Rep_Item_Too_Late (E, N) then
4536                return;
4537             end if;
4538
4539             if Prag_Id /= Pragma_Volatile then
4540                Set_Is_Atomic (E);
4541
4542                --  If the object declaration has an explicit initialization, a
4543                --  temporary may have to be created to hold the expression, to
4544                --  ensure that access to the object remain atomic.
4545
4546                if Nkind (Parent (E)) = N_Object_Declaration
4547                  and then Present (Expression (Parent (E)))
4548                then
4549                   Set_Has_Delayed_Freeze (E);
4550                end if;
4551
4552                --  An interesting improvement here. If an object of composite
4553                --  type X is declared atomic, and the type X isn't, that's a
4554                --  pity, since it may not have appropriate alignment etc. We
4555                --  can rescue this in the special case where the object and
4556                --  type are in the same unit by just setting the type as
4557                --  atomic, so that the back end will process it as atomic.
4558
4559                --  Note: we used to do this for elementary types as well,
4560                --  but that turns out to be a bad idea and can have unwanted
4561                --  effects, most notably if the type is elementary, the object
4562                --  a simple component within a record, and both are in a spec:
4563                --  every object of this type in the entire program will be
4564                --  treated as atomic, thus incurring a potentially costly
4565                --  synchronization operation for every access.
4566
4567                --  Of course it would be best if the back end could just adjust
4568                --  the alignment etc for the specific object, but that's not
4569                --  something we are capable of doing at this point.
4570
4571                Utyp := Underlying_Type (Etype (E));
4572
4573                if Present (Utyp)
4574                  and then Is_Composite_Type (Utyp)
4575                  and then Sloc (E) > No_Location
4576                  and then Sloc (Utyp) > No_Location
4577                  and then
4578                    Get_Source_File_Index (Sloc (E)) =
4579                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
4580                then
4581                   Set_Is_Atomic (Underlying_Type (Etype (E)));
4582                end if;
4583             end if;
4584
4585             Set_Is_Volatile (E);
4586             Set_Treat_As_Volatile (E);
4587
4588          else
4589             Error_Pragma_Arg
4590               ("inappropriate entity for pragma%", Arg1);
4591          end if;
4592       end Process_Atomic_Shared_Volatile;
4593
4594       -------------------------------------------
4595       -- Process_Compile_Time_Warning_Or_Error --
4596       -------------------------------------------
4597
4598       procedure Process_Compile_Time_Warning_Or_Error is
4599          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
4600
4601       begin
4602          Check_Arg_Count (2);
4603          Check_No_Identifiers;
4604          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
4605          Analyze_And_Resolve (Arg1x, Standard_Boolean);
4606
4607          if Compile_Time_Known_Value (Arg1x) then
4608             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
4609                declare
4610                   Str   : constant String_Id :=
4611                             Strval (Get_Pragma_Arg (Arg2));
4612                   Len   : constant Int := String_Length (Str);
4613                   Cont  : Boolean;
4614                   Ptr   : Nat;
4615                   CC    : Char_Code;
4616                   C     : Character;
4617                   Cent  : constant Entity_Id :=
4618                             Cunit_Entity (Current_Sem_Unit);
4619
4620                   Force : constant Boolean :=
4621                             Prag_Id = Pragma_Compile_Time_Warning
4622                               and then
4623                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
4624                               and then (Ekind (Cent) /= E_Package
4625                                           or else not In_Private_Part (Cent));
4626                   --  Set True if this is the warning case, and we are in the
4627                   --  visible part of a package spec, or in a subprogram spec,
4628                   --  in which case we want to force the client to see the
4629                   --  warning, even though it is not in the main unit.
4630
4631                begin
4632                   --  Loop through segments of message separated by line feeds.
4633                   --  We output these segments as separate messages with
4634                   --  continuation marks for all but the first.
4635
4636                   Cont := False;
4637                   Ptr := 1;
4638                   loop
4639                      Error_Msg_Strlen := 0;
4640
4641                      --  Loop to copy characters from argument to error message
4642                      --  string buffer.
4643
4644                      loop
4645                         exit when Ptr > Len;
4646                         CC := Get_String_Char (Str, Ptr);
4647                         Ptr := Ptr + 1;
4648
4649                         --  Ignore wide chars ??? else store character
4650
4651                         if In_Character_Range (CC) then
4652                            C := Get_Character (CC);
4653                            exit when C = ASCII.LF;
4654                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
4655                            Error_Msg_String (Error_Msg_Strlen) := C;
4656                         end if;
4657                      end loop;
4658
4659                      --  Here with one line ready to go
4660
4661                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
4662
4663                      --  If this is a warning in a spec, then we want clients
4664                      --  to see the warning, so mark the message with the
4665                      --  special sequence !! to force the warning. In the case
4666                      --  of a package spec, we do not force this if we are in
4667                      --  the private part of the spec.
4668
4669                      if Force then
4670                         if Cont = False then
4671                            Error_Msg_N ("<~!!", Arg1);
4672                            Cont := True;
4673                         else
4674                            Error_Msg_N ("\<~!!", Arg1);
4675                         end if;
4676
4677                      --  Error, rather than warning, or in a body, so we do not
4678                      --  need to force visibility for client (error will be
4679                      --  output in any case, and this is the situation in which
4680                      --  we do not want a client to get a warning, since the
4681                      --  warning is in the body or the spec private part).
4682
4683                      else
4684                         if Cont = False then
4685                            Error_Msg_N ("<~", Arg1);
4686                            Cont := True;
4687                         else
4688                            Error_Msg_N ("\<~", Arg1);
4689                         end if;
4690                      end if;
4691
4692                      exit when Ptr > Len;
4693                   end loop;
4694                end;
4695             end if;
4696          end if;
4697       end Process_Compile_Time_Warning_Or_Error;
4698
4699       ------------------------
4700       -- Process_Convention --
4701       ------------------------
4702
4703       procedure Process_Convention
4704         (C   : out Convention_Id;
4705          Ent : out Entity_Id)
4706       is
4707          Id        : Node_Id;
4708          E         : Entity_Id;
4709          E1        : Entity_Id;
4710          Cname     : Name_Id;
4711          Comp_Unit : Unit_Number_Type;
4712
4713          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
4714          --  Called if we have more than one Export/Import/Convention pragma.
4715          --  This is generally illegal, but we have a special case of allowing
4716          --  Import and Interface to coexist if they specify the convention in
4717          --  a consistent manner. We are allowed to do this, since Interface is
4718          --  an implementation defined pragma, and we choose to do it since we
4719          --  know Rational allows this combination. S is the entity id of the
4720          --  subprogram in question. This procedure also sets the special flag
4721          --  Import_Interface_Present in both pragmas in the case where we do
4722          --  have matching Import and Interface pragmas.
4723
4724          procedure Set_Convention_From_Pragma (E : Entity_Id);
4725          --  Set convention in entity E, and also flag that the entity has a
4726          --  convention pragma. If entity is for a private or incomplete type,
4727          --  also set convention and flag on underlying type. This procedure
4728          --  also deals with the special case of C_Pass_By_Copy convention.
4729
4730          -------------------------------
4731          -- Diagnose_Multiple_Pragmas --
4732          -------------------------------
4733
4734          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
4735             Pdec : constant Node_Id := Declaration_Node (S);
4736             Decl : Node_Id;
4737             Err  : Boolean;
4738
4739             function Same_Convention (Decl : Node_Id) return Boolean;
4740             --  Decl is a pragma node. This function returns True if this
4741             --  pragma has a first argument that is an identifier with a
4742             --  Chars field corresponding to the Convention_Id C.
4743
4744             function Same_Name (Decl : Node_Id) return Boolean;
4745             --  Decl is a pragma node. This function returns True if this
4746             --  pragma has a second argument that is an identifier with a
4747             --  Chars field that matches the Chars of the current subprogram.
4748
4749             ---------------------
4750             -- Same_Convention --
4751             ---------------------
4752
4753             function Same_Convention (Decl : Node_Id) return Boolean is
4754                Arg1 : constant Node_Id :=
4755                         First (Pragma_Argument_Associations (Decl));
4756
4757             begin
4758                if Present (Arg1) then
4759                   declare
4760                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
4761                   begin
4762                      if Nkind (Arg) = N_Identifier
4763                        and then Is_Convention_Name (Chars (Arg))
4764                        and then Get_Convention_Id (Chars (Arg)) = C
4765                      then
4766                         return True;
4767                      end if;
4768                   end;
4769                end if;
4770
4771                return False;
4772             end Same_Convention;
4773
4774             ---------------
4775             -- Same_Name --
4776             ---------------
4777
4778             function Same_Name (Decl : Node_Id) return Boolean is
4779                Arg1 : constant Node_Id :=
4780                         First (Pragma_Argument_Associations (Decl));
4781                Arg2 : Node_Id;
4782
4783             begin
4784                if No (Arg1) then
4785                   return False;
4786                end if;
4787
4788                Arg2 := Next (Arg1);
4789
4790                if No (Arg2) then
4791                   return False;
4792                end if;
4793
4794                declare
4795                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
4796                begin
4797                   if Nkind (Arg) = N_Identifier
4798                     and then Chars (Arg) = Chars (S)
4799                   then
4800                      return True;
4801                   end if;
4802                end;
4803
4804                return False;
4805             end Same_Name;
4806
4807          --  Start of processing for Diagnose_Multiple_Pragmas
4808
4809          begin
4810             Err := True;
4811
4812             --  Definitely give message if we have Convention/Export here
4813
4814             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
4815                null;
4816
4817                --  If we have an Import or Export, scan back from pragma to
4818                --  find any previous pragma applying to the same procedure.
4819                --  The scan will be terminated by the start of the list, or
4820                --  hitting the subprogram declaration. This won't allow one
4821                --  pragma to appear in the public part and one in the private
4822                --  part, but that seems very unlikely in practice.
4823
4824             else
4825                Decl := Prev (N);
4826                while Present (Decl) and then Decl /= Pdec loop
4827
4828                   --  Look for pragma with same name as us
4829
4830                   if Nkind (Decl) = N_Pragma
4831                     and then Same_Name (Decl)
4832                   then
4833                      --  Give error if same as our pragma or Export/Convention
4834
4835                      if Nam_In (Pragma_Name (Decl), Name_Export,
4836                                                     Name_Convention,
4837                                                     Pragma_Name (N))
4838                      then
4839                         exit;
4840
4841                      --  Case of Import/Interface or the other way round
4842
4843                      elsif Nam_In (Pragma_Name (Decl), Name_Interface,
4844                                                        Name_Import)
4845                      then
4846                         --  Here we know that we have Import and Interface. It
4847                         --  doesn't matter which way round they are. See if
4848                         --  they specify the same convention. If so, all OK,
4849                         --  and set special flags to stop other messages
4850
4851                         if Same_Convention (Decl) then
4852                            Set_Import_Interface_Present (N);
4853                            Set_Import_Interface_Present (Decl);
4854                            Err := False;
4855
4856                         --  If different conventions, special message
4857
4858                         else
4859                            Error_Msg_Sloc := Sloc (Decl);
4860                            Error_Pragma_Arg
4861                              ("convention differs from that given#", Arg1);
4862                            return;
4863                         end if;
4864                      end if;
4865                   end if;
4866
4867                   Next (Decl);
4868                end loop;
4869             end if;
4870
4871             --  Give message if needed if we fall through those tests
4872             --  except on Relaxed_RM_Semantics where we let go: either this
4873             --  is a case accepted/ignored by other Ada compilers (e.g.
4874             --  a mix of Convention and Import), or another error will be
4875             --  generated later (e.g. using both Import and Export).
4876
4877             if Err and not Relaxed_RM_Semantics then
4878                Error_Pragma_Arg
4879                  ("at most one Convention/Export/Import pragma is allowed",
4880                   Arg2);
4881             end if;
4882          end Diagnose_Multiple_Pragmas;
4883
4884          --------------------------------
4885          -- Set_Convention_From_Pragma --
4886          --------------------------------
4887
4888          procedure Set_Convention_From_Pragma (E : Entity_Id) is
4889          begin
4890             --  Ada 2005 (AI-430): Check invalid attempt to change convention
4891             --  for an overridden dispatching operation. Technically this is
4892             --  an amendment and should only be done in Ada 2005 mode. However,
4893             --  this is clearly a mistake, since the problem that is addressed
4894             --  by this AI is that there is a clear gap in the RM!
4895
4896             if Is_Dispatching_Operation (E)
4897               and then Present (Overridden_Operation (E))
4898               and then C /= Convention (Overridden_Operation (E))
4899             then
4900                --  An attempt to override a subprogram with a ghost subprogram
4901                --  appears as a mismatch in conventions.
4902
4903                if C = Convention_Ghost then
4904                   Error_Msg_N ("ghost subprogram & cannot be overriding", E);
4905                else
4906                   Error_Pragma_Arg
4907                     ("cannot change convention for overridden dispatching "
4908                      & "operation", Arg1);
4909                end if;
4910             end if;
4911
4912             --  Special checks for Convention_Stdcall
4913
4914             if C = Convention_Stdcall then
4915
4916                --  A dispatching call is not allowed. A dispatching subprogram
4917                --  cannot be used to interface to the Win32 API, so in fact
4918                --  this check does not impose any effective restriction.
4919
4920                if Is_Dispatching_Operation (E) then
4921                   Error_Msg_Sloc := Sloc (E);
4922
4923                   --  Note: make this unconditional so that if there is more
4924                   --  than one call to which the pragma applies, we get a
4925                   --  message for each call. Also don't use Error_Pragma,
4926                   --  so that we get multiple messages!
4927
4928                   Error_Msg_N
4929                     ("dispatching subprogram# cannot use Stdcall convention!",
4930                      Arg1);
4931
4932                --  Subprogram is allowed, but not a generic subprogram
4933
4934                elsif not Is_Subprogram (E)
4935                  and then not Is_Generic_Subprogram (E)
4936
4937                  --  A variable is OK
4938
4939                  and then Ekind (E) /= E_Variable
4940
4941                  --  An access to subprogram is also allowed
4942
4943                  and then not
4944                    (Is_Access_Type (E)
4945                      and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
4946
4947                  --  Allow internal call to set convention of subprogram type
4948
4949                  and then not (Ekind (E) = E_Subprogram_Type)
4950                then
4951                   Error_Pragma_Arg
4952                     ("second argument of pragma% must be subprogram (type)",
4953                      Arg2);
4954                end if;
4955             end if;
4956
4957             --  Set the convention
4958
4959             Set_Convention (E, C);
4960             Set_Has_Convention_Pragma (E);
4961
4962             if Is_Incomplete_Or_Private_Type (E)
4963               and then Present (Underlying_Type (E))
4964             then
4965                Set_Convention            (Underlying_Type (E), C);
4966                Set_Has_Convention_Pragma (Underlying_Type (E), True);
4967             end if;
4968
4969             --  A class-wide type should inherit the convention of the specific
4970             --  root type (although this isn't specified clearly by the RM).
4971
4972             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
4973                Set_Convention (Class_Wide_Type (E), C);
4974             end if;
4975
4976             --  If the entity is a record type, then check for special case of
4977             --  C_Pass_By_Copy, which is treated the same as C except that the
4978             --  special record flag is set. This convention is only permitted
4979             --  on record types (see AI95-00131).
4980
4981             if Cname = Name_C_Pass_By_Copy then
4982                if Is_Record_Type (E) then
4983                   Set_C_Pass_By_Copy (Base_Type (E));
4984                elsif Is_Incomplete_Or_Private_Type (E)
4985                  and then Is_Record_Type (Underlying_Type (E))
4986                then
4987                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
4988                else
4989                   Error_Pragma_Arg
4990                     ("C_Pass_By_Copy convention allowed only for record type",
4991                      Arg2);
4992                end if;
4993             end if;
4994
4995             --  If the entity is a derived boolean type, check for the special
4996             --  case of convention C, C++, or Fortran, where we consider any
4997             --  nonzero value to represent true.
4998
4999             if Is_Discrete_Type (E)
5000               and then Root_Type (Etype (E)) = Standard_Boolean
5001               and then
5002                 (C = Convention_C
5003                    or else
5004                  C = Convention_CPP
5005                    or else
5006                  C = Convention_Fortran)
5007             then
5008                Set_Nonzero_Is_True (Base_Type (E));
5009             end if;
5010          end Set_Convention_From_Pragma;
5011
5012       --  Start of processing for Process_Convention
5013
5014       begin
5015          Check_At_Least_N_Arguments (2);
5016          Check_Optional_Identifier (Arg1, Name_Convention);
5017          Check_Arg_Is_Identifier (Arg1);
5018          Cname := Chars (Get_Pragma_Arg (Arg1));
5019
5020          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
5021          --  tested again below to set the critical flag).
5022
5023          if Cname = Name_C_Pass_By_Copy then
5024             C := Convention_C;
5025
5026          --  Otherwise we must have something in the standard convention list
5027
5028          elsif Is_Convention_Name (Cname) then
5029             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
5030
5031          --  In DEC VMS, it seems that there is an undocumented feature that
5032          --  any unrecognized convention is treated as the default, which for
5033          --  us is convention C. It does not seem so terrible to do this
5034          --  unconditionally, silently in the VMS case, and with a warning
5035          --  in the non-VMS case.
5036
5037          else
5038             if Warn_On_Export_Import and not OpenVMS_On_Target then
5039                Error_Msg_N
5040                  ("??unrecognized convention name, C assumed",
5041                   Get_Pragma_Arg (Arg1));
5042             end if;
5043
5044             C := Convention_C;
5045          end if;
5046
5047          Check_Optional_Identifier (Arg2, Name_Entity);
5048          Check_Arg_Is_Local_Name (Arg2);
5049
5050          Id := Get_Pragma_Arg (Arg2);
5051          Analyze (Id);
5052
5053          if not Is_Entity_Name (Id) then
5054             Error_Pragma_Arg ("entity name required", Arg2);
5055          end if;
5056
5057          E := Entity (Id);
5058
5059          --  Set entity to return
5060
5061          Ent := E;
5062
5063          --  Ada_Pass_By_Copy special checking
5064
5065          if C = Convention_Ada_Pass_By_Copy then
5066             if not Is_First_Subtype (E) then
5067                Error_Pragma_Arg
5068                  ("convention `Ada_Pass_By_Copy` only allowed for types",
5069                   Arg2);
5070             end if;
5071
5072             if Is_By_Reference_Type (E) then
5073                Error_Pragma_Arg
5074                  ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
5075                   & "type", Arg1);
5076             end if;
5077          end if;
5078
5079          --  Ada_Pass_By_Reference special checking
5080
5081          if C = Convention_Ada_Pass_By_Reference then
5082             if not Is_First_Subtype (E) then
5083                Error_Pragma_Arg
5084                  ("convention `Ada_Pass_By_Reference` only allowed for types",
5085                   Arg2);
5086             end if;
5087
5088             if Is_By_Copy_Type (E) then
5089                Error_Pragma_Arg
5090                  ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
5091                   & "type", Arg1);
5092             end if;
5093          end if;
5094
5095          --  Ghost special checking
5096
5097          if Is_Ghost_Subprogram (E)
5098            and then Present (Overridden_Operation (E))
5099          then
5100             Error_Msg_N ("ghost subprogram & cannot be overriding", E);
5101          end if;
5102
5103          --  Go to renamed subprogram if present, since convention applies to
5104          --  the actual renamed entity, not to the renaming entity. If the
5105          --  subprogram is inherited, go to parent subprogram.
5106
5107          if Is_Subprogram (E)
5108            and then Present (Alias (E))
5109          then
5110             if Nkind (Parent (Declaration_Node (E))) =
5111                                        N_Subprogram_Renaming_Declaration
5112             then
5113                if Scope (E) /= Scope (Alias (E)) then
5114                   Error_Pragma_Ref
5115                     ("cannot apply pragma% to non-local entity&#", E);
5116                end if;
5117
5118                E := Alias (E);
5119
5120             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
5121                                         N_Private_Extension_Declaration)
5122               and then Scope (E) = Scope (Alias (E))
5123             then
5124                E := Alias (E);
5125
5126                --  Return the parent subprogram the entity was inherited from
5127
5128                Ent := E;
5129             end if;
5130          end if;
5131
5132          --  Check that we are not applying this to a specless body
5133          --  Relax this check if Relaxed_RM_Semantics to accomodate other Ada
5134          --  compilers.
5135
5136          if Is_Subprogram (E)
5137            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
5138            and then not Relaxed_RM_Semantics
5139          then
5140             Error_Pragma
5141               ("pragma% requires separate spec and must come before body");
5142          end if;
5143
5144          --  Check that we are not applying this to a named constant
5145
5146          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
5147             Error_Msg_Name_1 := Pname;
5148             Error_Msg_N
5149               ("cannot apply pragma% to named constant!",
5150                Get_Pragma_Arg (Arg2));
5151             Error_Pragma_Arg
5152               ("\supply appropriate type for&!", Arg2);
5153          end if;
5154
5155          if Ekind (E) = E_Enumeration_Literal then
5156             Error_Pragma ("enumeration literal not allowed for pragma%");
5157          end if;
5158
5159          --  Check for rep item appearing too early or too late
5160
5161          if Etype (E) = Any_Type
5162            or else Rep_Item_Too_Early (E, N)
5163          then
5164             raise Pragma_Exit;
5165
5166          elsif Present (Underlying_Type (E)) then
5167             E := Underlying_Type (E);
5168          end if;
5169
5170          if Rep_Item_Too_Late (E, N) then
5171             raise Pragma_Exit;
5172          end if;
5173
5174          if Has_Convention_Pragma (E) then
5175             Diagnose_Multiple_Pragmas (E);
5176
5177          elsif Convention (E) = Convention_Protected
5178            or else Ekind (Scope (E)) = E_Protected_Type
5179          then
5180             Error_Pragma_Arg
5181               ("a protected operation cannot be given a different convention",
5182                 Arg2);
5183          end if;
5184
5185          --  For Intrinsic, a subprogram is required
5186
5187          if C = Convention_Intrinsic
5188            and then not Is_Subprogram (E)
5189            and then not Is_Generic_Subprogram (E)
5190          then
5191             Error_Pragma_Arg
5192               ("second argument of pragma% must be a subprogram", Arg2);
5193          end if;
5194
5195          --  Deal with non-subprogram cases
5196
5197          if not Is_Subprogram (E)
5198            and then not Is_Generic_Subprogram (E)
5199          then
5200             Set_Convention_From_Pragma (E);
5201
5202             if Is_Type (E) then
5203                Check_First_Subtype (Arg2);
5204                Set_Convention_From_Pragma (Base_Type (E));
5205
5206                --  For access subprograms, we must set the convention on the
5207                --  internally generated directly designated type as well.
5208
5209                if Ekind (E) = E_Access_Subprogram_Type then
5210                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
5211                end if;
5212             end if;
5213
5214          --  For the subprogram case, set proper convention for all homonyms
5215          --  in same scope and the same declarative part, i.e. the same
5216          --  compilation unit.
5217
5218          else
5219             Comp_Unit := Get_Source_Unit (E);
5220             Set_Convention_From_Pragma (E);
5221
5222             --  Treat a pragma Import as an implicit body, and pragma import
5223             --  as implicit reference (for navigation in GPS).
5224
5225             if Prag_Id = Pragma_Import then
5226                Generate_Reference (E, Id, 'b');
5227
5228             --  For exported entities we restrict the generation of references
5229             --  to entities exported to foreign languages since entities
5230             --  exported to Ada do not provide further information to GPS and
5231             --  add undesired references to the output of the gnatxref tool.
5232
5233             elsif Prag_Id = Pragma_Export
5234               and then Convention (E) /= Convention_Ada
5235             then
5236                Generate_Reference (E, Id, 'i');
5237             end if;
5238
5239             --  If the pragma comes from from an aspect, it only applies to the
5240             --  given entity, not its homonyms.
5241
5242             if From_Aspect_Specification (N) then
5243                return;
5244             end if;
5245
5246             --  Otherwise Loop through the homonyms of the pragma argument's
5247             --  entity, an apply convention to those in the current scope.
5248
5249             E1 := Ent;
5250
5251             loop
5252                E1 := Homonym (E1);
5253                exit when No (E1) or else Scope (E1) /= Current_Scope;
5254
5255                --  Ignore entry for which convention is already set
5256
5257                if Has_Convention_Pragma (E1) then
5258                   goto Continue;
5259                end if;
5260
5261                --  Do not set the pragma on inherited operations or on formal
5262                --  subprograms.
5263
5264                if Comes_From_Source (E1)
5265                  and then Comp_Unit = Get_Source_Unit (E1)
5266                  and then not Is_Formal_Subprogram (E1)
5267                  and then Nkind (Original_Node (Parent (E1))) /=
5268                                                     N_Full_Type_Declaration
5269                then
5270                   if Present (Alias (E1))
5271                     and then Scope (E1) /= Scope (Alias (E1))
5272                   then
5273                      Error_Pragma_Ref
5274                        ("cannot apply pragma% to non-local entity& declared#",
5275                         E1);
5276                   end if;
5277
5278                   Set_Convention_From_Pragma (E1);
5279
5280                   if Prag_Id = Pragma_Import then
5281                      Generate_Reference (E1, Id, 'b');
5282                   end if;
5283                end if;
5284
5285             <<Continue>>
5286                null;
5287             end loop;
5288          end if;
5289       end Process_Convention;
5290
5291       ----------------------------------------
5292       -- Process_Disable_Enable_Atomic_Sync --
5293       ----------------------------------------
5294
5295       procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is
5296       begin
5297          Check_No_Identifiers;
5298          Check_At_Most_N_Arguments (1);
5299
5300          --  Modeled internally as
5301          --    pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
5302
5303          Rewrite (N,
5304            Make_Pragma (Loc,
5305              Pragma_Identifier            =>
5306                Make_Identifier (Loc, Nam),
5307              Pragma_Argument_Associations => New_List (
5308                Make_Pragma_Argument_Association (Loc,
5309                  Expression =>
5310                    Make_Identifier (Loc, Name_Atomic_Synchronization)))));
5311
5312          if Present (Arg1) then
5313             Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1));
5314          end if;
5315
5316          Analyze (N);
5317       end Process_Disable_Enable_Atomic_Sync;
5318
5319       -----------------------------------------------------
5320       -- Process_Extended_Import_Export_Exception_Pragma --
5321       -----------------------------------------------------
5322
5323       procedure Process_Extended_Import_Export_Exception_Pragma
5324         (Arg_Internal : Node_Id;
5325          Arg_External : Node_Id;
5326          Arg_Form     : Node_Id;
5327          Arg_Code     : Node_Id)
5328       is
5329          Def_Id   : Entity_Id;
5330          Code_Val : Uint;
5331
5332       begin
5333          if not OpenVMS_On_Target then
5334             Error_Pragma
5335               ("??pragma% ignored (applies only to Open'V'M'S)");
5336          end if;
5337
5338          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
5339          Def_Id := Entity (Arg_Internal);
5340
5341          if Ekind (Def_Id) /= E_Exception then
5342             Error_Pragma_Arg
5343               ("pragma% must refer to declared exception", Arg_Internal);
5344          end if;
5345
5346          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
5347
5348          if Present (Arg_Form) then
5349             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
5350          end if;
5351
5352          if Present (Arg_Form)
5353            and then Chars (Arg_Form) = Name_Ada
5354          then
5355             null;
5356          else
5357             Set_Is_VMS_Exception (Def_Id);
5358             Set_Exception_Code (Def_Id, No_Uint);
5359          end if;
5360
5361          if Present (Arg_Code) then
5362             if not Is_VMS_Exception (Def_Id) then
5363                Error_Pragma_Arg
5364                  ("Code option for pragma% not allowed for Ada case",
5365                   Arg_Code);
5366             end if;
5367
5368             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
5369             Code_Val := Expr_Value (Arg_Code);
5370
5371             if not UI_Is_In_Int_Range (Code_Val) then
5372                Error_Pragma_Arg
5373                  ("Code option for pragma% must be in 32-bit range",
5374                   Arg_Code);
5375
5376             else
5377                Set_Exception_Code (Def_Id, Code_Val);
5378             end if;
5379          end if;
5380       end Process_Extended_Import_Export_Exception_Pragma;
5381
5382       -------------------------------------------------
5383       -- Process_Extended_Import_Export_Internal_Arg --
5384       -------------------------------------------------
5385
5386       procedure Process_Extended_Import_Export_Internal_Arg
5387         (Arg_Internal : Node_Id := Empty)
5388       is
5389       begin
5390          if No (Arg_Internal) then
5391             Error_Pragma ("Internal parameter required for pragma%");
5392          end if;
5393
5394          if Nkind (Arg_Internal) = N_Identifier then
5395             null;
5396
5397          elsif Nkind (Arg_Internal) = N_Operator_Symbol
5398            and then (Prag_Id = Pragma_Import_Function
5399                        or else
5400                      Prag_Id = Pragma_Export_Function)
5401          then
5402             null;
5403
5404          else
5405             Error_Pragma_Arg
5406               ("wrong form for Internal parameter for pragma%", Arg_Internal);
5407          end if;
5408
5409          Check_Arg_Is_Local_Name (Arg_Internal);
5410       end Process_Extended_Import_Export_Internal_Arg;
5411
5412       --------------------------------------------------
5413       -- Process_Extended_Import_Export_Object_Pragma --
5414       --------------------------------------------------
5415
5416       procedure Process_Extended_Import_Export_Object_Pragma
5417         (Arg_Internal : Node_Id;
5418          Arg_External : Node_Id;
5419          Arg_Size     : Node_Id)
5420       is
5421          Def_Id : Entity_Id;
5422
5423       begin
5424          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
5425          Def_Id := Entity (Arg_Internal);
5426
5427          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
5428             Error_Pragma_Arg
5429               ("pragma% must designate an object", Arg_Internal);
5430          end if;
5431
5432          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
5433               or else
5434             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
5435          then
5436             Error_Pragma_Arg
5437               ("previous Common/Psect_Object applies, pragma % not permitted",
5438                Arg_Internal);
5439          end if;
5440
5441          if Rep_Item_Too_Late (Def_Id, N) then
5442             raise Pragma_Exit;
5443          end if;
5444
5445          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
5446
5447          if Present (Arg_Size) then
5448             Check_Arg_Is_External_Name (Arg_Size);
5449          end if;
5450
5451          --  Export_Object case
5452
5453          if Prag_Id = Pragma_Export_Object then
5454             if not Is_Library_Level_Entity (Def_Id) then
5455                Error_Pragma_Arg
5456                  ("argument for pragma% must be library level entity",
5457                   Arg_Internal);
5458             end if;
5459
5460             if Ekind (Current_Scope) = E_Generic_Package then
5461                Error_Pragma ("pragma& cannot appear in a generic unit");
5462             end if;
5463
5464             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
5465                Error_Pragma_Arg
5466                  ("exported object must have compile time known size",
5467                   Arg_Internal);
5468             end if;
5469
5470             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
5471                Error_Msg_N ("??duplicate Export_Object pragma", N);
5472             else
5473                Set_Exported (Def_Id, Arg_Internal);
5474             end if;
5475
5476          --  Import_Object case
5477
5478          else
5479             if Is_Concurrent_Type (Etype (Def_Id)) then
5480                Error_Pragma_Arg
5481                  ("cannot use pragma% for task/protected object",
5482                   Arg_Internal);
5483             end if;
5484
5485             if Ekind (Def_Id) = E_Constant then
5486                Error_Pragma_Arg
5487                  ("cannot import a constant", Arg_Internal);
5488             end if;
5489
5490             if Warn_On_Export_Import
5491               and then Has_Discriminants (Etype (Def_Id))
5492             then
5493                Error_Msg_N
5494                  ("imported value must be initialized??", Arg_Internal);
5495             end if;
5496
5497             if Warn_On_Export_Import
5498               and then Is_Access_Type (Etype (Def_Id))
5499             then
5500                Error_Pragma_Arg
5501                  ("cannot import object of an access type??", Arg_Internal);
5502             end if;
5503
5504             if Warn_On_Export_Import
5505               and then Is_Imported (Def_Id)
5506             then
5507                Error_Msg_N ("??duplicate Import_Object pragma", N);
5508
5509             --  Check for explicit initialization present. Note that an
5510             --  initialization generated by the code generator, e.g. for an
5511             --  access type, does not count here.
5512
5513             elsif Present (Expression (Parent (Def_Id)))
5514                and then
5515                  Comes_From_Source
5516                    (Original_Node (Expression (Parent (Def_Id))))
5517             then
5518                Error_Msg_Sloc := Sloc (Def_Id);
5519                Error_Pragma_Arg
5520                  ("imported entities cannot be initialized (RM B.1(24))",
5521                   "\no initialization allowed for & declared#", Arg1);
5522             else
5523                Set_Imported (Def_Id);
5524                Note_Possible_Modification (Arg_Internal, Sure => False);
5525             end if;
5526          end if;
5527       end Process_Extended_Import_Export_Object_Pragma;
5528
5529       ------------------------------------------------------
5530       -- Process_Extended_Import_Export_Subprogram_Pragma --
5531       ------------------------------------------------------
5532
5533       procedure Process_Extended_Import_Export_Subprogram_Pragma
5534         (Arg_Internal                 : Node_Id;
5535          Arg_External                 : Node_Id;
5536          Arg_Parameter_Types          : Node_Id;
5537          Arg_Result_Type              : Node_Id := Empty;
5538          Arg_Mechanism                : Node_Id;
5539          Arg_Result_Mechanism         : Node_Id := Empty;
5540          Arg_First_Optional_Parameter : Node_Id := Empty)
5541       is
5542          Ent       : Entity_Id;
5543          Def_Id    : Entity_Id;
5544          Hom_Id    : Entity_Id;
5545          Formal    : Entity_Id;
5546          Ambiguous : Boolean;
5547          Match     : Boolean;
5548          Dval      : Node_Id;
5549
5550          function Same_Base_Type
5551           (Ptype  : Node_Id;
5552            Formal : Entity_Id) return Boolean;
5553          --  Determines if Ptype references the type of Formal. Note that only
5554          --  the base types need to match according to the spec. Ptype here is
5555          --  the argument from the pragma, which is either a type name, or an
5556          --  access attribute.
5557
5558          --------------------
5559          -- Same_Base_Type --
5560          --------------------
5561
5562          function Same_Base_Type
5563            (Ptype  : Node_Id;
5564             Formal : Entity_Id) return Boolean
5565          is
5566             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
5567             Pref : Node_Id;
5568
5569          begin
5570             --  Case where pragma argument is typ'Access
5571
5572             if Nkind (Ptype) = N_Attribute_Reference
5573               and then Attribute_Name (Ptype) = Name_Access
5574             then
5575                Pref := Prefix (Ptype);
5576                Find_Type (Pref);
5577
5578                if not Is_Entity_Name (Pref)
5579                  or else Entity (Pref) = Any_Type
5580                then
5581                   raise Pragma_Exit;
5582                end if;
5583
5584                --  We have a match if the corresponding argument is of an
5585                --  anonymous access type, and its designated type matches the
5586                --  type of the prefix of the access attribute
5587
5588                return Ekind (Ftyp) = E_Anonymous_Access_Type
5589                  and then Base_Type (Entity (Pref)) =
5590                             Base_Type (Etype (Designated_Type (Ftyp)));
5591
5592             --  Case where pragma argument is a type name
5593
5594             else
5595                Find_Type (Ptype);
5596
5597                if not Is_Entity_Name (Ptype)
5598                  or else Entity (Ptype) = Any_Type
5599                then
5600                   raise Pragma_Exit;
5601                end if;
5602
5603                --  We have a match if the corresponding argument is of the type
5604                --  given in the pragma (comparing base types)
5605
5606                return Base_Type (Entity (Ptype)) = Ftyp;
5607             end if;
5608          end Same_Base_Type;
5609
5610       --  Start of processing for
5611       --  Process_Extended_Import_Export_Subprogram_Pragma
5612
5613       begin
5614          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
5615          Ent := Empty;
5616          Ambiguous := False;
5617
5618          --  Loop through homonyms (overloadings) of the entity
5619
5620          Hom_Id := Entity (Arg_Internal);
5621          while Present (Hom_Id) loop
5622             Def_Id := Get_Base_Subprogram (Hom_Id);
5623
5624             --  We need a subprogram in the current scope
5625
5626             if not Is_Subprogram (Def_Id)
5627               or else Scope (Def_Id) /= Current_Scope
5628             then
5629                null;
5630
5631             else
5632                Match := True;
5633
5634                --  Pragma cannot apply to subprogram body
5635
5636                if Is_Subprogram (Def_Id)
5637                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
5638                                                              N_Subprogram_Body
5639                then
5640                   Error_Pragma
5641                     ("pragma% requires separate spec"
5642                       & " and must come before body");
5643                end if;
5644
5645                --  Test result type if given, note that the result type
5646                --  parameter can only be present for the function cases.
5647
5648                if Present (Arg_Result_Type)
5649                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
5650                then
5651                   Match := False;
5652
5653                elsif Etype (Def_Id) /= Standard_Void_Type
5654                  and then
5655                    Nam_In (Pname, Name_Export_Procedure, Name_Import_Procedure)
5656                then
5657                   Match := False;
5658
5659                --  Test parameter types if given. Note that this parameter
5660                --  has not been analyzed (and must not be, since it is
5661                --  semantic nonsense), so we get it as the parser left it.
5662
5663                elsif Present (Arg_Parameter_Types) then
5664                   Check_Matching_Types : declare
5665                      Formal : Entity_Id;
5666                      Ptype  : Node_Id;
5667
5668                   begin
5669                      Formal := First_Formal (Def_Id);
5670
5671                      if Nkind (Arg_Parameter_Types) = N_Null then
5672                         if Present (Formal) then
5673                            Match := False;
5674                         end if;
5675
5676                      --  A list of one type, e.g. (List) is parsed as
5677                      --  a parenthesized expression.
5678
5679                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
5680                        and then Paren_Count (Arg_Parameter_Types) = 1
5681                      then
5682                         if No (Formal)
5683                           or else Present (Next_Formal (Formal))
5684                         then
5685                            Match := False;
5686                         else
5687                            Match :=
5688                              Same_Base_Type (Arg_Parameter_Types, Formal);
5689                         end if;
5690
5691                      --  A list of more than one type is parsed as a aggregate
5692
5693                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
5694                        and then Paren_Count (Arg_Parameter_Types) = 0
5695                      then
5696                         Ptype := First (Expressions (Arg_Parameter_Types));
5697                         while Present (Ptype) or else Present (Formal) loop
5698                            if No (Ptype)
5699                              or else No (Formal)
5700                              or else not Same_Base_Type (Ptype, Formal)
5701                            then
5702                               Match := False;
5703                               exit;
5704                            else
5705                               Next_Formal (Formal);
5706                               Next (Ptype);
5707                            end if;
5708                         end loop;
5709
5710                      --  Anything else is of the wrong form
5711
5712                      else
5713                         Error_Pragma_Arg
5714                           ("wrong form for Parameter_Types parameter",
5715                            Arg_Parameter_Types);
5716                      end if;
5717                   end Check_Matching_Types;
5718                end if;
5719
5720                --  Match is now False if the entry we found did not match
5721                --  either a supplied Parameter_Types or Result_Types argument
5722
5723                if Match then
5724                   if No (Ent) then
5725                      Ent := Def_Id;
5726
5727                   --  Ambiguous case, the flag Ambiguous shows if we already
5728                   --  detected this and output the initial messages.
5729
5730                   else
5731                      if not Ambiguous then
5732                         Ambiguous := True;
5733                         Error_Msg_Name_1 := Pname;
5734                         Error_Msg_N
5735                           ("pragma% does not uniquely identify subprogram!",
5736                            N);
5737                         Error_Msg_Sloc := Sloc (Ent);
5738                         Error_Msg_N ("matching subprogram #!", N);
5739                         Ent := Empty;
5740                      end if;
5741
5742                      Error_Msg_Sloc := Sloc (Def_Id);
5743                      Error_Msg_N ("matching subprogram #!", N);
5744                   end if;
5745                end if;
5746             end if;
5747
5748             Hom_Id := Homonym (Hom_Id);
5749          end loop;
5750
5751          --  See if we found an entry
5752
5753          if No (Ent) then
5754             if not Ambiguous then
5755                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
5756                   Error_Pragma
5757                     ("pragma% cannot be given for generic subprogram");
5758                else
5759                   Error_Pragma
5760                     ("pragma% does not identify local subprogram");
5761                end if;
5762             end if;
5763
5764             return;
5765          end if;
5766
5767          --  Import pragmas must be for imported entities
5768
5769          if Prag_Id = Pragma_Import_Function
5770               or else
5771             Prag_Id = Pragma_Import_Procedure
5772               or else
5773             Prag_Id = Pragma_Import_Valued_Procedure
5774          then
5775             if not Is_Imported (Ent) then
5776                Error_Pragma
5777                  ("pragma Import or Interface must precede pragma%");
5778             end if;
5779
5780          --  Here we have the Export case which can set the entity as exported
5781
5782          --  But does not do so if the specified external name is null, since
5783          --  that is taken as a signal in DEC Ada 83 (with which we want to be
5784          --  compatible) to request no external name.
5785
5786          elsif Nkind (Arg_External) = N_String_Literal
5787            and then String_Length (Strval (Arg_External)) = 0
5788          then
5789             null;
5790
5791          --  In all other cases, set entity as exported
5792
5793          else
5794             Set_Exported (Ent, Arg_Internal);
5795          end if;
5796
5797          --  Special processing for Valued_Procedure cases
5798
5799          if Prag_Id = Pragma_Import_Valued_Procedure
5800            or else
5801             Prag_Id = Pragma_Export_Valued_Procedure
5802          then
5803             Formal := First_Formal (Ent);
5804
5805             if No (Formal) then
5806                Error_Pragma ("at least one parameter required for pragma%");
5807
5808             elsif Ekind (Formal) /= E_Out_Parameter then
5809                Error_Pragma ("first parameter must have mode out for pragma%");
5810
5811             else
5812                Set_Is_Valued_Procedure (Ent);
5813             end if;
5814          end if;
5815
5816          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
5817
5818          --  Process Result_Mechanism argument if present. We have already
5819          --  checked that this is only allowed for the function case.
5820
5821          if Present (Arg_Result_Mechanism) then
5822             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
5823          end if;
5824
5825          --  Process Mechanism parameter if present. Note that this parameter
5826          --  is not analyzed, and must not be analyzed since it is semantic
5827          --  nonsense, so we get it in exactly as the parser left it.
5828
5829          if Present (Arg_Mechanism) then
5830             declare
5831                Formal : Entity_Id;
5832                Massoc : Node_Id;
5833                Mname  : Node_Id;
5834                Choice : Node_Id;
5835
5836             begin
5837                --  A single mechanism association without a formal parameter
5838                --  name is parsed as a parenthesized expression. All other
5839                --  cases are parsed as aggregates, so we rewrite the single
5840                --  parameter case as an aggregate for consistency.
5841
5842                if Nkind (Arg_Mechanism) /= N_Aggregate
5843                  and then Paren_Count (Arg_Mechanism) = 1
5844                then
5845                   Rewrite (Arg_Mechanism,
5846                     Make_Aggregate (Sloc (Arg_Mechanism),
5847                       Expressions => New_List (
5848                         Relocate_Node (Arg_Mechanism))));
5849                end if;
5850
5851                --  Case of only mechanism name given, applies to all formals
5852
5853                if Nkind (Arg_Mechanism) /= N_Aggregate then
5854                   Formal := First_Formal (Ent);
5855                   while Present (Formal) loop
5856                      Set_Mechanism_Value (Formal, Arg_Mechanism);
5857                      Next_Formal (Formal);
5858                   end loop;
5859
5860                --  Case of list of mechanism associations given
5861
5862                else
5863                   if Null_Record_Present (Arg_Mechanism) then
5864                      Error_Pragma_Arg
5865                        ("inappropriate form for Mechanism parameter",
5866                         Arg_Mechanism);
5867                   end if;
5868
5869                   --  Deal with positional ones first
5870
5871                   Formal := First_Formal (Ent);
5872
5873                   if Present (Expressions (Arg_Mechanism)) then
5874                      Mname := First (Expressions (Arg_Mechanism));
5875                      while Present (Mname) loop
5876                         if No (Formal) then
5877                            Error_Pragma_Arg
5878                              ("too many mechanism associations", Mname);
5879                         end if;
5880
5881                         Set_Mechanism_Value (Formal, Mname);
5882                         Next_Formal (Formal);
5883                         Next (Mname);
5884                      end loop;
5885                   end if;
5886
5887                   --  Deal with named entries
5888
5889                   if Present (Component_Associations (Arg_Mechanism)) then
5890                      Massoc := First (Component_Associations (Arg_Mechanism));
5891                      while Present (Massoc) loop
5892                         Choice := First (Choices (Massoc));
5893
5894                         if Nkind (Choice) /= N_Identifier
5895                           or else Present (Next (Choice))
5896                         then
5897                            Error_Pragma_Arg
5898                              ("incorrect form for mechanism association",
5899                               Massoc);
5900                         end if;
5901
5902                         Formal := First_Formal (Ent);
5903                         loop
5904                            if No (Formal) then
5905                               Error_Pragma_Arg
5906                                 ("parameter name & not present", Choice);
5907                            end if;
5908
5909                            if Chars (Choice) = Chars (Formal) then
5910                               Set_Mechanism_Value
5911                                 (Formal, Expression (Massoc));
5912
5913                               --  Set entity on identifier (needed by ASIS)
5914
5915                               Set_Entity (Choice, Formal);
5916
5917                               exit;
5918                            end if;
5919
5920                            Next_Formal (Formal);
5921                         end loop;
5922
5923                         Next (Massoc);
5924                      end loop;
5925                   end if;
5926                end if;
5927             end;
5928          end if;
5929
5930          --  Process First_Optional_Parameter argument if present. We have
5931          --  already checked that this is only allowed for the Import case.
5932
5933          if Present (Arg_First_Optional_Parameter) then
5934             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
5935                Error_Pragma_Arg
5936                  ("first optional parameter must be formal parameter name",
5937                   Arg_First_Optional_Parameter);
5938             end if;
5939
5940             Formal := First_Formal (Ent);
5941             loop
5942                if No (Formal) then
5943                   Error_Pragma_Arg
5944                     ("specified formal parameter& not found",
5945                      Arg_First_Optional_Parameter);
5946                end if;
5947
5948                exit when Chars (Formal) =
5949                          Chars (Arg_First_Optional_Parameter);
5950
5951                Next_Formal (Formal);
5952             end loop;
5953
5954             Set_First_Optional_Parameter (Ent, Formal);
5955
5956             --  Check specified and all remaining formals have right form
5957
5958             while Present (Formal) loop
5959                if Ekind (Formal) /= E_In_Parameter then
5960                   Error_Msg_NE
5961                     ("optional formal& is not of mode in!",
5962                      Arg_First_Optional_Parameter, Formal);
5963
5964                else
5965                   Dval := Default_Value (Formal);
5966
5967                   if No (Dval) then
5968                      Error_Msg_NE
5969                        ("optional formal& does not have default value!",
5970                         Arg_First_Optional_Parameter, Formal);
5971
5972                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
5973                      null;
5974
5975                   else
5976                      Error_Msg_FE
5977                        ("default value for optional formal& is non-static!",
5978                         Arg_First_Optional_Parameter, Formal);
5979                   end if;
5980                end if;
5981
5982                Set_Is_Optional_Parameter (Formal);
5983                Next_Formal (Formal);
5984             end loop;
5985          end if;
5986       end Process_Extended_Import_Export_Subprogram_Pragma;
5987
5988       --------------------------
5989       -- Process_Generic_List --
5990       --------------------------
5991
5992       procedure Process_Generic_List is
5993          Arg : Node_Id;
5994          Exp : Node_Id;
5995
5996       begin
5997          Check_No_Identifiers;
5998          Check_At_Least_N_Arguments (1);
5999
6000          --  Check all arguments are names of generic units or instances
6001
6002          Arg := Arg1;
6003          while Present (Arg) loop
6004             Exp := Get_Pragma_Arg (Arg);
6005             Analyze (Exp);
6006
6007             if not Is_Entity_Name (Exp)
6008               or else
6009                 (not Is_Generic_Instance (Entity (Exp))
6010                   and then
6011                  not Is_Generic_Unit (Entity (Exp)))
6012             then
6013                Error_Pragma_Arg
6014                  ("pragma% argument must be name of generic unit/instance",
6015                   Arg);
6016             end if;
6017
6018             Next (Arg);
6019          end loop;
6020       end Process_Generic_List;
6021
6022       ------------------------------------
6023       -- Process_Import_Predefined_Type --
6024       ------------------------------------
6025
6026       procedure Process_Import_Predefined_Type is
6027          Loc  : constant Source_Ptr := Sloc (N);
6028          Elmt : Elmt_Id;
6029          Ftyp : Node_Id := Empty;
6030          Decl : Node_Id;
6031          Def  : Node_Id;
6032          Nam  : Name_Id;
6033
6034       begin
6035          String_To_Name_Buffer (Strval (Expression (Arg3)));
6036          Nam := Name_Find;
6037
6038          Elmt := First_Elmt (Predefined_Float_Types);
6039          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
6040             Next_Elmt (Elmt);
6041          end loop;
6042
6043          Ftyp := Node (Elmt);
6044
6045          if Present (Ftyp) then
6046
6047             --  Don't build a derived type declaration, because predefined C
6048             --  types have no declaration anywhere, so cannot really be named.
6049             --  Instead build a full type declaration, starting with an
6050             --  appropriate type definition is built
6051
6052             if Is_Floating_Point_Type (Ftyp) then
6053                Def := Make_Floating_Point_Definition (Loc,
6054                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
6055                  Make_Real_Range_Specification (Loc,
6056                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
6057                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
6058
6059             --  Should never have a predefined type we cannot handle
6060
6061             else
6062                raise Program_Error;
6063             end if;
6064
6065             --  Build and insert a Full_Type_Declaration, which will be
6066             --  analyzed as soon as this list entry has been analyzed.
6067
6068             Decl := Make_Full_Type_Declaration (Loc,
6069               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
6070               Type_Definition => Def);
6071
6072             Insert_After (N, Decl);
6073             Mark_Rewrite_Insertion (Decl);
6074
6075          else
6076             Error_Pragma_Arg ("no matching type found for pragma%",
6077             Arg2);
6078          end if;
6079       end Process_Import_Predefined_Type;
6080
6081       ---------------------------------
6082       -- Process_Import_Or_Interface --
6083       ---------------------------------
6084
6085       procedure Process_Import_Or_Interface is
6086          C      : Convention_Id;
6087          Def_Id : Entity_Id;
6088          Hom_Id : Entity_Id;
6089
6090       begin
6091          Process_Convention (C, Def_Id);
6092          Kill_Size_Check_Code (Def_Id);
6093          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
6094
6095          if Ekind_In (Def_Id, E_Variable, E_Constant) then
6096
6097             --  We do not permit Import to apply to a renaming declaration
6098
6099             if Present (Renamed_Object (Def_Id)) then
6100                Error_Pragma_Arg
6101                  ("pragma% not allowed for object renaming", Arg2);
6102
6103             --  User initialization is not allowed for imported object, but
6104             --  the object declaration may contain a default initialization,
6105             --  that will be discarded. Note that an explicit initialization
6106             --  only counts if it comes from source, otherwise it is simply
6107             --  the code generator making an implicit initialization explicit.
6108
6109             elsif Present (Expression (Parent (Def_Id)))
6110               and then Comes_From_Source (Expression (Parent (Def_Id)))
6111             then
6112                Error_Msg_Sloc := Sloc (Def_Id);
6113                Error_Pragma_Arg
6114                  ("no initialization allowed for declaration of& #",
6115                   "\imported entities cannot be initialized (RM B.1(24))",
6116                   Arg2);
6117
6118             else
6119                Set_Imported (Def_Id);
6120                Process_Interface_Name (Def_Id, Arg3, Arg4);
6121
6122                --  Note that we do not set Is_Public here. That's because we
6123                --  only want to set it if there is no address clause, and we
6124                --  don't know that yet, so we delay that processing till
6125                --  freeze time.
6126
6127                --  pragma Import completes deferred constants
6128
6129                if Ekind (Def_Id) = E_Constant then
6130                   Set_Has_Completion (Def_Id);
6131                end if;
6132
6133                --  It is not possible to import a constant of an unconstrained
6134                --  array type (e.g. string) because there is no simple way to
6135                --  write a meaningful subtype for it.
6136
6137                if Is_Array_Type (Etype (Def_Id))
6138                  and then not Is_Constrained (Etype (Def_Id))
6139                then
6140                   Error_Msg_NE
6141                     ("imported constant& must have a constrained subtype",
6142                       N, Def_Id);
6143                end if;
6144             end if;
6145
6146          elsif Is_Subprogram (Def_Id)
6147            or else Is_Generic_Subprogram (Def_Id)
6148          then
6149             --  If the name is overloaded, pragma applies to all of the denoted
6150             --  entities in the same declarative part, unless the pragma comes
6151             --  from an aspect specification.
6152
6153             Hom_Id := Def_Id;
6154             while Present (Hom_Id) loop
6155
6156                Def_Id := Get_Base_Subprogram (Hom_Id);
6157
6158                --  Ignore inherited subprograms because the pragma will apply
6159                --  to the parent operation, which is the one called.
6160
6161                if Is_Overloadable (Def_Id)
6162                  and then Present (Alias (Def_Id))
6163                then
6164                   null;
6165
6166                --  If it is not a subprogram, it must be in an outer scope and
6167                --  pragma does not apply.
6168
6169                elsif not Is_Subprogram (Def_Id)
6170                  and then not Is_Generic_Subprogram (Def_Id)
6171                then
6172                   null;
6173
6174                --  The pragma does not apply to primitives of interfaces
6175
6176                elsif Is_Dispatching_Operation (Def_Id)
6177                  and then Present (Find_Dispatching_Type (Def_Id))
6178                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
6179                then
6180                   null;
6181
6182                --  Verify that the homonym is in the same declarative part (not
6183                --  just the same scope). If the pragma comes from an aspect
6184                --  specification we know that it is part of the declaration.
6185
6186                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
6187                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
6188                  and then not From_Aspect_Specification (N)
6189                then
6190                   exit;
6191
6192                else
6193                   Set_Imported (Def_Id);
6194
6195                   --  Reject an Import applied to an abstract subprogram
6196
6197                   if Is_Subprogram (Def_Id)
6198                     and then Is_Abstract_Subprogram (Def_Id)
6199                   then
6200                      Error_Msg_Sloc := Sloc (Def_Id);
6201                      Error_Msg_NE
6202                        ("cannot import abstract subprogram& declared#",
6203                         Arg2, Def_Id);
6204                   end if;
6205
6206                   --  Special processing for Convention_Intrinsic
6207
6208                   if C = Convention_Intrinsic then
6209
6210                      --  Link_Name argument not allowed for intrinsic
6211
6212                      Check_No_Link_Name;
6213
6214                      Set_Is_Intrinsic_Subprogram (Def_Id);
6215
6216                      --  If no external name is present, then check that this
6217                      --  is a valid intrinsic subprogram. If an external name
6218                      --  is present, then this is handled by the back end.
6219
6220                      if No (Arg3) then
6221                         Check_Intrinsic_Subprogram
6222                           (Def_Id, Get_Pragma_Arg (Arg2));
6223                      end if;
6224                   end if;
6225
6226                   --  All interfaced procedures need an external symbol created
6227                   --  for them since they are always referenced from another
6228                   --  object file.
6229
6230                   Set_Is_Public (Def_Id);
6231
6232                   --  Verify that the subprogram does not have a completion
6233                   --  through a renaming declaration. For other completions the
6234                   --  pragma appears as a too late representation.
6235
6236                   declare
6237                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
6238
6239                   begin
6240                      if Present (Decl)
6241                        and then Nkind (Decl) = N_Subprogram_Declaration
6242                        and then Present (Corresponding_Body (Decl))
6243                        and then Nkind (Unit_Declaration_Node
6244                                         (Corresponding_Body (Decl))) =
6245                                              N_Subprogram_Renaming_Declaration
6246                      then
6247                         Error_Msg_Sloc := Sloc (Def_Id);
6248                         Error_Msg_NE
6249                           ("cannot import&, renaming already provided for "
6250                            & "declaration #", N, Def_Id);
6251                      end if;
6252                   end;
6253
6254                   Set_Has_Completion (Def_Id);
6255                   Process_Interface_Name (Def_Id, Arg3, Arg4);
6256                end if;
6257
6258                if Is_Compilation_Unit (Hom_Id) then
6259
6260                   --  Its possible homonyms are not affected by the pragma.
6261                   --  Such homonyms might be present in the context of other
6262                   --  units being compiled.
6263
6264                   exit;
6265
6266                elsif From_Aspect_Specification (N) then
6267                   exit;
6268
6269                else
6270                   Hom_Id := Homonym (Hom_Id);
6271                end if;
6272             end loop;
6273
6274          --  When the convention is Java or CIL, we also allow Import to
6275          --  be given for packages, generic packages, exceptions, record
6276          --  components, and access to subprograms.
6277
6278          elsif (C = Convention_Java or else C = Convention_CIL)
6279            and then
6280              (Is_Package_Or_Generic_Package (Def_Id)
6281                or else Ekind (Def_Id) = E_Exception
6282                or else Ekind (Def_Id) = E_Access_Subprogram_Type
6283                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
6284          then
6285             Set_Imported (Def_Id);
6286             Set_Is_Public (Def_Id);
6287             Process_Interface_Name (Def_Id, Arg3, Arg4);
6288
6289          --  Import a CPP class
6290
6291          elsif C = Convention_CPP
6292            and then (Is_Record_Type (Def_Id)
6293                       or else Ekind (Def_Id) = E_Incomplete_Type)
6294          then
6295             if Ekind (Def_Id) = E_Incomplete_Type then
6296                if Present (Full_View (Def_Id)) then
6297                   Def_Id := Full_View (Def_Id);
6298
6299                else
6300                   Error_Msg_N
6301                     ("cannot import 'C'P'P type before full declaration seen",
6302                      Get_Pragma_Arg (Arg2));
6303
6304                   --  Although we have reported the error we decorate it as
6305                   --  CPP_Class to avoid reporting spurious errors
6306
6307                   Set_Is_CPP_Class (Def_Id);
6308                   return;
6309                end if;
6310             end if;
6311
6312             --  Types treated as CPP classes must be declared limited (note:
6313             --  this used to be a warning but there is no real benefit to it
6314             --  since we did effectively intend to treat the type as limited
6315             --  anyway).
6316
6317             if not Is_Limited_Type (Def_Id) then
6318                Error_Msg_N
6319                  ("imported 'C'P'P type must be limited",
6320                   Get_Pragma_Arg (Arg2));
6321             end if;
6322
6323             if Etype (Def_Id) /= Def_Id
6324               and then not Is_CPP_Class (Root_Type (Def_Id))
6325             then
6326                Error_Msg_N ("root type must be a 'C'P'P type", Arg1);
6327             end if;
6328
6329             Set_Is_CPP_Class (Def_Id);
6330
6331             --  Imported CPP types must not have discriminants (because C++
6332             --  classes do not have discriminants).
6333
6334             if Has_Discriminants (Def_Id) then
6335                Error_Msg_N
6336                  ("imported 'C'P'P type cannot have discriminants",
6337                   First (Discriminant_Specifications
6338                           (Declaration_Node (Def_Id))));
6339             end if;
6340
6341             --  Check that components of imported CPP types do not have default
6342             --  expressions. For private types this check is performed when the
6343             --  full view is analyzed (see Process_Full_View).
6344
6345             if not Is_Private_Type (Def_Id) then
6346                Check_CPP_Type_Has_No_Defaults (Def_Id);
6347             end if;
6348
6349          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
6350             Check_No_Link_Name;
6351             Check_Arg_Count (3);
6352             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
6353
6354             Process_Import_Predefined_Type;
6355
6356          else
6357             Error_Pragma_Arg
6358               ("second argument of pragma% must be object, subprogram "
6359                & "or incomplete type",
6360                Arg2);
6361          end if;
6362
6363          --  If this pragma applies to a compilation unit, then the unit, which
6364          --  is a subprogram, does not require (or allow) a body. We also do
6365          --  not need to elaborate imported procedures.
6366
6367          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
6368             declare
6369                Cunit : constant Node_Id := Parent (Parent (N));
6370             begin
6371                Set_Body_Required (Cunit, False);
6372             end;
6373          end if;
6374       end Process_Import_Or_Interface;
6375
6376       --------------------
6377       -- Process_Inline --
6378       --------------------
6379
6380       procedure Process_Inline (Status : Inline_Status) is
6381          Assoc     : Node_Id;
6382          Decl      : Node_Id;
6383          Subp_Id   : Node_Id;
6384          Subp      : Entity_Id;
6385          Applies   : Boolean;
6386
6387          Effective : Boolean := False;
6388          --  Set True if inline has some effect, i.e. if there is at least one
6389          --  subprogram set as inlined as a result of the use of the pragma.
6390
6391          procedure Make_Inline (Subp : Entity_Id);
6392          --  Subp is the defining unit name of the subprogram declaration. Set
6393          --  the flag, as well as the flag in the corresponding body, if there
6394          --  is one present.
6395
6396          procedure Set_Inline_Flags (Subp : Entity_Id);
6397          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
6398          --  Has_Pragma_Inline_Always for the Inline_Always case.
6399
6400          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
6401          --  Returns True if it can be determined at this stage that inlining
6402          --  is not possible, for example if the body is available and contains
6403          --  exception handlers, we prevent inlining, since otherwise we can
6404          --  get undefined symbols at link time. This function also emits a
6405          --  warning if front-end inlining is enabled and the pragma appears
6406          --  too late.
6407          --
6408          --  ??? is business with link symbols still valid, or does it relate
6409          --  to front end ZCX which is being phased out ???
6410
6411          ---------------------------
6412          -- Inlining_Not_Possible --
6413          ---------------------------
6414
6415          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
6416             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
6417             Stats : Node_Id;
6418
6419          begin
6420             if Nkind (Decl) = N_Subprogram_Body then
6421                Stats := Handled_Statement_Sequence (Decl);
6422                return Present (Exception_Handlers (Stats))
6423                  or else Present (At_End_Proc (Stats));
6424
6425             elsif Nkind (Decl) = N_Subprogram_Declaration
6426               and then Present (Corresponding_Body (Decl))
6427             then
6428                if Front_End_Inlining
6429                  and then Analyzed (Corresponding_Body (Decl))
6430                then
6431                   Error_Msg_N ("pragma appears too late, ignored??", N);
6432                   return True;
6433
6434                --  If the subprogram is a renaming as body, the body is just a
6435                --  call to the renamed subprogram, and inlining is trivially
6436                --  possible.
6437
6438                elsif
6439                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
6440                                              N_Subprogram_Renaming_Declaration
6441                then
6442                   return False;
6443
6444                else
6445                   Stats :=
6446                     Handled_Statement_Sequence
6447                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
6448
6449                   return
6450                     Present (Exception_Handlers (Stats))
6451                       or else Present (At_End_Proc (Stats));
6452                end if;
6453
6454             else
6455                --  If body is not available, assume the best, the check is
6456                --  performed again when compiling enclosing package bodies.
6457
6458                return False;
6459             end if;
6460          end Inlining_Not_Possible;
6461
6462          -----------------
6463          -- Make_Inline --
6464          -----------------
6465
6466          procedure Make_Inline (Subp : Entity_Id) is
6467             Kind       : constant Entity_Kind := Ekind (Subp);
6468             Inner_Subp : Entity_Id   := Subp;
6469
6470          begin
6471             --  Ignore if bad type, avoid cascaded error
6472
6473             if Etype (Subp) = Any_Type then
6474                Applies := True;
6475                return;
6476
6477             --  Ignore if all inlining is suppressed
6478
6479             elsif Suppress_All_Inlining then
6480                Applies := True;
6481                return;
6482
6483             --  If inlining is not possible, for now do not treat as an error
6484
6485             elsif Status /= Suppressed
6486               and then Inlining_Not_Possible (Subp)
6487             then
6488                Applies := True;
6489                return;
6490
6491             --  Here we have a candidate for inlining, but we must exclude
6492             --  derived operations. Otherwise we would end up trying to inline
6493             --  a phantom declaration, and the result would be to drag in a
6494             --  body which has no direct inlining associated with it. That
6495             --  would not only be inefficient but would also result in the
6496             --  backend doing cross-unit inlining in cases where it was
6497             --  definitely inappropriate to do so.
6498
6499             --  However, a simple Comes_From_Source test is insufficient, since
6500             --  we do want to allow inlining of generic instances which also do
6501             --  not come from source. We also need to recognize specs generated
6502             --  by the front-end for bodies that carry the pragma. Finally,
6503             --  predefined operators do not come from source but are not
6504             --  inlineable either.
6505
6506             elsif Is_Generic_Instance (Subp)
6507               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
6508             then
6509                null;
6510
6511             elsif not Comes_From_Source (Subp)
6512               and then Scope (Subp) /= Standard_Standard
6513             then
6514                Applies := True;
6515                return;
6516             end if;
6517
6518             --  The referenced entity must either be the enclosing entity, or
6519             --  an entity declared within the current open scope.
6520
6521             if Present (Scope (Subp))
6522               and then Scope (Subp) /= Current_Scope
6523               and then Subp /= Current_Scope
6524             then
6525                Error_Pragma_Arg
6526                  ("argument of% must be entity in current scope", Assoc);
6527                return;
6528             end if;
6529
6530             --  Processing for procedure, operator or function. If subprogram
6531             --  is aliased (as for an instance) indicate that the renamed
6532             --  entity (if declared in the same unit) is inlined.
6533
6534             if Is_Subprogram (Subp) then
6535                Inner_Subp := Ultimate_Alias (Inner_Subp);
6536
6537                if In_Same_Source_Unit (Subp, Inner_Subp) then
6538                   Set_Inline_Flags (Inner_Subp);
6539
6540                   Decl := Parent (Parent (Inner_Subp));
6541
6542                   if Nkind (Decl) = N_Subprogram_Declaration
6543                     and then Present (Corresponding_Body (Decl))
6544                   then
6545                      Set_Inline_Flags (Corresponding_Body (Decl));
6546
6547                   elsif Is_Generic_Instance (Subp) then
6548
6549                      --  Indicate that the body needs to be created for
6550                      --  inlining subsequent calls. The instantiation node
6551                      --  follows the declaration of the wrapper package
6552                      --  created for it.
6553
6554                      if Scope (Subp) /= Standard_Standard
6555                        and then
6556                          Need_Subprogram_Instance_Body
6557                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
6558                               Subp)
6559                      then
6560                         null;
6561                      end if;
6562
6563                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
6564                   --  appear in a formal part to apply to a formal subprogram.
6565                   --  Do not apply check within an instance or a formal package
6566                   --  the test will have been applied to the original generic.
6567
6568                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
6569                     and then List_Containing (Decl) = List_Containing (N)
6570                     and then not In_Instance
6571                   then
6572                      Error_Msg_N
6573                        ("Inline cannot apply to a formal subprogram", N);
6574
6575                   --  If Subp is a renaming, it is the renamed entity that
6576                   --  will appear in any call, and be inlined. However, for
6577                   --  ASIS uses it is convenient to indicate that the renaming
6578                   --  itself is an inlined subprogram, so that some gnatcheck
6579                   --  rules can be applied in the absence of expansion.
6580
6581                   elsif Nkind (Decl) = N_Subprogram_Renaming_Declaration then
6582                      Set_Inline_Flags (Subp);
6583                   end if;
6584                end if;
6585
6586                Applies := True;
6587
6588             --  For a generic subprogram set flag as well, for use at the point
6589             --  of instantiation, to determine whether the body should be
6590             --  generated.
6591
6592             elsif Is_Generic_Subprogram (Subp) then
6593                Set_Inline_Flags (Subp);
6594                Applies := True;
6595
6596             --  Literals are by definition inlined
6597
6598             elsif Kind = E_Enumeration_Literal then
6599                null;
6600
6601             --  Anything else is an error
6602
6603             else
6604                Error_Pragma_Arg
6605                  ("expect subprogram name for pragma%", Assoc);
6606             end if;
6607          end Make_Inline;
6608
6609          ----------------------
6610          -- Set_Inline_Flags --
6611          ----------------------
6612
6613          procedure Set_Inline_Flags (Subp : Entity_Id) is
6614          begin
6615             --  First set the Has_Pragma_XXX flags and issue the appropriate
6616             --  errors and warnings for suspicious combinations.
6617
6618             if Prag_Id = Pragma_No_Inline then
6619                if Has_Pragma_Inline_Always (Subp) then
6620                   Error_Msg_N
6621                     ("Inline_Always and No_Inline are mutually exclusive", N);
6622                elsif Has_Pragma_Inline (Subp) then
6623                   Error_Msg_NE
6624                     ("Inline and No_Inline both specified for& ??",
6625                      N, Entity (Subp_Id));
6626                end if;
6627
6628                Set_Has_Pragma_No_Inline (Subp);
6629             else
6630                if Prag_Id = Pragma_Inline_Always then
6631                   if Has_Pragma_No_Inline (Subp) then
6632                      Error_Msg_N
6633                        ("Inline_Always and No_Inline are mutually exclusive",
6634                         N);
6635                   end if;
6636
6637                   Set_Has_Pragma_Inline_Always (Subp);
6638                else
6639                   if Has_Pragma_No_Inline (Subp) then
6640                      Error_Msg_NE
6641                        ("Inline and No_Inline both specified for& ??",
6642                         N, Entity (Subp_Id));
6643                   end if;
6644                end if;
6645
6646                if not Has_Pragma_Inline (Subp) then
6647                   Set_Has_Pragma_Inline (Subp);
6648                   Effective := True;
6649                end if;
6650             end if;
6651
6652             --  Then adjust the Is_Inlined flag. It can never be set if the
6653             --  subprogram is subject to pragma No_Inline.
6654
6655             case Status is
6656                when Suppressed =>
6657                   Set_Is_Inlined (Subp, False);
6658                when Disabled =>
6659                   null;
6660                when Enabled =>
6661                   if not Has_Pragma_No_Inline (Subp) then
6662                      Set_Is_Inlined (Subp, True);
6663                   end if;
6664             end case;
6665          end Set_Inline_Flags;
6666
6667       --  Start of processing for Process_Inline
6668
6669       begin
6670          Check_No_Identifiers;
6671          Check_At_Least_N_Arguments (1);
6672
6673          if Status = Enabled then
6674             Inline_Processing_Required := True;
6675          end if;
6676
6677          Assoc := Arg1;
6678          while Present (Assoc) loop
6679             Subp_Id := Get_Pragma_Arg (Assoc);
6680             Analyze (Subp_Id);
6681             Applies := False;
6682
6683             if Is_Entity_Name (Subp_Id) then
6684                Subp := Entity (Subp_Id);
6685
6686                if Subp = Any_Id then
6687
6688                   --  If previous error, avoid cascaded errors
6689
6690                   Check_Error_Detected;
6691                   Applies   := True;
6692                   Effective := True;
6693
6694                else
6695                   Make_Inline (Subp);
6696
6697                   --  For the pragma case, climb homonym chain. This is
6698                   --  what implements allowing the pragma in the renaming
6699                   --  case, with the result applying to the ancestors, and
6700                   --  also allows Inline to apply to all previous homonyms.
6701
6702                   if not From_Aspect_Specification (N) then
6703                      while Present (Homonym (Subp))
6704                        and then Scope (Homonym (Subp)) = Current_Scope
6705                      loop
6706                         Make_Inline (Homonym (Subp));
6707                         Subp := Homonym (Subp);
6708                      end loop;
6709                   end if;
6710                end if;
6711             end if;
6712
6713             if not Applies then
6714                Error_Pragma_Arg
6715                  ("inappropriate argument for pragma%", Assoc);
6716
6717             elsif not Effective
6718               and then Warn_On_Redundant_Constructs
6719               and then not (Status = Suppressed or else Suppress_All_Inlining)
6720             then
6721                if Inlining_Not_Possible (Subp) then
6722                   Error_Msg_NE
6723                     ("pragma Inline for& is ignored?r?",
6724                      N, Entity (Subp_Id));
6725                else
6726                   Error_Msg_NE
6727                     ("pragma Inline for& is redundant?r?",
6728                      N, Entity (Subp_Id));
6729                end if;
6730             end if;
6731
6732             Next (Assoc);
6733          end loop;
6734       end Process_Inline;
6735
6736       ----------------------------
6737       -- Process_Interface_Name --
6738       ----------------------------
6739
6740       procedure Process_Interface_Name
6741         (Subprogram_Def : Entity_Id;
6742          Ext_Arg        : Node_Id;
6743          Link_Arg       : Node_Id)
6744       is
6745          Ext_Nam    : Node_Id;
6746          Link_Nam   : Node_Id;
6747          String_Val : String_Id;
6748
6749          procedure Check_Form_Of_Interface_Name
6750            (SN            : Node_Id;
6751             Ext_Name_Case : Boolean);
6752          --  SN is a string literal node for an interface name. This routine
6753          --  performs some minimal checks that the name is reasonable. In
6754          --  particular that no spaces or other obviously incorrect characters
6755          --  appear. This is only a warning, since any characters are allowed.
6756          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
6757
6758          ----------------------------------
6759          -- Check_Form_Of_Interface_Name --
6760          ----------------------------------
6761
6762          procedure Check_Form_Of_Interface_Name
6763            (SN            : Node_Id;
6764             Ext_Name_Case : Boolean)
6765          is
6766             S  : constant String_Id := Strval (Expr_Value_S (SN));
6767             SL : constant Nat       := String_Length (S);
6768             C  : Char_Code;
6769
6770          begin
6771             if SL = 0 then
6772                Error_Msg_N ("interface name cannot be null string", SN);
6773             end if;
6774
6775             for J in 1 .. SL loop
6776                C := Get_String_Char (S, J);
6777
6778                --  Look for dubious character and issue unconditional warning.
6779                --  Definitely dubious if not in character range.
6780
6781                if not In_Character_Range (C)
6782
6783                   --  For all cases except CLI target,
6784                   --  commas, spaces and slashes are dubious (in CLI, we use
6785                   --  commas and backslashes in external names to specify
6786                   --  assembly version and public key, while slashes and spaces
6787                   --  can be used in names to mark nested classes and
6788                   --  valuetypes).
6789
6790                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
6791                              and then (Get_Character (C) = ','
6792                                          or else
6793                                        Get_Character (C) = '\'))
6794                  or else (VM_Target /= CLI_Target
6795                             and then (Get_Character (C) = ' '
6796                                         or else
6797                                       Get_Character (C) = '/'))
6798                then
6799                   Error_Msg
6800                     ("??interface name contains illegal character",
6801                      Sloc (SN) + Source_Ptr (J));
6802                end if;
6803             end loop;
6804          end Check_Form_Of_Interface_Name;
6805
6806       --  Start of processing for Process_Interface_Name
6807
6808       begin
6809          if No (Link_Arg) then
6810             if No (Ext_Arg) then
6811                if VM_Target = CLI_Target
6812                  and then Ekind (Subprogram_Def) = E_Package
6813                  and then Nkind (Parent (Subprogram_Def)) =
6814                                                  N_Package_Specification
6815                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
6816                then
6817                   Set_Interface_Name
6818                      (Subprogram_Def,
6819                       Interface_Name
6820                         (Generic_Parent (Parent (Subprogram_Def))));
6821                end if;
6822
6823                return;
6824
6825             elsif Chars (Ext_Arg) = Name_Link_Name then
6826                Ext_Nam  := Empty;
6827                Link_Nam := Expression (Ext_Arg);
6828
6829             else
6830                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
6831                Ext_Nam  := Expression (Ext_Arg);
6832                Link_Nam := Empty;
6833             end if;
6834
6835          else
6836             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
6837             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
6838             Ext_Nam  := Expression (Ext_Arg);
6839             Link_Nam := Expression (Link_Arg);
6840          end if;
6841
6842          --  Check expressions for external name and link name are static
6843
6844          if Present (Ext_Nam) then
6845             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
6846             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
6847
6848             --  Verify that external name is not the name of a local entity,
6849             --  which would hide the imported one and could lead to run-time
6850             --  surprises. The problem can only arise for entities declared in
6851             --  a package body (otherwise the external name is fully qualified
6852             --  and will not conflict).
6853
6854             declare
6855                Nam : Name_Id;
6856                E   : Entity_Id;
6857                Par : Node_Id;
6858
6859             begin
6860                if Prag_Id = Pragma_Import then
6861                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
6862                   Nam := Name_Find;
6863                   E   := Entity_Id (Get_Name_Table_Info (Nam));
6864
6865                   if Nam /= Chars (Subprogram_Def)
6866                     and then Present (E)
6867                     and then not Is_Overloadable (E)
6868                     and then Is_Immediately_Visible (E)
6869                     and then not Is_Imported (E)
6870                     and then Ekind (Scope (E)) = E_Package
6871                   then
6872                      Par := Parent (E);
6873                      while Present (Par) loop
6874                         if Nkind (Par) = N_Package_Body then
6875                            Error_Msg_Sloc := Sloc (E);
6876                            Error_Msg_NE
6877                              ("imported entity is hidden by & declared#",
6878                               Ext_Arg, E);
6879                            exit;
6880                         end if;
6881
6882                         Par := Parent (Par);
6883                      end loop;
6884                   end if;
6885                end if;
6886             end;
6887          end if;
6888
6889          if Present (Link_Nam) then
6890             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
6891             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
6892          end if;
6893
6894          --  If there is no link name, just set the external name
6895
6896          if No (Link_Nam) then
6897             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
6898
6899          --  For the Link_Name case, the given literal is preceded by an
6900          --  asterisk, which indicates to GCC that the given name should be
6901          --  taken literally, and in particular that no prepending of
6902          --  underlines should occur, even in systems where this is the
6903          --  normal default.
6904
6905          else
6906             Start_String;
6907
6908             if VM_Target = No_VM then
6909                Store_String_Char (Get_Char_Code ('*'));
6910             end if;
6911
6912             String_Val := Strval (Expr_Value_S (Link_Nam));
6913             Store_String_Chars (String_Val);
6914             Link_Nam :=
6915               Make_String_Literal (Sloc (Link_Nam),
6916                 Strval => End_String);
6917          end if;
6918
6919          --  Set the interface name. If the entity is a generic instance, use
6920          --  its alias, which is the callable entity.
6921
6922          if Is_Generic_Instance (Subprogram_Def) then
6923             Set_Encoded_Interface_Name
6924               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
6925          else
6926             Set_Encoded_Interface_Name
6927               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
6928          end if;
6929
6930          --  We allow duplicated export names in CIL/Java, as they are always
6931          --  enclosed in a namespace that differentiates them, and overloaded
6932          --  entities are supported by the VM.
6933
6934          if Convention (Subprogram_Def) /= Convention_CIL
6935               and then
6936             Convention (Subprogram_Def) /= Convention_Java
6937          then
6938             Check_Duplicated_Export_Name (Link_Nam);
6939          end if;
6940       end Process_Interface_Name;
6941
6942       -----------------------------------------
6943       -- Process_Interrupt_Or_Attach_Handler --
6944       -----------------------------------------
6945
6946       procedure Process_Interrupt_Or_Attach_Handler is
6947          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
6948          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
6949          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
6950
6951       begin
6952          Set_Is_Interrupt_Handler (Handler_Proc);
6953
6954          --  If the pragma is not associated with a handler procedure within a
6955          --  protected type, then it must be for a nonprotected procedure for
6956          --  the AAMP target, in which case we don't associate a representation
6957          --  item with the procedure's scope.
6958
6959          if Ekind (Proc_Scope) = E_Protected_Type then
6960             if Prag_Id = Pragma_Interrupt_Handler
6961                  or else
6962                Prag_Id = Pragma_Attach_Handler
6963             then
6964                Record_Rep_Item (Proc_Scope, N);
6965             end if;
6966          end if;
6967       end Process_Interrupt_Or_Attach_Handler;
6968
6969       --------------------------------------------------
6970       -- Process_Restrictions_Or_Restriction_Warnings --
6971       --------------------------------------------------
6972
6973       --  Note: some of the simple identifier cases were handled in par-prag,
6974       --  but it is harmless (and more straightforward) to simply handle all
6975       --  cases here, even if it means we repeat a bit of work in some cases.
6976
6977       procedure Process_Restrictions_Or_Restriction_Warnings
6978         (Warn : Boolean)
6979       is
6980          Arg   : Node_Id;
6981          R_Id  : Restriction_Id;
6982          Id    : Name_Id;
6983          Expr  : Node_Id;
6984          Val   : Uint;
6985
6986          procedure Check_Unit_Name (N : Node_Id);
6987          --  Checks unit name parameter for No_Dependence. Returns if it has
6988          --  an appropriate form, otherwise raises pragma argument error.
6989
6990          ---------------------
6991          -- Check_Unit_Name --
6992          ---------------------
6993
6994          procedure Check_Unit_Name (N : Node_Id) is
6995          begin
6996             if Nkind (N) = N_Selected_Component then
6997                Check_Unit_Name (Prefix (N));
6998                Check_Unit_Name (Selector_Name (N));
6999
7000             elsif Nkind (N) = N_Identifier then
7001                return;
7002
7003             else
7004                Error_Pragma_Arg
7005                  ("wrong form for unit name for No_Dependence", N);
7006             end if;
7007          end Check_Unit_Name;
7008
7009       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
7010
7011       begin
7012          --  Ignore all Restrictions pragma in CodePeer mode
7013
7014          if CodePeer_Mode then
7015             return;
7016          end if;
7017
7018          Check_Ada_83_Warning;
7019          Check_At_Least_N_Arguments (1);
7020          Check_Valid_Configuration_Pragma;
7021
7022          Arg := Arg1;
7023          while Present (Arg) loop
7024             Id := Chars (Arg);
7025             Expr := Get_Pragma_Arg (Arg);
7026
7027             --  Case of no restriction identifier present
7028
7029             if Id = No_Name then
7030                if Nkind (Expr) /= N_Identifier then
7031                   Error_Pragma_Arg
7032                     ("invalid form for restriction", Arg);
7033                end if;
7034
7035                R_Id :=
7036                  Get_Restriction_Id
7037                    (Process_Restriction_Synonyms (Expr));
7038
7039                if R_Id not in All_Boolean_Restrictions then
7040                   Error_Msg_Name_1 := Pname;
7041                   Error_Msg_N
7042                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
7043
7044                   --  Check for possible misspelling
7045
7046                   for J in Restriction_Id loop
7047                      declare
7048                         Rnm : constant String := Restriction_Id'Image (J);
7049
7050                      begin
7051                         Name_Buffer (1 .. Rnm'Length) := Rnm;
7052                         Name_Len := Rnm'Length;
7053                         Set_Casing (All_Lower_Case);
7054
7055                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
7056                            Set_Casing
7057                              (Identifier_Casing (Current_Source_File));
7058                            Error_Msg_String (1 .. Rnm'Length) :=
7059                              Name_Buffer (1 .. Name_Len);
7060                            Error_Msg_Strlen := Rnm'Length;
7061                            Error_Msg_N -- CODEFIX
7062                              ("\possible misspelling of ""~""",
7063                               Get_Pragma_Arg (Arg));
7064                            exit;
7065                         end if;
7066                      end;
7067                   end loop;
7068
7069                   raise Pragma_Exit;
7070                end if;
7071
7072                if Implementation_Restriction (R_Id) then
7073                   Check_Restriction (No_Implementation_Restrictions, Arg);
7074                end if;
7075
7076                --  Special processing for No_Elaboration_Code restriction
7077
7078                if R_Id = No_Elaboration_Code then
7079
7080                   --  Restriction is only recognized within a configuration
7081                   --  pragma file, or within a unit of the main extended
7082                   --  program. Note: the test for Main_Unit is needed to
7083                   --  properly include the case of configuration pragma files.
7084
7085                   if not (Current_Sem_Unit = Main_Unit
7086                            or else In_Extended_Main_Source_Unit (N))
7087                   then
7088                      return;
7089
7090                   --  Don't allow in a subunit unless already specified in
7091                   --  body or spec.
7092
7093                   elsif Nkind (Parent (N)) = N_Compilation_Unit
7094                     and then Nkind (Unit (Parent (N))) = N_Subunit
7095                     and then not Restriction_Active (No_Elaboration_Code)
7096                   then
7097                      Error_Msg_N
7098                        ("invalid specification of ""No_Elaboration_Code""",
7099                         N);
7100                      Error_Msg_N
7101                        ("\restriction cannot be specified in a subunit", N);
7102                      Error_Msg_N
7103                        ("\unless also specified in body or spec", N);
7104                      return;
7105
7106                   --  If we have a No_Elaboration_Code pragma that we
7107                   --  accept, then it needs to be added to the configuration
7108                   --  restrcition set so that we get proper application to
7109                   --  other units in the main extended source as required.
7110
7111                   else
7112                      Add_To_Config_Boolean_Restrictions (No_Elaboration_Code);
7113                   end if;
7114                end if;
7115
7116                --  If this is a warning, then set the warning unless we already
7117                --  have a real restriction active (we never want a warning to
7118                --  override a real restriction).
7119
7120                if Warn then
7121                   if not Restriction_Active (R_Id) then
7122                      Set_Restriction (R_Id, N);
7123                      Restriction_Warnings (R_Id) := True;
7124                   end if;
7125
7126                --  If real restriction case, then set it and make sure that the
7127                --  restriction warning flag is off, since a real restriction
7128                --  always overrides a warning.
7129
7130                else
7131                   Set_Restriction (R_Id, N);
7132                   Restriction_Warnings (R_Id) := False;
7133                end if;
7134
7135                --  Check for obsolescent restrictions in Ada 2005 mode
7136
7137                if not Warn
7138                  and then Ada_Version >= Ada_2005
7139                  and then (R_Id = No_Asynchronous_Control
7140                             or else
7141                            R_Id = No_Unchecked_Deallocation
7142                             or else
7143                            R_Id = No_Unchecked_Conversion)
7144                then
7145                   Check_Restriction (No_Obsolescent_Features, N);
7146                end if;
7147
7148                --  A very special case that must be processed here: pragma
7149                --  Restrictions (No_Exceptions) turns off all run-time
7150                --  checking. This is a bit dubious in terms of the formal
7151                --  language definition, but it is what is intended by RM
7152                --  H.4(12). Restriction_Warnings never affects generated code
7153                --  so this is done only in the real restriction case.
7154
7155                --  Atomic_Synchronization is not a real check, so it is not
7156                --  affected by this processing).
7157
7158                if R_Id = No_Exceptions and then not Warn then
7159                   for J in Scope_Suppress.Suppress'Range loop
7160                      if J /= Atomic_Synchronization then
7161                         Scope_Suppress.Suppress (J) := True;
7162                      end if;
7163                   end loop;
7164                end if;
7165
7166             --  Case of No_Dependence => unit-name. Note that the parser
7167             --  already made the necessary entry in the No_Dependence table.
7168
7169             elsif Id = Name_No_Dependence then
7170                Check_Unit_Name (Expr);
7171
7172             --  Case of No_Specification_Of_Aspect => Identifier.
7173
7174             elsif Id = Name_No_Specification_Of_Aspect then
7175                declare
7176                   A_Id : Aspect_Id;
7177
7178                begin
7179                   if Nkind (Expr) /= N_Identifier then
7180                      A_Id := No_Aspect;
7181                   else
7182                      A_Id := Get_Aspect_Id (Chars (Expr));
7183                   end if;
7184
7185                   if A_Id = No_Aspect then
7186                      Error_Pragma_Arg ("invalid restriction name", Arg);
7187                   else
7188                      Set_Restriction_No_Specification_Of_Aspect (Expr, Warn);
7189                   end if;
7190                end;
7191
7192             elsif Id = Name_No_Use_Of_Attribute then
7193                if Nkind (Expr) /= N_Identifier
7194                  or else not Is_Attribute_Name (Chars (Expr))
7195                then
7196                   Error_Msg_N ("unknown attribute name?", Expr);
7197
7198                else
7199                   Set_Restriction_No_Use_Of_Attribute (Expr, Warn);
7200                end if;
7201
7202             elsif Id = Name_No_Use_Of_Pragma then
7203                if Nkind (Expr) /= N_Identifier
7204                  or else not Is_Pragma_Name (Chars (Expr))
7205                then
7206                   Error_Msg_N ("unknown pragma name?", Expr);
7207
7208                else
7209                   Set_Restriction_No_Use_Of_Pragma (Expr, Warn);
7210                end if;
7211
7212             --  All other cases of restriction identifier present
7213
7214             else
7215                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
7216                Analyze_And_Resolve (Expr, Any_Integer);
7217
7218                if R_Id not in All_Parameter_Restrictions then
7219                   Error_Pragma_Arg
7220                     ("invalid restriction parameter identifier", Arg);
7221
7222                elsif not Is_OK_Static_Expression (Expr) then
7223                   Flag_Non_Static_Expr
7224                     ("value must be static expression!", Expr);
7225                   raise Pragma_Exit;
7226
7227                elsif not Is_Integer_Type (Etype (Expr))
7228                  or else Expr_Value (Expr) < 0
7229                then
7230                   Error_Pragma_Arg
7231                     ("value must be non-negative integer", Arg);
7232                end if;
7233
7234                --  Restriction pragma is active
7235
7236                Val := Expr_Value (Expr);
7237
7238                if not UI_Is_In_Int_Range (Val) then
7239                   Error_Pragma_Arg
7240                     ("pragma ignored, value too large??", Arg);
7241                end if;
7242
7243                --  Warning case. If the real restriction is active, then we
7244                --  ignore the request, since warning never overrides a real
7245                --  restriction. Otherwise we set the proper warning. Note that
7246                --  this circuit sets the warning again if it is already set,
7247                --  which is what we want, since the constant may have changed.
7248
7249                if Warn then
7250                   if not Restriction_Active (R_Id) then
7251                      Set_Restriction
7252                        (R_Id, N, Integer (UI_To_Int (Val)));
7253                      Restriction_Warnings (R_Id) := True;
7254                   end if;
7255
7256                --  Real restriction case, set restriction and make sure warning
7257                --  flag is off since real restriction always overrides warning.
7258
7259                else
7260                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
7261                   Restriction_Warnings (R_Id) := False;
7262                end if;
7263             end if;
7264
7265             Next (Arg);
7266          end loop;
7267       end Process_Restrictions_Or_Restriction_Warnings;
7268
7269       ---------------------------------
7270       -- Process_Suppress_Unsuppress --
7271       ---------------------------------
7272
7273       --  Note: this procedure makes entries in the check suppress data
7274       --  structures managed by Sem. See spec of package Sem for full
7275       --  details on how we handle recording of check suppression.
7276
7277       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
7278          C    : Check_Id;
7279          E_Id : Node_Id;
7280          E    : Entity_Id;
7281
7282          In_Package_Spec : constant Boolean :=
7283                              Is_Package_Or_Generic_Package (Current_Scope)
7284                                and then not In_Package_Body (Current_Scope);
7285
7286          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
7287          --  Used to suppress a single check on the given entity
7288
7289          --------------------------------
7290          -- Suppress_Unsuppress_Echeck --
7291          --------------------------------
7292
7293          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
7294          begin
7295             --  Check for error of trying to set atomic synchronization for
7296             --  a non-atomic variable.
7297
7298             if C = Atomic_Synchronization
7299               and then not (Is_Atomic (E) or else Has_Atomic_Components (E))
7300             then
7301                Error_Msg_N
7302                  ("pragma & requires atomic type or variable",
7303                   Pragma_Identifier (Original_Node (N)));
7304             end if;
7305
7306             Set_Checks_May_Be_Suppressed (E);
7307
7308             if In_Package_Spec then
7309                Push_Global_Suppress_Stack_Entry
7310                  (Entity   => E,
7311                   Check    => C,
7312                   Suppress => Suppress_Case);
7313             else
7314                Push_Local_Suppress_Stack_Entry
7315                  (Entity   => E,
7316                   Check    => C,
7317                   Suppress => Suppress_Case);
7318             end if;
7319
7320             --  If this is a first subtype, and the base type is distinct,
7321             --  then also set the suppress flags on the base type.
7322
7323             if Is_First_Subtype (E) and then Etype (E) /= E then
7324                Suppress_Unsuppress_Echeck (Etype (E), C);
7325             end if;
7326          end Suppress_Unsuppress_Echeck;
7327
7328       --  Start of processing for Process_Suppress_Unsuppress
7329
7330       begin
7331          --  Ignore pragma Suppress/Unsuppress in CodePeer and SPARK modes on
7332          --  user code: we want to generate checks for analysis purposes, as
7333          --  set respectively by -gnatC and -gnatd.F
7334
7335          if (CodePeer_Mode or SPARK_Mode) and then Comes_From_Source (N) then
7336             return;
7337          end if;
7338
7339          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
7340          --  declarative part or a package spec (RM 11.5(5)).
7341
7342          if not Is_Configuration_Pragma then
7343             Check_Is_In_Decl_Part_Or_Package_Spec;
7344          end if;
7345
7346          Check_At_Least_N_Arguments (1);
7347          Check_At_Most_N_Arguments (2);
7348          Check_No_Identifier (Arg1);
7349          Check_Arg_Is_Identifier (Arg1);
7350
7351          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
7352
7353          if C = No_Check_Id then
7354             Error_Pragma_Arg
7355               ("argument of pragma% is not valid check name", Arg1);
7356          end if;
7357
7358          if Arg_Count = 1 then
7359
7360             --  Make an entry in the local scope suppress table. This is the
7361             --  table that directly shows the current value of the scope
7362             --  suppress check for any check id value.
7363
7364             if C = All_Checks then
7365
7366                --  For All_Checks, we set all specific predefined checks with
7367                --  the exception of Elaboration_Check, which is handled
7368                --  specially because of not wanting All_Checks to have the
7369                --  effect of deactivating static elaboration order processing.
7370                --  Atomic_Synchronization is also not affected, since this is
7371                --  not a real check.
7372
7373                for J in Scope_Suppress.Suppress'Range loop
7374                   if J /= Elaboration_Check
7375                        and then
7376                      J /= Atomic_Synchronization
7377                   then
7378                      Scope_Suppress.Suppress (J) := Suppress_Case;
7379                   end if;
7380                end loop;
7381
7382             --  If not All_Checks, and predefined check, then set appropriate
7383             --  scope entry. Note that we will set Elaboration_Check if this
7384             --  is explicitly specified. Atomic_Synchronization is allowed
7385             --  only if internally generated and entity is atomic.
7386
7387             elsif C in Predefined_Check_Id
7388               and then (not Comes_From_Source (N)
7389                          or else C /= Atomic_Synchronization)
7390             then
7391                Scope_Suppress.Suppress (C) := Suppress_Case;
7392             end if;
7393
7394             --  Also make an entry in the Local_Entity_Suppress table
7395
7396             Push_Local_Suppress_Stack_Entry
7397               (Entity   => Empty,
7398                Check    => C,
7399                Suppress => Suppress_Case);
7400
7401          --  Case of two arguments present, where the check is suppressed for
7402          --  a specified entity (given as the second argument of the pragma)
7403
7404          else
7405             --  This is obsolescent in Ada 2005 mode
7406
7407             if Ada_Version >= Ada_2005 then
7408                Check_Restriction (No_Obsolescent_Features, Arg2);
7409             end if;
7410
7411             Check_Optional_Identifier (Arg2, Name_On);
7412             E_Id := Get_Pragma_Arg (Arg2);
7413             Analyze (E_Id);
7414
7415             if not Is_Entity_Name (E_Id) then
7416                Error_Pragma_Arg
7417                  ("second argument of pragma% must be entity name", Arg2);
7418             end if;
7419
7420             E := Entity (E_Id);
7421
7422             if E = Any_Id then
7423                return;
7424             end if;
7425
7426             --  Enforce RM 11.5(7) which requires that for a pragma that
7427             --  appears within a package spec, the named entity must be
7428             --  within the package spec. We allow the package name itself
7429             --  to be mentioned since that makes sense, although it is not
7430             --  strictly allowed by 11.5(7).
7431
7432             if In_Package_Spec
7433               and then E /= Current_Scope
7434               and then Scope (E) /= Current_Scope
7435             then
7436                Error_Pragma_Arg
7437                  ("entity in pragma% is not in package spec (RM 11.5(7))",
7438                   Arg2);
7439             end if;
7440
7441             --  Loop through homonyms. As noted below, in the case of a package
7442             --  spec, only homonyms within the package spec are considered.
7443
7444             loop
7445                Suppress_Unsuppress_Echeck (E, C);
7446
7447                if Is_Generic_Instance (E)
7448                  and then Is_Subprogram (E)
7449                  and then Present (Alias (E))
7450                then
7451                   Suppress_Unsuppress_Echeck (Alias (E), C);
7452                end if;
7453
7454                --  Move to next homonym if not aspect spec case
7455
7456                exit when From_Aspect_Specification (N);
7457                E := Homonym (E);
7458                exit when No (E);
7459
7460                --  If we are within a package specification, the pragma only
7461                --  applies to homonyms in the same scope.
7462
7463                exit when In_Package_Spec
7464                  and then Scope (E) /= Current_Scope;
7465             end loop;
7466          end if;
7467       end Process_Suppress_Unsuppress;
7468
7469       ------------------
7470       -- Set_Exported --
7471       ------------------
7472
7473       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
7474       begin
7475          if Is_Imported (E) then
7476             Error_Pragma_Arg
7477               ("cannot export entity& that was previously imported", Arg);
7478
7479          elsif Present (Address_Clause (E))
7480            and then not Relaxed_RM_Semantics
7481          then
7482             Error_Pragma_Arg
7483               ("cannot export entity& that has an address clause", Arg);
7484          end if;
7485
7486          Set_Is_Exported (E);
7487
7488          --  Generate a reference for entity explicitly, because the
7489          --  identifier may be overloaded and name resolution will not
7490          --  generate one.
7491
7492          Generate_Reference (E, Arg);
7493
7494          --  Deal with exporting non-library level entity
7495
7496          if not Is_Library_Level_Entity (E) then
7497
7498             --  Not allowed at all for subprograms
7499
7500             if Is_Subprogram (E) then
7501                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
7502
7503             --  Otherwise set public and statically allocated
7504
7505             else
7506                Set_Is_Public (E);
7507                Set_Is_Statically_Allocated (E);
7508
7509                --  Warn if the corresponding W flag is set and the pragma comes
7510                --  from source. The latter may not be true e.g. on VMS where we
7511                --  expand export pragmas for exception codes associated with
7512                --  imported or exported exceptions. We do not want to generate
7513                --  a warning for something that the user did not write.
7514
7515                if Warn_On_Export_Import
7516                  and then Comes_From_Source (Arg)
7517                then
7518                   Error_Msg_NE
7519                     ("?x?& has been made static as a result of Export",
7520                      Arg, E);
7521                   Error_Msg_N
7522                     ("\?x?this usage is non-standard and non-portable",
7523                      Arg);
7524                end if;
7525             end if;
7526          end if;
7527
7528          if Warn_On_Export_Import and then Is_Type (E) then
7529             Error_Msg_NE ("exporting a type has no effect?x?", Arg, E);
7530          end if;
7531
7532          if Warn_On_Export_Import and Inside_A_Generic then
7533             Error_Msg_NE
7534               ("all instances of& will have the same external name?x?",
7535                Arg, E);
7536          end if;
7537       end Set_Exported;
7538
7539       ----------------------------------------------
7540       -- Set_Extended_Import_Export_External_Name --
7541       ----------------------------------------------
7542
7543       procedure Set_Extended_Import_Export_External_Name
7544         (Internal_Ent : Entity_Id;
7545          Arg_External : Node_Id)
7546       is
7547          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
7548          New_Name : Node_Id;
7549
7550       begin
7551          if No (Arg_External) then
7552             return;
7553          end if;
7554
7555          Check_Arg_Is_External_Name (Arg_External);
7556
7557          if Nkind (Arg_External) = N_String_Literal then
7558             if String_Length (Strval (Arg_External)) = 0 then
7559                return;
7560             else
7561                New_Name := Adjust_External_Name_Case (Arg_External);
7562             end if;
7563
7564          elsif Nkind (Arg_External) = N_Identifier then
7565             New_Name := Get_Default_External_Name (Arg_External);
7566
7567          --  Check_Arg_Is_External_Name should let through only identifiers and
7568          --  string literals or static string expressions (which are folded to
7569          --  string literals).
7570
7571          else
7572             raise Program_Error;
7573          end if;
7574
7575          --  If we already have an external name set (by a prior normal Import
7576          --  or Export pragma), then the external names must match
7577
7578          if Present (Interface_Name (Internal_Ent)) then
7579             Check_Matching_Internal_Names : declare
7580                S1 : constant String_Id := Strval (Old_Name);
7581                S2 : constant String_Id := Strval (New_Name);
7582
7583                procedure Mismatch;
7584                pragma No_Return (Mismatch);
7585                --  Called if names do not match
7586
7587                --------------
7588                -- Mismatch --
7589                --------------
7590
7591                procedure Mismatch is
7592                begin
7593                   Error_Msg_Sloc := Sloc (Old_Name);
7594                   Error_Pragma_Arg
7595                     ("external name does not match that given #",
7596                      Arg_External);
7597                end Mismatch;
7598
7599             --  Start of processing for Check_Matching_Internal_Names
7600
7601             begin
7602                if String_Length (S1) /= String_Length (S2) then
7603                   Mismatch;
7604
7605                else
7606                   for J in 1 .. String_Length (S1) loop
7607                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
7608                         Mismatch;
7609                      end if;
7610                   end loop;
7611                end if;
7612             end Check_Matching_Internal_Names;
7613
7614          --  Otherwise set the given name
7615
7616          else
7617             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
7618             Check_Duplicated_Export_Name (New_Name);
7619          end if;
7620       end Set_Extended_Import_Export_External_Name;
7621
7622       ------------------
7623       -- Set_Imported --
7624       ------------------
7625
7626       procedure Set_Imported (E : Entity_Id) is
7627       begin
7628          --  Error message if already imported or exported
7629
7630          if Is_Exported (E) or else Is_Imported (E) then
7631
7632             --  Error if being set Exported twice
7633
7634             if Is_Exported (E) then
7635                Error_Msg_NE ("entity& was previously exported", N, E);
7636
7637             --  Ignore error in CodePeer mode where we treat all imported
7638             --  subprograms as unknown.
7639
7640             elsif CodePeer_Mode then
7641                goto OK;
7642
7643             --  OK if Import/Interface case
7644
7645             elsif Import_Interface_Present (N) then
7646                goto OK;
7647
7648             --  Error if being set Imported twice
7649
7650             else
7651                Error_Msg_NE ("entity& was previously imported", N, E);
7652             end if;
7653
7654             Error_Msg_Name_1 := Pname;
7655             Error_Msg_N
7656               ("\(pragma% applies to all previous entities)", N);
7657
7658             Error_Msg_Sloc  := Sloc (E);
7659             Error_Msg_NE ("\import not allowed for& declared#", N, E);
7660
7661          --  Here if not previously imported or exported, OK to import
7662
7663          else
7664             Set_Is_Imported (E);
7665
7666             --  If the entity is an object that is not at the library level,
7667             --  then it is statically allocated. We do not worry about objects
7668             --  with address clauses in this context since they are not really
7669             --  imported in the linker sense.
7670
7671             if Is_Object (E)
7672               and then not Is_Library_Level_Entity (E)
7673               and then No (Address_Clause (E))
7674             then
7675                Set_Is_Statically_Allocated (E);
7676             end if;
7677          end if;
7678
7679          <<OK>> null;
7680       end Set_Imported;
7681
7682       -------------------------
7683       -- Set_Mechanism_Value --
7684       -------------------------
7685
7686       --  Note: the mechanism name has not been analyzed (and cannot indeed be
7687       --  analyzed, since it is semantic nonsense), so we get it in the exact
7688       --  form created by the parser.
7689
7690       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
7691          Class        : Node_Id;
7692          Param        : Node_Id;
7693          Mech_Name_Id : Name_Id;
7694
7695          procedure Bad_Class;
7696          pragma No_Return (Bad_Class);
7697          --  Signal bad descriptor class name
7698
7699          procedure Bad_Mechanism;
7700          pragma No_Return (Bad_Mechanism);
7701          --  Signal bad mechanism name
7702
7703          ---------------
7704          -- Bad_Class --
7705          ---------------
7706
7707          procedure Bad_Class is
7708          begin
7709             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
7710          end Bad_Class;
7711
7712          -------------------------
7713          -- Bad_Mechanism_Value --
7714          -------------------------
7715
7716          procedure Bad_Mechanism is
7717          begin
7718             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
7719          end Bad_Mechanism;
7720
7721       --  Start of processing for Set_Mechanism_Value
7722
7723       begin
7724          if Mechanism (Ent) /= Default_Mechanism then
7725             Error_Msg_NE
7726               ("mechanism for & has already been set", Mech_Name, Ent);
7727          end if;
7728
7729          --  MECHANISM_NAME ::= value | reference | descriptor |
7730          --                     short_descriptor
7731
7732          if Nkind (Mech_Name) = N_Identifier then
7733             if Chars (Mech_Name) = Name_Value then
7734                Set_Mechanism (Ent, By_Copy);
7735                return;
7736
7737             elsif Chars (Mech_Name) = Name_Reference then
7738                Set_Mechanism (Ent, By_Reference);
7739                return;
7740
7741             elsif Chars (Mech_Name) = Name_Descriptor then
7742                Check_VMS (Mech_Name);
7743
7744                --  Descriptor => Short_Descriptor if pragma was given
7745
7746                if Short_Descriptors then
7747                   Set_Mechanism (Ent, By_Short_Descriptor);
7748                else
7749                   Set_Mechanism (Ent, By_Descriptor);
7750                end if;
7751
7752                return;
7753
7754             elsif Chars (Mech_Name) = Name_Short_Descriptor then
7755                Check_VMS (Mech_Name);
7756                Set_Mechanism (Ent, By_Short_Descriptor);
7757                return;
7758
7759             elsif Chars (Mech_Name) = Name_Copy then
7760                Error_Pragma_Arg
7761                  ("bad mechanism name, Value assumed", Mech_Name);
7762
7763             else
7764                Bad_Mechanism;
7765             end if;
7766
7767          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
7768          --                     short_descriptor (CLASS_NAME)
7769          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
7770
7771          --  Note: this form is parsed as an indexed component
7772
7773          elsif Nkind (Mech_Name) = N_Indexed_Component then
7774             Class := First (Expressions (Mech_Name));
7775
7776             if Nkind (Prefix (Mech_Name)) /= N_Identifier
7777               or else
7778                 not Nam_In (Chars (Prefix (Mech_Name)), Name_Descriptor,
7779                                                         Name_Short_Descriptor)
7780               or else Present (Next (Class))
7781             then
7782                Bad_Mechanism;
7783             else
7784                Mech_Name_Id := Chars (Prefix (Mech_Name));
7785
7786                --  Change Descriptor => Short_Descriptor if pragma was given
7787
7788                if Mech_Name_Id = Name_Descriptor
7789                  and then Short_Descriptors
7790                then
7791                   Mech_Name_Id := Name_Short_Descriptor;
7792                end if;
7793             end if;
7794
7795          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
7796          --                     short_descriptor (Class => CLASS_NAME)
7797          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
7798
7799          --  Note: this form is parsed as a function call
7800
7801          elsif Nkind (Mech_Name) = N_Function_Call then
7802             Param := First (Parameter_Associations (Mech_Name));
7803
7804             if Nkind (Name (Mech_Name)) /= N_Identifier
7805               or else
7806                 not Nam_In (Chars (Name (Mech_Name)), Name_Descriptor,
7807                                                       Name_Short_Descriptor)
7808               or else Present (Next (Param))
7809               or else No (Selector_Name (Param))
7810               or else Chars (Selector_Name (Param)) /= Name_Class
7811             then
7812                Bad_Mechanism;
7813             else
7814                Class := Explicit_Actual_Parameter (Param);
7815                Mech_Name_Id := Chars (Name (Mech_Name));
7816             end if;
7817
7818          else
7819             Bad_Mechanism;
7820          end if;
7821
7822          --  Fall through here with Class set to descriptor class name
7823
7824          Check_VMS (Mech_Name);
7825
7826          if Nkind (Class) /= N_Identifier then
7827             Bad_Class;
7828
7829          elsif Mech_Name_Id = Name_Descriptor
7830            and then Chars (Class) = Name_UBS
7831          then
7832             Set_Mechanism (Ent, By_Descriptor_UBS);
7833
7834          elsif Mech_Name_Id = Name_Descriptor
7835            and then Chars (Class) = Name_UBSB
7836          then
7837             Set_Mechanism (Ent, By_Descriptor_UBSB);
7838
7839          elsif Mech_Name_Id = Name_Descriptor
7840            and then Chars (Class) = Name_UBA
7841          then
7842             Set_Mechanism (Ent, By_Descriptor_UBA);
7843
7844          elsif Mech_Name_Id = Name_Descriptor
7845            and then Chars (Class) = Name_S
7846          then
7847             Set_Mechanism (Ent, By_Descriptor_S);
7848
7849          elsif Mech_Name_Id = Name_Descriptor
7850            and then Chars (Class) = Name_SB
7851          then
7852             Set_Mechanism (Ent, By_Descriptor_SB);
7853
7854          elsif Mech_Name_Id = Name_Descriptor
7855            and then Chars (Class) = Name_A
7856          then
7857             Set_Mechanism (Ent, By_Descriptor_A);
7858
7859          elsif Mech_Name_Id = Name_Descriptor
7860            and then Chars (Class) = Name_NCA
7861          then
7862             Set_Mechanism (Ent, By_Descriptor_NCA);
7863
7864          elsif Mech_Name_Id = Name_Short_Descriptor
7865            and then Chars (Class) = Name_UBS
7866          then
7867             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
7868
7869          elsif Mech_Name_Id = Name_Short_Descriptor
7870            and then Chars (Class) = Name_UBSB
7871          then
7872             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
7873
7874          elsif Mech_Name_Id = Name_Short_Descriptor
7875            and then Chars (Class) = Name_UBA
7876          then
7877             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
7878
7879          elsif Mech_Name_Id = Name_Short_Descriptor
7880            and then Chars (Class) = Name_S
7881          then
7882             Set_Mechanism (Ent, By_Short_Descriptor_S);
7883
7884          elsif Mech_Name_Id = Name_Short_Descriptor
7885            and then Chars (Class) = Name_SB
7886          then
7887             Set_Mechanism (Ent, By_Short_Descriptor_SB);
7888
7889          elsif Mech_Name_Id = Name_Short_Descriptor
7890            and then Chars (Class) = Name_A
7891          then
7892             Set_Mechanism (Ent, By_Short_Descriptor_A);
7893
7894          elsif Mech_Name_Id = Name_Short_Descriptor
7895            and then Chars (Class) = Name_NCA
7896          then
7897             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
7898
7899          else
7900             Bad_Class;
7901          end if;
7902       end Set_Mechanism_Value;
7903
7904       --------------------------
7905       -- Set_Rational_Profile --
7906       --------------------------
7907
7908       --  The Rational profile includes Implicit_Packing, Use_Vads_Size, and
7909       --  and extension to the semantics of renaming declarations.
7910
7911       procedure Set_Rational_Profile is
7912       begin
7913          Implicit_Packing     := True;
7914          Overriding_Renamings := True;
7915          Use_VADS_Size        := True;
7916       end Set_Rational_Profile;
7917
7918       ---------------------------
7919       -- Set_Ravenscar_Profile --
7920       ---------------------------
7921
7922       --  The tasks to be done here are
7923
7924       --    Set required policies
7925
7926       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
7927       --      pragma Locking_Policy (Ceiling_Locking)
7928
7929       --    Set Detect_Blocking mode
7930
7931       --    Set required restrictions (see System.Rident for detailed list)
7932
7933       --    Set the No_Dependence rules
7934       --      No_Dependence => Ada.Asynchronous_Task_Control
7935       --      No_Dependence => Ada.Calendar
7936       --      No_Dependence => Ada.Execution_Time.Group_Budget
7937       --      No_Dependence => Ada.Execution_Time.Timers
7938       --      No_Dependence => Ada.Task_Attributes
7939       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
7940
7941       procedure Set_Ravenscar_Profile (N : Node_Id) is
7942          Prefix_Entity   : Entity_Id;
7943          Selector_Entity : Entity_Id;
7944          Prefix_Node     : Node_Id;
7945          Node            : Node_Id;
7946
7947       begin
7948          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
7949
7950          if Task_Dispatching_Policy /= ' '
7951            and then Task_Dispatching_Policy /= 'F'
7952          then
7953             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
7954             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
7955
7956          --  Set the FIFO_Within_Priorities policy, but always preserve
7957          --  System_Location since we like the error message with the run time
7958          --  name.
7959
7960          else
7961             Task_Dispatching_Policy := 'F';
7962
7963             if Task_Dispatching_Policy_Sloc /= System_Location then
7964                Task_Dispatching_Policy_Sloc := Loc;
7965             end if;
7966          end if;
7967
7968          --  pragma Locking_Policy (Ceiling_Locking)
7969
7970          if Locking_Policy /= ' '
7971            and then Locking_Policy /= 'C'
7972          then
7973             Error_Msg_Sloc := Locking_Policy_Sloc;
7974             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
7975
7976          --  Set the Ceiling_Locking policy, but preserve System_Location since
7977          --  we like the error message with the run time name.
7978
7979          else
7980             Locking_Policy := 'C';
7981
7982             if Locking_Policy_Sloc /= System_Location then
7983                Locking_Policy_Sloc := Loc;
7984             end if;
7985          end if;
7986
7987          --  pragma Detect_Blocking
7988
7989          Detect_Blocking := True;
7990
7991          --  Set the corresponding restrictions
7992
7993          Set_Profile_Restrictions
7994            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
7995
7996          --  Set the No_Dependence restrictions
7997
7998          --  The following No_Dependence restrictions:
7999          --    No_Dependence => Ada.Asynchronous_Task_Control
8000          --    No_Dependence => Ada.Calendar
8001          --    No_Dependence => Ada.Task_Attributes
8002          --  are already set by previous call to Set_Profile_Restrictions.
8003
8004          --  Set the following restrictions which were added to Ada 2005:
8005          --    No_Dependence => Ada.Execution_Time.Group_Budget
8006          --    No_Dependence => Ada.Execution_Time.Timers
8007
8008          if Ada_Version >= Ada_2005 then
8009             Name_Buffer (1 .. 3) := "ada";
8010             Name_Len := 3;
8011
8012             Prefix_Entity := Make_Identifier (Loc, Name_Find);
8013
8014             Name_Buffer (1 .. 14) := "execution_time";
8015             Name_Len := 14;
8016
8017             Selector_Entity := Make_Identifier (Loc, Name_Find);
8018
8019             Prefix_Node :=
8020               Make_Selected_Component
8021                 (Sloc          => Loc,
8022                  Prefix        => Prefix_Entity,
8023                  Selector_Name => Selector_Entity);
8024
8025             Name_Buffer (1 .. 13) := "group_budgets";
8026             Name_Len := 13;
8027
8028             Selector_Entity := Make_Identifier (Loc, Name_Find);
8029
8030             Node :=
8031               Make_Selected_Component
8032                 (Sloc          => Loc,
8033                  Prefix        => Prefix_Node,
8034                  Selector_Name => Selector_Entity);
8035
8036             Set_Restriction_No_Dependence
8037               (Unit    => Node,
8038                Warn    => Treat_Restrictions_As_Warnings,
8039                Profile => Ravenscar);
8040
8041             Name_Buffer (1 .. 6) := "timers";
8042             Name_Len := 6;
8043
8044             Selector_Entity := Make_Identifier (Loc, Name_Find);
8045
8046             Node :=
8047               Make_Selected_Component
8048                 (Sloc          => Loc,
8049                  Prefix        => Prefix_Node,
8050                  Selector_Name => Selector_Entity);
8051
8052             Set_Restriction_No_Dependence
8053               (Unit    => Node,
8054                Warn    => Treat_Restrictions_As_Warnings,
8055                Profile => Ravenscar);
8056          end if;
8057
8058          --  Set the following restrictions which was added to Ada 2012 (see
8059          --  AI-0171):
8060          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
8061
8062          if Ada_Version >= Ada_2012 then
8063             Name_Buffer (1 .. 6) := "system";
8064             Name_Len := 6;
8065
8066             Prefix_Entity := Make_Identifier (Loc, Name_Find);
8067
8068             Name_Buffer (1 .. 15) := "multiprocessors";
8069             Name_Len := 15;
8070
8071             Selector_Entity := Make_Identifier (Loc, Name_Find);
8072
8073             Prefix_Node :=
8074               Make_Selected_Component
8075                 (Sloc          => Loc,
8076                  Prefix        => Prefix_Entity,
8077                  Selector_Name => Selector_Entity);
8078
8079             Name_Buffer (1 .. 19) := "dispatching_domains";
8080             Name_Len := 19;
8081
8082             Selector_Entity := Make_Identifier (Loc, Name_Find);
8083
8084             Node :=
8085               Make_Selected_Component
8086                 (Sloc          => Loc,
8087                  Prefix        => Prefix_Node,
8088                  Selector_Name => Selector_Entity);
8089
8090             Set_Restriction_No_Dependence
8091               (Unit    => Node,
8092                Warn    => Treat_Restrictions_As_Warnings,
8093                Profile => Ravenscar);
8094          end if;
8095       end Set_Ravenscar_Profile;
8096
8097       ----------------
8098       -- S14_Pragma --
8099       ----------------
8100
8101       procedure S14_Pragma is
8102       begin
8103          if not Formal_Extensions then
8104             Error_Pragma ("pragma% requires the use of debug switch -gnatd.V");
8105          end if;
8106       end S14_Pragma;
8107
8108    --  Start of processing for Analyze_Pragma
8109
8110    begin
8111       --  The following code is a defense against recursion. Not clear that
8112       --  this can happen legitimately, but perhaps some error situations
8113       --  can cause it, and we did see this recursion during testing.
8114
8115       if Analyzed (N) then
8116          return;
8117       else
8118          Set_Analyzed (N, True);
8119       end if;
8120
8121       --  Deal with unrecognized pragma
8122
8123       Pname := Pragma_Name (N);
8124
8125       if not Is_Pragma_Name (Pname) then
8126          if Warn_On_Unrecognized_Pragma then
8127             Error_Msg_Name_1 := Pname;
8128             Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N));
8129
8130             for PN in First_Pragma_Name .. Last_Pragma_Name loop
8131                if Is_Bad_Spelling_Of (Pname, PN) then
8132                   Error_Msg_Name_1 := PN;
8133                   Error_Msg_N -- CODEFIX
8134                     ("\?g?possible misspelling of %!", Pragma_Identifier (N));
8135                   exit;
8136                end if;
8137             end loop;
8138          end if;
8139
8140          return;
8141       end if;
8142
8143       --  Here to start processing for recognized pragma
8144
8145       Prag_Id := Get_Pragma_Id (Pname);
8146       Pname := Original_Name (N);
8147
8148       --  Check applicable policy. We skip this for a pragma that came from
8149       --  an aspect, since we already dealt with the Disable case, and we set
8150       --  the Is_Ignored flag at the time the aspect was analyzed.
8151
8152       if not From_Aspect_Specification (N) then
8153          Check_Applicable_Policy (N);
8154
8155          --  If pragma is disabled, rewrite as NULL and skip analysis
8156
8157          if Is_Disabled (N) then
8158             Rewrite (N, Make_Null_Statement (Loc));
8159             Analyze (N);
8160             raise Pragma_Exit;
8161          end if;
8162       end if;
8163
8164       --  Preset arguments
8165
8166       Arg_Count := 0;
8167       Arg1      := Empty;
8168       Arg2      := Empty;
8169       Arg3      := Empty;
8170       Arg4      := Empty;
8171
8172       if Present (Pragma_Argument_Associations (N)) then
8173          Arg_Count := List_Length (Pragma_Argument_Associations (N));
8174          Arg1 := First (Pragma_Argument_Associations (N));
8175
8176          if Present (Arg1) then
8177             Arg2 := Next (Arg1);
8178
8179             if Present (Arg2) then
8180                Arg3 := Next (Arg2);
8181
8182                if Present (Arg3) then
8183                   Arg4 := Next (Arg3);
8184                end if;
8185             end if;
8186          end if;
8187       end if;
8188
8189       Check_Restriction_No_Use_Of_Pragma (N);
8190
8191       --  An enumeration type defines the pragmas that are supported by the
8192       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
8193       --  into the corresponding enumeration value for the following case.
8194
8195       case Prag_Id is
8196
8197          -----------------
8198          -- Abort_Defer --
8199          -----------------
8200
8201          --  pragma Abort_Defer;
8202
8203          when Pragma_Abort_Defer =>
8204             GNAT_Pragma;
8205             Check_Arg_Count (0);
8206
8207             --  The only required semantic processing is to check the
8208             --  placement. This pragma must appear at the start of the
8209             --  statement sequence of a handled sequence of statements.
8210
8211             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
8212               or else N /= First (Statements (Parent (N)))
8213             then
8214                Pragma_Misplaced;
8215             end if;
8216
8217          --------------------
8218          -- Abstract_State --
8219          --------------------
8220
8221          --  pragma Abstract_State (ABSTRACT_STATE_LIST)
8222
8223          --  ABSTRACT_STATE_LIST ::=
8224          --    null
8225          --  | STATE_NAME_WITH_PROPERTIES {, STATE_NAME_WITH_PROPERTIES}
8226
8227          --  STATE_NAME_WITH_PROPERTIES ::=
8228          --    STATE_NAME
8229          --  | (STATE_NAME with PROPERTY_LIST)
8230
8231          --  PROPERTY_LIST ::= PROPERTY {, PROPERTY}
8232          --  PROPERTY      ::= SIMPLE_PROPERTY | NAME_VALUE_PROPERTY
8233
8234          --  SIMPLE_PROPERTY      ::= IDENTIFIER
8235          --  NAME_VALUE_PROPERTY  ::= IDENTIFIER => EXPRESSION
8236
8237          --  STATE_NAME ::= DEFINING_IDENTIFIER
8238
8239          when Pragma_Abstract_State => Abstract_State : declare
8240             Pack_Id : Entity_Id;
8241
8242             --  Flags used to verify the consistency of states
8243
8244             Non_Null_Seen : Boolean := False;
8245             Null_Seen     : Boolean := False;
8246
8247             procedure Analyze_Abstract_State (State : Node_Id);
8248             --  Verify the legality of a single state declaration. Create and
8249             --  decorate a state abstraction entity and introduce it into the
8250             --  visibility chain.
8251
8252             ----------------------------
8253             -- Analyze_Abstract_State --
8254             ----------------------------
8255
8256             procedure Analyze_Abstract_State (State : Node_Id) is
8257                procedure Check_Duplicate_Property
8258                  (Prop   : Node_Id;
8259                   Status : in out Boolean);
8260                --  Flag Status denotes whether a particular property has been
8261                --  seen while processing a state. This routine verifies that
8262                --  Prop is not a duplicate property and sets the flag Status.
8263
8264                ------------------------------
8265                -- Check_Duplicate_Property --
8266                ------------------------------
8267
8268                procedure Check_Duplicate_Property
8269                  (Prop   : Node_Id;
8270                   Status : in out Boolean)
8271                is
8272                begin
8273                   if Status then
8274                      Error_Msg_N ("duplicate state property", Prop);
8275                   end if;
8276
8277                   Status := True;
8278                end Check_Duplicate_Property;
8279
8280                --  Local variables
8281
8282                Errors  : constant Nat := Serious_Errors_Detected;
8283                Loc     : constant Source_Ptr := Sloc (State);
8284                Assoc   : Node_Id;
8285                Id      : Entity_Id;
8286                Is_Null : Boolean := False;
8287                Level   : Uint := Uint_0;
8288                Name    : Name_Id;
8289                Prop    : Node_Id;
8290
8291                --  Flags used to verify the consistency of properties
8292
8293                Input_Seen     : Boolean := False;
8294                Integrity_Seen : Boolean := False;
8295                Output_Seen    : Boolean := False;
8296                Volatile_Seen  : Boolean := False;
8297
8298             --  Start of processing for Analyze_Abstract_State
8299
8300             begin
8301                --  A package with a null abstract state is not allowed to
8302                --  declare additional states.
8303
8304                if Null_Seen then
8305                   Error_Msg_NE
8306                     ("package & has null abstract state", State, Pack_Id);
8307
8308                --  Null states appear as internally generated entities
8309
8310                elsif Nkind (State) = N_Null then
8311                   Name := New_Internal_Name ('S');
8312                   Is_Null := True;
8313                   Null_Seen := True;
8314
8315                   --  Catch a case where a null state appears in a list of
8316                   --  non-null states.
8317
8318                   if Non_Null_Seen then
8319                      Error_Msg_NE
8320                        ("package & has non-null abstract state",
8321                         State, Pack_Id);
8322                   end if;
8323
8324                --  Simple state declaration
8325
8326                elsif Nkind (State) = N_Identifier then
8327                   Name := Chars (State);
8328                   Non_Null_Seen := True;
8329
8330                --  State declaration with various properties. This construct
8331                --  appears as an extension aggregate in the tree.
8332
8333                elsif Nkind (State) = N_Extension_Aggregate then
8334                   if Nkind (Ancestor_Part (State)) = N_Identifier then
8335                      Name := Chars (Ancestor_Part (State));
8336                      Non_Null_Seen := True;
8337                   else
8338                      Error_Msg_N
8339                        ("state name must be an identifier",
8340                         Ancestor_Part (State));
8341                   end if;
8342
8343                   --  Process properties Input, Output and Volatile. Ensure
8344                   --  that none of them appear more than once.
8345
8346                   Prop := First (Expressions (State));
8347                   while Present (Prop) loop
8348                      if Nkind (Prop) = N_Identifier then
8349                         if Chars (Prop) = Name_Input then
8350                            Check_Duplicate_Property (Prop, Input_Seen);
8351                         elsif Chars (Prop) = Name_Output then
8352                            Check_Duplicate_Property (Prop, Output_Seen);
8353                         elsif Chars (Prop) = Name_Volatile then
8354                            Check_Duplicate_Property (Prop, Volatile_Seen);
8355                         else
8356                            Error_Msg_N ("invalid state property", Prop);
8357                         end if;
8358                      else
8359                         Error_Msg_N ("invalid state property", Prop);
8360                      end if;
8361
8362                      Next (Prop);
8363                   end loop;
8364
8365                   --  Volatile requires exactly one Input or Output
8366
8367                   if Volatile_Seen and then Input_Seen = Output_Seen then
8368                      Error_Msg_N
8369                        ("property Volatile requires exactly one Input or "
8370                         & "Output", State);
8371                   end if;
8372
8373                   --  Either Input or Output require Volatile
8374
8375                   if (Input_Seen or Output_Seen)
8376                     and then not Volatile_Seen
8377                   then
8378                      Error_Msg_N
8379                        ("properties Input and Output require Volatile", State);
8380                   end if;
8381
8382                   --  State property Integrity appears as a component
8383                   --  association.
8384
8385                   Assoc := First (Component_Associations (State));
8386                   while Present (Assoc) loop
8387                      Prop := First (Choices (Assoc));
8388                      while Present (Prop) loop
8389                         if Nkind (Prop) = N_Identifier
8390                           and then Chars (Prop) = Name_Integrity
8391                         then
8392                            Check_Duplicate_Property (Prop, Integrity_Seen);
8393                         else
8394                            Error_Msg_N ("invalid state property", Prop);
8395                         end if;
8396
8397                         Next (Prop);
8398                      end loop;
8399
8400                      if Nkind (Expression (Assoc)) = N_Integer_Literal then
8401                         Level := Intval (Expression (Assoc));
8402                      else
8403                         Error_Msg_N
8404                           ("integrity level must be an integer literal",
8405                            Expression (Assoc));
8406                      end if;
8407
8408                      Next (Assoc);
8409                   end loop;
8410
8411                --  Any other attempt to declare a state is erroneous
8412
8413                else
8414                   Error_Msg_N ("malformed abstract state declaration", State);
8415                end if;
8416
8417                --  Do not generate a state abstraction entity if it was not
8418                --  properly declared.
8419
8420                if Serious_Errors_Detected > Errors then
8421                   return;
8422                end if;
8423
8424                --  The generated state abstraction reuses the same characters
8425                --  from the original state declaration. Decorate the entity.
8426
8427                Id := Make_Defining_Identifier (Loc, New_External_Name (Name));
8428                Set_Comes_From_Source (Id, not Is_Null);
8429                Set_Parent            (Id, State);
8430                Set_Ekind             (Id, E_Abstract_State);
8431                Set_Etype             (Id, Standard_Void_Type);
8432                Set_Integrity_Level   (Id, Level);
8433                Set_Refined_State     (Id, Empty);
8434
8435                --  Every non-null state must be nameable and resolvable the
8436                --  same way a constant is.
8437
8438                if not Is_Null then
8439                   Push_Scope (Pack_Id);
8440                   Enter_Name (Id);
8441                   Pop_Scope;
8442                end if;
8443
8444                --  Verify whether the state introduces an illegal hidden state
8445                --  within a package subject to a null abstract state.
8446
8447                if Formal_Extensions then
8448                   Check_No_Hidden_State (Id);
8449                end if;
8450
8451                --  Associate the state with its related package
8452
8453                if No (Abstract_States (Pack_Id)) then
8454                   Set_Abstract_States (Pack_Id, New_Elmt_List);
8455                end if;
8456
8457                Append_Elmt (Id, Abstract_States (Pack_Id));
8458             end Analyze_Abstract_State;
8459
8460             --  Local variables
8461
8462             Par   : Node_Id;
8463             State : Node_Id;
8464
8465          --  Start of processing for Abstract_State
8466
8467          begin
8468             GNAT_Pragma;
8469             S14_Pragma;
8470             Check_Arg_Count (1);
8471
8472             --  Ensure the proper placement of the pragma. Abstract states must
8473             --  be associated with a package declaration.
8474
8475             if From_Aspect_Specification (N) then
8476                Par := Parent (Corresponding_Aspect (N));
8477             else
8478                Par := Parent (Parent (N));
8479             end if;
8480
8481             if Nkind (Par) = N_Compilation_Unit then
8482                Par := Unit (Par);
8483             end if;
8484
8485             if not Nkind_In (Par, N_Generic_Package_Declaration,
8486                                   N_Package_Declaration)
8487             then
8488                Pragma_Misplaced;
8489                return;
8490             end if;
8491
8492             Pack_Id := Defining_Entity (Par);
8493             State   := Expression (Arg1);
8494
8495             --  Multiple abstract states appear as an aggregate
8496
8497             if Nkind (State) = N_Aggregate then
8498                State := First (Expressions (State));
8499                while Present (State) loop
8500                   Analyze_Abstract_State (State);
8501
8502                   Next (State);
8503                end loop;
8504
8505             --  Various forms of a single abstract state. Note that these may
8506             --  include malformed state declarations.
8507
8508             else
8509                Analyze_Abstract_State (State);
8510             end if;
8511          end Abstract_State;
8512
8513          ------------
8514          -- Ada_83 --
8515          ------------
8516
8517          --  pragma Ada_83;
8518
8519          --  Note: this pragma also has some specific processing in Par.Prag
8520          --  because we want to set the Ada version mode during parsing.
8521
8522          when Pragma_Ada_83 =>
8523             GNAT_Pragma;
8524             Check_Arg_Count (0);
8525
8526             --  We really should check unconditionally for proper configuration
8527             --  pragma placement, since we really don't want mixed Ada modes
8528             --  within a single unit, and the GNAT reference manual has always
8529             --  said this was a configuration pragma, but we did not check and
8530             --  are hesitant to add the check now.
8531
8532             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
8533             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
8534             --  or Ada 2012 mode.
8535
8536             if Ada_Version >= Ada_2005 then
8537                Check_Valid_Configuration_Pragma;
8538             end if;
8539
8540             --  Now set Ada 83 mode
8541
8542             Ada_Version := Ada_83;
8543             Ada_Version_Explicit := Ada_Version;
8544
8545          ------------
8546          -- Ada_95 --
8547          ------------
8548
8549          --  pragma Ada_95;
8550
8551          --  Note: this pragma also has some specific processing in Par.Prag
8552          --  because we want to set the Ada 83 version mode during parsing.
8553
8554          when Pragma_Ada_95 =>
8555             GNAT_Pragma;
8556             Check_Arg_Count (0);
8557
8558             --  We really should check unconditionally for proper configuration
8559             --  pragma placement, since we really don't want mixed Ada modes
8560             --  within a single unit, and the GNAT reference manual has always
8561             --  said this was a configuration pragma, but we did not check and
8562             --  are hesitant to add the check now.
8563
8564             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
8565             --  or Ada 95, so we must check if we are in Ada 2005 mode.
8566
8567             if Ada_Version >= Ada_2005 then
8568                Check_Valid_Configuration_Pragma;
8569             end if;
8570
8571             --  Now set Ada 95 mode
8572
8573             Ada_Version := Ada_95;
8574             Ada_Version_Explicit := Ada_Version;
8575
8576          ---------------------
8577          -- Ada_05/Ada_2005 --
8578          ---------------------
8579
8580          --  pragma Ada_05;
8581          --  pragma Ada_05 (LOCAL_NAME);
8582
8583          --  pragma Ada_2005;
8584          --  pragma Ada_2005 (LOCAL_NAME):
8585
8586          --  Note: these pragmas also have some specific processing in Par.Prag
8587          --  because we want to set the Ada 2005 version mode during parsing.
8588
8589          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
8590             E_Id : Node_Id;
8591
8592          begin
8593             GNAT_Pragma;
8594
8595             if Arg_Count = 1 then
8596                Check_Arg_Is_Local_Name (Arg1);
8597                E_Id := Get_Pragma_Arg (Arg1);
8598
8599                if Etype (E_Id) = Any_Type then
8600                   return;
8601                end if;
8602
8603                Set_Is_Ada_2005_Only (Entity (E_Id));
8604                Record_Rep_Item (Entity (E_Id), N);
8605
8606             else
8607                Check_Arg_Count (0);
8608
8609                --  For Ada_2005 we unconditionally enforce the documented
8610                --  configuration pragma placement, since we do not want to
8611                --  tolerate mixed modes in a unit involving Ada 2005. That
8612                --  would cause real difficulties for those cases where there
8613                --  are incompatibilities between Ada 95 and Ada 2005.
8614
8615                Check_Valid_Configuration_Pragma;
8616
8617                --  Now set appropriate Ada mode
8618
8619                Ada_Version          := Ada_2005;
8620                Ada_Version_Explicit := Ada_2005;
8621             end if;
8622          end;
8623
8624          ---------------------
8625          -- Ada_12/Ada_2012 --
8626          ---------------------
8627
8628          --  pragma Ada_12;
8629          --  pragma Ada_12 (LOCAL_NAME);
8630
8631          --  pragma Ada_2012;
8632          --  pragma Ada_2012 (LOCAL_NAME):
8633
8634          --  Note: these pragmas also have some specific processing in Par.Prag
8635          --  because we want to set the Ada 2012 version mode during parsing.
8636
8637          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
8638             E_Id : Node_Id;
8639
8640          begin
8641             GNAT_Pragma;
8642
8643             if Arg_Count = 1 then
8644                Check_Arg_Is_Local_Name (Arg1);
8645                E_Id := Get_Pragma_Arg (Arg1);
8646
8647                if Etype (E_Id) = Any_Type then
8648                   return;
8649                end if;
8650
8651                Set_Is_Ada_2012_Only (Entity (E_Id));
8652                Record_Rep_Item (Entity (E_Id), N);
8653
8654             else
8655                Check_Arg_Count (0);
8656
8657                --  For Ada_2012 we unconditionally enforce the documented
8658                --  configuration pragma placement, since we do not want to
8659                --  tolerate mixed modes in a unit involving Ada 2012. That
8660                --  would cause real difficulties for those cases where there
8661                --  are incompatibilities between Ada 95 and Ada 2012. We could
8662                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
8663
8664                Check_Valid_Configuration_Pragma;
8665
8666                --  Now set appropriate Ada mode
8667
8668                Ada_Version          := Ada_2012;
8669                Ada_Version_Explicit := Ada_2012;
8670             end if;
8671          end;
8672
8673          ----------------------
8674          -- All_Calls_Remote --
8675          ----------------------
8676
8677          --  pragma All_Calls_Remote [(library_package_NAME)];
8678
8679          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
8680             Lib_Entity : Entity_Id;
8681
8682          begin
8683             Check_Ada_83_Warning;
8684             Check_Valid_Library_Unit_Pragma;
8685
8686             if Nkind (N) = N_Null_Statement then
8687                return;
8688             end if;
8689
8690             Lib_Entity := Find_Lib_Unit_Name;
8691
8692             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
8693
8694             if Present (Lib_Entity)
8695               and then not Debug_Flag_U
8696             then
8697                if not Is_Remote_Call_Interface (Lib_Entity) then
8698                   Error_Pragma ("pragma% only apply to rci unit");
8699
8700                --  Set flag for entity of the library unit
8701
8702                else
8703                   Set_Has_All_Calls_Remote (Lib_Entity);
8704                end if;
8705
8706             end if;
8707          end All_Calls_Remote;
8708
8709          --------------
8710          -- Annotate --
8711          --------------
8712
8713          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
8714          --  ARG ::= NAME | EXPRESSION
8715
8716          --  The first two arguments are by convention intended to refer to an
8717          --  external tool and a tool-specific function. These arguments are
8718          --  not analyzed.
8719
8720          when Pragma_Annotate => Annotate : declare
8721             Arg : Node_Id;
8722             Exp : Node_Id;
8723
8724          begin
8725             GNAT_Pragma;
8726             Check_At_Least_N_Arguments (1);
8727             Check_Arg_Is_Identifier (Arg1);
8728             Check_No_Identifiers;
8729             Store_Note (N);
8730
8731             --  Second parameter is optional, it is never analyzed
8732
8733             if No (Arg2) then
8734                null;
8735
8736             --  Here if we have a second parameter
8737
8738             else
8739                --  Second parameter must be identifier
8740
8741                Check_Arg_Is_Identifier (Arg2);
8742
8743                --  Process remaining parameters if any
8744
8745                Arg := Next (Arg2);
8746                while Present (Arg) loop
8747                   Exp := Get_Pragma_Arg (Arg);
8748                   Analyze (Exp);
8749
8750                   if Is_Entity_Name (Exp) then
8751                      null;
8752
8753                   --  For string literals, we assume Standard_String as the
8754                   --  type, unless the string contains wide or wide_wide
8755                   --  characters.
8756
8757                   elsif Nkind (Exp) = N_String_Literal then
8758                      if Has_Wide_Wide_Character (Exp) then
8759                         Resolve (Exp, Standard_Wide_Wide_String);
8760                      elsif Has_Wide_Character (Exp) then
8761                         Resolve (Exp, Standard_Wide_String);
8762                      else
8763                         Resolve (Exp, Standard_String);
8764                      end if;
8765
8766                   elsif Is_Overloaded (Exp) then
8767                         Error_Pragma_Arg
8768                           ("ambiguous argument for pragma%", Exp);
8769
8770                   else
8771                      Resolve (Exp);
8772                   end if;
8773
8774                   Next (Arg);
8775                end loop;
8776             end if;
8777          end Annotate;
8778
8779          -------------------------------------------------
8780          -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
8781          -------------------------------------------------
8782
8783          --  pragma Assert
8784          --    (   [Check => ]  Boolean_EXPRESSION
8785          --     [, [Message =>] Static_String_EXPRESSION]);
8786
8787          --  pragma Assert_And_Cut
8788          --    (   [Check => ]  Boolean_EXPRESSION
8789          --     [, [Message =>] Static_String_EXPRESSION]);
8790
8791          --  pragma Assume
8792          --    (   [Check => ]  Boolean_EXPRESSION
8793          --     [, [Message =>] Static_String_EXPRESSION]);
8794
8795          --  pragma Loop_Invariant
8796          --    (   [Check => ]  Boolean_EXPRESSION
8797          --     [, [Message =>] Static_String_EXPRESSION]);
8798
8799          when Pragma_Assert         |
8800               Pragma_Assert_And_Cut |
8801               Pragma_Assume         |
8802               Pragma_Loop_Invariant =>
8803          Assert : declare
8804             Expr : Node_Id;
8805             Newa : List_Id;
8806
8807          begin
8808             --  Assert is an Ada 2005 RM-defined pragma
8809
8810             if Prag_Id = Pragma_Assert then
8811                Ada_2005_Pragma;
8812
8813             --  The remaining ones are GNAT pragmas
8814
8815             else
8816                GNAT_Pragma;
8817             end if;
8818
8819             Check_At_Least_N_Arguments (1);
8820             Check_At_Most_N_Arguments (2);
8821             Check_Arg_Order ((Name_Check, Name_Message));
8822             Check_Optional_Identifier (Arg1, Name_Check);
8823
8824             --  Special processing for Loop_Invariant
8825
8826             if Prag_Id = Pragma_Loop_Invariant then
8827
8828                --  Check restricted placement, must be within a loop
8829
8830                Check_Loop_Pragma_Placement;
8831
8832                --  Do preanalyze to deal with embedded Loop_Entry attribute
8833
8834                Preanalyze_Assert_Expression (Expression (Arg1), Any_Boolean);
8835             end if;
8836
8837             --  Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
8838             --  a corresponding Check pragma:
8839
8840             --    pragma Check (name, condition [, msg]);
8841
8842             --  Where name is the identifier matching the pragma name. So
8843             --  rewrite pragma in this manner, transfer the message argument
8844             --  if present, and analyze the result
8845
8846             --  Note: When dealing with a semantically analyzed tree, the
8847             --  information that a Check node N corresponds to a source Assert,
8848             --  Assume, or Assert_And_Cut pragma can be retrieved from the
8849             --  pragma kind of Original_Node(N).
8850
8851             Expr := Get_Pragma_Arg (Arg1);
8852             Newa := New_List (
8853               Make_Pragma_Argument_Association (Loc,
8854                 Expression => Make_Identifier (Loc, Pname)),
8855               Make_Pragma_Argument_Association (Sloc (Expr),
8856                 Expression => Expr));
8857
8858             if Arg_Count > 1 then
8859                Check_Optional_Identifier (Arg2, Name_Message);
8860                Append_To (Newa, New_Copy_Tree (Arg2));
8861             end if;
8862
8863             Rewrite (N,
8864               Make_Pragma (Loc,
8865                 Chars                        => Name_Check,
8866                 Pragma_Argument_Associations => Newa));
8867             Analyze (N);
8868          end Assert;
8869
8870          ----------------------
8871          -- Assertion_Policy --
8872          ----------------------
8873
8874          --  pragma Assertion_Policy (POLICY_IDENTIFIER);
8875
8876          --  The following form is Ada 2012 only, but we allow it in all modes
8877
8878          --  Pragma Assertion_Policy (
8879          --      ASSERTION_KIND => POLICY_IDENTIFIER
8880          --   {, ASSERTION_KIND => POLICY_IDENTIFIER});
8881
8882          --  ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
8883
8884          --  RM_ASSERTION_KIND ::= Assert               |
8885          --                        Static_Predicate     |
8886          --                        Dynamic_Predicate    |
8887          --                        Pre                  |
8888          --                        Pre'Class            |
8889          --                        Post                 |
8890          --                        Post'Class           |
8891          --                        Type_Invariant       |
8892          --                        Type_Invariant'Class
8893
8894          --  ID_ASSERTION_KIND ::= Assert_And_Cut       |
8895          --                        Assume               |
8896          --                        Contract_Cases       |
8897          --                        Debug                |
8898          --                        Loop_Invariant       |
8899          --                        Loop_Variant         |
8900          --                        Postcondition        |
8901          --                        Precondition         |
8902          --                        Predicate            |
8903          --                        Statement_Assertions
8904          --
8905          --  Note: The RM_ASSERTION_KIND list is language-defined, and the
8906          --  ID_ASSERTION_KIND list contains implementation-defined additions
8907          --  recognized by GNAT. The effect is to control the behavior of
8908          --  identically named aspects and pragmas, depending on the specified
8909          --  policy identifier:
8910
8911          --  POLICY_IDENTIFIER ::= Check | Disable | Ignore
8912
8913          --  Note: Check and Ignore are language-defined. Disable is a GNAT
8914          --  implementation defined addition that results in totally ignoring
8915          --  the corresponding assertion. If Disable is specified, then the
8916          --  argument of the assertion is not even analyzed. This is useful
8917          --  when the aspect/pragma argument references entities in a with'ed
8918          --  package that is replaced by a dummy package in the final build.
8919
8920          --  Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
8921          --  and Type_Invariant'Class were recognized by the parser and
8922          --  transformed into references to the special internal identifiers
8923          --  _Pre, _Post, _Invariant, and _Type_Invariant, so no special
8924          --  processing is required here.
8925
8926          when Pragma_Assertion_Policy => Assertion_Policy : declare
8927             LocP   : Source_Ptr;
8928             Policy : Node_Id;
8929             Arg    : Node_Id;
8930             Kind   : Name_Id;
8931
8932          begin
8933             Ada_2005_Pragma;
8934
8935             --  This can always appear as a configuration pragma
8936
8937             if Is_Configuration_Pragma then
8938                null;
8939
8940             --  It can also appear in a declarative part or package spec in Ada
8941             --  2012 mode. We allow this in other modes, but in that case we
8942             --  consider that we have an Ada 2012 pragma on our hands.
8943
8944             else
8945                Check_Is_In_Decl_Part_Or_Package_Spec;
8946                Ada_2012_Pragma;
8947             end if;
8948
8949             --  One argument case with no identifier (first form above)
8950
8951             if Arg_Count = 1
8952               and then (Nkind (Arg1) /= N_Pragma_Argument_Association
8953                          or else Chars (Arg1) = No_Name)
8954             then
8955                Check_Arg_Is_One_Of
8956                  (Arg1, Name_Check, Name_Disable, Name_Ignore);
8957
8958                --  Treat one argument Assertion_Policy as equivalent to:
8959
8960                --    pragma Check_Policy (Assertion, policy)
8961
8962                --  So rewrite pragma in that manner and link on to the chain
8963                --  of Check_Policy pragmas, marking the pragma as analyzed.
8964
8965                Policy := Get_Pragma_Arg (Arg1);
8966
8967                Rewrite (N,
8968                  Make_Pragma (Loc,
8969                    Chars                        => Name_Check_Policy,
8970                    Pragma_Argument_Associations => New_List (
8971                      Make_Pragma_Argument_Association (Loc,
8972                        Expression => Make_Identifier (Loc, Name_Assertion)),
8973
8974                      Make_Pragma_Argument_Association (Loc,
8975                        Expression =>
8976                          Make_Identifier (Sloc (Policy), Chars (Policy))))));
8977                Analyze (N);
8978
8979             --  Here if we have two or more arguments
8980
8981             else
8982                Check_At_Least_N_Arguments (1);
8983                Ada_2012_Pragma;
8984
8985                --  Loop through arguments
8986
8987                Arg := Arg1;
8988                while Present (Arg) loop
8989                   LocP := Sloc (Arg);
8990
8991                   --  Kind must be specified
8992
8993                   if Nkind (Arg) /= N_Pragma_Argument_Association
8994                     or else Chars (Arg) = No_Name
8995                   then
8996                      Error_Pragma_Arg
8997                        ("missing assertion kind for pragma%", Arg);
8998                   end if;
8999
9000                   --  Check Kind and Policy have allowed forms
9001
9002                   Kind := Chars (Arg);
9003
9004                   if not Is_Valid_Assertion_Kind (Kind) then
9005                      Error_Pragma_Arg
9006                        ("invalid assertion kind for pragma%", Arg);
9007                   end if;
9008
9009                   Check_Arg_Is_One_Of
9010                     (Arg, Name_Check, Name_Disable, Name_Ignore);
9011
9012                   --  We rewrite the Assertion_Policy pragma as a series of
9013                   --  Check_Policy pragmas:
9014
9015                   --    Check_Policy (Kind, Policy);
9016
9017                   Insert_Action (N,
9018                     Make_Pragma (LocP,
9019                       Chars                        => Name_Check_Policy,
9020                       Pragma_Argument_Associations => New_List (
9021                          Make_Pragma_Argument_Association (LocP,
9022                            Expression => Make_Identifier (LocP, Kind)),
9023                          Make_Pragma_Argument_Association (LocP,
9024                            Expression => Get_Pragma_Arg (Arg)))));
9025
9026                   Arg := Next (Arg);
9027                end loop;
9028
9029                --  Rewrite the Assertion_Policy pragma as null since we have
9030                --  now inserted all the equivalent Check pragmas.
9031
9032                Rewrite (N, Make_Null_Statement (Loc));
9033                Analyze (N);
9034             end if;
9035          end Assertion_Policy;
9036
9037          ------------------------------
9038          -- Assume_No_Invalid_Values --
9039          ------------------------------
9040
9041          --  pragma Assume_No_Invalid_Values (On | Off);
9042
9043          when Pragma_Assume_No_Invalid_Values =>
9044             GNAT_Pragma;
9045             Check_Valid_Configuration_Pragma;
9046             Check_Arg_Count (1);
9047             Check_No_Identifiers;
9048             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
9049
9050             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
9051                Assume_No_Invalid_Values := True;
9052             else
9053                Assume_No_Invalid_Values := False;
9054             end if;
9055
9056          --------------------------
9057          -- Attribute_Definition --
9058          --------------------------
9059
9060          --  pragma Attribute_Definition
9061          --    ([Attribute  =>] ATTRIBUTE_DESIGNATOR,
9062          --     [Entity     =>] LOCAL_NAME,
9063          --     [Expression =>] EXPRESSION | NAME);
9064
9065          when Pragma_Attribute_Definition => Attribute_Definition : declare
9066             Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1);
9067             Aname                : Name_Id;
9068
9069          begin
9070             GNAT_Pragma;
9071             Check_Arg_Count (3);
9072             Check_Optional_Identifier (Arg1, "attribute");
9073             Check_Optional_Identifier (Arg2, "entity");
9074             Check_Optional_Identifier (Arg3, "expression");
9075
9076             if Nkind (Attribute_Designator) /= N_Identifier then
9077                Error_Msg_N ("attribute name expected", Attribute_Designator);
9078                return;
9079             end if;
9080
9081             Check_Arg_Is_Local_Name (Arg2);
9082
9083             --  If the attribute is not recognized, then issue a warning (not
9084             --  an error), and ignore the pragma.
9085
9086             Aname := Chars (Attribute_Designator);
9087
9088             if not Is_Attribute_Name (Aname) then
9089                Bad_Attribute (Attribute_Designator, Aname, Warn => True);
9090                return;
9091             end if;
9092
9093             --  Otherwise, rewrite the pragma as an attribute definition clause
9094
9095             Rewrite (N,
9096               Make_Attribute_Definition_Clause (Loc,
9097                 Name       => Get_Pragma_Arg (Arg2),
9098                 Chars      => Aname,
9099                 Expression => Get_Pragma_Arg (Arg3)));
9100             Analyze (N);
9101          end Attribute_Definition;
9102
9103          ---------------
9104          -- AST_Entry --
9105          ---------------
9106
9107          --  pragma AST_Entry (entry_IDENTIFIER);
9108
9109          when Pragma_AST_Entry => AST_Entry : declare
9110             Ent : Node_Id;
9111
9112          begin
9113             GNAT_Pragma;
9114             Check_VMS (N);
9115             Check_Arg_Count (1);
9116             Check_No_Identifiers;
9117             Check_Arg_Is_Local_Name (Arg1);
9118             Ent := Entity (Get_Pragma_Arg (Arg1));
9119
9120             --  Note: the implementation of the AST_Entry pragma could handle
9121             --  the entry family case fine, but for now we are consistent with
9122             --  the DEC rules, and do not allow the pragma, which of course
9123             --  has the effect of also forbidding the attribute.
9124
9125             if Ekind (Ent) /= E_Entry then
9126                Error_Pragma_Arg
9127                  ("pragma% argument must be simple entry name", Arg1);
9128
9129             elsif Is_AST_Entry (Ent) then
9130                Error_Pragma_Arg
9131                  ("duplicate % pragma for entry", Arg1);
9132
9133             elsif Has_Homonym (Ent) then
9134                Error_Pragma_Arg
9135                  ("pragma% argument cannot specify overloaded entry", Arg1);
9136
9137             else
9138                declare
9139                   FF : constant Entity_Id := First_Formal (Ent);
9140
9141                begin
9142                   if Present (FF) then
9143                      if Present (Next_Formal (FF)) then
9144                         Error_Pragma_Arg
9145                           ("entry for pragma% can have only one argument",
9146                            Arg1);
9147
9148                      elsif Parameter_Mode (FF) /= E_In_Parameter then
9149                         Error_Pragma_Arg
9150                           ("entry parameter for pragma% must have mode IN",
9151                            Arg1);
9152                      end if;
9153                   end if;
9154                end;
9155
9156                Set_Is_AST_Entry (Ent);
9157             end if;
9158          end AST_Entry;
9159
9160          ------------------
9161          -- Asynchronous --
9162          ------------------
9163
9164          --  pragma Asynchronous (LOCAL_NAME);
9165
9166          when Pragma_Asynchronous => Asynchronous : declare
9167             Nm     : Entity_Id;
9168             C_Ent  : Entity_Id;
9169             L      : List_Id;
9170             S      : Node_Id;
9171             N      : Node_Id;
9172             Formal : Entity_Id;
9173
9174             procedure Process_Async_Pragma;
9175             --  Common processing for procedure and access-to-procedure case
9176
9177             --------------------------
9178             -- Process_Async_Pragma --
9179             --------------------------
9180
9181             procedure Process_Async_Pragma is
9182             begin
9183                if No (L) then
9184                   Set_Is_Asynchronous (Nm);
9185                   return;
9186                end if;
9187
9188                --  The formals should be of mode IN (RM E.4.1(6))
9189
9190                S := First (L);
9191                while Present (S) loop
9192                   Formal := Defining_Identifier (S);
9193
9194                   if Nkind (Formal) = N_Defining_Identifier
9195                     and then Ekind (Formal) /= E_In_Parameter
9196                   then
9197                      Error_Pragma_Arg
9198                        ("pragma% procedure can only have IN parameter",
9199                         Arg1);
9200                   end if;
9201
9202                   Next (S);
9203                end loop;
9204
9205                Set_Is_Asynchronous (Nm);
9206             end Process_Async_Pragma;
9207
9208          --  Start of processing for pragma Asynchronous
9209
9210          begin
9211             Check_Ada_83_Warning;
9212             Check_No_Identifiers;
9213             Check_Arg_Count (1);
9214             Check_Arg_Is_Local_Name (Arg1);
9215
9216             if Debug_Flag_U then
9217                return;
9218             end if;
9219
9220             C_Ent := Cunit_Entity (Current_Sem_Unit);
9221             Analyze (Get_Pragma_Arg (Arg1));
9222             Nm := Entity (Get_Pragma_Arg (Arg1));
9223
9224             if not Is_Remote_Call_Interface (C_Ent)
9225               and then not Is_Remote_Types (C_Ent)
9226             then
9227                --  This pragma should only appear in an RCI or Remote Types
9228                --  unit (RM E.4.1(4)).
9229
9230                Error_Pragma
9231                  ("pragma% not in Remote_Call_Interface or Remote_Types unit");
9232             end if;
9233
9234             if Ekind (Nm) = E_Procedure
9235               and then Nkind (Parent (Nm)) = N_Procedure_Specification
9236             then
9237                if not Is_Remote_Call_Interface (Nm) then
9238                   Error_Pragma_Arg
9239                     ("pragma% cannot be applied on non-remote procedure",
9240                      Arg1);
9241                end if;
9242
9243                L := Parameter_Specifications (Parent (Nm));
9244                Process_Async_Pragma;
9245                return;
9246
9247             elsif Ekind (Nm) = E_Function then
9248                Error_Pragma_Arg
9249                  ("pragma% cannot be applied to function", Arg1);
9250
9251             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
9252                   if Is_Record_Type (Nm) then
9253
9254                   --  A record type that is the Equivalent_Type for a remote
9255                   --  access-to-subprogram type.
9256
9257                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
9258
9259                   else
9260                      --  A non-expanded RAS type (distribution is not enabled)
9261
9262                      N := Declaration_Node (Nm);
9263                   end if;
9264
9265                if Nkind (N) = N_Full_Type_Declaration
9266                  and then Nkind (Type_Definition (N)) =
9267                                      N_Access_Procedure_Definition
9268                then
9269                   L := Parameter_Specifications (Type_Definition (N));
9270                   Process_Async_Pragma;
9271
9272                   if Is_Asynchronous (Nm)
9273                     and then Expander_Active
9274                     and then Get_PCS_Name /= Name_No_DSA
9275                   then
9276                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
9277                   end if;
9278
9279                else
9280                   Error_Pragma_Arg
9281                     ("pragma% cannot reference access-to-function type",
9282                     Arg1);
9283                end if;
9284
9285             --  Only other possibility is Access-to-class-wide type
9286
9287             elsif Is_Access_Type (Nm)
9288               and then Is_Class_Wide_Type (Designated_Type (Nm))
9289             then
9290                Check_First_Subtype (Arg1);
9291                Set_Is_Asynchronous (Nm);
9292                if Expander_Active then
9293                   RACW_Type_Is_Asynchronous (Nm);
9294                end if;
9295
9296             else
9297                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
9298             end if;
9299          end Asynchronous;
9300
9301          ------------
9302          -- Atomic --
9303          ------------
9304
9305          --  pragma Atomic (LOCAL_NAME);
9306
9307          when Pragma_Atomic =>
9308             Process_Atomic_Shared_Volatile;
9309
9310          -----------------------
9311          -- Atomic_Components --
9312          -----------------------
9313
9314          --  pragma Atomic_Components (array_LOCAL_NAME);
9315
9316          --  This processing is shared by Volatile_Components
9317
9318          when Pragma_Atomic_Components   |
9319               Pragma_Volatile_Components =>
9320
9321          Atomic_Components : declare
9322             E_Id : Node_Id;
9323             E    : Entity_Id;
9324             D    : Node_Id;
9325             K    : Node_Kind;
9326
9327          begin
9328             Check_Ada_83_Warning;
9329             Check_No_Identifiers;
9330             Check_Arg_Count (1);
9331             Check_Arg_Is_Local_Name (Arg1);
9332             E_Id := Get_Pragma_Arg (Arg1);
9333
9334             if Etype (E_Id) = Any_Type then
9335                return;
9336             end if;
9337
9338             E := Entity (E_Id);
9339
9340             Check_Duplicate_Pragma (E);
9341
9342             if Rep_Item_Too_Early (E, N)
9343                  or else
9344                Rep_Item_Too_Late (E, N)
9345             then
9346                return;
9347             end if;
9348
9349             D := Declaration_Node (E);
9350             K := Nkind (D);
9351
9352             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
9353               or else
9354                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9355                    and then Nkind (D) = N_Object_Declaration
9356                    and then Nkind (Object_Definition (D)) =
9357                                        N_Constrained_Array_Definition)
9358             then
9359                --  The flag is set on the object, or on the base type
9360
9361                if Nkind (D) /= N_Object_Declaration then
9362                   E := Base_Type (E);
9363                end if;
9364
9365                Set_Has_Volatile_Components (E);
9366
9367                if Prag_Id = Pragma_Atomic_Components then
9368                   Set_Has_Atomic_Components (E);
9369                end if;
9370
9371             else
9372                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9373             end if;
9374          end Atomic_Components;
9375
9376          --------------------
9377          -- Attach_Handler --
9378          --------------------
9379
9380          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
9381
9382          when Pragma_Attach_Handler =>
9383             Check_Ada_83_Warning;
9384             Check_No_Identifiers;
9385             Check_Arg_Count (2);
9386
9387             if No_Run_Time_Mode then
9388                Error_Msg_CRT ("Attach_Handler pragma", N);
9389             else
9390                Check_Interrupt_Or_Attach_Handler;
9391
9392                --  The expression that designates the attribute may depend on a
9393                --  discriminant, and is therefore a per-object expression, to
9394                --  be expanded in the init proc. If expansion is enabled, then
9395                --  perform semantic checks on a copy only.
9396
9397                if Expander_Active then
9398                   declare
9399                      Temp : constant Node_Id :=
9400                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
9401                   begin
9402                      Set_Parent (Temp, N);
9403                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
9404                   end;
9405
9406                else
9407                   Analyze (Get_Pragma_Arg (Arg2));
9408                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
9409                end if;
9410
9411                Process_Interrupt_Or_Attach_Handler;
9412             end if;
9413
9414          --------------------
9415          -- C_Pass_By_Copy --
9416          --------------------
9417
9418          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
9419
9420          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
9421             Arg : Node_Id;
9422             Val : Uint;
9423
9424          begin
9425             GNAT_Pragma;
9426             Check_Valid_Configuration_Pragma;
9427             Check_Arg_Count (1);
9428             Check_Optional_Identifier (Arg1, "max_size");
9429
9430             Arg := Get_Pragma_Arg (Arg1);
9431             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
9432
9433             Val := Expr_Value (Arg);
9434
9435             if Val <= 0 then
9436                Error_Pragma_Arg
9437                  ("maximum size for pragma% must be positive", Arg1);
9438
9439             elsif UI_Is_In_Int_Range (Val) then
9440                Default_C_Record_Mechanism := UI_To_Int (Val);
9441
9442             --  If a giant value is given, Int'Last will do well enough.
9443             --  If sometime someone complains that a record larger than
9444             --  two gigabytes is not copied, we will worry about it then!
9445
9446             else
9447                Default_C_Record_Mechanism := Mechanism_Type'Last;
9448             end if;
9449          end C_Pass_By_Copy;
9450
9451          -----------
9452          -- Check --
9453          -----------
9454
9455          --  pragma Check ([Name    =>] CHECK_KIND,
9456          --                [Check   =>] Boolean_EXPRESSION
9457          --              [,[Message =>] String_EXPRESSION]);
9458
9459          --  CHECK_KIND ::= IDENTIFIER           |
9460          --                 Pre'Class            |
9461          --                 Post'Class           |
9462          --                 Invariant'Class      |
9463          --                 Type_Invariant'Class
9464
9465          --  The identifiers Assertions and Statement_Assertions are not
9466          --  allowed, since they have special meaning for Check_Policy.
9467
9468          when Pragma_Check => Check : declare
9469             Expr  : Node_Id;
9470             Eloc  : Source_Ptr;
9471             Cname : Name_Id;
9472             Str   : Node_Id;
9473
9474             Check_On : Boolean;
9475             --  Set True if category of assertions referenced by Name enabled
9476
9477          begin
9478             GNAT_Pragma;
9479             Check_At_Least_N_Arguments (2);
9480             Check_At_Most_N_Arguments (3);
9481             Check_Optional_Identifier (Arg1, Name_Name);
9482             Check_Optional_Identifier (Arg2, Name_Check);
9483
9484             if Arg_Count = 3 then
9485                Check_Optional_Identifier (Arg3, Name_Message);
9486                Str := Get_Pragma_Arg (Arg3);
9487             end if;
9488
9489             Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1));
9490             Check_Arg_Is_Identifier (Arg1);
9491             Cname := Chars (Get_Pragma_Arg (Arg1));
9492
9493             --  Check forbidden name Assertions or Statement_Assertions
9494
9495             case Cname is
9496                when Name_Assertions =>
9497                   Error_Pragma_Arg
9498                     ("""Assertions"" is not allowed as a check kind "
9499                      & "for pragma%", Arg1);
9500
9501                when Name_Statement_Assertions =>
9502                   Error_Pragma_Arg
9503                     ("""Statement_Assertions"" is not allowed as a check kind "
9504                      & "for pragma%", Arg1);
9505
9506                when others =>
9507                   null;
9508             end case;
9509
9510             --  Set Check_On to indicate check status
9511
9512             --  If this comes from an aspect, we have already taken care of
9513             --  the policy active when the aspect was analyzed, and Is_Ignored
9514             --  is set appropriately already.
9515
9516             if From_Aspect_Specification (N) then
9517                Check_On := not Is_Ignored (N);
9518
9519             --  Otherwise check the status right now
9520
9521             else
9522                case Check_Kind (Cname) is
9523                   when Name_Ignore =>
9524                      Check_On := False;
9525
9526                   when Name_Check =>
9527                      Check_On := True;
9528
9529                   --  For disable, rewrite pragma as null statement and skip
9530                   --  rest of the analysis of the pragma.
9531
9532                   when Name_Disable =>
9533                      Rewrite (N, Make_Null_Statement (Loc));
9534                      Analyze (N);
9535                      raise Pragma_Exit;
9536
9537                      --  No other possibilities
9538
9539                   when others =>
9540                      raise Program_Error;
9541                end case;
9542             end if;
9543
9544             --  If check kind was not Disable, then continue pragma analysis
9545
9546             Expr := Get_Pragma_Arg (Arg2);
9547
9548             --  Deal with SCO generation
9549
9550             case Cname is
9551                when Name_Predicate |
9552                     Name_Invariant =>
9553
9554                   --  Nothing to do: since checks occur in client units,
9555                   --  the SCO for the aspect in the declaration unit is
9556                   --  conservatively always enabled.
9557
9558                   null;
9559
9560                when others =>
9561
9562                   if Check_On and then not Split_PPC (N) then
9563
9564                      --  Mark pragma/aspect SCO as enabled
9565
9566                      Set_SCO_Pragma_Enabled (Loc);
9567                   end if;
9568             end case;
9569
9570             --  Deal with analyzing the string argument.
9571
9572             if Arg_Count = 3 then
9573
9574                --  If checks are not on we don't want any expansion (since
9575                --  such expansion would not get properly deleted) but
9576                --  we do want to analyze (to get proper references).
9577                --  The Preanalyze_And_Resolve routine does just what we want
9578
9579                if not Check_On then
9580                   Preanalyze_And_Resolve (Str, Standard_String);
9581
9582                   --  Otherwise we need a proper analysis and expansion
9583
9584                else
9585                   Analyze_And_Resolve (Str, Standard_String);
9586                end if;
9587             end if;
9588
9589             --  Now you might think we could just do the same with the Boolean
9590             --  expression if checks are off (and expansion is on) and then
9591             --  rewrite the check as a null statement. This would work but we
9592             --  would lose the useful warnings about an assertion being bound
9593             --  to fail even if assertions are turned off.
9594
9595             --  So instead we wrap the boolean expression in an if statement
9596             --  that looks like:
9597
9598             --    if False and then condition then
9599             --       null;
9600             --    end if;
9601
9602             --  The reason we do this rewriting during semantic analysis
9603             --  rather than as part of normal expansion is that we cannot
9604             --  analyze and expand the code for the boolean expression
9605             --  directly, or it may cause insertion of actions that would
9606             --  escape the attempt to suppress the check code.
9607
9608             --  Note that the Sloc for the if statement corresponds to the
9609             --  argument condition, not the pragma itself. The reason for
9610             --  this is that we may generate a warning if the condition is
9611             --  False at compile time, and we do not want to delete this
9612             --  warning when we delete the if statement.
9613
9614             if Expander_Active and not Check_On then
9615                Eloc := Sloc (Expr);
9616
9617                Rewrite (N,
9618                  Make_If_Statement (Eloc,
9619                    Condition =>
9620                      Make_And_Then (Eloc,
9621                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
9622                        Right_Opnd => Expr),
9623                    Then_Statements => New_List (
9624                      Make_Null_Statement (Eloc))));
9625
9626                In_Assertion_Expr := In_Assertion_Expr + 1;
9627                Analyze (N);
9628                In_Assertion_Expr := In_Assertion_Expr - 1;
9629
9630             --  Check is active or expansion not active. In these cases we can
9631             --  just go ahead and analyze the boolean with no worries.
9632
9633             else
9634                In_Assertion_Expr := In_Assertion_Expr + 1;
9635                Analyze_And_Resolve (Expr, Any_Boolean);
9636                In_Assertion_Expr := In_Assertion_Expr - 1;
9637             end if;
9638          end Check;
9639
9640          --------------------------
9641          -- Check_Float_Overflow --
9642          --------------------------
9643
9644          --  pragma Check_Float_Overflow;
9645
9646          when Pragma_Check_Float_Overflow =>
9647             GNAT_Pragma;
9648             Check_Valid_Configuration_Pragma;
9649             Check_Arg_Count (0);
9650             Check_Float_Overflow := True;
9651
9652          ----------------
9653          -- Check_Name --
9654          ----------------
9655
9656          --  pragma Check_Name (check_IDENTIFIER);
9657
9658          when Pragma_Check_Name =>
9659             GNAT_Pragma;
9660             Check_No_Identifiers;
9661             Check_Valid_Configuration_Pragma;
9662             Check_Arg_Count (1);
9663             Check_Arg_Is_Identifier (Arg1);
9664
9665             declare
9666                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
9667
9668             begin
9669                for J in Check_Names.First .. Check_Names.Last loop
9670                   if Check_Names.Table (J) = Nam then
9671                      return;
9672                   end if;
9673                end loop;
9674
9675                Check_Names.Append (Nam);
9676             end;
9677
9678          ------------------
9679          -- Check_Policy --
9680          ------------------
9681
9682          --  This is the old style syntax, which is still allowed in all modes:
9683
9684          --  pragma Check_Policy ([Name   =>] CHECK_KIND
9685          --                       [Policy =>] POLICY_IDENTIFIER);
9686
9687          --  POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
9688
9689          --  CHECK_KIND ::= IDENTIFIER           |
9690          --                 Pre'Class            |
9691          --                 Post'Class           |
9692          --                 Type_Invariant'Class |
9693          --                 Invariant'Class
9694
9695          --  This is the new style syntax, compatible with Assertion_Policy
9696          --  and also allowed in all modes.
9697
9698          --  Pragma Check_Policy (
9699          --      CHECK_KIND => POLICY_IDENTIFIER
9700          --   {, CHECK_KIND => POLICY_IDENTIFIER});
9701
9702          --  Note: the identifiers Name and Policy are not allowed as
9703          --  Check_Kind values. This avoids ambiguities between the old and
9704          --  new form syntax.
9705
9706          when Pragma_Check_Policy => Check_Policy : declare
9707             Kind : Node_Id;
9708
9709          begin
9710             GNAT_Pragma;
9711             Check_At_Least_N_Arguments (1);
9712
9713             --  A Check_Policy pragma can appear either as a configuration
9714             --  pragma, or in a declarative part or a package spec (see RM
9715             --  11.5(5) for rules for Suppress/Unsuppress which are also
9716             --  followed for Check_Policy).
9717
9718             if not Is_Configuration_Pragma then
9719                Check_Is_In_Decl_Part_Or_Package_Spec;
9720             end if;
9721
9722             --  Figure out if we have the old or new syntax. We have the
9723             --  old syntax if the first argument has no identifier, or the
9724             --  identifier is Name.
9725
9726             if Nkind (Arg1) /= N_Pragma_Argument_Association
9727                or else Nam_In (Chars (Arg1), No_Name, Name_Name)
9728             then
9729                --  Old syntax
9730
9731                Check_Arg_Count (2);
9732                Check_Optional_Identifier (Arg1, Name_Name);
9733                Kind := Get_Pragma_Arg (Arg1);
9734                Rewrite_Assertion_Kind (Kind);
9735                Check_Arg_Is_Identifier (Arg1);
9736
9737                --  Check forbidden check kind
9738
9739                if Nam_In (Chars (Kind), Name_Name, Name_Policy) then
9740                   Error_Msg_Name_2 := Chars (Kind);
9741                      Error_Pragma_Arg
9742                        ("pragma% does not allow% as check name", Arg1);
9743                end if;
9744
9745                --  Check policy
9746
9747                Check_Optional_Identifier (Arg2, Name_Policy);
9748                Check_Arg_Is_One_Of
9749                  (Arg2,
9750                   Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
9751
9752                --  And chain pragma on the Check_Policy_List for search
9753
9754                Set_Next_Pragma (N, Opt.Check_Policy_List);
9755                Opt.Check_Policy_List := N;
9756
9757             --  For the new syntax, what we do is to convert each argument to
9758             --  an old syntax equivalent. We do that because we want to chain
9759             --  old style Check_Policy pragmas for the search (we don't want
9760             --  to have to deal with multiple arguments in the search).
9761
9762             else
9763                declare
9764                   Arg  : Node_Id;
9765                   Argx : Node_Id;
9766                   LocP : Source_Ptr;
9767
9768                begin
9769                   Arg := Arg1;
9770                   while Present (Arg) loop
9771                      LocP := Sloc (Arg);
9772                      Argx := Get_Pragma_Arg (Arg);
9773
9774                      --  Kind must be specified
9775
9776                      if Nkind (Arg) /= N_Pragma_Argument_Association
9777                        or else Chars (Arg) = No_Name
9778                      then
9779                         Error_Pragma_Arg
9780                           ("missing assertion kind for pragma%", Arg);
9781                      end if;
9782
9783                      --  Construct equivalent old form syntax Check_Policy
9784                      --  pragma and insert it to get remaining checks.
9785
9786                      Insert_Action (N,
9787                        Make_Pragma (LocP,
9788                          Chars                        => Name_Check_Policy,
9789                          Pragma_Argument_Associations => New_List (
9790                            Make_Pragma_Argument_Association (LocP,
9791                              Expression =>
9792                                Make_Identifier (LocP, Chars (Arg))),
9793                            Make_Pragma_Argument_Association (Sloc (Argx),
9794                              Expression => Argx))));
9795
9796                      Arg := Next (Arg);
9797                   end loop;
9798
9799                   --  Rewrite original Check_Policy pragma to null, since we
9800                   --  have converted it into a series of old syntax pragmas.
9801
9802                   Rewrite (N, Make_Null_Statement (Loc));
9803                   Analyze (N);
9804                end;
9805             end if;
9806          end Check_Policy;
9807
9808          ---------------------
9809          -- CIL_Constructor --
9810          ---------------------
9811
9812          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
9813
9814          --  Processing for this pragma is shared with Java_Constructor
9815
9816          -------------
9817          -- Comment --
9818          -------------
9819
9820          --  pragma Comment (static_string_EXPRESSION)
9821
9822          --  Processing for pragma Comment shares the circuitry for pragma
9823          --  Ident. The only differences are that Ident enforces a limit of 31
9824          --  characters on its argument, and also enforces limitations on
9825          --  placement for DEC compatibility. Pragma Comment shares neither of
9826          --  these restrictions.
9827
9828          -------------------
9829          -- Common_Object --
9830          -------------------
9831
9832          --  pragma Common_Object (
9833          --        [Internal =>] LOCAL_NAME
9834          --     [, [External =>] EXTERNAL_SYMBOL]
9835          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9836
9837          --  Processing for this pragma is shared with Psect_Object
9838
9839          ------------------------
9840          -- Compile_Time_Error --
9841          ------------------------
9842
9843          --  pragma Compile_Time_Error
9844          --    (boolean_EXPRESSION, static_string_EXPRESSION);
9845
9846          when Pragma_Compile_Time_Error =>
9847             GNAT_Pragma;
9848             Process_Compile_Time_Warning_Or_Error;
9849
9850          --------------------------
9851          -- Compile_Time_Warning --
9852          --------------------------
9853
9854          --  pragma Compile_Time_Warning
9855          --    (boolean_EXPRESSION, static_string_EXPRESSION);
9856
9857          when Pragma_Compile_Time_Warning =>
9858             GNAT_Pragma;
9859             Process_Compile_Time_Warning_Or_Error;
9860
9861          -------------------
9862          -- Compiler_Unit --
9863          -------------------
9864
9865          when Pragma_Compiler_Unit =>
9866             GNAT_Pragma;
9867             Check_Arg_Count (0);
9868             Set_Is_Compiler_Unit (Get_Source_Unit (N));
9869
9870          -----------------------------
9871          -- Complete_Representation --
9872          -----------------------------
9873
9874          --  pragma Complete_Representation;
9875
9876          when Pragma_Complete_Representation =>
9877             GNAT_Pragma;
9878             Check_Arg_Count (0);
9879
9880             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
9881                Error_Pragma
9882                  ("pragma & must appear within record representation clause");
9883             end if;
9884
9885          ----------------------------
9886          -- Complex_Representation --
9887          ----------------------------
9888
9889          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
9890
9891          when Pragma_Complex_Representation => Complex_Representation : declare
9892             E_Id : Entity_Id;
9893             E    : Entity_Id;
9894             Ent  : Entity_Id;
9895
9896          begin
9897             GNAT_Pragma;
9898             Check_Arg_Count (1);
9899             Check_Optional_Identifier (Arg1, Name_Entity);
9900             Check_Arg_Is_Local_Name (Arg1);
9901             E_Id := Get_Pragma_Arg (Arg1);
9902
9903             if Etype (E_Id) = Any_Type then
9904                return;
9905             end if;
9906
9907             E := Entity (E_Id);
9908
9909             if not Is_Record_Type (E) then
9910                Error_Pragma_Arg
9911                  ("argument for pragma% must be record type", Arg1);
9912             end if;
9913
9914             Ent := First_Entity (E);
9915
9916             if No (Ent)
9917               or else No (Next_Entity (Ent))
9918               or else Present (Next_Entity (Next_Entity (Ent)))
9919               or else not Is_Floating_Point_Type (Etype (Ent))
9920               or else Etype (Ent) /= Etype (Next_Entity (Ent))
9921             then
9922                Error_Pragma_Arg
9923                  ("record for pragma% must have two fields of the same "
9924                   & "floating-point type", Arg1);
9925
9926             else
9927                Set_Has_Complex_Representation (Base_Type (E));
9928
9929                --  We need to treat the type has having a non-standard
9930                --  representation, for back-end purposes, even though in
9931                --  general a complex will have the default representation
9932                --  of a record with two real components.
9933
9934                Set_Has_Non_Standard_Rep (Base_Type (E));
9935             end if;
9936          end Complex_Representation;
9937
9938          -------------------------
9939          -- Component_Alignment --
9940          -------------------------
9941
9942          --  pragma Component_Alignment (
9943          --        [Form =>] ALIGNMENT_CHOICE
9944          --     [, [Name =>] type_LOCAL_NAME]);
9945          --
9946          --   ALIGNMENT_CHOICE ::=
9947          --     Component_Size
9948          --   | Component_Size_4
9949          --   | Storage_Unit
9950          --   | Default
9951
9952          when Pragma_Component_Alignment => Component_AlignmentP : declare
9953             Args  : Args_List (1 .. 2);
9954             Names : constant Name_List (1 .. 2) := (
9955                       Name_Form,
9956                       Name_Name);
9957
9958             Form  : Node_Id renames Args (1);
9959             Name  : Node_Id renames Args (2);
9960
9961             Atype : Component_Alignment_Kind;
9962             Typ   : Entity_Id;
9963
9964          begin
9965             GNAT_Pragma;
9966             Gather_Associations (Names, Args);
9967
9968             if No (Form) then
9969                Error_Pragma ("missing Form argument for pragma%");
9970             end if;
9971
9972             Check_Arg_Is_Identifier (Form);
9973
9974             --  Get proper alignment, note that Default = Component_Size on all
9975             --  machines we have so far, and we want to set this value rather
9976             --  than the default value to indicate that it has been explicitly
9977             --  set (and thus will not get overridden by the default component
9978             --  alignment for the current scope)
9979
9980             if Chars (Form) = Name_Component_Size then
9981                Atype := Calign_Component_Size;
9982
9983             elsif Chars (Form) = Name_Component_Size_4 then
9984                Atype := Calign_Component_Size_4;
9985
9986             elsif Chars (Form) = Name_Default then
9987                Atype := Calign_Component_Size;
9988
9989             elsif Chars (Form) = Name_Storage_Unit then
9990                Atype := Calign_Storage_Unit;
9991
9992             else
9993                Error_Pragma_Arg
9994                  ("invalid Form parameter for pragma%", Form);
9995             end if;
9996
9997             --  Case with no name, supplied, affects scope table entry
9998
9999             if No (Name) then
10000                Scope_Stack.Table
10001                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
10002
10003             --  Case of name supplied
10004
10005             else
10006                Check_Arg_Is_Local_Name (Name);
10007                Find_Type (Name);
10008                Typ := Entity (Name);
10009
10010                if Typ = Any_Type
10011                  or else Rep_Item_Too_Early (Typ, N)
10012                then
10013                   return;
10014                else
10015                   Typ := Underlying_Type (Typ);
10016                end if;
10017
10018                if not Is_Record_Type (Typ)
10019                  and then not Is_Array_Type (Typ)
10020                then
10021                   Error_Pragma_Arg
10022                     ("Name parameter of pragma% must identify record or "
10023                      & "array type", Name);
10024                end if;
10025
10026                --  An explicit Component_Alignment pragma overrides an
10027                --  implicit pragma Pack, but not an explicit one.
10028
10029                if not Has_Pragma_Pack (Base_Type (Typ)) then
10030                   Set_Is_Packed (Base_Type (Typ), False);
10031                   Set_Component_Alignment (Base_Type (Typ), Atype);
10032                end if;
10033             end if;
10034          end Component_AlignmentP;
10035
10036          --------------------
10037          -- Contract_Cases --
10038          --------------------
10039
10040          --  pragma Contract_Cases (CONTRACT_CASE_LIST);
10041
10042          --  CONTRACT_CASE_LIST ::= CONTRACT_CASE {, CONTRACT_CASE}
10043
10044          --  CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
10045
10046          --  CASE_GUARD ::= boolean_EXPRESSION | others
10047
10048          --  CONSEQUENCE ::= boolean_EXPRESSION
10049
10050          when Pragma_Contract_Cases => Contract_Cases : declare
10051             Subp_Decl : Node_Id;
10052             Subp_Id   : Entity_Id;
10053
10054          begin
10055             GNAT_Pragma;
10056             Check_Arg_Count (1);
10057
10058             --  Ensure the proper placement of the pragma. Contract_Cases must
10059             --  be associated with a subprogram declaration or a body that acts
10060             --  as a spec.
10061
10062             Subp_Decl := Find_Related_Subprogram (N, Check_Duplicates => True);
10063
10064             if Nkind (Subp_Decl) /= N_Subprogram_Declaration
10065               and then (Nkind (Subp_Decl) /= N_Subprogram_Body
10066                          or else not Acts_As_Spec (Subp_Decl))
10067             then
10068                Pragma_Misplaced;
10069                return;
10070             end if;
10071
10072             Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
10073
10074             --  The pragma is analyzed at the end of the declarative part which
10075             --  contains the related subprogram. Reset the analyzed flag.
10076
10077             Set_Analyzed (N, False);
10078
10079             --  When the aspect/pragma appears on a subprogram body, perform
10080             --  the full analysis now.
10081
10082             if Nkind (Subp_Decl) = N_Subprogram_Body then
10083                Analyze_Contract_Cases_In_Decl_Part (N);
10084
10085             --  When Contract_Cases applies to a subprogram compilation unit,
10086             --  the corresponding pragma is placed after the unit's declaration
10087             --  node and needs to be analyzed immediately.
10088
10089             elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
10090               and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
10091             then
10092                Analyze_Contract_Cases_In_Decl_Part (N);
10093             end if;
10094
10095             --  Chain the pragma on the contract for further processing
10096
10097             Add_Contract_Item (N, Subp_Id);
10098          end Contract_Cases;
10099
10100          ----------------
10101          -- Controlled --
10102          ----------------
10103
10104          --  pragma Controlled (first_subtype_LOCAL_NAME);
10105
10106          when Pragma_Controlled => Controlled : declare
10107             Arg : Node_Id;
10108
10109          begin
10110             Check_No_Identifiers;
10111             Check_Arg_Count (1);
10112             Check_Arg_Is_Local_Name (Arg1);
10113             Arg := Get_Pragma_Arg (Arg1);
10114
10115             if not Is_Entity_Name (Arg)
10116               or else not Is_Access_Type (Entity (Arg))
10117             then
10118                Error_Pragma_Arg ("pragma% requires access type", Arg1);
10119             else
10120                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
10121             end if;
10122          end Controlled;
10123
10124          ----------------
10125          -- Convention --
10126          ----------------
10127
10128          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
10129          --    [Entity =>] LOCAL_NAME);
10130
10131          when Pragma_Convention => Convention : declare
10132             C : Convention_Id;
10133             E : Entity_Id;
10134             pragma Warnings (Off, C);
10135             pragma Warnings (Off, E);
10136          begin
10137             Check_Arg_Order ((Name_Convention, Name_Entity));
10138             Check_Ada_83_Warning;
10139             Check_Arg_Count (2);
10140             Process_Convention (C, E);
10141          end Convention;
10142
10143          ---------------------------
10144          -- Convention_Identifier --
10145          ---------------------------
10146
10147          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
10148          --    [Convention =>] convention_IDENTIFIER);
10149
10150          when Pragma_Convention_Identifier => Convention_Identifier : declare
10151             Idnam : Name_Id;
10152             Cname : Name_Id;
10153
10154          begin
10155             GNAT_Pragma;
10156             Check_Arg_Order ((Name_Name, Name_Convention));
10157             Check_Arg_Count (2);
10158             Check_Optional_Identifier (Arg1, Name_Name);
10159             Check_Optional_Identifier (Arg2, Name_Convention);
10160             Check_Arg_Is_Identifier (Arg1);
10161             Check_Arg_Is_Identifier (Arg2);
10162             Idnam := Chars (Get_Pragma_Arg (Arg1));
10163             Cname := Chars (Get_Pragma_Arg (Arg2));
10164
10165             if Is_Convention_Name (Cname) then
10166                Record_Convention_Identifier
10167                  (Idnam, Get_Convention_Id (Cname));
10168             else
10169                Error_Pragma_Arg
10170                  ("second arg for % pragma must be convention", Arg2);
10171             end if;
10172          end Convention_Identifier;
10173
10174          ---------------
10175          -- CPP_Class --
10176          ---------------
10177
10178          --  pragma CPP_Class ([Entity =>] local_NAME)
10179
10180          when Pragma_CPP_Class => CPP_Class : declare
10181          begin
10182             GNAT_Pragma;
10183
10184             if Warn_On_Obsolescent_Feature then
10185                Error_Msg_N
10186                  ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
10187                   & "effect; replace it by pragma import?j?", N);
10188             end if;
10189
10190             Check_Arg_Count (1);
10191
10192             Rewrite (N,
10193               Make_Pragma (Loc,
10194                 Chars                        => Name_Import,
10195                 Pragma_Argument_Associations => New_List (
10196                   Make_Pragma_Argument_Association (Loc,
10197                     Expression => Make_Identifier (Loc, Name_CPP)),
10198                   New_Copy (First (Pragma_Argument_Associations (N))))));
10199             Analyze (N);
10200          end CPP_Class;
10201
10202          ---------------------
10203          -- CPP_Constructor --
10204          ---------------------
10205
10206          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
10207          --    [, [External_Name =>] static_string_EXPRESSION ]
10208          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
10209
10210          when Pragma_CPP_Constructor => CPP_Constructor : declare
10211             Elmt    : Elmt_Id;
10212             Id      : Entity_Id;
10213             Def_Id  : Entity_Id;
10214             Tag_Typ : Entity_Id;
10215
10216          begin
10217             GNAT_Pragma;
10218             Check_At_Least_N_Arguments (1);
10219             Check_At_Most_N_Arguments (3);
10220             Check_Optional_Identifier (Arg1, Name_Entity);
10221             Check_Arg_Is_Local_Name (Arg1);
10222
10223             Id := Get_Pragma_Arg (Arg1);
10224             Find_Program_Unit_Name (Id);
10225
10226             --  If we did not find the name, we are done
10227
10228             if Etype (Id) = Any_Type then
10229                return;
10230             end if;
10231
10232             Def_Id := Entity (Id);
10233
10234             --  Check if already defined as constructor
10235
10236             if Is_Constructor (Def_Id) then
10237                Error_Msg_N
10238                  ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1);
10239                return;
10240             end if;
10241
10242             if Ekind (Def_Id) = E_Function
10243               and then (Is_CPP_Class (Etype (Def_Id))
10244                          or else (Is_Class_Wide_Type (Etype (Def_Id))
10245                                    and then
10246                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
10247             then
10248                if Scope (Def_Id) /= Scope (Etype (Def_Id)) then
10249                   Error_Msg_N
10250                     ("'C'P'P constructor must be defined in the scope of "
10251                      & "its returned type", Arg1);
10252                end if;
10253
10254                if Arg_Count >= 2 then
10255                   Set_Imported (Def_Id);
10256                   Set_Is_Public (Def_Id);
10257                   Process_Interface_Name (Def_Id, Arg2, Arg3);
10258                end if;
10259
10260                Set_Has_Completion (Def_Id);
10261                Set_Is_Constructor (Def_Id);
10262                Set_Convention (Def_Id, Convention_CPP);
10263
10264                --  Imported C++ constructors are not dispatching primitives
10265                --  because in C++ they don't have a dispatch table slot.
10266                --  However, in Ada the constructor has the profile of a
10267                --  function that returns a tagged type and therefore it has
10268                --  been treated as a primitive operation during semantic
10269                --  analysis. We now remove it from the list of primitive
10270                --  operations of the type.
10271
10272                if Is_Tagged_Type (Etype (Def_Id))
10273                  and then not Is_Class_Wide_Type (Etype (Def_Id))
10274                  and then Is_Dispatching_Operation (Def_Id)
10275                then
10276                   Tag_Typ := Etype (Def_Id);
10277
10278                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
10279                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
10280                      Next_Elmt (Elmt);
10281                   end loop;
10282
10283                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
10284                   Set_Is_Dispatching_Operation (Def_Id, False);
10285                end if;
10286
10287                --  For backward compatibility, if the constructor returns a
10288                --  class wide type, and we internally change the return type to
10289                --  the corresponding root type.
10290
10291                if Is_Class_Wide_Type (Etype (Def_Id)) then
10292                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
10293                end if;
10294             else
10295                Error_Pragma_Arg
10296                  ("pragma% requires function returning a 'C'P'P_Class type",
10297                    Arg1);
10298             end if;
10299          end CPP_Constructor;
10300
10301          -----------------
10302          -- CPP_Virtual --
10303          -----------------
10304
10305          when Pragma_CPP_Virtual => CPP_Virtual : declare
10306          begin
10307             GNAT_Pragma;
10308
10309             if Warn_On_Obsolescent_Feature then
10310                Error_Msg_N
10311                  ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
10312                   & "effect?j?", N);
10313             end if;
10314          end CPP_Virtual;
10315
10316          ----------------
10317          -- CPP_Vtable --
10318          ----------------
10319
10320          when Pragma_CPP_Vtable => CPP_Vtable : declare
10321          begin
10322             GNAT_Pragma;
10323
10324             if Warn_On_Obsolescent_Feature then
10325                Error_Msg_N
10326                  ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
10327                   & "effect?j?", N);
10328             end if;
10329          end CPP_Vtable;
10330
10331          ---------
10332          -- CPU --
10333          ---------
10334
10335          --  pragma CPU (EXPRESSION);
10336
10337          when Pragma_CPU => CPU : declare
10338             P   : constant Node_Id := Parent (N);
10339             Arg : Node_Id;
10340             Ent : Entity_Id;
10341
10342          begin
10343             Ada_2012_Pragma;
10344             Check_No_Identifiers;
10345             Check_Arg_Count (1);
10346
10347             --  Subprogram case
10348
10349             if Nkind (P) = N_Subprogram_Body then
10350                Check_In_Main_Program;
10351
10352                Arg := Get_Pragma_Arg (Arg1);
10353                Analyze_And_Resolve (Arg, Any_Integer);
10354
10355                Ent := Defining_Unit_Name (Specification (P));
10356
10357                if Nkind (Ent) = N_Defining_Program_Unit_Name then
10358                   Ent := Defining_Identifier (Ent);
10359                end if;
10360
10361                --  Must be static
10362
10363                if not Is_Static_Expression (Arg) then
10364                   Flag_Non_Static_Expr
10365                     ("main subprogram affinity is not static!", Arg);
10366                   raise Pragma_Exit;
10367
10368                --  If constraint error, then we already signalled an error
10369
10370                elsif Raises_Constraint_Error (Arg) then
10371                   null;
10372
10373                --  Otherwise check in range
10374
10375                else
10376                   declare
10377                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
10378                      --  This is the entity System.Multiprocessors.CPU_Range;
10379
10380                      Val : constant Uint := Expr_Value (Arg);
10381
10382                   begin
10383                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
10384                           or else
10385                         Val > Expr_Value (Type_High_Bound (CPU_Id))
10386                      then
10387                         Error_Pragma_Arg
10388                           ("main subprogram CPU is out of range", Arg1);
10389                      end if;
10390                   end;
10391                end if;
10392
10393                Set_Main_CPU
10394                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
10395
10396             --  Task case
10397
10398             elsif Nkind (P) = N_Task_Definition then
10399                Arg := Get_Pragma_Arg (Arg1);
10400                Ent := Defining_Identifier (Parent (P));
10401
10402                --  The expression must be analyzed in the special manner
10403                --  described in "Handling of Default and Per-Object
10404                --  Expressions" in sem.ads.
10405
10406                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
10407
10408             --  Anything else is incorrect
10409
10410             else
10411                Pragma_Misplaced;
10412             end if;
10413
10414             --  Check duplicate pragma before we chain the pragma in the Rep
10415             --  Item chain of Ent.
10416
10417             Check_Duplicate_Pragma (Ent);
10418             Record_Rep_Item (Ent, N);
10419          end CPU;
10420
10421          -----------
10422          -- Debug --
10423          -----------
10424
10425          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
10426
10427          when Pragma_Debug => Debug : declare
10428             Cond : Node_Id;
10429             Call : Node_Id;
10430
10431          begin
10432             GNAT_Pragma;
10433
10434             --  The condition for executing the call is that the expander
10435             --  is active and that we are not ignoring this debug pragma.
10436
10437             Cond :=
10438               New_Occurrence_Of
10439                 (Boolean_Literals
10440                   (Expander_Active and then not Is_Ignored (N)),
10441                  Loc);
10442
10443             if not Is_Ignored (N) then
10444                Set_SCO_Pragma_Enabled (Loc);
10445             end if;
10446
10447             if Arg_Count = 2 then
10448                Cond :=
10449                  Make_And_Then (Loc,
10450                    Left_Opnd  => Relocate_Node (Cond),
10451                    Right_Opnd => Get_Pragma_Arg (Arg1));
10452                Call := Get_Pragma_Arg (Arg2);
10453             else
10454                Call := Get_Pragma_Arg (Arg1);
10455             end if;
10456
10457             if Nkind_In (Call,
10458                  N_Indexed_Component,
10459                  N_Function_Call,
10460                  N_Identifier,
10461                  N_Expanded_Name,
10462                  N_Selected_Component)
10463             then
10464                --  If this pragma Debug comes from source, its argument was
10465                --  parsed as a name form (which is syntactically identical).
10466                --  In a generic context a parameterless call will be left as
10467                --  an expanded name (if global) or selected_component if local.
10468                --  Change it to a procedure call statement now.
10469
10470                Change_Name_To_Procedure_Call_Statement (Call);
10471
10472             elsif Nkind (Call) = N_Procedure_Call_Statement then
10473
10474                --  Already in the form of a procedure call statement: nothing
10475                --  to do (could happen in case of an internally generated
10476                --  pragma Debug).
10477
10478                null;
10479
10480             else
10481                --  All other cases: diagnose error
10482
10483                Error_Msg
10484                  ("argument of pragma ""Debug"" is not procedure call",
10485                   Sloc (Call));
10486                return;
10487             end if;
10488
10489             --  Rewrite into a conditional with an appropriate condition. We
10490             --  wrap the procedure call in a block so that overhead from e.g.
10491             --  use of the secondary stack does not generate execution overhead
10492             --  for suppressed conditions.
10493
10494             --  Normally the analysis that follows will freeze the subprogram
10495             --  being called. However, if the call is to a null procedure,
10496             --  we want to freeze it before creating the block, because the
10497             --  analysis that follows may be done with expansion disabled, in
10498             --  which case the body will not be generated, leading to spurious
10499             --  errors.
10500
10501             if Nkind (Call) = N_Procedure_Call_Statement
10502               and then Is_Entity_Name (Name (Call))
10503             then
10504                Analyze (Name (Call));
10505                Freeze_Before (N, Entity (Name (Call)));
10506             end if;
10507
10508             Rewrite (N, Make_Implicit_If_Statement (N,
10509               Condition => Cond,
10510                  Then_Statements => New_List (
10511                    Make_Block_Statement (Loc,
10512                      Handled_Statement_Sequence =>
10513                        Make_Handled_Sequence_Of_Statements (Loc,
10514                          Statements => New_List (Relocate_Node (Call)))))));
10515             Analyze (N);
10516          end Debug;
10517
10518          ------------------
10519          -- Debug_Policy --
10520          ------------------
10521
10522          --  pragma Debug_Policy (On | Off | Check | Disable | Ignore)
10523
10524          when Pragma_Debug_Policy =>
10525             GNAT_Pragma;
10526             Check_Arg_Count (1);
10527             Check_No_Identifiers;
10528             Check_Arg_Is_Identifier (Arg1);
10529
10530             --  Exactly equivalent to pragma Check_Policy (Debug, arg), so
10531             --  rewrite it that way, and let the rest of the checking come
10532             --  from analyzing the rewritten pragma.
10533
10534             Rewrite (N,
10535               Make_Pragma (Loc,
10536                 Chars                        => Name_Check_Policy,
10537                 Pragma_Argument_Associations => New_List (
10538                   Make_Pragma_Argument_Association (Loc,
10539                     Expression => Make_Identifier (Loc, Name_Debug)),
10540
10541                   Make_Pragma_Argument_Association (Loc,
10542                     Expression => Get_Pragma_Arg (Arg1)))));
10543             Analyze (N);
10544
10545          -------------
10546          -- Depends --
10547          -------------
10548
10549          --  pragma Depends (DEPENDENCY_RELATION);
10550
10551          --  DEPENDENCY_RELATION ::=
10552          --    null
10553          --  | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
10554
10555          --  DEPENDENCY_CLAUSE ::=
10556          --    OUTPUT_LIST =>[+] INPUT_LIST
10557          --  | NULL_DEPENDENCY_CLAUSE
10558
10559          --  NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
10560
10561          --  OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
10562
10563          --  INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
10564
10565          --  OUTPUT ::= NAME | FUNCTION_RESULT
10566          --  INPUT  ::= NAME
10567
10568          --  where FUNCTION_RESULT is a function Result attribute_reference
10569
10570          when Pragma_Depends => Depends : declare
10571             Subp_Decl : Node_Id;
10572             Subp_Id   : Entity_Id;
10573
10574          begin
10575             GNAT_Pragma;
10576             S14_Pragma;
10577             Check_Arg_Count (1);
10578
10579             --  Ensure the proper placement of the pragma. Depends must be
10580             --  associated with a subprogram declaration or a body that acts
10581             --  as a spec.
10582
10583             Subp_Decl := Find_Related_Subprogram (N, Check_Duplicates => True);
10584
10585             if Nkind (Subp_Decl) /= N_Subprogram_Declaration
10586               and then (Nkind (Subp_Decl) /= N_Subprogram_Body
10587                           or else not Acts_As_Spec (Subp_Decl))
10588             then
10589                Pragma_Misplaced;
10590                return;
10591             end if;
10592
10593             Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
10594
10595             --  When the aspect/pragma appears on a subprogram body, perform
10596             --  the full analysis now.
10597
10598             if Nkind (Subp_Decl) = N_Subprogram_Body then
10599                Analyze_Depends_In_Decl_Part (N);
10600
10601             --  When Depends applies to a subprogram compilation unit, the
10602             --  corresponding pragma is placed after the unit's declaration
10603             --  node and needs to be analyzed immediately.
10604
10605             elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
10606               and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
10607             then
10608                Analyze_Depends_In_Decl_Part (N);
10609             end if;
10610
10611             --  Chain the pragma on the contract for further processing
10612
10613             Add_Contract_Item (N, Subp_Id);
10614          end Depends;
10615
10616          ---------------------
10617          -- Detect_Blocking --
10618          ---------------------
10619
10620          --  pragma Detect_Blocking;
10621
10622          when Pragma_Detect_Blocking =>
10623             Ada_2005_Pragma;
10624             Check_Arg_Count (0);
10625             Check_Valid_Configuration_Pragma;
10626             Detect_Blocking := True;
10627
10628          --------------------------
10629          -- Default_Storage_Pool --
10630          --------------------------
10631
10632          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
10633
10634          when Pragma_Default_Storage_Pool =>
10635             Ada_2012_Pragma;
10636             Check_Arg_Count (1);
10637
10638             --  Default_Storage_Pool can appear as a configuration pragma, or
10639             --  in a declarative part or a package spec.
10640
10641             if not Is_Configuration_Pragma then
10642                Check_Is_In_Decl_Part_Or_Package_Spec;
10643             end if;
10644
10645             --  Case of Default_Storage_Pool (null);
10646
10647             if Nkind (Expression (Arg1)) = N_Null then
10648                Analyze (Expression (Arg1));
10649
10650                --  This is an odd case, this is not really an expression, so
10651                --  we don't have a type for it. So just set the type to Empty.
10652
10653                Set_Etype (Expression (Arg1), Empty);
10654
10655             --  Case of Default_Storage_Pool (storage_pool_NAME);
10656
10657             else
10658                --  If it's a configuration pragma, then the only allowed
10659                --  argument is "null".
10660
10661                if Is_Configuration_Pragma then
10662                   Error_Pragma_Arg ("NULL expected", Arg1);
10663                end if;
10664
10665                --  The expected type for a non-"null" argument is
10666                --  Root_Storage_Pool'Class.
10667
10668                Analyze_And_Resolve
10669                  (Get_Pragma_Arg (Arg1),
10670                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
10671             end if;
10672
10673             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
10674             --  for an access type will use this information to set the
10675             --  appropriate attributes of the access type.
10676
10677             Default_Pool := Expression (Arg1);
10678
10679          ------------------------------------
10680          -- Disable_Atomic_Synchronization --
10681          ------------------------------------
10682
10683          --  pragma Disable_Atomic_Synchronization [(Entity)];
10684
10685          when Pragma_Disable_Atomic_Synchronization =>
10686             GNAT_Pragma;
10687             Process_Disable_Enable_Atomic_Sync (Name_Suppress);
10688
10689          -------------------
10690          -- Discard_Names --
10691          -------------------
10692
10693          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
10694
10695          when Pragma_Discard_Names => Discard_Names : declare
10696             E    : Entity_Id;
10697             E_Id : Entity_Id;
10698
10699          begin
10700             Check_Ada_83_Warning;
10701
10702             --  Deal with configuration pragma case
10703
10704             if Arg_Count = 0 and then Is_Configuration_Pragma then
10705                Global_Discard_Names := True;
10706                return;
10707
10708             --  Otherwise, check correct appropriate context
10709
10710             else
10711                Check_Is_In_Decl_Part_Or_Package_Spec;
10712
10713                if Arg_Count = 0 then
10714
10715                   --  If there is no parameter, then from now on this pragma
10716                   --  applies to any enumeration, exception or tagged type
10717                   --  defined in the current declarative part, and recursively
10718                   --  to any nested scope.
10719
10720                   Set_Discard_Names (Current_Scope);
10721                   return;
10722
10723                else
10724                   Check_Arg_Count (1);
10725                   Check_Optional_Identifier (Arg1, Name_On);
10726                   Check_Arg_Is_Local_Name (Arg1);
10727
10728                   E_Id := Get_Pragma_Arg (Arg1);
10729
10730                   if Etype (E_Id) = Any_Type then
10731                      return;
10732                   else
10733                      E := Entity (E_Id);
10734                   end if;
10735
10736                   if (Is_First_Subtype (E)
10737                       and then
10738                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
10739                     or else Ekind (E) = E_Exception
10740                   then
10741                      Set_Discard_Names (E);
10742                      Record_Rep_Item (E, N);
10743
10744                   else
10745                      Error_Pragma_Arg
10746                        ("inappropriate entity for pragma%", Arg1);
10747                   end if;
10748
10749                end if;
10750             end if;
10751          end Discard_Names;
10752
10753          ------------------------
10754          -- Dispatching_Domain --
10755          ------------------------
10756
10757          --  pragma Dispatching_Domain (EXPRESSION);
10758
10759          when Pragma_Dispatching_Domain => Dispatching_Domain : declare
10760             P   : constant Node_Id := Parent (N);
10761             Arg : Node_Id;
10762             Ent : Entity_Id;
10763
10764          begin
10765             Ada_2012_Pragma;
10766             Check_No_Identifiers;
10767             Check_Arg_Count (1);
10768
10769             --  This pragma is born obsolete, but not the aspect
10770
10771             if not From_Aspect_Specification (N) then
10772                Check_Restriction
10773                  (No_Obsolescent_Features, Pragma_Identifier (N));
10774             end if;
10775
10776             if Nkind (P) = N_Task_Definition then
10777                Arg := Get_Pragma_Arg (Arg1);
10778                Ent := Defining_Identifier (Parent (P));
10779
10780                --  The expression must be analyzed in the special manner
10781                --  described in "Handling of Default and Per-Object
10782                --  Expressions" in sem.ads.
10783
10784                Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain));
10785
10786                --  Check duplicate pragma before we chain the pragma in the Rep
10787                --  Item chain of Ent.
10788
10789                Check_Duplicate_Pragma (Ent);
10790                Record_Rep_Item (Ent, N);
10791
10792             --  Anything else is incorrect
10793
10794             else
10795                Pragma_Misplaced;
10796             end if;
10797          end Dispatching_Domain;
10798
10799          ---------------
10800          -- Elaborate --
10801          ---------------
10802
10803          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
10804
10805          when Pragma_Elaborate => Elaborate : declare
10806             Arg   : Node_Id;
10807             Citem : Node_Id;
10808
10809          begin
10810             --  Pragma must be in context items list of a compilation unit
10811
10812             if not Is_In_Context_Clause then
10813                Pragma_Misplaced;
10814             end if;
10815
10816             --  Must be at least one argument
10817
10818             if Arg_Count = 0 then
10819                Error_Pragma ("pragma% requires at least one argument");
10820             end if;
10821
10822             --  In Ada 83 mode, there can be no items following it in the
10823             --  context list except other pragmas and implicit with clauses
10824             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
10825             --  placement rule does not apply.
10826
10827             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
10828                Citem := Next (N);
10829                while Present (Citem) loop
10830                   if Nkind (Citem) = N_Pragma
10831                     or else (Nkind (Citem) = N_With_Clause
10832                               and then Implicit_With (Citem))
10833                   then
10834                      null;
10835                   else
10836                      Error_Pragma
10837                        ("(Ada 83) pragma% must be at end of context clause");
10838                   end if;
10839
10840                   Next (Citem);
10841                end loop;
10842             end if;
10843
10844             --  Finally, the arguments must all be units mentioned in a with
10845             --  clause in the same context clause. Note we already checked (in
10846             --  Par.Prag) that the arguments are all identifiers or selected
10847             --  components.
10848
10849             Arg := Arg1;
10850             Outer : while Present (Arg) loop
10851                Citem := First (List_Containing (N));
10852                Inner : while Citem /= N loop
10853                   if Nkind (Citem) = N_With_Clause
10854                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10855                   then
10856                      Set_Elaborate_Present (Citem, True);
10857                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10858                      Generate_Reference (Entity (Name (Citem)), Citem);
10859
10860                      --  With the pragma present, elaboration calls on
10861                      --  subprograms from the named unit need no further
10862                      --  checks, as long as the pragma appears in the current
10863                      --  compilation unit. If the pragma appears in some unit
10864                      --  in the context, there might still be a need for an
10865                      --  Elaborate_All_Desirable from the current compilation
10866                      --  to the named unit, so we keep the check enabled.
10867
10868                      if In_Extended_Main_Source_Unit (N) then
10869                         Set_Suppress_Elaboration_Warnings
10870                           (Entity (Name (Citem)));
10871                      end if;
10872
10873                      exit Inner;
10874                   end if;
10875
10876                   Next (Citem);
10877                end loop Inner;
10878
10879                if Citem = N then
10880                   Error_Pragma_Arg
10881                     ("argument of pragma% is not withed unit", Arg);
10882                end if;
10883
10884                Next (Arg);
10885             end loop Outer;
10886
10887             --  Give a warning if operating in static mode with -gnatwl
10888             --  (elaboration warnings enabled) switch set.
10889
10890             if Elab_Warnings and not Dynamic_Elaboration_Checks then
10891                Error_Msg_N
10892                  ("?l?use of pragma Elaborate may not be safe", N);
10893                Error_Msg_N
10894                  ("?l?use pragma Elaborate_All instead if possible", N);
10895             end if;
10896          end Elaborate;
10897
10898          -------------------
10899          -- Elaborate_All --
10900          -------------------
10901
10902          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
10903
10904          when Pragma_Elaborate_All => Elaborate_All : declare
10905             Arg   : Node_Id;
10906             Citem : Node_Id;
10907
10908          begin
10909             Check_Ada_83_Warning;
10910
10911             --  Pragma must be in context items list of a compilation unit
10912
10913             if not Is_In_Context_Clause then
10914                Pragma_Misplaced;
10915             end if;
10916
10917             --  Must be at least one argument
10918
10919             if Arg_Count = 0 then
10920                Error_Pragma ("pragma% requires at least one argument");
10921             end if;
10922
10923             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
10924             --  have to appear at the end of the context clause, but may
10925             --  appear mixed in with other items, even in Ada 83 mode.
10926
10927             --  Final check: the arguments must all be units mentioned in
10928             --  a with clause in the same context clause. Note that we
10929             --  already checked (in Par.Prag) that all the arguments are
10930             --  either identifiers or selected components.
10931
10932             Arg := Arg1;
10933             Outr : while Present (Arg) loop
10934                Citem := First (List_Containing (N));
10935                Innr : while Citem /= N loop
10936                   if Nkind (Citem) = N_With_Clause
10937                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
10938                   then
10939                      Set_Elaborate_All_Present (Citem, True);
10940                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
10941
10942                      --  Suppress warnings and elaboration checks on the named
10943                      --  unit if the pragma is in the current compilation, as
10944                      --  for pragma Elaborate.
10945
10946                      if In_Extended_Main_Source_Unit (N) then
10947                         Set_Suppress_Elaboration_Warnings
10948                           (Entity (Name (Citem)));
10949                      end if;
10950                      exit Innr;
10951                   end if;
10952
10953                   Next (Citem);
10954                end loop Innr;
10955
10956                if Citem = N then
10957                   Set_Error_Posted (N);
10958                   Error_Pragma_Arg
10959                     ("argument of pragma% is not withed unit", Arg);
10960                end if;
10961
10962                Next (Arg);
10963             end loop Outr;
10964          end Elaborate_All;
10965
10966          --------------------
10967          -- Elaborate_Body --
10968          --------------------
10969
10970          --  pragma Elaborate_Body [( library_unit_NAME )];
10971
10972          when Pragma_Elaborate_Body => Elaborate_Body : declare
10973             Cunit_Node : Node_Id;
10974             Cunit_Ent  : Entity_Id;
10975
10976          begin
10977             Check_Ada_83_Warning;
10978             Check_Valid_Library_Unit_Pragma;
10979
10980             if Nkind (N) = N_Null_Statement then
10981                return;
10982             end if;
10983
10984             Cunit_Node := Cunit (Current_Sem_Unit);
10985             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
10986
10987             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
10988                                             N_Subprogram_Body)
10989             then
10990                Error_Pragma ("pragma% must refer to a spec, not a body");
10991             else
10992                Set_Body_Required (Cunit_Node, True);
10993                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
10994
10995                --  If we are in dynamic elaboration mode, then we suppress
10996                --  elaboration warnings for the unit, since it is definitely
10997                --  fine NOT to do dynamic checks at the first level (and such
10998                --  checks will be suppressed because no elaboration boolean
10999                --  is created for Elaborate_Body packages).
11000
11001                --  But in the static model of elaboration, Elaborate_Body is
11002                --  definitely NOT good enough to ensure elaboration safety on
11003                --  its own, since the body may WITH other units that are not
11004                --  safe from an elaboration point of view, so a client must
11005                --  still do an Elaborate_All on such units.
11006
11007                --  Debug flag -gnatdD restores the old behavior of 3.13, where
11008                --  Elaborate_Body always suppressed elab warnings.
11009
11010                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
11011                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
11012                end if;
11013             end if;
11014          end Elaborate_Body;
11015
11016          ------------------------
11017          -- Elaboration_Checks --
11018          ------------------------
11019
11020          --  pragma Elaboration_Checks (Static | Dynamic);
11021
11022          when Pragma_Elaboration_Checks =>
11023             GNAT_Pragma;
11024             Check_Arg_Count (1);
11025             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
11026             Dynamic_Elaboration_Checks :=
11027               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
11028
11029          ---------------
11030          -- Eliminate --
11031          ---------------
11032
11033          --  pragma Eliminate (
11034          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
11035          --    [,[Entity     =>] IDENTIFIER |
11036          --                      SELECTED_COMPONENT |
11037          --                      STRING_LITERAL]
11038          --    [,                OVERLOADING_RESOLUTION]);
11039
11040          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
11041          --                             SOURCE_LOCATION
11042
11043          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
11044          --                                        FUNCTION_PROFILE
11045
11046          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
11047
11048          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
11049          --                       Result_Type => result_SUBTYPE_NAME]
11050
11051          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
11052          --  SUBTYPE_NAME    ::= STRING_LITERAL
11053
11054          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
11055          --  SOURCE_TRACE    ::= STRING_LITERAL
11056
11057          when Pragma_Eliminate => Eliminate : declare
11058             Args  : Args_List (1 .. 5);
11059             Names : constant Name_List (1 .. 5) := (
11060                       Name_Unit_Name,
11061                       Name_Entity,
11062                       Name_Parameter_Types,
11063                       Name_Result_Type,
11064                       Name_Source_Location);
11065
11066             Unit_Name       : Node_Id renames Args (1);
11067             Entity          : Node_Id renames Args (2);
11068             Parameter_Types : Node_Id renames Args (3);
11069             Result_Type     : Node_Id renames Args (4);
11070             Source_Location : Node_Id renames Args (5);
11071
11072          begin
11073             GNAT_Pragma;
11074             Check_Valid_Configuration_Pragma;
11075             Gather_Associations (Names, Args);
11076
11077             if No (Unit_Name) then
11078                Error_Pragma ("missing Unit_Name argument for pragma%");
11079             end if;
11080
11081             if No (Entity)
11082               and then (Present (Parameter_Types)
11083                           or else
11084                         Present (Result_Type)
11085                           or else
11086                         Present (Source_Location))
11087             then
11088                Error_Pragma ("missing Entity argument for pragma%");
11089             end if;
11090
11091             if (Present (Parameter_Types)
11092                   or else
11093                 Present (Result_Type))
11094               and then
11095                 Present (Source_Location)
11096             then
11097                Error_Pragma
11098                  ("parameter profile and source location cannot be used "
11099                   & "together in pragma%");
11100             end if;
11101
11102             Process_Eliminate_Pragma
11103               (N,
11104                Unit_Name,
11105                Entity,
11106                Parameter_Types,
11107                Result_Type,
11108                Source_Location);
11109          end Eliminate;
11110
11111          -----------------------------------
11112          -- Enable_Atomic_Synchronization --
11113          -----------------------------------
11114
11115          --  pragma Enable_Atomic_Synchronization [(Entity)];
11116
11117          when Pragma_Enable_Atomic_Synchronization =>
11118             GNAT_Pragma;
11119             Process_Disable_Enable_Atomic_Sync (Name_Unsuppress);
11120
11121          ------------
11122          -- Export --
11123          ------------
11124
11125          --  pragma Export (
11126          --    [   Convention    =>] convention_IDENTIFIER,
11127          --    [   Entity        =>] local_NAME
11128          --    [, [External_Name =>] static_string_EXPRESSION ]
11129          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
11130
11131          when Pragma_Export => Export : declare
11132             C      : Convention_Id;
11133             Def_Id : Entity_Id;
11134
11135             pragma Warnings (Off, C);
11136
11137          begin
11138             Check_Ada_83_Warning;
11139             Check_Arg_Order
11140               ((Name_Convention,
11141                 Name_Entity,
11142                 Name_External_Name,
11143                 Name_Link_Name));
11144
11145             Check_At_Least_N_Arguments (2);
11146
11147             Check_At_Most_N_Arguments  (4);
11148             Process_Convention (C, Def_Id);
11149
11150             if Ekind (Def_Id) /= E_Constant then
11151                Note_Possible_Modification
11152                  (Get_Pragma_Arg (Arg2), Sure => False);
11153             end if;
11154
11155             Process_Interface_Name (Def_Id, Arg3, Arg4);
11156             Set_Exported (Def_Id, Arg2);
11157
11158             --  If the entity is a deferred constant, propagate the information
11159             --  to the full view, because gigi elaborates the full view only.
11160
11161             if Ekind (Def_Id) = E_Constant
11162               and then Present (Full_View (Def_Id))
11163             then
11164                declare
11165                   Id2 : constant Entity_Id := Full_View (Def_Id);
11166                begin
11167                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
11168                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
11169                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
11170                end;
11171             end if;
11172          end Export;
11173
11174          ----------------------
11175          -- Export_Exception --
11176          ----------------------
11177
11178          --  pragma Export_Exception (
11179          --        [Internal         =>] LOCAL_NAME
11180          --     [, [External         =>] EXTERNAL_SYMBOL]
11181          --     [, [Form     =>] Ada | VMS]
11182          --     [, [Code     =>] static_integer_EXPRESSION]);
11183
11184          when Pragma_Export_Exception => Export_Exception : declare
11185             Args  : Args_List (1 .. 4);
11186             Names : constant Name_List (1 .. 4) := (
11187                       Name_Internal,
11188                       Name_External,
11189                       Name_Form,
11190                       Name_Code);
11191
11192             Internal : Node_Id renames Args (1);
11193             External : Node_Id renames Args (2);
11194             Form     : Node_Id renames Args (3);
11195             Code     : Node_Id renames Args (4);
11196
11197          begin
11198             GNAT_Pragma;
11199
11200             if Inside_A_Generic then
11201                Error_Pragma ("pragma% cannot be used for generic entities");
11202             end if;
11203
11204             Gather_Associations (Names, Args);
11205             Process_Extended_Import_Export_Exception_Pragma (
11206               Arg_Internal => Internal,
11207               Arg_External => External,
11208               Arg_Form     => Form,
11209               Arg_Code     => Code);
11210
11211             if not Is_VMS_Exception (Entity (Internal)) then
11212                Set_Exported (Entity (Internal), Internal);
11213             end if;
11214          end Export_Exception;
11215
11216          ---------------------
11217          -- Export_Function --
11218          ---------------------
11219
11220          --  pragma Export_Function (
11221          --        [Internal         =>] LOCAL_NAME
11222          --     [, [External         =>] EXTERNAL_SYMBOL]
11223          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
11224          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
11225          --     [, [Mechanism        =>] MECHANISM]
11226          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
11227
11228          --  EXTERNAL_SYMBOL ::=
11229          --    IDENTIFIER
11230          --  | static_string_EXPRESSION
11231
11232          --  PARAMETER_TYPES ::=
11233          --    null
11234          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11235
11236          --  TYPE_DESIGNATOR ::=
11237          --    subtype_NAME
11238          --  | subtype_Name ' Access
11239
11240          --  MECHANISM ::=
11241          --    MECHANISM_NAME
11242          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11243
11244          --  MECHANISM_ASSOCIATION ::=
11245          --    [formal_parameter_NAME =>] MECHANISM_NAME
11246
11247          --  MECHANISM_NAME ::=
11248          --    Value
11249          --  | Reference
11250          --  | Descriptor [([Class =>] CLASS_NAME)]
11251
11252          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11253
11254          when Pragma_Export_Function => Export_Function : declare
11255             Args  : Args_List (1 .. 6);
11256             Names : constant Name_List (1 .. 6) := (
11257                       Name_Internal,
11258                       Name_External,
11259                       Name_Parameter_Types,
11260                       Name_Result_Type,
11261                       Name_Mechanism,
11262                       Name_Result_Mechanism);
11263
11264             Internal         : Node_Id renames Args (1);
11265             External         : Node_Id renames Args (2);
11266             Parameter_Types  : Node_Id renames Args (3);
11267             Result_Type      : Node_Id renames Args (4);
11268             Mechanism        : Node_Id renames Args (5);
11269             Result_Mechanism : Node_Id renames Args (6);
11270
11271          begin
11272             GNAT_Pragma;
11273             Gather_Associations (Names, Args);
11274             Process_Extended_Import_Export_Subprogram_Pragma (
11275               Arg_Internal         => Internal,
11276               Arg_External         => External,
11277               Arg_Parameter_Types  => Parameter_Types,
11278               Arg_Result_Type      => Result_Type,
11279               Arg_Mechanism        => Mechanism,
11280               Arg_Result_Mechanism => Result_Mechanism);
11281          end Export_Function;
11282
11283          -------------------
11284          -- Export_Object --
11285          -------------------
11286
11287          --  pragma Export_Object (
11288          --        [Internal =>] LOCAL_NAME
11289          --     [, [External =>] EXTERNAL_SYMBOL]
11290          --     [, [Size     =>] EXTERNAL_SYMBOL]);
11291
11292          --  EXTERNAL_SYMBOL ::=
11293          --    IDENTIFIER
11294          --  | static_string_EXPRESSION
11295
11296          --  PARAMETER_TYPES ::=
11297          --    null
11298          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11299
11300          --  TYPE_DESIGNATOR ::=
11301          --    subtype_NAME
11302          --  | subtype_Name ' Access
11303
11304          --  MECHANISM ::=
11305          --    MECHANISM_NAME
11306          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11307
11308          --  MECHANISM_ASSOCIATION ::=
11309          --    [formal_parameter_NAME =>] MECHANISM_NAME
11310
11311          --  MECHANISM_NAME ::=
11312          --    Value
11313          --  | Reference
11314          --  | Descriptor [([Class =>] CLASS_NAME)]
11315
11316          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11317
11318          when Pragma_Export_Object => Export_Object : declare
11319             Args  : Args_List (1 .. 3);
11320             Names : constant Name_List (1 .. 3) := (
11321                       Name_Internal,
11322                       Name_External,
11323                       Name_Size);
11324
11325             Internal : Node_Id renames Args (1);
11326             External : Node_Id renames Args (2);
11327             Size     : Node_Id renames Args (3);
11328
11329          begin
11330             GNAT_Pragma;
11331             Gather_Associations (Names, Args);
11332             Process_Extended_Import_Export_Object_Pragma (
11333               Arg_Internal => Internal,
11334               Arg_External => External,
11335               Arg_Size     => Size);
11336          end Export_Object;
11337
11338          ----------------------
11339          -- Export_Procedure --
11340          ----------------------
11341
11342          --  pragma Export_Procedure (
11343          --        [Internal         =>] LOCAL_NAME
11344          --     [, [External         =>] EXTERNAL_SYMBOL]
11345          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
11346          --     [, [Mechanism        =>] MECHANISM]);
11347
11348          --  EXTERNAL_SYMBOL ::=
11349          --    IDENTIFIER
11350          --  | static_string_EXPRESSION
11351
11352          --  PARAMETER_TYPES ::=
11353          --    null
11354          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11355
11356          --  TYPE_DESIGNATOR ::=
11357          --    subtype_NAME
11358          --  | subtype_Name ' Access
11359
11360          --  MECHANISM ::=
11361          --    MECHANISM_NAME
11362          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11363
11364          --  MECHANISM_ASSOCIATION ::=
11365          --    [formal_parameter_NAME =>] MECHANISM_NAME
11366
11367          --  MECHANISM_NAME ::=
11368          --    Value
11369          --  | Reference
11370          --  | Descriptor [([Class =>] CLASS_NAME)]
11371
11372          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11373
11374          when Pragma_Export_Procedure => Export_Procedure : declare
11375             Args  : Args_List (1 .. 4);
11376             Names : constant Name_List (1 .. 4) := (
11377                       Name_Internal,
11378                       Name_External,
11379                       Name_Parameter_Types,
11380                       Name_Mechanism);
11381
11382             Internal        : Node_Id renames Args (1);
11383             External        : Node_Id renames Args (2);
11384             Parameter_Types : Node_Id renames Args (3);
11385             Mechanism       : Node_Id renames Args (4);
11386
11387          begin
11388             GNAT_Pragma;
11389             Gather_Associations (Names, Args);
11390             Process_Extended_Import_Export_Subprogram_Pragma (
11391               Arg_Internal        => Internal,
11392               Arg_External        => External,
11393               Arg_Parameter_Types => Parameter_Types,
11394               Arg_Mechanism       => Mechanism);
11395          end Export_Procedure;
11396
11397          ------------------
11398          -- Export_Value --
11399          ------------------
11400
11401          --  pragma Export_Value (
11402          --     [Value     =>] static_integer_EXPRESSION,
11403          --     [Link_Name =>] static_string_EXPRESSION);
11404
11405          when Pragma_Export_Value =>
11406             GNAT_Pragma;
11407             Check_Arg_Order ((Name_Value, Name_Link_Name));
11408             Check_Arg_Count (2);
11409
11410             Check_Optional_Identifier (Arg1, Name_Value);
11411             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
11412
11413             Check_Optional_Identifier (Arg2, Name_Link_Name);
11414             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
11415
11416          -----------------------------
11417          -- Export_Valued_Procedure --
11418          -----------------------------
11419
11420          --  pragma Export_Valued_Procedure (
11421          --        [Internal         =>] LOCAL_NAME
11422          --     [, [External         =>] EXTERNAL_SYMBOL,]
11423          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
11424          --     [, [Mechanism        =>] MECHANISM]);
11425
11426          --  EXTERNAL_SYMBOL ::=
11427          --    IDENTIFIER
11428          --  | static_string_EXPRESSION
11429
11430          --  PARAMETER_TYPES ::=
11431          --    null
11432          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
11433
11434          --  TYPE_DESIGNATOR ::=
11435          --    subtype_NAME
11436          --  | subtype_Name ' Access
11437
11438          --  MECHANISM ::=
11439          --    MECHANISM_NAME
11440          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
11441
11442          --  MECHANISM_ASSOCIATION ::=
11443          --    [formal_parameter_NAME =>] MECHANISM_NAME
11444
11445          --  MECHANISM_NAME ::=
11446          --    Value
11447          --  | Reference
11448          --  | Descriptor [([Class =>] CLASS_NAME)]
11449
11450          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
11451
11452          when Pragma_Export_Valued_Procedure =>
11453          Export_Valued_Procedure : declare
11454             Args  : Args_List (1 .. 4);
11455             Names : constant Name_List (1 .. 4) := (
11456                       Name_Internal,
11457                       Name_External,
11458                       Name_Parameter_Types,
11459                       Name_Mechanism);
11460
11461             Internal        : Node_Id renames Args (1);
11462             External        : Node_Id renames Args (2);
11463             Parameter_Types : Node_Id renames Args (3);
11464             Mechanism       : Node_Id renames Args (4);
11465
11466          begin
11467             GNAT_Pragma;
11468             Gather_Associations (Names, Args);
11469             Process_Extended_Import_Export_Subprogram_Pragma (
11470               Arg_Internal        => Internal,
11471               Arg_External        => External,
11472               Arg_Parameter_Types => Parameter_Types,
11473               Arg_Mechanism       => Mechanism);
11474          end Export_Valued_Procedure;
11475
11476          -------------------
11477          -- Extend_System --
11478          -------------------
11479
11480          --  pragma Extend_System ([Name =>] Identifier);
11481
11482          when Pragma_Extend_System => Extend_System : declare
11483          begin
11484             GNAT_Pragma;
11485             Check_Valid_Configuration_Pragma;
11486             Check_Arg_Count (1);
11487             Check_Optional_Identifier (Arg1, Name_Name);
11488             Check_Arg_Is_Identifier (Arg1);
11489
11490             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11491
11492             if Name_Len > 4
11493               and then Name_Buffer (1 .. 4) = "aux_"
11494             then
11495                if Present (System_Extend_Pragma_Arg) then
11496                   if Chars (Get_Pragma_Arg (Arg1)) =
11497                      Chars (Expression (System_Extend_Pragma_Arg))
11498                   then
11499                      null;
11500                   else
11501                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
11502                      Error_Pragma ("pragma% conflicts with that #");
11503                   end if;
11504
11505                else
11506                   System_Extend_Pragma_Arg := Arg1;
11507
11508                   if not GNAT_Mode then
11509                      System_Extend_Unit := Arg1;
11510                   end if;
11511                end if;
11512             else
11513                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
11514             end if;
11515          end Extend_System;
11516
11517          ------------------------
11518          -- Extensions_Allowed --
11519          ------------------------
11520
11521          --  pragma Extensions_Allowed (ON | OFF);
11522
11523          when Pragma_Extensions_Allowed =>
11524             GNAT_Pragma;
11525             Check_Arg_Count (1);
11526             Check_No_Identifiers;
11527             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11528
11529             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
11530                Extensions_Allowed := True;
11531                Ada_Version := Ada_Version_Type'Last;
11532
11533             else
11534                Extensions_Allowed := False;
11535                Ada_Version := Ada_Version_Explicit;
11536             end if;
11537
11538          --------------
11539          -- External --
11540          --------------
11541
11542          --  pragma External (
11543          --    [   Convention    =>] convention_IDENTIFIER,
11544          --    [   Entity        =>] local_NAME
11545          --    [, [External_Name =>] static_string_EXPRESSION ]
11546          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
11547
11548          when Pragma_External => External : declare
11549                Def_Id : Entity_Id;
11550
11551                C : Convention_Id;
11552                pragma Warnings (Off, C);
11553
11554          begin
11555             GNAT_Pragma;
11556             Check_Arg_Order
11557               ((Name_Convention,
11558                 Name_Entity,
11559                 Name_External_Name,
11560                 Name_Link_Name));
11561             Check_At_Least_N_Arguments (2);
11562             Check_At_Most_N_Arguments  (4);
11563             Process_Convention (C, Def_Id);
11564             Note_Possible_Modification
11565               (Get_Pragma_Arg (Arg2), Sure => False);
11566             Process_Interface_Name (Def_Id, Arg3, Arg4);
11567             Set_Exported (Def_Id, Arg2);
11568          end External;
11569
11570          --------------------------
11571          -- External_Name_Casing --
11572          --------------------------
11573
11574          --  pragma External_Name_Casing (
11575          --    UPPERCASE | LOWERCASE
11576          --    [, AS_IS | UPPERCASE | LOWERCASE]);
11577
11578          when Pragma_External_Name_Casing => External_Name_Casing : declare
11579          begin
11580             GNAT_Pragma;
11581             Check_No_Identifiers;
11582
11583             if Arg_Count = 2 then
11584                Check_Arg_Is_One_Of
11585                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
11586
11587                case Chars (Get_Pragma_Arg (Arg2)) is
11588                   when Name_As_Is     =>
11589                      Opt.External_Name_Exp_Casing := As_Is;
11590
11591                   when Name_Uppercase =>
11592                      Opt.External_Name_Exp_Casing := Uppercase;
11593
11594                   when Name_Lowercase =>
11595                      Opt.External_Name_Exp_Casing := Lowercase;
11596
11597                   when others =>
11598                      null;
11599                end case;
11600
11601             else
11602                Check_Arg_Count (1);
11603             end if;
11604
11605             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
11606
11607             case Chars (Get_Pragma_Arg (Arg1)) is
11608                when Name_Uppercase =>
11609                   Opt.External_Name_Imp_Casing := Uppercase;
11610
11611                when Name_Lowercase =>
11612                   Opt.External_Name_Imp_Casing := Lowercase;
11613
11614                when others =>
11615                   null;
11616             end case;
11617          end External_Name_Casing;
11618
11619          ---------------
11620          -- Fast_Math --
11621          ---------------
11622
11623          --  pragma Fast_Math;
11624
11625          when Pragma_Fast_Math =>
11626             GNAT_Pragma;
11627             Check_No_Identifiers;
11628             Check_Valid_Configuration_Pragma;
11629             Fast_Math := True;
11630
11631          --------------------------
11632          -- Favor_Top_Level --
11633          --------------------------
11634
11635          --  pragma Favor_Top_Level (type_NAME);
11636
11637          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
11638                Named_Entity : Entity_Id;
11639
11640          begin
11641             GNAT_Pragma;
11642             Check_No_Identifiers;
11643             Check_Arg_Count (1);
11644             Check_Arg_Is_Local_Name (Arg1);
11645             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
11646
11647             --  If it's an access-to-subprogram type (in particular, not a
11648             --  subtype), set the flag on that type.
11649
11650             if Is_Access_Subprogram_Type (Named_Entity) then
11651                Set_Can_Use_Internal_Rep (Named_Entity, False);
11652
11653             --  Otherwise it's an error (name denotes the wrong sort of entity)
11654
11655             else
11656                Error_Pragma_Arg
11657                  ("access-to-subprogram type expected",
11658                   Get_Pragma_Arg (Arg1));
11659             end if;
11660          end Favor_Top_Level;
11661
11662          ---------------------------
11663          -- Finalize_Storage_Only --
11664          ---------------------------
11665
11666          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
11667
11668          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
11669             Assoc   : constant Node_Id := Arg1;
11670             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
11671             Typ     : Entity_Id;
11672
11673          begin
11674             GNAT_Pragma;
11675             Check_No_Identifiers;
11676             Check_Arg_Count (1);
11677             Check_Arg_Is_Local_Name (Arg1);
11678
11679             Find_Type (Type_Id);
11680             Typ := Entity (Type_Id);
11681
11682             if Typ = Any_Type
11683               or else Rep_Item_Too_Early (Typ, N)
11684             then
11685                return;
11686             else
11687                Typ := Underlying_Type (Typ);
11688             end if;
11689
11690             if not Is_Controlled (Typ) then
11691                Error_Pragma ("pragma% must specify controlled type");
11692             end if;
11693
11694             Check_First_Subtype (Arg1);
11695
11696             if Finalize_Storage_Only (Typ) then
11697                Error_Pragma ("duplicate pragma%, only one allowed");
11698
11699             elsif not Rep_Item_Too_Late (Typ, N) then
11700                Set_Finalize_Storage_Only (Base_Type (Typ), True);
11701             end if;
11702          end Finalize_Storage;
11703
11704          --------------------------
11705          -- Float_Representation --
11706          --------------------------
11707
11708          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
11709
11710          --  FLOAT_REP ::= VAX_Float | IEEE_Float
11711
11712          when Pragma_Float_Representation => Float_Representation : declare
11713             Argx : Node_Id;
11714             Digs : Nat;
11715             Ent  : Entity_Id;
11716
11717          begin
11718             GNAT_Pragma;
11719
11720             if Arg_Count = 1 then
11721                Check_Valid_Configuration_Pragma;
11722             else
11723                Check_Arg_Count (2);
11724                Check_Optional_Identifier (Arg2, Name_Entity);
11725                Check_Arg_Is_Local_Name (Arg2);
11726             end if;
11727
11728             Check_No_Identifier (Arg1);
11729             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
11730
11731             if not OpenVMS_On_Target then
11732                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11733                   Error_Pragma
11734                     ("??pragma% ignored (applies only to Open'V'M'S)");
11735                end if;
11736
11737                return;
11738             end if;
11739
11740             --  One argument case
11741
11742             if Arg_Count = 1 then
11743                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11744                   if Opt.Float_Format = 'I' then
11745                      Error_Pragma ("'I'E'E'E format previously specified");
11746                   end if;
11747
11748                   Opt.Float_Format := 'V';
11749
11750                else
11751                   if Opt.Float_Format = 'V' then
11752                      Error_Pragma ("'V'A'X format previously specified");
11753                   end if;
11754
11755                   Opt.Float_Format := 'I';
11756                end if;
11757
11758                Set_Standard_Fpt_Formats;
11759
11760             --  Two argument case
11761
11762             else
11763                Argx := Get_Pragma_Arg (Arg2);
11764
11765                if not Is_Entity_Name (Argx)
11766                  or else not Is_Floating_Point_Type (Entity (Argx))
11767                then
11768                   Error_Pragma_Arg
11769                     ("second argument of% pragma must be floating-point type",
11770                      Arg2);
11771                end if;
11772
11773                Ent  := Entity (Argx);
11774                Digs := UI_To_Int (Digits_Value (Ent));
11775
11776                --  Two arguments, VAX_Float case
11777
11778                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
11779                   case Digs is
11780                      when  6 => Set_F_Float (Ent);
11781                      when  9 => Set_D_Float (Ent);
11782                      when 15 => Set_G_Float (Ent);
11783
11784                      when others =>
11785                         Error_Pragma_Arg
11786                           ("wrong digits value, must be 6,9 or 15", Arg2);
11787                   end case;
11788
11789                --  Two arguments, IEEE_Float case
11790
11791                else
11792                   case Digs is
11793                      when  6 => Set_IEEE_Short (Ent);
11794                      when 15 => Set_IEEE_Long  (Ent);
11795
11796                      when others =>
11797                         Error_Pragma_Arg
11798                           ("wrong digits value, must be 6 or 15", Arg2);
11799                   end case;
11800                end if;
11801             end if;
11802          end Float_Representation;
11803
11804          ------------
11805          -- Global --
11806          ------------
11807
11808          --  pragma Global (GLOBAL_SPECIFICATION)
11809
11810          --  GLOBAL_SPECIFICATION ::=
11811          --    null
11812          --  | GLOBAL_LIST
11813          --  | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
11814
11815          --  MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
11816
11817          --  MODE_SELECTOR ::= Input | Output | In_Out | Contract_In
11818          --  GLOBAL_LIST   ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
11819          --  GLOBAL_ITEM   ::= NAME
11820
11821          when Pragma_Global => Global : declare
11822             Subp_Decl : Node_Id;
11823             Subp_Id   : Entity_Id;
11824
11825          begin
11826             GNAT_Pragma;
11827             S14_Pragma;
11828             Check_Arg_Count (1);
11829
11830             --  Ensure the proper placement of the pragma. Global must be
11831             --  associated with a subprogram declaration or a body that acts
11832             --  as a spec.
11833
11834             Subp_Decl := Find_Related_Subprogram (N, Check_Duplicates => True);
11835
11836             if Nkind (Subp_Decl) /= N_Subprogram_Declaration
11837               and then (Nkind (Subp_Decl) /= N_Subprogram_Body
11838                           or else not Acts_As_Spec (Subp_Decl))
11839             then
11840                Pragma_Misplaced;
11841                return;
11842             end if;
11843
11844             Subp_Id := Defining_Unit_Name (Specification (Subp_Decl));
11845
11846             --  When the aspect/pragma appears on a subprogram body, perform
11847             --  the full analysis now.
11848
11849             if Nkind (Subp_Decl) = N_Subprogram_Body then
11850                Analyze_Global_In_Decl_Part (N);
11851
11852             --  When Global applies to a subprogram compilation unit, the
11853             --  corresponding pragma is placed after the unit's declaration
11854             --  node and needs to be analyzed immediately.
11855
11856             elsif Nkind (Subp_Decl) = N_Subprogram_Declaration
11857               and then Nkind (Parent (Subp_Decl)) = N_Compilation_Unit
11858             then
11859                Analyze_Global_In_Decl_Part (N);
11860             end if;
11861
11862             --  Chain the pragma on the contract for further processing
11863
11864             Add_Contract_Item (N, Subp_Id);
11865          end Global;
11866
11867          -----------
11868          -- Ident --
11869          -----------
11870
11871          --  pragma Ident (static_string_EXPRESSION)
11872
11873          --  Note: pragma Comment shares this processing. Pragma Comment is
11874          --  identical to Ident, except that the restriction of the argument to
11875          --  31 characters and the placement restrictions are not enforced for
11876          --  pragma Comment.
11877
11878          when Pragma_Ident | Pragma_Comment => Ident : declare
11879             Str : Node_Id;
11880
11881          begin
11882             GNAT_Pragma;
11883             Check_Arg_Count (1);
11884             Check_No_Identifiers;
11885             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11886             Store_Note (N);
11887
11888             --  For pragma Ident, preserve DEC compatibility by requiring the
11889             --  pragma to appear in a declarative part or package spec.
11890
11891             if Prag_Id = Pragma_Ident then
11892                Check_Is_In_Decl_Part_Or_Package_Spec;
11893             end if;
11894
11895             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
11896
11897             declare
11898                CS : Node_Id;
11899                GP : Node_Id;
11900
11901             begin
11902                GP := Parent (Parent (N));
11903
11904                if Nkind_In (GP, N_Package_Declaration,
11905                                 N_Generic_Package_Declaration)
11906                then
11907                   GP := Parent (GP);
11908                end if;
11909
11910                --  If we have a compilation unit, then record the ident value,
11911                --  checking for improper duplication.
11912
11913                if Nkind (GP) = N_Compilation_Unit then
11914                   CS := Ident_String (Current_Sem_Unit);
11915
11916                   if Present (CS) then
11917
11918                      --  For Ident, we do not permit multiple instances
11919
11920                      if Prag_Id = Pragma_Ident then
11921                         Error_Pragma ("duplicate% pragma not permitted");
11922
11923                      --  For Comment, we concatenate the string, unless we want
11924                      --  to preserve the tree structure for ASIS.
11925
11926                      elsif not ASIS_Mode then
11927                         Start_String (Strval (CS));
11928                         Store_String_Char (' ');
11929                         Store_String_Chars (Strval (Str));
11930                         Set_Strval (CS, End_String);
11931                      end if;
11932
11933                   else
11934                      --  In VMS, the effect of IDENT is achieved by passing
11935                      --  --identification=name as a --for-linker switch.
11936
11937                      if OpenVMS_On_Target then
11938                         Start_String;
11939                         Store_String_Chars
11940                           ("--for-linker=--identification=");
11941                         String_To_Name_Buffer (Strval (Str));
11942                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
11943
11944                         --  Only the last processed IDENT is saved. The main
11945                         --  purpose is so an IDENT associated with a main
11946                         --  procedure will be used in preference to an IDENT
11947                         --  associated with a with'd package.
11948
11949                         Replace_Linker_Option_String
11950                           (End_String, "--for-linker=--identification=");
11951                      end if;
11952
11953                      Set_Ident_String (Current_Sem_Unit, Str);
11954                   end if;
11955
11956                --  For subunits, we just ignore the Ident, since in GNAT these
11957                --  are not separate object files, and hence not separate units
11958                --  in the unit table.
11959
11960                elsif Nkind (GP) = N_Subunit then
11961                   null;
11962
11963                --  Otherwise we have a misplaced pragma Ident, but we ignore
11964                --  this if we are in an instantiation, since it comes from
11965                --  a generic, and has no relevance to the instantiation.
11966
11967                elsif Prag_Id = Pragma_Ident then
11968                   if Instantiation_Location (Loc) = No_Location then
11969                      Error_Pragma ("pragma% only allowed at outer level");
11970                   end if;
11971                end if;
11972             end;
11973          end Ident;
11974
11975          ----------------------------
11976          -- Implementation_Defined --
11977          ----------------------------
11978
11979          --  pragma Implementation_Defined (local_NAME);
11980
11981          --  Marks previously declared entity as implementation defined. For
11982          --  an overloaded entity, applies to the most recent homonym.
11983
11984          --  pragma Implementation_Defined;
11985
11986          --  The form with no arguments appears anywhere within a scope, most
11987          --  typically a package spec, and indicates that all entities that are
11988          --  defined within the package spec are Implementation_Defined.
11989
11990          when Pragma_Implementation_Defined => Implementation_Defined : declare
11991             Ent : Entity_Id;
11992
11993          begin
11994             GNAT_Pragma;
11995             Check_No_Identifiers;
11996
11997             --  Form with no arguments
11998
11999             if Arg_Count = 0 then
12000                Set_Is_Implementation_Defined (Current_Scope);
12001
12002             --  Form with one argument
12003
12004             else
12005                Check_Arg_Count (1);
12006                Check_Arg_Is_Local_Name (Arg1);
12007                Ent := Entity (Get_Pragma_Arg (Arg1));
12008                Set_Is_Implementation_Defined (Ent);
12009             end if;
12010          end Implementation_Defined;
12011
12012          -----------------
12013          -- Implemented --
12014          -----------------
12015
12016          --  pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
12017
12018          --  IMPLEMENTATION_KIND ::=
12019          --    By_Entry | By_Protected_Procedure | By_Any | Optional
12020
12021          --  "By_Any" and "Optional" are treated as synonyms in order to
12022          --  support Ada 2012 aspect Synchronization.
12023
12024          when Pragma_Implemented => Implemented : declare
12025             Proc_Id : Entity_Id;
12026             Typ     : Entity_Id;
12027
12028          begin
12029             Ada_2012_Pragma;
12030             Check_Arg_Count (2);
12031             Check_No_Identifiers;
12032             Check_Arg_Is_Identifier (Arg1);
12033             Check_Arg_Is_Local_Name (Arg1);
12034             Check_Arg_Is_One_Of (Arg2,
12035               Name_By_Any,
12036               Name_By_Entry,
12037               Name_By_Protected_Procedure,
12038               Name_Optional);
12039
12040             --  Extract the name of the local procedure
12041
12042             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
12043
12044             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
12045             --  primitive procedure of a synchronized tagged type.
12046
12047             if Ekind (Proc_Id) = E_Procedure
12048               and then Is_Primitive (Proc_Id)
12049               and then Present (First_Formal (Proc_Id))
12050             then
12051                Typ := Etype (First_Formal (Proc_Id));
12052
12053                if Is_Tagged_Type (Typ)
12054                  and then
12055
12056                   --  Check for a protected, a synchronized or a task interface
12057
12058                    ((Is_Interface (Typ)
12059                        and then Is_Synchronized_Interface (Typ))
12060
12061                   --  Check for a protected type or a task type that implements
12062                   --  an interface.
12063
12064                    or else
12065                     (Is_Concurrent_Record_Type (Typ)
12066                        and then Present (Interfaces (Typ)))
12067
12068                   --  Check for a private record extension with keyword
12069                   --  "synchronized".
12070
12071                    or else
12072                     (Ekind_In (Typ, E_Record_Type_With_Private,
12073                                     E_Record_Subtype_With_Private)
12074                        and then Synchronized_Present (Parent (Typ))))
12075                then
12076                   null;
12077                else
12078                   Error_Pragma_Arg
12079                     ("controlling formal must be of synchronized tagged type",
12080                      Arg1);
12081                   return;
12082                end if;
12083
12084             --  Procedures declared inside a protected type must be accepted
12085
12086             elsif Ekind (Proc_Id) = E_Procedure
12087               and then Is_Protected_Type (Scope (Proc_Id))
12088             then
12089                null;
12090
12091             --  The first argument is not a primitive procedure
12092
12093             else
12094                Error_Pragma_Arg
12095                  ("pragma % must be applied to a primitive procedure", Arg1);
12096                return;
12097             end if;
12098
12099             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
12100             --  By_Protected_Procedure to the primitive procedure of a task
12101             --  interface.
12102
12103             if Chars (Arg2) = Name_By_Protected_Procedure
12104               and then Is_Interface (Typ)
12105               and then Is_Task_Interface (Typ)
12106             then
12107                Error_Pragma_Arg
12108                  ("implementation kind By_Protected_Procedure cannot be "
12109                   & "applied to a task interface primitive", Arg2);
12110                return;
12111             end if;
12112
12113             Record_Rep_Item (Proc_Id, N);
12114          end Implemented;
12115
12116          ----------------------
12117          -- Implicit_Packing --
12118          ----------------------
12119
12120          --  pragma Implicit_Packing;
12121
12122          when Pragma_Implicit_Packing =>
12123             GNAT_Pragma;
12124             Check_Arg_Count (0);
12125             Implicit_Packing := True;
12126
12127          ------------
12128          -- Import --
12129          ------------
12130
12131          --  pragma Import (
12132          --       [Convention    =>] convention_IDENTIFIER,
12133          --       [Entity        =>] local_NAME
12134          --    [, [External_Name =>] static_string_EXPRESSION ]
12135          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
12136
12137          when Pragma_Import =>
12138             Check_Ada_83_Warning;
12139             Check_Arg_Order
12140               ((Name_Convention,
12141                 Name_Entity,
12142                 Name_External_Name,
12143                 Name_Link_Name));
12144
12145             Check_At_Least_N_Arguments (2);
12146             Check_At_Most_N_Arguments  (4);
12147             Process_Import_Or_Interface;
12148
12149          ----------------------
12150          -- Import_Exception --
12151          ----------------------
12152
12153          --  pragma Import_Exception (
12154          --        [Internal         =>] LOCAL_NAME
12155          --     [, [External         =>] EXTERNAL_SYMBOL]
12156          --     [, [Form     =>] Ada | VMS]
12157          --     [, [Code     =>] static_integer_EXPRESSION]);
12158
12159          when Pragma_Import_Exception => Import_Exception : declare
12160             Args  : Args_List (1 .. 4);
12161             Names : constant Name_List (1 .. 4) := (
12162                       Name_Internal,
12163                       Name_External,
12164                       Name_Form,
12165                       Name_Code);
12166
12167             Internal : Node_Id renames Args (1);
12168             External : Node_Id renames Args (2);
12169             Form     : Node_Id renames Args (3);
12170             Code     : Node_Id renames Args (4);
12171
12172          begin
12173             GNAT_Pragma;
12174             Gather_Associations (Names, Args);
12175
12176             if Present (External) and then Present (Code) then
12177                Error_Pragma
12178                  ("cannot give both External and Code options for pragma%");
12179             end if;
12180
12181             Process_Extended_Import_Export_Exception_Pragma (
12182               Arg_Internal => Internal,
12183               Arg_External => External,
12184               Arg_Form     => Form,
12185               Arg_Code     => Code);
12186
12187             if not Is_VMS_Exception (Entity (Internal)) then
12188                Set_Imported (Entity (Internal));
12189             end if;
12190          end Import_Exception;
12191
12192          ---------------------
12193          -- Import_Function --
12194          ---------------------
12195
12196          --  pragma Import_Function (
12197          --        [Internal                 =>] LOCAL_NAME,
12198          --     [, [External                 =>] EXTERNAL_SYMBOL]
12199          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
12200          --     [, [Result_Type              =>] SUBTYPE_MARK]
12201          --     [, [Mechanism                =>] MECHANISM]
12202          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
12203          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
12204
12205          --  EXTERNAL_SYMBOL ::=
12206          --    IDENTIFIER
12207          --  | static_string_EXPRESSION
12208
12209          --  PARAMETER_TYPES ::=
12210          --    null
12211          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12212
12213          --  TYPE_DESIGNATOR ::=
12214          --    subtype_NAME
12215          --  | subtype_Name ' Access
12216
12217          --  MECHANISM ::=
12218          --    MECHANISM_NAME
12219          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12220
12221          --  MECHANISM_ASSOCIATION ::=
12222          --    [formal_parameter_NAME =>] MECHANISM_NAME
12223
12224          --  MECHANISM_NAME ::=
12225          --    Value
12226          --  | Reference
12227          --  | Descriptor [([Class =>] CLASS_NAME)]
12228
12229          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12230
12231          when Pragma_Import_Function => Import_Function : declare
12232             Args  : Args_List (1 .. 7);
12233             Names : constant Name_List (1 .. 7) := (
12234                       Name_Internal,
12235                       Name_External,
12236                       Name_Parameter_Types,
12237                       Name_Result_Type,
12238                       Name_Mechanism,
12239                       Name_Result_Mechanism,
12240                       Name_First_Optional_Parameter);
12241
12242             Internal                 : Node_Id renames Args (1);
12243             External                 : Node_Id renames Args (2);
12244             Parameter_Types          : Node_Id renames Args (3);
12245             Result_Type              : Node_Id renames Args (4);
12246             Mechanism                : Node_Id renames Args (5);
12247             Result_Mechanism         : Node_Id renames Args (6);
12248             First_Optional_Parameter : Node_Id renames Args (7);
12249
12250          begin
12251             GNAT_Pragma;
12252             Gather_Associations (Names, Args);
12253             Process_Extended_Import_Export_Subprogram_Pragma (
12254               Arg_Internal                 => Internal,
12255               Arg_External                 => External,
12256               Arg_Parameter_Types          => Parameter_Types,
12257               Arg_Result_Type              => Result_Type,
12258               Arg_Mechanism                => Mechanism,
12259               Arg_Result_Mechanism         => Result_Mechanism,
12260               Arg_First_Optional_Parameter => First_Optional_Parameter);
12261          end Import_Function;
12262
12263          -------------------
12264          -- Import_Object --
12265          -------------------
12266
12267          --  pragma Import_Object (
12268          --        [Internal =>] LOCAL_NAME
12269          --     [, [External =>] EXTERNAL_SYMBOL]
12270          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12271
12272          --  EXTERNAL_SYMBOL ::=
12273          --    IDENTIFIER
12274          --  | static_string_EXPRESSION
12275
12276          when Pragma_Import_Object => Import_Object : declare
12277             Args  : Args_List (1 .. 3);
12278             Names : constant Name_List (1 .. 3) := (
12279                       Name_Internal,
12280                       Name_External,
12281                       Name_Size);
12282
12283             Internal : Node_Id renames Args (1);
12284             External : Node_Id renames Args (2);
12285             Size     : Node_Id renames Args (3);
12286
12287          begin
12288             GNAT_Pragma;
12289             Gather_Associations (Names, Args);
12290             Process_Extended_Import_Export_Object_Pragma (
12291               Arg_Internal => Internal,
12292               Arg_External => External,
12293               Arg_Size     => Size);
12294          end Import_Object;
12295
12296          ----------------------
12297          -- Import_Procedure --
12298          ----------------------
12299
12300          --  pragma Import_Procedure (
12301          --        [Internal                 =>] LOCAL_NAME
12302          --     [, [External                 =>] EXTERNAL_SYMBOL]
12303          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
12304          --     [, [Mechanism                =>] MECHANISM]
12305          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
12306
12307          --  EXTERNAL_SYMBOL ::=
12308          --    IDENTIFIER
12309          --  | static_string_EXPRESSION
12310
12311          --  PARAMETER_TYPES ::=
12312          --    null
12313          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12314
12315          --  TYPE_DESIGNATOR ::=
12316          --    subtype_NAME
12317          --  | subtype_Name ' Access
12318
12319          --  MECHANISM ::=
12320          --    MECHANISM_NAME
12321          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12322
12323          --  MECHANISM_ASSOCIATION ::=
12324          --    [formal_parameter_NAME =>] MECHANISM_NAME
12325
12326          --  MECHANISM_NAME ::=
12327          --    Value
12328          --  | Reference
12329          --  | Descriptor [([Class =>] CLASS_NAME)]
12330
12331          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12332
12333          when Pragma_Import_Procedure => Import_Procedure : declare
12334             Args  : Args_List (1 .. 5);
12335             Names : constant Name_List (1 .. 5) := (
12336                       Name_Internal,
12337                       Name_External,
12338                       Name_Parameter_Types,
12339                       Name_Mechanism,
12340                       Name_First_Optional_Parameter);
12341
12342             Internal                 : Node_Id renames Args (1);
12343             External                 : Node_Id renames Args (2);
12344             Parameter_Types          : Node_Id renames Args (3);
12345             Mechanism                : Node_Id renames Args (4);
12346             First_Optional_Parameter : Node_Id renames Args (5);
12347
12348          begin
12349             GNAT_Pragma;
12350             Gather_Associations (Names, Args);
12351             Process_Extended_Import_Export_Subprogram_Pragma (
12352               Arg_Internal                 => Internal,
12353               Arg_External                 => External,
12354               Arg_Parameter_Types          => Parameter_Types,
12355               Arg_Mechanism                => Mechanism,
12356               Arg_First_Optional_Parameter => First_Optional_Parameter);
12357          end Import_Procedure;
12358
12359          -----------------------------
12360          -- Import_Valued_Procedure --
12361          -----------------------------
12362
12363          --  pragma Import_Valued_Procedure (
12364          --        [Internal                 =>] LOCAL_NAME
12365          --     [, [External                 =>] EXTERNAL_SYMBOL]
12366          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
12367          --     [, [Mechanism                =>] MECHANISM]
12368          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
12369
12370          --  EXTERNAL_SYMBOL ::=
12371          --    IDENTIFIER
12372          --  | static_string_EXPRESSION
12373
12374          --  PARAMETER_TYPES ::=
12375          --    null
12376          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
12377
12378          --  TYPE_DESIGNATOR ::=
12379          --    subtype_NAME
12380          --  | subtype_Name ' Access
12381
12382          --  MECHANISM ::=
12383          --    MECHANISM_NAME
12384          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
12385
12386          --  MECHANISM_ASSOCIATION ::=
12387          --    [formal_parameter_NAME =>] MECHANISM_NAME
12388
12389          --  MECHANISM_NAME ::=
12390          --    Value
12391          --  | Reference
12392          --  | Descriptor [([Class =>] CLASS_NAME)]
12393
12394          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
12395
12396          when Pragma_Import_Valued_Procedure =>
12397          Import_Valued_Procedure : declare
12398             Args  : Args_List (1 .. 5);
12399             Names : constant Name_List (1 .. 5) := (
12400                       Name_Internal,
12401                       Name_External,
12402                       Name_Parameter_Types,
12403                       Name_Mechanism,
12404                       Name_First_Optional_Parameter);
12405
12406             Internal                 : Node_Id renames Args (1);
12407             External                 : Node_Id renames Args (2);
12408             Parameter_Types          : Node_Id renames Args (3);
12409             Mechanism                : Node_Id renames Args (4);
12410             First_Optional_Parameter : Node_Id renames Args (5);
12411
12412          begin
12413             GNAT_Pragma;
12414             Gather_Associations (Names, Args);
12415             Process_Extended_Import_Export_Subprogram_Pragma (
12416               Arg_Internal                 => Internal,
12417               Arg_External                 => External,
12418               Arg_Parameter_Types          => Parameter_Types,
12419               Arg_Mechanism                => Mechanism,
12420               Arg_First_Optional_Parameter => First_Optional_Parameter);
12421          end Import_Valued_Procedure;
12422
12423          -----------------
12424          -- Independent --
12425          -----------------
12426
12427          --  pragma Independent (LOCAL_NAME);
12428
12429          when Pragma_Independent => Independent : declare
12430             E_Id : Node_Id;
12431             E    : Entity_Id;
12432             D    : Node_Id;
12433             K    : Node_Kind;
12434
12435          begin
12436             Check_Ada_83_Warning;
12437             Ada_2012_Pragma;
12438             Check_No_Identifiers;
12439             Check_Arg_Count (1);
12440             Check_Arg_Is_Local_Name (Arg1);
12441             E_Id := Get_Pragma_Arg (Arg1);
12442
12443             if Etype (E_Id) = Any_Type then
12444                return;
12445             end if;
12446
12447             E := Entity (E_Id);
12448             D := Declaration_Node (E);
12449             K := Nkind (D);
12450
12451             --  Check duplicate before we chain ourselves!
12452
12453             Check_Duplicate_Pragma (E);
12454
12455             --  Check appropriate entity
12456
12457             if Is_Type (E) then
12458                if Rep_Item_Too_Early (E, N)
12459                     or else
12460                   Rep_Item_Too_Late (E, N)
12461                then
12462                   return;
12463                else
12464                   Check_First_Subtype (Arg1);
12465                end if;
12466
12467             elsif K = N_Object_Declaration
12468               or else (K = N_Component_Declaration
12469                        and then Original_Record_Component (E) = E)
12470             then
12471                if Rep_Item_Too_Late (E, N) then
12472                   return;
12473                end if;
12474
12475             else
12476                Error_Pragma_Arg
12477                  ("inappropriate entity for pragma%", Arg1);
12478             end if;
12479
12480             Independence_Checks.Append ((N, E));
12481          end Independent;
12482
12483          ----------------------------
12484          -- Independent_Components --
12485          ----------------------------
12486
12487          --  pragma Atomic_Components (array_LOCAL_NAME);
12488
12489          --  This processing is shared by Volatile_Components
12490
12491          when Pragma_Independent_Components => Independent_Components : declare
12492             E_Id : Node_Id;
12493             E    : Entity_Id;
12494             D    : Node_Id;
12495             K    : Node_Kind;
12496
12497          begin
12498             Check_Ada_83_Warning;
12499             Ada_2012_Pragma;
12500             Check_No_Identifiers;
12501             Check_Arg_Count (1);
12502             Check_Arg_Is_Local_Name (Arg1);
12503             E_Id := Get_Pragma_Arg (Arg1);
12504
12505             if Etype (E_Id) = Any_Type then
12506                return;
12507             end if;
12508
12509             E := Entity (E_Id);
12510
12511             --  Check duplicate before we chain ourselves!
12512
12513             Check_Duplicate_Pragma (E);
12514
12515             --  Check appropriate entity
12516
12517             if Rep_Item_Too_Early (E, N)
12518                  or else
12519                Rep_Item_Too_Late (E, N)
12520             then
12521                return;
12522             end if;
12523
12524             D := Declaration_Node (E);
12525             K := Nkind (D);
12526
12527             if K = N_Full_Type_Declaration
12528               and then (Is_Array_Type (E) or else Is_Record_Type (E))
12529             then
12530                Independence_Checks.Append ((N, E));
12531                Set_Has_Independent_Components (Base_Type (E));
12532
12533             elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12534               and then Nkind (D) = N_Object_Declaration
12535               and then Nkind (Object_Definition (D)) =
12536                                            N_Constrained_Array_Definition
12537             then
12538                Independence_Checks.Append ((N, E));
12539                Set_Has_Independent_Components (E);
12540
12541             else
12542                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
12543             end if;
12544          end Independent_Components;
12545
12546          ------------------------
12547          -- Initialize_Scalars --
12548          ------------------------
12549
12550          --  pragma Initialize_Scalars;
12551
12552          when Pragma_Initialize_Scalars =>
12553             GNAT_Pragma;
12554             Check_Arg_Count (0);
12555             Check_Valid_Configuration_Pragma;
12556             Check_Restriction (No_Initialize_Scalars, N);
12557
12558             --  Initialize_Scalars creates false positives in CodePeer, and
12559             --  incorrect negative results in SPARK mode, so ignore this pragma
12560             --  in these modes.
12561
12562             if not Restriction_Active (No_Initialize_Scalars)
12563               and then not (CodePeer_Mode or SPARK_Mode)
12564             then
12565                Init_Or_Norm_Scalars := True;
12566                Initialize_Scalars := True;
12567             end if;
12568
12569          ------------
12570          -- Inline --
12571          ------------
12572
12573          --  pragma Inline ( NAME {, NAME} );
12574
12575          when Pragma_Inline =>
12576
12577             --  Inline status is Enabled if inlining option is active
12578
12579             if Inline_Active then
12580                Process_Inline (Enabled);
12581             else
12582                Process_Inline (Disabled);
12583             end if;
12584
12585          -------------------
12586          -- Inline_Always --
12587          -------------------
12588
12589          --  pragma Inline_Always ( NAME {, NAME} );
12590
12591          when Pragma_Inline_Always =>
12592             GNAT_Pragma;
12593
12594             --  Pragma always active unless in CodePeer or SPARK mode, since
12595             --  this causes walk order issues.
12596
12597             if not (CodePeer_Mode or SPARK_Mode) then
12598                Process_Inline (Enabled);
12599             end if;
12600
12601          --------------------
12602          -- Inline_Generic --
12603          --------------------
12604
12605          --  pragma Inline_Generic (NAME {, NAME});
12606
12607          when Pragma_Inline_Generic =>
12608             GNAT_Pragma;
12609             Process_Generic_List;
12610
12611          ----------------------
12612          -- Inspection_Point --
12613          ----------------------
12614
12615          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
12616
12617          when Pragma_Inspection_Point => Inspection_Point : declare
12618             Arg : Node_Id;
12619             Exp : Node_Id;
12620
12621          begin
12622             if Arg_Count > 0 then
12623                Arg := Arg1;
12624                loop
12625                   Exp := Get_Pragma_Arg (Arg);
12626                   Analyze (Exp);
12627
12628                   if not Is_Entity_Name (Exp)
12629                     or else not Is_Object (Entity (Exp))
12630                   then
12631                      Error_Pragma_Arg ("object name required", Arg);
12632                   end if;
12633
12634                   Next (Arg);
12635                   exit when No (Arg);
12636                end loop;
12637             end if;
12638          end Inspection_Point;
12639
12640          ---------------
12641          -- Interface --
12642          ---------------
12643
12644          --  pragma Interface (
12645          --    [   Convention    =>] convention_IDENTIFIER,
12646          --    [   Entity        =>] local_NAME
12647          --    [, [External_Name =>] static_string_EXPRESSION ]
12648          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
12649
12650          when Pragma_Interface =>
12651             GNAT_Pragma;
12652             Check_Arg_Order
12653               ((Name_Convention,
12654                 Name_Entity,
12655                 Name_External_Name,
12656                 Name_Link_Name));
12657             Check_At_Least_N_Arguments (2);
12658             Check_At_Most_N_Arguments  (4);
12659             Process_Import_Or_Interface;
12660
12661             --  In Ada 2005, the permission to use Interface (a reserved word)
12662             --  as a pragma name is considered an obsolescent feature, and this
12663             --  pragma was already obsolescent in Ada 95.
12664
12665             if Ada_Version >= Ada_95 then
12666                Check_Restriction
12667                  (No_Obsolescent_Features, Pragma_Identifier (N));
12668
12669                if Warn_On_Obsolescent_Feature then
12670                   Error_Msg_N
12671                     ("pragma Interface is an obsolescent feature?j?", N);
12672                   Error_Msg_N
12673                     ("|use pragma Import instead?j?", N);
12674                end if;
12675             end if;
12676
12677          --------------------
12678          -- Interface_Name --
12679          --------------------
12680
12681          --  pragma Interface_Name (
12682          --    [  Entity        =>] local_NAME
12683          --    [,[External_Name =>] static_string_EXPRESSION ]
12684          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
12685
12686          when Pragma_Interface_Name => Interface_Name : declare
12687             Id     : Node_Id;
12688             Def_Id : Entity_Id;
12689             Hom_Id : Entity_Id;
12690             Found  : Boolean;
12691
12692          begin
12693             GNAT_Pragma;
12694             Check_Arg_Order
12695               ((Name_Entity, Name_External_Name, Name_Link_Name));
12696             Check_At_Least_N_Arguments (2);
12697             Check_At_Most_N_Arguments  (3);
12698             Id := Get_Pragma_Arg (Arg1);
12699             Analyze (Id);
12700
12701             --  This is obsolete from Ada 95 on, but it is an implementation
12702             --  defined pragma, so we do not consider that it violates the
12703             --  restriction (No_Obsolescent_Features).
12704
12705             if Ada_Version >= Ada_95 then
12706                if Warn_On_Obsolescent_Feature then
12707                   Error_Msg_N
12708                     ("pragma Interface_Name is an obsolescent feature?j?", N);
12709                   Error_Msg_N
12710                     ("|use pragma Import instead?j?", N);
12711                end if;
12712             end if;
12713
12714             if not Is_Entity_Name (Id) then
12715                Error_Pragma_Arg
12716                  ("first argument for pragma% must be entity name", Arg1);
12717             elsif Etype (Id) = Any_Type then
12718                return;
12719             else
12720                Def_Id := Entity (Id);
12721             end if;
12722
12723             --  Special DEC-compatible processing for the object case, forces
12724             --  object to be imported.
12725
12726             if Ekind (Def_Id) = E_Variable then
12727                Kill_Size_Check_Code (Def_Id);
12728                Note_Possible_Modification (Id, Sure => False);
12729
12730                --  Initialization is not allowed for imported variable
12731
12732                if Present (Expression (Parent (Def_Id)))
12733                  and then Comes_From_Source (Expression (Parent (Def_Id)))
12734                then
12735                   Error_Msg_Sloc := Sloc (Def_Id);
12736                   Error_Pragma_Arg
12737                     ("no initialization allowed for declaration of& #",
12738                      Arg2);
12739
12740                else
12741                   --  For compatibility, support VADS usage of providing both
12742                   --  pragmas Interface and Interface_Name to obtain the effect
12743                   --  of a single Import pragma.
12744
12745                   if Is_Imported (Def_Id)
12746                     and then Present (First_Rep_Item (Def_Id))
12747                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
12748                     and then
12749                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
12750                   then
12751                      null;
12752                   else
12753                      Set_Imported (Def_Id);
12754                   end if;
12755
12756                   Set_Is_Public (Def_Id);
12757                   Process_Interface_Name (Def_Id, Arg2, Arg3);
12758                end if;
12759
12760             --  Otherwise must be subprogram
12761
12762             elsif not Is_Subprogram (Def_Id) then
12763                Error_Pragma_Arg
12764                  ("argument of pragma% is not subprogram", Arg1);
12765
12766             else
12767                Check_At_Most_N_Arguments (3);
12768                Hom_Id := Def_Id;
12769                Found := False;
12770
12771                --  Loop through homonyms
12772
12773                loop
12774                   Def_Id := Get_Base_Subprogram (Hom_Id);
12775
12776                   if Is_Imported (Def_Id) then
12777                      Process_Interface_Name (Def_Id, Arg2, Arg3);
12778                      Found := True;
12779                   end if;
12780
12781                   exit when From_Aspect_Specification (N);
12782                   Hom_Id := Homonym (Hom_Id);
12783
12784                   exit when No (Hom_Id)
12785                     or else Scope (Hom_Id) /= Current_Scope;
12786                end loop;
12787
12788                if not Found then
12789                   Error_Pragma_Arg
12790                     ("argument of pragma% is not imported subprogram",
12791                      Arg1);
12792                end if;
12793             end if;
12794          end Interface_Name;
12795
12796          -----------------------
12797          -- Interrupt_Handler --
12798          -----------------------
12799
12800          --  pragma Interrupt_Handler (handler_NAME);
12801
12802          when Pragma_Interrupt_Handler =>
12803             Check_Ada_83_Warning;
12804             Check_Arg_Count (1);
12805             Check_No_Identifiers;
12806
12807             if No_Run_Time_Mode then
12808                Error_Msg_CRT ("Interrupt_Handler pragma", N);
12809             else
12810                Check_Interrupt_Or_Attach_Handler;
12811                Process_Interrupt_Or_Attach_Handler;
12812             end if;
12813
12814          ------------------------
12815          -- Interrupt_Priority --
12816          ------------------------
12817
12818          --  pragma Interrupt_Priority [(EXPRESSION)];
12819
12820          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
12821             P   : constant Node_Id := Parent (N);
12822             Arg : Node_Id;
12823             Ent : Entity_Id;
12824
12825          begin
12826             Check_Ada_83_Warning;
12827
12828             if Arg_Count /= 0 then
12829                Arg := Get_Pragma_Arg (Arg1);
12830                Check_Arg_Count (1);
12831                Check_No_Identifiers;
12832
12833                --  The expression must be analyzed in the special manner
12834                --  described in "Handling of Default and Per-Object
12835                --  Expressions" in sem.ads.
12836
12837                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
12838             end if;
12839
12840             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
12841                Pragma_Misplaced;
12842                return;
12843
12844             else
12845                Ent := Defining_Identifier (Parent (P));
12846
12847                --  Check duplicate pragma before we chain the pragma in the Rep
12848                --  Item chain of Ent.
12849
12850                Check_Duplicate_Pragma (Ent);
12851                Record_Rep_Item (Ent, N);
12852             end if;
12853          end Interrupt_Priority;
12854
12855          ---------------------
12856          -- Interrupt_State --
12857          ---------------------
12858
12859          --  pragma Interrupt_State (
12860          --    [Name  =>] INTERRUPT_ID,
12861          --    [State =>] INTERRUPT_STATE);
12862
12863          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
12864          --  INTERRUPT_STATE => System | Runtime | User
12865
12866          --  Note: if the interrupt id is given as an identifier, then it must
12867          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
12868          --  given as a static integer expression which must be in the range of
12869          --  Ada.Interrupts.Interrupt_ID.
12870
12871          when Pragma_Interrupt_State => Interrupt_State : declare
12872
12873             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
12874             --  This is the entity Ada.Interrupts.Interrupt_ID;
12875
12876             State_Type : Character;
12877             --  Set to 's'/'r'/'u' for System/Runtime/User
12878
12879             IST_Num : Pos;
12880             --  Index to entry in Interrupt_States table
12881
12882             Int_Val : Uint;
12883             --  Value of interrupt
12884
12885             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
12886             --  The first argument to the pragma
12887
12888             Int_Ent : Entity_Id;
12889             --  Interrupt entity in Ada.Interrupts.Names
12890
12891          begin
12892             GNAT_Pragma;
12893             Check_Arg_Order ((Name_Name, Name_State));
12894             Check_Arg_Count (2);
12895
12896             Check_Optional_Identifier (Arg1, Name_Name);
12897             Check_Optional_Identifier (Arg2, Name_State);
12898             Check_Arg_Is_Identifier (Arg2);
12899
12900             --  First argument is identifier
12901
12902             if Nkind (Arg1X) = N_Identifier then
12903
12904                --  Search list of names in Ada.Interrupts.Names
12905
12906                Int_Ent := First_Entity (RTE (RE_Names));
12907                loop
12908                   if No (Int_Ent) then
12909                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
12910
12911                   elsif Chars (Int_Ent) = Chars (Arg1X) then
12912                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
12913                      exit;
12914                   end if;
12915
12916                   Next_Entity (Int_Ent);
12917                end loop;
12918
12919             --  First argument is not an identifier, so it must be a static
12920             --  expression of type Ada.Interrupts.Interrupt_ID.
12921
12922             else
12923                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
12924                Int_Val := Expr_Value (Arg1X);
12925
12926                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
12927                     or else
12928                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
12929                then
12930                   Error_Pragma_Arg
12931                     ("value not in range of type "
12932                      & """Ada.Interrupts.Interrupt_'I'D""", Arg1);
12933                end if;
12934             end if;
12935
12936             --  Check OK state
12937
12938             case Chars (Get_Pragma_Arg (Arg2)) is
12939                when Name_Runtime => State_Type := 'r';
12940                when Name_System  => State_Type := 's';
12941                when Name_User    => State_Type := 'u';
12942
12943                when others =>
12944                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
12945             end case;
12946
12947             --  Check if entry is already stored
12948
12949             IST_Num := Interrupt_States.First;
12950             loop
12951                --  If entry not found, add it
12952
12953                if IST_Num > Interrupt_States.Last then
12954                   Interrupt_States.Append
12955                     ((Interrupt_Number => UI_To_Int (Int_Val),
12956                       Interrupt_State  => State_Type,
12957                       Pragma_Loc       => Loc));
12958                   exit;
12959
12960                --  Case of entry for the same entry
12961
12962                elsif Int_Val = Interrupt_States.Table (IST_Num).
12963                                                            Interrupt_Number
12964                then
12965                   --  If state matches, done, no need to make redundant entry
12966
12967                   exit when
12968                     State_Type = Interrupt_States.Table (IST_Num).
12969                                                            Interrupt_State;
12970
12971                   --  Otherwise if state does not match, error
12972
12973                   Error_Msg_Sloc :=
12974                     Interrupt_States.Table (IST_Num).Pragma_Loc;
12975                   Error_Pragma_Arg
12976                     ("state conflicts with that given #", Arg2);
12977                   exit;
12978                end if;
12979
12980                IST_Num := IST_Num + 1;
12981             end loop;
12982          end Interrupt_State;
12983
12984          ---------------
12985          -- Invariant --
12986          ---------------
12987
12988          --  pragma Invariant
12989          --    ([Entity =>]    type_LOCAL_NAME,
12990          --     [Check  =>]    EXPRESSION
12991          --     [,[Message =>] String_Expression]);
12992
12993          when Pragma_Invariant => Invariant : declare
12994             Type_Id : Node_Id;
12995             Typ     : Entity_Id;
12996             PDecl   : Node_Id;
12997
12998             Discard : Boolean;
12999             pragma Unreferenced (Discard);
13000
13001          begin
13002             GNAT_Pragma;
13003             Check_At_Least_N_Arguments (2);
13004             Check_At_Most_N_Arguments (3);
13005             Check_Optional_Identifier (Arg1, Name_Entity);
13006             Check_Optional_Identifier (Arg2, Name_Check);
13007
13008             if Arg_Count = 3 then
13009                Check_Optional_Identifier (Arg3, Name_Message);
13010                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
13011             end if;
13012
13013             Check_Arg_Is_Local_Name (Arg1);
13014
13015             Type_Id := Get_Pragma_Arg (Arg1);
13016             Find_Type (Type_Id);
13017             Typ := Entity (Type_Id);
13018
13019             if Typ = Any_Type then
13020                return;
13021
13022             --  An invariant must apply to a private type, or appear in the
13023             --  private part of a package spec and apply to a completion.
13024
13025             elsif Ekind_In (Typ, E_Private_Type,
13026                                  E_Record_Type_With_Private,
13027                                  E_Limited_Private_Type)
13028             then
13029                null;
13030
13031             elsif In_Private_Part (Current_Scope)
13032               and then Has_Private_Declaration (Typ)
13033             then
13034                null;
13035
13036             elsif In_Private_Part (Current_Scope) then
13037                Error_Pragma_Arg
13038                  ("pragma% only allowed for private type declared in "
13039                   & "visible part", Arg1);
13040
13041             else
13042                Error_Pragma_Arg
13043                  ("pragma% only allowed for private type", Arg1);
13044             end if;
13045
13046             --  Note that the type has at least one invariant, and also that
13047             --  it has inheritable invariants if we have Invariant'Class
13048             --  or Type_Invariant'Class. Build the corresponding invariant
13049             --  procedure declaration, so that calls to it can be generated
13050             --  before the body is built (e.g. within an expression function).
13051
13052             PDecl := Build_Invariant_Procedure_Declaration (Typ);
13053
13054             Insert_After (N, PDecl);
13055             Analyze (PDecl);
13056
13057             if Class_Present (N) then
13058                Set_Has_Inheritable_Invariants (Typ);
13059             end if;
13060
13061             --  The remaining processing is simply to link the pragma on to
13062             --  the rep item chain, for processing when the type is frozen.
13063             --  This is accomplished by a call to Rep_Item_Too_Late.
13064
13065             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
13066          end Invariant;
13067
13068          ----------------------
13069          -- Java_Constructor --
13070          ----------------------
13071
13072          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
13073
13074          --  Also handles pragma CIL_Constructor
13075
13076          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
13077          Java_Constructor : declare
13078             Convention  : Convention_Id;
13079             Def_Id      : Entity_Id;
13080             Hom_Id      : Entity_Id;
13081             Id          : Entity_Id;
13082             This_Formal : Entity_Id;
13083
13084          begin
13085             GNAT_Pragma;
13086             Check_Arg_Count (1);
13087             Check_Optional_Identifier (Arg1, Name_Entity);
13088             Check_Arg_Is_Local_Name (Arg1);
13089
13090             Id := Get_Pragma_Arg (Arg1);
13091             Find_Program_Unit_Name (Id);
13092
13093             --  If we did not find the name, we are done
13094
13095             if Etype (Id) = Any_Type then
13096                return;
13097             end if;
13098
13099             --  Check wrong use of pragma in wrong VM target
13100
13101             if VM_Target = No_VM then
13102                return;
13103
13104             elsif VM_Target = CLI_Target
13105               and then Prag_Id = Pragma_Java_Constructor
13106             then
13107                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
13108
13109             elsif VM_Target = JVM_Target
13110               and then Prag_Id = Pragma_CIL_Constructor
13111             then
13112                Error_Pragma ("must use pragma 'Java_'Constructor");
13113             end if;
13114
13115             case Prag_Id is
13116                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
13117                when Pragma_Java_Constructor => Convention := Convention_Java;
13118                when others                  => null;
13119             end case;
13120
13121             Hom_Id := Entity (Id);
13122
13123             --  Loop through homonyms
13124
13125             loop
13126                Def_Id := Get_Base_Subprogram (Hom_Id);
13127
13128                --  The constructor is required to be a function
13129
13130                if Ekind (Def_Id) /= E_Function then
13131                   if VM_Target = JVM_Target then
13132                      Error_Pragma_Arg
13133                        ("pragma% requires function returning a 'Java access "
13134                         & "type", Def_Id);
13135                   else
13136                      Error_Pragma_Arg
13137                        ("pragma% requires function returning a 'C'I'L access "
13138                         & "type", Def_Id);
13139                   end if;
13140                end if;
13141
13142                --  Check arguments: For tagged type the first formal must be
13143                --  named "this" and its type must be a named access type
13144                --  designating a class-wide tagged type that has convention
13145                --  CIL/Java. The first formal must also have a null default
13146                --  value. For example:
13147
13148                --      type Typ is tagged ...
13149                --      type Ref is access all Typ;
13150                --      pragma Convention (CIL, Typ);
13151
13152                --      function New_Typ (This : Ref) return Ref;
13153                --      function New_Typ (This : Ref; I : Integer) return Ref;
13154                --      pragma Cil_Constructor (New_Typ);
13155
13156                --  Reason: The first formal must NOT be a primitive of the
13157                --  tagged type.
13158
13159                --  This rule also applies to constructors of delegates used
13160                --  to interface with standard target libraries. For example:
13161
13162                --      type Delegate is access procedure ...
13163                --      pragma Import (CIL, Delegate, ...);
13164
13165                --      function new_Delegate
13166                --        (This : Delegate := null; ... ) return Delegate;
13167
13168                --  For value-types this rule does not apply.
13169
13170                if not Is_Value_Type (Etype (Def_Id)) then
13171                   if No (First_Formal (Def_Id)) then
13172                      Error_Msg_Name_1 := Pname;
13173                      Error_Msg_N ("% function must have parameters", Def_Id);
13174                      return;
13175                   end if;
13176
13177                   --  In the JRE library we have several occurrences in which
13178                   --  the "this" parameter is not the first formal.
13179
13180                   This_Formal := First_Formal (Def_Id);
13181
13182                   --  In the JRE library we have several occurrences in which
13183                   --  the "this" parameter is not the first formal. Search for
13184                   --  it.
13185
13186                   if VM_Target = JVM_Target then
13187                      while Present (This_Formal)
13188                        and then Get_Name_String (Chars (This_Formal)) /= "this"
13189                      loop
13190                         Next_Formal (This_Formal);
13191                      end loop;
13192
13193                      if No (This_Formal) then
13194                         This_Formal := First_Formal (Def_Id);
13195                      end if;
13196                   end if;
13197
13198                   --  Warning: The first parameter should be named "this".
13199                   --  We temporarily allow it because we have the following
13200                   --  case in the Java runtime (file s-osinte.ads) ???
13201
13202                   --    function new_Thread
13203                   --      (Self_Id : System.Address) return Thread_Id;
13204                   --    pragma Java_Constructor (new_Thread);
13205
13206                   if VM_Target = JVM_Target
13207                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
13208                                = "self_id"
13209                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
13210                   then
13211                      null;
13212
13213                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
13214                      Error_Msg_Name_1 := Pname;
13215                      Error_Msg_N
13216                        ("first formal of % function must be named `this`",
13217                         Parent (This_Formal));
13218
13219                   elsif not Is_Access_Type (Etype (This_Formal)) then
13220                      Error_Msg_Name_1 := Pname;
13221                      Error_Msg_N
13222                        ("first formal of % function must be an access type",
13223                         Parameter_Type (Parent (This_Formal)));
13224
13225                   --  For delegates the type of the first formal must be a
13226                   --  named access-to-subprogram type (see previous example)
13227
13228                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
13229                     and then Ekind (Etype (This_Formal))
13230                                /= E_Access_Subprogram_Type
13231                   then
13232                      Error_Msg_Name_1 := Pname;
13233                      Error_Msg_N
13234                        ("first formal of % function must be a named access "
13235                         & "to subprogram type",
13236                         Parameter_Type (Parent (This_Formal)));
13237
13238                   --  Warning: We should reject anonymous access types because
13239                   --  the constructor must not be handled as a primitive of the
13240                   --  tagged type. We temporarily allow it because this profile
13241                   --  is currently generated by cil2ada???
13242
13243                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
13244                     and then not Ekind_In (Etype (This_Formal),
13245                                              E_Access_Type,
13246                                              E_General_Access_Type,
13247                                              E_Anonymous_Access_Type)
13248                   then
13249                      Error_Msg_Name_1 := Pname;
13250                      Error_Msg_N
13251                        ("first formal of % function must be a named access "
13252                         & "type", Parameter_Type (Parent (This_Formal)));
13253
13254                   elsif Atree.Convention
13255                          (Designated_Type (Etype (This_Formal))) /= Convention
13256                   then
13257                      Error_Msg_Name_1 := Pname;
13258
13259                      if Convention = Convention_Java then
13260                         Error_Msg_N
13261                           ("pragma% requires convention 'Cil in designated "
13262                            & "type", Parameter_Type (Parent (This_Formal)));
13263                      else
13264                         Error_Msg_N
13265                           ("pragma% requires convention 'Java in designated "
13266                            & "type", Parameter_Type (Parent (This_Formal)));
13267                      end if;
13268
13269                   elsif No (Expression (Parent (This_Formal)))
13270                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
13271                   then
13272                      Error_Msg_Name_1 := Pname;
13273                      Error_Msg_N
13274                        ("pragma% requires first formal with default `null`",
13275                         Parameter_Type (Parent (This_Formal)));
13276                   end if;
13277                end if;
13278
13279                --  Check result type: the constructor must be a function
13280                --  returning:
13281                --   * a value type (only allowed in the CIL compiler)
13282                --   * an access-to-subprogram type with convention Java/CIL
13283                --   * an access-type designating a type that has convention
13284                --     Java/CIL.
13285
13286                if Is_Value_Type (Etype (Def_Id)) then
13287                   null;
13288
13289                --  Access-to-subprogram type with convention Java/CIL
13290
13291                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
13292                   if Atree.Convention (Etype (Def_Id)) /= Convention then
13293                      if Convention = Convention_Java then
13294                         Error_Pragma_Arg
13295                           ("pragma% requires function returning a 'Java "
13296                            & "access type", Arg1);
13297                      else
13298                         pragma Assert (Convention = Convention_CIL);
13299                         Error_Pragma_Arg
13300                           ("pragma% requires function returning a 'C'I'L "
13301                            & "access type", Arg1);
13302                      end if;
13303                   end if;
13304
13305                elsif Ekind (Etype (Def_Id)) in Access_Kind then
13306                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
13307                                                    E_General_Access_Type)
13308                     or else
13309                       Atree.Convention
13310                         (Designated_Type (Etype (Def_Id))) /= Convention
13311                   then
13312                      Error_Msg_Name_1 := Pname;
13313
13314                      if Convention = Convention_Java then
13315                         Error_Pragma_Arg
13316                           ("pragma% requires function returning a named "
13317                            & "'Java access type", Arg1);
13318                      else
13319                         Error_Pragma_Arg
13320                           ("pragma% requires function returning a named "
13321                            & "'C'I'L access type", Arg1);
13322                      end if;
13323                   end if;
13324                end if;
13325
13326                Set_Is_Constructor (Def_Id);
13327                Set_Convention     (Def_Id, Convention);
13328                Set_Is_Imported    (Def_Id);
13329
13330                exit when From_Aspect_Specification (N);
13331                Hom_Id := Homonym (Hom_Id);
13332
13333                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
13334             end loop;
13335          end Java_Constructor;
13336
13337          ----------------------
13338          -- Java_Interface --
13339          ----------------------
13340
13341          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
13342
13343          when Pragma_Java_Interface => Java_Interface : declare
13344             Arg : Node_Id;
13345             Typ : Entity_Id;
13346
13347          begin
13348             GNAT_Pragma;
13349             Check_Arg_Count (1);
13350             Check_Optional_Identifier (Arg1, Name_Entity);
13351             Check_Arg_Is_Local_Name (Arg1);
13352
13353             Arg := Get_Pragma_Arg (Arg1);
13354             Analyze (Arg);
13355
13356             if Etype (Arg) = Any_Type then
13357                return;
13358             end if;
13359
13360             if not Is_Entity_Name (Arg)
13361               or else not Is_Type (Entity (Arg))
13362             then
13363                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
13364             end if;
13365
13366             Typ := Underlying_Type (Entity (Arg));
13367
13368             --  For now simply check some of the semantic constraints on the
13369             --  type. This currently leaves out some restrictions on interface
13370             --  types, namely that the parent type must be java.lang.Object.Typ
13371             --  and that all primitives of the type should be declared
13372             --  abstract. ???
13373
13374             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
13375                Error_Pragma_Arg
13376                  ("pragma% requires an abstract tagged type", Arg1);
13377
13378             elsif not Has_Discriminants (Typ)
13379               or else Ekind (Etype (First_Discriminant (Typ)))
13380                         /= E_Anonymous_Access_Type
13381               or else
13382                 not Is_Class_Wide_Type
13383                       (Designated_Type (Etype (First_Discriminant (Typ))))
13384             then
13385                Error_Pragma_Arg
13386                  ("type must have a class-wide access discriminant", Arg1);
13387             end if;
13388          end Java_Interface;
13389
13390          ----------------
13391          -- Keep_Names --
13392          ----------------
13393
13394          --  pragma Keep_Names ([On => ] local_NAME);
13395
13396          when Pragma_Keep_Names => Keep_Names : declare
13397             Arg : Node_Id;
13398
13399          begin
13400             GNAT_Pragma;
13401             Check_Arg_Count (1);
13402             Check_Optional_Identifier (Arg1, Name_On);
13403             Check_Arg_Is_Local_Name (Arg1);
13404
13405             Arg := Get_Pragma_Arg (Arg1);
13406             Analyze (Arg);
13407
13408             if Etype (Arg) = Any_Type then
13409                return;
13410             end if;
13411
13412             if not Is_Entity_Name (Arg)
13413               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
13414             then
13415                Error_Pragma_Arg
13416                  ("pragma% requires a local enumeration type", Arg1);
13417             end if;
13418
13419             Set_Discard_Names (Entity (Arg), False);
13420          end Keep_Names;
13421
13422          -------------
13423          -- License --
13424          -------------
13425
13426          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
13427
13428          when Pragma_License =>
13429             GNAT_Pragma;
13430             Check_Arg_Count (1);
13431             Check_No_Identifiers;
13432             Check_Valid_Configuration_Pragma;
13433             Check_Arg_Is_Identifier (Arg1);
13434
13435             declare
13436                Sind : constant Source_File_Index :=
13437                         Source_Index (Current_Sem_Unit);
13438
13439             begin
13440                case Chars (Get_Pragma_Arg (Arg1)) is
13441                   when Name_GPL =>
13442                      Set_License (Sind, GPL);
13443
13444                   when Name_Modified_GPL =>
13445                      Set_License (Sind, Modified_GPL);
13446
13447                   when Name_Restricted =>
13448                      Set_License (Sind, Restricted);
13449
13450                   when Name_Unrestricted =>
13451                      Set_License (Sind, Unrestricted);
13452
13453                   when others =>
13454                      Error_Pragma_Arg ("invalid license name", Arg1);
13455                end case;
13456             end;
13457
13458          ---------------
13459          -- Link_With --
13460          ---------------
13461
13462          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
13463
13464          when Pragma_Link_With => Link_With : declare
13465             Arg : Node_Id;
13466
13467          begin
13468             GNAT_Pragma;
13469
13470             if Operating_Mode = Generate_Code
13471               and then In_Extended_Main_Source_Unit (N)
13472             then
13473                Check_At_Least_N_Arguments (1);
13474                Check_No_Identifiers;
13475                Check_Is_In_Decl_Part_Or_Package_Spec;
13476                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13477                Start_String;
13478
13479                Arg := Arg1;
13480                while Present (Arg) loop
13481                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
13482
13483                   --  Store argument, converting sequences of spaces to a
13484                   --  single null character (this is one of the differences
13485                   --  in processing between Link_With and Linker_Options).
13486
13487                   Arg_Store : declare
13488                      C : constant Char_Code := Get_Char_Code (' ');
13489                      S : constant String_Id :=
13490                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
13491                      L : constant Nat := String_Length (S);
13492                      F : Nat := 1;
13493
13494                      procedure Skip_Spaces;
13495                      --  Advance F past any spaces
13496
13497                      -----------------
13498                      -- Skip_Spaces --
13499                      -----------------
13500
13501                      procedure Skip_Spaces is
13502                      begin
13503                         while F <= L and then Get_String_Char (S, F) = C loop
13504                            F := F + 1;
13505                         end loop;
13506                      end Skip_Spaces;
13507
13508                   --  Start of processing for Arg_Store
13509
13510                   begin
13511                      Skip_Spaces; -- skip leading spaces
13512
13513                      --  Loop through characters, changing any embedded
13514                      --  sequence of spaces to a single null character (this
13515                      --  is how Link_With/Linker_Options differ)
13516
13517                      while F <= L loop
13518                         if Get_String_Char (S, F) = C then
13519                            Skip_Spaces;
13520                            exit when F > L;
13521                            Store_String_Char (ASCII.NUL);
13522
13523                         else
13524                            Store_String_Char (Get_String_Char (S, F));
13525                            F := F + 1;
13526                         end if;
13527                      end loop;
13528                   end Arg_Store;
13529
13530                   Arg := Next (Arg);
13531
13532                   if Present (Arg) then
13533                      Store_String_Char (ASCII.NUL);
13534                   end if;
13535                end loop;
13536
13537                Store_Linker_Option_String (End_String);
13538             end if;
13539          end Link_With;
13540
13541          ------------------
13542          -- Linker_Alias --
13543          ------------------
13544
13545          --  pragma Linker_Alias (
13546          --      [Entity =>]  LOCAL_NAME
13547          --      [Target =>]  static_string_EXPRESSION);
13548
13549          when Pragma_Linker_Alias =>
13550             GNAT_Pragma;
13551             Check_Arg_Order ((Name_Entity, Name_Target));
13552             Check_Arg_Count (2);
13553             Check_Optional_Identifier (Arg1, Name_Entity);
13554             Check_Optional_Identifier (Arg2, Name_Target);
13555             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13556             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13557
13558             --  The only processing required is to link this item on to the
13559             --  list of rep items for the given entity. This is accomplished
13560             --  by the call to Rep_Item_Too_Late (when no error is detected
13561             --  and False is returned).
13562
13563             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13564                return;
13565             else
13566                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13567             end if;
13568
13569          ------------------------
13570          -- Linker_Constructor --
13571          ------------------------
13572
13573          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
13574
13575          --  Code is shared with Linker_Destructor
13576
13577          -----------------------
13578          -- Linker_Destructor --
13579          -----------------------
13580
13581          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
13582
13583          when Pragma_Linker_Constructor |
13584               Pragma_Linker_Destructor =>
13585          Linker_Constructor : declare
13586             Arg1_X : Node_Id;
13587             Proc   : Entity_Id;
13588
13589          begin
13590             GNAT_Pragma;
13591             Check_Arg_Count (1);
13592             Check_No_Identifiers;
13593             Check_Arg_Is_Local_Name (Arg1);
13594             Arg1_X := Get_Pragma_Arg (Arg1);
13595             Analyze (Arg1_X);
13596             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
13597
13598             if not Is_Library_Level_Entity (Proc) then
13599                Error_Pragma_Arg
13600                 ("argument for pragma% must be library level entity", Arg1);
13601             end if;
13602
13603             --  The only processing required is to link this item on to the
13604             --  list of rep items for the given entity. This is accomplished
13605             --  by the call to Rep_Item_Too_Late (when no error is detected
13606             --  and False is returned).
13607
13608             if Rep_Item_Too_Late (Proc, N) then
13609                return;
13610             else
13611                Set_Has_Gigi_Rep_Item (Proc);
13612             end if;
13613          end Linker_Constructor;
13614
13615          --------------------
13616          -- Linker_Options --
13617          --------------------
13618
13619          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
13620
13621          when Pragma_Linker_Options => Linker_Options : declare
13622             Arg : Node_Id;
13623
13624          begin
13625             Check_Ada_83_Warning;
13626             Check_No_Identifiers;
13627             Check_Arg_Count (1);
13628             Check_Is_In_Decl_Part_Or_Package_Spec;
13629             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13630             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
13631
13632             Arg := Arg2;
13633             while Present (Arg) loop
13634                Check_Arg_Is_Static_Expression (Arg, Standard_String);
13635                Store_String_Char (ASCII.NUL);
13636                Store_String_Chars
13637                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
13638                Arg := Next (Arg);
13639             end loop;
13640
13641             if Operating_Mode = Generate_Code
13642               and then In_Extended_Main_Source_Unit (N)
13643             then
13644                Store_Linker_Option_String (End_String);
13645             end if;
13646          end Linker_Options;
13647
13648          --------------------
13649          -- Linker_Section --
13650          --------------------
13651
13652          --  pragma Linker_Section (
13653          --      [Entity  =>]  LOCAL_NAME
13654          --      [Section =>]  static_string_EXPRESSION);
13655
13656          when Pragma_Linker_Section =>
13657             GNAT_Pragma;
13658             Check_Arg_Order ((Name_Entity, Name_Section));
13659             Check_Arg_Count (2);
13660             Check_Optional_Identifier (Arg1, Name_Entity);
13661             Check_Optional_Identifier (Arg2, Name_Section);
13662             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13663             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13664
13665             --  This pragma applies only to objects
13666
13667             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
13668                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
13669             end if;
13670
13671             --  The only processing required is to link this item on to the
13672             --  list of rep items for the given entity. This is accomplished
13673             --  by the call to Rep_Item_Too_Late (when no error is detected
13674             --  and False is returned).
13675
13676             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
13677                return;
13678             else
13679                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13680             end if;
13681
13682          ----------
13683          -- List --
13684          ----------
13685
13686          --  pragma List (On | Off)
13687
13688          --  There is nothing to do here, since we did all the processing for
13689          --  this pragma in Par.Prag (so that it works properly even in syntax
13690          --  only mode).
13691
13692          when Pragma_List =>
13693             null;
13694
13695          ---------------
13696          -- Lock_Free --
13697          ---------------
13698
13699          --  pragma Lock_Free [(Boolean_EXPRESSION)];
13700
13701          when Pragma_Lock_Free => Lock_Free : declare
13702             P   : constant Node_Id := Parent (N);
13703             Arg : Node_Id;
13704             Ent : Entity_Id;
13705             Val : Boolean;
13706
13707          begin
13708             Check_No_Identifiers;
13709             Check_At_Most_N_Arguments (1);
13710
13711             --  Protected definition case
13712
13713             if Nkind (P) = N_Protected_Definition then
13714                Ent := Defining_Identifier (Parent (P));
13715
13716                --  One argument
13717
13718                if Arg_Count = 1 then
13719                   Arg := Get_Pragma_Arg (Arg1);
13720                   Val := Is_True (Static_Boolean (Arg));
13721
13722                --  No arguments (expression is considered to be True)
13723
13724                else
13725                   Val := True;
13726                end if;
13727
13728                --  Check duplicate pragma before we chain the pragma in the Rep
13729                --  Item chain of Ent.
13730
13731                Check_Duplicate_Pragma (Ent);
13732                Record_Rep_Item        (Ent, N);
13733                Set_Uses_Lock_Free     (Ent, Val);
13734
13735             --  Anything else is incorrect placement
13736
13737             else
13738                Pragma_Misplaced;
13739             end if;
13740          end Lock_Free;
13741
13742          --------------------
13743          -- Locking_Policy --
13744          --------------------
13745
13746          --  pragma Locking_Policy (policy_IDENTIFIER);
13747
13748          when Pragma_Locking_Policy => declare
13749             subtype LP_Range is Name_Id
13750               range First_Locking_Policy_Name .. Last_Locking_Policy_Name;
13751             LP_Val : LP_Range;
13752             LP     : Character;
13753
13754          begin
13755             Check_Ada_83_Warning;
13756             Check_Arg_Count (1);
13757             Check_No_Identifiers;
13758             Check_Arg_Is_Locking_Policy (Arg1);
13759             Check_Valid_Configuration_Pragma;
13760             LP_Val := Chars (Get_Pragma_Arg (Arg1));
13761
13762             case LP_Val is
13763                when Name_Ceiling_Locking            =>
13764                   LP := 'C';
13765                when Name_Inheritance_Locking        =>
13766                   LP := 'I';
13767                when Name_Concurrent_Readers_Locking =>
13768                   LP := 'R';
13769             end case;
13770
13771             if Locking_Policy /= ' '
13772               and then Locking_Policy /= LP
13773             then
13774                Error_Msg_Sloc := Locking_Policy_Sloc;
13775                Error_Pragma ("locking policy incompatible with policy#");
13776
13777             --  Set new policy, but always preserve System_Location since we
13778             --  like the error message with the run time name.
13779
13780             else
13781                Locking_Policy := LP;
13782
13783                if Locking_Policy_Sloc /= System_Location then
13784                   Locking_Policy_Sloc := Loc;
13785                end if;
13786             end if;
13787          end;
13788
13789          ----------------
13790          -- Long_Float --
13791          ----------------
13792
13793          --  pragma Long_Float (D_Float | G_Float);
13794
13795          when Pragma_Long_Float => Long_Float : declare
13796          begin
13797             GNAT_Pragma;
13798             Check_Valid_Configuration_Pragma;
13799             Check_Arg_Count (1);
13800             Check_No_Identifier (Arg1);
13801             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
13802
13803             if not OpenVMS_On_Target then
13804                Error_Pragma ("??pragma% ignored (applies only to Open'V'M'S)");
13805             end if;
13806
13807             --  D_Float case
13808
13809             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
13810                if Opt.Float_Format_Long = 'G' then
13811                   Error_Pragma_Arg
13812                     ("G_Float previously specified", Arg1);
13813
13814                elsif Current_Sem_Unit /= Main_Unit
13815                  and then Opt.Float_Format_Long /= 'D'
13816                then
13817                   Error_Pragma_Arg
13818                     ("main unit not compiled with pragma Long_Float (D_Float)",
13819                      "\pragma% must be used consistently for whole partition",
13820                      Arg1);
13821
13822                else
13823                   Opt.Float_Format_Long := 'D';
13824                end if;
13825
13826             --  G_Float case (this is the default, does not need overriding)
13827
13828             else
13829                if Opt.Float_Format_Long = 'D' then
13830                   Error_Pragma ("D_Float previously specified");
13831
13832                elsif Current_Sem_Unit /= Main_Unit
13833                  and then Opt.Float_Format_Long /= 'G'
13834                then
13835                   Error_Pragma_Arg
13836                     ("main unit not compiled with pragma Long_Float (G_Float)",
13837                      "\pragma% must be used consistently for whole partition",
13838                      Arg1);
13839
13840                else
13841                   Opt.Float_Format_Long := 'G';
13842                end if;
13843             end if;
13844
13845             Set_Standard_Fpt_Formats;
13846          end Long_Float;
13847
13848          -------------------
13849          -- Loop_Optimize --
13850          -------------------
13851
13852          --  pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
13853
13854          --  OPTIMIZATION_HINT ::= No_Unroll | Unroll | No_Vector | Vector
13855
13856          when Pragma_Loop_Optimize => Loop_Optimize : declare
13857             Hint : Node_Id;
13858
13859          begin
13860             GNAT_Pragma;
13861             Check_At_Least_N_Arguments (1);
13862             Check_No_Identifiers;
13863
13864             Hint := First (Pragma_Argument_Associations (N));
13865             while Present (Hint) loop
13866                Check_Arg_Is_One_Of (Hint,
13867                  Name_No_Unroll, Name_Unroll, Name_No_Vector, Name_Vector);
13868                Next (Hint);
13869             end loop;
13870
13871             Check_Loop_Pragma_Placement;
13872          end Loop_Optimize;
13873
13874          ------------------
13875          -- Loop_Variant --
13876          ------------------
13877
13878          --  pragma Loop_Variant
13879          --         ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
13880
13881          --  LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
13882
13883          --  CHANGE_DIRECTION ::= Increases | Decreases
13884
13885          when Pragma_Loop_Variant => Loop_Variant : declare
13886             Variant : Node_Id;
13887
13888          begin
13889             GNAT_Pragma;
13890             Check_At_Least_N_Arguments (1);
13891             Check_Loop_Pragma_Placement;
13892
13893             --  Process all increasing / decreasing expressions
13894
13895             Variant := First (Pragma_Argument_Associations (N));
13896             while Present (Variant) loop
13897                if not Nam_In (Chars (Variant), Name_Decreases,
13898                                                Name_Increases)
13899                then
13900                   Error_Pragma_Arg ("wrong change modifier", Variant);
13901                end if;
13902
13903                Preanalyze_Assert_Expression
13904                  (Expression (Variant), Any_Discrete);
13905
13906                Next (Variant);
13907             end loop;
13908          end Loop_Variant;
13909
13910          -----------------------
13911          -- Machine_Attribute --
13912          -----------------------
13913
13914          --  pragma Machine_Attribute (
13915          --       [Entity         =>] LOCAL_NAME,
13916          --       [Attribute_Name =>] static_string_EXPRESSION
13917          --    [, [Info           =>] static_EXPRESSION] );
13918
13919          when Pragma_Machine_Attribute => Machine_Attribute : declare
13920             Def_Id : Entity_Id;
13921
13922          begin
13923             GNAT_Pragma;
13924             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
13925
13926             if Arg_Count = 3 then
13927                Check_Optional_Identifier (Arg3, Name_Info);
13928                Check_Arg_Is_Static_Expression (Arg3);
13929             else
13930                Check_Arg_Count (2);
13931             end if;
13932
13933             Check_Optional_Identifier (Arg1, Name_Entity);
13934             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
13935             Check_Arg_Is_Local_Name (Arg1);
13936             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
13937             Def_Id := Entity (Get_Pragma_Arg (Arg1));
13938
13939             if Is_Access_Type (Def_Id) then
13940                Def_Id := Designated_Type (Def_Id);
13941             end if;
13942
13943             if Rep_Item_Too_Early (Def_Id, N) then
13944                return;
13945             end if;
13946
13947             Def_Id := Underlying_Type (Def_Id);
13948
13949             --  The only processing required is to link this item on to the
13950             --  list of rep items for the given entity. This is accomplished
13951             --  by the call to Rep_Item_Too_Late (when no error is detected
13952             --  and False is returned).
13953
13954             if Rep_Item_Too_Late (Def_Id, N) then
13955                return;
13956             else
13957                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
13958             end if;
13959          end Machine_Attribute;
13960
13961          ----------
13962          -- Main --
13963          ----------
13964
13965          --  pragma Main
13966          --   (MAIN_OPTION [, MAIN_OPTION]);
13967
13968          --  MAIN_OPTION ::=
13969          --    [STACK_SIZE              =>] static_integer_EXPRESSION
13970          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
13971          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
13972
13973          when Pragma_Main => Main : declare
13974             Args  : Args_List (1 .. 3);
13975             Names : constant Name_List (1 .. 3) := (
13976                       Name_Stack_Size,
13977                       Name_Task_Stack_Size_Default,
13978                       Name_Time_Slicing_Enabled);
13979
13980             Nod : Node_Id;
13981
13982          begin
13983             GNAT_Pragma;
13984             Gather_Associations (Names, Args);
13985
13986             for J in 1 .. 2 loop
13987                if Present (Args (J)) then
13988                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
13989                end if;
13990             end loop;
13991
13992             if Present (Args (3)) then
13993                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
13994             end if;
13995
13996             Nod := Next (N);
13997             while Present (Nod) loop
13998                if Nkind (Nod) = N_Pragma
13999                  and then Pragma_Name (Nod) = Name_Main
14000                then
14001                   Error_Msg_Name_1 := Pname;
14002                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
14003                end if;
14004
14005                Next (Nod);
14006             end loop;
14007          end Main;
14008
14009          ------------------
14010          -- Main_Storage --
14011          ------------------
14012
14013          --  pragma Main_Storage
14014          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
14015
14016          --  MAIN_STORAGE_OPTION ::=
14017          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
14018          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
14019
14020          when Pragma_Main_Storage => Main_Storage : declare
14021             Args  : Args_List (1 .. 2);
14022             Names : constant Name_List (1 .. 2) := (
14023                       Name_Working_Storage,
14024                       Name_Top_Guard);
14025
14026             Nod : Node_Id;
14027
14028          begin
14029             GNAT_Pragma;
14030             Gather_Associations (Names, Args);
14031
14032             for J in 1 .. 2 loop
14033                if Present (Args (J)) then
14034                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
14035                end if;
14036             end loop;
14037
14038             Check_In_Main_Program;
14039
14040             Nod := Next (N);
14041             while Present (Nod) loop
14042                if Nkind (Nod) = N_Pragma
14043                  and then Pragma_Name (Nod) = Name_Main_Storage
14044                then
14045                   Error_Msg_Name_1 := Pname;
14046                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
14047                end if;
14048
14049                Next (Nod);
14050             end loop;
14051          end Main_Storage;
14052
14053          -----------------
14054          -- Memory_Size --
14055          -----------------
14056
14057          --  pragma Memory_Size (NUMERIC_LITERAL)
14058
14059          when Pragma_Memory_Size =>
14060             GNAT_Pragma;
14061
14062             --  Memory size is simply ignored
14063
14064             Check_No_Identifiers;
14065             Check_Arg_Count (1);
14066             Check_Arg_Is_Integer_Literal (Arg1);
14067
14068          -------------
14069          -- No_Body --
14070          -------------
14071
14072          --  pragma No_Body;
14073
14074          --  The only correct use of this pragma is on its own in a file, in
14075          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
14076          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
14077          --  check for a file containing nothing but a No_Body pragma). If we
14078          --  attempt to process it during normal semantics processing, it means
14079          --  it was misplaced.
14080
14081          when Pragma_No_Body =>
14082             GNAT_Pragma;
14083             Pragma_Misplaced;
14084
14085          ---------------
14086          -- No_Inline --
14087          ---------------
14088
14089          --  pragma No_Inline ( NAME {, NAME} );
14090
14091          when Pragma_No_Inline =>
14092             GNAT_Pragma;
14093             Process_Inline (Suppressed);
14094
14095          ---------------
14096          -- No_Return --
14097          ---------------
14098
14099          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
14100
14101          when Pragma_No_Return => No_Return : declare
14102             Id    : Node_Id;
14103             E     : Entity_Id;
14104             Found : Boolean;
14105             Arg   : Node_Id;
14106
14107          begin
14108             Ada_2005_Pragma;
14109             Check_At_Least_N_Arguments (1);
14110
14111             --  Loop through arguments of pragma
14112
14113             Arg := Arg1;
14114             while Present (Arg) loop
14115                Check_Arg_Is_Local_Name (Arg);
14116                Id := Get_Pragma_Arg (Arg);
14117                Analyze (Id);
14118
14119                if not Is_Entity_Name (Id) then
14120                   Error_Pragma_Arg ("entity name required", Arg);
14121                end if;
14122
14123                if Etype (Id) = Any_Type then
14124                   raise Pragma_Exit;
14125                end if;
14126
14127                --  Loop to find matching procedures
14128
14129                E := Entity (Id);
14130                Found := False;
14131                while Present (E)
14132                  and then Scope (E) = Current_Scope
14133                loop
14134                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
14135                      Set_No_Return (E);
14136
14137                      --  Set flag on any alias as well
14138
14139                      if Is_Overloadable (E) and then Present (Alias (E)) then
14140                         Set_No_Return (Alias (E));
14141                      end if;
14142
14143                      Found := True;
14144                   end if;
14145
14146                   exit when From_Aspect_Specification (N);
14147                   E := Homonym (E);
14148                end loop;
14149
14150                if not Found then
14151                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
14152                end if;
14153
14154                Next (Arg);
14155             end loop;
14156          end No_Return;
14157
14158          -----------------
14159          -- No_Run_Time --
14160          -----------------
14161
14162          --  pragma No_Run_Time;
14163
14164          --  Note: this pragma is retained for backwards compatibility. See
14165          --  body of Rtsfind for full details on its handling.
14166
14167          when Pragma_No_Run_Time =>
14168             GNAT_Pragma;
14169             Check_Valid_Configuration_Pragma;
14170             Check_Arg_Count (0);
14171
14172             No_Run_Time_Mode           := True;
14173             Configurable_Run_Time_Mode := True;
14174
14175             --  Set Duration to 32 bits if word size is 32
14176
14177             if Ttypes.System_Word_Size = 32 then
14178                Duration_32_Bits_On_Target := True;
14179             end if;
14180
14181             --  Set appropriate restrictions
14182
14183             Set_Restriction (No_Finalization, N);
14184             Set_Restriction (No_Exception_Handlers, N);
14185             Set_Restriction (Max_Tasks, N, 0);
14186             Set_Restriction (No_Tasking, N);
14187
14188          ------------------------
14189          -- No_Strict_Aliasing --
14190          ------------------------
14191
14192          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
14193
14194          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
14195             E_Id : Entity_Id;
14196
14197          begin
14198             GNAT_Pragma;
14199             Check_At_Most_N_Arguments (1);
14200
14201             if Arg_Count = 0 then
14202                Check_Valid_Configuration_Pragma;
14203                Opt.No_Strict_Aliasing := True;
14204
14205             else
14206                Check_Optional_Identifier (Arg2, Name_Entity);
14207                Check_Arg_Is_Local_Name (Arg1);
14208                E_Id := Entity (Get_Pragma_Arg (Arg1));
14209
14210                if E_Id = Any_Type then
14211                   return;
14212                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
14213                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
14214                end if;
14215
14216                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
14217             end if;
14218          end No_Strict_Aliasing;
14219
14220          -----------------------
14221          -- Normalize_Scalars --
14222          -----------------------
14223
14224          --  pragma Normalize_Scalars;
14225
14226          when Pragma_Normalize_Scalars =>
14227             Check_Ada_83_Warning;
14228             Check_Arg_Count (0);
14229             Check_Valid_Configuration_Pragma;
14230
14231             --  Normalize_Scalars creates false positives in CodePeer, and
14232             --  incorrect negative results in SPARK mode, so ignore this pragma
14233             --  in these modes.
14234
14235             if not (CodePeer_Mode or SPARK_Mode) then
14236                Normalize_Scalars := True;
14237                Init_Or_Norm_Scalars := True;
14238             end if;
14239
14240          -----------------
14241          -- Obsolescent --
14242          -----------------
14243
14244          --  pragma Obsolescent;
14245
14246          --  pragma Obsolescent (
14247          --    [Message =>] static_string_EXPRESSION
14248          --  [,[Version =>] Ada_05]]);
14249
14250          --  pragma Obsolescent (
14251          --    [Entity  =>] NAME
14252          --  [,[Message =>] static_string_EXPRESSION
14253          --  [,[Version =>] Ada_05]] );
14254
14255          when Pragma_Obsolescent => Obsolescent : declare
14256             Ename : Node_Id;
14257             Decl  : Node_Id;
14258
14259             procedure Set_Obsolescent (E : Entity_Id);
14260             --  Given an entity Ent, mark it as obsolescent if appropriate
14261
14262             ---------------------
14263             -- Set_Obsolescent --
14264             ---------------------
14265
14266             procedure Set_Obsolescent (E : Entity_Id) is
14267                Active : Boolean;
14268                Ent    : Entity_Id;
14269                S      : String_Id;
14270
14271             begin
14272                Active := True;
14273                Ent    := E;
14274
14275                --  Entity name was given
14276
14277                if Present (Ename) then
14278
14279                   --  If entity name matches, we are fine. Save entity in
14280                   --  pragma argument, for ASIS use.
14281
14282                   if Chars (Ename) = Chars (Ent) then
14283                      Set_Entity (Ename, Ent);
14284                      Generate_Reference (Ent, Ename);
14285
14286                   --  If entity name does not match, only possibility is an
14287                   --  enumeration literal from an enumeration type declaration.
14288
14289                   elsif Ekind (Ent) /= E_Enumeration_Type then
14290                      Error_Pragma
14291                        ("pragma % entity name does not match declaration");
14292
14293                   else
14294                      Ent := First_Literal (E);
14295                      loop
14296                         if No (Ent) then
14297                            Error_Pragma
14298                              ("pragma % entity name does not match any "
14299                               & "enumeration literal");
14300
14301                         elsif Chars (Ent) = Chars (Ename) then
14302                            Set_Entity (Ename, Ent);
14303                            Generate_Reference (Ent, Ename);
14304                            exit;
14305
14306                         else
14307                            Ent := Next_Literal (Ent);
14308                         end if;
14309                      end loop;
14310                   end if;
14311                end if;
14312
14313                --  Ent points to entity to be marked
14314
14315                if Arg_Count >= 1 then
14316
14317                   --  Deal with static string argument
14318
14319                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
14320                   S := Strval (Get_Pragma_Arg (Arg1));
14321
14322                   for J in 1 .. String_Length (S) loop
14323                      if not In_Character_Range (Get_String_Char (S, J)) then
14324                         Error_Pragma_Arg
14325                           ("pragma% argument does not allow wide characters",
14326                            Arg1);
14327                      end if;
14328                   end loop;
14329
14330                   Obsolescent_Warnings.Append
14331                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
14332
14333                   --  Check for Ada_05 parameter
14334
14335                   if Arg_Count /= 1 then
14336                      Check_Arg_Count (2);
14337
14338                      declare
14339                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
14340
14341                      begin
14342                         Check_Arg_Is_Identifier (Argx);
14343
14344                         if Chars (Argx) /= Name_Ada_05 then
14345                            Error_Msg_Name_2 := Name_Ada_05;
14346                            Error_Pragma_Arg
14347                              ("only allowed argument for pragma% is %", Argx);
14348                         end if;
14349
14350                         if Ada_Version_Explicit < Ada_2005
14351                           or else not Warn_On_Ada_2005_Compatibility
14352                         then
14353                            Active := False;
14354                         end if;
14355                      end;
14356                   end if;
14357                end if;
14358
14359                --  Set flag if pragma active
14360
14361                if Active then
14362                   Set_Is_Obsolescent (Ent);
14363                end if;
14364
14365                return;
14366             end Set_Obsolescent;
14367
14368          --  Start of processing for pragma Obsolescent
14369
14370          begin
14371             GNAT_Pragma;
14372
14373             Check_At_Most_N_Arguments (3);
14374
14375             --  See if first argument specifies an entity name
14376
14377             if Arg_Count >= 1
14378               and then
14379                 (Chars (Arg1) = Name_Entity
14380                    or else
14381                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
14382                                                       N_Identifier,
14383                                                       N_Operator_Symbol))
14384             then
14385                Ename := Get_Pragma_Arg (Arg1);
14386
14387                --  Eliminate first argument, so we can share processing
14388
14389                Arg1 := Arg2;
14390                Arg2 := Arg3;
14391                Arg_Count := Arg_Count - 1;
14392
14393             --  No Entity name argument given
14394
14395             else
14396                Ename := Empty;
14397             end if;
14398
14399             if Arg_Count >= 1 then
14400                Check_Optional_Identifier (Arg1, Name_Message);
14401
14402                if Arg_Count = 2 then
14403                   Check_Optional_Identifier (Arg2, Name_Version);
14404                end if;
14405             end if;
14406
14407             --  Get immediately preceding declaration
14408
14409             Decl := Prev (N);
14410             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
14411                Prev (Decl);
14412             end loop;
14413
14414             --  Cases where we do not follow anything other than another pragma
14415
14416             if No (Decl) then
14417
14418                --  First case: library level compilation unit declaration with
14419                --  the pragma immediately following the declaration.
14420
14421                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
14422                   Set_Obsolescent
14423                     (Defining_Entity (Unit (Parent (Parent (N)))));
14424                   return;
14425
14426                --  Case 2: library unit placement for package
14427
14428                else
14429                   declare
14430                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
14431                   begin
14432                      if Is_Package_Or_Generic_Package (Ent) then
14433                         Set_Obsolescent (Ent);
14434                         return;
14435                      end if;
14436                   end;
14437                end if;
14438
14439             --  Cases where we must follow a declaration
14440
14441             else
14442                if         Nkind (Decl) not in N_Declaration
14443                  and then Nkind (Decl) not in N_Later_Decl_Item
14444                  and then Nkind (Decl) not in N_Generic_Declaration
14445                  and then Nkind (Decl) not in N_Renaming_Declaration
14446                then
14447                   Error_Pragma
14448                     ("pragma% misplaced, "
14449                      & "must immediately follow a declaration");
14450
14451                else
14452                   Set_Obsolescent (Defining_Entity (Decl));
14453                   return;
14454                end if;
14455             end if;
14456          end Obsolescent;
14457
14458          --------------
14459          -- Optimize --
14460          --------------
14461
14462          --  pragma Optimize (Time | Space | Off);
14463
14464          --  The actual check for optimize is done in Gigi. Note that this
14465          --  pragma does not actually change the optimization setting, it
14466          --  simply checks that it is consistent with the pragma.
14467
14468          when Pragma_Optimize =>
14469             Check_No_Identifiers;
14470             Check_Arg_Count (1);
14471             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
14472
14473          ------------------------
14474          -- Optimize_Alignment --
14475          ------------------------
14476
14477          --  pragma Optimize_Alignment (Time | Space | Off);
14478
14479          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
14480             GNAT_Pragma;
14481             Check_No_Identifiers;
14482             Check_Arg_Count (1);
14483             Check_Valid_Configuration_Pragma;
14484
14485             declare
14486                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
14487             begin
14488                case Nam is
14489                   when Name_Time =>
14490                      Opt.Optimize_Alignment := 'T';
14491                   when Name_Space =>
14492                      Opt.Optimize_Alignment := 'S';
14493                   when Name_Off =>
14494                      Opt.Optimize_Alignment := 'O';
14495                   when others =>
14496                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
14497                end case;
14498             end;
14499
14500             --  Set indication that mode is set locally. If we are in fact in a
14501             --  configuration pragma file, this setting is harmless since the
14502             --  switch will get reset anyway at the start of each unit.
14503
14504             Optimize_Alignment_Local := True;
14505          end Optimize_Alignment;
14506
14507          -------------
14508          -- Ordered --
14509          -------------
14510
14511          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
14512
14513          when Pragma_Ordered => Ordered : declare
14514             Assoc   : constant Node_Id := Arg1;
14515             Type_Id : Node_Id;
14516             Typ     : Entity_Id;
14517
14518          begin
14519             GNAT_Pragma;
14520             Check_No_Identifiers;
14521             Check_Arg_Count (1);
14522             Check_Arg_Is_Local_Name (Arg1);
14523
14524             Type_Id := Get_Pragma_Arg (Assoc);
14525             Find_Type (Type_Id);
14526             Typ := Entity (Type_Id);
14527
14528             if Typ = Any_Type then
14529                return;
14530             else
14531                Typ := Underlying_Type (Typ);
14532             end if;
14533
14534             if not Is_Enumeration_Type (Typ) then
14535                Error_Pragma ("pragma% must specify enumeration type");
14536             end if;
14537
14538             Check_First_Subtype (Arg1);
14539             Set_Has_Pragma_Ordered (Base_Type (Typ));
14540          end Ordered;
14541
14542          -------------------
14543          -- Overflow_Mode --
14544          -------------------
14545
14546          --  pragma Overflow_Mode
14547          --    ([General => ] MODE [, [Assertions => ] MODE]);
14548
14549          --  MODE := STRICT | MINIMIZED | ELIMINATED
14550
14551          --  Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
14552          --  since System.Bignums makes this assumption. This is true of nearly
14553          --  all (all?) targets.
14554
14555          when Pragma_Overflow_Mode => Overflow_Mode : declare
14556             function Get_Overflow_Mode
14557               (Name : Name_Id;
14558                Arg  : Node_Id) return Overflow_Mode_Type;
14559             --  Function to process one pragma argument, Arg. If an identifier
14560             --  is present, it must be Name. Mode type is returned if a valid
14561             --  argument exists, otherwise an error is signalled.
14562
14563             -----------------------
14564             -- Get_Overflow_Mode --
14565             -----------------------
14566
14567             function Get_Overflow_Mode
14568               (Name : Name_Id;
14569                Arg  : Node_Id) return Overflow_Mode_Type
14570             is
14571                Argx : constant Node_Id := Get_Pragma_Arg (Arg);
14572
14573             begin
14574                Check_Optional_Identifier (Arg, Name);
14575                Check_Arg_Is_Identifier (Argx);
14576
14577                if Chars (Argx) = Name_Strict then
14578                   return Strict;
14579
14580                elsif Chars (Argx) = Name_Minimized then
14581                   return Minimized;
14582
14583                elsif Chars (Argx) = Name_Eliminated then
14584                   if Ttypes.Standard_Long_Long_Integer_Size /= 64 then
14585                      Error_Pragma_Arg
14586                        ("Eliminated not implemented on this target", Argx);
14587                   else
14588                      return Eliminated;
14589                   end if;
14590
14591                else
14592                   Error_Pragma_Arg ("invalid argument for pragma%", Argx);
14593                end if;
14594             end Get_Overflow_Mode;
14595
14596          --  Start of processing for Overflow_Mode
14597
14598          begin
14599             GNAT_Pragma;
14600             Check_At_Least_N_Arguments (1);
14601             Check_At_Most_N_Arguments (2);
14602
14603             --  Process first argument
14604
14605             Scope_Suppress.Overflow_Mode_General :=
14606               Get_Overflow_Mode (Name_General, Arg1);
14607
14608             --  Case of only one argument
14609
14610             if Arg_Count = 1 then
14611                Scope_Suppress.Overflow_Mode_Assertions :=
14612                  Scope_Suppress.Overflow_Mode_General;
14613
14614             --  Case of two arguments present
14615
14616             else
14617                Scope_Suppress.Overflow_Mode_Assertions  :=
14618                  Get_Overflow_Mode (Name_Assertions, Arg2);
14619             end if;
14620          end Overflow_Mode;
14621
14622          --------------------------
14623          -- Overriding Renamings --
14624          --------------------------
14625
14626          --  pragma Overriding_Renamings;
14627
14628          when Pragma_Overriding_Renamings =>
14629             GNAT_Pragma;
14630             Check_Arg_Count (0);
14631             Check_Valid_Configuration_Pragma;
14632             Overriding_Renamings := True;
14633
14634          ----------
14635          -- Pack --
14636          ----------
14637
14638          --  pragma Pack (first_subtype_LOCAL_NAME);
14639
14640          when Pragma_Pack => Pack : declare
14641             Assoc   : constant Node_Id := Arg1;
14642             Type_Id : Node_Id;
14643             Typ     : Entity_Id;
14644             Ctyp    : Entity_Id;
14645             Ignore  : Boolean := False;
14646
14647          begin
14648             Check_No_Identifiers;
14649             Check_Arg_Count (1);
14650             Check_Arg_Is_Local_Name (Arg1);
14651
14652             Type_Id := Get_Pragma_Arg (Assoc);
14653             Find_Type (Type_Id);
14654             Typ := Entity (Type_Id);
14655
14656             if Typ = Any_Type
14657               or else Rep_Item_Too_Early (Typ, N)
14658             then
14659                return;
14660             else
14661                Typ := Underlying_Type (Typ);
14662             end if;
14663
14664             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
14665                Error_Pragma ("pragma% must specify array or record type");
14666             end if;
14667
14668             Check_First_Subtype (Arg1);
14669             Check_Duplicate_Pragma (Typ);
14670
14671             --  Array type
14672
14673             if Is_Array_Type (Typ) then
14674                Ctyp := Component_Type (Typ);
14675
14676                --  Ignore pack that does nothing
14677
14678                if Known_Static_Esize (Ctyp)
14679                  and then Known_Static_RM_Size (Ctyp)
14680                  and then Esize (Ctyp) = RM_Size (Ctyp)
14681                  and then Addressable (Esize (Ctyp))
14682                then
14683                   Ignore := True;
14684                end if;
14685
14686                --  Process OK pragma Pack. Note that if there is a separate
14687                --  component clause present, the Pack will be cancelled. This
14688                --  processing is in Freeze.
14689
14690                if not Rep_Item_Too_Late (Typ, N) then
14691
14692                   --  In the context of static code analysis, we do not need
14693                   --  complex front-end expansions related to pragma Pack,
14694                   --  so disable handling of pragma Pack in these cases.
14695
14696                   if CodePeer_Mode or SPARK_Mode then
14697                      null;
14698
14699                   --  Don't attempt any packing for VM targets. We possibly
14700                   --  could deal with some cases of array bit-packing, but we
14701                   --  don't bother, since this is not a typical kind of
14702                   --  representation in the VM context anyway (and would not
14703                   --  for example work nicely with the debugger).
14704
14705                   elsif VM_Target /= No_VM then
14706                      if not GNAT_Mode then
14707                         Error_Pragma
14708                           ("??pragma% ignored in this configuration");
14709                      end if;
14710
14711                   --  Normal case where we do the pack action
14712
14713                   else
14714                      if not Ignore then
14715                         Set_Is_Packed            (Base_Type (Typ));
14716                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
14717                      end if;
14718
14719                      Set_Has_Pragma_Pack (Base_Type (Typ));
14720                   end if;
14721                end if;
14722
14723             --  For record types, the pack is always effective
14724
14725             else pragma Assert (Is_Record_Type (Typ));
14726                if not Rep_Item_Too_Late (Typ, N) then
14727
14728                   --  Ignore pack request with warning in VM mode (skip warning
14729                   --  if we are compiling GNAT run time library).
14730
14731                   if VM_Target /= No_VM then
14732                      if not GNAT_Mode then
14733                         Error_Pragma
14734                           ("??pragma% ignored in this configuration");
14735                      end if;
14736
14737                   --  Normal case of pack request active
14738
14739                   else
14740                      Set_Is_Packed            (Base_Type (Typ));
14741                      Set_Has_Pragma_Pack      (Base_Type (Typ));
14742                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
14743                   end if;
14744                end if;
14745             end if;
14746          end Pack;
14747
14748          ----------
14749          -- Page --
14750          ----------
14751
14752          --  pragma Page;
14753
14754          --  There is nothing to do here, since we did all the processing for
14755          --  this pragma in Par.Prag (so that it works properly even in syntax
14756          --  only mode).
14757
14758          when Pragma_Page =>
14759             null;
14760
14761          ----------------------------------
14762          -- Partition_Elaboration_Policy --
14763          ----------------------------------
14764
14765          --  pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
14766
14767          when Pragma_Partition_Elaboration_Policy => declare
14768             subtype PEP_Range is Name_Id
14769               range First_Partition_Elaboration_Policy_Name
14770                  .. Last_Partition_Elaboration_Policy_Name;
14771             PEP_Val : PEP_Range;
14772             PEP     : Character;
14773
14774          begin
14775             Ada_2005_Pragma;
14776             Check_Arg_Count (1);
14777             Check_No_Identifiers;
14778             Check_Arg_Is_Partition_Elaboration_Policy (Arg1);
14779             Check_Valid_Configuration_Pragma;
14780             PEP_Val := Chars (Get_Pragma_Arg (Arg1));
14781
14782             case PEP_Val is
14783                when Name_Concurrent =>
14784                   PEP := 'C';
14785                when Name_Sequential =>
14786                   PEP := 'S';
14787             end case;
14788
14789             if Partition_Elaboration_Policy /= ' '
14790               and then Partition_Elaboration_Policy /= PEP
14791             then
14792                Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc;
14793                Error_Pragma
14794                  ("partition elaboration policy incompatible with policy#");
14795
14796             --  Set new policy, but always preserve System_Location since we
14797             --  like the error message with the run time name.
14798
14799             else
14800                Partition_Elaboration_Policy := PEP;
14801
14802                if Partition_Elaboration_Policy_Sloc /= System_Location then
14803                   Partition_Elaboration_Policy_Sloc := Loc;
14804                end if;
14805             end if;
14806          end;
14807
14808          -------------
14809          -- Passive --
14810          -------------
14811
14812          --  pragma Passive [(PASSIVE_FORM)];
14813
14814          --  PASSIVE_FORM ::= Semaphore | No
14815
14816          when Pragma_Passive =>
14817             GNAT_Pragma;
14818
14819             if Nkind (Parent (N)) /= N_Task_Definition then
14820                Error_Pragma ("pragma% must be within task definition");
14821             end if;
14822
14823             if Arg_Count /= 0 then
14824                Check_Arg_Count (1);
14825                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
14826             end if;
14827
14828          ----------------------------------
14829          -- Preelaborable_Initialization --
14830          ----------------------------------
14831
14832          --  pragma Preelaborable_Initialization (DIRECT_NAME);
14833
14834          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
14835             Ent : Entity_Id;
14836
14837          begin
14838             Ada_2005_Pragma;
14839             Check_Arg_Count (1);
14840             Check_No_Identifiers;
14841             Check_Arg_Is_Identifier (Arg1);
14842             Check_Arg_Is_Local_Name (Arg1);
14843             Check_First_Subtype (Arg1);
14844             Ent := Entity (Get_Pragma_Arg (Arg1));
14845
14846             --  The pragma may come from an aspect on a private declaration,
14847             --  even if the freeze point at which this is analyzed in the
14848             --  private part after the full view.
14849
14850             if Has_Private_Declaration (Ent)
14851               and then From_Aspect_Specification (N)
14852             then
14853                null;
14854
14855             elsif Is_Private_Type (Ent)
14856               or else Is_Protected_Type (Ent)
14857               or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent))
14858             then
14859                null;
14860
14861             else
14862                Error_Pragma_Arg
14863                  ("pragma % can only be applied to private, formal derived or "
14864                   & "protected type",
14865                   Arg1);
14866             end if;
14867
14868             --  Give an error if the pragma is applied to a protected type that
14869             --  does not qualify (due to having entries, or due to components
14870             --  that do not qualify).
14871
14872             if Is_Protected_Type (Ent)
14873               and then not Has_Preelaborable_Initialization (Ent)
14874             then
14875                Error_Msg_N
14876                  ("protected type & does not have preelaborable "
14877                   & "initialization", Ent);
14878
14879             --  Otherwise mark the type as definitely having preelaborable
14880             --  initialization.
14881
14882             else
14883                Set_Known_To_Have_Preelab_Init (Ent);
14884             end if;
14885
14886             if Has_Pragma_Preelab_Init (Ent)
14887               and then Warn_On_Redundant_Constructs
14888             then
14889                Error_Pragma ("?r?duplicate pragma%!");
14890             else
14891                Set_Has_Pragma_Preelab_Init (Ent);
14892             end if;
14893          end Preelab_Init;
14894
14895          --------------------
14896          -- Persistent_BSS --
14897          --------------------
14898
14899          --  pragma Persistent_BSS [(object_NAME)];
14900
14901          when Pragma_Persistent_BSS => Persistent_BSS :  declare
14902             Decl : Node_Id;
14903             Ent  : Entity_Id;
14904             Prag : Node_Id;
14905
14906          begin
14907             GNAT_Pragma;
14908             Check_At_Most_N_Arguments (1);
14909
14910             --  Case of application to specific object (one argument)
14911
14912             if Arg_Count = 1 then
14913                Check_Arg_Is_Library_Level_Local_Name (Arg1);
14914
14915                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
14916                  or else not
14917                    Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
14918                                                              E_Constant)
14919                then
14920                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
14921                end if;
14922
14923                Ent := Entity (Get_Pragma_Arg (Arg1));
14924                Decl := Parent (Ent);
14925
14926                --  Check for duplication before inserting in list of
14927                --  representation items.
14928
14929                Check_Duplicate_Pragma (Ent);
14930
14931                if Rep_Item_Too_Late (Ent, N) then
14932                   return;
14933                end if;
14934
14935                if Present (Expression (Decl)) then
14936                   Error_Pragma_Arg
14937                     ("object for pragma% cannot have initialization", Arg1);
14938                end if;
14939
14940                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
14941                   Error_Pragma_Arg
14942                     ("object type for pragma% is not potentially persistent",
14943                      Arg1);
14944                end if;
14945
14946                Prag :=
14947                  Make_Linker_Section_Pragma
14948                    (Ent, Sloc (N), ".persistent.bss");
14949                Insert_After (N, Prag);
14950                Analyze (Prag);
14951
14952             --  Case of use as configuration pragma with no arguments
14953
14954             else
14955                Check_Valid_Configuration_Pragma;
14956                Persistent_BSS_Mode := True;
14957             end if;
14958          end Persistent_BSS;
14959
14960          -------------
14961          -- Polling --
14962          -------------
14963
14964          --  pragma Polling (ON | OFF);
14965
14966          when Pragma_Polling =>
14967             GNAT_Pragma;
14968             Check_Arg_Count (1);
14969             Check_No_Identifiers;
14970             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14971             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
14972
14973          -------------------
14974          -- Postcondition --
14975          -------------------
14976
14977          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
14978          --                      [,[Message =>] String_EXPRESSION]);
14979
14980          when Pragma_Postcondition => Postcondition : declare
14981             In_Body : Boolean;
14982
14983          begin
14984             GNAT_Pragma;
14985             Check_At_Least_N_Arguments (1);
14986             Check_At_Most_N_Arguments (2);
14987             Check_Optional_Identifier (Arg1, Name_Check);
14988
14989             --  Verify the proper placement of the pragma. The remainder of the
14990             --  processing is found in Sem_Ch6/Sem_Ch7.
14991
14992             Check_Precondition_Postcondition (In_Body);
14993
14994             --  When the pragma is a source construct appearing inside a body,
14995             --  preanalyze the boolean_expression to detect illegal forward
14996             --  references:
14997
14998             --    procedure P is
14999             --       pragma Postcondition (X'Old ...);
15000             --       X : ...
15001
15002             if Comes_From_Source (N) and then In_Body then
15003                Preanalyze_Spec_Expression (Expression (Arg1), Any_Boolean);
15004             end if;
15005          end Postcondition;
15006
15007          ------------------
15008          -- Precondition --
15009          ------------------
15010
15011          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
15012          --                     [,[Message =>] String_EXPRESSION]);
15013
15014          when Pragma_Precondition => Precondition : declare
15015             In_Body : Boolean;
15016
15017          begin
15018             GNAT_Pragma;
15019             Check_At_Least_N_Arguments (1);
15020             Check_At_Most_N_Arguments (2);
15021             Check_Optional_Identifier (Arg1, Name_Check);
15022             Check_Precondition_Postcondition (In_Body);
15023
15024             --  If in spec, nothing more to do. If in body, then we convert the
15025             --  pragma to an equivalent pragam Check. Note we do this whether
15026             --  or not precondition checks are enabled. That works fine since
15027             --  pragma Check will do this check, and will also analyze the
15028             --  condition itself in the proper context.
15029
15030             --  The form of the pragma Check is either:
15031
15032             --    pragma Check (Precondition, cond [, msg])
15033             --       or
15034             --    pragma Check (Pre, cond [, msg])
15035
15036             --  We use the Pre form if this pragma derived from a Pre aspect.
15037             --  This is needed to make sure that the right set of Policy
15038             --  pragmas are checked.
15039
15040             if In_Body then
15041                Rewrite (N,
15042                  Make_Pragma (Loc,
15043                    Chars                        => Name_Check,
15044                    Pragma_Argument_Associations => New_List (
15045                      Make_Pragma_Argument_Association (Loc,
15046                        Expression => Make_Identifier (Loc, Pname)),
15047
15048                      Make_Pragma_Argument_Association (Sloc (Arg1),
15049                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
15050
15051                if Arg_Count = 2 then
15052                   Append_To (Pragma_Argument_Associations (N),
15053                     Make_Pragma_Argument_Association (Sloc (Arg2),
15054                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
15055                end if;
15056
15057                Analyze (N);
15058             end if;
15059          end Precondition;
15060
15061          ---------------
15062          -- Predicate --
15063          ---------------
15064
15065          --  pragma Predicate
15066          --    ([Entity =>] type_LOCAL_NAME,
15067          --     [Check  =>] boolean_EXPRESSION);
15068
15069          when Pragma_Predicate => Predicate : declare
15070             Type_Id : Node_Id;
15071             Typ     : Entity_Id;
15072
15073             Discard : Boolean;
15074             pragma Unreferenced (Discard);
15075
15076          begin
15077             GNAT_Pragma;
15078             Check_Arg_Count (2);
15079             Check_Optional_Identifier (Arg1, Name_Entity);
15080             Check_Optional_Identifier (Arg2, Name_Check);
15081
15082             Check_Arg_Is_Local_Name (Arg1);
15083
15084             Type_Id := Get_Pragma_Arg (Arg1);
15085             Find_Type (Type_Id);
15086             Typ := Entity (Type_Id);
15087
15088             if Typ = Any_Type then
15089                return;
15090             end if;
15091
15092             --  The remaining processing is simply to link the pragma on to
15093             --  the rep item chain, for processing when the type is frozen.
15094             --  This is accomplished by a call to Rep_Item_Too_Late. We also
15095             --  mark the type as having predicates.
15096
15097             Set_Has_Predicates (Typ);
15098             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
15099          end Predicate;
15100
15101          ------------------
15102          -- Preelaborate --
15103          ------------------
15104
15105          --  pragma Preelaborate [(library_unit_NAME)];
15106
15107          --  Set the flag Is_Preelaborated of program unit name entity
15108
15109          when Pragma_Preelaborate => Preelaborate : declare
15110             Pa  : constant Node_Id   := Parent (N);
15111             Pk  : constant Node_Kind := Nkind (Pa);
15112             Ent : Entity_Id;
15113
15114          begin
15115             Check_Ada_83_Warning;
15116             Check_Valid_Library_Unit_Pragma;
15117
15118             if Nkind (N) = N_Null_Statement then
15119                return;
15120             end if;
15121
15122             Ent := Find_Lib_Unit_Name;
15123             Check_Duplicate_Pragma (Ent);
15124
15125             --  This filters out pragmas inside generic parent then
15126             --  show up inside instantiation
15127
15128             if Present (Ent)
15129               and then not (Pk = N_Package_Specification
15130                              and then Present (Generic_Parent (Pa)))
15131             then
15132                if not Debug_Flag_U then
15133                   Set_Is_Preelaborated (Ent);
15134                   Set_Suppress_Elaboration_Warnings (Ent);
15135                end if;
15136             end if;
15137          end Preelaborate;
15138
15139          ---------------------
15140          -- Preelaborate_05 --
15141          ---------------------
15142
15143          --  pragma Preelaborate_05 [(library_unit_NAME)];
15144
15145          --  This pragma is useable only in GNAT_Mode, where it is used like
15146          --  pragma Preelaborate but it is only effective in Ada 2005 mode
15147          --  (otherwise it is ignored). This is used to implement AI-362 which
15148          --  recategorizes some run-time packages in Ada 2005 mode.
15149
15150          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
15151             Ent : Entity_Id;
15152
15153          begin
15154             GNAT_Pragma;
15155             Check_Valid_Library_Unit_Pragma;
15156
15157             if not GNAT_Mode then
15158                Error_Pragma ("pragma% only available in GNAT mode");
15159             end if;
15160
15161             if Nkind (N) = N_Null_Statement then
15162                return;
15163             end if;
15164
15165             --  This is one of the few cases where we need to test the value of
15166             --  Ada_Version_Explicit rather than Ada_Version (which is always
15167             --  set to Ada_2012 in a predefined unit), we need to know the
15168             --  explicit version set to know if this pragma is active.
15169
15170             if Ada_Version_Explicit >= Ada_2005 then
15171                Ent := Find_Lib_Unit_Name;
15172                Set_Is_Preelaborated (Ent);
15173                Set_Suppress_Elaboration_Warnings (Ent);
15174             end if;
15175          end Preelaborate_05;
15176
15177          --------------
15178          -- Priority --
15179          --------------
15180
15181          --  pragma Priority (EXPRESSION);
15182
15183          when Pragma_Priority => Priority : declare
15184             P   : constant Node_Id := Parent (N);
15185             Arg : Node_Id;
15186             Ent : Entity_Id;
15187
15188          begin
15189             Check_No_Identifiers;
15190             Check_Arg_Count (1);
15191
15192             --  Subprogram case
15193
15194             if Nkind (P) = N_Subprogram_Body then
15195                Check_In_Main_Program;
15196
15197                Ent := Defining_Unit_Name (Specification (P));
15198
15199                if Nkind (Ent) = N_Defining_Program_Unit_Name then
15200                   Ent := Defining_Identifier (Ent);
15201                end if;
15202
15203                Arg := Get_Pragma_Arg (Arg1);
15204                Analyze_And_Resolve (Arg, Standard_Integer);
15205
15206                --  Must be static
15207
15208                if not Is_Static_Expression (Arg) then
15209                   Flag_Non_Static_Expr
15210                     ("main subprogram priority is not static!", Arg);
15211                   raise Pragma_Exit;
15212
15213                --  If constraint error, then we already signalled an error
15214
15215                elsif Raises_Constraint_Error (Arg) then
15216                   null;
15217
15218                --  Otherwise check in range
15219
15220                else
15221                   declare
15222                      Val : constant Uint := Expr_Value (Arg);
15223
15224                   begin
15225                      if Val < 0
15226                        or else Val > Expr_Value (Expression
15227                                        (Parent (RTE (RE_Max_Priority))))
15228                      then
15229                         Error_Pragma_Arg
15230                           ("main subprogram priority is out of range", Arg1);
15231                      end if;
15232                   end;
15233                end if;
15234
15235                Set_Main_Priority
15236                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
15237
15238                --  Load an arbitrary entity from System.Tasking to make sure
15239                --  this package is implicitly with'ed, since we need to have
15240                --  the tasking run-time active for the pragma Priority to have
15241                --  any effect.
15242
15243                declare
15244                   Discard : Entity_Id;
15245                   pragma Warnings (Off, Discard);
15246                begin
15247                   Discard := RTE (RE_Task_List);
15248                end;
15249
15250             --  Task or Protected, must be of type Integer
15251
15252             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
15253                Arg := Get_Pragma_Arg (Arg1);
15254                Ent := Defining_Identifier (Parent (P));
15255
15256                --  The expression must be analyzed in the special manner
15257                --  described in "Handling of Default and Per-Object
15258                --  Expressions" in sem.ads.
15259
15260                Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority));
15261
15262                if not Is_Static_Expression (Arg) then
15263                   Check_Restriction (Static_Priorities, Arg);
15264                end if;
15265
15266             --  Anything else is incorrect
15267
15268             else
15269                Pragma_Misplaced;
15270             end if;
15271
15272             --  Check duplicate pragma before we chain the pragma in the Rep
15273             --  Item chain of Ent.
15274
15275             Check_Duplicate_Pragma (Ent);
15276             Record_Rep_Item (Ent, N);
15277          end Priority;
15278
15279          -----------------------------------
15280          -- Priority_Specific_Dispatching --
15281          -----------------------------------
15282
15283          --  pragma Priority_Specific_Dispatching (
15284          --    policy_IDENTIFIER,
15285          --    first_priority_EXPRESSION,
15286          --    last_priority_EXPRESSION);
15287
15288          when Pragma_Priority_Specific_Dispatching =>
15289          Priority_Specific_Dispatching : declare
15290             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
15291             --  This is the entity System.Any_Priority;
15292
15293             DP          : Character;
15294             Lower_Bound : Node_Id;
15295             Upper_Bound : Node_Id;
15296             Lower_Val   : Uint;
15297             Upper_Val   : Uint;
15298
15299          begin
15300             Ada_2005_Pragma;
15301             Check_Arg_Count (3);
15302             Check_No_Identifiers;
15303             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
15304             Check_Valid_Configuration_Pragma;
15305             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15306             DP := Fold_Upper (Name_Buffer (1));
15307
15308             Lower_Bound := Get_Pragma_Arg (Arg2);
15309             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
15310             Lower_Val := Expr_Value (Lower_Bound);
15311
15312             Upper_Bound := Get_Pragma_Arg (Arg3);
15313             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
15314             Upper_Val := Expr_Value (Upper_Bound);
15315
15316             --  It is not allowed to use Task_Dispatching_Policy and
15317             --  Priority_Specific_Dispatching in the same partition.
15318
15319             if Task_Dispatching_Policy /= ' ' then
15320                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15321                Error_Pragma
15322                  ("pragma% incompatible with Task_Dispatching_Policy#");
15323
15324             --  Check lower bound in range
15325
15326             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
15327                     or else
15328                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
15329             then
15330                Error_Pragma_Arg
15331                  ("first_priority is out of range", Arg2);
15332
15333             --  Check upper bound in range
15334
15335             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
15336                     or else
15337                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
15338             then
15339                Error_Pragma_Arg
15340                  ("last_priority is out of range", Arg3);
15341
15342             --  Check that the priority range is valid
15343
15344             elsif Lower_Val > Upper_Val then
15345                Error_Pragma
15346                  ("last_priority_expression must be greater than or equal to "
15347                   & "first_priority_expression");
15348
15349             --  Store the new policy, but always preserve System_Location since
15350             --  we like the error message with the run-time name.
15351
15352             else
15353                --  Check overlapping in the priority ranges specified in other
15354                --  Priority_Specific_Dispatching pragmas within the same
15355                --  partition. We can only check those we know about!
15356
15357                for J in
15358                   Specific_Dispatching.First .. Specific_Dispatching.Last
15359                loop
15360                   if Specific_Dispatching.Table (J).First_Priority in
15361                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15362                   or else Specific_Dispatching.Table (J).Last_Priority in
15363                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
15364                   then
15365                      Error_Msg_Sloc :=
15366                        Specific_Dispatching.Table (J).Pragma_Loc;
15367                         Error_Pragma
15368                           ("priority range overlaps with "
15369                            & "Priority_Specific_Dispatching#");
15370                   end if;
15371                end loop;
15372
15373                --  The use of Priority_Specific_Dispatching is incompatible
15374                --  with Task_Dispatching_Policy.
15375
15376                if Task_Dispatching_Policy /= ' ' then
15377                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
15378                      Error_Pragma
15379                        ("Priority_Specific_Dispatching incompatible "
15380                         & "with Task_Dispatching_Policy#");
15381                end if;
15382
15383                --  The use of Priority_Specific_Dispatching forces ceiling
15384                --  locking policy.
15385
15386                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
15387                   Error_Msg_Sloc := Locking_Policy_Sloc;
15388                      Error_Pragma
15389                        ("Priority_Specific_Dispatching incompatible "
15390                         & "with Locking_Policy#");
15391
15392                --  Set the Ceiling_Locking policy, but preserve System_Location
15393                --  since we like the error message with the run time name.
15394
15395                else
15396                   Locking_Policy := 'C';
15397
15398                   if Locking_Policy_Sloc /= System_Location then
15399                      Locking_Policy_Sloc := Loc;
15400                   end if;
15401                end if;
15402
15403                --  Add entry in the table
15404
15405                Specific_Dispatching.Append
15406                     ((Dispatching_Policy => DP,
15407                       First_Priority     => UI_To_Int (Lower_Val),
15408                       Last_Priority      => UI_To_Int (Upper_Val),
15409                       Pragma_Loc         => Loc));
15410             end if;
15411          end Priority_Specific_Dispatching;
15412
15413          -------------
15414          -- Profile --
15415          -------------
15416
15417          --  pragma Profile (profile_IDENTIFIER);
15418
15419          --  profile_IDENTIFIER => Restricted | Ravenscar | Rational
15420
15421          when Pragma_Profile =>
15422             Ada_2005_Pragma;
15423             Check_Arg_Count (1);
15424             Check_Valid_Configuration_Pragma;
15425             Check_No_Identifiers;
15426
15427             declare
15428                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15429
15430             begin
15431                if Chars (Argx) = Name_Ravenscar then
15432                   Set_Ravenscar_Profile (N);
15433
15434                elsif Chars (Argx) = Name_Restricted then
15435                   Set_Profile_Restrictions
15436                     (Restricted,
15437                      N, Warn => Treat_Restrictions_As_Warnings);
15438
15439                elsif Chars (Argx) = Name_Rational then
15440                   Set_Rational_Profile;
15441
15442                elsif Chars (Argx) = Name_No_Implementation_Extensions then
15443                   Set_Profile_Restrictions
15444                     (No_Implementation_Extensions,
15445                      N, Warn => Treat_Restrictions_As_Warnings);
15446
15447                else
15448                   Error_Pragma_Arg ("& is not a valid profile", Argx);
15449                end if;
15450             end;
15451
15452          ----------------------
15453          -- Profile_Warnings --
15454          ----------------------
15455
15456          --  pragma Profile_Warnings (profile_IDENTIFIER);
15457
15458          --  profile_IDENTIFIER => Restricted | Ravenscar
15459
15460          when Pragma_Profile_Warnings =>
15461             GNAT_Pragma;
15462             Check_Arg_Count (1);
15463             Check_Valid_Configuration_Pragma;
15464             Check_No_Identifiers;
15465
15466             declare
15467                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
15468
15469             begin
15470                if Chars (Argx) = Name_Ravenscar then
15471                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
15472
15473                elsif Chars (Argx) = Name_Restricted then
15474                   Set_Profile_Restrictions (Restricted, N, Warn => True);
15475
15476                elsif Chars (Argx) = Name_No_Implementation_Extensions then
15477                   Set_Profile_Restrictions
15478                     (No_Implementation_Extensions, N, Warn => True);
15479
15480                else
15481                   Error_Pragma_Arg ("& is not a valid profile", Argx);
15482                end if;
15483             end;
15484
15485          --------------------------
15486          -- Propagate_Exceptions --
15487          --------------------------
15488
15489          --  pragma Propagate_Exceptions;
15490
15491          --  Note: this pragma is obsolete and has no effect
15492
15493          when Pragma_Propagate_Exceptions =>
15494             GNAT_Pragma;
15495             Check_Arg_Count (0);
15496
15497             if Warn_On_Obsolescent_Feature then
15498                Error_Msg_N
15499                  ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
15500                   "and has no effect?j?", N);
15501             end if;
15502
15503          ------------------
15504          -- Psect_Object --
15505          ------------------
15506
15507          --  pragma Psect_Object (
15508          --        [Internal =>] LOCAL_NAME,
15509          --     [, [External =>] EXTERNAL_SYMBOL]
15510          --     [, [Size     =>] EXTERNAL_SYMBOL]);
15511
15512          when Pragma_Psect_Object | Pragma_Common_Object =>
15513          Psect_Object : declare
15514             Args  : Args_List (1 .. 3);
15515             Names : constant Name_List (1 .. 3) := (
15516                       Name_Internal,
15517                       Name_External,
15518                       Name_Size);
15519
15520             Internal : Node_Id renames Args (1);
15521             External : Node_Id renames Args (2);
15522             Size     : Node_Id renames Args (3);
15523
15524             Def_Id : Entity_Id;
15525
15526             procedure Check_Too_Long (Arg : Node_Id);
15527             --  Posts message if the argument is an identifier with more
15528             --  than 31 characters, or a string literal with more than
15529             --  31 characters, and we are operating under VMS
15530
15531             --------------------
15532             -- Check_Too_Long --
15533             --------------------
15534
15535             procedure Check_Too_Long (Arg : Node_Id) is
15536                X : constant Node_Id := Original_Node (Arg);
15537
15538             begin
15539                if not Nkind_In (X, N_String_Literal, N_Identifier) then
15540                   Error_Pragma_Arg
15541                     ("inappropriate argument for pragma %", Arg);
15542                end if;
15543
15544                if OpenVMS_On_Target then
15545                   if (Nkind (X) = N_String_Literal
15546                        and then String_Length (Strval (X)) > 31)
15547                     or else
15548                      (Nkind (X) = N_Identifier
15549                        and then Length_Of_Name (Chars (X)) > 31)
15550                   then
15551                      Error_Pragma_Arg
15552                        ("argument for pragma % is longer than 31 characters",
15553                         Arg);
15554                   end if;
15555                end if;
15556             end Check_Too_Long;
15557
15558          --  Start of processing for Common_Object/Psect_Object
15559
15560          begin
15561             GNAT_Pragma;
15562             Gather_Associations (Names, Args);
15563             Process_Extended_Import_Export_Internal_Arg (Internal);
15564
15565             Def_Id := Entity (Internal);
15566
15567             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
15568                Error_Pragma_Arg
15569                  ("pragma% must designate an object", Internal);
15570             end if;
15571
15572             Check_Too_Long (Internal);
15573
15574             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
15575                Error_Pragma_Arg
15576                  ("cannot use pragma% for imported/exported object",
15577                   Internal);
15578             end if;
15579
15580             if Is_Concurrent_Type (Etype (Internal)) then
15581                Error_Pragma_Arg
15582                  ("cannot specify pragma % for task/protected object",
15583                   Internal);
15584             end if;
15585
15586             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
15587                  or else
15588                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
15589             then
15590                Error_Msg_N ("??duplicate Common/Psect_Object pragma", N);
15591             end if;
15592
15593             if Ekind (Def_Id) = E_Constant then
15594                Error_Pragma_Arg
15595                  ("cannot specify pragma % for a constant", Internal);
15596             end if;
15597
15598             if Is_Record_Type (Etype (Internal)) then
15599                declare
15600                   Ent  : Entity_Id;
15601                   Decl : Entity_Id;
15602
15603                begin
15604                   Ent := First_Entity (Etype (Internal));
15605                   while Present (Ent) loop
15606                      Decl := Declaration_Node (Ent);
15607
15608                      if Ekind (Ent) = E_Component
15609                        and then Nkind (Decl) = N_Component_Declaration
15610                        and then Present (Expression (Decl))
15611                        and then Warn_On_Export_Import
15612                      then
15613                         Error_Msg_N
15614                           ("?x?object for pragma % has defaults", Internal);
15615                         exit;
15616
15617                      else
15618                         Next_Entity (Ent);
15619                      end if;
15620                   end loop;
15621                end;
15622             end if;
15623
15624             if Present (Size) then
15625                Check_Too_Long (Size);
15626             end if;
15627
15628             if Present (External) then
15629                Check_Arg_Is_External_Name (External);
15630                Check_Too_Long (External);
15631             end if;
15632
15633             --  If all error tests pass, link pragma on to the rep item chain
15634
15635             Record_Rep_Item (Def_Id, N);
15636          end Psect_Object;
15637
15638          ----------
15639          -- Pure --
15640          ----------
15641
15642          --  pragma Pure [(library_unit_NAME)];
15643
15644          when Pragma_Pure => Pure : declare
15645             Ent : Entity_Id;
15646
15647          begin
15648             Check_Ada_83_Warning;
15649             Check_Valid_Library_Unit_Pragma;
15650
15651             if Nkind (N) = N_Null_Statement then
15652                return;
15653             end if;
15654
15655             Ent := Find_Lib_Unit_Name;
15656             Set_Is_Pure (Ent);
15657             Set_Has_Pragma_Pure (Ent);
15658             Set_Suppress_Elaboration_Warnings (Ent);
15659          end Pure;
15660
15661          -------------
15662          -- Pure_05 --
15663          -------------
15664
15665          --  pragma Pure_05 [(library_unit_NAME)];
15666
15667          --  This pragma is useable only in GNAT_Mode, where it is used like
15668          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
15669          --  it is ignored). It may be used after a pragma Preelaborate, in
15670          --  which case it overrides the effect of the pragma Preelaborate.
15671          --  This is used to implement AI-362 which recategorizes some run-time
15672          --  packages in Ada 2005 mode.
15673
15674          when Pragma_Pure_05 => Pure_05 : declare
15675             Ent : Entity_Id;
15676
15677          begin
15678             GNAT_Pragma;
15679             Check_Valid_Library_Unit_Pragma;
15680
15681             if not GNAT_Mode then
15682                Error_Pragma ("pragma% only available in GNAT mode");
15683             end if;
15684
15685             if Nkind (N) = N_Null_Statement then
15686                return;
15687             end if;
15688
15689             --  This is one of the few cases where we need to test the value of
15690             --  Ada_Version_Explicit rather than Ada_Version (which is always
15691             --  set to Ada_2012 in a predefined unit), we need to know the
15692             --  explicit version set to know if this pragma is active.
15693
15694             if Ada_Version_Explicit >= Ada_2005 then
15695                Ent := Find_Lib_Unit_Name;
15696                Set_Is_Preelaborated (Ent, False);
15697                Set_Is_Pure (Ent);
15698                Set_Suppress_Elaboration_Warnings (Ent);
15699             end if;
15700          end Pure_05;
15701
15702          -------------
15703          -- Pure_12 --
15704          -------------
15705
15706          --  pragma Pure_12 [(library_unit_NAME)];
15707
15708          --  This pragma is useable only in GNAT_Mode, where it is used like
15709          --  pragma Pure but it is only effective in Ada 2012 mode (otherwise
15710          --  it is ignored). It may be used after a pragma Preelaborate, in
15711          --  which case it overrides the effect of the pragma Preelaborate.
15712          --  This is used to implement AI05-0212 which recategorizes some
15713          --  run-time packages in Ada 2012 mode.
15714
15715          when Pragma_Pure_12 => Pure_12 : declare
15716             Ent : Entity_Id;
15717
15718          begin
15719             GNAT_Pragma;
15720             Check_Valid_Library_Unit_Pragma;
15721
15722             if not GNAT_Mode then
15723                Error_Pragma ("pragma% only available in GNAT mode");
15724             end if;
15725
15726             if Nkind (N) = N_Null_Statement then
15727                return;
15728             end if;
15729
15730             --  This is one of the few cases where we need to test the value of
15731             --  Ada_Version_Explicit rather than Ada_Version (which is always
15732             --  set to Ada_2012 in a predefined unit), we need to know the
15733             --  explicit version set to know if this pragma is active.
15734
15735             if Ada_Version_Explicit >= Ada_2012 then
15736                Ent := Find_Lib_Unit_Name;
15737                Set_Is_Preelaborated (Ent, False);
15738                Set_Is_Pure (Ent);
15739                Set_Suppress_Elaboration_Warnings (Ent);
15740             end if;
15741          end Pure_12;
15742
15743          -------------------
15744          -- Pure_Function --
15745          -------------------
15746
15747          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
15748
15749          when Pragma_Pure_Function => Pure_Function : declare
15750             E_Id      : Node_Id;
15751             E         : Entity_Id;
15752             Def_Id    : Entity_Id;
15753             Effective : Boolean := False;
15754
15755          begin
15756             GNAT_Pragma;
15757             Check_Arg_Count (1);
15758             Check_Optional_Identifier (Arg1, Name_Entity);
15759             Check_Arg_Is_Local_Name (Arg1);
15760             E_Id := Get_Pragma_Arg (Arg1);
15761
15762             if Error_Posted (E_Id) then
15763                return;
15764             end if;
15765
15766             --  Loop through homonyms (overloadings) of referenced entity
15767
15768             E := Entity (E_Id);
15769
15770             if Present (E) then
15771                loop
15772                   Def_Id := Get_Base_Subprogram (E);
15773
15774                   if not Ekind_In (Def_Id, E_Function,
15775                                            E_Generic_Function,
15776                                            E_Operator)
15777                   then
15778                      Error_Pragma_Arg
15779                        ("pragma% requires a function name", Arg1);
15780                   end if;
15781
15782                   Set_Is_Pure (Def_Id);
15783
15784                   if not Has_Pragma_Pure_Function (Def_Id) then
15785                      Set_Has_Pragma_Pure_Function (Def_Id);
15786                      Effective := True;
15787                   end if;
15788
15789                   exit when From_Aspect_Specification (N);
15790                   E := Homonym (E);
15791                   exit when No (E) or else Scope (E) /= Current_Scope;
15792                end loop;
15793
15794                if not Effective
15795                  and then Warn_On_Redundant_Constructs
15796                then
15797                   Error_Msg_NE
15798                     ("pragma Pure_Function on& is redundant?r?",
15799                      N, Entity (E_Id));
15800                end if;
15801             end if;
15802          end Pure_Function;
15803
15804          --------------------
15805          -- Queuing_Policy --
15806          --------------------
15807
15808          --  pragma Queuing_Policy (policy_IDENTIFIER);
15809
15810          when Pragma_Queuing_Policy => declare
15811             QP : Character;
15812
15813          begin
15814             Check_Ada_83_Warning;
15815             Check_Arg_Count (1);
15816             Check_No_Identifiers;
15817             Check_Arg_Is_Queuing_Policy (Arg1);
15818             Check_Valid_Configuration_Pragma;
15819             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
15820             QP := Fold_Upper (Name_Buffer (1));
15821
15822             if Queuing_Policy /= ' '
15823               and then Queuing_Policy /= QP
15824             then
15825                Error_Msg_Sloc := Queuing_Policy_Sloc;
15826                Error_Pragma ("queuing policy incompatible with policy#");
15827
15828             --  Set new policy, but always preserve System_Location since we
15829             --  like the error message with the run time name.
15830
15831             else
15832                Queuing_Policy := QP;
15833
15834                if Queuing_Policy_Sloc /= System_Location then
15835                   Queuing_Policy_Sloc := Loc;
15836                end if;
15837             end if;
15838          end;
15839
15840          --------------
15841          -- Rational --
15842          --------------
15843
15844          --  pragma Rational, for compatibility with foreign compiler
15845
15846          when Pragma_Rational =>
15847             Set_Rational_Profile;
15848
15849          -----------------------
15850          -- Relative_Deadline --
15851          -----------------------
15852
15853          --  pragma Relative_Deadline (time_span_EXPRESSION);
15854
15855          when Pragma_Relative_Deadline => Relative_Deadline : declare
15856             P   : constant Node_Id := Parent (N);
15857             Arg : Node_Id;
15858
15859          begin
15860             Ada_2005_Pragma;
15861             Check_No_Identifiers;
15862             Check_Arg_Count (1);
15863
15864             Arg := Get_Pragma_Arg (Arg1);
15865
15866             --  The expression must be analyzed in the special manner described
15867             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
15868
15869             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
15870
15871             --  Subprogram case
15872
15873             if Nkind (P) = N_Subprogram_Body then
15874                Check_In_Main_Program;
15875
15876             --  Only Task and subprogram cases allowed
15877
15878             elsif Nkind (P) /= N_Task_Definition then
15879                Pragma_Misplaced;
15880             end if;
15881
15882             --  Check duplicate pragma before we set the corresponding flag
15883
15884             if Has_Relative_Deadline_Pragma (P) then
15885                Error_Pragma ("duplicate pragma% not allowed");
15886             end if;
15887
15888             --  Set Has_Relative_Deadline_Pragma only for tasks. Note that
15889             --  Relative_Deadline pragma node cannot be inserted in the Rep
15890             --  Item chain of Ent since it is rewritten by the expander as a
15891             --  procedure call statement that will break the chain.
15892
15893             Set_Has_Relative_Deadline_Pragma (P, True);
15894          end Relative_Deadline;
15895
15896          ------------------------
15897          -- Remote_Access_Type --
15898          ------------------------
15899
15900          --  pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
15901
15902          when Pragma_Remote_Access_Type => Remote_Access_Type : declare
15903             E : Entity_Id;
15904
15905          begin
15906             GNAT_Pragma;
15907             Check_Arg_Count (1);
15908             Check_Optional_Identifier (Arg1, Name_Entity);
15909             Check_Arg_Is_Local_Name (Arg1);
15910
15911             E := Entity (Get_Pragma_Arg (Arg1));
15912
15913             if Nkind (Parent (E)) = N_Formal_Type_Declaration
15914               and then Ekind (E) = E_General_Access_Type
15915               and then Is_Class_Wide_Type (Directly_Designated_Type (E))
15916               and then Scope (Root_Type (Directly_Designated_Type (E)))
15917                          = Scope (E)
15918               and then Is_Valid_Remote_Object_Type
15919                          (Root_Type (Directly_Designated_Type (E)))
15920             then
15921                Set_Is_Remote_Types (E);
15922
15923             else
15924                Error_Pragma_Arg
15925                  ("pragma% applies only to formal access to classwide types",
15926                   Arg1);
15927             end if;
15928          end Remote_Access_Type;
15929
15930          ---------------------------
15931          -- Remote_Call_Interface --
15932          ---------------------------
15933
15934          --  pragma Remote_Call_Interface [(library_unit_NAME)];
15935
15936          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
15937             Cunit_Node : Node_Id;
15938             Cunit_Ent  : Entity_Id;
15939             K          : Node_Kind;
15940
15941          begin
15942             Check_Ada_83_Warning;
15943             Check_Valid_Library_Unit_Pragma;
15944
15945             if Nkind (N) = N_Null_Statement then
15946                return;
15947             end if;
15948
15949             Cunit_Node := Cunit (Current_Sem_Unit);
15950             K          := Nkind (Unit (Cunit_Node));
15951             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
15952
15953             if K = N_Package_Declaration
15954               or else K = N_Generic_Package_Declaration
15955               or else K = N_Subprogram_Declaration
15956               or else K = N_Generic_Subprogram_Declaration
15957               or else (K = N_Subprogram_Body
15958                          and then Acts_As_Spec (Unit (Cunit_Node)))
15959             then
15960                null;
15961             else
15962                Error_Pragma (
15963                  "pragma% must apply to package or subprogram declaration");
15964             end if;
15965
15966             Set_Is_Remote_Call_Interface (Cunit_Ent);
15967          end Remote_Call_Interface;
15968
15969          ------------------
15970          -- Remote_Types --
15971          ------------------
15972
15973          --  pragma Remote_Types [(library_unit_NAME)];
15974
15975          when Pragma_Remote_Types => Remote_Types : declare
15976             Cunit_Node : Node_Id;
15977             Cunit_Ent  : Entity_Id;
15978
15979          begin
15980             Check_Ada_83_Warning;
15981             Check_Valid_Library_Unit_Pragma;
15982
15983             if Nkind (N) = N_Null_Statement then
15984                return;
15985             end if;
15986
15987             Cunit_Node := Cunit (Current_Sem_Unit);
15988             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
15989
15990             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
15991                                                 N_Generic_Package_Declaration)
15992             then
15993                Error_Pragma
15994                  ("pragma% can only apply to a package declaration");
15995             end if;
15996
15997             Set_Is_Remote_Types (Cunit_Ent);
15998          end Remote_Types;
15999
16000          ---------------
16001          -- Ravenscar --
16002          ---------------
16003
16004          --  pragma Ravenscar;
16005
16006          when Pragma_Ravenscar =>
16007             GNAT_Pragma;
16008             Check_Arg_Count (0);
16009             Check_Valid_Configuration_Pragma;
16010             Set_Ravenscar_Profile (N);
16011
16012             if Warn_On_Obsolescent_Feature then
16013                Error_Msg_N
16014                  ("pragma Ravenscar is an obsolescent feature?j?", N);
16015                Error_Msg_N
16016                  ("|use pragma Profile (Ravenscar) instead?j?", N);
16017             end if;
16018
16019          -------------------------
16020          -- Restricted_Run_Time --
16021          -------------------------
16022
16023          --  pragma Restricted_Run_Time;
16024
16025          when Pragma_Restricted_Run_Time =>
16026             GNAT_Pragma;
16027             Check_Arg_Count (0);
16028             Check_Valid_Configuration_Pragma;
16029             Set_Profile_Restrictions
16030               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
16031
16032             if Warn_On_Obsolescent_Feature then
16033                Error_Msg_N
16034                  ("pragma Restricted_Run_Time is an obsolescent feature?j?",
16035                   N);
16036                Error_Msg_N
16037                  ("|use pragma Profile (Restricted) instead?j?", N);
16038             end if;
16039
16040          ------------------
16041          -- Restrictions --
16042          ------------------
16043
16044          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
16045
16046          --  RESTRICTION ::=
16047          --    restriction_IDENTIFIER
16048          --  | restriction_parameter_IDENTIFIER => EXPRESSION
16049
16050          when Pragma_Restrictions =>
16051             Process_Restrictions_Or_Restriction_Warnings
16052               (Warn => Treat_Restrictions_As_Warnings);
16053
16054          --------------------------
16055          -- Restriction_Warnings --
16056          --------------------------
16057
16058          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
16059
16060          --  RESTRICTION ::=
16061          --    restriction_IDENTIFIER
16062          --  | restriction_parameter_IDENTIFIER => EXPRESSION
16063
16064          when Pragma_Restriction_Warnings =>
16065             GNAT_Pragma;
16066             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
16067
16068          ----------------
16069          -- Reviewable --
16070          ----------------
16071
16072          --  pragma Reviewable;
16073
16074          when Pragma_Reviewable =>
16075             Check_Ada_83_Warning;
16076             Check_Arg_Count (0);
16077
16078             --  Call dummy debugging function rv. This is done to assist front
16079             --  end debugging. By placing a Reviewable pragma in the source
16080             --  program, a breakpoint on rv catches this place in the source,
16081             --  allowing convenient stepping to the point of interest.
16082
16083             rv;
16084
16085          --------------------------
16086          -- Short_Circuit_And_Or --
16087          --------------------------
16088
16089          --  pragma Short_Circuit_And_Or;
16090
16091          when Pragma_Short_Circuit_And_Or =>
16092             GNAT_Pragma;
16093             Check_Arg_Count (0);
16094             Check_Valid_Configuration_Pragma;
16095             Short_Circuit_And_Or := True;
16096
16097          -------------------
16098          -- Share_Generic --
16099          -------------------
16100
16101          --  pragma Share_Generic (GNAME {, GNAME});
16102
16103          --  GNAME ::= generic_unit_NAME | generic_instance_NAME
16104
16105          when Pragma_Share_Generic =>
16106             GNAT_Pragma;
16107             Process_Generic_List;
16108
16109          ------------
16110          -- Shared --
16111          ------------
16112
16113          --  pragma Shared (LOCAL_NAME);
16114
16115          when Pragma_Shared =>
16116             GNAT_Pragma;
16117             Process_Atomic_Shared_Volatile;
16118
16119          --------------------
16120          -- Shared_Passive --
16121          --------------------
16122
16123          --  pragma Shared_Passive [(library_unit_NAME)];
16124
16125          --  Set the flag Is_Shared_Passive of program unit name entity
16126
16127          when Pragma_Shared_Passive => Shared_Passive : declare
16128             Cunit_Node : Node_Id;
16129             Cunit_Ent  : Entity_Id;
16130
16131          begin
16132             Check_Ada_83_Warning;
16133             Check_Valid_Library_Unit_Pragma;
16134
16135             if Nkind (N) = N_Null_Statement then
16136                return;
16137             end if;
16138
16139             Cunit_Node := Cunit (Current_Sem_Unit);
16140             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
16141
16142             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
16143                                                 N_Generic_Package_Declaration)
16144             then
16145                Error_Pragma
16146                  ("pragma% can only apply to a package declaration");
16147             end if;
16148
16149             Set_Is_Shared_Passive (Cunit_Ent);
16150          end Shared_Passive;
16151
16152          -----------------------
16153          -- Short_Descriptors --
16154          -----------------------
16155
16156          --  pragma Short_Descriptors;
16157
16158          when Pragma_Short_Descriptors =>
16159             GNAT_Pragma;
16160             Check_Arg_Count (0);
16161             Check_Valid_Configuration_Pragma;
16162             Short_Descriptors := True;
16163
16164          ------------------------------
16165          -- Simple_Storage_Pool_Type --
16166          ------------------------------
16167
16168          --  pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
16169
16170          when Pragma_Simple_Storage_Pool_Type =>
16171          Simple_Storage_Pool_Type : declare
16172             Type_Id : Node_Id;
16173             Typ     : Entity_Id;
16174
16175          begin
16176             GNAT_Pragma;
16177             Check_Arg_Count (1);
16178             Check_Arg_Is_Library_Level_Local_Name (Arg1);
16179
16180             Type_Id := Get_Pragma_Arg (Arg1);
16181             Find_Type (Type_Id);
16182             Typ := Entity (Type_Id);
16183
16184             if Typ = Any_Type then
16185                return;
16186             end if;
16187
16188             --  We require the pragma to apply to a type declared in a package
16189             --  declaration, but not (immediately) within a package body.
16190
16191             if Ekind (Current_Scope) /= E_Package
16192               or else In_Package_Body (Current_Scope)
16193             then
16194                Error_Pragma
16195                  ("pragma% can only apply to type declared immediately "
16196                   & "within a package declaration");
16197             end if;
16198
16199             --  A simple storage pool type must be an immutably limited record
16200             --  or private type. If the pragma is given for a private type,
16201             --  the full type is similarly restricted (which is checked later
16202             --  in Freeze_Entity).
16203
16204             if Is_Record_Type (Typ)
16205               and then not Is_Immutably_Limited_Type (Typ)
16206             then
16207                Error_Pragma
16208                  ("pragma% can only apply to explicitly limited record type");
16209
16210             elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then
16211                Error_Pragma
16212                  ("pragma% can only apply to a private type that is limited");
16213
16214             elsif not Is_Record_Type (Typ)
16215               and then not Is_Private_Type (Typ)
16216             then
16217                Error_Pragma
16218                  ("pragma% can only apply to limited record or private type");
16219             end if;
16220
16221             Record_Rep_Item (Typ, N);
16222          end Simple_Storage_Pool_Type;
16223
16224          ----------------------
16225          -- Source_File_Name --
16226          ----------------------
16227
16228          --  There are five forms for this pragma:
16229
16230          --  pragma Source_File_Name (
16231          --    [UNIT_NAME      =>] unit_NAME,
16232          --     BODY_FILE_NAME =>  STRING_LITERAL
16233          --    [, [INDEX =>] INTEGER_LITERAL]);
16234
16235          --  pragma Source_File_Name (
16236          --    [UNIT_NAME      =>] unit_NAME,
16237          --     SPEC_FILE_NAME =>  STRING_LITERAL
16238          --    [, [INDEX =>] INTEGER_LITERAL]);
16239
16240          --  pragma Source_File_Name (
16241          --     BODY_FILE_NAME  => STRING_LITERAL
16242          --  [, DOT_REPLACEMENT => STRING_LITERAL]
16243          --  [, CASING          => CASING_SPEC]);
16244
16245          --  pragma Source_File_Name (
16246          --     SPEC_FILE_NAME  => STRING_LITERAL
16247          --  [, DOT_REPLACEMENT => STRING_LITERAL]
16248          --  [, CASING          => CASING_SPEC]);
16249
16250          --  pragma Source_File_Name (
16251          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
16252          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
16253          --  [, CASING             => CASING_SPEC]);
16254
16255          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
16256
16257          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
16258          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
16259          --  only be used when no project file is used, while SFNP can only be
16260          --  used when a project file is used.
16261
16262          --  No processing here. Processing was completed during parsing, since
16263          --  we need to have file names set as early as possible. Units are
16264          --  loaded well before semantic processing starts.
16265
16266          --  The only processing we defer to this point is the check for
16267          --  correct placement.
16268
16269          when Pragma_Source_File_Name =>
16270             GNAT_Pragma;
16271             Check_Valid_Configuration_Pragma;
16272
16273          ------------------------------
16274          -- Source_File_Name_Project --
16275          ------------------------------
16276
16277          --  See Source_File_Name for syntax
16278
16279          --  No processing here. Processing was completed during parsing, since
16280          --  we need to have file names set as early as possible. Units are
16281          --  loaded well before semantic processing starts.
16282
16283          --  The only processing we defer to this point is the check for
16284          --  correct placement.
16285
16286          when Pragma_Source_File_Name_Project =>
16287             GNAT_Pragma;
16288             Check_Valid_Configuration_Pragma;
16289
16290             --  Check that a pragma Source_File_Name_Project is used only in a
16291             --  configuration pragmas file.
16292
16293             --  Pragmas Source_File_Name_Project should only be generated by
16294             --  the Project Manager in configuration pragmas files.
16295
16296             --  This is really an ugly test. It seems to depend on some
16297             --  accidental and undocumented property. At the very least it
16298             --  needs to be documented, but it would be better to have a
16299             --  clean way of testing if we are in a configuration file???
16300
16301             if Present (Parent (N)) then
16302                Error_Pragma
16303                  ("pragma% can only appear in a configuration pragmas file");
16304             end if;
16305
16306          ----------------------
16307          -- Source_Reference --
16308          ----------------------
16309
16310          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
16311
16312          --  Nothing to do, all processing completed in Par.Prag, since we need
16313          --  the information for possible parser messages that are output.
16314
16315          when Pragma_Source_Reference =>
16316             GNAT_Pragma;
16317
16318          --------------------------------
16319          -- Static_Elaboration_Desired --
16320          --------------------------------
16321
16322          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
16323
16324          when Pragma_Static_Elaboration_Desired =>
16325             GNAT_Pragma;
16326             Check_At_Most_N_Arguments (1);
16327
16328             if Is_Compilation_Unit (Current_Scope)
16329               and then Ekind (Current_Scope) = E_Package
16330             then
16331                Set_Static_Elaboration_Desired (Current_Scope, True);
16332             else
16333                Error_Pragma ("pragma% must apply to a library-level package");
16334             end if;
16335
16336          ------------------
16337          -- Storage_Size --
16338          ------------------
16339
16340          --  pragma Storage_Size (EXPRESSION);
16341
16342          when Pragma_Storage_Size => Storage_Size : declare
16343             P   : constant Node_Id := Parent (N);
16344             Arg : Node_Id;
16345
16346          begin
16347             Check_No_Identifiers;
16348             Check_Arg_Count (1);
16349
16350             --  The expression must be analyzed in the special manner described
16351             --  in "Handling of Default Expressions" in sem.ads.
16352
16353             Arg := Get_Pragma_Arg (Arg1);
16354             Preanalyze_Spec_Expression (Arg, Any_Integer);
16355
16356             if not Is_Static_Expression (Arg) then
16357                Check_Restriction (Static_Storage_Size, Arg);
16358             end if;
16359
16360             if Nkind (P) /= N_Task_Definition then
16361                Pragma_Misplaced;
16362                return;
16363
16364             else
16365                if Has_Storage_Size_Pragma (P) then
16366                   Error_Pragma ("duplicate pragma% not allowed");
16367                else
16368                   Set_Has_Storage_Size_Pragma (P, True);
16369                end if;
16370
16371                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
16372             end if;
16373          end Storage_Size;
16374
16375          ------------------
16376          -- Storage_Unit --
16377          ------------------
16378
16379          --  pragma Storage_Unit (NUMERIC_LITERAL);
16380
16381          --  Only permitted argument is System'Storage_Unit value
16382
16383          when Pragma_Storage_Unit =>
16384             Check_No_Identifiers;
16385             Check_Arg_Count (1);
16386             Check_Arg_Is_Integer_Literal (Arg1);
16387
16388             if Intval (Get_Pragma_Arg (Arg1)) /=
16389               UI_From_Int (Ttypes.System_Storage_Unit)
16390             then
16391                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
16392                Error_Pragma_Arg
16393                  ("the only allowed argument for pragma% is ^", Arg1);
16394             end if;
16395
16396          --------------------
16397          -- Stream_Convert --
16398          --------------------
16399
16400          --  pragma Stream_Convert (
16401          --    [Entity =>] type_LOCAL_NAME,
16402          --    [Read   =>] function_NAME,
16403          --    [Write  =>] function NAME);
16404
16405          when Pragma_Stream_Convert => Stream_Convert : declare
16406
16407             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
16408             --  Check that the given argument is the name of a local function
16409             --  of one argument that is not overloaded earlier in the current
16410             --  local scope. A check is also made that the argument is a
16411             --  function with one parameter.
16412
16413             --------------------------------------
16414             -- Check_OK_Stream_Convert_Function --
16415             --------------------------------------
16416
16417             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
16418                Ent : Entity_Id;
16419
16420             begin
16421                Check_Arg_Is_Local_Name (Arg);
16422                Ent := Entity (Get_Pragma_Arg (Arg));
16423
16424                if Has_Homonym (Ent) then
16425                   Error_Pragma_Arg
16426                     ("argument for pragma% may not be overloaded", Arg);
16427                end if;
16428
16429                if Ekind (Ent) /= E_Function
16430                  or else No (First_Formal (Ent))
16431                  or else Present (Next_Formal (First_Formal (Ent)))
16432                then
16433                   Error_Pragma_Arg
16434                     ("argument for pragma% must be function of one argument",
16435                      Arg);
16436                end if;
16437             end Check_OK_Stream_Convert_Function;
16438
16439          --  Start of processing for Stream_Convert
16440
16441          begin
16442             GNAT_Pragma;
16443             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
16444             Check_Arg_Count (3);
16445             Check_Optional_Identifier (Arg1, Name_Entity);
16446             Check_Optional_Identifier (Arg2, Name_Read);
16447             Check_Optional_Identifier (Arg3, Name_Write);
16448             Check_Arg_Is_Local_Name (Arg1);
16449             Check_OK_Stream_Convert_Function (Arg2);
16450             Check_OK_Stream_Convert_Function (Arg3);
16451
16452             declare
16453                Typ   : constant Entity_Id :=
16454                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
16455                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
16456                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
16457
16458             begin
16459                Check_First_Subtype (Arg1);
16460
16461                --  Check for too early or too late. Note that we don't enforce
16462                --  the rule about primitive operations in this case, since, as
16463                --  is the case for explicit stream attributes themselves, these
16464                --  restrictions are not appropriate. Note that the chaining of
16465                --  the pragma by Rep_Item_Too_Late is actually the critical
16466                --  processing done for this pragma.
16467
16468                if Rep_Item_Too_Early (Typ, N)
16469                     or else
16470                   Rep_Item_Too_Late (Typ, N, FOnly => True)
16471                then
16472                   return;
16473                end if;
16474
16475                --  Return if previous error
16476
16477                if Etype (Typ) = Any_Type
16478                     or else
16479                   Etype (Read) = Any_Type
16480                     or else
16481                   Etype (Write) = Any_Type
16482                then
16483                   return;
16484                end if;
16485
16486                --  Error checks
16487
16488                if Underlying_Type (Etype (Read)) /= Typ then
16489                   Error_Pragma_Arg
16490                     ("incorrect return type for function&", Arg2);
16491                end if;
16492
16493                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
16494                   Error_Pragma_Arg
16495                     ("incorrect parameter type for function&", Arg3);
16496                end if;
16497
16498                if Underlying_Type (Etype (First_Formal (Read))) /=
16499                   Underlying_Type (Etype (Write))
16500                then
16501                   Error_Pragma_Arg
16502                     ("result type of & does not match Read parameter type",
16503                      Arg3);
16504                end if;
16505             end;
16506          end Stream_Convert;
16507
16508          ------------------
16509          -- Style_Checks --
16510          ------------------
16511
16512          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
16513
16514          --  This is processed by the parser since some of the style checks
16515          --  take place during source scanning and parsing. This means that
16516          --  we don't need to issue error messages here.
16517
16518          when Pragma_Style_Checks => Style_Checks : declare
16519             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
16520             S  : String_Id;
16521             C  : Char_Code;
16522
16523          begin
16524             GNAT_Pragma;
16525             Check_No_Identifiers;
16526
16527             --  Two argument form
16528
16529             if Arg_Count = 2 then
16530                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
16531
16532                declare
16533                   E_Id : Node_Id;
16534                   E    : Entity_Id;
16535
16536                begin
16537                   E_Id := Get_Pragma_Arg (Arg2);
16538                   Analyze (E_Id);
16539
16540                   if not Is_Entity_Name (E_Id) then
16541                      Error_Pragma_Arg
16542                        ("second argument of pragma% must be entity name",
16543                         Arg2);
16544                   end if;
16545
16546                   E := Entity (E_Id);
16547
16548                   if not Ignore_Style_Checks_Pragmas then
16549                      if E = Any_Id then
16550                         return;
16551                      else
16552                         loop
16553                            Set_Suppress_Style_Checks
16554                              (E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off);
16555                            exit when No (Homonym (E));
16556                            E := Homonym (E);
16557                         end loop;
16558                      end if;
16559                   end if;
16560                end;
16561
16562             --  One argument form
16563
16564             else
16565                Check_Arg_Count (1);
16566
16567                if Nkind (A) = N_String_Literal then
16568                   S   := Strval (A);
16569
16570                   declare
16571                      Slen    : constant Natural := Natural (String_Length (S));
16572                      Options : String (1 .. Slen);
16573                      J       : Natural;
16574
16575                   begin
16576                      J := 1;
16577                      loop
16578                         C := Get_String_Char (S, Int (J));
16579                         exit when not In_Character_Range (C);
16580                         Options (J) := Get_Character (C);
16581
16582                         --  If at end of string, set options. As per discussion
16583                         --  above, no need to check for errors, since we issued
16584                         --  them in the parser.
16585
16586                         if J = Slen then
16587                            if not Ignore_Style_Checks_Pragmas then
16588                               Set_Style_Check_Options (Options);
16589                            end if;
16590
16591                            exit;
16592                         end if;
16593
16594                         J := J + 1;
16595                      end loop;
16596                   end;
16597
16598                elsif Nkind (A) = N_Identifier then
16599                   if Chars (A) = Name_All_Checks then
16600                      if not Ignore_Style_Checks_Pragmas then
16601                         if GNAT_Mode then
16602                            Set_GNAT_Style_Check_Options;
16603                         else
16604                            Set_Default_Style_Check_Options;
16605                         end if;
16606                      end if;
16607
16608                   elsif Chars (A) = Name_On then
16609                      if not Ignore_Style_Checks_Pragmas then
16610                         Style_Check := True;
16611                      end if;
16612
16613                   elsif Chars (A) = Name_Off then
16614                      if not Ignore_Style_Checks_Pragmas then
16615                         Style_Check := False;
16616                      end if;
16617                   end if;
16618                end if;
16619             end if;
16620          end Style_Checks;
16621
16622          --------------
16623          -- Subtitle --
16624          --------------
16625
16626          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
16627
16628          when Pragma_Subtitle =>
16629             GNAT_Pragma;
16630             Check_Arg_Count (1);
16631             Check_Optional_Identifier (Arg1, Name_Subtitle);
16632             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
16633             Store_Note (N);
16634
16635          --------------
16636          -- Suppress --
16637          --------------
16638
16639          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
16640
16641          when Pragma_Suppress =>
16642             Process_Suppress_Unsuppress (True);
16643
16644          ------------------
16645          -- Suppress_All --
16646          ------------------
16647
16648          --  pragma Suppress_All;
16649
16650          --  The only check made here is that the pragma has no arguments.
16651          --  There are no placement rules, and the processing required (setting
16652          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
16653          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
16654          --  then creates and inserts a pragma Suppress (All_Checks).
16655
16656          when Pragma_Suppress_All =>
16657             GNAT_Pragma;
16658             Check_Arg_Count (0);
16659
16660          -------------------------
16661          -- Suppress_Debug_Info --
16662          -------------------------
16663
16664          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
16665
16666          when Pragma_Suppress_Debug_Info =>
16667             GNAT_Pragma;
16668             Check_Arg_Count (1);
16669             Check_Optional_Identifier (Arg1, Name_Entity);
16670             Check_Arg_Is_Local_Name (Arg1);
16671             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
16672
16673          ----------------------------------
16674          -- Suppress_Exception_Locations --
16675          ----------------------------------
16676
16677          --  pragma Suppress_Exception_Locations;
16678
16679          when Pragma_Suppress_Exception_Locations =>
16680             GNAT_Pragma;
16681             Check_Arg_Count (0);
16682             Check_Valid_Configuration_Pragma;
16683             Exception_Locations_Suppressed := True;
16684
16685          -----------------------------
16686          -- Suppress_Initialization --
16687          -----------------------------
16688
16689          --  pragma Suppress_Initialization ([Entity =>] type_Name);
16690
16691          when Pragma_Suppress_Initialization => Suppress_Init : declare
16692             E_Id : Node_Id;
16693             E    : Entity_Id;
16694
16695          begin
16696             GNAT_Pragma;
16697             Check_Arg_Count (1);
16698             Check_Optional_Identifier (Arg1, Name_Entity);
16699             Check_Arg_Is_Local_Name (Arg1);
16700
16701             E_Id := Get_Pragma_Arg (Arg1);
16702
16703             if Etype (E_Id) = Any_Type then
16704                return;
16705             end if;
16706
16707             E := Entity (E_Id);
16708
16709             if not Is_Type (E) then
16710                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
16711             end if;
16712
16713             if Rep_Item_Too_Early (E, N)
16714                  or else
16715                Rep_Item_Too_Late (E, N, FOnly => True)
16716             then
16717                return;
16718             end if;
16719
16720             --  For incomplete/private type, set flag on full view
16721
16722             if Is_Incomplete_Or_Private_Type (E) then
16723                if No (Full_View (Base_Type (E))) then
16724                   Error_Pragma_Arg
16725                     ("argument of pragma% cannot be an incomplete type", Arg1);
16726                else
16727                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
16728                end if;
16729
16730             --  For first subtype, set flag on base type
16731
16732             elsif Is_First_Subtype (E) then
16733                Set_Suppress_Initialization (Base_Type (E));
16734
16735             --  For other than first subtype, set flag on subtype itself
16736
16737             else
16738                Set_Suppress_Initialization (E);
16739             end if;
16740          end Suppress_Init;
16741
16742          -----------------
16743          -- System_Name --
16744          -----------------
16745
16746          --  pragma System_Name (DIRECT_NAME);
16747
16748          --  Syntax check: one argument, which must be the identifier GNAT or
16749          --  the identifier GCC, no other identifiers are acceptable.
16750
16751          when Pragma_System_Name =>
16752             GNAT_Pragma;
16753             Check_No_Identifiers;
16754             Check_Arg_Count (1);
16755             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
16756
16757          -----------------------------
16758          -- Task_Dispatching_Policy --
16759          -----------------------------
16760
16761          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
16762
16763          when Pragma_Task_Dispatching_Policy => declare
16764             DP : Character;
16765
16766          begin
16767             Check_Ada_83_Warning;
16768             Check_Arg_Count (1);
16769             Check_No_Identifiers;
16770             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
16771             Check_Valid_Configuration_Pragma;
16772             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
16773             DP := Fold_Upper (Name_Buffer (1));
16774
16775             if Task_Dispatching_Policy /= ' '
16776               and then Task_Dispatching_Policy /= DP
16777             then
16778                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
16779                Error_Pragma
16780                  ("task dispatching policy incompatible with policy#");
16781
16782             --  Set new policy, but always preserve System_Location since we
16783             --  like the error message with the run time name.
16784
16785             else
16786                Task_Dispatching_Policy := DP;
16787
16788                if Task_Dispatching_Policy_Sloc /= System_Location then
16789                   Task_Dispatching_Policy_Sloc := Loc;
16790                end if;
16791             end if;
16792          end;
16793
16794          ---------------
16795          -- Task_Info --
16796          ---------------
16797
16798          --  pragma Task_Info (EXPRESSION);
16799
16800          when Pragma_Task_Info => Task_Info : declare
16801             P   : constant Node_Id := Parent (N);
16802             Ent : Entity_Id;
16803
16804          begin
16805             GNAT_Pragma;
16806
16807             if Nkind (P) /= N_Task_Definition then
16808                Error_Pragma ("pragma% must appear in task definition");
16809             end if;
16810
16811             Check_No_Identifiers;
16812             Check_Arg_Count (1);
16813
16814             Analyze_And_Resolve
16815               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
16816
16817             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
16818                return;
16819             end if;
16820
16821             Ent := Defining_Identifier (Parent (P));
16822
16823             --  Check duplicate pragma before we chain the pragma in the Rep
16824             --  Item chain of Ent.
16825
16826             if Has_Rep_Pragma
16827                  (Ent, Name_Task_Info, Check_Parents => False)
16828             then
16829                Error_Pragma ("duplicate pragma% not allowed");
16830             end if;
16831
16832             Record_Rep_Item (Ent, N);
16833          end Task_Info;
16834
16835          ---------------
16836          -- Task_Name --
16837          ---------------
16838
16839          --  pragma Task_Name (string_EXPRESSION);
16840
16841          when Pragma_Task_Name => Task_Name : declare
16842             P   : constant Node_Id := Parent (N);
16843             Arg : Node_Id;
16844             Ent : Entity_Id;
16845
16846          begin
16847             Check_No_Identifiers;
16848             Check_Arg_Count (1);
16849
16850             Arg := Get_Pragma_Arg (Arg1);
16851
16852             --  The expression is used in the call to Create_Task, and must be
16853             --  expanded there, not in the context of the current spec. It must
16854             --  however be analyzed to capture global references, in case it
16855             --  appears in a generic context.
16856
16857             Preanalyze_And_Resolve (Arg, Standard_String);
16858
16859             if Nkind (P) /= N_Task_Definition then
16860                Pragma_Misplaced;
16861             end if;
16862
16863             Ent := Defining_Identifier (Parent (P));
16864
16865             --  Check duplicate pragma before we chain the pragma in the Rep
16866             --  Item chain of Ent.
16867
16868             if Has_Rep_Pragma
16869                  (Ent, Name_Task_Name, Check_Parents => False)
16870             then
16871                Error_Pragma ("duplicate pragma% not allowed");
16872             end if;
16873
16874             Record_Rep_Item (Ent, N);
16875          end Task_Name;
16876
16877          ------------------
16878          -- Task_Storage --
16879          ------------------
16880
16881          --  pragma Task_Storage (
16882          --     [Task_Type =>] LOCAL_NAME,
16883          --     [Top_Guard =>] static_integer_EXPRESSION);
16884
16885          when Pragma_Task_Storage => Task_Storage : declare
16886             Args  : Args_List (1 .. 2);
16887             Names : constant Name_List (1 .. 2) := (
16888                       Name_Task_Type,
16889                       Name_Top_Guard);
16890
16891             Task_Type : Node_Id renames Args (1);
16892             Top_Guard : Node_Id renames Args (2);
16893
16894             Ent : Entity_Id;
16895
16896          begin
16897             GNAT_Pragma;
16898             Gather_Associations (Names, Args);
16899
16900             if No (Task_Type) then
16901                Error_Pragma
16902                  ("missing task_type argument for pragma%");
16903             end if;
16904
16905             Check_Arg_Is_Local_Name (Task_Type);
16906
16907             Ent := Entity (Task_Type);
16908
16909             if not Is_Task_Type (Ent) then
16910                Error_Pragma_Arg
16911                  ("argument for pragma% must be task type", Task_Type);
16912             end if;
16913
16914             if No (Top_Guard) then
16915                Error_Pragma_Arg
16916                  ("pragma% takes two arguments", Task_Type);
16917             else
16918                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
16919             end if;
16920
16921             Check_First_Subtype (Task_Type);
16922
16923             if Rep_Item_Too_Late (Ent, N) then
16924                raise Pragma_Exit;
16925             end if;
16926          end Task_Storage;
16927
16928          ---------------
16929          -- Test_Case --
16930          ---------------
16931
16932          --  pragma Test_Case
16933          --    ([Name     =>] Static_String_EXPRESSION
16934          --    ,[Mode     =>] MODE_TYPE
16935          --   [, Requires =>  Boolean_EXPRESSION]
16936          --   [, Ensures  =>  Boolean_EXPRESSION]);
16937
16938          --  MODE_TYPE ::= Nominal | Robustness
16939
16940          when Pragma_Test_Case =>
16941             GNAT_Pragma;
16942             Check_Test_Case;
16943
16944          --------------------------
16945          -- Thread_Local_Storage --
16946          --------------------------
16947
16948          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
16949
16950          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
16951             Id : Node_Id;
16952             E  : Entity_Id;
16953
16954          begin
16955             GNAT_Pragma;
16956             Check_Arg_Count (1);
16957             Check_Optional_Identifier (Arg1, Name_Entity);
16958             Check_Arg_Is_Library_Level_Local_Name (Arg1);
16959
16960             Id := Get_Pragma_Arg (Arg1);
16961             Analyze (Id);
16962
16963             if not Is_Entity_Name (Id)
16964               or else Ekind (Entity (Id)) /= E_Variable
16965             then
16966                Error_Pragma_Arg ("local variable name required", Arg1);
16967             end if;
16968
16969             E := Entity (Id);
16970
16971             if Rep_Item_Too_Early (E, N)
16972               or else Rep_Item_Too_Late (E, N)
16973             then
16974                raise Pragma_Exit;
16975             end if;
16976
16977             Set_Has_Pragma_Thread_Local_Storage (E);
16978             Set_Has_Gigi_Rep_Item (E);
16979          end Thread_Local_Storage;
16980
16981          ----------------
16982          -- Time_Slice --
16983          ----------------
16984
16985          --  pragma Time_Slice (static_duration_EXPRESSION);
16986
16987          when Pragma_Time_Slice => Time_Slice : declare
16988             Val : Ureal;
16989             Nod : Node_Id;
16990
16991          begin
16992             GNAT_Pragma;
16993             Check_Arg_Count (1);
16994             Check_No_Identifiers;
16995             Check_In_Main_Program;
16996             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
16997
16998             if not Error_Posted (Arg1) then
16999                Nod := Next (N);
17000                while Present (Nod) loop
17001                   if Nkind (Nod) = N_Pragma
17002                     and then Pragma_Name (Nod) = Name_Time_Slice
17003                   then
17004                      Error_Msg_Name_1 := Pname;
17005                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
17006                   end if;
17007
17008                   Next (Nod);
17009                end loop;
17010             end if;
17011
17012             --  Process only if in main unit
17013
17014             if Get_Source_Unit (Loc) = Main_Unit then
17015                Opt.Time_Slice_Set := True;
17016                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
17017
17018                if Val <= Ureal_0 then
17019                   Opt.Time_Slice_Value := 0;
17020
17021                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
17022                   Opt.Time_Slice_Value := 1_000_000_000;
17023
17024                else
17025                   Opt.Time_Slice_Value :=
17026                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
17027                end if;
17028             end if;
17029          end Time_Slice;
17030
17031          -----------
17032          -- Title --
17033          -----------
17034
17035          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
17036
17037          --   TITLING_OPTION ::=
17038          --     [Title =>] STRING_LITERAL
17039          --   | [Subtitle =>] STRING_LITERAL
17040
17041          when Pragma_Title => Title : declare
17042             Args  : Args_List (1 .. 2);
17043             Names : constant Name_List (1 .. 2) := (
17044                       Name_Title,
17045                       Name_Subtitle);
17046
17047          begin
17048             GNAT_Pragma;
17049             Gather_Associations (Names, Args);
17050             Store_Note (N);
17051
17052             for J in 1 .. 2 loop
17053                if Present (Args (J)) then
17054                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
17055                end if;
17056             end loop;
17057          end Title;
17058
17059          ---------------------
17060          -- Unchecked_Union --
17061          ---------------------
17062
17063          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
17064
17065          when Pragma_Unchecked_Union => Unchecked_Union : declare
17066             Assoc   : constant Node_Id := Arg1;
17067             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
17068             Typ     : Entity_Id;
17069             Tdef    : Node_Id;
17070             Clist   : Node_Id;
17071             Vpart   : Node_Id;
17072             Comp    : Node_Id;
17073             Variant : Node_Id;
17074
17075          begin
17076             Ada_2005_Pragma;
17077             Check_No_Identifiers;
17078             Check_Arg_Count (1);
17079             Check_Arg_Is_Local_Name (Arg1);
17080
17081             Find_Type (Type_Id);
17082
17083             Typ := Entity (Type_Id);
17084
17085             if Typ = Any_Type
17086               or else Rep_Item_Too_Early (Typ, N)
17087             then
17088                return;
17089             else
17090                Typ := Underlying_Type (Typ);
17091             end if;
17092
17093             if Rep_Item_Too_Late (Typ, N) then
17094                return;
17095             end if;
17096
17097             Check_First_Subtype (Arg1);
17098
17099             --  Note remaining cases are references to a type in the current
17100             --  declarative part. If we find an error, we post the error on
17101             --  the relevant type declaration at an appropriate point.
17102
17103             if not Is_Record_Type (Typ) then
17104                Error_Msg_N ("unchecked union must be record type", Typ);
17105                return;
17106
17107             elsif Is_Tagged_Type (Typ) then
17108                Error_Msg_N ("unchecked union must not be tagged", Typ);
17109                return;
17110
17111             elsif not Has_Discriminants (Typ) then
17112                Error_Msg_N
17113                 ("unchecked union must have one discriminant", Typ);
17114                return;
17115
17116             --  Note: in previous versions of GNAT we used to check for limited
17117             --  types and give an error, but in fact the standard does allow
17118             --  Unchecked_Union on limited types, so this check was removed.
17119
17120             --  Similarly, GNAT used to require that all discriminants have
17121             --  default values, but this is not mandated by the RM.
17122
17123             --  Proceed with basic error checks completed
17124
17125             else
17126                Tdef  := Type_Definition (Declaration_Node (Typ));
17127                Clist := Component_List (Tdef);
17128
17129                --  Check presence of component list and variant part
17130
17131                if No (Clist) or else No (Variant_Part (Clist)) then
17132                   Error_Msg_N
17133                     ("unchecked union must have variant part", Tdef);
17134                   return;
17135                end if;
17136
17137                --  Check components
17138
17139                Comp := First (Component_Items (Clist));
17140                while Present (Comp) loop
17141                   Check_Component (Comp, Typ);
17142                   Next (Comp);
17143                end loop;
17144
17145                --  Check variant part
17146
17147                Vpart := Variant_Part (Clist);
17148
17149                Variant := First (Variants (Vpart));
17150                while Present (Variant) loop
17151                   Check_Variant (Variant, Typ);
17152                   Next (Variant);
17153                end loop;
17154             end if;
17155
17156             Set_Is_Unchecked_Union  (Typ);
17157             Set_Convention (Typ, Convention_C);
17158             Set_Has_Unchecked_Union (Base_Type (Typ));
17159             Set_Is_Unchecked_Union  (Base_Type (Typ));
17160          end Unchecked_Union;
17161
17162          ------------------------
17163          -- Unimplemented_Unit --
17164          ------------------------
17165
17166          --  pragma Unimplemented_Unit;
17167
17168          --  Note: this only gives an error if we are generating code, or if
17169          --  we are in a generic library unit (where the pragma appears in the
17170          --  body, not in the spec).
17171
17172          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
17173             Cunitent : constant Entity_Id :=
17174                          Cunit_Entity (Get_Source_Unit (Loc));
17175             Ent_Kind : constant Entity_Kind :=
17176                          Ekind (Cunitent);
17177
17178          begin
17179             GNAT_Pragma;
17180             Check_Arg_Count (0);
17181
17182             if Operating_Mode = Generate_Code
17183               or else Ent_Kind = E_Generic_Function
17184               or else Ent_Kind = E_Generic_Procedure
17185               or else Ent_Kind = E_Generic_Package
17186             then
17187                Get_Name_String (Chars (Cunitent));
17188                Set_Casing (Mixed_Case);
17189                Write_Str (Name_Buffer (1 .. Name_Len));
17190                Write_Str (" is not supported in this configuration");
17191                Write_Eol;
17192                raise Unrecoverable_Error;
17193             end if;
17194          end Unimplemented_Unit;
17195
17196          ------------------------
17197          -- Universal_Aliasing --
17198          ------------------------
17199
17200          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
17201
17202          when Pragma_Universal_Aliasing => Universal_Alias : declare
17203             E_Id : Entity_Id;
17204
17205          begin
17206             GNAT_Pragma;
17207             Check_Arg_Count (1);
17208             Check_Optional_Identifier (Arg2, Name_Entity);
17209             Check_Arg_Is_Local_Name (Arg1);
17210             E_Id := Entity (Get_Pragma_Arg (Arg1));
17211
17212             if E_Id = Any_Type then
17213                return;
17214             elsif No (E_Id) or else not Is_Type (E_Id) then
17215                Error_Pragma_Arg ("pragma% requires type", Arg1);
17216             end if;
17217
17218             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
17219             Record_Rep_Item (E_Id, N);
17220          end Universal_Alias;
17221
17222          --------------------
17223          -- Universal_Data --
17224          --------------------
17225
17226          --  pragma Universal_Data [(library_unit_NAME)];
17227
17228          when Pragma_Universal_Data =>
17229             GNAT_Pragma;
17230
17231             --  If this is a configuration pragma, then set the universal
17232             --  addressing option, otherwise confirm that the pragma satisfies
17233             --  the requirements of library unit pragma placement and leave it
17234             --  to the GNAAMP back end to detect the pragma (avoids transitive
17235             --  setting of the option due to withed units).
17236
17237             if Is_Configuration_Pragma then
17238                Universal_Addressing_On_AAMP := True;
17239             else
17240                Check_Valid_Library_Unit_Pragma;
17241             end if;
17242
17243             if not AAMP_On_Target then
17244                Error_Pragma ("??pragma% ignored (applies only to AAMP)");
17245             end if;
17246
17247          ----------------
17248          -- Unmodified --
17249          ----------------
17250
17251          --  pragma Unmodified (local_Name {, local_Name});
17252
17253          when Pragma_Unmodified => Unmodified : declare
17254             Arg_Node : Node_Id;
17255             Arg_Expr : Node_Id;
17256             Arg_Ent  : Entity_Id;
17257
17258          begin
17259             GNAT_Pragma;
17260             Check_At_Least_N_Arguments (1);
17261
17262             --  Loop through arguments
17263
17264             Arg_Node := Arg1;
17265             while Present (Arg_Node) loop
17266                Check_No_Identifier (Arg_Node);
17267
17268                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
17269                --  in fact generate reference, so that the entity will have a
17270                --  reference, which will inhibit any warnings about it not
17271                --  being referenced, and also properly show up in the ali file
17272                --  as a reference. But this reference is recorded before the
17273                --  Has_Pragma_Unreferenced flag is set, so that no warning is
17274                --  generated for this reference.
17275
17276                Check_Arg_Is_Local_Name (Arg_Node);
17277                Arg_Expr := Get_Pragma_Arg (Arg_Node);
17278
17279                if Is_Entity_Name (Arg_Expr) then
17280                   Arg_Ent := Entity (Arg_Expr);
17281
17282                   if not Is_Assignable (Arg_Ent) then
17283                      Error_Pragma_Arg
17284                        ("pragma% can only be applied to a variable",
17285                         Arg_Expr);
17286                   else
17287                      Set_Has_Pragma_Unmodified (Arg_Ent);
17288                   end if;
17289                end if;
17290
17291                Next (Arg_Node);
17292             end loop;
17293          end Unmodified;
17294
17295          ------------------
17296          -- Unreferenced --
17297          ------------------
17298
17299          --  pragma Unreferenced (local_Name {, local_Name});
17300
17301          --    or when used in a context clause:
17302
17303          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
17304
17305          when Pragma_Unreferenced => Unreferenced : declare
17306             Arg_Node : Node_Id;
17307             Arg_Expr : Node_Id;
17308             Arg_Ent  : Entity_Id;
17309             Citem    : Node_Id;
17310
17311          begin
17312             GNAT_Pragma;
17313             Check_At_Least_N_Arguments (1);
17314
17315             --  Check case of appearing within context clause
17316
17317             if Is_In_Context_Clause then
17318
17319                --  The arguments must all be units mentioned in a with clause
17320                --  in the same context clause. Note we already checked (in
17321                --  Par.Prag) that the arguments are either identifiers or
17322                --  selected components.
17323
17324                Arg_Node := Arg1;
17325                while Present (Arg_Node) loop
17326                   Citem := First (List_Containing (N));
17327                   while Citem /= N loop
17328                      if Nkind (Citem) = N_With_Clause
17329                        and then
17330                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
17331                      then
17332                         Set_Has_Pragma_Unreferenced
17333                           (Cunit_Entity
17334                              (Get_Source_Unit
17335                                 (Library_Unit (Citem))));
17336                         Set_Unit_Name
17337                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
17338                         exit;
17339                      end if;
17340
17341                      Next (Citem);
17342                   end loop;
17343
17344                   if Citem = N then
17345                      Error_Pragma_Arg
17346                        ("argument of pragma% is not withed unit", Arg_Node);
17347                   end if;
17348
17349                   Next (Arg_Node);
17350                end loop;
17351
17352             --  Case of not in list of context items
17353
17354             else
17355                Arg_Node := Arg1;
17356                while Present (Arg_Node) loop
17357                   Check_No_Identifier (Arg_Node);
17358
17359                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
17360                   --  will in fact generate reference, so that the entity will
17361                   --  have a reference, which will inhibit any warnings about
17362                   --  it not being referenced, and also properly show up in the
17363                   --  ali file as a reference. But this reference is recorded
17364                   --  before the Has_Pragma_Unreferenced flag is set, so that
17365                   --  no warning is generated for this reference.
17366
17367                   Check_Arg_Is_Local_Name (Arg_Node);
17368                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
17369
17370                   if Is_Entity_Name (Arg_Expr) then
17371                      Arg_Ent := Entity (Arg_Expr);
17372
17373                      --  If the entity is overloaded, the pragma applies to the
17374                      --  most recent overloading, as documented. In this case,
17375                      --  name resolution does not generate a reference, so it
17376                      --  must be done here explicitly.
17377
17378                      if Is_Overloaded (Arg_Expr) then
17379                         Generate_Reference (Arg_Ent, N);
17380                      end if;
17381
17382                      Set_Has_Pragma_Unreferenced (Arg_Ent);
17383                   end if;
17384
17385                   Next (Arg_Node);
17386                end loop;
17387             end if;
17388          end Unreferenced;
17389
17390          --------------------------
17391          -- Unreferenced_Objects --
17392          --------------------------
17393
17394          --  pragma Unreferenced_Objects (local_Name {, local_Name});
17395
17396          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
17397             Arg_Node : Node_Id;
17398             Arg_Expr : Node_Id;
17399
17400          begin
17401             GNAT_Pragma;
17402             Check_At_Least_N_Arguments (1);
17403
17404             Arg_Node := Arg1;
17405             while Present (Arg_Node) loop
17406                Check_No_Identifier (Arg_Node);
17407                Check_Arg_Is_Local_Name (Arg_Node);
17408                Arg_Expr := Get_Pragma_Arg (Arg_Node);
17409
17410                if not Is_Entity_Name (Arg_Expr)
17411                  or else not Is_Type (Entity (Arg_Expr))
17412                then
17413                   Error_Pragma_Arg
17414                     ("argument for pragma% must be type or subtype", Arg_Node);
17415                end if;
17416
17417                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
17418                Next (Arg_Node);
17419             end loop;
17420          end Unreferenced_Objects;
17421
17422          ------------------------------
17423          -- Unreserve_All_Interrupts --
17424          ------------------------------
17425
17426          --  pragma Unreserve_All_Interrupts;
17427
17428          when Pragma_Unreserve_All_Interrupts =>
17429             GNAT_Pragma;
17430             Check_Arg_Count (0);
17431
17432             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
17433                Unreserve_All_Interrupts := True;
17434             end if;
17435
17436          ----------------
17437          -- Unsuppress --
17438          ----------------
17439
17440          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
17441
17442          when Pragma_Unsuppress =>
17443             Ada_2005_Pragma;
17444             Process_Suppress_Unsuppress (False);
17445
17446          -------------------
17447          -- Use_VADS_Size --
17448          -------------------
17449
17450          --  pragma Use_VADS_Size;
17451
17452          when Pragma_Use_VADS_Size =>
17453             GNAT_Pragma;
17454             Check_Arg_Count (0);
17455             Check_Valid_Configuration_Pragma;
17456             Use_VADS_Size := True;
17457
17458          ---------------------
17459          -- Validity_Checks --
17460          ---------------------
17461
17462          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
17463
17464          when Pragma_Validity_Checks => Validity_Checks : declare
17465             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
17466             S  : String_Id;
17467             C  : Char_Code;
17468
17469          begin
17470             GNAT_Pragma;
17471             Check_Arg_Count (1);
17472             Check_No_Identifiers;
17473
17474             if Nkind (A) = N_String_Literal then
17475                S   := Strval (A);
17476
17477                declare
17478                   Slen    : constant Natural := Natural (String_Length (S));
17479                   Options : String (1 .. Slen);
17480                   J       : Natural;
17481
17482                begin
17483                   J := 1;
17484                   loop
17485                      C := Get_String_Char (S, Int (J));
17486                      exit when not In_Character_Range (C);
17487                      Options (J) := Get_Character (C);
17488
17489                      if J = Slen then
17490                         Set_Validity_Check_Options (Options);
17491                         exit;
17492                      else
17493                         J := J + 1;
17494                      end if;
17495                   end loop;
17496                end;
17497
17498             elsif Nkind (A) = N_Identifier then
17499                if Chars (A) = Name_All_Checks then
17500                   Set_Validity_Check_Options ("a");
17501                elsif Chars (A) = Name_On then
17502                   Validity_Checks_On := True;
17503                elsif Chars (A) = Name_Off then
17504                   Validity_Checks_On := False;
17505                end if;
17506             end if;
17507          end Validity_Checks;
17508
17509          --------------
17510          -- Volatile --
17511          --------------
17512
17513          --  pragma Volatile (LOCAL_NAME);
17514
17515          when Pragma_Volatile =>
17516             Process_Atomic_Shared_Volatile;
17517
17518          -------------------------
17519          -- Volatile_Components --
17520          -------------------------
17521
17522          --  pragma Volatile_Components (array_LOCAL_NAME);
17523
17524          --  Volatile is handled by the same circuit as Atomic_Components
17525
17526          --------------
17527          -- Warnings --
17528          --------------
17529
17530          --  pragma Warnings (On | Off [,REASON]);
17531          --  pragma Warnings (On | Off, LOCAL_NAME [,REASON]);
17532          --  pragma Warnings (static_string_EXPRESSION [,REASON]);
17533          --  pragma Warnings (On | Off, STRING_LITERAL [,REASON]);
17534
17535          --  REASON ::= Reason => Static_String_Expression
17536
17537          when Pragma_Warnings => Warnings : begin
17538             GNAT_Pragma;
17539             Check_At_Least_N_Arguments (1);
17540
17541             --  See if last argument is labeled Reason. If so, make sure we
17542             --  have a static string expression, but otherwise just ignore
17543             --  the REASON argument by decreasing Num_Args by 1 (all the
17544             --  remaining tests look only at the first Num_Args arguments).
17545
17546             declare
17547                Last_Arg : constant Node_Id :=
17548                             Last (Pragma_Argument_Associations (N));
17549             begin
17550                if Nkind (Last_Arg) = N_Pragma_Argument_Association
17551                  and then Chars (Last_Arg) = Name_Reason
17552                then
17553                   Check_Arg_Is_Static_Expression (Last_Arg, Standard_String);
17554                   Arg_Count := Arg_Count - 1;
17555                end if;
17556             end;
17557
17558             --  Now proceed with REASON taken care of and eliminated
17559
17560             Check_No_Identifiers;
17561
17562             --  If debug flag -gnatd.i is set, pragma is ignored
17563
17564             if Debug_Flag_Dot_I then
17565                return;
17566             end if;
17567
17568             --  Process various forms of the pragma
17569
17570             declare
17571                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
17572
17573             begin
17574                --  One argument case
17575
17576                if Arg_Count = 1 then
17577
17578                   --  On/Off one argument case was processed by parser
17579
17580                   if Nkind (Argx) = N_Identifier
17581                     and then Nam_In (Chars (Argx), Name_On, Name_Off)
17582                   then
17583                      null;
17584
17585                   --  One argument case must be ON/OFF or static string expr
17586
17587                   elsif not Is_Static_String_Expression (Arg1) then
17588                      Error_Pragma_Arg
17589                        ("argument of pragma% must be On/Off or static string "
17590                         & "expression", Arg1);
17591
17592                   --  One argument string expression case
17593
17594                   else
17595                      declare
17596                         Lit : constant Node_Id   := Expr_Value_S (Argx);
17597                         Str : constant String_Id := Strval (Lit);
17598                         Len : constant Nat       := String_Length (Str);
17599                         C   : Char_Code;
17600                         J   : Nat;
17601                         OK  : Boolean;
17602                         Chr : Character;
17603
17604                      begin
17605                         J := 1;
17606                         while J <= Len loop
17607                            C := Get_String_Char (Str, J);
17608                            OK := In_Character_Range (C);
17609
17610                            if OK then
17611                               Chr := Get_Character (C);
17612
17613                               --  Dash case: only -Wxxx is accepted
17614
17615                               if J = 1
17616                                 and then J < Len
17617                                 and then Chr = '-'
17618                               then
17619                                  J := J + 1;
17620                                  C := Get_String_Char (Str, J);
17621                                  Chr := Get_Character (C);
17622                                  exit when Chr = 'W';
17623                                  OK := False;
17624
17625                               --  Dot case
17626
17627                               elsif J < Len and then Chr = '.' then
17628                                  J := J + 1;
17629                                  C := Get_String_Char (Str, J);
17630                                  Chr := Get_Character (C);
17631
17632                                  if not Set_Dot_Warning_Switch (Chr) then
17633                                     Error_Pragma_Arg
17634                                       ("invalid warning switch character "
17635                                        & '.' & Chr, Arg1);
17636                                  end if;
17637
17638                               --  Non-Dot case
17639
17640                               else
17641                                  OK := Set_Warning_Switch (Chr);
17642                               end if;
17643                            end if;
17644
17645                            if not OK then
17646                               Error_Pragma_Arg
17647                                 ("invalid warning switch character " & Chr,
17648                                  Arg1);
17649                            end if;
17650
17651                            J := J + 1;
17652                         end loop;
17653                      end;
17654                   end if;
17655
17656                --  Two or more arguments (must be two)
17657
17658                else
17659                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
17660                   Check_At_Most_N_Arguments (2);
17661
17662                   declare
17663                      E_Id : Node_Id;
17664                      E    : Entity_Id;
17665                      Err  : Boolean;
17666
17667                   begin
17668                      E_Id := Get_Pragma_Arg (Arg2);
17669                      Analyze (E_Id);
17670
17671                      --  In the expansion of an inlined body, a reference to
17672                      --  the formal may be wrapped in a conversion if the
17673                      --  actual is a conversion. Retrieve the real entity name.
17674
17675                      if (In_Instance_Body or In_Inlined_Body)
17676                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
17677                      then
17678                         E_Id := Expression (E_Id);
17679                      end if;
17680
17681                      --  Entity name case
17682
17683                      if Is_Entity_Name (E_Id) then
17684                         E := Entity (E_Id);
17685
17686                         if E = Any_Id then
17687                            return;
17688                         else
17689                            loop
17690                               Set_Warnings_Off
17691                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
17692                                       Name_Off));
17693
17694                               --  For OFF case, make entry in warnings off
17695                               --  pragma table for later processing. But we do
17696                               --  not do that within an instance, since these
17697                               --  warnings are about what is needed in the
17698                               --  template, not an instance of it.
17699
17700                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
17701                                 and then Warn_On_Warnings_Off
17702                                 and then not In_Instance
17703                               then
17704                                  Warnings_Off_Pragmas.Append ((N, E));
17705                               end if;
17706
17707                               if Is_Enumeration_Type (E) then
17708                                  declare
17709                                     Lit : Entity_Id;
17710                                  begin
17711                                     Lit := First_Literal (E);
17712                                     while Present (Lit) loop
17713                                        Set_Warnings_Off (Lit);
17714                                        Next_Literal (Lit);
17715                                     end loop;
17716                                  end;
17717                               end if;
17718
17719                               exit when No (Homonym (E));
17720                               E := Homonym (E);
17721                            end loop;
17722                         end if;
17723
17724                      --  Error if not entity or static string literal case
17725
17726                      elsif not Is_Static_String_Expression (Arg2) then
17727                         Error_Pragma_Arg
17728                           ("second argument of pragma% must be entity name "
17729                            & "or static string expression", Arg2);
17730
17731                      --  String literal case
17732
17733                      else
17734                         String_To_Name_Buffer
17735                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
17736
17737                         --  Note on configuration pragma case: If this is a
17738                         --  configuration pragma, then for an OFF pragma, we
17739                         --  just set Config True in the call, which is all
17740                         --  that needs to be done. For the case of ON, this
17741                         --  is normally an error, unless it is canceling the
17742                         --  effect of a previous OFF pragma in the same file.
17743                         --  In any other case, an error will be signalled (ON
17744                         --  with no matching OFF).
17745
17746                         --  Note: We set Used if we are inside a generic to
17747                         --  disable the test that the non-config case actually
17748                         --  cancels a warning. That's because we can't be sure
17749                         --  there isn't an instantiation in some other unit
17750                         --  where a warning is suppressed.
17751
17752                         --  We could do a little better here by checking if the
17753                         --  generic unit we are inside is public, but for now
17754                         --  we don't bother with that refinement.
17755
17756                         if Chars (Argx) = Name_Off then
17757                            Set_Specific_Warning_Off
17758                              (Loc, Name_Buffer (1 .. Name_Len),
17759                               Config => Is_Configuration_Pragma,
17760                               Used   => Inside_A_Generic or else In_Instance);
17761
17762                         elsif Chars (Argx) = Name_On then
17763                            Set_Specific_Warning_On
17764                              (Loc, Name_Buffer (1 .. Name_Len), Err);
17765
17766                            if Err then
17767                               Error_Msg
17768                                 ("??pragma Warnings On with no matching "
17769                                  & "Warnings Off", Loc);
17770                            end if;
17771                         end if;
17772                      end if;
17773                   end;
17774                end if;
17775             end;
17776          end Warnings;
17777
17778          -------------------
17779          -- Weak_External --
17780          -------------------
17781
17782          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
17783
17784          when Pragma_Weak_External => Weak_External : declare
17785             Ent : Entity_Id;
17786
17787          begin
17788             GNAT_Pragma;
17789             Check_Arg_Count (1);
17790             Check_Optional_Identifier (Arg1, Name_Entity);
17791             Check_Arg_Is_Library_Level_Local_Name (Arg1);
17792             Ent := Entity (Get_Pragma_Arg (Arg1));
17793
17794             if Rep_Item_Too_Early (Ent, N) then
17795                return;
17796             else
17797                Ent := Underlying_Type (Ent);
17798             end if;
17799
17800             --  The only processing required is to link this item on to the
17801             --  list of rep items for the given entity. This is accomplished
17802             --  by the call to Rep_Item_Too_Late (when no error is detected
17803             --  and False is returned).
17804
17805             if Rep_Item_Too_Late (Ent, N) then
17806                return;
17807             else
17808                Set_Has_Gigi_Rep_Item (Ent);
17809             end if;
17810          end Weak_External;
17811
17812          -----------------------------
17813          -- Wide_Character_Encoding --
17814          -----------------------------
17815
17816          --  pragma Wide_Character_Encoding (IDENTIFIER);
17817
17818          when Pragma_Wide_Character_Encoding =>
17819             GNAT_Pragma;
17820
17821             --  Nothing to do, handled in parser. Note that we do not enforce
17822             --  configuration pragma placement, this pragma can appear at any
17823             --  place in the source, allowing mixed encodings within a single
17824             --  source program.
17825
17826             null;
17827
17828          --------------------
17829          -- Unknown_Pragma --
17830          --------------------
17831
17832          --  Should be impossible, since the case of an unknown pragma is
17833          --  separately processed before the case statement is entered.
17834
17835          when Unknown_Pragma =>
17836             raise Program_Error;
17837       end case;
17838
17839       --  AI05-0144: detect dangerous order dependence. Disabled for now,
17840       --  until AI is formally approved.
17841
17842       --  Check_Order_Dependence;
17843
17844    exception
17845       when Pragma_Exit => null;
17846    end Analyze_Pragma;
17847
17848    ------------------------------------
17849    -- Analyze_Test_Case_In_Decl_Part --
17850    ------------------------------------
17851
17852    procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id; S : Entity_Id) is
17853    begin
17854       --  Install formals and push subprogram spec onto scope stack so that we
17855       --  can see the formals from the pragma.
17856
17857       Push_Scope (S);
17858       Install_Formals (S);
17859
17860       --  Preanalyze the boolean expressions, we treat these as spec
17861       --  expressions (i.e. similar to a default expression).
17862
17863       if Pragma_Name (N) = Name_Test_Case then
17864          Preanalyze_CTC_Args
17865            (N,
17866             Get_Requires_From_CTC_Pragma (N),
17867             Get_Ensures_From_CTC_Pragma (N));
17868       end if;
17869
17870       --  Remove the subprogram from the scope stack now that the pre-analysis
17871       --  of the expressions in the contract case or test case is done.
17872
17873       End_Scope;
17874    end Analyze_Test_Case_In_Decl_Part;
17875
17876    ----------------
17877    -- Appears_In --
17878    ----------------
17879
17880    function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is
17881       Elmt : Elmt_Id;
17882       Id   : Entity_Id;
17883
17884    begin
17885       if Present (List) then
17886          Elmt := First_Elmt (List);
17887          while Present (Elmt) loop
17888             if Nkind (Node (Elmt)) = N_Defining_Identifier then
17889                Id := Node (Elmt);
17890             else
17891                Id := Entity (Node (Elmt));
17892             end if;
17893
17894             if Id = Item_Id then
17895                return True;
17896             end if;
17897
17898             Next_Elmt (Elmt);
17899          end loop;
17900       end if;
17901
17902       return False;
17903    end Appears_In;
17904
17905    ----------------
17906    -- Check_Kind --
17907    ----------------
17908
17909    function Check_Kind (Nam : Name_Id) return Name_Id is
17910       PP : Node_Id;
17911
17912    begin
17913       --  Loop through entries in check policy list
17914
17915       PP := Opt.Check_Policy_List;
17916       while Present (PP) loop
17917          declare
17918             PPA : constant List_Id := Pragma_Argument_Associations (PP);
17919             Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
17920
17921          begin
17922             if Nam = Pnm
17923               or else (Pnm = Name_Assertion
17924                         and then Is_Valid_Assertion_Kind (Nam))
17925               or else (Pnm = Name_Statement_Assertions
17926                         and then Nam_In (Nam, Name_Assert,
17927                                               Name_Assert_And_Cut,
17928                                               Name_Assume,
17929                                               Name_Loop_Invariant))
17930             then
17931                case (Chars (Get_Pragma_Arg (Last (PPA)))) is
17932                   when Name_On | Name_Check =>
17933                      return Name_Check;
17934                   when Name_Off | Name_Ignore =>
17935                      return Name_Ignore;
17936                   when Name_Disable =>
17937                      return Name_Disable;
17938                   when others =>
17939                      raise Program_Error;
17940                end case;
17941
17942             else
17943                PP := Next_Pragma (PP);
17944             end if;
17945          end;
17946       end loop;
17947
17948       --  If there are no specific entries that matched, then we let the
17949       --  setting of assertions govern. Note that this provides the needed
17950       --  compatibility with the RM for the cases of assertion, invariant,
17951       --  precondition, predicate, and postcondition.
17952
17953       if Assertions_Enabled then
17954          return Name_Check;
17955       else
17956          return Name_Ignore;
17957       end if;
17958    end Check_Kind;
17959
17960    -----------------------------
17961    -- Check_Applicable_Policy --
17962    -----------------------------
17963
17964    procedure Check_Applicable_Policy (N : Node_Id) is
17965       PP     : Node_Id;
17966       Policy : Name_Id;
17967
17968       Ename : constant Name_Id := Original_Name (N);
17969
17970    begin
17971       --  No effect if not valid assertion kind name
17972
17973       if not Is_Valid_Assertion_Kind (Ename) then
17974          return;
17975       end if;
17976
17977       --  Loop through entries in check policy list
17978
17979       PP := Opt.Check_Policy_List;
17980       while Present (PP) loop
17981          declare
17982             PPA : constant List_Id := Pragma_Argument_Associations (PP);
17983             Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA)));
17984
17985          begin
17986             if Ename = Pnm or else Pnm = Name_Assertion then
17987                Policy := Chars (Get_Pragma_Arg (Last (PPA)));
17988
17989                case Policy is
17990                   when Name_Off | Name_Ignore =>
17991                      Set_Is_Ignored (N, True);
17992
17993                   when Name_Disable =>
17994                      Set_Is_Ignored  (N, True);
17995                      Set_Is_Disabled (N, True);
17996
17997                   when others =>
17998                      null;
17999                end case;
18000
18001                return;
18002             end if;
18003
18004             PP := Next_Pragma (PP);
18005          end;
18006       end loop;
18007
18008       --  If there are no specific entries that matched, then we let the
18009       --  setting of assertions govern. Note that this provides the needed
18010       --  compatibility with the RM for the cases of assertion, invariant,
18011       --  precondition, predicate, and postcondition.
18012
18013       if not Assertions_Enabled then
18014          Set_Is_Ignored (N);
18015       end if;
18016    end Check_Applicable_Policy;
18017
18018    ---------------------------------------
18019    -- Collect_Subprogram_Inputs_Outputs --
18020    ---------------------------------------
18021
18022    procedure Collect_Subprogram_Inputs_Outputs
18023      (Subp_Id      : Entity_Id;
18024       Subp_Inputs  : in out Elist_Id;
18025       Subp_Outputs : in out Elist_Id;
18026       Global_Seen  : out Boolean)
18027    is
18028       procedure Collect_Global_List
18029         (List : Node_Id;
18030          Mode : Name_Id := Name_Input);
18031       --  Collect all relevant items from a global list
18032
18033       -------------------------
18034       -- Collect_Global_List --
18035       -------------------------
18036
18037       procedure Collect_Global_List
18038         (List : Node_Id;
18039          Mode : Name_Id := Name_Input)
18040       is
18041          procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id);
18042          --  Add an item to the proper subprogram input or output collection
18043
18044          -------------------------
18045          -- Collect_Global_Item --
18046          -------------------------
18047
18048          procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is
18049          begin
18050             if Nam_In (Mode, Name_In_Out, Name_Input) then
18051                Add_Item (Item, Subp_Inputs);
18052             end if;
18053
18054             if Nam_In (Mode, Name_In_Out, Name_Output) then
18055                Add_Item (Item, Subp_Outputs);
18056             end if;
18057          end Collect_Global_Item;
18058
18059          --  Local variables
18060
18061          Assoc : Node_Id;
18062          Item  : Node_Id;
18063
18064       --  Start of processing for Collect_Global_List
18065
18066       begin
18067          --  Single global item declaration
18068
18069          if Nkind_In (List, N_Identifier, N_Selected_Component) then
18070             Collect_Global_Item (List, Mode);
18071
18072          --  Simple global list or moded global list declaration
18073
18074          else
18075             if Present (Expressions (List)) then
18076                Item := First (Expressions (List));
18077                while Present (Item) loop
18078                   Collect_Global_Item (Item, Mode);
18079                   Next (Item);
18080                end loop;
18081
18082             else
18083                Assoc := First (Component_Associations (List));
18084                while Present (Assoc) loop
18085                   Collect_Global_List
18086                     (List => Expression (Assoc),
18087                      Mode => Chars (First (Choices (Assoc))));
18088                   Next (Assoc);
18089                end loop;
18090             end if;
18091          end if;
18092       end Collect_Global_List;
18093
18094       --  Local variables
18095
18096       Formal : Entity_Id;
18097       Global : Node_Id;
18098       List   : Node_Id;
18099
18100    --  Start of processing for Collect_Subprogram_Inputs_Outputs
18101
18102    begin
18103       Global_Seen := False;
18104
18105       --  Process all formal parameters
18106
18107       Formal := First_Formal (Subp_Id);
18108       while Present (Formal) loop
18109          if Ekind_In (Formal, E_In_Out_Parameter, E_In_Parameter) then
18110             Add_Item (Formal, Subp_Inputs);
18111          end if;
18112
18113          if Ekind_In (Formal, E_In_Out_Parameter, E_Out_Parameter) then
18114             Add_Item (Formal, Subp_Outputs);
18115          end if;
18116
18117          Next_Formal (Formal);
18118       end loop;
18119
18120       --  If the subprogram is subject to pragma Global, traverse all global
18121       --  lists and gather the relevant items.
18122
18123       Global := Find_Aspect (Subp_Id, Aspect_Global);
18124       if Present (Global) then
18125          Global_Seen := True;
18126
18127          --  Retrieve the pragma as it contains the analyzed lists
18128
18129          Global := Aspect_Rep_Item (Global);
18130          List   := Expression (First (Pragma_Argument_Associations (Global)));
18131
18132          --  The pragma may not have been analyzed because of the arbitrary
18133          --  declaration order of aspects. Make sure that it is analyzed for
18134          --  the purposes of item extraction.
18135
18136          if not Analyzed (List) then
18137             Analyze_Global_In_Decl_Part (Global);
18138          end if;
18139
18140          --  Nothing to be done for a null global list
18141
18142          if Nkind (List) /= N_Null then
18143             Collect_Global_List (List);
18144          end if;
18145       end if;
18146    end Collect_Subprogram_Inputs_Outputs;
18147
18148    ---------------------------------
18149    -- Delay_Config_Pragma_Analyze --
18150    ---------------------------------
18151
18152    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
18153    begin
18154       return Nam_In (Pragma_Name (N), Name_Interrupt_State,
18155                                       Name_Priority_Specific_Dispatching);
18156    end Delay_Config_Pragma_Analyze;
18157
18158    -----------------------------
18159    -- Find_Related_Subprogram --
18160    -----------------------------
18161
18162    function Find_Related_Subprogram
18163      (Prag             : Node_Id;
18164       Check_Duplicates : Boolean := False) return Node_Id
18165    is
18166       Context   : constant Node_Id := Parent (Prag);
18167       Nam       : constant Name_Id := Pragma_Name (Prag);
18168       Elmt      : Node_Id;
18169       Subp_Decl : Node_Id;
18170
18171    begin
18172       pragma Assert (Nkind (Prag) = N_Pragma);
18173
18174       --  If the pragma comes from an aspect, then what we want is the
18175       --  declaration to which the aspect is attached, i.e. its parent.
18176
18177       if Present (Corresponding_Aspect (Prag)) then
18178          return Parent (Corresponding_Aspect (Prag));
18179       end if;
18180
18181       --  Otherwise the pragma must be a list element, and the first thing to
18182       --  do is to position past any previous pragmas or generated code. What
18183       --  we are doing here is looking for the preceding declaration. This is
18184       --  also where we will check for a duplicate pragma.
18185
18186       pragma Assert (Is_List_Member (Prag));
18187
18188       Elmt := Prag;
18189       loop
18190          Elmt := Prev (Elmt);
18191          exit when No (Elmt);
18192
18193          --  Typically want we will want is the declaration original node. But
18194          --  for the generic subprogram case, don't go to to the original node,
18195          --  which is the unanalyzed tree: we need to attach the pre- and post-
18196          --  conditions to the analyzed version at this point. They propagate
18197          --  to the original tree when analyzing the corresponding body.
18198
18199          if Nkind (Elmt) not in N_Generic_Declaration then
18200             Subp_Decl := Original_Node (Elmt);
18201          else
18202             Subp_Decl := Elmt;
18203          end if;
18204
18205          --  Skip prior pragmas
18206
18207          if Nkind (Subp_Decl) = N_Pragma then
18208             if Check_Duplicates and then Pragma_Name (Subp_Decl) = Nam then
18209                Error_Msg_Name_1 := Nam;
18210                Error_Msg_Sloc   := Sloc (Subp_Decl);
18211                Error_Msg_N ("pragma % duplicates pragma declared #", Prag);
18212             end if;
18213
18214          --  Skip internally generated code
18215
18216          elsif not Comes_From_Source (Subp_Decl) then
18217             null;
18218
18219          --  Otherwise we have a declaration to return
18220
18221          else
18222             return Subp_Decl;
18223          end if;
18224       end loop;
18225
18226       --  We fell through, which means there was no declaration preceding the
18227       --  pragma (either it was the first element of the list, or we only had
18228       --  other pragmas and generated code before it).
18229
18230       --  The pragma is associated with a library-level subprogram
18231
18232       if Nkind (Context) = N_Compilation_Unit_Aux then
18233          return Unit (Parent (Context));
18234
18235       --  The pragma appears inside the declarative part of a subprogram body
18236
18237       elsif Nkind (Context) = N_Subprogram_Body then
18238          return Context;
18239
18240       --  Otherwise no subprogram found, return original pragma
18241
18242       else
18243          return Prag;
18244       end if;
18245    end Find_Related_Subprogram;
18246
18247    -------------------------
18248    -- Get_Base_Subprogram --
18249    -------------------------
18250
18251    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
18252       Result : Entity_Id;
18253
18254    begin
18255       --  Follow subprogram renaming chain
18256
18257       Result := Def_Id;
18258
18259       if Is_Subprogram (Result)
18260         and then
18261           Nkind (Parent (Declaration_Node (Result))) =
18262                                          N_Subprogram_Renaming_Declaration
18263         and then Present (Alias (Result))
18264       then
18265          Result := Alias (Result);
18266       end if;
18267
18268       return Result;
18269    end Get_Base_Subprogram;
18270
18271    ----------------
18272    -- Initialize --
18273    ----------------
18274
18275    procedure Initialize is
18276    begin
18277       Externals.Init;
18278    end Initialize;
18279
18280    -----------------------------
18281    -- Is_Config_Static_String --
18282    -----------------------------
18283
18284    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
18285
18286       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
18287       --  This is an internal recursive function that is just like the outer
18288       --  function except that it adds the string to the name buffer rather
18289       --  than placing the string in the name buffer.
18290
18291       ------------------------------
18292       -- Add_Config_Static_String --
18293       ------------------------------
18294
18295       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
18296          N : Node_Id;
18297          C : Char_Code;
18298
18299       begin
18300          N := Arg;
18301
18302          if Nkind (N) = N_Op_Concat then
18303             if Add_Config_Static_String (Left_Opnd (N)) then
18304                N := Right_Opnd (N);
18305             else
18306                return False;
18307             end if;
18308          end if;
18309
18310          if Nkind (N) /= N_String_Literal then
18311             Error_Msg_N ("string literal expected for pragma argument", N);
18312             return False;
18313
18314          else
18315             for J in 1 .. String_Length (Strval (N)) loop
18316                C := Get_String_Char (Strval (N), J);
18317
18318                if not In_Character_Range (C) then
18319                   Error_Msg
18320                     ("string literal contains invalid wide character",
18321                      Sloc (N) + 1 + Source_Ptr (J));
18322                   return False;
18323                end if;
18324
18325                Add_Char_To_Name_Buffer (Get_Character (C));
18326             end loop;
18327          end if;
18328
18329          return True;
18330       end Add_Config_Static_String;
18331
18332    --  Start of processing for Is_Config_Static_String
18333
18334    begin
18335
18336       Name_Len := 0;
18337       return Add_Config_Static_String (Arg);
18338    end Is_Config_Static_String;
18339
18340    -----------------------------------------
18341    -- Is_Non_Significant_Pragma_Reference --
18342    -----------------------------------------
18343
18344    --  This function makes use of the following static table which indicates
18345    --  whether appearance of some name in a given pragma is to be considered
18346    --  as a reference for the purposes of warnings about unreferenced objects.
18347
18348    --  -1  indicates that references in any argument position are significant
18349    --  0   indicates that appearance in any argument is not significant
18350    --  +n  indicates that appearance as argument n is significant, but all
18351    --      other arguments are not significant
18352    --  99  special processing required (e.g. for pragma Check)
18353
18354    Sig_Flags : constant array (Pragma_Id) of Int :=
18355      (Pragma_AST_Entry                      => -1,
18356       Pragma_Abort_Defer                    => -1,
18357       Pragma_Abstract_State                 => -1,
18358       Pragma_Ada_83                         => -1,
18359       Pragma_Ada_95                         => -1,
18360       Pragma_Ada_05                         => -1,
18361       Pragma_Ada_2005                       => -1,
18362       Pragma_Ada_12                         => -1,
18363       Pragma_Ada_2012                       => -1,
18364       Pragma_All_Calls_Remote               => -1,
18365       Pragma_Annotate                       => -1,
18366       Pragma_Assert                         => -1,
18367       Pragma_Assert_And_Cut                 => -1,
18368       Pragma_Assertion_Policy               =>  0,
18369       Pragma_Assume                         => -1,
18370       Pragma_Assume_No_Invalid_Values       =>  0,
18371       Pragma_Attribute_Definition           => +3,
18372       Pragma_Asynchronous                   => -1,
18373       Pragma_Atomic                         =>  0,
18374       Pragma_Atomic_Components              =>  0,
18375       Pragma_Attach_Handler                 => -1,
18376       Pragma_Check                          => 99,
18377       Pragma_Check_Float_Overflow           =>  0,
18378       Pragma_Check_Name                     =>  0,
18379       Pragma_Check_Policy                   =>  0,
18380       Pragma_CIL_Constructor                => -1,
18381       Pragma_CPP_Class                      =>  0,
18382       Pragma_CPP_Constructor                =>  0,
18383       Pragma_CPP_Virtual                    =>  0,
18384       Pragma_CPP_Vtable                     =>  0,
18385       Pragma_CPU                            => -1,
18386       Pragma_C_Pass_By_Copy                 =>  0,
18387       Pragma_Comment                        =>  0,
18388       Pragma_Common_Object                  => -1,
18389       Pragma_Compile_Time_Error             => -1,
18390       Pragma_Compile_Time_Warning           => -1,
18391       Pragma_Compiler_Unit                  =>  0,
18392       Pragma_Complete_Representation        =>  0,
18393       Pragma_Complex_Representation         =>  0,
18394       Pragma_Component_Alignment            => -1,
18395       Pragma_Contract_Cases                 => -1,
18396       Pragma_Controlled                     =>  0,
18397       Pragma_Convention                     =>  0,
18398       Pragma_Convention_Identifier          =>  0,
18399       Pragma_Debug                          => -1,
18400       Pragma_Debug_Policy                   =>  0,
18401       Pragma_Detect_Blocking                => -1,
18402       Pragma_Default_Storage_Pool           => -1,
18403       Pragma_Depends                        => -1,
18404       Pragma_Disable_Atomic_Synchronization => -1,
18405       Pragma_Discard_Names                  =>  0,
18406       Pragma_Dispatching_Domain             => -1,
18407       Pragma_Elaborate                      => -1,
18408       Pragma_Elaborate_All                  => -1,
18409       Pragma_Elaborate_Body                 => -1,
18410       Pragma_Elaboration_Checks             => -1,
18411       Pragma_Eliminate                      => -1,
18412       Pragma_Enable_Atomic_Synchronization  => -1,
18413       Pragma_Export                         => -1,
18414       Pragma_Export_Exception               => -1,
18415       Pragma_Export_Function                => -1,
18416       Pragma_Export_Object                  => -1,
18417       Pragma_Export_Procedure               => -1,
18418       Pragma_Export_Value                   => -1,
18419       Pragma_Export_Valued_Procedure        => -1,
18420       Pragma_Extend_System                  => -1,
18421       Pragma_Extensions_Allowed             => -1,
18422       Pragma_External                       => -1,
18423       Pragma_Favor_Top_Level                => -1,
18424       Pragma_External_Name_Casing           => -1,
18425       Pragma_Fast_Math                      => -1,
18426       Pragma_Finalize_Storage_Only          =>  0,
18427       Pragma_Float_Representation           =>  0,
18428       Pragma_Global                         => -1,
18429       Pragma_Ident                          => -1,
18430       Pragma_Implementation_Defined         => -1,
18431       Pragma_Implemented                    => -1,
18432       Pragma_Implicit_Packing               =>  0,
18433       Pragma_Import                         => +2,
18434       Pragma_Import_Exception               =>  0,
18435       Pragma_Import_Function                =>  0,
18436       Pragma_Import_Object                  =>  0,
18437       Pragma_Import_Procedure               =>  0,
18438       Pragma_Import_Valued_Procedure        =>  0,
18439       Pragma_Independent                    =>  0,
18440       Pragma_Independent_Components         =>  0,
18441       Pragma_Initialize_Scalars             => -1,
18442       Pragma_Inline                         =>  0,
18443       Pragma_Inline_Always                  =>  0,
18444       Pragma_Inline_Generic                 =>  0,
18445       Pragma_Inspection_Point               => -1,
18446       Pragma_Interface                      => +2,
18447       Pragma_Interface_Name                 => +2,
18448       Pragma_Interrupt_Handler              => -1,
18449       Pragma_Interrupt_Priority             => -1,
18450       Pragma_Interrupt_State                => -1,
18451       Pragma_Invariant                      => -1,
18452       Pragma_Java_Constructor               => -1,
18453       Pragma_Java_Interface                 => -1,
18454       Pragma_Keep_Names                     =>  0,
18455       Pragma_License                        => -1,
18456       Pragma_Link_With                      => -1,
18457       Pragma_Linker_Alias                   => -1,
18458       Pragma_Linker_Constructor             => -1,
18459       Pragma_Linker_Destructor              => -1,
18460       Pragma_Linker_Options                 => -1,
18461       Pragma_Linker_Section                 => -1,
18462       Pragma_List                           => -1,
18463       Pragma_Lock_Free                      => -1,
18464       Pragma_Locking_Policy                 => -1,
18465       Pragma_Long_Float                     => -1,
18466       Pragma_Loop_Invariant                 => -1,
18467       Pragma_Loop_Optimize                  => -1,
18468       Pragma_Loop_Variant                   => -1,
18469       Pragma_Machine_Attribute              => -1,
18470       Pragma_Main                           => -1,
18471       Pragma_Main_Storage                   => -1,
18472       Pragma_Memory_Size                    => -1,
18473       Pragma_No_Return                      =>  0,
18474       Pragma_No_Body                        =>  0,
18475       Pragma_No_Inline                      =>  0,
18476       Pragma_No_Run_Time                    => -1,
18477       Pragma_No_Strict_Aliasing             => -1,
18478       Pragma_Normalize_Scalars              => -1,
18479       Pragma_Obsolescent                    =>  0,
18480       Pragma_Optimize                       => -1,
18481       Pragma_Optimize_Alignment             => -1,
18482       Pragma_Overflow_Mode                  =>  0,
18483       Pragma_Overriding_Renamings           =>  0,
18484       Pragma_Ordered                        =>  0,
18485       Pragma_Pack                           =>  0,
18486       Pragma_Page                           => -1,
18487       Pragma_Partition_Elaboration_Policy   => -1,
18488       Pragma_Passive                        => -1,
18489       Pragma_Preelaborable_Initialization   => -1,
18490       Pragma_Polling                        => -1,
18491       Pragma_Persistent_BSS                 =>  0,
18492       Pragma_Postcondition                  => -1,
18493       Pragma_Precondition                   => -1,
18494       Pragma_Predicate                      => -1,
18495       Pragma_Preelaborate                   => -1,
18496       Pragma_Preelaborate_05                => -1,
18497       Pragma_Priority                       => -1,
18498       Pragma_Priority_Specific_Dispatching  => -1,
18499       Pragma_Profile                        =>  0,
18500       Pragma_Profile_Warnings               =>  0,
18501       Pragma_Propagate_Exceptions           => -1,
18502       Pragma_Psect_Object                   => -1,
18503       Pragma_Pure                           => -1,
18504       Pragma_Pure_05                        => -1,
18505       Pragma_Pure_12                        => -1,
18506       Pragma_Pure_Function                  => -1,
18507       Pragma_Queuing_Policy                 => -1,
18508       Pragma_Rational                       => -1,
18509       Pragma_Ravenscar                      => -1,
18510       Pragma_Relative_Deadline              => -1,
18511       Pragma_Remote_Access_Type             => -1,
18512       Pragma_Remote_Call_Interface          => -1,
18513       Pragma_Remote_Types                   => -1,
18514       Pragma_Restricted_Run_Time            => -1,
18515       Pragma_Restriction_Warnings           => -1,
18516       Pragma_Restrictions                   => -1,
18517       Pragma_Reviewable                     => -1,
18518       Pragma_Short_Circuit_And_Or           => -1,
18519       Pragma_Share_Generic                  => -1,
18520       Pragma_Shared                         => -1,
18521       Pragma_Shared_Passive                 => -1,
18522       Pragma_Short_Descriptors              =>  0,
18523       Pragma_Simple_Storage_Pool_Type       =>  0,
18524       Pragma_Source_File_Name               => -1,
18525       Pragma_Source_File_Name_Project       => -1,
18526       Pragma_Source_Reference               => -1,
18527       Pragma_Storage_Size                   => -1,
18528       Pragma_Storage_Unit                   => -1,
18529       Pragma_Static_Elaboration_Desired     => -1,
18530       Pragma_Stream_Convert                 => -1,
18531       Pragma_Style_Checks                   => -1,
18532       Pragma_Subtitle                       => -1,
18533       Pragma_Suppress                       =>  0,
18534       Pragma_Suppress_Exception_Locations   =>  0,
18535       Pragma_Suppress_All                   => -1,
18536       Pragma_Suppress_Debug_Info            =>  0,
18537       Pragma_Suppress_Initialization        =>  0,
18538       Pragma_System_Name                    => -1,
18539       Pragma_Task_Dispatching_Policy        => -1,
18540       Pragma_Task_Info                      => -1,
18541       Pragma_Task_Name                      => -1,
18542       Pragma_Task_Storage                   =>  0,
18543       Pragma_Test_Case                      => -1,
18544       Pragma_Thread_Local_Storage           =>  0,
18545       Pragma_Time_Slice                     => -1,
18546       Pragma_Title                          => -1,
18547       Pragma_Unchecked_Union                =>  0,
18548       Pragma_Unimplemented_Unit             => -1,
18549       Pragma_Universal_Aliasing             => -1,
18550       Pragma_Universal_Data                 => -1,
18551       Pragma_Unmodified                     => -1,
18552       Pragma_Unreferenced                   => -1,
18553       Pragma_Unreferenced_Objects           => -1,
18554       Pragma_Unreserve_All_Interrupts       => -1,
18555       Pragma_Unsuppress                     =>  0,
18556       Pragma_Use_VADS_Size                  => -1,
18557       Pragma_Validity_Checks                => -1,
18558       Pragma_Volatile                       =>  0,
18559       Pragma_Volatile_Components            =>  0,
18560       Pragma_Warnings                       => -1,
18561       Pragma_Weak_External                  => -1,
18562       Pragma_Wide_Character_Encoding        =>  0,
18563       Unknown_Pragma                        =>  0);
18564
18565    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
18566       Id : Pragma_Id;
18567       P  : Node_Id;
18568       C  : Int;
18569       A  : Node_Id;
18570
18571    begin
18572       P := Parent (N);
18573
18574       if Nkind (P) /= N_Pragma_Argument_Association then
18575          return False;
18576
18577       else
18578          Id := Get_Pragma_Id (Parent (P));
18579          C := Sig_Flags (Id);
18580
18581          case C is
18582             when -1 =>
18583                return False;
18584
18585             when 0 =>
18586                return True;
18587
18588             when 99 =>
18589                case Id is
18590
18591                   --  For pragma Check, the first argument is not significant,
18592                   --  the second and the third (if present) arguments are
18593                   --  significant.
18594
18595                   when Pragma_Check =>
18596                      return
18597                        P = First (Pragma_Argument_Associations (Parent (P)));
18598
18599                   when others =>
18600                      raise Program_Error;
18601                end case;
18602
18603             when others =>
18604                A := First (Pragma_Argument_Associations (Parent (P)));
18605                for J in 1 .. C - 1 loop
18606                   if No (A) then
18607                      return False;
18608                   end if;
18609
18610                   Next (A);
18611                end loop;
18612
18613                return A = P; -- is this wrong way round ???
18614          end case;
18615       end if;
18616    end Is_Non_Significant_Pragma_Reference;
18617
18618    ------------------------------
18619    -- Is_Pragma_String_Literal --
18620    ------------------------------
18621
18622    --  This function returns true if the corresponding pragma argument is a
18623    --  static string expression. These are the only cases in which string
18624    --  literals can appear as pragma arguments. We also allow a string literal
18625    --  as the first argument to pragma Assert (although it will of course
18626    --  always generate a type error).
18627
18628    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
18629       Pragn : constant Node_Id := Parent (Par);
18630       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
18631       Pname : constant Name_Id := Pragma_Name (Pragn);
18632       Argn  : Natural;
18633       N     : Node_Id;
18634
18635    begin
18636       Argn := 1;
18637       N := First (Assoc);
18638       loop
18639          exit when N = Par;
18640          Argn := Argn + 1;
18641          Next (N);
18642       end loop;
18643
18644       if Pname = Name_Assert then
18645          return True;
18646
18647       elsif Pname = Name_Export then
18648          return Argn > 2;
18649
18650       elsif Pname = Name_Ident then
18651          return Argn = 1;
18652
18653       elsif Pname = Name_Import then
18654          return Argn > 2;
18655
18656       elsif Pname = Name_Interface_Name then
18657          return Argn > 1;
18658
18659       elsif Pname = Name_Linker_Alias then
18660          return Argn = 2;
18661
18662       elsif Pname = Name_Linker_Section then
18663          return Argn = 2;
18664
18665       elsif Pname = Name_Machine_Attribute then
18666          return Argn = 2;
18667
18668       elsif Pname = Name_Source_File_Name then
18669          return True;
18670
18671       elsif Pname = Name_Source_Reference then
18672          return Argn = 2;
18673
18674       elsif Pname = Name_Title then
18675          return True;
18676
18677       elsif Pname = Name_Subtitle then
18678          return True;
18679
18680       else
18681          return False;
18682       end if;
18683    end Is_Pragma_String_Literal;
18684
18685    -----------------------------
18686    -- Is_Valid_Assertion_Kind --
18687    -----------------------------
18688
18689    function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is
18690    begin
18691       case Nam is
18692          when
18693             --  RM defined
18694
18695             Name_Assert               |
18696             Name_Static_Predicate     |
18697             Name_Dynamic_Predicate    |
18698             Name_Pre                  |
18699             Name_uPre                 |
18700             Name_Post                 |
18701             Name_uPost                |
18702             Name_Type_Invariant       |
18703             Name_uType_Invariant      |
18704
18705             --  Impl defined
18706
18707             Name_Assert_And_Cut       |
18708             Name_Assume               |
18709             Name_Contract_Cases       |
18710             Name_Debug                |
18711             Name_Invariant            |
18712             Name_uInvariant           |
18713             Name_Loop_Invariant       |
18714             Name_Loop_Variant         |
18715             Name_Postcondition        |
18716             Name_Precondition         |
18717             Name_Predicate            |
18718             Name_Statement_Assertions => return True;
18719
18720          when others                  => return False;
18721       end case;
18722    end Is_Valid_Assertion_Kind;
18723
18724    -----------------------------------------
18725    -- Make_Aspect_For_PPC_In_Gen_Sub_Decl --
18726    -----------------------------------------
18727
18728    procedure Make_Aspect_For_PPC_In_Gen_Sub_Decl (Decl : Node_Id) is
18729       Aspects : constant List_Id := New_List;
18730       Loc     : constant Source_Ptr := Sloc (Decl);
18731       Or_Decl : constant Node_Id := Original_Node (Decl);
18732
18733       Original_Aspects : List_Id;
18734       --  To capture global references, a copy of the created aspects must be
18735       --  inserted in the original tree.
18736
18737       Prag         : Node_Id;
18738       Prag_Arg_Ass : Node_Id;
18739       Prag_Id      : Pragma_Id;
18740
18741    begin
18742       --  Check for any PPC pragmas that appear within Decl
18743
18744       Prag := Next (Decl);
18745       while Nkind (Prag) = N_Pragma loop
18746          Prag_Id := Get_Pragma_Id (Chars (Pragma_Identifier (Prag)));
18747
18748          case Prag_Id is
18749             when Pragma_Postcondition | Pragma_Precondition =>
18750                Prag_Arg_Ass := First (Pragma_Argument_Associations (Prag));
18751
18752                --  Make an aspect from any PPC pragma
18753
18754                Append_To (Aspects,
18755                  Make_Aspect_Specification (Loc,
18756                    Identifier =>
18757                      Make_Identifier (Loc, Chars (Pragma_Identifier (Prag))),
18758                    Expression =>
18759                      Copy_Separate_Tree (Expression (Prag_Arg_Ass))));
18760
18761                --  Generate the analysis information in the pragma expression
18762                --  and then set the pragma node analyzed to avoid any further
18763                --  analysis.
18764
18765                Analyze (Expression (Prag_Arg_Ass));
18766                Set_Analyzed (Prag, True);
18767
18768             when others => null;
18769          end case;
18770
18771          Next (Prag);
18772       end loop;
18773
18774       --  Set all new aspects into the generic declaration node
18775
18776       if Is_Non_Empty_List (Aspects) then
18777
18778          --  Create the list of aspects to be inserted in the original tree
18779
18780          Original_Aspects := Copy_Separate_List (Aspects);
18781
18782          --  Check if Decl already has aspects
18783
18784          --  Attach the new lists of aspects to both the generic copy and the
18785          --  original tree.
18786
18787          if Has_Aspects (Decl) then
18788             Append_List (Aspects, Aspect_Specifications (Decl));
18789             Append_List (Original_Aspects, Aspect_Specifications (Or_Decl));
18790
18791          else
18792             Set_Parent (Aspects, Decl);
18793             Set_Aspect_Specifications (Decl, Aspects);
18794             Set_Parent (Original_Aspects, Or_Decl);
18795             Set_Aspect_Specifications (Or_Decl, Original_Aspects);
18796          end if;
18797       end if;
18798    end Make_Aspect_For_PPC_In_Gen_Sub_Decl;
18799
18800    -------------------
18801    -- Original_Name --
18802    -------------------
18803
18804    function Original_Name (N : Node_Id) return Name_Id is
18805       Pras : Node_Id;
18806       Name : Name_Id;
18807
18808    begin
18809       pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
18810       Pras := N;
18811
18812       if Is_Rewrite_Substitution (Pras)
18813         and then Nkind (Original_Node (Pras)) = N_Pragma
18814       then
18815          Pras := Original_Node (Pras);
18816       end if;
18817
18818       --  Case where we came from aspect specication
18819
18820       if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
18821          Pras := Corresponding_Aspect (Pras);
18822       end if;
18823
18824       --  Get name from aspect or pragma
18825
18826       if Nkind (Pras) = N_Pragma then
18827          Name := Pragma_Name (Pras);
18828       else
18829          Name := Chars (Identifier (Pras));
18830       end if;
18831
18832       --  Deal with 'Class
18833
18834       if Class_Present (Pras) then
18835          case Name is
18836
18837          --  Names that need converting to special _xxx form
18838
18839             when Name_Pre             => Name := Name_uPre;
18840             when Name_Post            => Name := Name_uPost;
18841             when Name_Invariant       => Name := Name_uInvariant;
18842             when Name_Type_Invariant  => Name := Name_uType_Invariant;
18843
18844                --  Names already in special _xxx form (leave them alone)
18845
18846             when Name_uPre            => null;
18847             when Name_uPost           => null;
18848             when Name_uInvariant      => null;
18849             when Name_uType_Invariant => null;
18850
18851                --  Anything else is impossible with Class_Present set True
18852
18853             when others               => raise Program_Error;
18854          end case;
18855       end if;
18856
18857       return Name;
18858    end Original_Name;
18859
18860    -------------------------
18861    -- Preanalyze_CTC_Args --
18862    -------------------------
18863
18864    procedure Preanalyze_CTC_Args (N, Arg_Req, Arg_Ens : Node_Id) is
18865    begin
18866       --  Preanalyze the boolean expressions, we treat these as spec
18867       --  expressions (i.e. similar to a default expression).
18868
18869       if Present (Arg_Req) then
18870          Preanalyze_Assert_Expression
18871            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
18872
18873          --  In ASIS mode, for a pragma generated from a source aspect, also
18874          --  analyze the original aspect expression.
18875
18876          if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18877             Preanalyze_Assert_Expression
18878               (Original_Node (Get_Pragma_Arg (Arg_Req)), Standard_Boolean);
18879          end if;
18880       end if;
18881
18882       if Present (Arg_Ens) then
18883          Preanalyze_Assert_Expression
18884            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
18885
18886          --  In ASIS mode, for a pragma generated from a source aspect, also
18887          --  analyze the original aspect expression.
18888
18889          if ASIS_Mode and then Present (Corresponding_Aspect (N)) then
18890             Preanalyze_Assert_Expression
18891               (Original_Node (Get_Pragma_Arg (Arg_Ens)), Standard_Boolean);
18892          end if;
18893       end if;
18894    end Preanalyze_CTC_Args;
18895
18896    --------------------------------------
18897    -- Process_Compilation_Unit_Pragmas --
18898    --------------------------------------
18899
18900    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
18901    begin
18902       --  A special check for pragma Suppress_All, a very strange DEC pragma,
18903       --  strange because it comes at the end of the unit. Rational has the
18904       --  same name for a pragma, but treats it as a program unit pragma, In
18905       --  GNAT we just decide to allow it anywhere at all. If it appeared then
18906       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
18907       --  node, and we insert a pragma Suppress (All_Checks) at the start of
18908       --  the context clause to ensure the correct processing.
18909
18910       if Has_Pragma_Suppress_All (N) then
18911          Prepend_To (Context_Items (N),
18912            Make_Pragma (Sloc (N),
18913              Chars                        => Name_Suppress,
18914              Pragma_Argument_Associations => New_List (
18915                Make_Pragma_Argument_Association (Sloc (N),
18916                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
18917       end if;
18918
18919       --  Nothing else to do at the current time!
18920
18921    end Process_Compilation_Unit_Pragmas;
18922
18923    ----------------------------
18924    -- Rewrite_Assertion_Kind --
18925    ----------------------------
18926
18927    procedure Rewrite_Assertion_Kind (N : Node_Id) is
18928       Nam : Name_Id;
18929
18930    begin
18931       if Nkind (N) = N_Attribute_Reference
18932         and then Attribute_Name (N) = Name_Class
18933         and then Nkind (Prefix (N)) = N_Identifier
18934       then
18935          case Chars (Prefix (N)) is
18936             when Name_Pre =>
18937                Nam := Name_uPre;
18938             when Name_Post =>
18939                Nam := Name_uPost;
18940             when Name_Type_Invariant =>
18941                Nam := Name_uType_Invariant;
18942             when Name_Invariant =>
18943                Nam := Name_uInvariant;
18944             when others =>
18945                return;
18946          end case;
18947
18948          Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam));
18949       end if;
18950    end Rewrite_Assertion_Kind;
18951
18952    --------
18953    -- rv --
18954    --------
18955
18956    procedure rv is
18957    begin
18958       null;
18959    end rv;
18960
18961    -----------------------------------
18962    -- Requires_Profile_Installation --
18963    -----------------------------------
18964
18965    function Requires_Profile_Installation
18966      (Prag : Node_Id;
18967       Subp : Node_Id) return Boolean
18968    is
18969    begin
18970       --  When aspects Depends and Global are associated with a subprogram
18971       --  declaration, their corresponding pragmas are analyzed at the end of
18972       --  the declarative part. This is done out of context, therefore the
18973       --  formals must be installed in visibility.
18974
18975       if Nkind (Subp) = N_Subprogram_Declaration then
18976          return True;
18977
18978       --  When aspects Depends and Global are associated with a subprogram body
18979       --  which is also a compilation unit, their corresponding pragmas appear
18980       --  in the Pragmas_After list. The Pragmas_After collection is analyzed
18981       --  out of context and the formals must be installed in visibility. This
18982       --  does not apply when the pragma is a source construct.
18983
18984       elsif Nkind (Subp) = N_Subprogram_Body then
18985          if Nkind (Parent (Subp)) = N_Compilation_Unit then
18986             return Present (Corresponding_Aspect (Prag));
18987          else
18988             return False;
18989          end if;
18990
18991       --  In all other cases the two corresponding pragmas are analyzed in
18992       --  context and the formals are already visibile.
18993
18994       else
18995          return False;
18996       end if;
18997    end Requires_Profile_Installation;
18998
18999    --------------------------------
19000    -- Set_Encoded_Interface_Name --
19001    --------------------------------
19002
19003    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
19004       Str : constant String_Id := Strval (S);
19005       Len : constant Int       := String_Length (Str);
19006       CC  : Char_Code;
19007       C   : Character;
19008       J   : Int;
19009
19010       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
19011
19012       procedure Encode;
19013       --  Stores encoded value of character code CC. The encoding we use an
19014       --  underscore followed by four lower case hex digits.
19015
19016       ------------
19017       -- Encode --
19018       ------------
19019
19020       procedure Encode is
19021       begin
19022          Store_String_Char (Get_Char_Code ('_'));
19023          Store_String_Char
19024            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
19025          Store_String_Char
19026            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
19027          Store_String_Char
19028            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
19029          Store_String_Char
19030            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
19031       end Encode;
19032
19033    --  Start of processing for Set_Encoded_Interface_Name
19034
19035    begin
19036       --  If first character is asterisk, this is a link name, and we leave it
19037       --  completely unmodified. We also ignore null strings (the latter case
19038       --  happens only in error cases) and no encoding should occur for Java or
19039       --  AAMP interface names.
19040
19041       if Len = 0
19042         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
19043         or else VM_Target /= No_VM
19044         or else AAMP_On_Target
19045       then
19046          Set_Interface_Name (E, S);
19047
19048       else
19049          J := 1;
19050          loop
19051             CC := Get_String_Char (Str, J);
19052
19053             exit when not In_Character_Range (CC);
19054
19055             C := Get_Character (CC);
19056
19057             exit when C /= '_' and then C /= '$'
19058               and then C not in '0' .. '9'
19059               and then C not in 'a' .. 'z'
19060               and then C not in 'A' .. 'Z';
19061
19062             if J = Len then
19063                Set_Interface_Name (E, S);
19064                return;
19065
19066             else
19067                J := J + 1;
19068             end if;
19069          end loop;
19070
19071          --  Here we need to encode. The encoding we use as follows:
19072          --     three underscores  + four hex digits (lower case)
19073
19074          Start_String;
19075
19076          for J in 1 .. String_Length (Str) loop
19077             CC := Get_String_Char (Str, J);
19078
19079             if not In_Character_Range (CC) then
19080                Encode;
19081             else
19082                C := Get_Character (CC);
19083
19084                if C = '_' or else C = '$'
19085                  or else C in '0' .. '9'
19086                  or else C in 'a' .. 'z'
19087                  or else C in 'A' .. 'Z'
19088                then
19089                   Store_String_Char (CC);
19090                else
19091                   Encode;
19092                end if;
19093             end if;
19094          end loop;
19095
19096          Set_Interface_Name (E,
19097            Make_String_Literal (Sloc (S),
19098              Strval => End_String));
19099       end if;
19100    end Set_Encoded_Interface_Name;
19101
19102    -------------------
19103    -- Set_Unit_Name --
19104    -------------------
19105
19106    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
19107       Pref : Node_Id;
19108       Scop : Entity_Id;
19109
19110    begin
19111       if Nkind (N) = N_Identifier
19112         and then Nkind (With_Item) = N_Identifier
19113       then
19114          Set_Entity (N, Entity (With_Item));
19115
19116       elsif Nkind (N) = N_Selected_Component then
19117          Change_Selected_Component_To_Expanded_Name (N);
19118          Set_Entity (N, Entity (With_Item));
19119          Set_Entity (Selector_Name (N), Entity (N));
19120
19121          Pref := Prefix (N);
19122          Scop := Scope (Entity (N));
19123          while Nkind (Pref) = N_Selected_Component loop
19124             Change_Selected_Component_To_Expanded_Name (Pref);
19125             Set_Entity (Selector_Name (Pref), Scop);
19126             Set_Entity (Pref, Scop);
19127             Pref := Prefix (Pref);
19128             Scop := Scope (Scop);
19129          end loop;
19130
19131          Set_Entity (Pref, Scop);
19132       end if;
19133    end Set_Unit_Name;
19134
19135 end Sem_Prag;