OSDN Git Service

2011-08-04 Yannick Moy <moy@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ P R A G                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with Atree;    use Atree;
33 with Casing;   use Casing;
34 with Checks;   use Checks;
35 with Csets;    use Csets;
36 with Debug;    use Debug;
37 with Einfo;    use Einfo;
38 with Elists;   use Elists;
39 with Errout;   use Errout;
40 with Exp_Dist; use Exp_Dist;
41 with Exp_Util; use Exp_Util;
42 with Lib;      use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists;   use Nlists;
47 with Nmake;    use Nmake;
48 with Opt;      use Opt;
49 with Output;   use Output;
50 with Par_SCO;  use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident;   use Rident;
53 with Rtsfind;  use Rtsfind;
54 with Sem;      use Sem;
55 with Sem_Aux;  use Sem_Aux;
56 with Sem_Ch3;  use Sem_Ch3;
57 with Sem_Ch6;  use Sem_Ch6;
58 with Sem_Ch8;  use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res;  use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand;    use Stand;
73 with Sinfo;    use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput;   use Sinput;
76 with Snames;   use Snames;
77 with Stringt;  use Stringt;
78 with Stylesw;  use Stylesw;
79 with Table;
80 with Targparm; use Targparm;
81 with Tbuild;   use Tbuild;
82 with Ttypes;
83 with Uintp;    use Uintp;
84 with Uname;    use Uname;
85 with Urealp;   use Urealp;
86 with Validsw;  use Validsw;
87 with Warnsw;   use Warnsw;
88
89 package body Sem_Prag is
90
91    ----------------------------------------------
92    -- Common Handling of Import-Export Pragmas --
93    ----------------------------------------------
94
95    --  In the following section, a number of Import_xxx and Export_xxx pragmas
96    --  are defined by GNAT. These are compatible with the DEC pragmas of the
97    --  same name, and all have the following common form and processing:
98
99    --  pragma Export_xxx
100    --        [Internal                 =>] LOCAL_NAME
101    --     [, [External                 =>] EXTERNAL_SYMBOL]
102    --     [, other optional parameters   ]);
103
104    --  pragma Import_xxx
105    --        [Internal                 =>] LOCAL_NAME
106    --     [, [External                 =>] EXTERNAL_SYMBOL]
107    --     [, other optional parameters   ]);
108
109    --   EXTERNAL_SYMBOL ::=
110    --     IDENTIFIER
111    --   | static_string_EXPRESSION
112
113    --  The internal LOCAL_NAME designates the entity that is imported or
114    --  exported, and must refer to an entity in the current declarative
115    --  part (as required by the rules for LOCAL_NAME).
116
117    --  The external linker name is designated by the External parameter if
118    --  given, or the Internal parameter if not (if there is no External
119    --  parameter, the External parameter is a copy of the Internal name).
120
121    --  If the External parameter is given as a string, then this string is
122    --  treated as an external name (exactly as though it had been given as an
123    --  External_Name parameter for a normal Import pragma).
124
125    --  If the External parameter is given as an identifier (or there is no
126    --  External parameter, so that the Internal identifier is used), then
127    --  the external name is the characters of the identifier, translated
128    --  to all upper case letters for OpenVMS versions of GNAT, and to all
129    --  lower case letters for all other versions
130
131    --  Note: the external name specified or implied by any of these special
132    --  Import_xxx or Export_xxx pragmas override an external or link name
133    --  specified in a previous Import or Export pragma.
134
135    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
136    --  named notation, following the standard rules for subprogram calls, i.e.
137    --  parameters can be given in any order if named notation is used, and
138    --  positional and named notation can be mixed, subject to the rule that all
139    --  positional parameters must appear first.
140
141    --  Note: All these pragmas are implemented exactly following the DEC design
142    --  and implementation and are intended to be fully compatible with the use
143    --  of these pragmas in the DEC Ada compiler.
144
145    --------------------------------------------
146    -- Checking for Duplicated External Names --
147    --------------------------------------------
148
149    --  It is suspicious if two separate Export pragmas use the same external
150    --  name. The following table is used to diagnose this situation so that
151    --  an appropriate warning can be issued.
152
153    --  The Node_Id stored is for the N_String_Literal node created to hold
154    --  the value of the external name. The Sloc of this node is used to
155    --  cross-reference the location of the duplication.
156
157    package Externals is new Table.Table (
158      Table_Component_Type => Node_Id,
159      Table_Index_Type     => Int,
160      Table_Low_Bound      => 0,
161      Table_Initial        => 100,
162      Table_Increment      => 100,
163      Table_Name           => "Name_Externals");
164
165    -------------------------------------
166    -- Local Subprograms and Variables --
167    -------------------------------------
168
169    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170    --  This routine is used for possible casing adjustment of an explicit
171    --  external name supplied as a string literal (the node N), according to
172    --  the casing requirement of Opt.External_Name_Casing. If this is set to
173    --  As_Is, then the string literal is returned unchanged, but if it is set
174    --  to Uppercase or Lowercase, then a new string literal with appropriate
175    --  casing is constructed.
176
177    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
179    --  original one, following the renaming chain) is returned. Otherwise the
180    --  entity is returned unchanged. Should be in Einfo???
181
182    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id);
183    --  Preanalyze the boolean expressions in the Requires and Ensures arguments
184    --  of a Test_Case pragma if present (possibly Empty). We treat these as
185    --  spec expressions (i.e. similar to a default expression).
186
187    procedure rv;
188    --  This is a dummy function called by the processing for pragma Reviewable.
189    --  It is there for assisting front end debugging. By placing a Reviewable
190    --  pragma in the source program, a breakpoint on rv catches this place in
191    --  the source, allowing convenient stepping to the point of interest.
192
193    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
194    --  Place semantic information on the argument of an Elaborate/Elaborate_All
195    --  pragma. Entity name for unit and its parents is taken from item in
196    --  previous with_clause that mentions the unit.
197
198    -------------------------------
199    -- Adjust_External_Name_Case --
200    -------------------------------
201
202    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
203       CC : Char_Code;
204
205    begin
206       --  Adjust case of literal if required
207
208       if Opt.External_Name_Exp_Casing = As_Is then
209          return N;
210
211       else
212          --  Copy existing string
213
214          Start_String;
215
216          --  Set proper casing
217
218          for J in 1 .. String_Length (Strval (N)) loop
219             CC := Get_String_Char (Strval (N), J);
220
221             if Opt.External_Name_Exp_Casing = Uppercase
222               and then CC >= Get_Char_Code ('a')
223               and then CC <= Get_Char_Code ('z')
224             then
225                Store_String_Char (CC - 32);
226
227             elsif Opt.External_Name_Exp_Casing = Lowercase
228               and then CC >= Get_Char_Code ('A')
229               and then CC <= Get_Char_Code ('Z')
230             then
231                Store_String_Char (CC + 32);
232
233             else
234                Store_String_Char (CC);
235             end if;
236          end loop;
237
238          return
239            Make_String_Literal (Sloc (N),
240              Strval => End_String);
241       end if;
242    end Adjust_External_Name_Case;
243
244    ------------------------------
245    -- Analyze_PPC_In_Decl_Part --
246    ------------------------------
247
248    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
249       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
250
251    begin
252       --  Install formals and push subprogram spec onto scope stack so that we
253       --  can see the formals from the pragma.
254
255       Install_Formals (S);
256       Push_Scope (S);
257
258       --  Preanalyze the boolean expression, we treat this as a spec expression
259       --  (i.e. similar to a default expression).
260
261       pragma Assert (In_Pre_Post_Expression = False);
262       In_Pre_Post_Expression := True;
263       Preanalyze_Spec_Expression
264         (Get_Pragma_Arg (Arg1), Standard_Boolean);
265       In_Pre_Post_Expression := False;
266
267       --  Remove the subprogram from the scope stack now that the pre-analysis
268       --  of the precondition/postcondition is done.
269
270       End_Scope;
271    end Analyze_PPC_In_Decl_Part;
272
273    --------------------
274    -- Analyze_Pragma --
275    --------------------
276
277    procedure Analyze_Pragma (N : Node_Id) is
278       Loc     : constant Source_Ptr := Sloc (N);
279       Pname   : constant Name_Id    := Pragma_Name (N);
280       Prag_Id : Pragma_Id;
281
282       Pragma_Exit : exception;
283       --  This exception is used to exit pragma processing completely. It is
284       --  used when an error is detected, and no further processing is
285       --  required. It is also used if an earlier error has left the tree in
286       --  a state where the pragma should not be processed.
287
288       Arg_Count : Nat;
289       --  Number of pragma argument associations
290
291       Arg1 : Node_Id;
292       Arg2 : Node_Id;
293       Arg3 : Node_Id;
294       Arg4 : Node_Id;
295       --  First four pragma arguments (pragma argument association nodes, or
296       --  Empty if the corresponding argument does not exist).
297
298       type Name_List is array (Natural range <>) of Name_Id;
299       type Args_List is array (Natural range <>) of Node_Id;
300       --  Types used for arguments to Check_Arg_Order and Gather_Associations
301
302       procedure Ada_2005_Pragma;
303       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
304       --  Ada 95 mode, these are implementation defined pragmas, so should be
305       --  caught by the No_Implementation_Pragmas restriction.
306
307       procedure Ada_2012_Pragma;
308       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
309       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
310       --  should be caught by the No_Implementation_Pragmas restriction.
311
312       procedure Check_Ada_83_Warning;
313       --  Issues a warning message for the current pragma if operating in Ada
314       --  83 mode (used for language pragmas that are not a standard part of
315       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
316       --  of 95 pragma.
317
318       procedure Check_Arg_Count (Required : Nat);
319       --  Check argument count for pragma is equal to given parameter. If not,
320       --  then issue an error message and raise Pragma_Exit.
321
322       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
323       --  Arg which can either be a pragma argument association, in which case
324       --  the check is applied to the expression of the association or an
325       --  expression directly.
326
327       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
328       --  Check that an argument has the right form for an EXTERNAL_NAME
329       --  parameter of an extended import/export pragma. The rule is that the
330       --  name must be an identifier or string literal (in Ada 83 mode) or a
331       --  static string expression (in Ada 95 mode).
332
333       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
334       --  Check the specified argument Arg to make sure that it is an
335       --  identifier. If not give error and raise Pragma_Exit.
336
337       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
338       --  Check the specified argument Arg to make sure that it is an integer
339       --  literal. If not give error and raise Pragma_Exit.
340
341       procedure Check_Arg_Is_String_Literal (Arg : Node_Id);
342       --  Check the specified argument Arg to make sure that it is a string
343       --  literal. If not give error and raise Pragma_Exit.
344
345       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
346       --  Check the specified argument Arg to make sure that it has the proper
347       --  syntactic form for a local name and meets the semantic requirements
348       --  for a local name. The local name is analyzed as part of the
349       --  processing for this call. In addition, the local name is required
350       --  to represent an entity at the library level.
351
352       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
353       --  Check the specified argument Arg to make sure that it has the proper
354       --  syntactic form for a local name and meets the semantic requirements
355       --  for a local name. The local name is analyzed as part of the
356       --  processing for this call.
357
358       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
359       --  Check the specified argument Arg to make sure that it is a valid
360       --  locking policy name. If not give error and raise Pragma_Exit.
361
362       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
363       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
364       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
365       --  Check the specified argument Arg to make sure that it is an
366       --  identifier whose name matches either N1 or N2 (or N3 if present).
367       --  If not then give error and raise Pragma_Exit.
368
369       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
370       --  Check the specified argument Arg to make sure that it is a valid
371       --  queuing policy name. If not give error and raise Pragma_Exit.
372
373       procedure Check_Arg_Is_Static_Expression
374         (Arg : Node_Id;
375          Typ : Entity_Id := Empty);
376       --  Check the specified argument Arg to make sure that it is a static
377       --  expression of the given type (i.e. it will be analyzed and resolved
378       --  using this type, which can be any valid argument to Resolve, e.g.
379       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
380       --  Typ is left Empty, then any static expression is allowed.
381
382       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
383       --  Check the specified argument Arg to make sure that it is a valid task
384       --  dispatching policy name. If not give error and raise Pragma_Exit.
385
386       procedure Check_Arg_Order (Names : Name_List);
387       --  Checks for an instance of two arguments with identifiers for the
388       --  current pragma which are not in the sequence indicated by Names,
389       --  and if so, generates a fatal message about bad order of arguments.
390
391       procedure Check_At_Least_N_Arguments (N : Nat);
392       --  Check there are at least N arguments present
393
394       procedure Check_At_Most_N_Arguments (N : Nat);
395       --  Check there are no more than N arguments present
396
397       procedure Check_Component
398         (Comp            : Node_Id;
399          UU_Typ          : Entity_Id;
400          In_Variant_Part : Boolean := False);
401       --  Examine an Unchecked_Union component for correct use of per-object
402       --  constrained subtypes, and for restrictions on finalizable components.
403       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
404       --  should be set when Comp comes from a record variant.
405
406       procedure Check_Duplicate_Pragma (E : Entity_Id);
407       --  Check if a pragma of the same name as the current pragma is already
408       --  chained as a rep pragma to the given entity. If so give a message
409       --  about the duplicate, and then raise Pragma_Exit so does not return.
410       --  Also checks for delayed aspect specification node in the chain.
411
412       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
413       --  Nam is an N_String_Literal node containing the external name set by
414       --  an Import or Export pragma (or extended Import or Export pragma).
415       --  This procedure checks for possible duplications if this is the export
416       --  case, and if found, issues an appropriate error message.
417
418       procedure Check_First_Subtype (Arg : Node_Id);
419       --  Checks that Arg, whose expression is an entity name, references a
420       --  first subtype.
421
422       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
423       --  Checks that the given argument has an identifier, and if so, requires
424       --  it to match the given identifier name. If there is no identifier, or
425       --  a non-matching identifier, then an error message is given and
426       --  Error_Pragmas raised.
427
428       procedure Check_In_Main_Program;
429       --  Common checks for pragmas that appear within a main program
430       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
431
432       procedure Check_Interrupt_Or_Attach_Handler;
433       --  Common processing for first argument of pragma Interrupt_Handler or
434       --  pragma Attach_Handler.
435
436       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
437       --  Check that pragma appears in a declarative part, or in a package
438       --  specification, i.e. that it does not occur in a statement sequence
439       --  in a body.
440
441       procedure Check_No_Identifier (Arg : Node_Id);
442       --  Checks that the given argument does not have an identifier. If
443       --  an identifier is present, then an error message is issued, and
444       --  Pragma_Exit is raised.
445
446       procedure Check_No_Identifiers;
447       --  Checks that none of the arguments to the pragma has an identifier.
448       --  If any argument has an identifier, then an error message is issued,
449       --  and Pragma_Exit is raised.
450
451       procedure Check_No_Link_Name;
452       --  Checks that no link name is specified
453
454       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
455       --  Checks if the given argument has an identifier, and if so, requires
456       --  it to match the given identifier name. If there is a non-matching
457       --  identifier, then an error message is given and Error_Pragmas raised.
458
459       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
460       --  Checks if the given argument has an identifier, and if so, requires
461       --  it to match the given identifier name. If there is a non-matching
462       --  identifier, then an error message is given and Error_Pragmas raised.
463       --  In this version of the procedure, the identifier name is given as
464       --  a string with lower case letters.
465
466       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
467       --  Called to process a precondition or postcondition pragma. There are
468       --  three cases:
469       --
470       --    The pragma appears after a subprogram spec
471       --
472       --      If the corresponding check is not enabled, the pragma is analyzed
473       --      but otherwise ignored and control returns with In_Body set False.
474       --
475       --      If the check is enabled, then the first step is to analyze the
476       --      pragma, but this is skipped if the subprogram spec appears within
477       --      a package specification (because this is the case where we delay
478       --      analysis till the end of the spec). Then (whether or not it was
479       --      analyzed), the pragma is chained to the subprogram in question
480       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
481       --      caller with In_Body set False.
482       --
483       --    The pragma appears at the start of subprogram body declarations
484       --
485       --      In this case an immediate return to the caller is made with
486       --      In_Body set True, and the pragma is NOT analyzed.
487       --
488       --    In all other cases, an error message for bad placement is given
489
490       procedure Check_Static_Constraint (Constr : Node_Id);
491       --  Constr is a constraint from an N_Subtype_Indication node from a
492       --  component constraint in an Unchecked_Union type. This routine checks
493       --  that the constraint is static as required by the restrictions for
494       --  Unchecked_Union.
495
496       procedure Check_Test_Case;
497       --  Called to process a test-case pragma. The treatment is similar to the
498       --  one for pre- and postcondition in Check_Precondition_Postcondition.
499       --  There are three cases:
500       --
501       --    The pragma appears after a subprogram spec
502       --
503       --      The first step is to analyze the pragma, but this is skipped if
504       --      the subprogram spec appears within a package specification
505       --      (because this is the case where we delay analysis till the end of
506       --      the spec). Then (whether or not it was analyzed), the pragma is
507       --      chained to the subprogram in question (using Spec_TC_List and
508       --      Next_Pragma).
509       --
510       --    The pragma appears at the start of subprogram body declarations
511       --
512       --      In this case an immediate return to the caller is made, and the
513       --      pragma is NOT analyzed.
514       --
515       --    In all other cases, an error message for bad placement is given
516
517       procedure Check_Valid_Configuration_Pragma;
518       --  Legality checks for placement of a configuration pragma
519
520       procedure Check_Valid_Library_Unit_Pragma;
521       --  Legality checks for library unit pragmas. A special case arises for
522       --  pragmas in generic instances that come from copies of the original
523       --  library unit pragmas in the generic templates. In the case of other
524       --  than library level instantiations these can appear in contexts which
525       --  would normally be invalid (they only apply to the original template
526       --  and to library level instantiations), and they are simply ignored,
527       --  which is implemented by rewriting them as null statements.
528
529       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
530       --  Check an Unchecked_Union variant for lack of nested variants and
531       --  presence of at least one component. UU_Typ is the related Unchecked_
532       --  Union type.
533
534       procedure Error_Pragma (Msg : String);
535       pragma No_Return (Error_Pragma);
536       --  Outputs error message for current pragma. The message contains a %
537       --  that will be replaced with the pragma name, and the flag is placed
538       --  on the pragma itself. Pragma_Exit is then raised.
539
540       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
541       pragma No_Return (Error_Pragma_Arg);
542       --  Outputs error message for current pragma. The message may contain
543       --  a % that will be replaced with the pragma name. The parameter Arg
544       --  may either be a pragma argument association, in which case the flag
545       --  is placed on the expression of this association, or an expression,
546       --  in which case the flag is placed directly on the expression. The
547       --  message is placed using Error_Msg_N, so the message may also contain
548       --  an & insertion character which will reference the given Arg value.
549       --  After placing the message, Pragma_Exit is raised.
550
551       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
552       pragma No_Return (Error_Pragma_Arg);
553       --  Similar to above form of Error_Pragma_Arg except that two messages
554       --  are provided, the second is a continuation comment starting with \.
555
556       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
557       pragma No_Return (Error_Pragma_Arg_Ident);
558       --  Outputs error message for current pragma. The message may contain
559       --  a % that will be replaced with the pragma name. The parameter Arg
560       --  must be a pragma argument association with a non-empty identifier
561       --  (i.e. its Chars field must be set), and the error message is placed
562       --  on the identifier. The message is placed using Error_Msg_N so
563       --  the message may also contain an & insertion character which will
564       --  reference the identifier. After placing the message, Pragma_Exit
565       --  is raised.
566
567       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
568       pragma No_Return (Error_Pragma_Ref);
569       --  Outputs error message for current pragma. The message may contain
570       --  a % that will be replaced with the pragma name. The parameter Ref
571       --  must be an entity whose name can be referenced by & and sloc by #.
572       --  After placing the message, Pragma_Exit is raised.
573
574       function Find_Lib_Unit_Name return Entity_Id;
575       --  Used for a library unit pragma to find the entity to which the
576       --  library unit pragma applies, returns the entity found.
577
578       procedure Find_Program_Unit_Name (Id : Node_Id);
579       --  If the pragma is a compilation unit pragma, the id must denote the
580       --  compilation unit in the same compilation, and the pragma must appear
581       --  in the list of preceding or trailing pragmas. If it is a program
582       --  unit pragma that is not a compilation unit pragma, then the
583       --  identifier must be visible.
584
585       function Find_Unique_Parameterless_Procedure
586         (Name : Entity_Id;
587          Arg  : Node_Id) return Entity_Id;
588       --  Used for a procedure pragma to find the unique parameterless
589       --  procedure identified by Name, returns it if it exists, otherwise
590       --  errors out and uses Arg as the pragma argument for the message.
591
592       procedure Fix_Error (Msg : in out String);
593       --  This is called prior to issuing an error message. Msg is a string
594       --  which typically contains the substring pragma. If the current pragma
595       --  comes from an aspect, each such "pragma" substring is replaced with
596       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
597       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
598
599       procedure Gather_Associations
600         (Names : Name_List;
601          Args  : out Args_List);
602       --  This procedure is used to gather the arguments for a pragma that
603       --  permits arbitrary ordering of parameters using the normal rules
604       --  for named and positional parameters. The Names argument is a list
605       --  of Name_Id values that corresponds to the allowed pragma argument
606       --  association identifiers in order. The result returned in Args is
607       --  a list of corresponding expressions that are the pragma arguments.
608       --  Note that this is a list of expressions, not of pragma argument
609       --  associations (Gather_Associations has completely checked all the
610       --  optional identifiers when it returns). An entry in Args is Empty
611       --  on return if the corresponding argument is not present.
612
613       procedure GNAT_Pragma;
614       --  Called for all GNAT defined pragmas to check the relevant restriction
615       --  (No_Implementation_Pragmas).
616
617       function Is_Before_First_Decl
618         (Pragma_Node : Node_Id;
619          Decls       : List_Id) return Boolean;
620       --  Return True if Pragma_Node is before the first declarative item in
621       --  Decls where Decls is the list of declarative items.
622
623       function Is_Configuration_Pragma return Boolean;
624       --  Determines if the placement of the current pragma is appropriate
625       --  for a configuration pragma.
626
627       function Is_In_Context_Clause return Boolean;
628       --  Returns True if pragma appears within the context clause of a unit,
629       --  and False for any other placement (does not generate any messages).
630
631       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
632       --  Analyzes the argument, and determines if it is a static string
633       --  expression, returns True if so, False if non-static or not String.
634
635       procedure Pragma_Misplaced;
636       pragma No_Return (Pragma_Misplaced);
637       --  Issue fatal error message for misplaced pragma
638
639       procedure Process_Atomic_Shared_Volatile;
640       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
641       --  Shared is an obsolete Ada 83 pragma, treated as being identical
642       --  in effect to pragma Atomic.
643
644       procedure Process_Compile_Time_Warning_Or_Error;
645       --  Common processing for Compile_Time_Error and Compile_Time_Warning
646
647       procedure Process_Convention
648         (C   : out Convention_Id;
649          Ent : out Entity_Id);
650       --  Common processing for Convention, Interface, Import and Export.
651       --  Checks first two arguments of pragma, and sets the appropriate
652       --  convention value in the specified entity or entities. On return
653       --  C is the convention, Ent is the referenced entity.
654
655       procedure Process_Extended_Import_Export_Exception_Pragma
656         (Arg_Internal : Node_Id;
657          Arg_External : Node_Id;
658          Arg_Form     : Node_Id;
659          Arg_Code     : Node_Id);
660       --  Common processing for the pragmas Import/Export_Exception. The three
661       --  arguments correspond to the three named parameters of the pragma. An
662       --  argument is empty if the corresponding parameter is not present in
663       --  the pragma.
664
665       procedure Process_Extended_Import_Export_Object_Pragma
666         (Arg_Internal : Node_Id;
667          Arg_External : Node_Id;
668          Arg_Size     : Node_Id);
669       --  Common processing for the pragmas Import/Export_Object. The three
670       --  arguments correspond to the three named parameters of the pragmas. An
671       --  argument is empty if the corresponding parameter is not present in
672       --  the pragma.
673
674       procedure Process_Extended_Import_Export_Internal_Arg
675         (Arg_Internal : Node_Id := Empty);
676       --  Common processing for all extended Import and Export pragmas. The
677       --  argument is the pragma parameter for the Internal argument. If
678       --  Arg_Internal is empty or inappropriate, an error message is posted.
679       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
680       --  set to identify the referenced entity.
681
682       procedure Process_Extended_Import_Export_Subprogram_Pragma
683         (Arg_Internal                 : Node_Id;
684          Arg_External                 : Node_Id;
685          Arg_Parameter_Types          : Node_Id;
686          Arg_Result_Type              : Node_Id := Empty;
687          Arg_Mechanism                : Node_Id;
688          Arg_Result_Mechanism         : Node_Id := Empty;
689          Arg_First_Optional_Parameter : Node_Id := Empty);
690       --  Common processing for all extended Import and Export pragmas applying
691       --  to subprograms. The caller omits any arguments that do not apply to
692       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
693       --  only in the Import_Function and Export_Function cases). The argument
694       --  names correspond to the allowed pragma association identifiers.
695
696       procedure Process_Generic_List;
697       --  Common processing for Share_Generic and Inline_Generic
698
699       procedure Process_Import_Or_Interface;
700       --  Common processing for Import of Interface
701
702       procedure Process_Import_Predefined_Type;
703       --  Processing for completing a type with pragma Import. This is used
704       --  to declare types that match predefined C types, especially for cases
705       --  without corresponding Ada predefined type.
706
707       procedure Process_Inline (Active : Boolean);
708       --  Common processing for Inline and Inline_Always. The parameter
709       --  indicates if the inline pragma is active, i.e. if it should actually
710       --  cause inlining to occur.
711
712       procedure Process_Interface_Name
713         (Subprogram_Def : Entity_Id;
714          Ext_Arg        : Node_Id;
715          Link_Arg       : Node_Id);
716       --  Given the last two arguments of pragma Import, pragma Export, or
717       --  pragma Interface_Name, performs validity checks and sets the
718       --  Interface_Name field of the given subprogram entity to the
719       --  appropriate external or link name, depending on the arguments given.
720       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
721       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
722       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
723       --  nor Link_Arg is present, the interface name is set to the default
724       --  from the subprogram name.
725
726       procedure Process_Interrupt_Or_Attach_Handler;
727       --  Common processing for Interrupt and Attach_Handler pragmas
728
729       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
730       --  Common processing for Restrictions and Restriction_Warnings pragmas.
731       --  Warn is True for Restriction_Warnings, or for Restrictions if the
732       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
733       --  is not set in the Restrictions case.
734
735       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
736       --  Common processing for Suppress and Unsuppress. The boolean parameter
737       --  Suppress_Case is True for the Suppress case, and False for the
738       --  Unsuppress case.
739
740       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
741       --  This procedure sets the Is_Exported flag for the given entity,
742       --  checking that the entity was not previously imported. Arg is
743       --  the argument that specified the entity. A check is also made
744       --  for exporting inappropriate entities.
745
746       procedure Set_Extended_Import_Export_External_Name
747         (Internal_Ent : Entity_Id;
748          Arg_External : Node_Id);
749       --  Common processing for all extended import export pragmas. The first
750       --  argument, Internal_Ent, is the internal entity, which has already
751       --  been checked for validity by the caller. Arg_External is from the
752       --  Import or Export pragma, and may be null if no External parameter
753       --  was present. If Arg_External is present and is a non-null string
754       --  (a null string is treated as the default), then the Interface_Name
755       --  field of Internal_Ent is set appropriately.
756
757       procedure Set_Imported (E : Entity_Id);
758       --  This procedure sets the Is_Imported flag for the given entity,
759       --  checking that it is not previously exported or imported.
760
761       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
762       --  Mech is a parameter passing mechanism (see Import_Function syntax
763       --  for MECHANISM_NAME). This routine checks that the mechanism argument
764       --  has the right form, and if not issues an error message. If the
765       --  argument has the right form then the Mechanism field of Ent is
766       --  set appropriately.
767
768       procedure Set_Ravenscar_Profile (N : Node_Id);
769       --  Activate the set of configuration pragmas and restrictions that make
770       --  up the Ravenscar Profile. N is the corresponding pragma node, which
771       --  is used for error messages on any constructs that violate the
772       --  profile.
773
774       ---------------------
775       -- Ada_2005_Pragma --
776       ---------------------
777
778       procedure Ada_2005_Pragma is
779       begin
780          if Ada_Version <= Ada_95 then
781             Check_Restriction (No_Implementation_Pragmas, N);
782          end if;
783       end Ada_2005_Pragma;
784
785       ---------------------
786       -- Ada_2012_Pragma --
787       ---------------------
788
789       procedure Ada_2012_Pragma is
790       begin
791          if Ada_Version <= Ada_2005 then
792             Check_Restriction (No_Implementation_Pragmas, N);
793          end if;
794       end Ada_2012_Pragma;
795
796       --------------------------
797       -- Check_Ada_83_Warning --
798       --------------------------
799
800       procedure Check_Ada_83_Warning is
801       begin
802          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
803             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
804          end if;
805       end Check_Ada_83_Warning;
806
807       ---------------------
808       -- Check_Arg_Count --
809       ---------------------
810
811       procedure Check_Arg_Count (Required : Nat) is
812       begin
813          if Arg_Count /= Required then
814             Error_Pragma ("wrong number of arguments for pragma%");
815          end if;
816       end Check_Arg_Count;
817
818       --------------------------------
819       -- Check_Arg_Is_External_Name --
820       --------------------------------
821
822       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
823          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
824
825       begin
826          if Nkind (Argx) = N_Identifier then
827             return;
828
829          else
830             Analyze_And_Resolve (Argx, Standard_String);
831
832             if Is_OK_Static_Expression (Argx) then
833                return;
834
835             elsif Etype (Argx) = Any_Type then
836                raise Pragma_Exit;
837
838             --  An interesting special case, if we have a string literal and
839             --  we are in Ada 83 mode, then we allow it even though it will
840             --  not be flagged as static. This allows expected Ada 83 mode
841             --  use of external names which are string literals, even though
842             --  technically these are not static in Ada 83.
843
844             elsif Ada_Version = Ada_83
845               and then Nkind (Argx) = N_String_Literal
846             then
847                return;
848
849             --  Static expression that raises Constraint_Error. This has
850             --  already been flagged, so just exit from pragma processing.
851
852             elsif Is_Static_Expression (Argx) then
853                raise Pragma_Exit;
854
855             --  Here we have a real error (non-static expression)
856
857             else
858                Error_Msg_Name_1 := Pname;
859
860                declare
861                   Msg : String :=
862                           "argument for pragma% must be a identifier or "
863                           & "static string expression!";
864                begin
865                   Fix_Error (Msg);
866                   Flag_Non_Static_Expr (Msg, Argx);
867                   raise Pragma_Exit;
868                end;
869             end if;
870          end if;
871       end Check_Arg_Is_External_Name;
872
873       -----------------------------
874       -- Check_Arg_Is_Identifier --
875       -----------------------------
876
877       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
878          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
879       begin
880          if Nkind (Argx) /= N_Identifier then
881             Error_Pragma_Arg
882               ("argument for pragma% must be identifier", Argx);
883          end if;
884       end Check_Arg_Is_Identifier;
885
886       ----------------------------------
887       -- Check_Arg_Is_Integer_Literal --
888       ----------------------------------
889
890       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
891          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
892       begin
893          if Nkind (Argx) /= N_Integer_Literal then
894             Error_Pragma_Arg
895               ("argument for pragma% must be integer literal", Argx);
896          end if;
897       end Check_Arg_Is_Integer_Literal;
898
899       ---------------------------------
900       -- Check_Arg_Is_String_Literal --
901       ---------------------------------
902
903       procedure Check_Arg_Is_String_Literal (Arg : Node_Id) is
904          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
905       begin
906          if Nkind (Argx) /= N_String_Literal then
907             Error_Pragma_Arg
908               ("argument for pragma% must be string literal", Argx);
909          end if;
910       end Check_Arg_Is_String_Literal;
911
912       -------------------------------------------
913       -- Check_Arg_Is_Library_Level_Local_Name --
914       -------------------------------------------
915
916       --  LOCAL_NAME ::=
917       --    DIRECT_NAME
918       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
919       --  | library_unit_NAME
920
921       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
922       begin
923          Check_Arg_Is_Local_Name (Arg);
924
925          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
926            and then Comes_From_Source (N)
927          then
928             Error_Pragma_Arg
929               ("argument for pragma% must be library level entity", Arg);
930          end if;
931       end Check_Arg_Is_Library_Level_Local_Name;
932
933       -----------------------------
934       -- Check_Arg_Is_Local_Name --
935       -----------------------------
936
937       --  LOCAL_NAME ::=
938       --    DIRECT_NAME
939       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
940       --  | library_unit_NAME
941
942       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
943          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
944
945       begin
946          Analyze (Argx);
947
948          if Nkind (Argx) not in N_Direct_Name
949            and then (Nkind (Argx) /= N_Attribute_Reference
950                       or else Present (Expressions (Argx))
951                       or else Nkind (Prefix (Argx)) /= N_Identifier)
952            and then (not Is_Entity_Name (Argx)
953                       or else not Is_Compilation_Unit (Entity (Argx)))
954          then
955             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
956          end if;
957
958          --  No further check required if not an entity name
959
960          if not Is_Entity_Name (Argx) then
961             null;
962
963          else
964             declare
965                OK   : Boolean;
966                Ent  : constant Entity_Id := Entity (Argx);
967                Scop : constant Entity_Id := Scope (Ent);
968             begin
969                --  Case of a pragma applied to a compilation unit: pragma must
970                --  occur immediately after the program unit in the compilation.
971
972                if Is_Compilation_Unit (Ent) then
973                   declare
974                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
975                   begin
976                      --  Case of pragma placed immediately after spec
977
978                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
979                         OK := True;
980
981                      --  Case of pragma placed immediately after body
982
983                      elsif Nkind (Decl) = N_Subprogram_Declaration
984                              and then Present (Corresponding_Body (Decl))
985                      then
986                         OK := Parent (N) =
987                                 Aux_Decls_Node
988                                   (Parent (Unit_Declaration_Node
989                                              (Corresponding_Body (Decl))));
990
991                      --  All other cases are illegal
992
993                      else
994                         OK := False;
995                      end if;
996                   end;
997
998                --  Special restricted placement rule from 10.2.1(11.8/2)
999
1000                elsif Is_Generic_Formal (Ent)
1001                        and then Prag_Id = Pragma_Preelaborable_Initialization
1002                then
1003                   OK := List_Containing (N) =
1004                           Generic_Formal_Declarations
1005                             (Unit_Declaration_Node (Scop));
1006
1007                --  Default case, just check that the pragma occurs in the scope
1008                --  of the entity denoted by the name.
1009
1010                else
1011                   OK := Current_Scope = Scop;
1012                end if;
1013
1014                if not OK then
1015                   Error_Pragma_Arg
1016                     ("pragma% argument must be in same declarative part", Arg);
1017                end if;
1018             end;
1019          end if;
1020       end Check_Arg_Is_Local_Name;
1021
1022       ---------------------------------
1023       -- Check_Arg_Is_Locking_Policy --
1024       ---------------------------------
1025
1026       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1027          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1028
1029       begin
1030          Check_Arg_Is_Identifier (Argx);
1031
1032          if not Is_Locking_Policy_Name (Chars (Argx)) then
1033             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1034          end if;
1035       end Check_Arg_Is_Locking_Policy;
1036
1037       -------------------------
1038       -- Check_Arg_Is_One_Of --
1039       -------------------------
1040
1041       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1042          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1043
1044       begin
1045          Check_Arg_Is_Identifier (Argx);
1046
1047          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1048             Error_Msg_Name_2 := N1;
1049             Error_Msg_Name_3 := N2;
1050             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1051          end if;
1052       end Check_Arg_Is_One_Of;
1053
1054       procedure Check_Arg_Is_One_Of
1055         (Arg        : Node_Id;
1056          N1, N2, N3 : Name_Id)
1057       is
1058          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1059
1060       begin
1061          Check_Arg_Is_Identifier (Argx);
1062
1063          if Chars (Argx) /= N1
1064            and then Chars (Argx) /= N2
1065            and then Chars (Argx) /= N3
1066          then
1067             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1068          end if;
1069       end Check_Arg_Is_One_Of;
1070
1071       procedure Check_Arg_Is_One_Of
1072         (Arg            : Node_Id;
1073          N1, N2, N3, N4 : Name_Id)
1074       is
1075          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1076
1077       begin
1078          Check_Arg_Is_Identifier (Argx);
1079
1080          if Chars (Argx) /= N1
1081            and then Chars (Argx) /= N2
1082            and then Chars (Argx) /= N3
1083            and then Chars (Argx) /= N4
1084          then
1085             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1086          end if;
1087       end Check_Arg_Is_One_Of;
1088
1089       ---------------------------------
1090       -- Check_Arg_Is_Queuing_Policy --
1091       ---------------------------------
1092
1093       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1094          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1095
1096       begin
1097          Check_Arg_Is_Identifier (Argx);
1098
1099          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1100             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1101          end if;
1102       end Check_Arg_Is_Queuing_Policy;
1103
1104       ------------------------------------
1105       -- Check_Arg_Is_Static_Expression --
1106       ------------------------------------
1107
1108       procedure Check_Arg_Is_Static_Expression
1109         (Arg : Node_Id;
1110          Typ : Entity_Id := Empty)
1111       is
1112          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1113
1114       begin
1115          if Present (Typ) then
1116             Analyze_And_Resolve (Argx, Typ);
1117          else
1118             Analyze_And_Resolve (Argx);
1119          end if;
1120
1121          if Is_OK_Static_Expression (Argx) then
1122             return;
1123
1124          elsif Etype (Argx) = Any_Type then
1125             raise Pragma_Exit;
1126
1127          --  An interesting special case, if we have a string literal and we
1128          --  are in Ada 83 mode, then we allow it even though it will not be
1129          --  flagged as static. This allows the use of Ada 95 pragmas like
1130          --  Import in Ada 83 mode. They will of course be flagged with
1131          --  warnings as usual, but will not cause errors.
1132
1133          elsif Ada_Version = Ada_83
1134            and then Nkind (Argx) = N_String_Literal
1135          then
1136             return;
1137
1138          --  Static expression that raises Constraint_Error. This has already
1139          --  been flagged, so just exit from pragma processing.
1140
1141          elsif Is_Static_Expression (Argx) then
1142             raise Pragma_Exit;
1143
1144          --  Finally, we have a real error
1145
1146          else
1147             Error_Msg_Name_1 := Pname;
1148
1149             declare
1150                Msg : String :=
1151                        "argument for pragma% must be a static expression!";
1152             begin
1153                Fix_Error (Msg);
1154                Flag_Non_Static_Expr (Msg, Argx);
1155             end;
1156
1157             raise Pragma_Exit;
1158          end if;
1159       end Check_Arg_Is_Static_Expression;
1160
1161       ------------------------------------------
1162       -- Check_Arg_Is_Task_Dispatching_Policy --
1163       ------------------------------------------
1164
1165       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1166          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1167
1168       begin
1169          Check_Arg_Is_Identifier (Argx);
1170
1171          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1172             Error_Pragma_Arg
1173               ("& is not a valid task dispatching policy name", Argx);
1174          end if;
1175       end Check_Arg_Is_Task_Dispatching_Policy;
1176
1177       ---------------------
1178       -- Check_Arg_Order --
1179       ---------------------
1180
1181       procedure Check_Arg_Order (Names : Name_List) is
1182          Arg : Node_Id;
1183
1184          Highest_So_Far : Natural := 0;
1185          --  Highest index in Names seen do far
1186
1187       begin
1188          Arg := Arg1;
1189          for J in 1 .. Arg_Count loop
1190             if Chars (Arg) /= No_Name then
1191                for K in Names'Range loop
1192                   if Chars (Arg) = Names (K) then
1193                      if K < Highest_So_Far then
1194                         Error_Msg_Name_1 := Pname;
1195                         Error_Msg_N
1196                           ("parameters out of order for pragma%", Arg);
1197                         Error_Msg_Name_1 := Names (K);
1198                         Error_Msg_Name_2 := Names (Highest_So_Far);
1199                         Error_Msg_N ("\% must appear before %", Arg);
1200                         raise Pragma_Exit;
1201
1202                      else
1203                         Highest_So_Far := K;
1204                      end if;
1205                   end if;
1206                end loop;
1207             end if;
1208
1209             Arg := Next (Arg);
1210          end loop;
1211       end Check_Arg_Order;
1212
1213       --------------------------------
1214       -- Check_At_Least_N_Arguments --
1215       --------------------------------
1216
1217       procedure Check_At_Least_N_Arguments (N : Nat) is
1218       begin
1219          if Arg_Count < N then
1220             Error_Pragma ("too few arguments for pragma%");
1221          end if;
1222       end Check_At_Least_N_Arguments;
1223
1224       -------------------------------
1225       -- Check_At_Most_N_Arguments --
1226       -------------------------------
1227
1228       procedure Check_At_Most_N_Arguments (N : Nat) is
1229          Arg : Node_Id;
1230       begin
1231          if Arg_Count > N then
1232             Arg := Arg1;
1233             for J in 1 .. N loop
1234                Next (Arg);
1235                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1236             end loop;
1237          end if;
1238       end Check_At_Most_N_Arguments;
1239
1240       ---------------------
1241       -- Check_Component --
1242       ---------------------
1243
1244       procedure Check_Component
1245         (Comp            : Node_Id;
1246          UU_Typ          : Entity_Id;
1247          In_Variant_Part : Boolean := False)
1248       is
1249          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1250          Sindic  : constant Node_Id :=
1251                      Subtype_Indication (Component_Definition (Comp));
1252          Typ     : constant Entity_Id := Etype (Comp_Id);
1253
1254          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1255          --  Determine whether entity Id appears inside a generic body.
1256          --  Shouldn't this be in a more general place ???
1257
1258          -------------------------
1259          -- Inside_Generic_Body --
1260          -------------------------
1261
1262          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1263             S : Entity_Id;
1264
1265          begin
1266             S := Id;
1267             while Present (S) and then S /= Standard_Standard loop
1268                if Ekind (S) = E_Generic_Package
1269                  and then In_Package_Body (S)
1270                then
1271                   return True;
1272                end if;
1273
1274                S := Scope (S);
1275             end loop;
1276
1277             return False;
1278          end Inside_Generic_Body;
1279
1280       --  Start of processing for Check_Component
1281
1282       begin
1283          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1284          --  object constraint, then the component type shall be an Unchecked_
1285          --  Union.
1286
1287          if Nkind (Sindic) = N_Subtype_Indication
1288            and then Has_Per_Object_Constraint (Comp_Id)
1289            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1290          then
1291             Error_Msg_N
1292               ("component subtype subject to per-object constraint " &
1293                "must be an Unchecked_Union", Comp);
1294
1295          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1296          --  the body of a generic unit, or within the body of any of its
1297          --  descendant library units, no part of the type of a component
1298          --  declared in a variant_part of the unchecked union type shall be of
1299          --  a formal private type or formal private extension declared within
1300          --  the formal part of the generic unit.
1301
1302          elsif Ada_Version >= Ada_2012
1303            and then Inside_Generic_Body (UU_Typ)
1304            and then In_Variant_Part
1305            and then Is_Private_Type (Typ)
1306            and then Is_Generic_Type (Typ)
1307          then
1308             Error_Msg_N
1309               ("component of Unchecked_Union cannot be of generic type", Comp);
1310
1311          elsif Needs_Finalization (Typ) then
1312             Error_Msg_N
1313               ("component of Unchecked_Union cannot be controlled", Comp);
1314
1315          elsif Has_Task (Typ) then
1316             Error_Msg_N
1317               ("component of Unchecked_Union cannot have tasks", Comp);
1318          end if;
1319       end Check_Component;
1320
1321       ----------------------------
1322       -- Check_Duplicate_Pragma --
1323       ----------------------------
1324
1325       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1326          P : Node_Id;
1327
1328       begin
1329          --  Nothing to do if this pragma comes from an aspect specification,
1330          --  since we could not be duplicating a pragma, and we dealt with the
1331          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1332
1333          if From_Aspect_Specification (N) then
1334             return;
1335          end if;
1336
1337          --  Otherwise current pragma may duplicate previous pragma or a
1338          --  previously given aspect specification for the same pragma.
1339
1340          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1341
1342          if Present (P) then
1343             Error_Msg_Name_1 := Pragma_Name (N);
1344             Error_Msg_Sloc := Sloc (P);
1345
1346             if Nkind (P) = N_Aspect_Specification
1347               or else From_Aspect_Specification (P)
1348             then
1349                Error_Msg_NE ("aspect% for & previously given#", N, E);
1350             else
1351                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1352             end if;
1353
1354             raise Pragma_Exit;
1355          end if;
1356       end Check_Duplicate_Pragma;
1357
1358       ----------------------------------
1359       -- Check_Duplicated_Export_Name --
1360       ----------------------------------
1361
1362       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1363          String_Val : constant String_Id := Strval (Nam);
1364
1365       begin
1366          --  We are only interested in the export case, and in the case of
1367          --  generics, it is the instance, not the template, that is the
1368          --  problem (the template will generate a warning in any case).
1369
1370          if not Inside_A_Generic
1371            and then (Prag_Id = Pragma_Export
1372                        or else
1373                      Prag_Id = Pragma_Export_Procedure
1374                        or else
1375                      Prag_Id = Pragma_Export_Valued_Procedure
1376                        or else
1377                      Prag_Id = Pragma_Export_Function)
1378          then
1379             for J in Externals.First .. Externals.Last loop
1380                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1381                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1382                   Error_Msg_N ("external name duplicates name given#", Nam);
1383                   exit;
1384                end if;
1385             end loop;
1386
1387             Externals.Append (Nam);
1388          end if;
1389       end Check_Duplicated_Export_Name;
1390
1391       -------------------------
1392       -- Check_First_Subtype --
1393       -------------------------
1394
1395       procedure Check_First_Subtype (Arg : Node_Id) is
1396          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1397          Ent  : constant Entity_Id := Entity (Argx);
1398
1399       begin
1400          if Is_First_Subtype (Ent) then
1401             null;
1402
1403          elsif Is_Type (Ent) then
1404             Error_Pragma_Arg
1405               ("pragma% cannot apply to subtype", Argx);
1406
1407          elsif Is_Object (Ent) then
1408             Error_Pragma_Arg
1409               ("pragma% cannot apply to object, requires a type", Argx);
1410
1411          else
1412             Error_Pragma_Arg
1413               ("pragma% cannot apply to&, requires a type", Argx);
1414          end if;
1415       end Check_First_Subtype;
1416
1417       ----------------------
1418       -- Check_Identifier --
1419       ----------------------
1420
1421       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1422       begin
1423          if Present (Arg)
1424            and then Nkind (Arg) = N_Pragma_Argument_Association
1425          then
1426             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1427                Error_Msg_Name_1 := Pname;
1428                Error_Msg_Name_2 := Id;
1429                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1430                raise Pragma_Exit;
1431             end if;
1432          end if;
1433       end Check_Identifier;
1434
1435       ---------------------------
1436       -- Check_In_Main_Program --
1437       ---------------------------
1438
1439       procedure Check_In_Main_Program is
1440          P : constant Node_Id := Parent (N);
1441
1442       begin
1443          --  Must be at in subprogram body
1444
1445          if Nkind (P) /= N_Subprogram_Body then
1446             Error_Pragma ("% pragma allowed only in subprogram");
1447
1448          --  Otherwise warn if obviously not main program
1449
1450          elsif Present (Parameter_Specifications (Specification (P)))
1451            or else not Is_Compilation_Unit (Defining_Entity (P))
1452          then
1453             Error_Msg_Name_1 := Pname;
1454             Error_Msg_N
1455               ("?pragma% is only effective in main program", N);
1456          end if;
1457       end Check_In_Main_Program;
1458
1459       ---------------------------------------
1460       -- Check_Interrupt_Or_Attach_Handler --
1461       ---------------------------------------
1462
1463       procedure Check_Interrupt_Or_Attach_Handler is
1464          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1465          Handler_Proc, Proc_Scope : Entity_Id;
1466
1467       begin
1468          Analyze (Arg1_X);
1469
1470          if Prag_Id = Pragma_Interrupt_Handler then
1471             Check_Restriction (No_Dynamic_Attachment, N);
1472          end if;
1473
1474          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1475          Proc_Scope := Scope (Handler_Proc);
1476
1477          --  On AAMP only, a pragma Interrupt_Handler is supported for
1478          --  nonprotected parameterless procedures.
1479
1480          if not AAMP_On_Target
1481            or else Prag_Id = Pragma_Attach_Handler
1482          then
1483             if Ekind (Proc_Scope) /= E_Protected_Type then
1484                Error_Pragma_Arg
1485                  ("argument of pragma% must be protected procedure", Arg1);
1486             end if;
1487
1488             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1489                Error_Pragma ("pragma% must be in protected definition");
1490             end if;
1491          end if;
1492
1493          if not Is_Library_Level_Entity (Proc_Scope)
1494            or else (AAMP_On_Target
1495                      and then not Is_Library_Level_Entity (Handler_Proc))
1496          then
1497             Error_Pragma_Arg
1498               ("argument for pragma% must be library level entity", Arg1);
1499          end if;
1500
1501          --  AI05-0033: A pragma cannot appear within a generic body, because
1502          --  instance can be in a nested scope. The check that protected type
1503          --  is itself a library-level declaration is done elsewhere.
1504
1505          --  Note: we omit this check in Codepeer mode to properly handle code
1506          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1507
1508          if Inside_A_Generic then
1509             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1510               and then In_Package_Body (Scope (Current_Scope))
1511               and then not CodePeer_Mode
1512             then
1513                Error_Pragma ("pragma% cannot be used inside a generic");
1514             end if;
1515          end if;
1516       end Check_Interrupt_Or_Attach_Handler;
1517
1518       -------------------------------------------
1519       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1520       -------------------------------------------
1521
1522       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1523          P : Node_Id;
1524
1525       begin
1526          P := Parent (N);
1527          loop
1528             if No (P) then
1529                exit;
1530
1531             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1532                exit;
1533
1534             elsif Nkind_In (P, N_Package_Specification,
1535                                N_Block_Statement)
1536             then
1537                return;
1538
1539             --  Note: the following tests seem a little peculiar, because
1540             --  they test for bodies, but if we were in the statement part
1541             --  of the body, we would already have hit the handled statement
1542             --  sequence, so the only way we get here is by being in the
1543             --  declarative part of the body.
1544
1545             elsif Nkind_In (P, N_Subprogram_Body,
1546                                N_Package_Body,
1547                                N_Task_Body,
1548                                N_Entry_Body)
1549             then
1550                return;
1551             end if;
1552
1553             P := Parent (P);
1554          end loop;
1555
1556          Error_Pragma ("pragma% is not in declarative part or package spec");
1557       end Check_Is_In_Decl_Part_Or_Package_Spec;
1558
1559       -------------------------
1560       -- Check_No_Identifier --
1561       -------------------------
1562
1563       procedure Check_No_Identifier (Arg : Node_Id) is
1564       begin
1565          if Nkind (Arg) = N_Pragma_Argument_Association
1566            and then Chars (Arg) /= No_Name
1567          then
1568             Error_Pragma_Arg_Ident
1569               ("pragma% does not permit identifier& here", Arg);
1570          end if;
1571       end Check_No_Identifier;
1572
1573       --------------------------
1574       -- Check_No_Identifiers --
1575       --------------------------
1576
1577       procedure Check_No_Identifiers is
1578          Arg_Node : Node_Id;
1579       begin
1580          if Arg_Count > 0 then
1581             Arg_Node := Arg1;
1582             while Present (Arg_Node) loop
1583                Check_No_Identifier (Arg_Node);
1584                Next (Arg_Node);
1585             end loop;
1586          end if;
1587       end Check_No_Identifiers;
1588
1589       ------------------------
1590       -- Check_No_Link_Name --
1591       ------------------------
1592
1593       procedure Check_No_Link_Name is
1594       begin
1595          if Present (Arg3)
1596            and then Chars (Arg3) = Name_Link_Name
1597          then
1598             Arg4 := Arg3;
1599          end if;
1600
1601          if Present (Arg4) then
1602             Error_Pragma_Arg
1603               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1604          end if;
1605       end Check_No_Link_Name;
1606
1607       -------------------------------
1608       -- Check_Optional_Identifier --
1609       -------------------------------
1610
1611       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1612       begin
1613          if Present (Arg)
1614            and then Nkind (Arg) = N_Pragma_Argument_Association
1615            and then Chars (Arg) /= No_Name
1616          then
1617             if Chars (Arg) /= Id then
1618                Error_Msg_Name_1 := Pname;
1619                Error_Msg_Name_2 := Id;
1620                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1621                raise Pragma_Exit;
1622             end if;
1623          end if;
1624       end Check_Optional_Identifier;
1625
1626       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1627       begin
1628          Name_Buffer (1 .. Id'Length) := Id;
1629          Name_Len := Id'Length;
1630          Check_Optional_Identifier (Arg, Name_Find);
1631       end Check_Optional_Identifier;
1632
1633       --------------------------------------
1634       -- Check_Precondition_Postcondition --
1635       --------------------------------------
1636
1637       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1638          P  : Node_Id;
1639          PO : Node_Id;
1640
1641          procedure Chain_PPC (PO : Node_Id);
1642          --  If PO is an entry or a [generic] subprogram declaration node, then
1643          --  the precondition/postcondition applies to this subprogram and the
1644          --  processing for the pragma is completed. Otherwise the pragma is
1645          --  misplaced.
1646
1647          ---------------
1648          -- Chain_PPC --
1649          ---------------
1650
1651          procedure Chain_PPC (PO : Node_Id) is
1652             S   : Entity_Id;
1653             P   : Node_Id;
1654
1655          begin
1656             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1657                if not From_Aspect_Specification (N) then
1658                   Error_Pragma
1659                     ("pragma% cannot be applied to abstract subprogram");
1660
1661                elsif Class_Present (N) then
1662                   null;
1663
1664                else
1665                   Error_Pragma
1666                     ("aspect % requires ''Class for abstract subprogram");
1667                end if;
1668
1669             --  AI05-0230: The same restriction applies to null procedures. For
1670             --  compatibility with earlier uses of the Ada pragma, apply this
1671             --  rule only to aspect specifications.
1672
1673             --  The above discrpency needs documentation. Robert is dubious
1674             --  about whether it is a good idea ???
1675
1676             elsif Nkind (PO) = N_Subprogram_Declaration
1677               and then Nkind (Specification (PO)) = N_Procedure_Specification
1678               and then Null_Present (Specification (PO))
1679               and then From_Aspect_Specification (N)
1680               and then not Class_Present (N)
1681             then
1682                Error_Pragma
1683                  ("aspect % requires ''Class for null procedure");
1684
1685             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1686                                     N_Generic_Subprogram_Declaration,
1687                                     N_Entry_Declaration)
1688             then
1689                Pragma_Misplaced;
1690             end if;
1691
1692             --  Here if we have [generic] subprogram or entry declaration
1693
1694             if Nkind (PO) = N_Entry_Declaration then
1695                S := Defining_Entity (PO);
1696             else
1697                S := Defining_Unit_Name (Specification (PO));
1698             end if;
1699
1700             --  Make sure we do not have the case of a precondition pragma when
1701             --  the Pre'Class aspect is present.
1702
1703             --  We do this by looking at pragmas already chained to the entity
1704             --  since the aspect derived pragma will be put on this list first.
1705
1706             if Pragma_Name (N) = Name_Precondition then
1707                if not From_Aspect_Specification (N) then
1708                   P := Spec_PPC_List (Contract (S));
1709                   while Present (P) loop
1710                      if Pragma_Name (P) = Name_Precondition
1711                        and then From_Aspect_Specification (P)
1712                        and then Class_Present (P)
1713                      then
1714                         Error_Msg_Sloc := Sloc (P);
1715                         Error_Pragma
1716                           ("pragma% not allowed, `Pre''Class` aspect given#");
1717                      end if;
1718
1719                      P := Next_Pragma (P);
1720                   end loop;
1721                end if;
1722             end if;
1723
1724             --  Similarly check for Pre with inherited Pre'Class. Note that
1725             --  we cover the aspect case as well here.
1726
1727             if Pragma_Name (N) = Name_Precondition
1728               and then not Class_Present (N)
1729             then
1730                declare
1731                   Inherited : constant Subprogram_List :=
1732                                 Inherited_Subprograms (S);
1733                   P         : Node_Id;
1734
1735                begin
1736                   for J in Inherited'Range loop
1737                      P := Spec_PPC_List (Contract (Inherited (J)));
1738                      while Present (P) loop
1739                         if Pragma_Name (P) = Name_Precondition
1740                           and then Class_Present (P)
1741                         then
1742                            Error_Msg_Sloc := Sloc (P);
1743                            Error_Pragma
1744                              ("pragma% not allowed, `Pre''Class` "
1745                               & "aspect inherited from#");
1746                         end if;
1747
1748                         P := Next_Pragma (P);
1749                      end loop;
1750                   end loop;
1751                end;
1752             end if;
1753
1754             --  Note: we do not analyze the pragma at this point. Instead we
1755             --  delay this analysis until the end of the declarative part in
1756             --  which the pragma appears. This implements the required delay
1757             --  in this analysis, allowing forward references. The analysis
1758             --  happens at the end of Analyze_Declarations.
1759
1760             --  Chain spec PPC pragma to list for subprogram
1761
1762             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1763             Set_Spec_PPC_List (Contract (S), N);
1764
1765             --  Return indicating spec case
1766
1767             In_Body := False;
1768             return;
1769          end Chain_PPC;
1770
1771       --  Start of processing for Check_Precondition_Postcondition
1772
1773       begin
1774          if not Is_List_Member (N) then
1775             Pragma_Misplaced;
1776          end if;
1777
1778          --  Preanalyze message argument if present. Visibility in this
1779          --  argument is established at the point of pragma occurrence.
1780
1781          if Arg_Count = 2 then
1782             Check_Optional_Identifier (Arg2, Name_Message);
1783             Preanalyze_Spec_Expression
1784               (Get_Pragma_Arg (Arg2), Standard_String);
1785          end if;
1786
1787          --  Record if pragma is enabled
1788
1789          if Check_Enabled (Pname) then
1790             Set_SCO_Pragma_Enabled (Loc);
1791          end if;
1792
1793          --  If we are within an inlined body, the legality of the pragma
1794          --  has been checked already.
1795
1796          if In_Inlined_Body then
1797             In_Body := True;
1798             return;
1799          end if;
1800
1801          --  Search prior declarations
1802
1803          P := N;
1804          while Present (Prev (P)) loop
1805             P := Prev (P);
1806
1807             --  If the previous node is a generic subprogram, do not go to to
1808             --  the original node, which is the unanalyzed tree: we need to
1809             --  attach the pre/postconditions to the analyzed version at this
1810             --  point. They get propagated to the original tree when analyzing
1811             --  the corresponding body.
1812
1813             if Nkind (P) not in N_Generic_Declaration then
1814                PO := Original_Node (P);
1815             else
1816                PO := P;
1817             end if;
1818
1819             --  Skip past prior pragma
1820
1821             if Nkind (PO) = N_Pragma then
1822                null;
1823
1824             --  Skip stuff not coming from source
1825
1826             elsif not Comes_From_Source (PO) then
1827
1828                --  The condition may apply to a subprogram instantiation
1829
1830                if Nkind (PO) = N_Subprogram_Declaration
1831                  and then Present (Generic_Parent (Specification (PO)))
1832                then
1833                   Chain_PPC (PO);
1834                   return;
1835
1836                --  For all other cases of non source code, do nothing
1837
1838                else
1839                   null;
1840                end if;
1841
1842             --  Only remaining possibility is subprogram declaration
1843
1844             else
1845                Chain_PPC (PO);
1846                return;
1847             end if;
1848          end loop;
1849
1850          --  If we fall through loop, pragma is at start of list, so see if it
1851          --  is at the start of declarations of a subprogram body.
1852
1853          if Nkind (Parent (N)) = N_Subprogram_Body
1854            and then List_Containing (N) = Declarations (Parent (N))
1855          then
1856             if Operating_Mode /= Generate_Code
1857               or else Inside_A_Generic
1858             then
1859                --  Analyze pragma expression for correctness and for ASIS use
1860
1861                Preanalyze_Spec_Expression
1862                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
1863             end if;
1864
1865             In_Body := True;
1866             return;
1867
1868          --  See if it is in the pragmas after a library level subprogram
1869
1870          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1871             Chain_PPC (Unit (Parent (Parent (N))));
1872             return;
1873          end if;
1874
1875          --  If we fall through, pragma was misplaced
1876
1877          Pragma_Misplaced;
1878       end Check_Precondition_Postcondition;
1879
1880       -----------------------------
1881       -- Check_Static_Constraint --
1882       -----------------------------
1883
1884       --  Note: for convenience in writing this procedure, in addition to
1885       --  the officially (i.e. by spec) allowed argument which is always a
1886       --  constraint, it also allows ranges and discriminant associations.
1887       --  Above is not clear ???
1888
1889       procedure Check_Static_Constraint (Constr : Node_Id) is
1890
1891          procedure Require_Static (E : Node_Id);
1892          --  Require given expression to be static expression
1893
1894          --------------------
1895          -- Require_Static --
1896          --------------------
1897
1898          procedure Require_Static (E : Node_Id) is
1899          begin
1900             if not Is_OK_Static_Expression (E) then
1901                Flag_Non_Static_Expr
1902                  ("non-static constraint not allowed in Unchecked_Union!", E);
1903                raise Pragma_Exit;
1904             end if;
1905          end Require_Static;
1906
1907       --  Start of processing for Check_Static_Constraint
1908
1909       begin
1910          case Nkind (Constr) is
1911             when N_Discriminant_Association =>
1912                Require_Static (Expression (Constr));
1913
1914             when N_Range =>
1915                Require_Static (Low_Bound (Constr));
1916                Require_Static (High_Bound (Constr));
1917
1918             when N_Attribute_Reference =>
1919                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
1920                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1921
1922             when N_Range_Constraint =>
1923                Check_Static_Constraint (Range_Expression (Constr));
1924
1925             when N_Index_Or_Discriminant_Constraint =>
1926                declare
1927                   IDC : Entity_Id;
1928                begin
1929                   IDC := First (Constraints (Constr));
1930                   while Present (IDC) loop
1931                      Check_Static_Constraint (IDC);
1932                      Next (IDC);
1933                   end loop;
1934                end;
1935
1936             when others =>
1937                null;
1938          end case;
1939       end Check_Static_Constraint;
1940
1941       ---------------------
1942       -- Check_Test_Case --
1943       ---------------------
1944
1945       procedure Check_Test_Case is
1946          P  : Node_Id;
1947          PO : Node_Id;
1948
1949          procedure Chain_TC (PO : Node_Id);
1950          --  If PO is an entry or a [generic] subprogram declaration node, then
1951          --  the test-case applies to this subprogram and the processing for
1952          --  the pragma is completed. Otherwise the pragma is misplaced.
1953
1954          --------------
1955          -- Chain_TC --
1956          --------------
1957
1958          procedure Chain_TC (PO : Node_Id) is
1959             S   : Entity_Id;
1960
1961          begin
1962             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1963                if From_Aspect_Specification (N) then
1964                   Error_Pragma
1965                     ("aspect% cannot be applied to abstract subprogram");
1966                else
1967                   Error_Pragma
1968                     ("pragma% cannot be applied to abstract subprogram");
1969                end if;
1970
1971             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1972                                     N_Generic_Subprogram_Declaration,
1973                                     N_Entry_Declaration)
1974             then
1975                Pragma_Misplaced;
1976             end if;
1977
1978             --  Here if we have [generic] subprogram or entry declaration
1979
1980             if Nkind (PO) = N_Entry_Declaration then
1981                S := Defining_Entity (PO);
1982             else
1983                S := Defining_Unit_Name (Specification (PO));
1984             end if;
1985
1986             --  Note: we do not analyze the pragma at this point. Instead we
1987             --  delay this analysis until the end of the declarative part in
1988             --  which the pragma appears. This implements the required delay
1989             --  in this analysis, allowing forward references. The analysis
1990             --  happens at the end of Analyze_Declarations.
1991
1992             --  Chain spec TC pragma to list for subprogram
1993
1994             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
1995             Set_Spec_TC_List (Contract (S), N);
1996          end Chain_TC;
1997
1998       --  Start of processing for Check_Test_Case
1999
2000       begin
2001          if not Is_List_Member (N) then
2002             Pragma_Misplaced;
2003          end if;
2004
2005          --  Search prior declarations
2006
2007          P := N;
2008          while Present (Prev (P)) loop
2009             P := Prev (P);
2010
2011             --  If the previous node is a generic subprogram, do not go to to
2012             --  the original node, which is the unanalyzed tree: we need to
2013             --  attach the test-case to the analyzed version at this point.
2014             --  They get propagated to the original tree when analyzing the
2015             --  corresponding body.
2016
2017             if Nkind (P) not in N_Generic_Declaration then
2018                PO := Original_Node (P);
2019             else
2020                PO := P;
2021             end if;
2022
2023             --  Skip past prior pragma
2024
2025             if Nkind (PO) = N_Pragma then
2026                null;
2027
2028             --  Skip stuff not coming from source
2029
2030             elsif not Comes_From_Source (PO) then
2031                null;
2032
2033             --  Only remaining possibility is subprogram declaration
2034
2035             else
2036                Chain_TC (PO);
2037                return;
2038             end if;
2039          end loop;
2040
2041          --  If we fall through loop, pragma is at start of list, so see if it
2042          --  is at the start of declarations of a subprogram body.
2043
2044          if Nkind (Parent (N)) = N_Subprogram_Body
2045            and then List_Containing (N) = Declarations (Parent (N))
2046          then
2047             if Operating_Mode /= Generate_Code
2048               or else Inside_A_Generic
2049             then
2050                --  Analyze pragma expressions for correctness and for ASIS use
2051
2052                Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
2053                                    Get_Ensures_From_Test_Case_Pragma (N));
2054             end if;
2055
2056             return;
2057
2058          --  See if it is in the pragmas after a library level subprogram
2059
2060          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2061             Chain_TC (Unit (Parent (Parent (N))));
2062             return;
2063          end if;
2064
2065          --  If we fall through, pragma was misplaced
2066
2067          Pragma_Misplaced;
2068       end Check_Test_Case;
2069
2070       --------------------------------------
2071       -- Check_Valid_Configuration_Pragma --
2072       --------------------------------------
2073
2074       --  A configuration pragma must appear in the context clause of a
2075       --  compilation unit, and only other pragmas may precede it. Note that
2076       --  the test also allows use in a configuration pragma file.
2077
2078       procedure Check_Valid_Configuration_Pragma is
2079       begin
2080          if not Is_Configuration_Pragma then
2081             Error_Pragma ("incorrect placement for configuration pragma%");
2082          end if;
2083       end Check_Valid_Configuration_Pragma;
2084
2085       -------------------------------------
2086       -- Check_Valid_Library_Unit_Pragma --
2087       -------------------------------------
2088
2089       procedure Check_Valid_Library_Unit_Pragma is
2090          Plist       : List_Id;
2091          Parent_Node : Node_Id;
2092          Unit_Name   : Entity_Id;
2093          Unit_Kind   : Node_Kind;
2094          Unit_Node   : Node_Id;
2095          Sindex      : Source_File_Index;
2096
2097       begin
2098          if not Is_List_Member (N) then
2099             Pragma_Misplaced;
2100
2101          else
2102             Plist := List_Containing (N);
2103             Parent_Node := Parent (Plist);
2104
2105             if Parent_Node = Empty then
2106                Pragma_Misplaced;
2107
2108             --  Case of pragma appearing after a compilation unit. In this case
2109             --  it must have an argument with the corresponding name and must
2110             --  be part of the following pragmas of its parent.
2111
2112             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2113                if Plist /= Pragmas_After (Parent_Node) then
2114                   Pragma_Misplaced;
2115
2116                elsif Arg_Count = 0 then
2117                   Error_Pragma
2118                     ("argument required if outside compilation unit");
2119
2120                else
2121                   Check_No_Identifiers;
2122                   Check_Arg_Count (1);
2123                   Unit_Node := Unit (Parent (Parent_Node));
2124                   Unit_Kind := Nkind (Unit_Node);
2125
2126                   Analyze (Get_Pragma_Arg (Arg1));
2127
2128                   if Unit_Kind = N_Generic_Subprogram_Declaration
2129                     or else Unit_Kind = N_Subprogram_Declaration
2130                   then
2131                      Unit_Name := Defining_Entity (Unit_Node);
2132
2133                   elsif Unit_Kind in N_Generic_Instantiation then
2134                      Unit_Name := Defining_Entity (Unit_Node);
2135
2136                   else
2137                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2138                   end if;
2139
2140                   if Chars (Unit_Name) /=
2141                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2142                   then
2143                      Error_Pragma_Arg
2144                        ("pragma% argument is not current unit name", Arg1);
2145                   end if;
2146
2147                   if Ekind (Unit_Name) = E_Package
2148                     and then Present (Renamed_Entity (Unit_Name))
2149                   then
2150                      Error_Pragma ("pragma% not allowed for renamed package");
2151                   end if;
2152                end if;
2153
2154             --  Pragma appears other than after a compilation unit
2155
2156             else
2157                --  Here we check for the generic instantiation case and also
2158                --  for the case of processing a generic formal package. We
2159                --  detect these cases by noting that the Sloc on the node
2160                --  does not belong to the current compilation unit.
2161
2162                Sindex := Source_Index (Current_Sem_Unit);
2163
2164                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2165                   Rewrite (N, Make_Null_Statement (Loc));
2166                   return;
2167
2168                --  If before first declaration, the pragma applies to the
2169                --  enclosing unit, and the name if present must be this name.
2170
2171                elsif Is_Before_First_Decl (N, Plist) then
2172                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2173                   Unit_Kind := Nkind (Unit_Node);
2174
2175                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2176                      Pragma_Misplaced;
2177
2178                   elsif Unit_Kind = N_Subprogram_Body
2179                     and then not Acts_As_Spec (Unit_Node)
2180                   then
2181                      Pragma_Misplaced;
2182
2183                   elsif Nkind (Parent_Node) = N_Package_Body then
2184                      Pragma_Misplaced;
2185
2186                   elsif Nkind (Parent_Node) = N_Package_Specification
2187                     and then Plist = Private_Declarations (Parent_Node)
2188                   then
2189                      Pragma_Misplaced;
2190
2191                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2192                            or else Nkind (Parent_Node) =
2193                                              N_Generic_Subprogram_Declaration)
2194                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2195                   then
2196                      Pragma_Misplaced;
2197
2198                   elsif Arg_Count > 0 then
2199                      Analyze (Get_Pragma_Arg (Arg1));
2200
2201                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2202                         Error_Pragma_Arg
2203                           ("name in pragma% must be enclosing unit", Arg1);
2204                      end if;
2205
2206                   --  It is legal to have no argument in this context
2207
2208                   else
2209                      return;
2210                   end if;
2211
2212                --  Error if not before first declaration. This is because a
2213                --  library unit pragma argument must be the name of a library
2214                --  unit (RM 10.1.5(7)), but the only names permitted in this
2215                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2216                --  generic subprogram declarations or generic instantiations.
2217
2218                else
2219                   Error_Pragma
2220                     ("pragma% misplaced, must be before first declaration");
2221                end if;
2222             end if;
2223          end if;
2224       end Check_Valid_Library_Unit_Pragma;
2225
2226       -------------------
2227       -- Check_Variant --
2228       -------------------
2229
2230       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2231          Clist : constant Node_Id := Component_List (Variant);
2232          Comp  : Node_Id;
2233
2234       begin
2235          if not Is_Non_Empty_List (Component_Items (Clist)) then
2236             Error_Msg_N
2237               ("Unchecked_Union may not have empty component list",
2238                Variant);
2239             return;
2240          end if;
2241
2242          Comp := First (Component_Items (Clist));
2243          while Present (Comp) loop
2244             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2245             Next (Comp);
2246          end loop;
2247       end Check_Variant;
2248
2249       ------------------
2250       -- Error_Pragma --
2251       ------------------
2252
2253       procedure Error_Pragma (Msg : String) is
2254          MsgF : String := Msg;
2255       begin
2256          Error_Msg_Name_1 := Pname;
2257          Fix_Error (MsgF);
2258          Error_Msg_N (MsgF, N);
2259          raise Pragma_Exit;
2260       end Error_Pragma;
2261
2262       ----------------------
2263       -- Error_Pragma_Arg --
2264       ----------------------
2265
2266       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2267          MsgF : String := Msg;
2268       begin
2269          Error_Msg_Name_1 := Pname;
2270          Fix_Error (MsgF);
2271          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2272          raise Pragma_Exit;
2273       end Error_Pragma_Arg;
2274
2275       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2276          MsgF : String := Msg1;
2277       begin
2278          Error_Msg_Name_1 := Pname;
2279          Fix_Error (MsgF);
2280          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2281          Error_Pragma_Arg (Msg2, Arg);
2282       end Error_Pragma_Arg;
2283
2284       ----------------------------
2285       -- Error_Pragma_Arg_Ident --
2286       ----------------------------
2287
2288       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2289          MsgF : String := Msg;
2290       begin
2291          Error_Msg_Name_1 := Pname;
2292          Fix_Error (MsgF);
2293          Error_Msg_N (MsgF, Arg);
2294          raise Pragma_Exit;
2295       end Error_Pragma_Arg_Ident;
2296
2297       ----------------------
2298       -- Error_Pragma_Ref --
2299       ----------------------
2300
2301       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2302          MsgF : String := Msg;
2303       begin
2304          Error_Msg_Name_1 := Pname;
2305          Fix_Error (MsgF);
2306          Error_Msg_Sloc   := Sloc (Ref);
2307          Error_Msg_NE (MsgF, N, Ref);
2308          raise Pragma_Exit;
2309       end Error_Pragma_Ref;
2310
2311       ------------------------
2312       -- Find_Lib_Unit_Name --
2313       ------------------------
2314
2315       function Find_Lib_Unit_Name return Entity_Id is
2316       begin
2317          --  Return inner compilation unit entity, for case of nested
2318          --  categorization pragmas. This happens in generic unit.
2319
2320          if Nkind (Parent (N)) = N_Package_Specification
2321            and then Defining_Entity (Parent (N)) /= Current_Scope
2322          then
2323             return Defining_Entity (Parent (N));
2324          else
2325             return Current_Scope;
2326          end if;
2327       end Find_Lib_Unit_Name;
2328
2329       ----------------------------
2330       -- Find_Program_Unit_Name --
2331       ----------------------------
2332
2333       procedure Find_Program_Unit_Name (Id : Node_Id) is
2334          Unit_Name : Entity_Id;
2335          Unit_Kind : Node_Kind;
2336          P         : constant Node_Id := Parent (N);
2337
2338       begin
2339          if Nkind (P) = N_Compilation_Unit then
2340             Unit_Kind := Nkind (Unit (P));
2341
2342             if Unit_Kind = N_Subprogram_Declaration
2343               or else Unit_Kind = N_Package_Declaration
2344               or else Unit_Kind in N_Generic_Declaration
2345             then
2346                Unit_Name := Defining_Entity (Unit (P));
2347
2348                if Chars (Id) = Chars (Unit_Name) then
2349                   Set_Entity (Id, Unit_Name);
2350                   Set_Etype (Id, Etype (Unit_Name));
2351                else
2352                   Set_Etype (Id, Any_Type);
2353                   Error_Pragma
2354                     ("cannot find program unit referenced by pragma%");
2355                end if;
2356
2357             else
2358                Set_Etype (Id, Any_Type);
2359                Error_Pragma ("pragma% inapplicable to this unit");
2360             end if;
2361
2362          else
2363             Analyze (Id);
2364          end if;
2365       end Find_Program_Unit_Name;
2366
2367       -----------------------------------------
2368       -- Find_Unique_Parameterless_Procedure --
2369       -----------------------------------------
2370
2371       function Find_Unique_Parameterless_Procedure
2372         (Name : Entity_Id;
2373          Arg  : Node_Id) return Entity_Id
2374       is
2375          Proc : Entity_Id := Empty;
2376
2377       begin
2378          --  The body of this procedure needs some comments ???
2379
2380          if not Is_Entity_Name (Name) then
2381             Error_Pragma_Arg
2382               ("argument of pragma% must be entity name", Arg);
2383
2384          elsif not Is_Overloaded (Name) then
2385             Proc := Entity (Name);
2386
2387             if Ekind (Proc) /= E_Procedure
2388               or else Present (First_Formal (Proc))
2389             then
2390                Error_Pragma_Arg
2391                  ("argument of pragma% must be parameterless procedure", Arg);
2392             end if;
2393
2394          else
2395             declare
2396                Found : Boolean := False;
2397                It    : Interp;
2398                Index : Interp_Index;
2399
2400             begin
2401                Get_First_Interp (Name, Index, It);
2402                while Present (It.Nam) loop
2403                   Proc := It.Nam;
2404
2405                   if Ekind (Proc) = E_Procedure
2406                     and then No (First_Formal (Proc))
2407                   then
2408                      if not Found then
2409                         Found := True;
2410                         Set_Entity (Name, Proc);
2411                         Set_Is_Overloaded (Name, False);
2412                      else
2413                         Error_Pragma_Arg
2414                           ("ambiguous handler name for pragma% ", Arg);
2415                      end if;
2416                   end if;
2417
2418                   Get_Next_Interp (Index, It);
2419                end loop;
2420
2421                if not Found then
2422                   Error_Pragma_Arg
2423                     ("argument of pragma% must be parameterless procedure",
2424                      Arg);
2425                else
2426                   Proc := Entity (Name);
2427                end if;
2428             end;
2429          end if;
2430
2431          return Proc;
2432       end Find_Unique_Parameterless_Procedure;
2433
2434       ---------------
2435       -- Fix_Error --
2436       ---------------
2437
2438       procedure Fix_Error (Msg : in out String) is
2439       begin
2440          if From_Aspect_Specification (N) then
2441             for J in Msg'First .. Msg'Last - 5 loop
2442                if Msg (J .. J + 5) = "pragma" then
2443                   Msg (J .. J + 5) := "aspect";
2444                end if;
2445             end loop;
2446
2447             if Error_Msg_Name_1 = Name_Precondition then
2448                Error_Msg_Name_1 := Name_Pre;
2449             elsif Error_Msg_Name_1 = Name_Postcondition then
2450                Error_Msg_Name_1 := Name_Post;
2451             end if;
2452          end if;
2453       end Fix_Error;
2454
2455       -------------------------
2456       -- Gather_Associations --
2457       -------------------------
2458
2459       procedure Gather_Associations
2460         (Names : Name_List;
2461          Args  : out Args_List)
2462       is
2463          Arg : Node_Id;
2464
2465       begin
2466          --  Initialize all parameters to Empty
2467
2468          for J in Args'Range loop
2469             Args (J) := Empty;
2470          end loop;
2471
2472          --  That's all we have to do if there are no argument associations
2473
2474          if No (Pragma_Argument_Associations (N)) then
2475             return;
2476          end if;
2477
2478          --  Otherwise first deal with any positional parameters present
2479
2480          Arg := First (Pragma_Argument_Associations (N));
2481          for Index in Args'Range loop
2482             exit when No (Arg) or else Chars (Arg) /= No_Name;
2483             Args (Index) := Get_Pragma_Arg (Arg);
2484             Next (Arg);
2485          end loop;
2486
2487          --  Positional parameters all processed, if any left, then we
2488          --  have too many positional parameters.
2489
2490          if Present (Arg) and then Chars (Arg) = No_Name then
2491             Error_Pragma_Arg
2492               ("too many positional associations for pragma%", Arg);
2493          end if;
2494
2495          --  Process named parameters if any are present
2496
2497          while Present (Arg) loop
2498             if Chars (Arg) = No_Name then
2499                Error_Pragma_Arg
2500                  ("positional association cannot follow named association",
2501                   Arg);
2502
2503             else
2504                for Index in Names'Range loop
2505                   if Names (Index) = Chars (Arg) then
2506                      if Present (Args (Index)) then
2507                         Error_Pragma_Arg
2508                           ("duplicate argument association for pragma%", Arg);
2509                      else
2510                         Args (Index) := Get_Pragma_Arg (Arg);
2511                         exit;
2512                      end if;
2513                   end if;
2514
2515                   if Index = Names'Last then
2516                      Error_Msg_Name_1 := Pname;
2517                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2518
2519                      --  Check for possible misspelling
2520
2521                      for Index1 in Names'Range loop
2522                         if Is_Bad_Spelling_Of
2523                              (Chars (Arg), Names (Index1))
2524                         then
2525                            Error_Msg_Name_1 := Names (Index1);
2526                            Error_Msg_N -- CODEFIX
2527                              ("\possible misspelling of%", Arg);
2528                            exit;
2529                         end if;
2530                      end loop;
2531
2532                      raise Pragma_Exit;
2533                   end if;
2534                end loop;
2535             end if;
2536
2537             Next (Arg);
2538          end loop;
2539       end Gather_Associations;
2540
2541       -----------------
2542       -- GNAT_Pragma --
2543       -----------------
2544
2545       procedure GNAT_Pragma is
2546       begin
2547          Check_Restriction (No_Implementation_Pragmas, N);
2548       end GNAT_Pragma;
2549
2550       --------------------------
2551       -- Is_Before_First_Decl --
2552       --------------------------
2553
2554       function Is_Before_First_Decl
2555         (Pragma_Node : Node_Id;
2556          Decls       : List_Id) return Boolean
2557       is
2558          Item : Node_Id := First (Decls);
2559
2560       begin
2561          --  Only other pragmas can come before this pragma
2562
2563          loop
2564             if No (Item) or else Nkind (Item) /= N_Pragma then
2565                return False;
2566
2567             elsif Item = Pragma_Node then
2568                return True;
2569             end if;
2570
2571             Next (Item);
2572          end loop;
2573       end Is_Before_First_Decl;
2574
2575       -----------------------------
2576       -- Is_Configuration_Pragma --
2577       -----------------------------
2578
2579       --  A configuration pragma must appear in the context clause of a
2580       --  compilation unit, and only other pragmas may precede it. Note that
2581       --  the test below also permits use in a configuration pragma file.
2582
2583       function Is_Configuration_Pragma return Boolean is
2584          Lis : constant List_Id := List_Containing (N);
2585          Par : constant Node_Id := Parent (N);
2586          Prg : Node_Id;
2587
2588       begin
2589          --  If no parent, then we are in the configuration pragma file,
2590          --  so the placement is definitely appropriate.
2591
2592          if No (Par) then
2593             return True;
2594
2595          --  Otherwise we must be in the context clause of a compilation unit
2596          --  and the only thing allowed before us in the context list is more
2597          --  configuration pragmas.
2598
2599          elsif Nkind (Par) = N_Compilation_Unit
2600            and then Context_Items (Par) = Lis
2601          then
2602             Prg := First (Lis);
2603
2604             loop
2605                if Prg = N then
2606                   return True;
2607                elsif Nkind (Prg) /= N_Pragma then
2608                   return False;
2609                end if;
2610
2611                Next (Prg);
2612             end loop;
2613
2614          else
2615             return False;
2616          end if;
2617       end Is_Configuration_Pragma;
2618
2619       --------------------------
2620       -- Is_In_Context_Clause --
2621       --------------------------
2622
2623       function Is_In_Context_Clause return Boolean is
2624          Plist       : List_Id;
2625          Parent_Node : Node_Id;
2626
2627       begin
2628          if not Is_List_Member (N) then
2629             return False;
2630
2631          else
2632             Plist := List_Containing (N);
2633             Parent_Node := Parent (Plist);
2634
2635             if Parent_Node = Empty
2636               or else Nkind (Parent_Node) /= N_Compilation_Unit
2637               or else Context_Items (Parent_Node) /= Plist
2638             then
2639                return False;
2640             end if;
2641          end if;
2642
2643          return True;
2644       end Is_In_Context_Clause;
2645
2646       ---------------------------------
2647       -- Is_Static_String_Expression --
2648       ---------------------------------
2649
2650       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2651          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2652
2653       begin
2654          Analyze_And_Resolve (Argx);
2655          return Is_OK_Static_Expression (Argx)
2656            and then Nkind (Argx) = N_String_Literal;
2657       end Is_Static_String_Expression;
2658
2659       ----------------------
2660       -- Pragma_Misplaced --
2661       ----------------------
2662
2663       procedure Pragma_Misplaced is
2664       begin
2665          Error_Pragma ("incorrect placement of pragma%");
2666       end Pragma_Misplaced;
2667
2668       ------------------------------------
2669       -- Process Atomic_Shared_Volatile --
2670       ------------------------------------
2671
2672       procedure Process_Atomic_Shared_Volatile is
2673          E_Id : Node_Id;
2674          E    : Entity_Id;
2675          D    : Node_Id;
2676          K    : Node_Kind;
2677          Utyp : Entity_Id;
2678
2679          procedure Set_Atomic (E : Entity_Id);
2680          --  Set given type as atomic, and if no explicit alignment was given,
2681          --  set alignment to unknown, since back end knows what the alignment
2682          --  requirements are for atomic arrays. Note: this step is necessary
2683          --  for derived types.
2684
2685          ----------------
2686          -- Set_Atomic --
2687          ----------------
2688
2689          procedure Set_Atomic (E : Entity_Id) is
2690          begin
2691             Set_Is_Atomic (E);
2692
2693             if not Has_Alignment_Clause (E) then
2694                Set_Alignment (E, Uint_0);
2695             end if;
2696          end Set_Atomic;
2697
2698       --  Start of processing for Process_Atomic_Shared_Volatile
2699
2700       begin
2701          Check_Ada_83_Warning;
2702          Check_No_Identifiers;
2703          Check_Arg_Count (1);
2704          Check_Arg_Is_Local_Name (Arg1);
2705          E_Id := Get_Pragma_Arg (Arg1);
2706
2707          if Etype (E_Id) = Any_Type then
2708             return;
2709          end if;
2710
2711          E := Entity (E_Id);
2712          D := Declaration_Node (E);
2713          K := Nkind (D);
2714
2715          --  Check duplicate before we chain ourselves!
2716
2717          Check_Duplicate_Pragma (E);
2718
2719          --  Now check appropriateness of the entity
2720
2721          if Is_Type (E) then
2722             if Rep_Item_Too_Early (E, N)
2723                  or else
2724                Rep_Item_Too_Late (E, N)
2725             then
2726                return;
2727             else
2728                Check_First_Subtype (Arg1);
2729             end if;
2730
2731             if Prag_Id /= Pragma_Volatile then
2732                Set_Atomic (E);
2733                Set_Atomic (Underlying_Type (E));
2734                Set_Atomic (Base_Type (E));
2735             end if;
2736
2737             --  Attribute belongs on the base type. If the view of the type is
2738             --  currently private, it also belongs on the underlying type.
2739
2740             Set_Is_Volatile (Base_Type (E));
2741             Set_Is_Volatile (Underlying_Type (E));
2742
2743             Set_Treat_As_Volatile (E);
2744             Set_Treat_As_Volatile (Underlying_Type (E));
2745
2746          elsif K = N_Object_Declaration
2747            or else (K = N_Component_Declaration
2748                      and then Original_Record_Component (E) = E)
2749          then
2750             if Rep_Item_Too_Late (E, N) then
2751                return;
2752             end if;
2753
2754             if Prag_Id /= Pragma_Volatile then
2755                Set_Is_Atomic (E);
2756
2757                --  If the object declaration has an explicit initialization, a
2758                --  temporary may have to be created to hold the expression, to
2759                --  ensure that access to the object remain atomic.
2760
2761                if Nkind (Parent (E)) = N_Object_Declaration
2762                  and then Present (Expression (Parent (E)))
2763                then
2764                   Set_Has_Delayed_Freeze (E);
2765                end if;
2766
2767                --  An interesting improvement here. If an object of type X is
2768                --  declared atomic, and the type X is not atomic, that's a
2769                --  pity, since it may not have appropriate alignment etc. We
2770                --  can rescue this in the special case where the object and
2771                --  type are in the same unit by just setting the type as
2772                --  atomic, so that the back end will process it as atomic.
2773
2774                Utyp := Underlying_Type (Etype (E));
2775
2776                if Present (Utyp)
2777                  and then Sloc (E) > No_Location
2778                  and then Sloc (Utyp) > No_Location
2779                  and then
2780                    Get_Source_File_Index (Sloc (E)) =
2781                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2782                then
2783                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2784                end if;
2785             end if;
2786
2787             Set_Is_Volatile (E);
2788             Set_Treat_As_Volatile (E);
2789
2790          else
2791             Error_Pragma_Arg
2792               ("inappropriate entity for pragma%", Arg1);
2793          end if;
2794       end Process_Atomic_Shared_Volatile;
2795
2796       -------------------------------------------
2797       -- Process_Compile_Time_Warning_Or_Error --
2798       -------------------------------------------
2799
2800       procedure Process_Compile_Time_Warning_Or_Error is
2801          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2802
2803       begin
2804          Check_Arg_Count (2);
2805          Check_No_Identifiers;
2806          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2807          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2808
2809          if Compile_Time_Known_Value (Arg1x) then
2810             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2811                declare
2812                   Str   : constant String_Id :=
2813                             Strval (Get_Pragma_Arg (Arg2));
2814                   Len   : constant Int := String_Length (Str);
2815                   Cont  : Boolean;
2816                   Ptr   : Nat;
2817                   CC    : Char_Code;
2818                   C     : Character;
2819                   Cent  : constant Entity_Id :=
2820                             Cunit_Entity (Current_Sem_Unit);
2821
2822                   Force : constant Boolean :=
2823                             Prag_Id = Pragma_Compile_Time_Warning
2824                               and then
2825                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2826                               and then (Ekind (Cent) /= E_Package
2827                                           or else not In_Private_Part (Cent));
2828                   --  Set True if this is the warning case, and we are in the
2829                   --  visible part of a package spec, or in a subprogram spec,
2830                   --  in which case we want to force the client to see the
2831                   --  warning, even though it is not in the main unit.
2832
2833                begin
2834                   --  Loop through segments of message separated by line feeds.
2835                   --  We output these segments as separate messages with
2836                   --  continuation marks for all but the first.
2837
2838                   Cont := False;
2839                   Ptr := 1;
2840                   loop
2841                      Error_Msg_Strlen := 0;
2842
2843                      --  Loop to copy characters from argument to error message
2844                      --  string buffer.
2845
2846                      loop
2847                         exit when Ptr > Len;
2848                         CC := Get_String_Char (Str, Ptr);
2849                         Ptr := Ptr + 1;
2850
2851                         --  Ignore wide chars ??? else store character
2852
2853                         if In_Character_Range (CC) then
2854                            C := Get_Character (CC);
2855                            exit when C = ASCII.LF;
2856                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
2857                            Error_Msg_String (Error_Msg_Strlen) := C;
2858                         end if;
2859                      end loop;
2860
2861                      --  Here with one line ready to go
2862
2863                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2864
2865                      --  If this is a warning in a spec, then we want clients
2866                      --  to see the warning, so mark the message with the
2867                      --  special sequence !! to force the warning. In the case
2868                      --  of a package spec, we do not force this if we are in
2869                      --  the private part of the spec.
2870
2871                      if Force then
2872                         if Cont = False then
2873                            Error_Msg_N ("<~!!", Arg1);
2874                            Cont := True;
2875                         else
2876                            Error_Msg_N ("\<~!!", Arg1);
2877                         end if;
2878
2879                      --  Error, rather than warning, or in a body, so we do not
2880                      --  need to force visibility for client (error will be
2881                      --  output in any case, and this is the situation in which
2882                      --  we do not want a client to get a warning, since the
2883                      --  warning is in the body or the spec private part).
2884
2885                      else
2886                         if Cont = False then
2887                            Error_Msg_N ("<~", Arg1);
2888                            Cont := True;
2889                         else
2890                            Error_Msg_N ("\<~", Arg1);
2891                         end if;
2892                      end if;
2893
2894                      exit when Ptr > Len;
2895                   end loop;
2896                end;
2897             end if;
2898          end if;
2899       end Process_Compile_Time_Warning_Or_Error;
2900
2901       ------------------------
2902       -- Process_Convention --
2903       ------------------------
2904
2905       procedure Process_Convention
2906         (C   : out Convention_Id;
2907          Ent : out Entity_Id)
2908       is
2909          Id        : Node_Id;
2910          E         : Entity_Id;
2911          E1        : Entity_Id;
2912          Cname     : Name_Id;
2913          Comp_Unit : Unit_Number_Type;
2914
2915          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2916          --  Called if we have more than one Export/Import/Convention pragma.
2917          --  This is generally illegal, but we have a special case of allowing
2918          --  Import and Interface to coexist if they specify the convention in
2919          --  a consistent manner. We are allowed to do this, since Interface is
2920          --  an implementation defined pragma, and we choose to do it since we
2921          --  know Rational allows this combination. S is the entity id of the
2922          --  subprogram in question. This procedure also sets the special flag
2923          --  Import_Interface_Present in both pragmas in the case where we do
2924          --  have matching Import and Interface pragmas.
2925
2926          procedure Set_Convention_From_Pragma (E : Entity_Id);
2927          --  Set convention in entity E, and also flag that the entity has a
2928          --  convention pragma. If entity is for a private or incomplete type,
2929          --  also set convention and flag on underlying type. This procedure
2930          --  also deals with the special case of C_Pass_By_Copy convention.
2931
2932          -------------------------------
2933          -- Diagnose_Multiple_Pragmas --
2934          -------------------------------
2935
2936          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2937             Pdec : constant Node_Id := Declaration_Node (S);
2938             Decl : Node_Id;
2939             Err  : Boolean;
2940
2941             function Same_Convention (Decl : Node_Id) return Boolean;
2942             --  Decl is a pragma node. This function returns True if this
2943             --  pragma has a first argument that is an identifier with a
2944             --  Chars field corresponding to the Convention_Id C.
2945
2946             function Same_Name (Decl : Node_Id) return Boolean;
2947             --  Decl is a pragma node. This function returns True if this
2948             --  pragma has a second argument that is an identifier with a
2949             --  Chars field that matches the Chars of the current subprogram.
2950
2951             ---------------------
2952             -- Same_Convention --
2953             ---------------------
2954
2955             function Same_Convention (Decl : Node_Id) return Boolean is
2956                Arg1 : constant Node_Id :=
2957                         First (Pragma_Argument_Associations (Decl));
2958
2959             begin
2960                if Present (Arg1) then
2961                   declare
2962                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2963                   begin
2964                      if Nkind (Arg) = N_Identifier
2965                        and then Is_Convention_Name (Chars (Arg))
2966                        and then Get_Convention_Id (Chars (Arg)) = C
2967                      then
2968                         return True;
2969                      end if;
2970                   end;
2971                end if;
2972
2973                return False;
2974             end Same_Convention;
2975
2976             ---------------
2977             -- Same_Name --
2978             ---------------
2979
2980             function Same_Name (Decl : Node_Id) return Boolean is
2981                Arg1 : constant Node_Id :=
2982                         First (Pragma_Argument_Associations (Decl));
2983                Arg2 : Node_Id;
2984
2985             begin
2986                if No (Arg1) then
2987                   return False;
2988                end if;
2989
2990                Arg2 := Next (Arg1);
2991
2992                if No (Arg2) then
2993                   return False;
2994                end if;
2995
2996                declare
2997                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
2998                begin
2999                   if Nkind (Arg) = N_Identifier
3000                     and then Chars (Arg) = Chars (S)
3001                   then
3002                      return True;
3003                   end if;
3004                end;
3005
3006                return False;
3007             end Same_Name;
3008
3009          --  Start of processing for Diagnose_Multiple_Pragmas
3010
3011          begin
3012             Err := True;
3013
3014             --  Definitely give message if we have Convention/Export here
3015
3016             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3017                null;
3018
3019                --  If we have an Import or Export, scan back from pragma to
3020                --  find any previous pragma applying to the same procedure.
3021                --  The scan will be terminated by the start of the list, or
3022                --  hitting the subprogram declaration. This won't allow one
3023                --  pragma to appear in the public part and one in the private
3024                --  part, but that seems very unlikely in practice.
3025
3026             else
3027                Decl := Prev (N);
3028                while Present (Decl) and then Decl /= Pdec loop
3029
3030                   --  Look for pragma with same name as us
3031
3032                   if Nkind (Decl) = N_Pragma
3033                     and then Same_Name (Decl)
3034                   then
3035                      --  Give error if same as our pragma or Export/Convention
3036
3037                      if Pragma_Name (Decl) = Name_Export
3038                           or else
3039                         Pragma_Name (Decl) = Name_Convention
3040                           or else
3041                         Pragma_Name (Decl) = Pragma_Name (N)
3042                      then
3043                         exit;
3044
3045                      --  Case of Import/Interface or the other way round
3046
3047                      elsif Pragma_Name (Decl) = Name_Interface
3048                              or else
3049                            Pragma_Name (Decl) = Name_Import
3050                      then
3051                         --  Here we know that we have Import and Interface. It
3052                         --  doesn't matter which way round they are. See if
3053                         --  they specify the same convention. If so, all OK,
3054                         --  and set special flags to stop other messages
3055
3056                         if Same_Convention (Decl) then
3057                            Set_Import_Interface_Present (N);
3058                            Set_Import_Interface_Present (Decl);
3059                            Err := False;
3060
3061                         --  If different conventions, special message
3062
3063                         else
3064                            Error_Msg_Sloc := Sloc (Decl);
3065                            Error_Pragma_Arg
3066                              ("convention differs from that given#", Arg1);
3067                            return;
3068                         end if;
3069                      end if;
3070                   end if;
3071
3072                   Next (Decl);
3073                end loop;
3074             end if;
3075
3076             --  Give message if needed if we fall through those tests
3077
3078             if Err then
3079                Error_Pragma_Arg
3080                  ("at most one Convention/Export/Import pragma is allowed",
3081                   Arg2);
3082             end if;
3083          end Diagnose_Multiple_Pragmas;
3084
3085          --------------------------------
3086          -- Set_Convention_From_Pragma --
3087          --------------------------------
3088
3089          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3090          begin
3091             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3092             --  for an overridden dispatching operation. Technically this is
3093             --  an amendment and should only be done in Ada 2005 mode. However,
3094             --  this is clearly a mistake, since the problem that is addressed
3095             --  by this AI is that there is a clear gap in the RM!
3096
3097             if Is_Dispatching_Operation (E)
3098               and then Present (Overridden_Operation (E))
3099               and then C /= Convention (Overridden_Operation (E))
3100             then
3101                Error_Pragma_Arg
3102                  ("cannot change convention for " &
3103                   "overridden dispatching operation",
3104                   Arg1);
3105             end if;
3106
3107             --  Set the convention
3108
3109             Set_Convention (E, C);
3110             Set_Has_Convention_Pragma (E);
3111
3112             if Is_Incomplete_Or_Private_Type (E)
3113               and then Present (Underlying_Type (E))
3114             then
3115                Set_Convention            (Underlying_Type (E), C);
3116                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3117             end if;
3118
3119             --  A class-wide type should inherit the convention of the specific
3120             --  root type (although this isn't specified clearly by the RM).
3121
3122             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3123                Set_Convention (Class_Wide_Type (E), C);
3124             end if;
3125
3126             --  If the entity is a record type, then check for special case of
3127             --  C_Pass_By_Copy, which is treated the same as C except that the
3128             --  special record flag is set. This convention is only permitted
3129             --  on record types (see AI95-00131).
3130
3131             if Cname = Name_C_Pass_By_Copy then
3132                if Is_Record_Type (E) then
3133                   Set_C_Pass_By_Copy (Base_Type (E));
3134                elsif Is_Incomplete_Or_Private_Type (E)
3135                  and then Is_Record_Type (Underlying_Type (E))
3136                then
3137                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3138                else
3139                   Error_Pragma_Arg
3140                     ("C_Pass_By_Copy convention allowed only for record type",
3141                      Arg2);
3142                end if;
3143             end if;
3144
3145             --  If the entity is a derived boolean type, check for the special
3146             --  case of convention C, C++, or Fortran, where we consider any
3147             --  nonzero value to represent true.
3148
3149             if Is_Discrete_Type (E)
3150               and then Root_Type (Etype (E)) = Standard_Boolean
3151               and then
3152                 (C = Convention_C
3153                    or else
3154                  C = Convention_CPP
3155                    or else
3156                  C = Convention_Fortran)
3157             then
3158                Set_Nonzero_Is_True (Base_Type (E));
3159             end if;
3160          end Set_Convention_From_Pragma;
3161
3162       --  Start of processing for Process_Convention
3163
3164       begin
3165          Check_At_Least_N_Arguments (2);
3166          Check_Optional_Identifier (Arg1, Name_Convention);
3167          Check_Arg_Is_Identifier (Arg1);
3168          Cname := Chars (Get_Pragma_Arg (Arg1));
3169
3170          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3171          --  tested again below to set the critical flag).
3172
3173          if Cname = Name_C_Pass_By_Copy then
3174             C := Convention_C;
3175
3176          --  Otherwise we must have something in the standard convention list
3177
3178          elsif Is_Convention_Name (Cname) then
3179             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3180
3181          --  In DEC VMS, it seems that there is an undocumented feature that
3182          --  any unrecognized convention is treated as the default, which for
3183          --  us is convention C. It does not seem so terrible to do this
3184          --  unconditionally, silently in the VMS case, and with a warning
3185          --  in the non-VMS case.
3186
3187          else
3188             if Warn_On_Export_Import and not OpenVMS_On_Target then
3189                Error_Msg_N
3190                  ("?unrecognized convention name, C assumed",
3191                   Get_Pragma_Arg (Arg1));
3192             end if;
3193
3194             C := Convention_C;
3195          end if;
3196
3197          Check_Optional_Identifier (Arg2, Name_Entity);
3198          Check_Arg_Is_Local_Name (Arg2);
3199
3200          Id := Get_Pragma_Arg (Arg2);
3201          Analyze (Id);
3202
3203          if not Is_Entity_Name (Id) then
3204             Error_Pragma_Arg ("entity name required", Arg2);
3205          end if;
3206
3207          E := Entity (Id);
3208
3209          --  Set entity to return
3210
3211          Ent := E;
3212
3213          --  Ada_Pass_By_Copy special checking
3214
3215          if C = Convention_Ada_Pass_By_Copy then
3216             if not Is_First_Subtype (E) then
3217                Error_Pragma_Arg
3218                  ("convention `Ada_Pass_By_Copy` only "
3219                   & "allowed for types", Arg2);
3220             end if;
3221
3222             if Is_By_Reference_Type (E) then
3223                Error_Pragma_Arg
3224                  ("convention `Ada_Pass_By_Copy` not allowed for "
3225                   & "by-reference type", Arg1);
3226             end if;
3227          end if;
3228
3229          --  Ada_Pass_By_Reference special checking
3230
3231          if C = Convention_Ada_Pass_By_Reference then
3232             if not Is_First_Subtype (E) then
3233                Error_Pragma_Arg
3234                  ("convention `Ada_Pass_By_Reference` only "
3235                   & "allowed for types", Arg2);
3236             end if;
3237
3238             if Is_By_Copy_Type (E) then
3239                Error_Pragma_Arg
3240                  ("convention `Ada_Pass_By_Reference` not allowed for "
3241                   & "by-copy type", Arg1);
3242             end if;
3243          end if;
3244
3245          --  Go to renamed subprogram if present, since convention applies to
3246          --  the actual renamed entity, not to the renaming entity. If the
3247          --  subprogram is inherited, go to parent subprogram.
3248
3249          if Is_Subprogram (E)
3250            and then Present (Alias (E))
3251          then
3252             if Nkind (Parent (Declaration_Node (E))) =
3253                                        N_Subprogram_Renaming_Declaration
3254             then
3255                if Scope (E) /= Scope (Alias (E)) then
3256                   Error_Pragma_Ref
3257                     ("cannot apply pragma% to non-local entity&#", E);
3258                end if;
3259
3260                E := Alias (E);
3261
3262             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3263                                         N_Private_Extension_Declaration)
3264               and then Scope (E) = Scope (Alias (E))
3265             then
3266                E := Alias (E);
3267
3268                --  Return the parent subprogram the entity was inherited from
3269
3270                Ent := E;
3271             end if;
3272          end if;
3273
3274          --  Check that we are not applying this to a specless body
3275
3276          if Is_Subprogram (E)
3277            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3278          then
3279             Error_Pragma
3280               ("pragma% requires separate spec and must come before body");
3281          end if;
3282
3283          --  Check that we are not applying this to a named constant
3284
3285          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3286             Error_Msg_Name_1 := Pname;
3287             Error_Msg_N
3288               ("cannot apply pragma% to named constant!",
3289                Get_Pragma_Arg (Arg2));
3290             Error_Pragma_Arg
3291               ("\supply appropriate type for&!", Arg2);
3292          end if;
3293
3294          if Ekind (E) = E_Enumeration_Literal then
3295             Error_Pragma ("enumeration literal not allowed for pragma%");
3296          end if;
3297
3298          --  Check for rep item appearing too early or too late
3299
3300          if Etype (E) = Any_Type
3301            or else Rep_Item_Too_Early (E, N)
3302          then
3303             raise Pragma_Exit;
3304
3305          elsif Present (Underlying_Type (E)) then
3306             E := Underlying_Type (E);
3307          end if;
3308
3309          if Rep_Item_Too_Late (E, N) then
3310             raise Pragma_Exit;
3311          end if;
3312
3313          if Has_Convention_Pragma (E) then
3314             Diagnose_Multiple_Pragmas (E);
3315
3316          elsif Convention (E) = Convention_Protected
3317            or else Ekind (Scope (E)) = E_Protected_Type
3318          then
3319             Error_Pragma_Arg
3320               ("a protected operation cannot be given a different convention",
3321                 Arg2);
3322          end if;
3323
3324          --  For Intrinsic, a subprogram is required
3325
3326          if C = Convention_Intrinsic
3327            and then not Is_Subprogram (E)
3328            and then not Is_Generic_Subprogram (E)
3329          then
3330             Error_Pragma_Arg
3331               ("second argument of pragma% must be a subprogram", Arg2);
3332          end if;
3333
3334          --  For Stdcall, a subprogram, variable or subprogram type is required
3335
3336          if C = Convention_Stdcall
3337            and then not Is_Subprogram (E)
3338            and then not Is_Generic_Subprogram (E)
3339            and then Ekind (E) /= E_Variable
3340            and then not
3341              (Is_Access_Type (E)
3342                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3343          then
3344             Error_Pragma_Arg
3345               ("second argument of pragma% must be subprogram (type)",
3346                Arg2);
3347          end if;
3348
3349          if not Is_Subprogram (E)
3350            and then not Is_Generic_Subprogram (E)
3351          then
3352             Set_Convention_From_Pragma (E);
3353
3354             if Is_Type (E) then
3355                Check_First_Subtype (Arg2);
3356                Set_Convention_From_Pragma (Base_Type (E));
3357
3358                --  For subprograms, we must set the convention on the
3359                --  internally generated directly designated type as well.
3360
3361                if Ekind (E) = E_Access_Subprogram_Type then
3362                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3363                end if;
3364             end if;
3365
3366          --  For the subprogram case, set proper convention for all homonyms
3367          --  in same scope and the same declarative part, i.e. the same
3368          --  compilation unit.
3369
3370          else
3371             Comp_Unit := Get_Source_Unit (E);
3372             Set_Convention_From_Pragma (E);
3373
3374             --  Treat a pragma Import as an implicit body, for GPS use
3375
3376             if Prag_Id = Pragma_Import then
3377                Generate_Reference (E, Id, 'b');
3378             end if;
3379
3380             --  Loop through the homonyms of the pragma argument's entity
3381
3382             E1 := Ent;
3383             loop
3384                E1 := Homonym (E1);
3385                exit when No (E1) or else Scope (E1) /= Current_Scope;
3386
3387                --  Do not set the pragma on inherited operations or on formal
3388                --  subprograms.
3389
3390                if Comes_From_Source (E1)
3391                  and then Comp_Unit = Get_Source_Unit (E1)
3392                  and then not Is_Formal_Subprogram (E1)
3393                  and then Nkind (Original_Node (Parent (E1))) /=
3394                                                     N_Full_Type_Declaration
3395                then
3396                   if Present (Alias (E1))
3397                     and then Scope (E1) /= Scope (Alias (E1))
3398                   then
3399                      Error_Pragma_Ref
3400                        ("cannot apply pragma% to non-local entity& declared#",
3401                         E1);
3402                   end if;
3403
3404                   Set_Convention_From_Pragma (E1);
3405
3406                   if Prag_Id = Pragma_Import then
3407                      Generate_Reference (E1, Id, 'b');
3408                   end if;
3409                end if;
3410
3411                --  For aspect case, do NOT apply to homonyms
3412
3413                exit when From_Aspect_Specification (N);
3414             end loop;
3415          end if;
3416       end Process_Convention;
3417
3418       -----------------------------------------------------
3419       -- Process_Extended_Import_Export_Exception_Pragma --
3420       -----------------------------------------------------
3421
3422       procedure Process_Extended_Import_Export_Exception_Pragma
3423         (Arg_Internal : Node_Id;
3424          Arg_External : Node_Id;
3425          Arg_Form     : Node_Id;
3426          Arg_Code     : Node_Id)
3427       is
3428          Def_Id   : Entity_Id;
3429          Code_Val : Uint;
3430
3431       begin
3432          if not OpenVMS_On_Target then
3433             Error_Pragma
3434               ("?pragma% ignored (applies only to Open'V'M'S)");
3435          end if;
3436
3437          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3438          Def_Id := Entity (Arg_Internal);
3439
3440          if Ekind (Def_Id) /= E_Exception then
3441             Error_Pragma_Arg
3442               ("pragma% must refer to declared exception", Arg_Internal);
3443          end if;
3444
3445          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3446
3447          if Present (Arg_Form) then
3448             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3449          end if;
3450
3451          if Present (Arg_Form)
3452            and then Chars (Arg_Form) = Name_Ada
3453          then
3454             null;
3455          else
3456             Set_Is_VMS_Exception (Def_Id);
3457             Set_Exception_Code (Def_Id, No_Uint);
3458          end if;
3459
3460          if Present (Arg_Code) then
3461             if not Is_VMS_Exception (Def_Id) then
3462                Error_Pragma_Arg
3463                  ("Code option for pragma% not allowed for Ada case",
3464                   Arg_Code);
3465             end if;
3466
3467             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3468             Code_Val := Expr_Value (Arg_Code);
3469
3470             if not UI_Is_In_Int_Range (Code_Val) then
3471                Error_Pragma_Arg
3472                  ("Code option for pragma% must be in 32-bit range",
3473                   Arg_Code);
3474
3475             else
3476                Set_Exception_Code (Def_Id, Code_Val);
3477             end if;
3478          end if;
3479       end Process_Extended_Import_Export_Exception_Pragma;
3480
3481       -------------------------------------------------
3482       -- Process_Extended_Import_Export_Internal_Arg --
3483       -------------------------------------------------
3484
3485       procedure Process_Extended_Import_Export_Internal_Arg
3486         (Arg_Internal : Node_Id := Empty)
3487       is
3488       begin
3489          if No (Arg_Internal) then
3490             Error_Pragma ("Internal parameter required for pragma%");
3491          end if;
3492
3493          if Nkind (Arg_Internal) = N_Identifier then
3494             null;
3495
3496          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3497            and then (Prag_Id = Pragma_Import_Function
3498                        or else
3499                      Prag_Id = Pragma_Export_Function)
3500          then
3501             null;
3502
3503          else
3504             Error_Pragma_Arg
3505               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3506          end if;
3507
3508          Check_Arg_Is_Local_Name (Arg_Internal);
3509       end Process_Extended_Import_Export_Internal_Arg;
3510
3511       --------------------------------------------------
3512       -- Process_Extended_Import_Export_Object_Pragma --
3513       --------------------------------------------------
3514
3515       procedure Process_Extended_Import_Export_Object_Pragma
3516         (Arg_Internal : Node_Id;
3517          Arg_External : Node_Id;
3518          Arg_Size     : Node_Id)
3519       is
3520          Def_Id : Entity_Id;
3521
3522       begin
3523          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3524          Def_Id := Entity (Arg_Internal);
3525
3526          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3527             Error_Pragma_Arg
3528               ("pragma% must designate an object", Arg_Internal);
3529          end if;
3530
3531          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3532               or else
3533             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3534          then
3535             Error_Pragma_Arg
3536               ("previous Common/Psect_Object applies, pragma % not permitted",
3537                Arg_Internal);
3538          end if;
3539
3540          if Rep_Item_Too_Late (Def_Id, N) then
3541             raise Pragma_Exit;
3542          end if;
3543
3544          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3545
3546          if Present (Arg_Size) then
3547             Check_Arg_Is_External_Name (Arg_Size);
3548          end if;
3549
3550          --  Export_Object case
3551
3552          if Prag_Id = Pragma_Export_Object then
3553             if not Is_Library_Level_Entity (Def_Id) then
3554                Error_Pragma_Arg
3555                  ("argument for pragma% must be library level entity",
3556                   Arg_Internal);
3557             end if;
3558
3559             if Ekind (Current_Scope) = E_Generic_Package then
3560                Error_Pragma ("pragma& cannot appear in a generic unit");
3561             end if;
3562
3563             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3564                Error_Pragma_Arg
3565                  ("exported object must have compile time known size",
3566                   Arg_Internal);
3567             end if;
3568
3569             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3570                Error_Msg_N ("?duplicate Export_Object pragma", N);
3571             else
3572                Set_Exported (Def_Id, Arg_Internal);
3573             end if;
3574
3575          --  Import_Object case
3576
3577          else
3578             if Is_Concurrent_Type (Etype (Def_Id)) then
3579                Error_Pragma_Arg
3580                  ("cannot use pragma% for task/protected object",
3581                   Arg_Internal);
3582             end if;
3583
3584             if Ekind (Def_Id) = E_Constant then
3585                Error_Pragma_Arg
3586                  ("cannot import a constant", Arg_Internal);
3587             end if;
3588
3589             if Warn_On_Export_Import
3590               and then Has_Discriminants (Etype (Def_Id))
3591             then
3592                Error_Msg_N
3593                  ("imported value must be initialized?", Arg_Internal);
3594             end if;
3595
3596             if Warn_On_Export_Import
3597               and then Is_Access_Type (Etype (Def_Id))
3598             then
3599                Error_Pragma_Arg
3600                  ("cannot import object of an access type?", Arg_Internal);
3601             end if;
3602
3603             if Warn_On_Export_Import
3604               and then Is_Imported (Def_Id)
3605             then
3606                Error_Msg_N
3607                  ("?duplicate Import_Object pragma", N);
3608
3609             --  Check for explicit initialization present. Note that an
3610             --  initialization generated by the code generator, e.g. for an
3611             --  access type, does not count here.
3612
3613             elsif Present (Expression (Parent (Def_Id)))
3614                and then
3615                  Comes_From_Source
3616                    (Original_Node (Expression (Parent (Def_Id))))
3617             then
3618                Error_Msg_Sloc := Sloc (Def_Id);
3619                Error_Pragma_Arg
3620                  ("imported entities cannot be initialized (RM B.1(24))",
3621                   "\no initialization allowed for & declared#", Arg1);
3622             else
3623                Set_Imported (Def_Id);
3624                Note_Possible_Modification (Arg_Internal, Sure => False);
3625             end if;
3626          end if;
3627       end Process_Extended_Import_Export_Object_Pragma;
3628
3629       ------------------------------------------------------
3630       -- Process_Extended_Import_Export_Subprogram_Pragma --
3631       ------------------------------------------------------
3632
3633       procedure Process_Extended_Import_Export_Subprogram_Pragma
3634         (Arg_Internal                 : Node_Id;
3635          Arg_External                 : Node_Id;
3636          Arg_Parameter_Types          : Node_Id;
3637          Arg_Result_Type              : Node_Id := Empty;
3638          Arg_Mechanism                : Node_Id;
3639          Arg_Result_Mechanism         : Node_Id := Empty;
3640          Arg_First_Optional_Parameter : Node_Id := Empty)
3641       is
3642          Ent       : Entity_Id;
3643          Def_Id    : Entity_Id;
3644          Hom_Id    : Entity_Id;
3645          Formal    : Entity_Id;
3646          Ambiguous : Boolean;
3647          Match     : Boolean;
3648          Dval      : Node_Id;
3649
3650          function Same_Base_Type
3651           (Ptype  : Node_Id;
3652            Formal : Entity_Id) return Boolean;
3653          --  Determines if Ptype references the type of Formal. Note that only
3654          --  the base types need to match according to the spec. Ptype here is
3655          --  the argument from the pragma, which is either a type name, or an
3656          --  access attribute.
3657
3658          --------------------
3659          -- Same_Base_Type --
3660          --------------------
3661
3662          function Same_Base_Type
3663            (Ptype  : Node_Id;
3664             Formal : Entity_Id) return Boolean
3665          is
3666             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3667             Pref : Node_Id;
3668
3669          begin
3670             --  Case where pragma argument is typ'Access
3671
3672             if Nkind (Ptype) = N_Attribute_Reference
3673               and then Attribute_Name (Ptype) = Name_Access
3674             then
3675                Pref := Prefix (Ptype);
3676                Find_Type (Pref);
3677
3678                if not Is_Entity_Name (Pref)
3679                  or else Entity (Pref) = Any_Type
3680                then
3681                   raise Pragma_Exit;
3682                end if;
3683
3684                --  We have a match if the corresponding argument is of an
3685                --  anonymous access type, and its designated type matches the
3686                --  type of the prefix of the access attribute
3687
3688                return Ekind (Ftyp) = E_Anonymous_Access_Type
3689                  and then Base_Type (Entity (Pref)) =
3690                             Base_Type (Etype (Designated_Type (Ftyp)));
3691
3692             --  Case where pragma argument is a type name
3693
3694             else
3695                Find_Type (Ptype);
3696
3697                if not Is_Entity_Name (Ptype)
3698                  or else Entity (Ptype) = Any_Type
3699                then
3700                   raise Pragma_Exit;
3701                end if;
3702
3703                --  We have a match if the corresponding argument is of the type
3704                --  given in the pragma (comparing base types)
3705
3706                return Base_Type (Entity (Ptype)) = Ftyp;
3707             end if;
3708          end Same_Base_Type;
3709
3710       --  Start of processing for
3711       --  Process_Extended_Import_Export_Subprogram_Pragma
3712
3713       begin
3714          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3715          Ent := Empty;
3716          Ambiguous := False;
3717
3718          --  Loop through homonyms (overloadings) of the entity
3719
3720          Hom_Id := Entity (Arg_Internal);
3721          while Present (Hom_Id) loop
3722             Def_Id := Get_Base_Subprogram (Hom_Id);
3723
3724             --  We need a subprogram in the current scope
3725
3726             if not Is_Subprogram (Def_Id)
3727               or else Scope (Def_Id) /= Current_Scope
3728             then
3729                null;
3730
3731             else
3732                Match := True;
3733
3734                --  Pragma cannot apply to subprogram body
3735
3736                if Is_Subprogram (Def_Id)
3737                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3738                                                              N_Subprogram_Body
3739                then
3740                   Error_Pragma
3741                     ("pragma% requires separate spec"
3742                       & " and must come before body");
3743                end if;
3744
3745                --  Test result type if given, note that the result type
3746                --  parameter can only be present for the function cases.
3747
3748                if Present (Arg_Result_Type)
3749                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3750                then
3751                   Match := False;
3752
3753                elsif Etype (Def_Id) /= Standard_Void_Type
3754                  and then
3755                    (Pname = Name_Export_Procedure
3756                       or else
3757                     Pname = Name_Import_Procedure)
3758                then
3759                   Match := False;
3760
3761                --  Test parameter types if given. Note that this parameter
3762                --  has not been analyzed (and must not be, since it is
3763                --  semantic nonsense), so we get it as the parser left it.
3764
3765                elsif Present (Arg_Parameter_Types) then
3766                   Check_Matching_Types : declare
3767                      Formal : Entity_Id;
3768                      Ptype  : Node_Id;
3769
3770                   begin
3771                      Formal := First_Formal (Def_Id);
3772
3773                      if Nkind (Arg_Parameter_Types) = N_Null then
3774                         if Present (Formal) then
3775                            Match := False;
3776                         end if;
3777
3778                      --  A list of one type, e.g. (List) is parsed as
3779                      --  a parenthesized expression.
3780
3781                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3782                        and then Paren_Count (Arg_Parameter_Types) = 1
3783                      then
3784                         if No (Formal)
3785                           or else Present (Next_Formal (Formal))
3786                         then
3787                            Match := False;
3788                         else
3789                            Match :=
3790                              Same_Base_Type (Arg_Parameter_Types, Formal);
3791                         end if;
3792
3793                      --  A list of more than one type is parsed as a aggregate
3794
3795                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3796                        and then Paren_Count (Arg_Parameter_Types) = 0
3797                      then
3798                         Ptype := First (Expressions (Arg_Parameter_Types));
3799                         while Present (Ptype) or else Present (Formal) loop
3800                            if No (Ptype)
3801                              or else No (Formal)
3802                              or else not Same_Base_Type (Ptype, Formal)
3803                            then
3804                               Match := False;
3805                               exit;
3806                            else
3807                               Next_Formal (Formal);
3808                               Next (Ptype);
3809                            end if;
3810                         end loop;
3811
3812                      --  Anything else is of the wrong form
3813
3814                      else
3815                         Error_Pragma_Arg
3816                           ("wrong form for Parameter_Types parameter",
3817                            Arg_Parameter_Types);
3818                      end if;
3819                   end Check_Matching_Types;
3820                end if;
3821
3822                --  Match is now False if the entry we found did not match
3823                --  either a supplied Parameter_Types or Result_Types argument
3824
3825                if Match then
3826                   if No (Ent) then
3827                      Ent := Def_Id;
3828
3829                   --  Ambiguous case, the flag Ambiguous shows if we already
3830                   --  detected this and output the initial messages.
3831
3832                   else
3833                      if not Ambiguous then
3834                         Ambiguous := True;
3835                         Error_Msg_Name_1 := Pname;
3836                         Error_Msg_N
3837                           ("pragma% does not uniquely identify subprogram!",
3838                            N);
3839                         Error_Msg_Sloc := Sloc (Ent);
3840                         Error_Msg_N ("matching subprogram #!", N);
3841                         Ent := Empty;
3842                      end if;
3843
3844                      Error_Msg_Sloc := Sloc (Def_Id);
3845                      Error_Msg_N ("matching subprogram #!", N);
3846                   end if;
3847                end if;
3848             end if;
3849
3850             Hom_Id := Homonym (Hom_Id);
3851          end loop;
3852
3853          --  See if we found an entry
3854
3855          if No (Ent) then
3856             if not Ambiguous then
3857                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3858                   Error_Pragma
3859                     ("pragma% cannot be given for generic subprogram");
3860                else
3861                   Error_Pragma
3862                     ("pragma% does not identify local subprogram");
3863                end if;
3864             end if;
3865
3866             return;
3867          end if;
3868
3869          --  Import pragmas must be for imported entities
3870
3871          if Prag_Id = Pragma_Import_Function
3872               or else
3873             Prag_Id = Pragma_Import_Procedure
3874               or else
3875             Prag_Id = Pragma_Import_Valued_Procedure
3876          then
3877             if not Is_Imported (Ent) then
3878                Error_Pragma
3879                  ("pragma Import or Interface must precede pragma%");
3880             end if;
3881
3882          --  Here we have the Export case which can set the entity as exported
3883
3884          --  But does not do so if the specified external name is null, since
3885          --  that is taken as a signal in DEC Ada 83 (with which we want to be
3886          --  compatible) to request no external name.
3887
3888          elsif Nkind (Arg_External) = N_String_Literal
3889            and then String_Length (Strval (Arg_External)) = 0
3890          then
3891             null;
3892
3893          --  In all other cases, set entity as exported
3894
3895          else
3896             Set_Exported (Ent, Arg_Internal);
3897          end if;
3898
3899          --  Special processing for Valued_Procedure cases
3900
3901          if Prag_Id = Pragma_Import_Valued_Procedure
3902            or else
3903             Prag_Id = Pragma_Export_Valued_Procedure
3904          then
3905             Formal := First_Formal (Ent);
3906
3907             if No (Formal) then
3908                Error_Pragma ("at least one parameter required for pragma%");
3909
3910             elsif Ekind (Formal) /= E_Out_Parameter then
3911                Error_Pragma ("first parameter must have mode out for pragma%");
3912
3913             else
3914                Set_Is_Valued_Procedure (Ent);
3915             end if;
3916          end if;
3917
3918          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3919
3920          --  Process Result_Mechanism argument if present. We have already
3921          --  checked that this is only allowed for the function case.
3922
3923          if Present (Arg_Result_Mechanism) then
3924             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3925          end if;
3926
3927          --  Process Mechanism parameter if present. Note that this parameter
3928          --  is not analyzed, and must not be analyzed since it is semantic
3929          --  nonsense, so we get it in exactly as the parser left it.
3930
3931          if Present (Arg_Mechanism) then
3932             declare
3933                Formal : Entity_Id;
3934                Massoc : Node_Id;
3935                Mname  : Node_Id;
3936                Choice : Node_Id;
3937
3938             begin
3939                --  A single mechanism association without a formal parameter
3940                --  name is parsed as a parenthesized expression. All other
3941                --  cases are parsed as aggregates, so we rewrite the single
3942                --  parameter case as an aggregate for consistency.
3943
3944                if Nkind (Arg_Mechanism) /= N_Aggregate
3945                  and then Paren_Count (Arg_Mechanism) = 1
3946                then
3947                   Rewrite (Arg_Mechanism,
3948                     Make_Aggregate (Sloc (Arg_Mechanism),
3949                       Expressions => New_List (
3950                         Relocate_Node (Arg_Mechanism))));
3951                end if;
3952
3953                --  Case of only mechanism name given, applies to all formals
3954
3955                if Nkind (Arg_Mechanism) /= N_Aggregate then
3956                   Formal := First_Formal (Ent);
3957                   while Present (Formal) loop
3958                      Set_Mechanism_Value (Formal, Arg_Mechanism);
3959                      Next_Formal (Formal);
3960                   end loop;
3961
3962                --  Case of list of mechanism associations given
3963
3964                else
3965                   if Null_Record_Present (Arg_Mechanism) then
3966                      Error_Pragma_Arg
3967                        ("inappropriate form for Mechanism parameter",
3968                         Arg_Mechanism);
3969                   end if;
3970
3971                   --  Deal with positional ones first
3972
3973                   Formal := First_Formal (Ent);
3974
3975                   if Present (Expressions (Arg_Mechanism)) then
3976                      Mname := First (Expressions (Arg_Mechanism));
3977                      while Present (Mname) loop
3978                         if No (Formal) then
3979                            Error_Pragma_Arg
3980                              ("too many mechanism associations", Mname);
3981                         end if;
3982
3983                         Set_Mechanism_Value (Formal, Mname);
3984                         Next_Formal (Formal);
3985                         Next (Mname);
3986                      end loop;
3987                   end if;
3988
3989                   --  Deal with named entries
3990
3991                   if Present (Component_Associations (Arg_Mechanism)) then
3992                      Massoc := First (Component_Associations (Arg_Mechanism));
3993                      while Present (Massoc) loop
3994                         Choice := First (Choices (Massoc));
3995
3996                         if Nkind (Choice) /= N_Identifier
3997                           or else Present (Next (Choice))
3998                         then
3999                            Error_Pragma_Arg
4000                              ("incorrect form for mechanism association",
4001                               Massoc);
4002                         end if;
4003
4004                         Formal := First_Formal (Ent);
4005                         loop
4006                            if No (Formal) then
4007                               Error_Pragma_Arg
4008                                 ("parameter name & not present", Choice);
4009                            end if;
4010
4011                            if Chars (Choice) = Chars (Formal) then
4012                               Set_Mechanism_Value
4013                                 (Formal, Expression (Massoc));
4014
4015                               --  Set entity on identifier (needed by ASIS)
4016
4017                               Set_Entity (Choice, Formal);
4018
4019                               exit;
4020                            end if;
4021
4022                            Next_Formal (Formal);
4023                         end loop;
4024
4025                         Next (Massoc);
4026                      end loop;
4027                   end if;
4028                end if;
4029             end;
4030          end if;
4031
4032          --  Process First_Optional_Parameter argument if present. We have
4033          --  already checked that this is only allowed for the Import case.
4034
4035          if Present (Arg_First_Optional_Parameter) then
4036             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4037                Error_Pragma_Arg
4038                  ("first optional parameter must be formal parameter name",
4039                   Arg_First_Optional_Parameter);
4040             end if;
4041
4042             Formal := First_Formal (Ent);
4043             loop
4044                if No (Formal) then
4045                   Error_Pragma_Arg
4046                     ("specified formal parameter& not found",
4047                      Arg_First_Optional_Parameter);
4048                end if;
4049
4050                exit when Chars (Formal) =
4051                          Chars (Arg_First_Optional_Parameter);
4052
4053                Next_Formal (Formal);
4054             end loop;
4055
4056             Set_First_Optional_Parameter (Ent, Formal);
4057
4058             --  Check specified and all remaining formals have right form
4059
4060             while Present (Formal) loop
4061                if Ekind (Formal) /= E_In_Parameter then
4062                   Error_Msg_NE
4063                     ("optional formal& is not of mode in!",
4064                      Arg_First_Optional_Parameter, Formal);
4065
4066                else
4067                   Dval := Default_Value (Formal);
4068
4069                   if No (Dval) then
4070                      Error_Msg_NE
4071                        ("optional formal& does not have default value!",
4072                         Arg_First_Optional_Parameter, Formal);
4073
4074                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4075                      null;
4076
4077                   else
4078                      Error_Msg_FE
4079                        ("default value for optional formal& is non-static!",
4080                         Arg_First_Optional_Parameter, Formal);
4081                   end if;
4082                end if;
4083
4084                Set_Is_Optional_Parameter (Formal);
4085                Next_Formal (Formal);
4086             end loop;
4087          end if;
4088       end Process_Extended_Import_Export_Subprogram_Pragma;
4089
4090       --------------------------
4091       -- Process_Generic_List --
4092       --------------------------
4093
4094       procedure Process_Generic_List is
4095          Arg : Node_Id;
4096          Exp : Node_Id;
4097
4098       begin
4099          Check_No_Identifiers;
4100          Check_At_Least_N_Arguments (1);
4101
4102          Arg := Arg1;
4103          while Present (Arg) loop
4104             Exp := Get_Pragma_Arg (Arg);
4105             Analyze (Exp);
4106
4107             if not Is_Entity_Name (Exp)
4108               or else
4109                 (not Is_Generic_Instance (Entity (Exp))
4110                   and then
4111                  not Is_Generic_Unit (Entity (Exp)))
4112             then
4113                Error_Pragma_Arg
4114                  ("pragma% argument must be name of generic unit/instance",
4115                   Arg);
4116             end if;
4117
4118             Next (Arg);
4119          end loop;
4120       end Process_Generic_List;
4121
4122       ------------------------------------
4123       -- Process_Import_Predefined_Type --
4124       ------------------------------------
4125
4126       procedure Process_Import_Predefined_Type is
4127          Loc  : constant Source_Ptr := Sloc (N);
4128          Elmt : Elmt_Id;
4129          Ftyp : Node_Id := Empty;
4130          Decl : Node_Id;
4131          Def  : Node_Id;
4132          Nam  : Name_Id;
4133
4134       begin
4135          String_To_Name_Buffer (Strval (Expression (Arg3)));
4136          Nam := Name_Find;
4137
4138          Elmt := First_Elmt (Predefined_Float_Types);
4139          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4140             Next_Elmt (Elmt);
4141          end loop;
4142
4143          Ftyp := Node (Elmt);
4144
4145          if Present (Ftyp) then
4146
4147             --  Don't build a derived type declaration, because predefined C
4148             --  types have no declaration anywhere, so cannot really be named.
4149             --  Instead build a full type declaration, starting with an
4150             --  appropriate type definition is built
4151
4152             if Is_Floating_Point_Type (Ftyp) then
4153                Def := Make_Floating_Point_Definition (Loc,
4154                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4155                  Make_Real_Range_Specification (Loc,
4156                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4157                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4158
4159             --  Should never have a predefined type we cannot handle
4160
4161             else
4162                raise Program_Error;
4163             end if;
4164
4165             --  Build and insert a Full_Type_Declaration, which will be
4166             --  analyzed as soon as this list entry has been analyzed.
4167
4168             Decl := Make_Full_Type_Declaration (Loc,
4169               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4170               Type_Definition => Def);
4171
4172             Insert_After (N, Decl);
4173             Mark_Rewrite_Insertion (Decl);
4174
4175          else
4176             Error_Pragma_Arg ("no matching type found for pragma%",
4177             Arg2);
4178          end if;
4179       end Process_Import_Predefined_Type;
4180
4181       ---------------------------------
4182       -- Process_Import_Or_Interface --
4183       ---------------------------------
4184
4185       procedure Process_Import_Or_Interface is
4186          C      : Convention_Id;
4187          Def_Id : Entity_Id;
4188          Hom_Id : Entity_Id;
4189
4190       begin
4191          Process_Convention (C, Def_Id);
4192          Kill_Size_Check_Code (Def_Id);
4193          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4194
4195          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4196
4197             --  We do not permit Import to apply to a renaming declaration
4198
4199             if Present (Renamed_Object (Def_Id)) then
4200                Error_Pragma_Arg
4201                  ("pragma% not allowed for object renaming", Arg2);
4202
4203             --  User initialization is not allowed for imported object, but
4204             --  the object declaration may contain a default initialization,
4205             --  that will be discarded. Note that an explicit initialization
4206             --  only counts if it comes from source, otherwise it is simply
4207             --  the code generator making an implicit initialization explicit.
4208
4209             elsif Present (Expression (Parent (Def_Id)))
4210               and then Comes_From_Source (Expression (Parent (Def_Id)))
4211             then
4212                Error_Msg_Sloc := Sloc (Def_Id);
4213                Error_Pragma_Arg
4214                  ("no initialization allowed for declaration of& #",
4215                   "\imported entities cannot be initialized (RM B.1(24))",
4216                   Arg2);
4217
4218             else
4219                Set_Imported (Def_Id);
4220                Process_Interface_Name (Def_Id, Arg3, Arg4);
4221
4222                --  Note that we do not set Is_Public here. That's because we
4223                --  only want to set it if there is no address clause, and we
4224                --  don't know that yet, so we delay that processing till
4225                --  freeze time.
4226
4227                --  pragma Import completes deferred constants
4228
4229                if Ekind (Def_Id) = E_Constant then
4230                   Set_Has_Completion (Def_Id);
4231                end if;
4232
4233                --  It is not possible to import a constant of an unconstrained
4234                --  array type (e.g. string) because there is no simple way to
4235                --  write a meaningful subtype for it.
4236
4237                if Is_Array_Type (Etype (Def_Id))
4238                  and then not Is_Constrained (Etype (Def_Id))
4239                then
4240                   Error_Msg_NE
4241                     ("imported constant& must have a constrained subtype",
4242                       N, Def_Id);
4243                end if;
4244             end if;
4245
4246          elsif Is_Subprogram (Def_Id)
4247            or else Is_Generic_Subprogram (Def_Id)
4248          then
4249             --  If the name is overloaded, pragma applies to all of the denoted
4250             --  entities in the same declarative part.
4251
4252             Hom_Id := Def_Id;
4253             while Present (Hom_Id) loop
4254                Def_Id := Get_Base_Subprogram (Hom_Id);
4255
4256                --  Ignore inherited subprograms because the pragma will apply
4257                --  to the parent operation, which is the one called.
4258
4259                if Is_Overloadable (Def_Id)
4260                  and then Present (Alias (Def_Id))
4261                then
4262                   null;
4263
4264                --  If it is not a subprogram, it must be in an outer scope and
4265                --  pragma does not apply.
4266
4267                elsif not Is_Subprogram (Def_Id)
4268                  and then not Is_Generic_Subprogram (Def_Id)
4269                then
4270                   null;
4271
4272                --  The pragma does not apply to primitives of interfaces
4273
4274                elsif Is_Dispatching_Operation (Def_Id)
4275                  and then Present (Find_Dispatching_Type (Def_Id))
4276                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4277                then
4278                   null;
4279
4280                --  Verify that the homonym is in the same declarative part (not
4281                --  just the same scope).
4282
4283                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4284                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4285                then
4286                   exit;
4287
4288                else
4289                   Set_Imported (Def_Id);
4290
4291                   --  Reject an Import applied to an abstract subprogram
4292
4293                   if Is_Subprogram (Def_Id)
4294                     and then Is_Abstract_Subprogram (Def_Id)
4295                   then
4296                      Error_Msg_Sloc := Sloc (Def_Id);
4297                      Error_Msg_NE
4298                        ("cannot import abstract subprogram& declared#",
4299                         Arg2, Def_Id);
4300                   end if;
4301
4302                   --  Special processing for Convention_Intrinsic
4303
4304                   if C = Convention_Intrinsic then
4305
4306                      --  Link_Name argument not allowed for intrinsic
4307
4308                      Check_No_Link_Name;
4309
4310                      Set_Is_Intrinsic_Subprogram (Def_Id);
4311
4312                      --  If no external name is present, then check that this
4313                      --  is a valid intrinsic subprogram. If an external name
4314                      --  is present, then this is handled by the back end.
4315
4316                      if No (Arg3) then
4317                         Check_Intrinsic_Subprogram
4318                           (Def_Id, Get_Pragma_Arg (Arg2));
4319                      end if;
4320                   end if;
4321
4322                   --  All interfaced procedures need an external symbol created
4323                   --  for them since they are always referenced from another
4324                   --  object file.
4325
4326                   Set_Is_Public (Def_Id);
4327
4328                   --  Verify that the subprogram does not have a completion
4329                   --  through a renaming declaration. For other completions the
4330                   --  pragma appears as a too late representation.
4331
4332                   declare
4333                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4334
4335                   begin
4336                      if Present (Decl)
4337                        and then Nkind (Decl) = N_Subprogram_Declaration
4338                        and then Present (Corresponding_Body (Decl))
4339                        and then Nkind (Unit_Declaration_Node
4340                                         (Corresponding_Body (Decl))) =
4341                                              N_Subprogram_Renaming_Declaration
4342                      then
4343                         Error_Msg_Sloc := Sloc (Def_Id);
4344                         Error_Msg_NE
4345                           ("cannot import&, renaming already provided for " &
4346                            "declaration #", N, Def_Id);
4347                      end if;
4348                   end;
4349
4350                   Set_Has_Completion (Def_Id);
4351                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4352                end if;
4353
4354                if Is_Compilation_Unit (Hom_Id) then
4355
4356                   --  Its possible homonyms are not affected by the pragma.
4357                   --  Such homonyms might be present in the context of other
4358                   --  units being compiled.
4359
4360                   exit;
4361
4362                else
4363                   Hom_Id := Homonym (Hom_Id);
4364                end if;
4365             end loop;
4366
4367          --  When the convention is Java or CIL, we also allow Import to be
4368          --  given for packages, generic packages, exceptions, record
4369          --  components, and access to subprograms.
4370
4371          elsif (C = Convention_Java or else C = Convention_CIL)
4372            and then
4373              (Is_Package_Or_Generic_Package (Def_Id)
4374                or else Ekind (Def_Id) = E_Exception
4375                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4376                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4377          then
4378             Set_Imported (Def_Id);
4379             Set_Is_Public (Def_Id);
4380             Process_Interface_Name (Def_Id, Arg3, Arg4);
4381
4382          --  Import a CPP class
4383
4384          elsif Is_Record_Type (Def_Id)
4385            and then C = Convention_CPP
4386          then
4387             --  Types treated as CPP classes must be declared limited (note:
4388             --  this used to be a warning but there is no real benefit to it
4389             --  since we did effectively intend to treat the type as limited
4390             --  anyway).
4391
4392             if not Is_Limited_Type (Def_Id) then
4393                Error_Msg_N
4394                  ("imported 'C'P'P type must be limited",
4395                   Get_Pragma_Arg (Arg2));
4396             end if;
4397
4398             Set_Is_CPP_Class (Def_Id);
4399
4400             --  Imported CPP types must not have discriminants (because C++
4401             --  classes do not have discriminants).
4402
4403             if Has_Discriminants (Def_Id) then
4404                Error_Msg_N
4405                  ("imported 'C'P'P type cannot have discriminants",
4406                   First (Discriminant_Specifications
4407                           (Declaration_Node (Def_Id))));
4408             end if;
4409
4410             --  Components of imported CPP types must not have default
4411             --  expressions because the constructor (if any) is on the
4412             --  C++ side.
4413
4414             declare
4415                Tdef  : constant Node_Id :=
4416                          Type_Definition (Declaration_Node (Def_Id));
4417                Clist : Node_Id;
4418                Comp  : Node_Id;
4419
4420             begin
4421                if Nkind (Tdef) = N_Record_Definition then
4422                   Clist := Component_List (Tdef);
4423
4424                else
4425                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4426                   Clist := Component_List (Record_Extension_Part (Tdef));
4427                end if;
4428
4429                if Present (Clist) then
4430                   Comp := First (Component_Items (Clist));
4431                   while Present (Comp) loop
4432                      if Present (Expression (Comp)) then
4433                         Error_Msg_N
4434                           ("component of imported 'C'P'P type cannot have" &
4435                            " default expression", Expression (Comp));
4436                      end if;
4437
4438                      Next (Comp);
4439                   end loop;
4440                end if;
4441             end;
4442
4443          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4444             Check_No_Link_Name;
4445             Check_Arg_Count (3);
4446             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4447
4448             Process_Import_Predefined_Type;
4449
4450          else
4451             Error_Pragma_Arg
4452               ("second argument of pragma% must be object, subprogram" &
4453                " or incomplete type",
4454                Arg2);
4455          end if;
4456
4457          --  If this pragma applies to a compilation unit, then the unit, which
4458          --  is a subprogram, does not require (or allow) a body. We also do
4459          --  not need to elaborate imported procedures.
4460
4461          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4462             declare
4463                Cunit : constant Node_Id := Parent (Parent (N));
4464             begin
4465                Set_Body_Required (Cunit, False);
4466             end;
4467          end if;
4468       end Process_Import_Or_Interface;
4469
4470       --------------------
4471       -- Process_Inline --
4472       --------------------
4473
4474       procedure Process_Inline (Active : Boolean) is
4475          Assoc     : Node_Id;
4476          Decl      : Node_Id;
4477          Subp_Id   : Node_Id;
4478          Subp      : Entity_Id;
4479          Applies   : Boolean;
4480
4481          Effective : Boolean := False;
4482          --  Set True if inline has some effect, i.e. if there is at least one
4483          --  subprogram set as inlined as a result of the use of the pragma.
4484
4485          procedure Make_Inline (Subp : Entity_Id);
4486          --  Subp is the defining unit name of the subprogram declaration. Set
4487          --  the flag, as well as the flag in the corresponding body, if there
4488          --  is one present.
4489
4490          procedure Set_Inline_Flags (Subp : Entity_Id);
4491          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4492          --  Has_Pragma_Inline_Always for the Inline_Always case.
4493
4494          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4495          --  Returns True if it can be determined at this stage that inlining
4496          --  is not possible, for example if the body is available and contains
4497          --  exception handlers, we prevent inlining, since otherwise we can
4498          --  get undefined symbols at link time. This function also emits a
4499          --  warning if front-end inlining is enabled and the pragma appears
4500          --  too late.
4501          --
4502          --  ??? is business with link symbols still valid, or does it relate
4503          --  to front end ZCX which is being phased out ???
4504
4505          ---------------------------
4506          -- Inlining_Not_Possible --
4507          ---------------------------
4508
4509          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4510             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4511             Stats : Node_Id;
4512
4513          begin
4514             if Nkind (Decl) = N_Subprogram_Body then
4515                Stats := Handled_Statement_Sequence (Decl);
4516                return Present (Exception_Handlers (Stats))
4517                  or else Present (At_End_Proc (Stats));
4518
4519             elsif Nkind (Decl) = N_Subprogram_Declaration
4520               and then Present (Corresponding_Body (Decl))
4521             then
4522                if Front_End_Inlining
4523                  and then Analyzed (Corresponding_Body (Decl))
4524                then
4525                   Error_Msg_N ("pragma appears too late, ignored?", N);
4526                   return True;
4527
4528                --  If the subprogram is a renaming as body, the body is just a
4529                --  call to the renamed subprogram, and inlining is trivially
4530                --  possible.
4531
4532                elsif
4533                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4534                                              N_Subprogram_Renaming_Declaration
4535                then
4536                   return False;
4537
4538                else
4539                   Stats :=
4540                     Handled_Statement_Sequence
4541                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4542
4543                   return
4544                     Present (Exception_Handlers (Stats))
4545                       or else Present (At_End_Proc (Stats));
4546                end if;
4547
4548             else
4549                --  If body is not available, assume the best, the check is
4550                --  performed again when compiling enclosing package bodies.
4551
4552                return False;
4553             end if;
4554          end Inlining_Not_Possible;
4555
4556          -----------------
4557          -- Make_Inline --
4558          -----------------
4559
4560          procedure Make_Inline (Subp : Entity_Id) is
4561             Kind       : constant Entity_Kind := Ekind (Subp);
4562             Inner_Subp : Entity_Id   := Subp;
4563
4564          begin
4565             --  Ignore if bad type, avoid cascaded error
4566
4567             if Etype (Subp) = Any_Type then
4568                Applies := True;
4569                return;
4570
4571             --  Ignore if all inlining is suppressed
4572
4573             elsif Suppress_All_Inlining then
4574                Applies := True;
4575                return;
4576
4577             --  If inlining is not possible, for now do not treat as an error
4578
4579             elsif Inlining_Not_Possible (Subp) then
4580                Applies := True;
4581                return;
4582
4583             --  Here we have a candidate for inlining, but we must exclude
4584             --  derived operations. Otherwise we would end up trying to inline
4585             --  a phantom declaration, and the result would be to drag in a
4586             --  body which has no direct inlining associated with it. That
4587             --  would not only be inefficient but would also result in the
4588             --  backend doing cross-unit inlining in cases where it was
4589             --  definitely inappropriate to do so.
4590
4591             --  However, a simple Comes_From_Source test is insufficient, since
4592             --  we do want to allow inlining of generic instances which also do
4593             --  not come from source. We also need to recognize specs generated
4594             --  by the front-end for bodies that carry the pragma. Finally,
4595             --  predefined operators do not come from source but are not
4596             --  inlineable either.
4597
4598             elsif Is_Generic_Instance (Subp)
4599               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4600             then
4601                null;
4602
4603             elsif not Comes_From_Source (Subp)
4604               and then Scope (Subp) /= Standard_Standard
4605             then
4606                Applies := True;
4607                return;
4608             end if;
4609
4610             --  The referenced entity must either be the enclosing entity, or
4611             --  an entity declared within the current open scope.
4612
4613             if Present (Scope (Subp))
4614               and then Scope (Subp) /= Current_Scope
4615               and then Subp /= Current_Scope
4616             then
4617                Error_Pragma_Arg
4618                  ("argument of% must be entity in current scope", Assoc);
4619                return;
4620             end if;
4621
4622             --  Processing for procedure, operator or function. If subprogram
4623             --  is aliased (as for an instance) indicate that the renamed
4624             --  entity (if declared in the same unit) is inlined.
4625
4626             if Is_Subprogram (Subp) then
4627                Inner_Subp := Ultimate_Alias (Inner_Subp);
4628
4629                if In_Same_Source_Unit (Subp, Inner_Subp) then
4630                   Set_Inline_Flags (Inner_Subp);
4631
4632                   Decl := Parent (Parent (Inner_Subp));
4633
4634                   if Nkind (Decl) = N_Subprogram_Declaration
4635                     and then Present (Corresponding_Body (Decl))
4636                   then
4637                      Set_Inline_Flags (Corresponding_Body (Decl));
4638
4639                   elsif Is_Generic_Instance (Subp) then
4640
4641                      --  Indicate that the body needs to be created for
4642                      --  inlining subsequent calls. The instantiation node
4643                      --  follows the declaration of the wrapper package
4644                      --  created for it.
4645
4646                      if Scope (Subp) /= Standard_Standard
4647                        and then
4648                          Need_Subprogram_Instance_Body
4649                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4650                               Subp)
4651                      then
4652                         null;
4653                      end if;
4654                   end if;
4655                end if;
4656
4657                Applies := True;
4658
4659             --  For a generic subprogram set flag as well, for use at the point
4660             --  of instantiation, to determine whether the body should be
4661             --  generated.
4662
4663             elsif Is_Generic_Subprogram (Subp) then
4664                Set_Inline_Flags (Subp);
4665                Applies := True;
4666
4667             --  Literals are by definition inlined
4668
4669             elsif Kind = E_Enumeration_Literal then
4670                null;
4671
4672             --  Anything else is an error
4673
4674             else
4675                Error_Pragma_Arg
4676                  ("expect subprogram name for pragma%", Assoc);
4677             end if;
4678          end Make_Inline;
4679
4680          ----------------------
4681          -- Set_Inline_Flags --
4682          ----------------------
4683
4684          procedure Set_Inline_Flags (Subp : Entity_Id) is
4685          begin
4686             if Active then
4687                Set_Is_Inlined (Subp);
4688             end if;
4689
4690             if not Has_Pragma_Inline (Subp) then
4691                Set_Has_Pragma_Inline (Subp);
4692                Effective := True;
4693             end if;
4694
4695             if Prag_Id = Pragma_Inline_Always then
4696                Set_Has_Pragma_Inline_Always (Subp);
4697             end if;
4698          end Set_Inline_Flags;
4699
4700       --  Start of processing for Process_Inline
4701
4702       begin
4703          Check_No_Identifiers;
4704          Check_At_Least_N_Arguments (1);
4705
4706          if Active then
4707             Inline_Processing_Required := True;
4708          end if;
4709
4710          Assoc := Arg1;
4711          while Present (Assoc) loop
4712             Subp_Id := Get_Pragma_Arg (Assoc);
4713             Analyze (Subp_Id);
4714             Applies := False;
4715
4716             if Is_Entity_Name (Subp_Id) then
4717                Subp := Entity (Subp_Id);
4718
4719                if Subp = Any_Id then
4720
4721                   --  If previous error, avoid cascaded errors
4722
4723                   Applies := True;
4724                   Effective := True;
4725
4726                else
4727                   Make_Inline (Subp);
4728
4729                   --  For the pragma case, climb homonym chain. This is
4730                   --  what implements allowing the pragma in the renaming
4731                   --  case, with the result applying to the ancestors.
4732
4733                   if not From_Aspect_Specification (N) then
4734                      while Present (Homonym (Subp))
4735                        and then Scope (Homonym (Subp)) = Current_Scope
4736                      loop
4737                         Make_Inline (Homonym (Subp));
4738                         Subp := Homonym (Subp);
4739                      end loop;
4740                   end if;
4741                end if;
4742             end if;
4743
4744             if not Applies then
4745                Error_Pragma_Arg
4746                  ("inappropriate argument for pragma%", Assoc);
4747
4748             elsif not Effective
4749               and then Warn_On_Redundant_Constructs
4750               and then not Suppress_All_Inlining
4751             then
4752                if Inlining_Not_Possible (Subp) then
4753                   Error_Msg_NE
4754                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4755                else
4756                   Error_Msg_NE
4757                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4758                end if;
4759             end if;
4760
4761             Next (Assoc);
4762          end loop;
4763       end Process_Inline;
4764
4765       ----------------------------
4766       -- Process_Interface_Name --
4767       ----------------------------
4768
4769       procedure Process_Interface_Name
4770         (Subprogram_Def : Entity_Id;
4771          Ext_Arg        : Node_Id;
4772          Link_Arg       : Node_Id)
4773       is
4774          Ext_Nam    : Node_Id;
4775          Link_Nam   : Node_Id;
4776          String_Val : String_Id;
4777
4778          procedure Check_Form_Of_Interface_Name
4779            (SN            : Node_Id;
4780             Ext_Name_Case : Boolean);
4781          --  SN is a string literal node for an interface name. This routine
4782          --  performs some minimal checks that the name is reasonable. In
4783          --  particular that no spaces or other obviously incorrect characters
4784          --  appear. This is only a warning, since any characters are allowed.
4785          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4786
4787          ----------------------------------
4788          -- Check_Form_Of_Interface_Name --
4789          ----------------------------------
4790
4791          procedure Check_Form_Of_Interface_Name
4792            (SN            : Node_Id;
4793             Ext_Name_Case : Boolean)
4794          is
4795             S  : constant String_Id := Strval (Expr_Value_S (SN));
4796             SL : constant Nat       := String_Length (S);
4797             C  : Char_Code;
4798
4799          begin
4800             if SL = 0 then
4801                Error_Msg_N ("interface name cannot be null string", SN);
4802             end if;
4803
4804             for J in 1 .. SL loop
4805                C := Get_String_Char (S, J);
4806
4807                --  Look for dubious character and issue unconditional warning.
4808                --  Definitely dubious if not in character range.
4809
4810                if not In_Character_Range (C)
4811
4812                   --  For all cases except CLI target,
4813                   --  commas, spaces and slashes are dubious (in CLI, we use
4814                   --  commas and backslashes in external names to specify
4815                   --  assembly version and public key, while slashes and spaces
4816                   --  can be used in names to mark nested classes and
4817                   --  valuetypes).
4818
4819                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4820                              and then (Get_Character (C) = ','
4821                                          or else
4822                                        Get_Character (C) = '\'))
4823                  or else (VM_Target /= CLI_Target
4824                             and then (Get_Character (C) = ' '
4825                                         or else
4826                                       Get_Character (C) = '/'))
4827                then
4828                   Error_Msg
4829                     ("?interface name contains illegal character",
4830                      Sloc (SN) + Source_Ptr (J));
4831                end if;
4832             end loop;
4833          end Check_Form_Of_Interface_Name;
4834
4835       --  Start of processing for Process_Interface_Name
4836
4837       begin
4838          if No (Link_Arg) then
4839             if No (Ext_Arg) then
4840                if VM_Target = CLI_Target
4841                  and then Ekind (Subprogram_Def) = E_Package
4842                  and then Nkind (Parent (Subprogram_Def)) =
4843                                                  N_Package_Specification
4844                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
4845                then
4846                   Set_Interface_Name
4847                      (Subprogram_Def,
4848                       Interface_Name
4849                         (Generic_Parent (Parent (Subprogram_Def))));
4850                end if;
4851
4852                return;
4853
4854             elsif Chars (Ext_Arg) = Name_Link_Name then
4855                Ext_Nam  := Empty;
4856                Link_Nam := Expression (Ext_Arg);
4857
4858             else
4859                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4860                Ext_Nam  := Expression (Ext_Arg);
4861                Link_Nam := Empty;
4862             end if;
4863
4864          else
4865             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
4866             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4867             Ext_Nam  := Expression (Ext_Arg);
4868             Link_Nam := Expression (Link_Arg);
4869          end if;
4870
4871          --  Check expressions for external name and link name are static
4872
4873          if Present (Ext_Nam) then
4874             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4875             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4876
4877             --  Verify that external name is not the name of a local entity,
4878             --  which would hide the imported one and could lead to run-time
4879             --  surprises. The problem can only arise for entities declared in
4880             --  a package body (otherwise the external name is fully qualified
4881             --  and will not conflict).
4882
4883             declare
4884                Nam : Name_Id;
4885                E   : Entity_Id;
4886                Par : Node_Id;
4887
4888             begin
4889                if Prag_Id = Pragma_Import then
4890                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4891                   Nam := Name_Find;
4892                   E   := Entity_Id (Get_Name_Table_Info (Nam));
4893
4894                   if Nam /= Chars (Subprogram_Def)
4895                     and then Present (E)
4896                     and then not Is_Overloadable (E)
4897                     and then Is_Immediately_Visible (E)
4898                     and then not Is_Imported (E)
4899                     and then Ekind (Scope (E)) = E_Package
4900                   then
4901                      Par := Parent (E);
4902                      while Present (Par) loop
4903                         if Nkind (Par) = N_Package_Body then
4904                            Error_Msg_Sloc := Sloc (E);
4905                            Error_Msg_NE
4906                              ("imported entity is hidden by & declared#",
4907                               Ext_Arg, E);
4908                            exit;
4909                         end if;
4910
4911                         Par := Parent (Par);
4912                      end loop;
4913                   end if;
4914                end if;
4915             end;
4916          end if;
4917
4918          if Present (Link_Nam) then
4919             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4920             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4921          end if;
4922
4923          --  If there is no link name, just set the external name
4924
4925          if No (Link_Nam) then
4926             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4927
4928          --  For the Link_Name case, the given literal is preceded by an
4929          --  asterisk, which indicates to GCC that the given name should be
4930          --  taken literally, and in particular that no prepending of
4931          --  underlines should occur, even in systems where this is the
4932          --  normal default.
4933
4934          else
4935             Start_String;
4936
4937             if VM_Target = No_VM then
4938                Store_String_Char (Get_Char_Code ('*'));
4939             end if;
4940
4941             String_Val := Strval (Expr_Value_S (Link_Nam));
4942             Store_String_Chars (String_Val);
4943             Link_Nam :=
4944               Make_String_Literal (Sloc (Link_Nam),
4945                 Strval => End_String);
4946          end if;
4947
4948          --  Set the interface name. If the entity is a generic instance, use
4949          --  its alias, which is the callable entity.
4950
4951          if Is_Generic_Instance (Subprogram_Def) then
4952             Set_Encoded_Interface_Name
4953               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
4954          else
4955             Set_Encoded_Interface_Name
4956               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4957          end if;
4958
4959          --  We allow duplicated export names in CIL/Java, as they are always
4960          --  enclosed in a namespace that differentiates them, and overloaded
4961          --  entities are supported by the VM.
4962
4963          if Convention (Subprogram_Def) /= Convention_CIL
4964               and then
4965             Convention (Subprogram_Def) /= Convention_Java
4966          then
4967             Check_Duplicated_Export_Name (Link_Nam);
4968          end if;
4969       end Process_Interface_Name;
4970
4971       -----------------------------------------
4972       -- Process_Interrupt_Or_Attach_Handler --
4973       -----------------------------------------
4974
4975       procedure Process_Interrupt_Or_Attach_Handler is
4976          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
4977          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
4978          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
4979
4980       begin
4981          Set_Is_Interrupt_Handler (Handler_Proc);
4982
4983          --  If the pragma is not associated with a handler procedure within a
4984          --  protected type, then it must be for a nonprotected procedure for
4985          --  the AAMP target, in which case we don't associate a representation
4986          --  item with the procedure's scope.
4987
4988          if Ekind (Proc_Scope) = E_Protected_Type then
4989             if Prag_Id = Pragma_Interrupt_Handler
4990                  or else
4991                Prag_Id = Pragma_Attach_Handler
4992             then
4993                Record_Rep_Item (Proc_Scope, N);
4994             end if;
4995          end if;
4996       end Process_Interrupt_Or_Attach_Handler;
4997
4998       --------------------------------------------------
4999       -- Process_Restrictions_Or_Restriction_Warnings --
5000       --------------------------------------------------
5001
5002       --  Note: some of the simple identifier cases were handled in par-prag,
5003       --  but it is harmless (and more straightforward) to simply handle all
5004       --  cases here, even if it means we repeat a bit of work in some cases.
5005
5006       procedure Process_Restrictions_Or_Restriction_Warnings
5007         (Warn : Boolean)
5008       is
5009          Arg   : Node_Id;
5010          R_Id  : Restriction_Id;
5011          Id    : Name_Id;
5012          Expr  : Node_Id;
5013          Val   : Uint;
5014
5015          procedure Check_Unit_Name (N : Node_Id);
5016          --  Checks unit name parameter for No_Dependence. Returns if it has
5017          --  an appropriate form, otherwise raises pragma argument error.
5018
5019          ---------------------
5020          -- Check_Unit_Name --
5021          ---------------------
5022
5023          procedure Check_Unit_Name (N : Node_Id) is
5024          begin
5025             if Nkind (N) = N_Selected_Component then
5026                Check_Unit_Name (Prefix (N));
5027                Check_Unit_Name (Selector_Name (N));
5028
5029             elsif Nkind (N) = N_Identifier then
5030                return;
5031
5032             else
5033                Error_Pragma_Arg
5034                  ("wrong form for unit name for No_Dependence", N);
5035             end if;
5036          end Check_Unit_Name;
5037
5038       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5039
5040       begin
5041          --  Ignore all Restrictions pragma in CodePeer mode
5042
5043          if CodePeer_Mode then
5044             return;
5045          end if;
5046
5047          Check_Ada_83_Warning;
5048          Check_At_Least_N_Arguments (1);
5049          Check_Valid_Configuration_Pragma;
5050
5051          Arg := Arg1;
5052          while Present (Arg) loop
5053             Id := Chars (Arg);
5054             Expr := Get_Pragma_Arg (Arg);
5055
5056             --  Case of no restriction identifier present
5057
5058             if Id = No_Name then
5059                if Nkind (Expr) /= N_Identifier then
5060                   Error_Pragma_Arg
5061                     ("invalid form for restriction", Arg);
5062                end if;
5063
5064                R_Id :=
5065                  Get_Restriction_Id
5066                    (Process_Restriction_Synonyms (Expr));
5067
5068                if R_Id not in All_Boolean_Restrictions then
5069                   Error_Msg_Name_1 := Pname;
5070                   Error_Msg_N
5071                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5072
5073                   --  Check for possible misspelling
5074
5075                   for J in Restriction_Id loop
5076                      declare
5077                         Rnm : constant String := Restriction_Id'Image (J);
5078
5079                      begin
5080                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5081                         Name_Len := Rnm'Length;
5082                         Set_Casing (All_Lower_Case);
5083
5084                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5085                            Set_Casing
5086                              (Identifier_Casing (Current_Source_File));
5087                            Error_Msg_String (1 .. Rnm'Length) :=
5088                              Name_Buffer (1 .. Name_Len);
5089                            Error_Msg_Strlen := Rnm'Length;
5090                            Error_Msg_N -- CODEFIX
5091                              ("\possible misspelling of ""~""",
5092                               Get_Pragma_Arg (Arg));
5093                            exit;
5094                         end if;
5095                      end;
5096                   end loop;
5097
5098                   raise Pragma_Exit;
5099                end if;
5100
5101                if Implementation_Restriction (R_Id) then
5102                   Check_Restriction (No_Implementation_Restrictions, Arg);
5103                end if;
5104
5105                --  If this is a warning, then set the warning unless we already
5106                --  have a real restriction active (we never want a warning to
5107                --  override a real restriction).
5108
5109                if Warn then
5110                   if not Restriction_Active (R_Id) then
5111                      Set_Restriction (R_Id, N);
5112                      Restriction_Warnings (R_Id) := True;
5113                   end if;
5114
5115                --  If real restriction case, then set it and make sure that the
5116                --  restriction warning flag is off, since a real restriction
5117                --  always overrides a warning.
5118
5119                else
5120                   Set_Restriction (R_Id, N);
5121                   Restriction_Warnings (R_Id) := False;
5122                end if;
5123
5124                --  Check for obsolescent restrictions in Ada 2005 mode
5125
5126                if not Warn
5127                  and then Ada_Version >= Ada_2005
5128                  and then (R_Id = No_Asynchronous_Control
5129                             or else
5130                            R_Id = No_Unchecked_Deallocation
5131                             or else
5132                            R_Id = No_Unchecked_Conversion)
5133                then
5134                   Check_Restriction (No_Obsolescent_Features, N);
5135                end if;
5136
5137                --  A very special case that must be processed here: pragma
5138                --  Restrictions (No_Exceptions) turns off all run-time
5139                --  checking. This is a bit dubious in terms of the formal
5140                --  language definition, but it is what is intended by RM
5141                --  H.4(12). Restriction_Warnings never affects generated code
5142                --  so this is done only in the real restriction case.
5143
5144                if R_Id = No_Exceptions and then not Warn then
5145                   Scope_Suppress := (others => True);
5146                end if;
5147
5148             --  Case of No_Dependence => unit-name. Note that the parser
5149             --  already made the necessary entry in the No_Dependence table.
5150
5151             elsif Id = Name_No_Dependence then
5152                Check_Unit_Name (Expr);
5153
5154             --  All other cases of restriction identifier present
5155
5156             else
5157                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5158                Analyze_And_Resolve (Expr, Any_Integer);
5159
5160                if R_Id not in All_Parameter_Restrictions then
5161                   Error_Pragma_Arg
5162                     ("invalid restriction parameter identifier", Arg);
5163
5164                elsif not Is_OK_Static_Expression (Expr) then
5165                   Flag_Non_Static_Expr
5166                     ("value must be static expression!", Expr);
5167                   raise Pragma_Exit;
5168
5169                elsif not Is_Integer_Type (Etype (Expr))
5170                  or else Expr_Value (Expr) < 0
5171                then
5172                   Error_Pragma_Arg
5173                     ("value must be non-negative integer", Arg);
5174                end if;
5175
5176                --  Restriction pragma is active
5177
5178                Val := Expr_Value (Expr);
5179
5180                if not UI_Is_In_Int_Range (Val) then
5181                   Error_Pragma_Arg
5182                     ("pragma ignored, value too large?", Arg);
5183                end if;
5184
5185                --  Warning case. If the real restriction is active, then we
5186                --  ignore the request, since warning never overrides a real
5187                --  restriction. Otherwise we set the proper warning. Note that
5188                --  this circuit sets the warning again if it is already set,
5189                --  which is what we want, since the constant may have changed.
5190
5191                if Warn then
5192                   if not Restriction_Active (R_Id) then
5193                      Set_Restriction
5194                        (R_Id, N, Integer (UI_To_Int (Val)));
5195                      Restriction_Warnings (R_Id) := True;
5196                   end if;
5197
5198                --  Real restriction case, set restriction and make sure warning
5199                --  flag is off since real restriction always overrides warning.
5200
5201                else
5202                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5203                   Restriction_Warnings (R_Id) := False;
5204                end if;
5205             end if;
5206
5207             Next (Arg);
5208          end loop;
5209       end Process_Restrictions_Or_Restriction_Warnings;
5210
5211       ---------------------------------
5212       -- Process_Suppress_Unsuppress --
5213       ---------------------------------
5214
5215       --  Note: this procedure makes entries in the check suppress data
5216       --  structures managed by Sem. See spec of package Sem for full
5217       --  details on how we handle recording of check suppression.
5218
5219       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5220          C    : Check_Id;
5221          E_Id : Node_Id;
5222          E    : Entity_Id;
5223
5224          In_Package_Spec : constant Boolean :=
5225                              Is_Package_Or_Generic_Package (Current_Scope)
5226                                and then not In_Package_Body (Current_Scope);
5227
5228          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5229          --  Used to suppress a single check on the given entity
5230
5231          --------------------------------
5232          -- Suppress_Unsuppress_Echeck --
5233          --------------------------------
5234
5235          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5236          begin
5237             Set_Checks_May_Be_Suppressed (E);
5238
5239             if In_Package_Spec then
5240                Push_Global_Suppress_Stack_Entry
5241                  (Entity   => E,
5242                   Check    => C,
5243                   Suppress => Suppress_Case);
5244
5245             else
5246                Push_Local_Suppress_Stack_Entry
5247                  (Entity   => E,
5248                   Check    => C,
5249                   Suppress => Suppress_Case);
5250             end if;
5251
5252             --  If this is a first subtype, and the base type is distinct,
5253             --  then also set the suppress flags on the base type.
5254
5255             if Is_First_Subtype (E)
5256               and then Etype (E) /= E
5257             then
5258                Suppress_Unsuppress_Echeck (Etype (E), C);
5259             end if;
5260          end Suppress_Unsuppress_Echeck;
5261
5262       --  Start of processing for Process_Suppress_Unsuppress
5263
5264       begin
5265          --  Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5266          --  we want to generate checks for analysis purposes, as set by -gnatC
5267
5268          if CodePeer_Mode and then Comes_From_Source (N) then
5269             return;
5270          end if;
5271
5272          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5273          --  declarative part or a package spec (RM 11.5(5)).
5274
5275          if not Is_Configuration_Pragma then
5276             Check_Is_In_Decl_Part_Or_Package_Spec;
5277          end if;
5278
5279          Check_At_Least_N_Arguments (1);
5280          Check_At_Most_N_Arguments (2);
5281          Check_No_Identifier (Arg1);
5282          Check_Arg_Is_Identifier (Arg1);
5283
5284          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5285
5286          if C = No_Check_Id then
5287             Error_Pragma_Arg
5288               ("argument of pragma% is not valid check name", Arg1);
5289          end if;
5290
5291          if not Suppress_Case
5292            and then (C = All_Checks or else C = Overflow_Check)
5293          then
5294             Opt.Overflow_Checks_Unsuppressed := True;
5295          end if;
5296
5297          if Arg_Count = 1 then
5298
5299             --  Make an entry in the local scope suppress table. This is the
5300             --  table that directly shows the current value of the scope
5301             --  suppress check for any check id value.
5302
5303             if C = All_Checks then
5304
5305                --  For All_Checks, we set all specific predefined checks with
5306                --  the exception of Elaboration_Check, which is handled
5307                --  specially because of not wanting All_Checks to have the
5308                --  effect of deactivating static elaboration order processing.
5309
5310                for J in Scope_Suppress'Range loop
5311                   if J /= Elaboration_Check then
5312                      Scope_Suppress (J) := Suppress_Case;
5313                   end if;
5314                end loop;
5315
5316             --  If not All_Checks, and predefined check, then set appropriate
5317             --  scope entry. Note that we will set Elaboration_Check if this
5318             --  is explicitly specified.
5319
5320             elsif C in Predefined_Check_Id then
5321                Scope_Suppress (C) := Suppress_Case;
5322             end if;
5323
5324             --  Also make an entry in the Local_Entity_Suppress table
5325
5326             Push_Local_Suppress_Stack_Entry
5327               (Entity   => Empty,
5328                Check    => C,
5329                Suppress => Suppress_Case);
5330
5331          --  Case of two arguments present, where the check is suppressed for
5332          --  a specified entity (given as the second argument of the pragma)
5333
5334          else
5335             --  This is obsolescent in Ada 2005 mode
5336
5337             if Ada_Version >= Ada_2005 then
5338                Check_Restriction (No_Obsolescent_Features, Arg2);
5339             end if;
5340
5341             Check_Optional_Identifier (Arg2, Name_On);
5342             E_Id := Get_Pragma_Arg (Arg2);
5343             Analyze (E_Id);
5344
5345             if not Is_Entity_Name (E_Id) then
5346                Error_Pragma_Arg
5347                  ("second argument of pragma% must be entity name", Arg2);
5348             end if;
5349
5350             E := Entity (E_Id);
5351
5352             if E = Any_Id then
5353                return;
5354             end if;
5355
5356             --  Enforce RM 11.5(7) which requires that for a pragma that
5357             --  appears within a package spec, the named entity must be
5358             --  within the package spec. We allow the package name itself
5359             --  to be mentioned since that makes sense, although it is not
5360             --  strictly allowed by 11.5(7).
5361
5362             if In_Package_Spec
5363               and then E /= Current_Scope
5364               and then Scope (E) /= Current_Scope
5365             then
5366                Error_Pragma_Arg
5367                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5368                   Arg2);
5369             end if;
5370
5371             --  Loop through homonyms. As noted below, in the case of a package
5372             --  spec, only homonyms within the package spec are considered.
5373
5374             loop
5375                Suppress_Unsuppress_Echeck (E, C);
5376
5377                if Is_Generic_Instance (E)
5378                  and then Is_Subprogram (E)
5379                  and then Present (Alias (E))
5380                then
5381                   Suppress_Unsuppress_Echeck (Alias (E), C);
5382                end if;
5383
5384                --  Move to next homonym if not aspect spec case
5385
5386                exit when From_Aspect_Specification (N);
5387                E := Homonym (E);
5388                exit when No (E);
5389
5390                --  If we are within a package specification, the pragma only
5391                --  applies to homonyms in the same scope.
5392
5393                exit when In_Package_Spec
5394                  and then Scope (E) /= Current_Scope;
5395             end loop;
5396          end if;
5397       end Process_Suppress_Unsuppress;
5398
5399       ------------------
5400       -- Set_Exported --
5401       ------------------
5402
5403       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5404       begin
5405          if Is_Imported (E) then
5406             Error_Pragma_Arg
5407               ("cannot export entity& that was previously imported", Arg);
5408
5409          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5410             Error_Pragma_Arg
5411               ("cannot export entity& that has an address clause", Arg);
5412          end if;
5413
5414          Set_Is_Exported (E);
5415
5416          --  Generate a reference for entity explicitly, because the
5417          --  identifier may be overloaded and name resolution will not
5418          --  generate one.
5419
5420          Generate_Reference (E, Arg);
5421
5422          --  Deal with exporting non-library level entity
5423
5424          if not Is_Library_Level_Entity (E) then
5425
5426             --  Not allowed at all for subprograms
5427
5428             if Is_Subprogram (E) then
5429                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5430
5431             --  Otherwise set public and statically allocated
5432
5433             else
5434                Set_Is_Public (E);
5435                Set_Is_Statically_Allocated (E);
5436
5437                --  Warn if the corresponding W flag is set and the pragma comes
5438                --  from source. The latter may not be true e.g. on VMS where we
5439                --  expand export pragmas for exception codes associated with
5440                --  imported or exported exceptions. We do not want to generate
5441                --  a warning for something that the user did not write.
5442
5443                if Warn_On_Export_Import
5444                  and then Comes_From_Source (Arg)
5445                then
5446                   Error_Msg_NE
5447                     ("?& has been made static as a result of Export", Arg, E);
5448                   Error_Msg_N
5449                     ("\this usage is non-standard and non-portable", Arg);
5450                end if;
5451             end if;
5452          end if;
5453
5454          if Warn_On_Export_Import and then Is_Type (E) then
5455             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5456          end if;
5457
5458          if Warn_On_Export_Import and Inside_A_Generic then
5459             Error_Msg_NE
5460               ("all instances of& will have the same external name?", Arg, E);
5461          end if;
5462       end Set_Exported;
5463
5464       ----------------------------------------------
5465       -- Set_Extended_Import_Export_External_Name --
5466       ----------------------------------------------
5467
5468       procedure Set_Extended_Import_Export_External_Name
5469         (Internal_Ent : Entity_Id;
5470          Arg_External : Node_Id)
5471       is
5472          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5473          New_Name : Node_Id;
5474
5475       begin
5476          if No (Arg_External) then
5477             return;
5478          end if;
5479
5480          Check_Arg_Is_External_Name (Arg_External);
5481
5482          if Nkind (Arg_External) = N_String_Literal then
5483             if String_Length (Strval (Arg_External)) = 0 then
5484                return;
5485             else
5486                New_Name := Adjust_External_Name_Case (Arg_External);
5487             end if;
5488
5489          elsif Nkind (Arg_External) = N_Identifier then
5490             New_Name := Get_Default_External_Name (Arg_External);
5491
5492          --  Check_Arg_Is_External_Name should let through only identifiers and
5493          --  string literals or static string expressions (which are folded to
5494          --  string literals).
5495
5496          else
5497             raise Program_Error;
5498          end if;
5499
5500          --  If we already have an external name set (by a prior normal Import
5501          --  or Export pragma), then the external names must match
5502
5503          if Present (Interface_Name (Internal_Ent)) then
5504             Check_Matching_Internal_Names : declare
5505                S1 : constant String_Id := Strval (Old_Name);
5506                S2 : constant String_Id := Strval (New_Name);
5507
5508                procedure Mismatch;
5509                --  Called if names do not match
5510
5511                --------------
5512                -- Mismatch --
5513                --------------
5514
5515                procedure Mismatch is
5516                begin
5517                   Error_Msg_Sloc := Sloc (Old_Name);
5518                   Error_Pragma_Arg
5519                     ("external name does not match that given #",
5520                      Arg_External);
5521                end Mismatch;
5522
5523             --  Start of processing for Check_Matching_Internal_Names
5524
5525             begin
5526                if String_Length (S1) /= String_Length (S2) then
5527                   Mismatch;
5528
5529                else
5530                   for J in 1 .. String_Length (S1) loop
5531                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5532                         Mismatch;
5533                      end if;
5534                   end loop;
5535                end if;
5536             end Check_Matching_Internal_Names;
5537
5538          --  Otherwise set the given name
5539
5540          else
5541             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5542             Check_Duplicated_Export_Name (New_Name);
5543          end if;
5544       end Set_Extended_Import_Export_External_Name;
5545
5546       ------------------
5547       -- Set_Imported --
5548       ------------------
5549
5550       procedure Set_Imported (E : Entity_Id) is
5551       begin
5552          --  Error message if already imported or exported
5553
5554          if Is_Exported (E) or else Is_Imported (E) then
5555
5556             --  Error if being set Exported twice
5557
5558             if Is_Exported (E) then
5559                Error_Msg_NE ("entity& was previously exported", N, E);
5560
5561             --  OK if Import/Interface case
5562
5563             elsif Import_Interface_Present (N) then
5564                goto OK;
5565
5566             --  Error if being set Imported twice
5567
5568             else
5569                Error_Msg_NE ("entity& was previously imported", N, E);
5570             end if;
5571
5572             Error_Msg_Name_1 := Pname;
5573             Error_Msg_N
5574               ("\(pragma% applies to all previous entities)", N);
5575
5576             Error_Msg_Sloc  := Sloc (E);
5577             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5578
5579          --  Here if not previously imported or exported, OK to import
5580
5581          else
5582             Set_Is_Imported (E);
5583
5584             --  If the entity is an object that is not at the library level,
5585             --  then it is statically allocated. We do not worry about objects
5586             --  with address clauses in this context since they are not really
5587             --  imported in the linker sense.
5588
5589             if Is_Object (E)
5590               and then not Is_Library_Level_Entity (E)
5591               and then No (Address_Clause (E))
5592             then
5593                Set_Is_Statically_Allocated (E);
5594             end if;
5595          end if;
5596
5597          <<OK>> null;
5598       end Set_Imported;
5599
5600       -------------------------
5601       -- Set_Mechanism_Value --
5602       -------------------------
5603
5604       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5605       --  analyzed, since it is semantic nonsense), so we get it in the exact
5606       --  form created by the parser.
5607
5608       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5609          Class        : Node_Id;
5610          Param        : Node_Id;
5611          Mech_Name_Id : Name_Id;
5612
5613          procedure Bad_Class;
5614          --  Signal bad descriptor class name
5615
5616          procedure Bad_Mechanism;
5617          --  Signal bad mechanism name
5618
5619          ---------------
5620          -- Bad_Class --
5621          ---------------
5622
5623          procedure Bad_Class is
5624          begin
5625             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5626          end Bad_Class;
5627
5628          -------------------------
5629          -- Bad_Mechanism_Value --
5630          -------------------------
5631
5632          procedure Bad_Mechanism is
5633          begin
5634             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5635          end Bad_Mechanism;
5636
5637       --  Start of processing for Set_Mechanism_Value
5638
5639       begin
5640          if Mechanism (Ent) /= Default_Mechanism then
5641             Error_Msg_NE
5642               ("mechanism for & has already been set", Mech_Name, Ent);
5643          end if;
5644
5645          --  MECHANISM_NAME ::= value | reference | descriptor |
5646          --                     short_descriptor
5647
5648          if Nkind (Mech_Name) = N_Identifier then
5649             if Chars (Mech_Name) = Name_Value then
5650                Set_Mechanism (Ent, By_Copy);
5651                return;
5652
5653             elsif Chars (Mech_Name) = Name_Reference then
5654                Set_Mechanism (Ent, By_Reference);
5655                return;
5656
5657             elsif Chars (Mech_Name) = Name_Descriptor then
5658                Check_VMS (Mech_Name);
5659
5660                --  Descriptor => Short_Descriptor if pragma was given
5661
5662                if Short_Descriptors then
5663                   Set_Mechanism (Ent, By_Short_Descriptor);
5664                else
5665                   Set_Mechanism (Ent, By_Descriptor);
5666                end if;
5667
5668                return;
5669
5670             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5671                Check_VMS (Mech_Name);
5672                Set_Mechanism (Ent, By_Short_Descriptor);
5673                return;
5674
5675             elsif Chars (Mech_Name) = Name_Copy then
5676                Error_Pragma_Arg
5677                  ("bad mechanism name, Value assumed", Mech_Name);
5678
5679             else
5680                Bad_Mechanism;
5681             end if;
5682
5683          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5684          --                     short_descriptor (CLASS_NAME)
5685          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5686
5687          --  Note: this form is parsed as an indexed component
5688
5689          elsif Nkind (Mech_Name) = N_Indexed_Component then
5690             Class := First (Expressions (Mech_Name));
5691
5692             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5693              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5694                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5695              or else Present (Next (Class))
5696             then
5697                Bad_Mechanism;
5698             else
5699                Mech_Name_Id := Chars (Prefix (Mech_Name));
5700
5701                --  Change Descriptor => Short_Descriptor if pragma was given
5702
5703                if Mech_Name_Id = Name_Descriptor
5704                  and then Short_Descriptors
5705                then
5706                   Mech_Name_Id := Name_Short_Descriptor;
5707                end if;
5708             end if;
5709
5710          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5711          --                     short_descriptor (Class => CLASS_NAME)
5712          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5713
5714          --  Note: this form is parsed as a function call
5715
5716          elsif Nkind (Mech_Name) = N_Function_Call then
5717             Param := First (Parameter_Associations (Mech_Name));
5718
5719             if Nkind (Name (Mech_Name)) /= N_Identifier
5720               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5721                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5722               or else Present (Next (Param))
5723               or else No (Selector_Name (Param))
5724               or else Chars (Selector_Name (Param)) /= Name_Class
5725             then
5726                Bad_Mechanism;
5727             else
5728                Class := Explicit_Actual_Parameter (Param);
5729                Mech_Name_Id := Chars (Name (Mech_Name));
5730             end if;
5731
5732          else
5733             Bad_Mechanism;
5734          end if;
5735
5736          --  Fall through here with Class set to descriptor class name
5737
5738          Check_VMS (Mech_Name);
5739
5740          if Nkind (Class) /= N_Identifier then
5741             Bad_Class;
5742
5743          elsif Mech_Name_Id = Name_Descriptor
5744            and then Chars (Class) = Name_UBS
5745          then
5746             Set_Mechanism (Ent, By_Descriptor_UBS);
5747
5748          elsif Mech_Name_Id = Name_Descriptor
5749            and then Chars (Class) = Name_UBSB
5750          then
5751             Set_Mechanism (Ent, By_Descriptor_UBSB);
5752
5753          elsif Mech_Name_Id = Name_Descriptor
5754            and then Chars (Class) = Name_UBA
5755          then
5756             Set_Mechanism (Ent, By_Descriptor_UBA);
5757
5758          elsif Mech_Name_Id = Name_Descriptor
5759            and then Chars (Class) = Name_S
5760          then
5761             Set_Mechanism (Ent, By_Descriptor_S);
5762
5763          elsif Mech_Name_Id = Name_Descriptor
5764            and then Chars (Class) = Name_SB
5765          then
5766             Set_Mechanism (Ent, By_Descriptor_SB);
5767
5768          elsif Mech_Name_Id = Name_Descriptor
5769            and then Chars (Class) = Name_A
5770          then
5771             Set_Mechanism (Ent, By_Descriptor_A);
5772
5773          elsif Mech_Name_Id = Name_Descriptor
5774            and then Chars (Class) = Name_NCA
5775          then
5776             Set_Mechanism (Ent, By_Descriptor_NCA);
5777
5778          elsif Mech_Name_Id = Name_Short_Descriptor
5779            and then Chars (Class) = Name_UBS
5780          then
5781             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5782
5783          elsif Mech_Name_Id = Name_Short_Descriptor
5784            and then Chars (Class) = Name_UBSB
5785          then
5786             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5787
5788          elsif Mech_Name_Id = Name_Short_Descriptor
5789            and then Chars (Class) = Name_UBA
5790          then
5791             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5792
5793          elsif Mech_Name_Id = Name_Short_Descriptor
5794            and then Chars (Class) = Name_S
5795          then
5796             Set_Mechanism (Ent, By_Short_Descriptor_S);
5797
5798          elsif Mech_Name_Id = Name_Short_Descriptor
5799            and then Chars (Class) = Name_SB
5800          then
5801             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5802
5803          elsif Mech_Name_Id = Name_Short_Descriptor
5804            and then Chars (Class) = Name_A
5805          then
5806             Set_Mechanism (Ent, By_Short_Descriptor_A);
5807
5808          elsif Mech_Name_Id = Name_Short_Descriptor
5809            and then Chars (Class) = Name_NCA
5810          then
5811             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5812
5813          else
5814             Bad_Class;
5815          end if;
5816       end Set_Mechanism_Value;
5817
5818       ---------------------------
5819       -- Set_Ravenscar_Profile --
5820       ---------------------------
5821
5822       --  The tasks to be done here are
5823
5824       --    Set required policies
5825
5826       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5827       --      pragma Locking_Policy (Ceiling_Locking)
5828
5829       --    Set Detect_Blocking mode
5830
5831       --    Set required restrictions (see System.Rident for detailed list)
5832
5833       --    Set the No_Dependence rules
5834       --      No_Dependence => Ada.Asynchronous_Task_Control
5835       --      No_Dependence => Ada.Calendar
5836       --      No_Dependence => Ada.Execution_Time.Group_Budget
5837       --      No_Dependence => Ada.Execution_Time.Timers
5838       --      No_Dependence => Ada.Task_Attributes
5839       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
5840
5841       procedure Set_Ravenscar_Profile (N : Node_Id) is
5842          Prefix_Entity   : Entity_Id;
5843          Selector_Entity : Entity_Id;
5844          Prefix_Node     : Node_Id;
5845          Node            : Node_Id;
5846
5847       begin
5848          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5849
5850          if Task_Dispatching_Policy /= ' '
5851            and then Task_Dispatching_Policy /= 'F'
5852          then
5853             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5854             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5855
5856          --  Set the FIFO_Within_Priorities policy, but always preserve
5857          --  System_Location since we like the error message with the run time
5858          --  name.
5859
5860          else
5861             Task_Dispatching_Policy := 'F';
5862
5863             if Task_Dispatching_Policy_Sloc /= System_Location then
5864                Task_Dispatching_Policy_Sloc := Loc;
5865             end if;
5866          end if;
5867
5868          --  pragma Locking_Policy (Ceiling_Locking)
5869
5870          if Locking_Policy /= ' '
5871            and then Locking_Policy /= 'C'
5872          then
5873             Error_Msg_Sloc := Locking_Policy_Sloc;
5874             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5875
5876          --  Set the Ceiling_Locking policy, but preserve System_Location since
5877          --  we like the error message with the run time name.
5878
5879          else
5880             Locking_Policy := 'C';
5881
5882             if Locking_Policy_Sloc /= System_Location then
5883                Locking_Policy_Sloc := Loc;
5884             end if;
5885          end if;
5886
5887          --  pragma Detect_Blocking
5888
5889          Detect_Blocking := True;
5890
5891          --  Set the corresponding restrictions
5892
5893          Set_Profile_Restrictions
5894            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5895
5896          --  Set the No_Dependence restrictions
5897
5898          --  The following No_Dependence restrictions:
5899          --    No_Dependence => Ada.Asynchronous_Task_Control
5900          --    No_Dependence => Ada.Calendar
5901          --    No_Dependence => Ada.Task_Attributes
5902          --  are already set by previous call to Set_Profile_Restrictions.
5903
5904          --  Set the following restrictions which were added to Ada 2005:
5905          --    No_Dependence => Ada.Execution_Time.Group_Budget
5906          --    No_Dependence => Ada.Execution_Time.Timers
5907
5908          if Ada_Version >= Ada_2005 then
5909             Name_Buffer (1 .. 3) := "ada";
5910             Name_Len := 3;
5911
5912             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5913
5914             Name_Buffer (1 .. 14) := "execution_time";
5915             Name_Len := 14;
5916
5917             Selector_Entity := Make_Identifier (Loc, Name_Find);
5918
5919             Prefix_Node :=
5920               Make_Selected_Component
5921                 (Sloc          => Loc,
5922                  Prefix        => Prefix_Entity,
5923                  Selector_Name => Selector_Entity);
5924
5925             Name_Buffer (1 .. 13) := "group_budgets";
5926             Name_Len := 13;
5927
5928             Selector_Entity := Make_Identifier (Loc, Name_Find);
5929
5930             Node :=
5931               Make_Selected_Component
5932                 (Sloc          => Loc,
5933                  Prefix        => Prefix_Node,
5934                  Selector_Name => Selector_Entity);
5935
5936             Set_Restriction_No_Dependence
5937               (Unit    => Node,
5938                Warn    => Treat_Restrictions_As_Warnings,
5939                Profile => Ravenscar);
5940
5941             Name_Buffer (1 .. 6) := "timers";
5942             Name_Len := 6;
5943
5944             Selector_Entity := Make_Identifier (Loc, Name_Find);
5945
5946             Node :=
5947               Make_Selected_Component
5948                 (Sloc          => Loc,
5949                  Prefix        => Prefix_Node,
5950                  Selector_Name => Selector_Entity);
5951
5952             Set_Restriction_No_Dependence
5953               (Unit    => Node,
5954                Warn    => Treat_Restrictions_As_Warnings,
5955                Profile => Ravenscar);
5956          end if;
5957
5958          --  Set the following restrictions which was added to Ada 2012 (see
5959          --  AI-0171):
5960          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
5961
5962          if Ada_Version >= Ada_2012 then
5963             Name_Buffer (1 .. 6) := "system";
5964             Name_Len := 6;
5965
5966             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5967
5968             Name_Buffer (1 .. 15) := "multiprocessors";
5969             Name_Len := 15;
5970
5971             Selector_Entity := Make_Identifier (Loc, Name_Find);
5972
5973             Prefix_Node :=
5974               Make_Selected_Component
5975                 (Sloc          => Loc,
5976                  Prefix        => Prefix_Entity,
5977                  Selector_Name => Selector_Entity);
5978
5979             Name_Buffer (1 .. 19) := "dispatching_domains";
5980             Name_Len := 19;
5981
5982             Selector_Entity := Make_Identifier (Loc, Name_Find);
5983
5984             Node :=
5985               Make_Selected_Component
5986                 (Sloc          => Loc,
5987                  Prefix        => Prefix_Node,
5988                  Selector_Name => Selector_Entity);
5989
5990             Set_Restriction_No_Dependence
5991               (Unit    => Node,
5992                Warn    => Treat_Restrictions_As_Warnings,
5993                Profile => Ravenscar);
5994          end if;
5995       end Set_Ravenscar_Profile;
5996
5997    --  Start of processing for Analyze_Pragma
5998
5999    begin
6000       --  The following code is a defense against recursion. Not clear that
6001       --  this can happen legitimately, but perhaps some error situations
6002       --  can cause it, and we did see this recursion during testing.
6003
6004       if Analyzed (N) then
6005          return;
6006       else
6007          Set_Analyzed (N, True);
6008       end if;
6009
6010       --  Deal with unrecognized pragma
6011
6012       if not Is_Pragma_Name (Pname) then
6013          if Warn_On_Unrecognized_Pragma then
6014             Error_Msg_Name_1 := Pname;
6015             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6016
6017             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6018                if Is_Bad_Spelling_Of (Pname, PN) then
6019                   Error_Msg_Name_1 := PN;
6020                   Error_Msg_N -- CODEFIX
6021                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6022                   exit;
6023                end if;
6024             end loop;
6025          end if;
6026
6027          return;
6028       end if;
6029
6030       --  Here to start processing for recognized pragma
6031
6032       Prag_Id := Get_Pragma_Id (Pname);
6033
6034       --  Preset arguments
6035
6036       Arg_Count := 0;
6037       Arg1      := Empty;
6038       Arg2      := Empty;
6039       Arg3      := Empty;
6040       Arg4      := Empty;
6041
6042       if Present (Pragma_Argument_Associations (N)) then
6043          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6044          Arg1 := First (Pragma_Argument_Associations (N));
6045
6046          if Present (Arg1) then
6047             Arg2 := Next (Arg1);
6048
6049             if Present (Arg2) then
6050                Arg3 := Next (Arg2);
6051
6052                if Present (Arg3) then
6053                   Arg4 := Next (Arg3);
6054                end if;
6055             end if;
6056          end if;
6057       end if;
6058
6059       --  An enumeration type defines the pragmas that are supported by the
6060       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6061       --  into the corresponding enumeration value for the following case.
6062
6063       case Prag_Id is
6064
6065          -----------------
6066          -- Abort_Defer --
6067          -----------------
6068
6069          --  pragma Abort_Defer;
6070
6071          when Pragma_Abort_Defer =>
6072             GNAT_Pragma;
6073             Check_Arg_Count (0);
6074
6075             --  The only required semantic processing is to check the
6076             --  placement. This pragma must appear at the start of the
6077             --  statement sequence of a handled sequence of statements.
6078
6079             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6080               or else N /= First (Statements (Parent (N)))
6081             then
6082                Pragma_Misplaced;
6083             end if;
6084
6085          ------------
6086          -- Ada_83 --
6087          ------------
6088
6089          --  pragma Ada_83;
6090
6091          --  Note: this pragma also has some specific processing in Par.Prag
6092          --  because we want to set the Ada version mode during parsing.
6093
6094          when Pragma_Ada_83 =>
6095             GNAT_Pragma;
6096             Check_Arg_Count (0);
6097
6098             --  We really should check unconditionally for proper configuration
6099             --  pragma placement, since we really don't want mixed Ada modes
6100             --  within a single unit, and the GNAT reference manual has always
6101             --  said this was a configuration pragma, but we did not check and
6102             --  are hesitant to add the check now.
6103
6104             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6105             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6106             --  or Ada 2012 mode.
6107
6108             if Ada_Version >= Ada_2005 then
6109                Check_Valid_Configuration_Pragma;
6110             end if;
6111
6112             --  Now set Ada 83 mode
6113
6114             Ada_Version := Ada_83;
6115             Ada_Version_Explicit := Ada_Version;
6116
6117          ------------
6118          -- Ada_95 --
6119          ------------
6120
6121          --  pragma Ada_95;
6122
6123          --  Note: this pragma also has some specific processing in Par.Prag
6124          --  because we want to set the Ada 83 version mode during parsing.
6125
6126          when Pragma_Ada_95 =>
6127             GNAT_Pragma;
6128             Check_Arg_Count (0);
6129
6130             --  We really should check unconditionally for proper configuration
6131             --  pragma placement, since we really don't want mixed Ada modes
6132             --  within a single unit, and the GNAT reference manual has always
6133             --  said this was a configuration pragma, but we did not check and
6134             --  are hesitant to add the check now.
6135
6136             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6137             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6138
6139             if Ada_Version >= Ada_2005 then
6140                Check_Valid_Configuration_Pragma;
6141             end if;
6142
6143             --  Now set Ada 95 mode
6144
6145             Ada_Version := Ada_95;
6146             Ada_Version_Explicit := Ada_Version;
6147
6148          ---------------------
6149          -- Ada_05/Ada_2005 --
6150          ---------------------
6151
6152          --  pragma Ada_05;
6153          --  pragma Ada_05 (LOCAL_NAME);
6154
6155          --  pragma Ada_2005;
6156          --  pragma Ada_2005 (LOCAL_NAME):
6157
6158          --  Note: these pragmas also have some specific processing in Par.Prag
6159          --  because we want to set the Ada 2005 version mode during parsing.
6160
6161          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6162             E_Id : Node_Id;
6163
6164          begin
6165             GNAT_Pragma;
6166
6167             if Arg_Count = 1 then
6168                Check_Arg_Is_Local_Name (Arg1);
6169                E_Id := Get_Pragma_Arg (Arg1);
6170
6171                if Etype (E_Id) = Any_Type then
6172                   return;
6173                end if;
6174
6175                Set_Is_Ada_2005_Only (Entity (E_Id));
6176
6177             else
6178                Check_Arg_Count (0);
6179
6180                --  For Ada_2005 we unconditionally enforce the documented
6181                --  configuration pragma placement, since we do not want to
6182                --  tolerate mixed modes in a unit involving Ada 2005. That
6183                --  would cause real difficulties for those cases where there
6184                --  are incompatibilities between Ada 95 and Ada 2005.
6185
6186                Check_Valid_Configuration_Pragma;
6187
6188                --  Now set appropriate Ada mode
6189
6190                Ada_Version          := Ada_2005;
6191                Ada_Version_Explicit := Ada_2005;
6192             end if;
6193          end;
6194
6195          ---------------------
6196          -- Ada_12/Ada_2012 --
6197          ---------------------
6198
6199          --  pragma Ada_12;
6200          --  pragma Ada_12 (LOCAL_NAME);
6201
6202          --  pragma Ada_2012;
6203          --  pragma Ada_2012 (LOCAL_NAME):
6204
6205          --  Note: these pragmas also have some specific processing in Par.Prag
6206          --  because we want to set the Ada 2012 version mode during parsing.
6207
6208          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6209             E_Id : Node_Id;
6210
6211          begin
6212             GNAT_Pragma;
6213
6214             if Arg_Count = 1 then
6215                Check_Arg_Is_Local_Name (Arg1);
6216                E_Id := Get_Pragma_Arg (Arg1);
6217
6218                if Etype (E_Id) = Any_Type then
6219                   return;
6220                end if;
6221
6222                Set_Is_Ada_2012_Only (Entity (E_Id));
6223
6224             else
6225                Check_Arg_Count (0);
6226
6227                --  For Ada_2012 we unconditionally enforce the documented
6228                --  configuration pragma placement, since we do not want to
6229                --  tolerate mixed modes in a unit involving Ada 2012. That
6230                --  would cause real difficulties for those cases where there
6231                --  are incompatibilities between Ada 95 and Ada 2012. We could
6232                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6233
6234                Check_Valid_Configuration_Pragma;
6235
6236                --  Now set appropriate Ada mode
6237
6238                Ada_Version          := Ada_2012;
6239                Ada_Version_Explicit := Ada_2012;
6240             end if;
6241          end;
6242
6243          ----------------------
6244          -- All_Calls_Remote --
6245          ----------------------
6246
6247          --  pragma All_Calls_Remote [(library_package_NAME)];
6248
6249          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6250             Lib_Entity : Entity_Id;
6251
6252          begin
6253             Check_Ada_83_Warning;
6254             Check_Valid_Library_Unit_Pragma;
6255
6256             if Nkind (N) = N_Null_Statement then
6257                return;
6258             end if;
6259
6260             Lib_Entity := Find_Lib_Unit_Name;
6261
6262             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6263
6264             if Present (Lib_Entity)
6265               and then not Debug_Flag_U
6266             then
6267                if not Is_Remote_Call_Interface (Lib_Entity) then
6268                   Error_Pragma ("pragma% only apply to rci unit");
6269
6270                --  Set flag for entity of the library unit
6271
6272                else
6273                   Set_Has_All_Calls_Remote (Lib_Entity);
6274                end if;
6275
6276             end if;
6277          end All_Calls_Remote;
6278
6279          --------------
6280          -- Annotate --
6281          --------------
6282
6283          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6284          --  ARG ::= NAME | EXPRESSION
6285
6286          --  The first two arguments are by convention intended to refer to an
6287          --  external tool and a tool-specific function. These arguments are
6288          --  not analyzed.
6289
6290          when Pragma_Annotate => Annotate : declare
6291             Arg : Node_Id;
6292             Exp : Node_Id;
6293
6294          begin
6295             GNAT_Pragma;
6296             Check_At_Least_N_Arguments (1);
6297             Check_Arg_Is_Identifier (Arg1);
6298             Check_No_Identifiers;
6299             Store_Note (N);
6300
6301             --  Second parameter is optional, it is never analyzed
6302
6303             if No (Arg2) then
6304                null;
6305
6306             --  Here if we have a second parameter
6307
6308             else
6309                --  Second parameter must be identifier
6310
6311                Check_Arg_Is_Identifier (Arg2);
6312
6313                --  Process remaining parameters if any
6314
6315                Arg := Next (Arg2);
6316                while Present (Arg) loop
6317                   Exp := Get_Pragma_Arg (Arg);
6318                   Analyze (Exp);
6319
6320                   if Is_Entity_Name (Exp) then
6321                      null;
6322
6323                   --  For string literals, we assume Standard_String as the
6324                   --  type, unless the string contains wide or wide_wide
6325                   --  characters.
6326
6327                   elsif Nkind (Exp) = N_String_Literal then
6328                      if Has_Wide_Wide_Character (Exp) then
6329                         Resolve (Exp, Standard_Wide_Wide_String);
6330                      elsif Has_Wide_Character (Exp) then
6331                         Resolve (Exp, Standard_Wide_String);
6332                      else
6333                         Resolve (Exp, Standard_String);
6334                      end if;
6335
6336                   elsif Is_Overloaded (Exp) then
6337                         Error_Pragma_Arg
6338                           ("ambiguous argument for pragma%", Exp);
6339
6340                   else
6341                      Resolve (Exp);
6342                   end if;
6343
6344                   Next (Arg);
6345                end loop;
6346             end if;
6347          end Annotate;
6348
6349          ------------
6350          -- Assert --
6351          ------------
6352
6353          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6354          --                 [, [Message =>] Static_String_EXPRESSION]);
6355
6356          when Pragma_Assert => Assert : declare
6357             Expr : Node_Id;
6358             Newa : List_Id;
6359
6360          begin
6361             Ada_2005_Pragma;
6362             Check_At_Least_N_Arguments (1);
6363             Check_At_Most_N_Arguments (2);
6364             Check_Arg_Order ((Name_Check, Name_Message));
6365             Check_Optional_Identifier (Arg1, Name_Check);
6366
6367             --  We treat pragma Assert as equivalent to:
6368
6369             --    pragma Check (Assertion, condition [, msg]);
6370
6371             --  So rewrite pragma in this manner, and analyze the result
6372
6373             Expr := Get_Pragma_Arg (Arg1);
6374             Newa := New_List (
6375               Make_Pragma_Argument_Association (Loc,
6376                 Expression => Make_Identifier (Loc, Name_Assertion)),
6377
6378               Make_Pragma_Argument_Association (Sloc (Expr),
6379                 Expression => Expr));
6380
6381             if Arg_Count > 1 then
6382                Check_Optional_Identifier (Arg2, Name_Message);
6383                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6384                Append_To (Newa, Relocate_Node (Arg2));
6385             end if;
6386
6387             Rewrite (N,
6388               Make_Pragma (Loc,
6389                 Chars => Name_Check,
6390                 Pragma_Argument_Associations => Newa));
6391             Analyze (N);
6392          end Assert;
6393
6394          ----------------------
6395          -- Assertion_Policy --
6396          ----------------------
6397
6398          --  pragma Assertion_Policy (Check | Ignore)
6399
6400          when Pragma_Assertion_Policy => Assertion_Policy : declare
6401             Policy : Node_Id;
6402
6403          begin
6404             Ada_2005_Pragma;
6405             Check_Valid_Configuration_Pragma;
6406             Check_Arg_Count (1);
6407             Check_No_Identifiers;
6408             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6409
6410             --  We treat pragma Assertion_Policy as equivalent to:
6411
6412             --    pragma Check_Policy (Assertion, policy)
6413
6414             --  So rewrite the pragma in that manner and link on to the chain
6415             --  of Check_Policy pragmas, marking the pragma as analyzed.
6416
6417             Policy := Get_Pragma_Arg (Arg1);
6418
6419             Rewrite (N,
6420               Make_Pragma (Loc,
6421                 Chars => Name_Check_Policy,
6422
6423                 Pragma_Argument_Associations => New_List (
6424                   Make_Pragma_Argument_Association (Loc,
6425                     Expression => Make_Identifier (Loc, Name_Assertion)),
6426
6427                   Make_Pragma_Argument_Association (Loc,
6428                     Expression =>
6429                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6430
6431             Set_Analyzed (N);
6432             Set_Next_Pragma (N, Opt.Check_Policy_List);
6433             Opt.Check_Policy_List := N;
6434          end Assertion_Policy;
6435
6436          ------------------------------
6437          -- Assume_No_Invalid_Values --
6438          ------------------------------
6439
6440          --  pragma Assume_No_Invalid_Values (On | Off);
6441
6442          when Pragma_Assume_No_Invalid_Values =>
6443             GNAT_Pragma;
6444             Check_Valid_Configuration_Pragma;
6445             Check_Arg_Count (1);
6446             Check_No_Identifiers;
6447             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6448
6449             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6450                Assume_No_Invalid_Values := True;
6451             else
6452                Assume_No_Invalid_Values := False;
6453             end if;
6454
6455          ---------------
6456          -- AST_Entry --
6457          ---------------
6458
6459          --  pragma AST_Entry (entry_IDENTIFIER);
6460
6461          when Pragma_AST_Entry => AST_Entry : declare
6462             Ent : Node_Id;
6463
6464          begin
6465             GNAT_Pragma;
6466             Check_VMS (N);
6467             Check_Arg_Count (1);
6468             Check_No_Identifiers;
6469             Check_Arg_Is_Local_Name (Arg1);
6470             Ent := Entity (Get_Pragma_Arg (Arg1));
6471
6472             --  Note: the implementation of the AST_Entry pragma could handle
6473             --  the entry family case fine, but for now we are consistent with
6474             --  the DEC rules, and do not allow the pragma, which of course
6475             --  has the effect of also forbidding the attribute.
6476
6477             if Ekind (Ent) /= E_Entry then
6478                Error_Pragma_Arg
6479                  ("pragma% argument must be simple entry name", Arg1);
6480
6481             elsif Is_AST_Entry (Ent) then
6482                Error_Pragma_Arg
6483                  ("duplicate % pragma for entry", Arg1);
6484
6485             elsif Has_Homonym (Ent) then
6486                Error_Pragma_Arg
6487                  ("pragma% argument cannot specify overloaded entry", Arg1);
6488
6489             else
6490                declare
6491                   FF : constant Entity_Id := First_Formal (Ent);
6492
6493                begin
6494                   if Present (FF) then
6495                      if Present (Next_Formal (FF)) then
6496                         Error_Pragma_Arg
6497                           ("entry for pragma% can have only one argument",
6498                            Arg1);
6499
6500                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6501                         Error_Pragma_Arg
6502                           ("entry parameter for pragma% must have mode IN",
6503                            Arg1);
6504                      end if;
6505                   end if;
6506                end;
6507
6508                Set_Is_AST_Entry (Ent);
6509             end if;
6510          end AST_Entry;
6511
6512          ------------------
6513          -- Asynchronous --
6514          ------------------
6515
6516          --  pragma Asynchronous (LOCAL_NAME);
6517
6518          when Pragma_Asynchronous => Asynchronous : declare
6519             Nm     : Entity_Id;
6520             C_Ent  : Entity_Id;
6521             L      : List_Id;
6522             S      : Node_Id;
6523             N      : Node_Id;
6524             Formal : Entity_Id;
6525
6526             procedure Process_Async_Pragma;
6527             --  Common processing for procedure and access-to-procedure case
6528
6529             --------------------------
6530             -- Process_Async_Pragma --
6531             --------------------------
6532
6533             procedure Process_Async_Pragma is
6534             begin
6535                if No (L) then
6536                   Set_Is_Asynchronous (Nm);
6537                   return;
6538                end if;
6539
6540                --  The formals should be of mode IN (RM E.4.1(6))
6541
6542                S := First (L);
6543                while Present (S) loop
6544                   Formal := Defining_Identifier (S);
6545
6546                   if Nkind (Formal) = N_Defining_Identifier
6547                     and then Ekind (Formal) /= E_In_Parameter
6548                   then
6549                      Error_Pragma_Arg
6550                        ("pragma% procedure can only have IN parameter",
6551                         Arg1);
6552                   end if;
6553
6554                   Next (S);
6555                end loop;
6556
6557                Set_Is_Asynchronous (Nm);
6558             end Process_Async_Pragma;
6559
6560          --  Start of processing for pragma Asynchronous
6561
6562          begin
6563             Check_Ada_83_Warning;
6564             Check_No_Identifiers;
6565             Check_Arg_Count (1);
6566             Check_Arg_Is_Local_Name (Arg1);
6567
6568             if Debug_Flag_U then
6569                return;
6570             end if;
6571
6572             C_Ent := Cunit_Entity (Current_Sem_Unit);
6573             Analyze (Get_Pragma_Arg (Arg1));
6574             Nm := Entity (Get_Pragma_Arg (Arg1));
6575
6576             if not Is_Remote_Call_Interface (C_Ent)
6577               and then not Is_Remote_Types (C_Ent)
6578             then
6579                --  This pragma should only appear in an RCI or Remote Types
6580                --  unit (RM E.4.1(4)).
6581
6582                Error_Pragma
6583                  ("pragma% not in Remote_Call_Interface or " &
6584                   "Remote_Types unit");
6585             end if;
6586
6587             if Ekind (Nm) = E_Procedure
6588               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6589             then
6590                if not Is_Remote_Call_Interface (Nm) then
6591                   Error_Pragma_Arg
6592                     ("pragma% cannot be applied on non-remote procedure",
6593                      Arg1);
6594                end if;
6595
6596                L := Parameter_Specifications (Parent (Nm));
6597                Process_Async_Pragma;
6598                return;
6599
6600             elsif Ekind (Nm) = E_Function then
6601                Error_Pragma_Arg
6602                  ("pragma% cannot be applied to function", Arg1);
6603
6604             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6605                   if Is_Record_Type (Nm) then
6606
6607                   --  A record type that is the Equivalent_Type for a remote
6608                   --  access-to-subprogram type.
6609
6610                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6611
6612                   else
6613                      --  A non-expanded RAS type (distribution is not enabled)
6614
6615                      N := Declaration_Node (Nm);
6616                   end if;
6617
6618                if Nkind (N) = N_Full_Type_Declaration
6619                  and then Nkind (Type_Definition (N)) =
6620                                      N_Access_Procedure_Definition
6621                then
6622                   L := Parameter_Specifications (Type_Definition (N));
6623                   Process_Async_Pragma;
6624
6625                   if Is_Asynchronous (Nm)
6626                     and then Expander_Active
6627                     and then Get_PCS_Name /= Name_No_DSA
6628                   then
6629                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6630                   end if;
6631
6632                else
6633                   Error_Pragma_Arg
6634                     ("pragma% cannot reference access-to-function type",
6635                     Arg1);
6636                end if;
6637
6638             --  Only other possibility is Access-to-class-wide type
6639
6640             elsif Is_Access_Type (Nm)
6641               and then Is_Class_Wide_Type (Designated_Type (Nm))
6642             then
6643                Check_First_Subtype (Arg1);
6644                Set_Is_Asynchronous (Nm);
6645                if Expander_Active then
6646                   RACW_Type_Is_Asynchronous (Nm);
6647                end if;
6648
6649             else
6650                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6651             end if;
6652          end Asynchronous;
6653
6654          ------------
6655          -- Atomic --
6656          ------------
6657
6658          --  pragma Atomic (LOCAL_NAME);
6659
6660          when Pragma_Atomic =>
6661             Process_Atomic_Shared_Volatile;
6662
6663          -----------------------
6664          -- Atomic_Components --
6665          -----------------------
6666
6667          --  pragma Atomic_Components (array_LOCAL_NAME);
6668
6669          --  This processing is shared by Volatile_Components
6670
6671          when Pragma_Atomic_Components   |
6672               Pragma_Volatile_Components =>
6673
6674          Atomic_Components : declare
6675             E_Id : Node_Id;
6676             E    : Entity_Id;
6677             D    : Node_Id;
6678             K    : Node_Kind;
6679
6680          begin
6681             Check_Ada_83_Warning;
6682             Check_No_Identifiers;
6683             Check_Arg_Count (1);
6684             Check_Arg_Is_Local_Name (Arg1);
6685             E_Id := Get_Pragma_Arg (Arg1);
6686
6687             if Etype (E_Id) = Any_Type then
6688                return;
6689             end if;
6690
6691             E := Entity (E_Id);
6692
6693             Check_Duplicate_Pragma (E);
6694
6695             if Rep_Item_Too_Early (E, N)
6696                  or else
6697                Rep_Item_Too_Late (E, N)
6698             then
6699                return;
6700             end if;
6701
6702             D := Declaration_Node (E);
6703             K := Nkind (D);
6704
6705             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6706               or else
6707                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6708                    and then Nkind (D) = N_Object_Declaration
6709                    and then Nkind (Object_Definition (D)) =
6710                                        N_Constrained_Array_Definition)
6711             then
6712                --  The flag is set on the object, or on the base type
6713
6714                if Nkind (D) /= N_Object_Declaration then
6715                   E := Base_Type (E);
6716                end if;
6717
6718                Set_Has_Volatile_Components (E);
6719
6720                if Prag_Id = Pragma_Atomic_Components then
6721                   Set_Has_Atomic_Components (E);
6722                end if;
6723
6724             else
6725                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6726             end if;
6727          end Atomic_Components;
6728
6729          --------------------
6730          -- Attach_Handler --
6731          --------------------
6732
6733          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6734
6735          when Pragma_Attach_Handler =>
6736             Check_Ada_83_Warning;
6737             Check_No_Identifiers;
6738             Check_Arg_Count (2);
6739
6740             if No_Run_Time_Mode then
6741                Error_Msg_CRT ("Attach_Handler pragma", N);
6742             else
6743                Check_Interrupt_Or_Attach_Handler;
6744
6745                --  The expression that designates the attribute may depend on a
6746                --  discriminant, and is therefore a per- object expression, to
6747                --  be expanded in the init proc. If expansion is enabled, then
6748                --  perform semantic checks on a copy only.
6749
6750                if Expander_Active then
6751                   declare
6752                      Temp : constant Node_Id :=
6753                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6754                   begin
6755                      Set_Parent (Temp, N);
6756                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6757                   end;
6758
6759                else
6760                   Analyze (Get_Pragma_Arg (Arg2));
6761                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6762                end if;
6763
6764                Process_Interrupt_Or_Attach_Handler;
6765             end if;
6766
6767          --------------------
6768          -- C_Pass_By_Copy --
6769          --------------------
6770
6771          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6772
6773          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6774             Arg : Node_Id;
6775             Val : Uint;
6776
6777          begin
6778             GNAT_Pragma;
6779             Check_Valid_Configuration_Pragma;
6780             Check_Arg_Count (1);
6781             Check_Optional_Identifier (Arg1, "max_size");
6782
6783             Arg := Get_Pragma_Arg (Arg1);
6784             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6785
6786             Val := Expr_Value (Arg);
6787
6788             if Val <= 0 then
6789                Error_Pragma_Arg
6790                  ("maximum size for pragma% must be positive", Arg1);
6791
6792             elsif UI_Is_In_Int_Range (Val) then
6793                Default_C_Record_Mechanism := UI_To_Int (Val);
6794
6795             --  If a giant value is given, Int'Last will do well enough.
6796             --  If sometime someone complains that a record larger than
6797             --  two gigabytes is not copied, we will worry about it then!
6798
6799             else
6800                Default_C_Record_Mechanism := Mechanism_Type'Last;
6801             end if;
6802          end C_Pass_By_Copy;
6803
6804          -----------
6805          -- Check --
6806          -----------
6807
6808          --  pragma Check ([Name    =>] Identifier,
6809          --                [Check   =>] Boolean_Expression
6810          --              [,[Message =>] String_Expression]);
6811
6812          when Pragma_Check => Check : declare
6813             Expr : Node_Id;
6814             Eloc : Source_Ptr;
6815
6816             Check_On : Boolean;
6817             --  Set True if category of assertions referenced by Name enabled
6818
6819          begin
6820             GNAT_Pragma;
6821             Check_At_Least_N_Arguments (2);
6822             Check_At_Most_N_Arguments (3);
6823             Check_Optional_Identifier (Arg1, Name_Name);
6824             Check_Optional_Identifier (Arg2, Name_Check);
6825
6826             if Arg_Count = 3 then
6827                Check_Optional_Identifier (Arg3, Name_Message);
6828                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6829             end if;
6830
6831             Check_Arg_Is_Identifier (Arg1);
6832
6833             --  Indicate if pragma is enabled. The Original_Node reference here
6834             --  is to deal with pragma Assert rewritten as a Check pragma.
6835
6836             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6837
6838             if Check_On then
6839                Set_SCO_Pragma_Enabled (Loc);
6840             end if;
6841
6842             --  If expansion is active and the check is not enabled then we
6843             --  rewrite the Check as:
6844
6845             --    if False and then condition then
6846             --       null;
6847             --    end if;
6848
6849             --  The reason we do this rewriting during semantic analysis rather
6850             --  than as part of normal expansion is that we cannot analyze and
6851             --  expand the code for the boolean expression directly, or it may
6852             --  cause insertion of actions that would escape the attempt to
6853             --  suppress the check code.
6854
6855             --  Note that the Sloc for the if statement corresponds to the
6856             --  argument condition, not the pragma itself. The reason for this
6857             --  is that we may generate a warning if the condition is False at
6858             --  compile time, and we do not want to delete this warning when we
6859             --  delete the if statement.
6860
6861             Expr := Get_Pragma_Arg (Arg2);
6862
6863             if Expander_Active and then not Check_On then
6864                Eloc := Sloc (Expr);
6865
6866                Rewrite (N,
6867                  Make_If_Statement (Eloc,
6868                    Condition =>
6869                      Make_And_Then (Eloc,
6870                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
6871                        Right_Opnd => Expr),
6872                    Then_Statements => New_List (
6873                      Make_Null_Statement (Eloc))));
6874
6875                Analyze (N);
6876
6877             --  Check is active
6878
6879             else
6880                Analyze_And_Resolve (Expr, Any_Boolean);
6881             end if;
6882          end Check;
6883
6884          ----------------
6885          -- Check_Name --
6886          ----------------
6887
6888          --  pragma Check_Name (check_IDENTIFIER);
6889
6890          when Pragma_Check_Name =>
6891             Check_No_Identifiers;
6892             GNAT_Pragma;
6893             Check_Valid_Configuration_Pragma;
6894             Check_Arg_Count (1);
6895             Check_Arg_Is_Identifier (Arg1);
6896
6897             declare
6898                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6899
6900             begin
6901                for J in Check_Names.First .. Check_Names.Last loop
6902                   if Check_Names.Table (J) = Nam then
6903                      return;
6904                   end if;
6905                end loop;
6906
6907                Check_Names.Append (Nam);
6908             end;
6909
6910          ------------------
6911          -- Check_Policy --
6912          ------------------
6913
6914          --  pragma Check_Policy (
6915          --    [Name   =>] IDENTIFIER,
6916          --    [Policy =>] POLICY_IDENTIFIER);
6917
6918          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6919
6920          --  Note: this is a configuration pragma, but it is allowed to appear
6921          --  anywhere else.
6922
6923          when Pragma_Check_Policy =>
6924             GNAT_Pragma;
6925             Check_Arg_Count (2);
6926             Check_Optional_Identifier (Arg1, Name_Name);
6927             Check_Optional_Identifier (Arg2, Name_Policy);
6928             Check_Arg_Is_One_Of
6929               (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6930
6931             --  A Check_Policy pragma can appear either as a configuration
6932             --  pragma, or in a declarative part or a package spec (see RM
6933             --  11.5(5) for rules for Suppress/Unsuppress which are also
6934             --  followed for Check_Policy).
6935
6936             if not Is_Configuration_Pragma then
6937                Check_Is_In_Decl_Part_Or_Package_Spec;
6938             end if;
6939
6940             Set_Next_Pragma (N, Opt.Check_Policy_List);
6941             Opt.Check_Policy_List := N;
6942
6943          ---------------------
6944          -- CIL_Constructor --
6945          ---------------------
6946
6947          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6948
6949          --  Processing for this pragma is shared with Java_Constructor
6950
6951          -------------
6952          -- Comment --
6953          -------------
6954
6955          --  pragma Comment (static_string_EXPRESSION)
6956
6957          --  Processing for pragma Comment shares the circuitry for pragma
6958          --  Ident. The only differences are that Ident enforces a limit of 31
6959          --  characters on its argument, and also enforces limitations on
6960          --  placement for DEC compatibility. Pragma Comment shares neither of
6961          --  these restrictions.
6962
6963          -------------------
6964          -- Common_Object --
6965          -------------------
6966
6967          --  pragma Common_Object (
6968          --        [Internal =>] LOCAL_NAME
6969          --     [, [External =>] EXTERNAL_SYMBOL]
6970          --     [, [Size     =>] EXTERNAL_SYMBOL]);
6971
6972          --  Processing for this pragma is shared with Psect_Object
6973
6974          ------------------------
6975          -- Compile_Time_Error --
6976          ------------------------
6977
6978          --  pragma Compile_Time_Error
6979          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6980
6981          when Pragma_Compile_Time_Error =>
6982             GNAT_Pragma;
6983             Process_Compile_Time_Warning_Or_Error;
6984
6985          --------------------------
6986          -- Compile_Time_Warning --
6987          --------------------------
6988
6989          --  pragma Compile_Time_Warning
6990          --    (boolean_EXPRESSION, static_string_EXPRESSION);
6991
6992          when Pragma_Compile_Time_Warning =>
6993             GNAT_Pragma;
6994             Process_Compile_Time_Warning_Or_Error;
6995
6996          -------------------
6997          -- Compiler_Unit --
6998          -------------------
6999
7000          when Pragma_Compiler_Unit =>
7001             GNAT_Pragma;
7002             Check_Arg_Count (0);
7003             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7004
7005          -----------------------------
7006          -- Complete_Representation --
7007          -----------------------------
7008
7009          --  pragma Complete_Representation;
7010
7011          when Pragma_Complete_Representation =>
7012             GNAT_Pragma;
7013             Check_Arg_Count (0);
7014
7015             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7016                Error_Pragma
7017                  ("pragma & must appear within record representation clause");
7018             end if;
7019
7020          ----------------------------
7021          -- Complex_Representation --
7022          ----------------------------
7023
7024          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7025
7026          when Pragma_Complex_Representation => Complex_Representation : declare
7027             E_Id : Entity_Id;
7028             E    : Entity_Id;
7029             Ent  : Entity_Id;
7030
7031          begin
7032             GNAT_Pragma;
7033             Check_Arg_Count (1);
7034             Check_Optional_Identifier (Arg1, Name_Entity);
7035             Check_Arg_Is_Local_Name (Arg1);
7036             E_Id := Get_Pragma_Arg (Arg1);
7037
7038             if Etype (E_Id) = Any_Type then
7039                return;
7040             end if;
7041
7042             E := Entity (E_Id);
7043
7044             if not Is_Record_Type (E) then
7045                Error_Pragma_Arg
7046                  ("argument for pragma% must be record type", Arg1);
7047             end if;
7048
7049             Ent := First_Entity (E);
7050
7051             if No (Ent)
7052               or else No (Next_Entity (Ent))
7053               or else Present (Next_Entity (Next_Entity (Ent)))
7054               or else not Is_Floating_Point_Type (Etype (Ent))
7055               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7056             then
7057                Error_Pragma_Arg
7058                  ("record for pragma% must have two fields of the same "
7059                   & "floating-point type", Arg1);
7060
7061             else
7062                Set_Has_Complex_Representation (Base_Type (E));
7063
7064                --  We need to treat the type has having a non-standard
7065                --  representation, for back-end purposes, even though in
7066                --  general a complex will have the default representation
7067                --  of a record with two real components.
7068
7069                Set_Has_Non_Standard_Rep (Base_Type (E));
7070             end if;
7071          end Complex_Representation;
7072
7073          -------------------------
7074          -- Component_Alignment --
7075          -------------------------
7076
7077          --  pragma Component_Alignment (
7078          --        [Form =>] ALIGNMENT_CHOICE
7079          --     [, [Name =>] type_LOCAL_NAME]);
7080          --
7081          --   ALIGNMENT_CHOICE ::=
7082          --     Component_Size
7083          --   | Component_Size_4
7084          --   | Storage_Unit
7085          --   | Default
7086
7087          when Pragma_Component_Alignment => Component_AlignmentP : declare
7088             Args  : Args_List (1 .. 2);
7089             Names : constant Name_List (1 .. 2) := (
7090                       Name_Form,
7091                       Name_Name);
7092
7093             Form  : Node_Id renames Args (1);
7094             Name  : Node_Id renames Args (2);
7095
7096             Atype : Component_Alignment_Kind;
7097             Typ   : Entity_Id;
7098
7099          begin
7100             GNAT_Pragma;
7101             Gather_Associations (Names, Args);
7102
7103             if No (Form) then
7104                Error_Pragma ("missing Form argument for pragma%");
7105             end if;
7106
7107             Check_Arg_Is_Identifier (Form);
7108
7109             --  Get proper alignment, note that Default = Component_Size on all
7110             --  machines we have so far, and we want to set this value rather
7111             --  than the default value to indicate that it has been explicitly
7112             --  set (and thus will not get overridden by the default component
7113             --  alignment for the current scope)
7114
7115             if Chars (Form) = Name_Component_Size then
7116                Atype := Calign_Component_Size;
7117
7118             elsif Chars (Form) = Name_Component_Size_4 then
7119                Atype := Calign_Component_Size_4;
7120
7121             elsif Chars (Form) = Name_Default then
7122                Atype := Calign_Component_Size;
7123
7124             elsif Chars (Form) = Name_Storage_Unit then
7125                Atype := Calign_Storage_Unit;
7126
7127             else
7128                Error_Pragma_Arg
7129                  ("invalid Form parameter for pragma%", Form);
7130             end if;
7131
7132             --  Case with no name, supplied, affects scope table entry
7133
7134             if No (Name) then
7135                Scope_Stack.Table
7136                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7137
7138             --  Case of name supplied
7139
7140             else
7141                Check_Arg_Is_Local_Name (Name);
7142                Find_Type (Name);
7143                Typ := Entity (Name);
7144
7145                if Typ = Any_Type
7146                  or else Rep_Item_Too_Early (Typ, N)
7147                then
7148                   return;
7149                else
7150                   Typ := Underlying_Type (Typ);
7151                end if;
7152
7153                if not Is_Record_Type (Typ)
7154                  and then not Is_Array_Type (Typ)
7155                then
7156                   Error_Pragma_Arg
7157                     ("Name parameter of pragma% must identify record or " &
7158                      "array type", Name);
7159                end if;
7160
7161                --  An explicit Component_Alignment pragma overrides an
7162                --  implicit pragma Pack, but not an explicit one.
7163
7164                if not Has_Pragma_Pack (Base_Type (Typ)) then
7165                   Set_Is_Packed (Base_Type (Typ), False);
7166                   Set_Component_Alignment (Base_Type (Typ), Atype);
7167                end if;
7168             end if;
7169          end Component_AlignmentP;
7170
7171          ----------------
7172          -- Controlled --
7173          ----------------
7174
7175          --  pragma Controlled (first_subtype_LOCAL_NAME);
7176
7177          when Pragma_Controlled => Controlled : declare
7178             Arg : Node_Id;
7179
7180          begin
7181             Check_No_Identifiers;
7182             Check_Arg_Count (1);
7183             Check_Arg_Is_Local_Name (Arg1);
7184             Arg := Get_Pragma_Arg (Arg1);
7185
7186             if not Is_Entity_Name (Arg)
7187               or else not Is_Access_Type (Entity (Arg))
7188             then
7189                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7190             else
7191                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7192             end if;
7193          end Controlled;
7194
7195          ----------------
7196          -- Convention --
7197          ----------------
7198
7199          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7200          --    [Entity =>] LOCAL_NAME);
7201
7202          when Pragma_Convention => Convention : declare
7203             C : Convention_Id;
7204             E : Entity_Id;
7205             pragma Warnings (Off, C);
7206             pragma Warnings (Off, E);
7207          begin
7208             Check_Arg_Order ((Name_Convention, Name_Entity));
7209             Check_Ada_83_Warning;
7210             Check_Arg_Count (2);
7211             Process_Convention (C, E);
7212          end Convention;
7213
7214          ---------------------------
7215          -- Convention_Identifier --
7216          ---------------------------
7217
7218          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7219          --    [Convention =>] convention_IDENTIFIER);
7220
7221          when Pragma_Convention_Identifier => Convention_Identifier : declare
7222             Idnam : Name_Id;
7223             Cname : Name_Id;
7224
7225          begin
7226             GNAT_Pragma;
7227             Check_Arg_Order ((Name_Name, Name_Convention));
7228             Check_Arg_Count (2);
7229             Check_Optional_Identifier (Arg1, Name_Name);
7230             Check_Optional_Identifier (Arg2, Name_Convention);
7231             Check_Arg_Is_Identifier (Arg1);
7232             Check_Arg_Is_Identifier (Arg2);
7233             Idnam := Chars (Get_Pragma_Arg (Arg1));
7234             Cname := Chars (Get_Pragma_Arg (Arg2));
7235
7236             if Is_Convention_Name (Cname) then
7237                Record_Convention_Identifier
7238                  (Idnam, Get_Convention_Id (Cname));
7239             else
7240                Error_Pragma_Arg
7241                  ("second arg for % pragma must be convention", Arg2);
7242             end if;
7243          end Convention_Identifier;
7244
7245          ---------------
7246          -- CPP_Class --
7247          ---------------
7248
7249          --  pragma CPP_Class ([Entity =>] local_NAME)
7250
7251          when Pragma_CPP_Class => CPP_Class : declare
7252             Arg : Node_Id;
7253             Typ : Entity_Id;
7254
7255          begin
7256             if Warn_On_Obsolescent_Feature then
7257                Error_Msg_N
7258                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7259                   " by pragma import?", N);
7260             end if;
7261
7262             GNAT_Pragma;
7263             Check_Arg_Count (1);
7264             Check_Optional_Identifier (Arg1, Name_Entity);
7265             Check_Arg_Is_Local_Name (Arg1);
7266
7267             Arg := Get_Pragma_Arg (Arg1);
7268             Analyze (Arg);
7269
7270             if Etype (Arg) = Any_Type then
7271                return;
7272             end if;
7273
7274             if not Is_Entity_Name (Arg)
7275               or else not Is_Type (Entity (Arg))
7276             then
7277                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7278             end if;
7279
7280             Typ := Entity (Arg);
7281
7282             if not Is_Tagged_Type (Typ) then
7283                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7284             end if;
7285
7286             --  Types treated as CPP classes must be declared limited (note:
7287             --  this used to be a warning but there is no real benefit to it
7288             --  since we did effectively intend to treat the type as limited
7289             --  anyway).
7290
7291             if not Is_Limited_Type (Typ) then
7292                Error_Msg_N
7293                  ("imported 'C'P'P type must be limited",
7294                   Get_Pragma_Arg (Arg1));
7295             end if;
7296
7297             Set_Is_CPP_Class      (Typ);
7298             Set_Convention        (Typ, Convention_CPP);
7299
7300             --  Imported CPP types must not have discriminants (because C++
7301             --  classes do not have discriminants).
7302
7303             if Has_Discriminants (Typ) then
7304                Error_Msg_N
7305                  ("imported 'C'P'P type cannot have discriminants",
7306                   First (Discriminant_Specifications
7307                           (Declaration_Node (Typ))));
7308             end if;
7309
7310             --  Components of imported CPP types must not have default
7311             --  expressions because the constructor (if any) is in the
7312             --  C++ side.
7313
7314             if Is_Incomplete_Or_Private_Type (Typ)
7315               and then No (Underlying_Type (Typ))
7316             then
7317                --  It should be an error to apply pragma CPP to a private
7318                --  type if the underlying type is not visible (as it is
7319                --  for any representation item). For now, for backward
7320                --  compatibility we do nothing but we cannot check components
7321                --  because they are not available at this stage. All this code
7322                --  will be removed when we cleanup this obsolete GNAT pragma???
7323
7324                null;
7325
7326             else
7327                declare
7328                   Tdef  : constant Node_Id :=
7329                             Type_Definition (Declaration_Node (Typ));
7330                   Clist : Node_Id;
7331                   Comp  : Node_Id;
7332
7333                begin
7334                   if Nkind (Tdef) = N_Record_Definition then
7335                      Clist := Component_List (Tdef);
7336                   else
7337                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7338                      Clist := Component_List (Record_Extension_Part (Tdef));
7339                   end if;
7340
7341                   if Present (Clist) then
7342                      Comp := First (Component_Items (Clist));
7343                      while Present (Comp) loop
7344                         if Present (Expression (Comp)) then
7345                            Error_Msg_N
7346                              ("component of imported 'C'P'P type cannot have" &
7347                               " default expression", Expression (Comp));
7348                         end if;
7349
7350                         Next (Comp);
7351                      end loop;
7352                   end if;
7353                end;
7354             end if;
7355          end CPP_Class;
7356
7357          ---------------------
7358          -- CPP_Constructor --
7359          ---------------------
7360
7361          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7362          --    [, [External_Name =>] static_string_EXPRESSION ]
7363          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7364
7365          when Pragma_CPP_Constructor => CPP_Constructor : declare
7366             Elmt    : Elmt_Id;
7367             Id      : Entity_Id;
7368             Def_Id  : Entity_Id;
7369             Tag_Typ : Entity_Id;
7370
7371          begin
7372             GNAT_Pragma;
7373             Check_At_Least_N_Arguments (1);
7374             Check_At_Most_N_Arguments (3);
7375             Check_Optional_Identifier (Arg1, Name_Entity);
7376             Check_Arg_Is_Local_Name (Arg1);
7377
7378             Id := Get_Pragma_Arg (Arg1);
7379             Find_Program_Unit_Name (Id);
7380
7381             --  If we did not find the name, we are done
7382
7383             if Etype (Id) = Any_Type then
7384                return;
7385             end if;
7386
7387             Def_Id := Entity (Id);
7388
7389             --  Check if already defined as constructor
7390
7391             if Is_Constructor (Def_Id) then
7392                Error_Msg_N
7393                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7394                return;
7395             end if;
7396
7397             if Ekind (Def_Id) = E_Function
7398               and then (Is_CPP_Class (Etype (Def_Id))
7399                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7400                                    and then
7401                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7402             then
7403                if Arg_Count >= 2 then
7404                   Set_Imported (Def_Id);
7405                   Set_Is_Public (Def_Id);
7406                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7407                end if;
7408
7409                Set_Has_Completion (Def_Id);
7410                Set_Is_Constructor (Def_Id);
7411
7412                --  Imported C++ constructors are not dispatching primitives
7413                --  because in C++ they don't have a dispatch table slot.
7414                --  However, in Ada the constructor has the profile of a
7415                --  function that returns a tagged type and therefore it has
7416                --  been treated as a primitive operation during semantic
7417                --  analysis. We now remove it from the list of primitive
7418                --  operations of the type.
7419
7420                if Is_Tagged_Type (Etype (Def_Id))
7421                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7422                then
7423                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7424                   Tag_Typ := Etype (Def_Id);
7425
7426                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7427                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7428                      Next_Elmt (Elmt);
7429                   end loop;
7430
7431                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7432                   Set_Is_Dispatching_Operation (Def_Id, False);
7433                end if;
7434
7435                --  For backward compatibility, if the constructor returns a
7436                --  class wide type, and we internally change the return type to
7437                --  the corresponding root type.
7438
7439                if Is_Class_Wide_Type (Etype (Def_Id)) then
7440                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7441                end if;
7442             else
7443                Error_Pragma_Arg
7444                  ("pragma% requires function returning a 'C'P'P_Class type",
7445                    Arg1);
7446             end if;
7447          end CPP_Constructor;
7448
7449          -----------------
7450          -- CPP_Virtual --
7451          -----------------
7452
7453          when Pragma_CPP_Virtual => CPP_Virtual : declare
7454          begin
7455             GNAT_Pragma;
7456
7457             if Warn_On_Obsolescent_Feature then
7458                Error_Msg_N
7459                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7460                   "no effect?", N);
7461             end if;
7462          end CPP_Virtual;
7463
7464          ----------------
7465          -- CPP_Vtable --
7466          ----------------
7467
7468          when Pragma_CPP_Vtable => CPP_Vtable : declare
7469          begin
7470             GNAT_Pragma;
7471
7472             if Warn_On_Obsolescent_Feature then
7473                Error_Msg_N
7474                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7475                   "no effect?", N);
7476             end if;
7477          end CPP_Vtable;
7478
7479          ---------
7480          -- CPU --
7481          ---------
7482
7483          --  pragma CPU (EXPRESSION);
7484
7485          when Pragma_CPU => CPU : declare
7486             P   : constant Node_Id := Parent (N);
7487             Arg : Node_Id;
7488
7489          begin
7490             Ada_2012_Pragma;
7491             Check_No_Identifiers;
7492             Check_Arg_Count (1);
7493
7494             --  Subprogram case
7495
7496             if Nkind (P) = N_Subprogram_Body then
7497                Check_In_Main_Program;
7498
7499                Arg := Get_Pragma_Arg (Arg1);
7500                Analyze_And_Resolve (Arg, Any_Integer);
7501
7502                --  Must be static
7503
7504                if not Is_Static_Expression (Arg) then
7505                   Flag_Non_Static_Expr
7506                     ("main subprogram affinity is not static!", Arg);
7507                   raise Pragma_Exit;
7508
7509                --  If constraint error, then we already signalled an error
7510
7511                elsif Raises_Constraint_Error (Arg) then
7512                   null;
7513
7514                --  Otherwise check in range
7515
7516                else
7517                   declare
7518                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7519                      --  This is the entity System.Multiprocessors.CPU_Range;
7520
7521                      Val : constant Uint := Expr_Value (Arg);
7522
7523                   begin
7524                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7525                           or else
7526                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7527                      then
7528                         Error_Pragma_Arg
7529                           ("main subprogram CPU is out of range", Arg1);
7530                      end if;
7531                   end;
7532                end if;
7533
7534                Set_Main_CPU
7535                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7536
7537             --  Task case
7538
7539             elsif Nkind (P) = N_Task_Definition then
7540                Arg := Get_Pragma_Arg (Arg1);
7541
7542                --  The expression must be analyzed in the special manner
7543                --  described in "Handling of Default and Per-Object
7544                --  Expressions" in sem.ads.
7545
7546                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7547
7548             --  Anything else is incorrect
7549
7550             else
7551                Pragma_Misplaced;
7552             end if;
7553
7554             if Has_Pragma_CPU (P) then
7555                Error_Pragma ("duplicate pragma% not allowed");
7556             else
7557                Set_Has_Pragma_CPU (P, True);
7558
7559                if Nkind (P) = N_Task_Definition then
7560                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7561                end if;
7562             end if;
7563          end CPU;
7564
7565          -----------
7566          -- Debug --
7567          -----------
7568
7569          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7570
7571          when Pragma_Debug => Debug : declare
7572             Cond : Node_Id;
7573             Call : Node_Id;
7574
7575          begin
7576             GNAT_Pragma;
7577
7578             Cond :=
7579               New_Occurrence_Of
7580                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7581                  Loc);
7582
7583             if Arg_Count = 2 then
7584                Cond :=
7585                  Make_And_Then (Loc,
7586                    Left_Opnd  => Relocate_Node (Cond),
7587                    Right_Opnd => Get_Pragma_Arg (Arg1));
7588                Call := Get_Pragma_Arg (Arg2);
7589             else
7590                Call := Get_Pragma_Arg (Arg1);
7591             end if;
7592
7593             if Nkind_In (Call,
7594                  N_Indexed_Component,
7595                  N_Function_Call,
7596                  N_Identifier,
7597                  N_Selected_Component)
7598             then
7599                --  If this pragma Debug comes from source, its argument was
7600                --  parsed as a name form (which is syntactically identical).
7601                --  Change it to a procedure call statement now.
7602
7603                Change_Name_To_Procedure_Call_Statement (Call);
7604
7605             elsif Nkind (Call) = N_Procedure_Call_Statement then
7606
7607                --  Already in the form of a procedure call statement: nothing
7608                --  to do (could happen in case of an internally generated
7609                --  pragma Debug).
7610
7611                null;
7612
7613             else
7614                --  All other cases: diagnose error
7615
7616                Error_Msg
7617                  ("argument of pragma% is not procedure call", Sloc (Call));
7618                return;
7619             end if;
7620
7621             --  Rewrite into a conditional with an appropriate condition. We
7622             --  wrap the procedure call in a block so that overhead from e.g.
7623             --  use of the secondary stack does not generate execution overhead
7624             --  for suppressed conditions.
7625
7626             Rewrite (N, Make_Implicit_If_Statement (N,
7627               Condition => Cond,
7628                  Then_Statements => New_List (
7629                    Make_Block_Statement (Loc,
7630                      Handled_Statement_Sequence =>
7631                        Make_Handled_Sequence_Of_Statements (Loc,
7632                          Statements => New_List (Relocate_Node (Call)))))));
7633             Analyze (N);
7634          end Debug;
7635
7636          ------------------
7637          -- Debug_Policy --
7638          ------------------
7639
7640          --  pragma Debug_Policy (Check | Ignore)
7641
7642          when Pragma_Debug_Policy =>
7643             GNAT_Pragma;
7644             Check_Arg_Count (1);
7645             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7646             Debug_Pragmas_Enabled :=
7647               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7648
7649          ---------------------
7650          -- Detect_Blocking --
7651          ---------------------
7652
7653          --  pragma Detect_Blocking;
7654
7655          when Pragma_Detect_Blocking =>
7656             Ada_2005_Pragma;
7657             Check_Arg_Count (0);
7658             Check_Valid_Configuration_Pragma;
7659             Detect_Blocking := True;
7660
7661          --------------------------
7662          -- Default_Storage_Pool --
7663          --------------------------
7664
7665          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7666
7667          when Pragma_Default_Storage_Pool =>
7668             Ada_2012_Pragma;
7669             Check_Arg_Count (1);
7670
7671             --  Default_Storage_Pool can appear as a configuration pragma, or
7672             --  in a declarative part or a package spec.
7673
7674             if not Is_Configuration_Pragma then
7675                Check_Is_In_Decl_Part_Or_Package_Spec;
7676             end if;
7677
7678             --  Case of Default_Storage_Pool (null);
7679
7680             if Nkind (Expression (Arg1)) = N_Null then
7681                Analyze (Expression (Arg1));
7682
7683                --  This is an odd case, this is not really an expression, so
7684                --  we don't have a type for it. So just set the type to Empty.
7685
7686                Set_Etype (Expression (Arg1), Empty);
7687
7688             --  Case of Default_Storage_Pool (storage_pool_NAME);
7689
7690             else
7691                --  If it's a configuration pragma, then the only allowed
7692                --  argument is "null".
7693
7694                if Is_Configuration_Pragma then
7695                   Error_Pragma_Arg ("NULL expected", Arg1);
7696                end if;
7697
7698                --  The expected type for a non-"null" argument is
7699                --  Root_Storage_Pool'Class.
7700
7701                Analyze_And_Resolve
7702                  (Get_Pragma_Arg (Arg1),
7703                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7704             end if;
7705
7706             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7707             --  for an access type will use this information to set the
7708             --  appropriate attributes of the access type.
7709
7710             Default_Pool := Expression (Arg1);
7711
7712          ---------------
7713          -- Dimension --
7714          ---------------
7715
7716          when Pragma_Dimension =>
7717             GNAT_Pragma;
7718             Check_Arg_Count (4);
7719             Check_No_Identifiers;
7720             Check_Arg_Is_Local_Name (Arg1);
7721
7722             if not Is_Type (Arg1) then
7723                Error_Pragma ("first argument for pragma% must be subtype");
7724             end if;
7725
7726             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7727             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7728             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7729
7730          -------------------
7731          -- Discard_Names --
7732          -------------------
7733
7734          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7735
7736          when Pragma_Discard_Names => Discard_Names : declare
7737             E    : Entity_Id;
7738             E_Id : Entity_Id;
7739
7740          begin
7741             Check_Ada_83_Warning;
7742
7743             --  Deal with configuration pragma case
7744
7745             if Arg_Count = 0 and then Is_Configuration_Pragma then
7746                Global_Discard_Names := True;
7747                return;
7748
7749             --  Otherwise, check correct appropriate context
7750
7751             else
7752                Check_Is_In_Decl_Part_Or_Package_Spec;
7753
7754                if Arg_Count = 0 then
7755
7756                   --  If there is no parameter, then from now on this pragma
7757                   --  applies to any enumeration, exception or tagged type
7758                   --  defined in the current declarative part, and recursively
7759                   --  to any nested scope.
7760
7761                   Set_Discard_Names (Current_Scope);
7762                   return;
7763
7764                else
7765                   Check_Arg_Count (1);
7766                   Check_Optional_Identifier (Arg1, Name_On);
7767                   Check_Arg_Is_Local_Name (Arg1);
7768
7769                   E_Id := Get_Pragma_Arg (Arg1);
7770
7771                   if Etype (E_Id) = Any_Type then
7772                      return;
7773                   else
7774                      E := Entity (E_Id);
7775                   end if;
7776
7777                   if (Is_First_Subtype (E)
7778                       and then
7779                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7780                     or else Ekind (E) = E_Exception
7781                   then
7782                      Set_Discard_Names (E);
7783                   else
7784                      Error_Pragma_Arg
7785                        ("inappropriate entity for pragma%", Arg1);
7786                   end if;
7787
7788                end if;
7789             end if;
7790          end Discard_Names;
7791
7792          ---------------
7793          -- Elaborate --
7794          ---------------
7795
7796          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7797
7798          when Pragma_Elaborate => Elaborate : declare
7799             Arg   : Node_Id;
7800             Citem : Node_Id;
7801
7802          begin
7803             --  Pragma must be in context items list of a compilation unit
7804
7805             if not Is_In_Context_Clause then
7806                Pragma_Misplaced;
7807             end if;
7808
7809             --  Must be at least one argument
7810
7811             if Arg_Count = 0 then
7812                Error_Pragma ("pragma% requires at least one argument");
7813             end if;
7814
7815             --  In Ada 83 mode, there can be no items following it in the
7816             --  context list except other pragmas and implicit with clauses
7817             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7818             --  placement rule does not apply.
7819
7820             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7821                Citem := Next (N);
7822                while Present (Citem) loop
7823                   if Nkind (Citem) = N_Pragma
7824                     or else (Nkind (Citem) = N_With_Clause
7825                               and then Implicit_With (Citem))
7826                   then
7827                      null;
7828                   else
7829                      Error_Pragma
7830                        ("(Ada 83) pragma% must be at end of context clause");
7831                   end if;
7832
7833                   Next (Citem);
7834                end loop;
7835             end if;
7836
7837             --  Finally, the arguments must all be units mentioned in a with
7838             --  clause in the same context clause. Note we already checked (in
7839             --  Par.Prag) that the arguments are all identifiers or selected
7840             --  components.
7841
7842             Arg := Arg1;
7843             Outer : while Present (Arg) loop
7844                Citem := First (List_Containing (N));
7845                Inner : while Citem /= N loop
7846                   if Nkind (Citem) = N_With_Clause
7847                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7848                   then
7849                      Set_Elaborate_Present (Citem, True);
7850                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7851                      Generate_Reference (Entity (Name (Citem)), Citem);
7852
7853                      --  With the pragma present, elaboration calls on
7854                      --  subprograms from the named unit need no further
7855                      --  checks, as long as the pragma appears in the current
7856                      --  compilation unit. If the pragma appears in some unit
7857                      --  in the context, there might still be a need for an
7858                      --  Elaborate_All_Desirable from the current compilation
7859                      --  to the named unit, so we keep the check enabled.
7860
7861                      if In_Extended_Main_Source_Unit (N) then
7862                         Set_Suppress_Elaboration_Warnings
7863                           (Entity (Name (Citem)));
7864                      end if;
7865
7866                      exit Inner;
7867                   end if;
7868
7869                   Next (Citem);
7870                end loop Inner;
7871
7872                if Citem = N then
7873                   Error_Pragma_Arg
7874                     ("argument of pragma% is not with'ed unit", Arg);
7875                end if;
7876
7877                Next (Arg);
7878             end loop Outer;
7879
7880             --  Give a warning if operating in static mode with -gnatwl
7881             --  (elaboration warnings enabled) switch set.
7882
7883             if Elab_Warnings and not Dynamic_Elaboration_Checks then
7884                Error_Msg_N
7885                  ("?use of pragma Elaborate may not be safe", N);
7886                Error_Msg_N
7887                  ("?use pragma Elaborate_All instead if possible", N);
7888             end if;
7889          end Elaborate;
7890
7891          -------------------
7892          -- Elaborate_All --
7893          -------------------
7894
7895          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7896
7897          when Pragma_Elaborate_All => Elaborate_All : declare
7898             Arg   : Node_Id;
7899             Citem : Node_Id;
7900
7901          begin
7902             Check_Ada_83_Warning;
7903
7904             --  Pragma must be in context items list of a compilation unit
7905
7906             if not Is_In_Context_Clause then
7907                Pragma_Misplaced;
7908             end if;
7909
7910             --  Must be at least one argument
7911
7912             if Arg_Count = 0 then
7913                Error_Pragma ("pragma% requires at least one argument");
7914             end if;
7915
7916             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
7917             --  have to appear at the end of the context clause, but may
7918             --  appear mixed in with other items, even in Ada 83 mode.
7919
7920             --  Final check: the arguments must all be units mentioned in
7921             --  a with clause in the same context clause. Note that we
7922             --  already checked (in Par.Prag) that all the arguments are
7923             --  either identifiers or selected components.
7924
7925             Arg := Arg1;
7926             Outr : while Present (Arg) loop
7927                Citem := First (List_Containing (N));
7928                Innr : while Citem /= N loop
7929                   if Nkind (Citem) = N_With_Clause
7930                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7931                   then
7932                      Set_Elaborate_All_Present (Citem, True);
7933                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7934
7935                      --  Suppress warnings and elaboration checks on the named
7936                      --  unit if the pragma is in the current compilation, as
7937                      --  for pragma Elaborate.
7938
7939                      if In_Extended_Main_Source_Unit (N) then
7940                         Set_Suppress_Elaboration_Warnings
7941                           (Entity (Name (Citem)));
7942                      end if;
7943                      exit Innr;
7944                   end if;
7945
7946                   Next (Citem);
7947                end loop Innr;
7948
7949                if Citem = N then
7950                   Set_Error_Posted (N);
7951                   Error_Pragma_Arg
7952                     ("argument of pragma% is not with'ed unit", Arg);
7953                end if;
7954
7955                Next (Arg);
7956             end loop Outr;
7957          end Elaborate_All;
7958
7959          --------------------
7960          -- Elaborate_Body --
7961          --------------------
7962
7963          --  pragma Elaborate_Body [( library_unit_NAME )];
7964
7965          when Pragma_Elaborate_Body => Elaborate_Body : declare
7966             Cunit_Node : Node_Id;
7967             Cunit_Ent  : Entity_Id;
7968
7969          begin
7970             Check_Ada_83_Warning;
7971             Check_Valid_Library_Unit_Pragma;
7972
7973             if Nkind (N) = N_Null_Statement then
7974                return;
7975             end if;
7976
7977             Cunit_Node := Cunit (Current_Sem_Unit);
7978             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
7979
7980             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
7981                                             N_Subprogram_Body)
7982             then
7983                Error_Pragma ("pragma% must refer to a spec, not a body");
7984             else
7985                Set_Body_Required (Cunit_Node, True);
7986                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
7987
7988                --  If we are in dynamic elaboration mode, then we suppress
7989                --  elaboration warnings for the unit, since it is definitely
7990                --  fine NOT to do dynamic checks at the first level (and such
7991                --  checks will be suppressed because no elaboration boolean
7992                --  is created for Elaborate_Body packages).
7993
7994                --  But in the static model of elaboration, Elaborate_Body is
7995                --  definitely NOT good enough to ensure elaboration safety on
7996                --  its own, since the body may WITH other units that are not
7997                --  safe from an elaboration point of view, so a client must
7998                --  still do an Elaborate_All on such units.
7999
8000                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8001                --  Elaborate_Body always suppressed elab warnings.
8002
8003                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8004                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8005                end if;
8006             end if;
8007          end Elaborate_Body;
8008
8009          ------------------------
8010          -- Elaboration_Checks --
8011          ------------------------
8012
8013          --  pragma Elaboration_Checks (Static | Dynamic);
8014
8015          when Pragma_Elaboration_Checks =>
8016             GNAT_Pragma;
8017             Check_Arg_Count (1);
8018             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8019             Dynamic_Elaboration_Checks :=
8020               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8021
8022          ---------------
8023          -- Eliminate --
8024          ---------------
8025
8026          --  pragma Eliminate (
8027          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8028          --    [,[Entity     =>] IDENTIFIER |
8029          --                      SELECTED_COMPONENT |
8030          --                      STRING_LITERAL]
8031          --    [,                OVERLOADING_RESOLUTION]);
8032
8033          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8034          --                             SOURCE_LOCATION
8035
8036          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8037          --                                        FUNCTION_PROFILE
8038
8039          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8040
8041          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8042          --                       Result_Type => result_SUBTYPE_NAME]
8043
8044          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8045          --  SUBTYPE_NAME    ::= STRING_LITERAL
8046
8047          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8048          --  SOURCE_TRACE    ::= STRING_LITERAL
8049
8050          when Pragma_Eliminate => Eliminate : declare
8051             Args  : Args_List (1 .. 5);
8052             Names : constant Name_List (1 .. 5) := (
8053                       Name_Unit_Name,
8054                       Name_Entity,
8055                       Name_Parameter_Types,
8056                       Name_Result_Type,
8057                       Name_Source_Location);
8058
8059             Unit_Name       : Node_Id renames Args (1);
8060             Entity          : Node_Id renames Args (2);
8061             Parameter_Types : Node_Id renames Args (3);
8062             Result_Type     : Node_Id renames Args (4);
8063             Source_Location : Node_Id renames Args (5);
8064
8065          begin
8066             GNAT_Pragma;
8067             Check_Valid_Configuration_Pragma;
8068             Gather_Associations (Names, Args);
8069
8070             if No (Unit_Name) then
8071                Error_Pragma ("missing Unit_Name argument for pragma%");
8072             end if;
8073
8074             if No (Entity)
8075               and then (Present (Parameter_Types)
8076                           or else
8077                         Present (Result_Type)
8078                           or else
8079                         Present (Source_Location))
8080             then
8081                Error_Pragma ("missing Entity argument for pragma%");
8082             end if;
8083
8084             if (Present (Parameter_Types)
8085                   or else
8086                 Present (Result_Type))
8087               and then
8088                 Present (Source_Location)
8089             then
8090                Error_Pragma
8091                  ("parameter profile and source location cannot " &
8092                   "be used together in pragma%");
8093             end if;
8094
8095             Process_Eliminate_Pragma
8096               (N,
8097                Unit_Name,
8098                Entity,
8099                Parameter_Types,
8100                Result_Type,
8101                Source_Location);
8102          end Eliminate;
8103
8104          ------------
8105          -- Export --
8106          ------------
8107
8108          --  pragma Export (
8109          --    [   Convention    =>] convention_IDENTIFIER,
8110          --    [   Entity        =>] local_NAME
8111          --    [, [External_Name =>] static_string_EXPRESSION ]
8112          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8113
8114          when Pragma_Export => Export : declare
8115             C      : Convention_Id;
8116             Def_Id : Entity_Id;
8117
8118             pragma Warnings (Off, C);
8119
8120          begin
8121             Check_Ada_83_Warning;
8122             Check_Arg_Order
8123               ((Name_Convention,
8124                 Name_Entity,
8125                 Name_External_Name,
8126                 Name_Link_Name));
8127             Check_At_Least_N_Arguments (2);
8128             Check_At_Most_N_Arguments  (4);
8129             Process_Convention (C, Def_Id);
8130
8131             if Ekind (Def_Id) /= E_Constant then
8132                Note_Possible_Modification
8133                  (Get_Pragma_Arg (Arg2), Sure => False);
8134             end if;
8135
8136             Process_Interface_Name (Def_Id, Arg3, Arg4);
8137             Set_Exported (Def_Id, Arg2);
8138
8139             --  If the entity is a deferred constant, propagate the information
8140             --  to the full view, because gigi elaborates the full view only.
8141
8142             if Ekind (Def_Id) = E_Constant
8143               and then Present (Full_View (Def_Id))
8144             then
8145                declare
8146                   Id2 : constant Entity_Id := Full_View (Def_Id);
8147                begin
8148                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8149                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8150                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8151                end;
8152             end if;
8153          end Export;
8154
8155          ----------------------
8156          -- Export_Exception --
8157          ----------------------
8158
8159          --  pragma Export_Exception (
8160          --        [Internal         =>] LOCAL_NAME
8161          --     [, [External         =>] EXTERNAL_SYMBOL]
8162          --     [, [Form     =>] Ada | VMS]
8163          --     [, [Code     =>] static_integer_EXPRESSION]);
8164
8165          when Pragma_Export_Exception => Export_Exception : declare
8166             Args  : Args_List (1 .. 4);
8167             Names : constant Name_List (1 .. 4) := (
8168                       Name_Internal,
8169                       Name_External,
8170                       Name_Form,
8171                       Name_Code);
8172
8173             Internal : Node_Id renames Args (1);
8174             External : Node_Id renames Args (2);
8175             Form     : Node_Id renames Args (3);
8176             Code     : Node_Id renames Args (4);
8177
8178          begin
8179             GNAT_Pragma;
8180
8181             if Inside_A_Generic then
8182                Error_Pragma ("pragma% cannot be used for generic entities");
8183             end if;
8184
8185             Gather_Associations (Names, Args);
8186             Process_Extended_Import_Export_Exception_Pragma (
8187               Arg_Internal => Internal,
8188               Arg_External => External,
8189               Arg_Form     => Form,
8190               Arg_Code     => Code);
8191
8192             if not Is_VMS_Exception (Entity (Internal)) then
8193                Set_Exported (Entity (Internal), Internal);
8194             end if;
8195          end Export_Exception;
8196
8197          ---------------------
8198          -- Export_Function --
8199          ---------------------
8200
8201          --  pragma Export_Function (
8202          --        [Internal         =>] LOCAL_NAME
8203          --     [, [External         =>] EXTERNAL_SYMBOL]
8204          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8205          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8206          --     [, [Mechanism        =>] MECHANISM]
8207          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8208
8209          --  EXTERNAL_SYMBOL ::=
8210          --    IDENTIFIER
8211          --  | static_string_EXPRESSION
8212
8213          --  PARAMETER_TYPES ::=
8214          --    null
8215          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8216
8217          --  TYPE_DESIGNATOR ::=
8218          --    subtype_NAME
8219          --  | subtype_Name ' Access
8220
8221          --  MECHANISM ::=
8222          --    MECHANISM_NAME
8223          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8224
8225          --  MECHANISM_ASSOCIATION ::=
8226          --    [formal_parameter_NAME =>] MECHANISM_NAME
8227
8228          --  MECHANISM_NAME ::=
8229          --    Value
8230          --  | Reference
8231          --  | Descriptor [([Class =>] CLASS_NAME)]
8232
8233          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8234
8235          when Pragma_Export_Function => Export_Function : declare
8236             Args  : Args_List (1 .. 6);
8237             Names : constant Name_List (1 .. 6) := (
8238                       Name_Internal,
8239                       Name_External,
8240                       Name_Parameter_Types,
8241                       Name_Result_Type,
8242                       Name_Mechanism,
8243                       Name_Result_Mechanism);
8244
8245             Internal         : Node_Id renames Args (1);
8246             External         : Node_Id renames Args (2);
8247             Parameter_Types  : Node_Id renames Args (3);
8248             Result_Type      : Node_Id renames Args (4);
8249             Mechanism        : Node_Id renames Args (5);
8250             Result_Mechanism : Node_Id renames Args (6);
8251
8252          begin
8253             GNAT_Pragma;
8254             Gather_Associations (Names, Args);
8255             Process_Extended_Import_Export_Subprogram_Pragma (
8256               Arg_Internal         => Internal,
8257               Arg_External         => External,
8258               Arg_Parameter_Types  => Parameter_Types,
8259               Arg_Result_Type      => Result_Type,
8260               Arg_Mechanism        => Mechanism,
8261               Arg_Result_Mechanism => Result_Mechanism);
8262          end Export_Function;
8263
8264          -------------------
8265          -- Export_Object --
8266          -------------------
8267
8268          --  pragma Export_Object (
8269          --        [Internal =>] LOCAL_NAME
8270          --     [, [External =>] EXTERNAL_SYMBOL]
8271          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8272
8273          --  EXTERNAL_SYMBOL ::=
8274          --    IDENTIFIER
8275          --  | static_string_EXPRESSION
8276
8277          --  PARAMETER_TYPES ::=
8278          --    null
8279          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8280
8281          --  TYPE_DESIGNATOR ::=
8282          --    subtype_NAME
8283          --  | subtype_Name ' Access
8284
8285          --  MECHANISM ::=
8286          --    MECHANISM_NAME
8287          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8288
8289          --  MECHANISM_ASSOCIATION ::=
8290          --    [formal_parameter_NAME =>] MECHANISM_NAME
8291
8292          --  MECHANISM_NAME ::=
8293          --    Value
8294          --  | Reference
8295          --  | Descriptor [([Class =>] CLASS_NAME)]
8296
8297          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8298
8299          when Pragma_Export_Object => Export_Object : declare
8300             Args  : Args_List (1 .. 3);
8301             Names : constant Name_List (1 .. 3) := (
8302                       Name_Internal,
8303                       Name_External,
8304                       Name_Size);
8305
8306             Internal : Node_Id renames Args (1);
8307             External : Node_Id renames Args (2);
8308             Size     : Node_Id renames Args (3);
8309
8310          begin
8311             GNAT_Pragma;
8312             Gather_Associations (Names, Args);
8313             Process_Extended_Import_Export_Object_Pragma (
8314               Arg_Internal => Internal,
8315               Arg_External => External,
8316               Arg_Size     => Size);
8317          end Export_Object;
8318
8319          ----------------------
8320          -- Export_Procedure --
8321          ----------------------
8322
8323          --  pragma Export_Procedure (
8324          --        [Internal         =>] LOCAL_NAME
8325          --     [, [External         =>] EXTERNAL_SYMBOL]
8326          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8327          --     [, [Mechanism        =>] MECHANISM]);
8328
8329          --  EXTERNAL_SYMBOL ::=
8330          --    IDENTIFIER
8331          --  | static_string_EXPRESSION
8332
8333          --  PARAMETER_TYPES ::=
8334          --    null
8335          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8336
8337          --  TYPE_DESIGNATOR ::=
8338          --    subtype_NAME
8339          --  | subtype_Name ' Access
8340
8341          --  MECHANISM ::=
8342          --    MECHANISM_NAME
8343          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8344
8345          --  MECHANISM_ASSOCIATION ::=
8346          --    [formal_parameter_NAME =>] MECHANISM_NAME
8347
8348          --  MECHANISM_NAME ::=
8349          --    Value
8350          --  | Reference
8351          --  | Descriptor [([Class =>] CLASS_NAME)]
8352
8353          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8354
8355          when Pragma_Export_Procedure => Export_Procedure : declare
8356             Args  : Args_List (1 .. 4);
8357             Names : constant Name_List (1 .. 4) := (
8358                       Name_Internal,
8359                       Name_External,
8360                       Name_Parameter_Types,
8361                       Name_Mechanism);
8362
8363             Internal        : Node_Id renames Args (1);
8364             External        : Node_Id renames Args (2);
8365             Parameter_Types : Node_Id renames Args (3);
8366             Mechanism       : Node_Id renames Args (4);
8367
8368          begin
8369             GNAT_Pragma;
8370             Gather_Associations (Names, Args);
8371             Process_Extended_Import_Export_Subprogram_Pragma (
8372               Arg_Internal        => Internal,
8373               Arg_External        => External,
8374               Arg_Parameter_Types => Parameter_Types,
8375               Arg_Mechanism       => Mechanism);
8376          end Export_Procedure;
8377
8378          ------------------
8379          -- Export_Value --
8380          ------------------
8381
8382          --  pragma Export_Value (
8383          --     [Value     =>] static_integer_EXPRESSION,
8384          --     [Link_Name =>] static_string_EXPRESSION);
8385
8386          when Pragma_Export_Value =>
8387             GNAT_Pragma;
8388             Check_Arg_Order ((Name_Value, Name_Link_Name));
8389             Check_Arg_Count (2);
8390
8391             Check_Optional_Identifier (Arg1, Name_Value);
8392             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8393
8394             Check_Optional_Identifier (Arg2, Name_Link_Name);
8395             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8396
8397          -----------------------------
8398          -- Export_Valued_Procedure --
8399          -----------------------------
8400
8401          --  pragma Export_Valued_Procedure (
8402          --        [Internal         =>] LOCAL_NAME
8403          --     [, [External         =>] EXTERNAL_SYMBOL,]
8404          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8405          --     [, [Mechanism        =>] MECHANISM]);
8406
8407          --  EXTERNAL_SYMBOL ::=
8408          --    IDENTIFIER
8409          --  | static_string_EXPRESSION
8410
8411          --  PARAMETER_TYPES ::=
8412          --    null
8413          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8414
8415          --  TYPE_DESIGNATOR ::=
8416          --    subtype_NAME
8417          --  | subtype_Name ' Access
8418
8419          --  MECHANISM ::=
8420          --    MECHANISM_NAME
8421          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8422
8423          --  MECHANISM_ASSOCIATION ::=
8424          --    [formal_parameter_NAME =>] MECHANISM_NAME
8425
8426          --  MECHANISM_NAME ::=
8427          --    Value
8428          --  | Reference
8429          --  | Descriptor [([Class =>] CLASS_NAME)]
8430
8431          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8432
8433          when Pragma_Export_Valued_Procedure =>
8434          Export_Valued_Procedure : declare
8435             Args  : Args_List (1 .. 4);
8436             Names : constant Name_List (1 .. 4) := (
8437                       Name_Internal,
8438                       Name_External,
8439                       Name_Parameter_Types,
8440                       Name_Mechanism);
8441
8442             Internal        : Node_Id renames Args (1);
8443             External        : Node_Id renames Args (2);
8444             Parameter_Types : Node_Id renames Args (3);
8445             Mechanism       : Node_Id renames Args (4);
8446
8447          begin
8448             GNAT_Pragma;
8449             Gather_Associations (Names, Args);
8450             Process_Extended_Import_Export_Subprogram_Pragma (
8451               Arg_Internal        => Internal,
8452               Arg_External        => External,
8453               Arg_Parameter_Types => Parameter_Types,
8454               Arg_Mechanism       => Mechanism);
8455          end Export_Valued_Procedure;
8456
8457          -------------------
8458          -- Extend_System --
8459          -------------------
8460
8461          --  pragma Extend_System ([Name =>] Identifier);
8462
8463          when Pragma_Extend_System => Extend_System : declare
8464          begin
8465             GNAT_Pragma;
8466             Check_Valid_Configuration_Pragma;
8467             Check_Arg_Count (1);
8468             Check_Optional_Identifier (Arg1, Name_Name);
8469             Check_Arg_Is_Identifier (Arg1);
8470
8471             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8472
8473             if Name_Len > 4
8474               and then Name_Buffer (1 .. 4) = "aux_"
8475             then
8476                if Present (System_Extend_Pragma_Arg) then
8477                   if Chars (Get_Pragma_Arg (Arg1)) =
8478                      Chars (Expression (System_Extend_Pragma_Arg))
8479                   then
8480                      null;
8481                   else
8482                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8483                      Error_Pragma ("pragma% conflicts with that #");
8484                   end if;
8485
8486                else
8487                   System_Extend_Pragma_Arg := Arg1;
8488
8489                   if not GNAT_Mode then
8490                      System_Extend_Unit := Arg1;
8491                   end if;
8492                end if;
8493             else
8494                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8495             end if;
8496          end Extend_System;
8497
8498          ------------------------
8499          -- Extensions_Allowed --
8500          ------------------------
8501
8502          --  pragma Extensions_Allowed (ON | OFF);
8503
8504          when Pragma_Extensions_Allowed =>
8505             GNAT_Pragma;
8506             Check_Arg_Count (1);
8507             Check_No_Identifiers;
8508             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8509
8510             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8511                Extensions_Allowed := True;
8512                Ada_Version := Ada_Version_Type'Last;
8513
8514             else
8515                Extensions_Allowed := False;
8516                Ada_Version := Ada_Version_Explicit;
8517             end if;
8518
8519          --------------
8520          -- External --
8521          --------------
8522
8523          --  pragma External (
8524          --    [   Convention    =>] convention_IDENTIFIER,
8525          --    [   Entity        =>] local_NAME
8526          --    [, [External_Name =>] static_string_EXPRESSION ]
8527          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8528
8529          when Pragma_External => External : declare
8530                Def_Id : Entity_Id;
8531
8532                C : Convention_Id;
8533                pragma Warnings (Off, C);
8534
8535          begin
8536             GNAT_Pragma;
8537             Check_Arg_Order
8538               ((Name_Convention,
8539                 Name_Entity,
8540                 Name_External_Name,
8541                 Name_Link_Name));
8542             Check_At_Least_N_Arguments (2);
8543             Check_At_Most_N_Arguments  (4);
8544             Process_Convention (C, Def_Id);
8545             Note_Possible_Modification
8546               (Get_Pragma_Arg (Arg2), Sure => False);
8547             Process_Interface_Name (Def_Id, Arg3, Arg4);
8548             Set_Exported (Def_Id, Arg2);
8549          end External;
8550
8551          --------------------------
8552          -- External_Name_Casing --
8553          --------------------------
8554
8555          --  pragma External_Name_Casing (
8556          --    UPPERCASE | LOWERCASE
8557          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8558
8559          when Pragma_External_Name_Casing => External_Name_Casing : declare
8560          begin
8561             GNAT_Pragma;
8562             Check_No_Identifiers;
8563
8564             if Arg_Count = 2 then
8565                Check_Arg_Is_One_Of
8566                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8567
8568                case Chars (Get_Pragma_Arg (Arg2)) is
8569                   when Name_As_Is     =>
8570                      Opt.External_Name_Exp_Casing := As_Is;
8571
8572                   when Name_Uppercase =>
8573                      Opt.External_Name_Exp_Casing := Uppercase;
8574
8575                   when Name_Lowercase =>
8576                      Opt.External_Name_Exp_Casing := Lowercase;
8577
8578                   when others =>
8579                      null;
8580                end case;
8581
8582             else
8583                Check_Arg_Count (1);
8584             end if;
8585
8586             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8587
8588             case Chars (Get_Pragma_Arg (Arg1)) is
8589                when Name_Uppercase =>
8590                   Opt.External_Name_Imp_Casing := Uppercase;
8591
8592                when Name_Lowercase =>
8593                   Opt.External_Name_Imp_Casing := Lowercase;
8594
8595                when others =>
8596                   null;
8597             end case;
8598          end External_Name_Casing;
8599
8600          --------------------------
8601          -- Favor_Top_Level --
8602          --------------------------
8603
8604          --  pragma Favor_Top_Level (type_NAME);
8605
8606          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8607                Named_Entity : Entity_Id;
8608
8609          begin
8610             GNAT_Pragma;
8611             Check_No_Identifiers;
8612             Check_Arg_Count (1);
8613             Check_Arg_Is_Local_Name (Arg1);
8614             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8615
8616             --  If it's an access-to-subprogram type (in particular, not a
8617             --  subtype), set the flag on that type.
8618
8619             if Is_Access_Subprogram_Type (Named_Entity) then
8620                Set_Can_Use_Internal_Rep (Named_Entity, False);
8621
8622             --  Otherwise it's an error (name denotes the wrong sort of entity)
8623
8624             else
8625                Error_Pragma_Arg
8626                  ("access-to-subprogram type expected",
8627                   Get_Pragma_Arg (Arg1));
8628             end if;
8629          end Favor_Top_Level;
8630
8631          ---------------
8632          -- Fast_Math --
8633          ---------------
8634
8635          --  pragma Fast_Math;
8636
8637          when Pragma_Fast_Math =>
8638             GNAT_Pragma;
8639             Check_No_Identifiers;
8640             Check_Valid_Configuration_Pragma;
8641             Fast_Math := True;
8642
8643          ---------------------------
8644          -- Finalize_Storage_Only --
8645          ---------------------------
8646
8647          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8648
8649          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8650             Assoc   : constant Node_Id := Arg1;
8651             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8652             Typ     : Entity_Id;
8653
8654          begin
8655             GNAT_Pragma;
8656             Check_No_Identifiers;
8657             Check_Arg_Count (1);
8658             Check_Arg_Is_Local_Name (Arg1);
8659
8660             Find_Type (Type_Id);
8661             Typ := Entity (Type_Id);
8662
8663             if Typ = Any_Type
8664               or else Rep_Item_Too_Early (Typ, N)
8665             then
8666                return;
8667             else
8668                Typ := Underlying_Type (Typ);
8669             end if;
8670
8671             if not Is_Controlled (Typ) then
8672                Error_Pragma ("pragma% must specify controlled type");
8673             end if;
8674
8675             Check_First_Subtype (Arg1);
8676
8677             if Finalize_Storage_Only (Typ) then
8678                Error_Pragma ("duplicate pragma%, only one allowed");
8679
8680             elsif not Rep_Item_Too_Late (Typ, N) then
8681                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8682             end if;
8683          end Finalize_Storage;
8684
8685          --------------------------
8686          -- Float_Representation --
8687          --------------------------
8688
8689          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8690
8691          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8692
8693          when Pragma_Float_Representation => Float_Representation : declare
8694             Argx : Node_Id;
8695             Digs : Nat;
8696             Ent  : Entity_Id;
8697
8698          begin
8699             GNAT_Pragma;
8700
8701             if Arg_Count = 1 then
8702                Check_Valid_Configuration_Pragma;
8703             else
8704                Check_Arg_Count (2);
8705                Check_Optional_Identifier (Arg2, Name_Entity);
8706                Check_Arg_Is_Local_Name (Arg2);
8707             end if;
8708
8709             Check_No_Identifier (Arg1);
8710             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8711
8712             if not OpenVMS_On_Target then
8713                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8714                   Error_Pragma
8715                     ("?pragma% ignored (applies only to Open'V'M'S)");
8716                end if;
8717
8718                return;
8719             end if;
8720
8721             --  One argument case
8722
8723             if Arg_Count = 1 then
8724                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8725                   if Opt.Float_Format = 'I' then
8726                      Error_Pragma ("'I'E'E'E format previously specified");
8727                   end if;
8728
8729                   Opt.Float_Format := 'V';
8730
8731                else
8732                   if Opt.Float_Format = 'V' then
8733                      Error_Pragma ("'V'A'X format previously specified");
8734                   end if;
8735
8736                   Opt.Float_Format := 'I';
8737                end if;
8738
8739                Set_Standard_Fpt_Formats;
8740
8741             --  Two argument case
8742
8743             else
8744                Argx := Get_Pragma_Arg (Arg2);
8745
8746                if not Is_Entity_Name (Argx)
8747                  or else not Is_Floating_Point_Type (Entity (Argx))
8748                then
8749                   Error_Pragma_Arg
8750                     ("second argument of% pragma must be floating-point type",
8751                      Arg2);
8752                end if;
8753
8754                Ent  := Entity (Argx);
8755                Digs := UI_To_Int (Digits_Value (Ent));
8756
8757                --  Two arguments, VAX_Float case
8758
8759                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8760                   case Digs is
8761                      when  6 => Set_F_Float (Ent);
8762                      when  9 => Set_D_Float (Ent);
8763                      when 15 => Set_G_Float (Ent);
8764
8765                      when others =>
8766                         Error_Pragma_Arg
8767                           ("wrong digits value, must be 6,9 or 15", Arg2);
8768                   end case;
8769
8770                --  Two arguments, IEEE_Float case
8771
8772                else
8773                   case Digs is
8774                      when  6 => Set_IEEE_Short (Ent);
8775                      when 15 => Set_IEEE_Long  (Ent);
8776
8777                      when others =>
8778                         Error_Pragma_Arg
8779                           ("wrong digits value, must be 6 or 15", Arg2);
8780                   end case;
8781                end if;
8782             end if;
8783          end Float_Representation;
8784
8785          -----------
8786          -- Ident --
8787          -----------
8788
8789          --  pragma Ident (static_string_EXPRESSION)
8790
8791          --  Note: pragma Comment shares this processing. Pragma Comment is
8792          --  identical to Ident, except that the restriction of the argument to
8793          --  31 characters and the placement restrictions are not enforced for
8794          --  pragma Comment.
8795
8796          when Pragma_Ident | Pragma_Comment => Ident : declare
8797             Str : Node_Id;
8798
8799          begin
8800             GNAT_Pragma;
8801             Check_Arg_Count (1);
8802             Check_No_Identifiers;
8803             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8804             Store_Note (N);
8805
8806             --  For pragma Ident, preserve DEC compatibility by requiring the
8807             --  pragma to appear in a declarative part or package spec.
8808
8809             if Prag_Id = Pragma_Ident then
8810                Check_Is_In_Decl_Part_Or_Package_Spec;
8811             end if;
8812
8813             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8814
8815             declare
8816                CS : Node_Id;
8817                GP : Node_Id;
8818
8819             begin
8820                GP := Parent (Parent (N));
8821
8822                if Nkind_In (GP, N_Package_Declaration,
8823                                 N_Generic_Package_Declaration)
8824                then
8825                   GP := Parent (GP);
8826                end if;
8827
8828                --  If we have a compilation unit, then record the ident value,
8829                --  checking for improper duplication.
8830
8831                if Nkind (GP) = N_Compilation_Unit then
8832                   CS := Ident_String (Current_Sem_Unit);
8833
8834                   if Present (CS) then
8835
8836                      --  For Ident, we do not permit multiple instances
8837
8838                      if Prag_Id = Pragma_Ident then
8839                         Error_Pragma ("duplicate% pragma not permitted");
8840
8841                      --  For Comment, we concatenate the string, unless we want
8842                      --  to preserve the tree structure for ASIS.
8843
8844                      elsif not ASIS_Mode then
8845                         Start_String (Strval (CS));
8846                         Store_String_Char (' ');
8847                         Store_String_Chars (Strval (Str));
8848                         Set_Strval (CS, End_String);
8849                      end if;
8850
8851                   else
8852                      --  In VMS, the effect of IDENT is achieved by passing
8853                      --  --identification=name as a --for-linker switch.
8854
8855                      if OpenVMS_On_Target then
8856                         Start_String;
8857                         Store_String_Chars
8858                           ("--for-linker=--identification=");
8859                         String_To_Name_Buffer (Strval (Str));
8860                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
8861
8862                         --  Only the last processed IDENT is saved. The main
8863                         --  purpose is so an IDENT associated with a main
8864                         --  procedure will be used in preference to an IDENT
8865                         --  associated with a with'd package.
8866
8867                         Replace_Linker_Option_String
8868                           (End_String, "--for-linker=--identification=");
8869                      end if;
8870
8871                      Set_Ident_String (Current_Sem_Unit, Str);
8872                   end if;
8873
8874                --  For subunits, we just ignore the Ident, since in GNAT these
8875                --  are not separate object files, and hence not separate units
8876                --  in the unit table.
8877
8878                elsif Nkind (GP) = N_Subunit then
8879                   null;
8880
8881                --  Otherwise we have a misplaced pragma Ident, but we ignore
8882                --  this if we are in an instantiation, since it comes from
8883                --  a generic, and has no relevance to the instantiation.
8884
8885                elsif Prag_Id = Pragma_Ident then
8886                   if Instantiation_Location (Loc) = No_Location then
8887                      Error_Pragma ("pragma% only allowed at outer level");
8888                   end if;
8889                end if;
8890             end;
8891          end Ident;
8892
8893          -----------------
8894          -- Implemented --
8895          -----------------
8896
8897          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8898          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8899
8900          when Pragma_Implemented => Implemented : declare
8901             Proc_Id : Entity_Id;
8902             Typ     : Entity_Id;
8903
8904          begin
8905             Ada_2012_Pragma;
8906             Check_Arg_Count (2);
8907             Check_No_Identifiers;
8908             Check_Arg_Is_Identifier (Arg1);
8909             Check_Arg_Is_Local_Name (Arg1);
8910             Check_Arg_Is_One_Of
8911               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8912
8913             --  Extract the name of the local procedure
8914
8915             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8916
8917             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8918             --  primitive procedure of a synchronized tagged type.
8919
8920             if Ekind (Proc_Id) = E_Procedure
8921               and then Is_Primitive (Proc_Id)
8922               and then Present (First_Formal (Proc_Id))
8923             then
8924                Typ := Etype (First_Formal (Proc_Id));
8925
8926                if Is_Tagged_Type (Typ)
8927                  and then
8928
8929                   --  Check for a protected, a synchronized or a task interface
8930
8931                    ((Is_Interface (Typ)
8932                        and then Is_Synchronized_Interface (Typ))
8933
8934                   --  Check for a protected type or a task type that implements
8935                   --  an interface.
8936
8937                    or else
8938                     (Is_Concurrent_Record_Type (Typ)
8939                        and then Present (Interfaces (Typ)))
8940
8941                   --  Check for a private record extension with keyword
8942                   --  "synchronized".
8943
8944                    or else
8945                     (Ekind_In (Typ, E_Record_Type_With_Private,
8946                                     E_Record_Subtype_With_Private)
8947                        and then Synchronized_Present (Parent (Typ))))
8948                then
8949                   null;
8950                else
8951                   Error_Pragma_Arg
8952                     ("controlling formal must be of synchronized " &
8953                      "tagged type", Arg1);
8954                   return;
8955                end if;
8956
8957             --  Procedures declared inside a protected type must be accepted
8958
8959             elsif Ekind (Proc_Id) = E_Procedure
8960               and then Is_Protected_Type (Scope (Proc_Id))
8961             then
8962                null;
8963
8964             --  The first argument is not a primitive procedure
8965
8966             else
8967                Error_Pragma_Arg
8968                  ("pragma % must be applied to a primitive procedure", Arg1);
8969                return;
8970             end if;
8971
8972             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8973             --  By_Protected_Procedure to the primitive procedure of a task
8974             --  interface.
8975
8976             if Chars (Arg2) = Name_By_Protected_Procedure
8977               and then Is_Interface (Typ)
8978               and then Is_Task_Interface (Typ)
8979             then
8980                Error_Pragma_Arg
8981                  ("implementation kind By_Protected_Procedure cannot be " &
8982                   "applied to a task interface primitive", Arg2);
8983                return;
8984             end if;
8985
8986             Record_Rep_Item (Proc_Id, N);
8987          end Implemented;
8988
8989          ----------------------
8990          -- Implicit_Packing --
8991          ----------------------
8992
8993          --  pragma Implicit_Packing;
8994
8995          when Pragma_Implicit_Packing =>
8996             GNAT_Pragma;
8997             Check_Arg_Count (0);
8998             Implicit_Packing := True;
8999
9000          ------------
9001          -- Import --
9002          ------------
9003
9004          --  pragma Import (
9005          --       [Convention    =>] convention_IDENTIFIER,
9006          --       [Entity        =>] local_NAME
9007          --    [, [External_Name =>] static_string_EXPRESSION ]
9008          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9009
9010          when Pragma_Import =>
9011             Check_Ada_83_Warning;
9012             Check_Arg_Order
9013               ((Name_Convention,
9014                 Name_Entity,
9015                 Name_External_Name,
9016                 Name_Link_Name));
9017             Check_At_Least_N_Arguments (2);
9018             Check_At_Most_N_Arguments  (4);
9019             Process_Import_Or_Interface;
9020
9021          ----------------------
9022          -- Import_Exception --
9023          ----------------------
9024
9025          --  pragma Import_Exception (
9026          --        [Internal         =>] LOCAL_NAME
9027          --     [, [External         =>] EXTERNAL_SYMBOL]
9028          --     [, [Form     =>] Ada | VMS]
9029          --     [, [Code     =>] static_integer_EXPRESSION]);
9030
9031          when Pragma_Import_Exception => Import_Exception : declare
9032             Args  : Args_List (1 .. 4);
9033             Names : constant Name_List (1 .. 4) := (
9034                       Name_Internal,
9035                       Name_External,
9036                       Name_Form,
9037                       Name_Code);
9038
9039             Internal : Node_Id renames Args (1);
9040             External : Node_Id renames Args (2);
9041             Form     : Node_Id renames Args (3);
9042             Code     : Node_Id renames Args (4);
9043
9044          begin
9045             GNAT_Pragma;
9046             Gather_Associations (Names, Args);
9047
9048             if Present (External) and then Present (Code) then
9049                Error_Pragma
9050                  ("cannot give both External and Code options for pragma%");
9051             end if;
9052
9053             Process_Extended_Import_Export_Exception_Pragma (
9054               Arg_Internal => Internal,
9055               Arg_External => External,
9056               Arg_Form     => Form,
9057               Arg_Code     => Code);
9058
9059             if not Is_VMS_Exception (Entity (Internal)) then
9060                Set_Imported (Entity (Internal));
9061             end if;
9062          end Import_Exception;
9063
9064          ---------------------
9065          -- Import_Function --
9066          ---------------------
9067
9068          --  pragma Import_Function (
9069          --        [Internal                 =>] LOCAL_NAME,
9070          --     [, [External                 =>] EXTERNAL_SYMBOL]
9071          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9072          --     [, [Result_Type              =>] SUBTYPE_MARK]
9073          --     [, [Mechanism                =>] MECHANISM]
9074          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9075          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9076
9077          --  EXTERNAL_SYMBOL ::=
9078          --    IDENTIFIER
9079          --  | static_string_EXPRESSION
9080
9081          --  PARAMETER_TYPES ::=
9082          --    null
9083          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9084
9085          --  TYPE_DESIGNATOR ::=
9086          --    subtype_NAME
9087          --  | subtype_Name ' Access
9088
9089          --  MECHANISM ::=
9090          --    MECHANISM_NAME
9091          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9092
9093          --  MECHANISM_ASSOCIATION ::=
9094          --    [formal_parameter_NAME =>] MECHANISM_NAME
9095
9096          --  MECHANISM_NAME ::=
9097          --    Value
9098          --  | Reference
9099          --  | Descriptor [([Class =>] CLASS_NAME)]
9100
9101          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9102
9103          when Pragma_Import_Function => Import_Function : declare
9104             Args  : Args_List (1 .. 7);
9105             Names : constant Name_List (1 .. 7) := (
9106                       Name_Internal,
9107                       Name_External,
9108                       Name_Parameter_Types,
9109                       Name_Result_Type,
9110                       Name_Mechanism,
9111                       Name_Result_Mechanism,
9112                       Name_First_Optional_Parameter);
9113
9114             Internal                 : Node_Id renames Args (1);
9115             External                 : Node_Id renames Args (2);
9116             Parameter_Types          : Node_Id renames Args (3);
9117             Result_Type              : Node_Id renames Args (4);
9118             Mechanism                : Node_Id renames Args (5);
9119             Result_Mechanism         : Node_Id renames Args (6);
9120             First_Optional_Parameter : Node_Id renames Args (7);
9121
9122          begin
9123             GNAT_Pragma;
9124             Gather_Associations (Names, Args);
9125             Process_Extended_Import_Export_Subprogram_Pragma (
9126               Arg_Internal                 => Internal,
9127               Arg_External                 => External,
9128               Arg_Parameter_Types          => Parameter_Types,
9129               Arg_Result_Type              => Result_Type,
9130               Arg_Mechanism                => Mechanism,
9131               Arg_Result_Mechanism         => Result_Mechanism,
9132               Arg_First_Optional_Parameter => First_Optional_Parameter);
9133          end Import_Function;
9134
9135          -------------------
9136          -- Import_Object --
9137          -------------------
9138
9139          --  pragma Import_Object (
9140          --        [Internal =>] LOCAL_NAME
9141          --     [, [External =>] EXTERNAL_SYMBOL]
9142          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9143
9144          --  EXTERNAL_SYMBOL ::=
9145          --    IDENTIFIER
9146          --  | static_string_EXPRESSION
9147
9148          when Pragma_Import_Object => Import_Object : declare
9149             Args  : Args_List (1 .. 3);
9150             Names : constant Name_List (1 .. 3) := (
9151                       Name_Internal,
9152                       Name_External,
9153                       Name_Size);
9154
9155             Internal : Node_Id renames Args (1);
9156             External : Node_Id renames Args (2);
9157             Size     : Node_Id renames Args (3);
9158
9159          begin
9160             GNAT_Pragma;
9161             Gather_Associations (Names, Args);
9162             Process_Extended_Import_Export_Object_Pragma (
9163               Arg_Internal => Internal,
9164               Arg_External => External,
9165               Arg_Size     => Size);
9166          end Import_Object;
9167
9168          ----------------------
9169          -- Import_Procedure --
9170          ----------------------
9171
9172          --  pragma Import_Procedure (
9173          --        [Internal                 =>] LOCAL_NAME
9174          --     [, [External                 =>] EXTERNAL_SYMBOL]
9175          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9176          --     [, [Mechanism                =>] MECHANISM]
9177          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9178
9179          --  EXTERNAL_SYMBOL ::=
9180          --    IDENTIFIER
9181          --  | static_string_EXPRESSION
9182
9183          --  PARAMETER_TYPES ::=
9184          --    null
9185          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9186
9187          --  TYPE_DESIGNATOR ::=
9188          --    subtype_NAME
9189          --  | subtype_Name ' Access
9190
9191          --  MECHANISM ::=
9192          --    MECHANISM_NAME
9193          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9194
9195          --  MECHANISM_ASSOCIATION ::=
9196          --    [formal_parameter_NAME =>] MECHANISM_NAME
9197
9198          --  MECHANISM_NAME ::=
9199          --    Value
9200          --  | Reference
9201          --  | Descriptor [([Class =>] CLASS_NAME)]
9202
9203          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9204
9205          when Pragma_Import_Procedure => Import_Procedure : declare
9206             Args  : Args_List (1 .. 5);
9207             Names : constant Name_List (1 .. 5) := (
9208                       Name_Internal,
9209                       Name_External,
9210                       Name_Parameter_Types,
9211                       Name_Mechanism,
9212                       Name_First_Optional_Parameter);
9213
9214             Internal                 : Node_Id renames Args (1);
9215             External                 : Node_Id renames Args (2);
9216             Parameter_Types          : Node_Id renames Args (3);
9217             Mechanism                : Node_Id renames Args (4);
9218             First_Optional_Parameter : Node_Id renames Args (5);
9219
9220          begin
9221             GNAT_Pragma;
9222             Gather_Associations (Names, Args);
9223             Process_Extended_Import_Export_Subprogram_Pragma (
9224               Arg_Internal                 => Internal,
9225               Arg_External                 => External,
9226               Arg_Parameter_Types          => Parameter_Types,
9227               Arg_Mechanism                => Mechanism,
9228               Arg_First_Optional_Parameter => First_Optional_Parameter);
9229          end Import_Procedure;
9230
9231          -----------------------------
9232          -- Import_Valued_Procedure --
9233          -----------------------------
9234
9235          --  pragma Import_Valued_Procedure (
9236          --        [Internal                 =>] LOCAL_NAME
9237          --     [, [External                 =>] EXTERNAL_SYMBOL]
9238          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9239          --     [, [Mechanism                =>] MECHANISM]
9240          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9241
9242          --  EXTERNAL_SYMBOL ::=
9243          --    IDENTIFIER
9244          --  | static_string_EXPRESSION
9245
9246          --  PARAMETER_TYPES ::=
9247          --    null
9248          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9249
9250          --  TYPE_DESIGNATOR ::=
9251          --    subtype_NAME
9252          --  | subtype_Name ' Access
9253
9254          --  MECHANISM ::=
9255          --    MECHANISM_NAME
9256          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9257
9258          --  MECHANISM_ASSOCIATION ::=
9259          --    [formal_parameter_NAME =>] MECHANISM_NAME
9260
9261          --  MECHANISM_NAME ::=
9262          --    Value
9263          --  | Reference
9264          --  | Descriptor [([Class =>] CLASS_NAME)]
9265
9266          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9267
9268          when Pragma_Import_Valued_Procedure =>
9269          Import_Valued_Procedure : declare
9270             Args  : Args_List (1 .. 5);
9271             Names : constant Name_List (1 .. 5) := (
9272                       Name_Internal,
9273                       Name_External,
9274                       Name_Parameter_Types,
9275                       Name_Mechanism,
9276                       Name_First_Optional_Parameter);
9277
9278             Internal                 : Node_Id renames Args (1);
9279             External                 : Node_Id renames Args (2);
9280             Parameter_Types          : Node_Id renames Args (3);
9281             Mechanism                : Node_Id renames Args (4);
9282             First_Optional_Parameter : Node_Id renames Args (5);
9283
9284          begin
9285             GNAT_Pragma;
9286             Gather_Associations (Names, Args);
9287             Process_Extended_Import_Export_Subprogram_Pragma (
9288               Arg_Internal                 => Internal,
9289               Arg_External                 => External,
9290               Arg_Parameter_Types          => Parameter_Types,
9291               Arg_Mechanism                => Mechanism,
9292               Arg_First_Optional_Parameter => First_Optional_Parameter);
9293          end Import_Valued_Procedure;
9294
9295          -----------------
9296          -- Independent --
9297          -----------------
9298
9299          --  pragma Independent (LOCAL_NAME);
9300
9301          when Pragma_Independent => Independent : declare
9302             E_Id : Node_Id;
9303             E    : Entity_Id;
9304             D    : Node_Id;
9305             K    : Node_Kind;
9306
9307          begin
9308             Check_Ada_83_Warning;
9309             Ada_2012_Pragma;
9310             Check_No_Identifiers;
9311             Check_Arg_Count (1);
9312             Check_Arg_Is_Local_Name (Arg1);
9313             E_Id := Get_Pragma_Arg (Arg1);
9314
9315             if Etype (E_Id) = Any_Type then
9316                return;
9317             end if;
9318
9319             E := Entity (E_Id);
9320             D := Declaration_Node (E);
9321             K := Nkind (D);
9322
9323             --  Check duplicate before we chain ourselves!
9324
9325             Check_Duplicate_Pragma (E);
9326
9327             --  Check appropriate entity
9328
9329             if Is_Type (E) then
9330                if Rep_Item_Too_Early (E, N)
9331                     or else
9332                   Rep_Item_Too_Late (E, N)
9333                then
9334                   return;
9335                else
9336                   Check_First_Subtype (Arg1);
9337                end if;
9338
9339             elsif K = N_Object_Declaration
9340               or else (K = N_Component_Declaration
9341                        and then Original_Record_Component (E) = E)
9342             then
9343                if Rep_Item_Too_Late (E, N) then
9344                   return;
9345                end if;
9346
9347             else
9348                Error_Pragma_Arg
9349                  ("inappropriate entity for pragma%", Arg1);
9350             end if;
9351
9352             Independence_Checks.Append ((N, E));
9353          end Independent;
9354
9355          ----------------------------
9356          -- Independent_Components --
9357          ----------------------------
9358
9359          --  pragma Atomic_Components (array_LOCAL_NAME);
9360
9361          --  This processing is shared by Volatile_Components
9362
9363          when Pragma_Independent_Components => Independent_Components : declare
9364             E_Id : Node_Id;
9365             E    : Entity_Id;
9366             D    : Node_Id;
9367             K    : Node_Kind;
9368
9369          begin
9370             Check_Ada_83_Warning;
9371             Ada_2012_Pragma;
9372             Check_No_Identifiers;
9373             Check_Arg_Count (1);
9374             Check_Arg_Is_Local_Name (Arg1);
9375             E_Id := Get_Pragma_Arg (Arg1);
9376
9377             if Etype (E_Id) = Any_Type then
9378                return;
9379             end if;
9380
9381             E := Entity (E_Id);
9382
9383             --  Check duplicate before we chain ourselves!
9384
9385             Check_Duplicate_Pragma (E);
9386
9387             --  Check appropriate entity
9388
9389             if Rep_Item_Too_Early (E, N)
9390                  or else
9391                Rep_Item_Too_Late (E, N)
9392             then
9393                return;
9394             end if;
9395
9396             D := Declaration_Node (E);
9397             K := Nkind (D);
9398
9399             if (K = N_Full_Type_Declaration
9400                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9401               or else
9402                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9403                    and then Nkind (D) = N_Object_Declaration
9404                    and then Nkind (Object_Definition (D)) =
9405                                        N_Constrained_Array_Definition)
9406             then
9407                Independence_Checks.Append ((N, E));
9408
9409             else
9410                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9411             end if;
9412          end Independent_Components;
9413
9414          ------------------------
9415          -- Initialize_Scalars --
9416          ------------------------
9417
9418          --  pragma Initialize_Scalars;
9419
9420          when Pragma_Initialize_Scalars =>
9421             GNAT_Pragma;
9422             Check_Arg_Count (0);
9423             Check_Valid_Configuration_Pragma;
9424             Check_Restriction (No_Initialize_Scalars, N);
9425
9426             --  Initialize_Scalars creates false positives in CodePeer,
9427             --  so ignore this pragma in this mode.
9428
9429             if not Restriction_Active (No_Initialize_Scalars)
9430               and then not CodePeer_Mode
9431             then
9432                Init_Or_Norm_Scalars := True;
9433                Initialize_Scalars := True;
9434             end if;
9435
9436          ------------
9437          -- Inline --
9438          ------------
9439
9440          --  pragma Inline ( NAME {, NAME} );
9441
9442          when Pragma_Inline =>
9443
9444             --  Pragma is active if inlining option is active
9445
9446             Process_Inline (Inline_Active);
9447
9448          -------------------
9449          -- Inline_Always --
9450          -------------------
9451
9452          --  pragma Inline_Always ( NAME {, NAME} );
9453
9454          when Pragma_Inline_Always =>
9455             GNAT_Pragma;
9456
9457             --  Pragma always active unless in CodePeer mode, since this causes
9458             --  walk order issues.
9459
9460             if not CodePeer_Mode then
9461                Process_Inline (True);
9462             end if;
9463
9464          --------------------
9465          -- Inline_Generic --
9466          --------------------
9467
9468          --  pragma Inline_Generic (NAME {, NAME});
9469
9470          when Pragma_Inline_Generic =>
9471             GNAT_Pragma;
9472             Process_Generic_List;
9473
9474          ----------------------
9475          -- Inspection_Point --
9476          ----------------------
9477
9478          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9479
9480          when Pragma_Inspection_Point => Inspection_Point : declare
9481             Arg : Node_Id;
9482             Exp : Node_Id;
9483
9484          begin
9485             if Arg_Count > 0 then
9486                Arg := Arg1;
9487                loop
9488                   Exp := Get_Pragma_Arg (Arg);
9489                   Analyze (Exp);
9490
9491                   if not Is_Entity_Name (Exp)
9492                     or else not Is_Object (Entity (Exp))
9493                   then
9494                      Error_Pragma_Arg ("object name required", Arg);
9495                   end if;
9496
9497                   Next (Arg);
9498                   exit when No (Arg);
9499                end loop;
9500             end if;
9501          end Inspection_Point;
9502
9503          ---------------
9504          -- Interface --
9505          ---------------
9506
9507          --  pragma Interface (
9508          --    [   Convention    =>] convention_IDENTIFIER,
9509          --    [   Entity        =>] local_NAME
9510          --    [, [External_Name =>] static_string_EXPRESSION ]
9511          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9512
9513          when Pragma_Interface =>
9514             GNAT_Pragma;
9515             Check_Arg_Order
9516               ((Name_Convention,
9517                 Name_Entity,
9518                 Name_External_Name,
9519                 Name_Link_Name));
9520             Check_At_Least_N_Arguments (2);
9521             Check_At_Most_N_Arguments  (4);
9522             Process_Import_Or_Interface;
9523
9524             --  In Ada 2005, the permission to use Interface (a reserved word)
9525             --  as a pragma name is considered an obsolescent feature.
9526
9527             if Ada_Version >= Ada_2005 then
9528                Check_Restriction
9529                  (No_Obsolescent_Features, Pragma_Identifier (N));
9530             end if;
9531
9532          --------------------
9533          -- Interface_Name --
9534          --------------------
9535
9536          --  pragma Interface_Name (
9537          --    [  Entity        =>] local_NAME
9538          --    [,[External_Name =>] static_string_EXPRESSION ]
9539          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9540
9541          when Pragma_Interface_Name => Interface_Name : declare
9542             Id     : Node_Id;
9543             Def_Id : Entity_Id;
9544             Hom_Id : Entity_Id;
9545             Found  : Boolean;
9546
9547          begin
9548             GNAT_Pragma;
9549             Check_Arg_Order
9550               ((Name_Entity, Name_External_Name, Name_Link_Name));
9551             Check_At_Least_N_Arguments (2);
9552             Check_At_Most_N_Arguments  (3);
9553             Id := Get_Pragma_Arg (Arg1);
9554             Analyze (Id);
9555
9556             if not Is_Entity_Name (Id) then
9557                Error_Pragma_Arg
9558                  ("first argument for pragma% must be entity name", Arg1);
9559             elsif Etype (Id) = Any_Type then
9560                return;
9561             else
9562                Def_Id := Entity (Id);
9563             end if;
9564
9565             --  Special DEC-compatible processing for the object case, forces
9566             --  object to be imported.
9567
9568             if Ekind (Def_Id) = E_Variable then
9569                Kill_Size_Check_Code (Def_Id);
9570                Note_Possible_Modification (Id, Sure => False);
9571
9572                --  Initialization is not allowed for imported variable
9573
9574                if Present (Expression (Parent (Def_Id)))
9575                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9576                then
9577                   Error_Msg_Sloc := Sloc (Def_Id);
9578                   Error_Pragma_Arg
9579                     ("no initialization allowed for declaration of& #",
9580                      Arg2);
9581
9582                else
9583                   --  For compatibility, support VADS usage of providing both
9584                   --  pragmas Interface and Interface_Name to obtain the effect
9585                   --  of a single Import pragma.
9586
9587                   if Is_Imported (Def_Id)
9588                     and then Present (First_Rep_Item (Def_Id))
9589                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9590                     and then
9591                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9592                   then
9593                      null;
9594                   else
9595                      Set_Imported (Def_Id);
9596                   end if;
9597
9598                   Set_Is_Public (Def_Id);
9599                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9600                end if;
9601
9602             --  Otherwise must be subprogram
9603
9604             elsif not Is_Subprogram (Def_Id) then
9605                Error_Pragma_Arg
9606                  ("argument of pragma% is not subprogram", Arg1);
9607
9608             else
9609                Check_At_Most_N_Arguments (3);
9610                Hom_Id := Def_Id;
9611                Found := False;
9612
9613                --  Loop through homonyms
9614
9615                loop
9616                   Def_Id := Get_Base_Subprogram (Hom_Id);
9617
9618                   if Is_Imported (Def_Id) then
9619                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9620                      Found := True;
9621                   end if;
9622
9623                   exit when From_Aspect_Specification (N);
9624                   Hom_Id := Homonym (Hom_Id);
9625
9626                   exit when No (Hom_Id)
9627                     or else Scope (Hom_Id) /= Current_Scope;
9628                end loop;
9629
9630                if not Found then
9631                   Error_Pragma_Arg
9632                     ("argument of pragma% is not imported subprogram",
9633                      Arg1);
9634                end if;
9635             end if;
9636          end Interface_Name;
9637
9638          -----------------------
9639          -- Interrupt_Handler --
9640          -----------------------
9641
9642          --  pragma Interrupt_Handler (handler_NAME);
9643
9644          when Pragma_Interrupt_Handler =>
9645             Check_Ada_83_Warning;
9646             Check_Arg_Count (1);
9647             Check_No_Identifiers;
9648
9649             if No_Run_Time_Mode then
9650                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9651             else
9652                Check_Interrupt_Or_Attach_Handler;
9653                Process_Interrupt_Or_Attach_Handler;
9654             end if;
9655
9656          ------------------------
9657          -- Interrupt_Priority --
9658          ------------------------
9659
9660          --  pragma Interrupt_Priority [(EXPRESSION)];
9661
9662          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9663             P   : constant Node_Id := Parent (N);
9664             Arg : Node_Id;
9665
9666          begin
9667             Check_Ada_83_Warning;
9668
9669             if Arg_Count /= 0 then
9670                Arg := Get_Pragma_Arg (Arg1);
9671                Check_Arg_Count (1);
9672                Check_No_Identifiers;
9673
9674                --  The expression must be analyzed in the special manner
9675                --  described in "Handling of Default and Per-Object
9676                --  Expressions" in sem.ads.
9677
9678                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9679             end if;
9680
9681             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9682                Pragma_Misplaced;
9683                return;
9684
9685             elsif Has_Pragma_Priority (P) then
9686                Error_Pragma ("duplicate pragma% not allowed");
9687
9688             else
9689                Set_Has_Pragma_Priority (P, True);
9690                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9691             end if;
9692          end Interrupt_Priority;
9693
9694          ---------------------
9695          -- Interrupt_State --
9696          ---------------------
9697
9698          --  pragma Interrupt_State (
9699          --    [Name  =>] INTERRUPT_ID,
9700          --    [State =>] INTERRUPT_STATE);
9701
9702          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9703          --  INTERRUPT_STATE => System | Runtime | User
9704
9705          --  Note: if the interrupt id is given as an identifier, then it must
9706          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9707          --  given as a static integer expression which must be in the range of
9708          --  Ada.Interrupts.Interrupt_ID.
9709
9710          when Pragma_Interrupt_State => Interrupt_State : declare
9711
9712             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9713             --  This is the entity Ada.Interrupts.Interrupt_ID;
9714
9715             State_Type : Character;
9716             --  Set to 's'/'r'/'u' for System/Runtime/User
9717
9718             IST_Num : Pos;
9719             --  Index to entry in Interrupt_States table
9720
9721             Int_Val : Uint;
9722             --  Value of interrupt
9723
9724             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9725             --  The first argument to the pragma
9726
9727             Int_Ent : Entity_Id;
9728             --  Interrupt entity in Ada.Interrupts.Names
9729
9730          begin
9731             GNAT_Pragma;
9732             Check_Arg_Order ((Name_Name, Name_State));
9733             Check_Arg_Count (2);
9734
9735             Check_Optional_Identifier (Arg1, Name_Name);
9736             Check_Optional_Identifier (Arg2, Name_State);
9737             Check_Arg_Is_Identifier (Arg2);
9738
9739             --  First argument is identifier
9740
9741             if Nkind (Arg1X) = N_Identifier then
9742
9743                --  Search list of names in Ada.Interrupts.Names
9744
9745                Int_Ent := First_Entity (RTE (RE_Names));
9746                loop
9747                   if No (Int_Ent) then
9748                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9749
9750                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9751                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9752                      exit;
9753                   end if;
9754
9755                   Next_Entity (Int_Ent);
9756                end loop;
9757
9758             --  First argument is not an identifier, so it must be a static
9759             --  expression of type Ada.Interrupts.Interrupt_ID.
9760
9761             else
9762                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9763                Int_Val := Expr_Value (Arg1X);
9764
9765                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9766                     or else
9767                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9768                then
9769                   Error_Pragma_Arg
9770                     ("value not in range of type " &
9771                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9772                end if;
9773             end if;
9774
9775             --  Check OK state
9776
9777             case Chars (Get_Pragma_Arg (Arg2)) is
9778                when Name_Runtime => State_Type := 'r';
9779                when Name_System  => State_Type := 's';
9780                when Name_User    => State_Type := 'u';
9781
9782                when others =>
9783                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
9784             end case;
9785
9786             --  Check if entry is already stored
9787
9788             IST_Num := Interrupt_States.First;
9789             loop
9790                --  If entry not found, add it
9791
9792                if IST_Num > Interrupt_States.Last then
9793                   Interrupt_States.Append
9794                     ((Interrupt_Number => UI_To_Int (Int_Val),
9795                       Interrupt_State  => State_Type,
9796                       Pragma_Loc       => Loc));
9797                   exit;
9798
9799                --  Case of entry for the same entry
9800
9801                elsif Int_Val = Interrupt_States.Table (IST_Num).
9802                                                            Interrupt_Number
9803                then
9804                   --  If state matches, done, no need to make redundant entry
9805
9806                   exit when
9807                     State_Type = Interrupt_States.Table (IST_Num).
9808                                                            Interrupt_State;
9809
9810                   --  Otherwise if state does not match, error
9811
9812                   Error_Msg_Sloc :=
9813                     Interrupt_States.Table (IST_Num).Pragma_Loc;
9814                   Error_Pragma_Arg
9815                     ("state conflicts with that given #", Arg2);
9816                   exit;
9817                end if;
9818
9819                IST_Num := IST_Num + 1;
9820             end loop;
9821          end Interrupt_State;
9822
9823          ---------------
9824          -- Invariant --
9825          ---------------
9826
9827          --  pragma Invariant
9828          --    ([Entity =>]    type_LOCAL_NAME,
9829          --     [Check  =>]    EXPRESSION
9830          --     [,[Message =>] String_Expression]);
9831
9832          when Pragma_Invariant => Invariant : declare
9833             Type_Id : Node_Id;
9834             Typ     : Entity_Id;
9835
9836             Discard : Boolean;
9837             pragma Unreferenced (Discard);
9838
9839          begin
9840             GNAT_Pragma;
9841             Check_At_Least_N_Arguments (2);
9842             Check_At_Most_N_Arguments (3);
9843             Check_Optional_Identifier (Arg1, Name_Entity);
9844             Check_Optional_Identifier (Arg2, Name_Check);
9845
9846             if Arg_Count = 3 then
9847                Check_Optional_Identifier (Arg3, Name_Message);
9848                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9849             end if;
9850
9851             Check_Arg_Is_Local_Name (Arg1);
9852
9853             Type_Id := Get_Pragma_Arg (Arg1);
9854             Find_Type (Type_Id);
9855             Typ := Entity (Type_Id);
9856
9857             if Typ = Any_Type then
9858                return;
9859
9860             elsif not Ekind_In (Typ, E_Private_Type,
9861                                      E_Record_Type_With_Private,
9862                                      E_Limited_Private_Type)
9863             then
9864                Error_Pragma_Arg
9865                  ("pragma% only allowed for private type", Arg1);
9866             end if;
9867
9868             --  Note that the type has at least one invariant, and also that
9869             --  it has inheritable invariants if we have Invariant'Class.
9870
9871             Set_Has_Invariants (Typ);
9872
9873             if Class_Present (N) then
9874                Set_Has_Inheritable_Invariants (Typ);
9875             end if;
9876
9877             --  The remaining processing is simply to link the pragma on to
9878             --  the rep item chain, for processing when the type is frozen.
9879             --  This is accomplished by a call to Rep_Item_Too_Late.
9880
9881             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9882          end Invariant;
9883
9884          ----------------------
9885          -- Java_Constructor --
9886          ----------------------
9887
9888          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9889
9890          --  Also handles pragma CIL_Constructor
9891
9892          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9893          Java_Constructor : declare
9894             Convention  : Convention_Id;
9895             Def_Id      : Entity_Id;
9896             Hom_Id      : Entity_Id;
9897             Id          : Entity_Id;
9898             This_Formal : Entity_Id;
9899
9900          begin
9901             GNAT_Pragma;
9902             Check_Arg_Count (1);
9903             Check_Optional_Identifier (Arg1, Name_Entity);
9904             Check_Arg_Is_Local_Name (Arg1);
9905
9906             Id := Get_Pragma_Arg (Arg1);
9907             Find_Program_Unit_Name (Id);
9908
9909             --  If we did not find the name, we are done
9910
9911             if Etype (Id) = Any_Type then
9912                return;
9913             end if;
9914
9915             --  Check wrong use of pragma in wrong VM target
9916
9917             if VM_Target = No_VM then
9918                return;
9919
9920             elsif VM_Target = CLI_Target
9921               and then Prag_Id = Pragma_Java_Constructor
9922             then
9923                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9924
9925             elsif VM_Target = JVM_Target
9926               and then Prag_Id = Pragma_CIL_Constructor
9927             then
9928                Error_Pragma ("must use pragma 'Java_'Constructor");
9929             end if;
9930
9931             case Prag_Id is
9932                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
9933                when Pragma_Java_Constructor => Convention := Convention_Java;
9934                when others                  => null;
9935             end case;
9936
9937             Hom_Id := Entity (Id);
9938
9939             --  Loop through homonyms
9940
9941             loop
9942                Def_Id := Get_Base_Subprogram (Hom_Id);
9943
9944                --  The constructor is required to be a function
9945
9946                if Ekind (Def_Id) /= E_Function then
9947                   if VM_Target = JVM_Target then
9948                      Error_Pragma_Arg
9949                        ("pragma% requires function returning a " &
9950                         "'Java access type", Def_Id);
9951                   else
9952                      Error_Pragma_Arg
9953                        ("pragma% requires function returning a " &
9954                         "'C'I'L access type", Def_Id);
9955                   end if;
9956                end if;
9957
9958                --  Check arguments: For tagged type the first formal must be
9959                --  named "this" and its type must be a named access type
9960                --  designating a class-wide tagged type that has convention
9961                --  CIL/Java. The first formal must also have a null default
9962                --  value. For example:
9963
9964                --      type Typ is tagged ...
9965                --      type Ref is access all Typ;
9966                --      pragma Convention (CIL, Typ);
9967
9968                --      function New_Typ (This : Ref) return Ref;
9969                --      function New_Typ (This : Ref; I : Integer) return Ref;
9970                --      pragma Cil_Constructor (New_Typ);
9971
9972                --  Reason: The first formal must NOT be a primitive of the
9973                --  tagged type.
9974
9975                --  This rule also applies to constructors of delegates used
9976                --  to interface with standard target libraries. For example:
9977
9978                --      type Delegate is access procedure ...
9979                --      pragma Import (CIL, Delegate, ...);
9980
9981                --      function new_Delegate
9982                --        (This : Delegate := null; ... ) return Delegate;
9983
9984                --  For value-types this rule does not apply.
9985
9986                if not Is_Value_Type (Etype (Def_Id)) then
9987                   if No (First_Formal (Def_Id)) then
9988                      Error_Msg_Name_1 := Pname;
9989                      Error_Msg_N ("% function must have parameters", Def_Id);
9990                      return;
9991                   end if;
9992
9993                   --  In the JRE library we have several occurrences in which
9994                   --  the "this" parameter is not the first formal.
9995
9996                   This_Formal := First_Formal (Def_Id);
9997
9998                   --  In the JRE library we have several occurrences in which
9999                   --  the "this" parameter is not the first formal. Search for
10000                   --  it.
10001
10002                   if VM_Target = JVM_Target then
10003                      while Present (This_Formal)
10004                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10005                      loop
10006                         Next_Formal (This_Formal);
10007                      end loop;
10008
10009                      if No (This_Formal) then
10010                         This_Formal := First_Formal (Def_Id);
10011                      end if;
10012                   end if;
10013
10014                   --  Warning: The first parameter should be named "this".
10015                   --  We temporarily allow it because we have the following
10016                   --  case in the Java runtime (file s-osinte.ads) ???
10017
10018                   --    function new_Thread
10019                   --      (Self_Id : System.Address) return Thread_Id;
10020                   --    pragma Java_Constructor (new_Thread);
10021
10022                   if VM_Target = JVM_Target
10023                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10024                                = "self_id"
10025                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10026                   then
10027                      null;
10028
10029                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10030                      Error_Msg_Name_1 := Pname;
10031                      Error_Msg_N
10032                        ("first formal of % function must be named `this`",
10033                         Parent (This_Formal));
10034
10035                   elsif not Is_Access_Type (Etype (This_Formal)) then
10036                      Error_Msg_Name_1 := Pname;
10037                      Error_Msg_N
10038                        ("first formal of % function must be an access type",
10039                         Parameter_Type (Parent (This_Formal)));
10040
10041                   --  For delegates the type of the first formal must be a
10042                   --  named access-to-subprogram type (see previous example)
10043
10044                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10045                     and then Ekind (Etype (This_Formal))
10046                                /= E_Access_Subprogram_Type
10047                   then
10048                      Error_Msg_Name_1 := Pname;
10049                      Error_Msg_N
10050                        ("first formal of % function must be a named access" &
10051                         " to subprogram type",
10052                         Parameter_Type (Parent (This_Formal)));
10053
10054                   --  Warning: We should reject anonymous access types because
10055                   --  the constructor must not be handled as a primitive of the
10056                   --  tagged type. We temporarily allow it because this profile
10057                   --  is currently generated by cil2ada???
10058
10059                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10060                     and then not Ekind_In (Etype (This_Formal),
10061                                              E_Access_Type,
10062                                              E_General_Access_Type,
10063                                              E_Anonymous_Access_Type)
10064                   then
10065                      Error_Msg_Name_1 := Pname;
10066                      Error_Msg_N
10067                        ("first formal of % function must be a named access" &
10068                         " type",
10069                         Parameter_Type (Parent (This_Formal)));
10070
10071                   elsif Atree.Convention
10072                          (Designated_Type (Etype (This_Formal))) /= Convention
10073                   then
10074                      Error_Msg_Name_1 := Pname;
10075
10076                      if Convention = Convention_Java then
10077                         Error_Msg_N
10078                           ("pragma% requires convention 'Cil in designated" &
10079                            " type",
10080                            Parameter_Type (Parent (This_Formal)));
10081                      else
10082                         Error_Msg_N
10083                           ("pragma% requires convention 'Java in designated" &
10084                            " type",
10085                            Parameter_Type (Parent (This_Formal)));
10086                      end if;
10087
10088                   elsif No (Expression (Parent (This_Formal)))
10089                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10090                   then
10091                      Error_Msg_Name_1 := Pname;
10092                      Error_Msg_N
10093                        ("pragma% requires first formal with default `null`",
10094                         Parameter_Type (Parent (This_Formal)));
10095                   end if;
10096                end if;
10097
10098                --  Check result type: the constructor must be a function
10099                --  returning:
10100                --   * a value type (only allowed in the CIL compiler)
10101                --   * an access-to-subprogram type with convention Java/CIL
10102                --   * an access-type designating a type that has convention
10103                --     Java/CIL.
10104
10105                if Is_Value_Type (Etype (Def_Id)) then
10106                   null;
10107
10108                --  Access-to-subprogram type with convention Java/CIL
10109
10110                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10111                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10112                      if Convention = Convention_Java then
10113                         Error_Pragma_Arg
10114                           ("pragma% requires function returning a " &
10115                            "'Java access type", Arg1);
10116                      else
10117                         pragma Assert (Convention = Convention_CIL);
10118                         Error_Pragma_Arg
10119                           ("pragma% requires function returning a " &
10120                            "'C'I'L access type", Arg1);
10121                      end if;
10122                   end if;
10123
10124                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10125                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10126                                                    E_General_Access_Type)
10127                     or else
10128                       Atree.Convention
10129                         (Designated_Type (Etype (Def_Id))) /= Convention
10130                   then
10131                      Error_Msg_Name_1 := Pname;
10132
10133                      if Convention = Convention_Java then
10134                         Error_Pragma_Arg
10135                           ("pragma% requires function returning a named" &
10136                            "'Java access type", Arg1);
10137                      else
10138                         Error_Pragma_Arg
10139                           ("pragma% requires function returning a named" &
10140                            "'C'I'L access type", Arg1);
10141                      end if;
10142                   end if;
10143                end if;
10144
10145                Set_Is_Constructor (Def_Id);
10146                Set_Convention     (Def_Id, Convention);
10147                Set_Is_Imported    (Def_Id);
10148
10149                exit when From_Aspect_Specification (N);
10150                Hom_Id := Homonym (Hom_Id);
10151
10152                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10153             end loop;
10154          end Java_Constructor;
10155
10156          ----------------------
10157          -- Java_Interface --
10158          ----------------------
10159
10160          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10161
10162          when Pragma_Java_Interface => Java_Interface : declare
10163             Arg : Node_Id;
10164             Typ : Entity_Id;
10165
10166          begin
10167             GNAT_Pragma;
10168             Check_Arg_Count (1);
10169             Check_Optional_Identifier (Arg1, Name_Entity);
10170             Check_Arg_Is_Local_Name (Arg1);
10171
10172             Arg := Get_Pragma_Arg (Arg1);
10173             Analyze (Arg);
10174
10175             if Etype (Arg) = Any_Type then
10176                return;
10177             end if;
10178
10179             if not Is_Entity_Name (Arg)
10180               or else not Is_Type (Entity (Arg))
10181             then
10182                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10183             end if;
10184
10185             Typ := Underlying_Type (Entity (Arg));
10186
10187             --  For now simply check some of the semantic constraints on the
10188             --  type. This currently leaves out some restrictions on interface
10189             --  types, namely that the parent type must be java.lang.Object.Typ
10190             --  and that all primitives of the type should be declared
10191             --  abstract. ???
10192
10193             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10194                Error_Pragma_Arg ("pragma% requires an abstract "
10195                  & "tagged type", Arg1);
10196
10197             elsif not Has_Discriminants (Typ)
10198               or else Ekind (Etype (First_Discriminant (Typ)))
10199                         /= E_Anonymous_Access_Type
10200               or else
10201                 not Is_Class_Wide_Type
10202                       (Designated_Type (Etype (First_Discriminant (Typ))))
10203             then
10204                Error_Pragma_Arg
10205                  ("type must have a class-wide access discriminant", Arg1);
10206             end if;
10207          end Java_Interface;
10208
10209          ----------------
10210          -- Keep_Names --
10211          ----------------
10212
10213          --  pragma Keep_Names ([On => ] local_NAME);
10214
10215          when Pragma_Keep_Names => Keep_Names : declare
10216             Arg : Node_Id;
10217
10218          begin
10219             GNAT_Pragma;
10220             Check_Arg_Count (1);
10221             Check_Optional_Identifier (Arg1, Name_On);
10222             Check_Arg_Is_Local_Name (Arg1);
10223
10224             Arg := Get_Pragma_Arg (Arg1);
10225             Analyze (Arg);
10226
10227             if Etype (Arg) = Any_Type then
10228                return;
10229             end if;
10230
10231             if not Is_Entity_Name (Arg)
10232               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10233             then
10234                Error_Pragma_Arg
10235                  ("pragma% requires a local enumeration type", Arg1);
10236             end if;
10237
10238             Set_Discard_Names (Entity (Arg), False);
10239          end Keep_Names;
10240
10241          -------------
10242          -- License --
10243          -------------
10244
10245          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10246
10247          when Pragma_License =>
10248             GNAT_Pragma;
10249             Check_Arg_Count (1);
10250             Check_No_Identifiers;
10251             Check_Valid_Configuration_Pragma;
10252             Check_Arg_Is_Identifier (Arg1);
10253
10254             declare
10255                Sind : constant Source_File_Index :=
10256                         Source_Index (Current_Sem_Unit);
10257
10258             begin
10259                case Chars (Get_Pragma_Arg (Arg1)) is
10260                   when Name_GPL =>
10261                      Set_License (Sind, GPL);
10262
10263                   when Name_Modified_GPL =>
10264                      Set_License (Sind, Modified_GPL);
10265
10266                   when Name_Restricted =>
10267                      Set_License (Sind, Restricted);
10268
10269                   when Name_Unrestricted =>
10270                      Set_License (Sind, Unrestricted);
10271
10272                   when others =>
10273                      Error_Pragma_Arg ("invalid license name", Arg1);
10274                end case;
10275             end;
10276
10277          ---------------
10278          -- Link_With --
10279          ---------------
10280
10281          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10282
10283          when Pragma_Link_With => Link_With : declare
10284             Arg : Node_Id;
10285
10286          begin
10287             GNAT_Pragma;
10288
10289             if Operating_Mode = Generate_Code
10290               and then In_Extended_Main_Source_Unit (N)
10291             then
10292                Check_At_Least_N_Arguments (1);
10293                Check_No_Identifiers;
10294                Check_Is_In_Decl_Part_Or_Package_Spec;
10295                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10296                Start_String;
10297
10298                Arg := Arg1;
10299                while Present (Arg) loop
10300                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10301
10302                   --  Store argument, converting sequences of spaces to a
10303                   --  single null character (this is one of the differences
10304                   --  in processing between Link_With and Linker_Options).
10305
10306                   Arg_Store : declare
10307                      C : constant Char_Code := Get_Char_Code (' ');
10308                      S : constant String_Id :=
10309                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10310                      L : constant Nat := String_Length (S);
10311                      F : Nat := 1;
10312
10313                      procedure Skip_Spaces;
10314                      --  Advance F past any spaces
10315
10316                      -----------------
10317                      -- Skip_Spaces --
10318                      -----------------
10319
10320                      procedure Skip_Spaces is
10321                      begin
10322                         while F <= L and then Get_String_Char (S, F) = C loop
10323                            F := F + 1;
10324                         end loop;
10325                      end Skip_Spaces;
10326
10327                   --  Start of processing for Arg_Store
10328
10329                   begin
10330                      Skip_Spaces; -- skip leading spaces
10331
10332                      --  Loop through characters, changing any embedded
10333                      --  sequence of spaces to a single null character (this
10334                      --  is how Link_With/Linker_Options differ)
10335
10336                      while F <= L loop
10337                         if Get_String_Char (S, F) = C then
10338                            Skip_Spaces;
10339                            exit when F > L;
10340                            Store_String_Char (ASCII.NUL);
10341
10342                         else
10343                            Store_String_Char (Get_String_Char (S, F));
10344                            F := F + 1;
10345                         end if;
10346                      end loop;
10347                   end Arg_Store;
10348
10349                   Arg := Next (Arg);
10350
10351                   if Present (Arg) then
10352                      Store_String_Char (ASCII.NUL);
10353                   end if;
10354                end loop;
10355
10356                Store_Linker_Option_String (End_String);
10357             end if;
10358          end Link_With;
10359
10360          ------------------
10361          -- Linker_Alias --
10362          ------------------
10363
10364          --  pragma Linker_Alias (
10365          --      [Entity =>]  LOCAL_NAME
10366          --      [Target =>]  static_string_EXPRESSION);
10367
10368          when Pragma_Linker_Alias =>
10369             GNAT_Pragma;
10370             Check_Arg_Order ((Name_Entity, Name_Target));
10371             Check_Arg_Count (2);
10372             Check_Optional_Identifier (Arg1, Name_Entity);
10373             Check_Optional_Identifier (Arg2, Name_Target);
10374             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10375             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10376
10377             --  The only processing required is to link this item on to the
10378             --  list of rep items for the given entity. This is accomplished
10379             --  by the call to Rep_Item_Too_Late (when no error is detected
10380             --  and False is returned).
10381
10382             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10383                return;
10384             else
10385                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10386             end if;
10387
10388          ------------------------
10389          -- Linker_Constructor --
10390          ------------------------
10391
10392          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10393
10394          --  Code is shared with Linker_Destructor
10395
10396          -----------------------
10397          -- Linker_Destructor --
10398          -----------------------
10399
10400          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10401
10402          when Pragma_Linker_Constructor |
10403               Pragma_Linker_Destructor =>
10404          Linker_Constructor : declare
10405             Arg1_X : Node_Id;
10406             Proc   : Entity_Id;
10407
10408          begin
10409             GNAT_Pragma;
10410             Check_Arg_Count (1);
10411             Check_No_Identifiers;
10412             Check_Arg_Is_Local_Name (Arg1);
10413             Arg1_X := Get_Pragma_Arg (Arg1);
10414             Analyze (Arg1_X);
10415             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10416
10417             if not Is_Library_Level_Entity (Proc) then
10418                Error_Pragma_Arg
10419                 ("argument for pragma% must be library level entity", Arg1);
10420             end if;
10421
10422             --  The only processing required is to link this item on to the
10423             --  list of rep items for the given entity. This is accomplished
10424             --  by the call to Rep_Item_Too_Late (when no error is detected
10425             --  and False is returned).
10426
10427             if Rep_Item_Too_Late (Proc, N) then
10428                return;
10429             else
10430                Set_Has_Gigi_Rep_Item (Proc);
10431             end if;
10432          end Linker_Constructor;
10433
10434          --------------------
10435          -- Linker_Options --
10436          --------------------
10437
10438          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10439
10440          when Pragma_Linker_Options => Linker_Options : declare
10441             Arg : Node_Id;
10442
10443          begin
10444             Check_Ada_83_Warning;
10445             Check_No_Identifiers;
10446             Check_Arg_Count (1);
10447             Check_Is_In_Decl_Part_Or_Package_Spec;
10448             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10449             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10450
10451             Arg := Arg2;
10452             while Present (Arg) loop
10453                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10454                Store_String_Char (ASCII.NUL);
10455                Store_String_Chars
10456                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10457                Arg := Next (Arg);
10458             end loop;
10459
10460             if Operating_Mode = Generate_Code
10461               and then In_Extended_Main_Source_Unit (N)
10462             then
10463                Store_Linker_Option_String (End_String);
10464             end if;
10465          end Linker_Options;
10466
10467          --------------------
10468          -- Linker_Section --
10469          --------------------
10470
10471          --  pragma Linker_Section (
10472          --      [Entity  =>]  LOCAL_NAME
10473          --      [Section =>]  static_string_EXPRESSION);
10474
10475          when Pragma_Linker_Section =>
10476             GNAT_Pragma;
10477             Check_Arg_Order ((Name_Entity, Name_Section));
10478             Check_Arg_Count (2);
10479             Check_Optional_Identifier (Arg1, Name_Entity);
10480             Check_Optional_Identifier (Arg2, Name_Section);
10481             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10482             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10483
10484             --  This pragma applies only to objects
10485
10486             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10487                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10488             end if;
10489
10490             --  The only processing required is to link this item on to the
10491             --  list of rep items for the given entity. This is accomplished
10492             --  by the call to Rep_Item_Too_Late (when no error is detected
10493             --  and False is returned).
10494
10495             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10496                return;
10497             else
10498                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10499             end if;
10500
10501          ----------
10502          -- List --
10503          ----------
10504
10505          --  pragma List (On | Off)
10506
10507          --  There is nothing to do here, since we did all the processing for
10508          --  this pragma in Par.Prag (so that it works properly even in syntax
10509          --  only mode).
10510
10511          when Pragma_List =>
10512             null;
10513
10514          --------------------
10515          -- Locking_Policy --
10516          --------------------
10517
10518          --  pragma Locking_Policy (policy_IDENTIFIER);
10519
10520          when Pragma_Locking_Policy => declare
10521             LP : Character;
10522
10523          begin
10524             Check_Ada_83_Warning;
10525             Check_Arg_Count (1);
10526             Check_No_Identifiers;
10527             Check_Arg_Is_Locking_Policy (Arg1);
10528             Check_Valid_Configuration_Pragma;
10529             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10530             LP := Fold_Upper (Name_Buffer (1));
10531
10532             if Locking_Policy /= ' '
10533               and then Locking_Policy /= LP
10534             then
10535                Error_Msg_Sloc := Locking_Policy_Sloc;
10536                Error_Pragma ("locking policy incompatible with policy#");
10537
10538             --  Set new policy, but always preserve System_Location since we
10539             --  like the error message with the run time name.
10540
10541             else
10542                Locking_Policy := LP;
10543
10544                if Locking_Policy_Sloc /= System_Location then
10545                   Locking_Policy_Sloc := Loc;
10546                end if;
10547             end if;
10548          end;
10549
10550          ----------------
10551          -- Long_Float --
10552          ----------------
10553
10554          --  pragma Long_Float (D_Float | G_Float);
10555
10556          when Pragma_Long_Float =>
10557             GNAT_Pragma;
10558             Check_Valid_Configuration_Pragma;
10559             Check_Arg_Count (1);
10560             Check_No_Identifier (Arg1);
10561             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10562
10563             if not OpenVMS_On_Target then
10564                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10565             end if;
10566
10567             --  D_Float case
10568
10569             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10570                if Opt.Float_Format_Long = 'G' then
10571                   Error_Pragma ("G_Float previously specified");
10572                end if;
10573
10574                Opt.Float_Format_Long := 'D';
10575
10576             --  G_Float case (this is the default, does not need overriding)
10577
10578             else
10579                if Opt.Float_Format_Long = 'D' then
10580                   Error_Pragma ("D_Float previously specified");
10581                end if;
10582
10583                Opt.Float_Format_Long := 'G';
10584             end if;
10585
10586             Set_Standard_Fpt_Formats;
10587
10588          -----------------------
10589          -- Machine_Attribute --
10590          -----------------------
10591
10592          --  pragma Machine_Attribute (
10593          --       [Entity         =>] LOCAL_NAME,
10594          --       [Attribute_Name =>] static_string_EXPRESSION
10595          --    [, [Info           =>] static_EXPRESSION] );
10596
10597          when Pragma_Machine_Attribute => Machine_Attribute : declare
10598             Def_Id : Entity_Id;
10599
10600          begin
10601             GNAT_Pragma;
10602             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10603
10604             if Arg_Count = 3 then
10605                Check_Optional_Identifier (Arg3, Name_Info);
10606                Check_Arg_Is_Static_Expression (Arg3);
10607             else
10608                Check_Arg_Count (2);
10609             end if;
10610
10611             Check_Optional_Identifier (Arg1, Name_Entity);
10612             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10613             Check_Arg_Is_Local_Name (Arg1);
10614             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10615             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10616
10617             if Is_Access_Type (Def_Id) then
10618                Def_Id := Designated_Type (Def_Id);
10619             end if;
10620
10621             if Rep_Item_Too_Early (Def_Id, N) then
10622                return;
10623             end if;
10624
10625             Def_Id := Underlying_Type (Def_Id);
10626
10627             --  The only processing required is to link this item on to the
10628             --  list of rep items for the given entity. This is accomplished
10629             --  by the call to Rep_Item_Too_Late (when no error is detected
10630             --  and False is returned).
10631
10632             if Rep_Item_Too_Late (Def_Id, N) then
10633                return;
10634             else
10635                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10636             end if;
10637          end Machine_Attribute;
10638
10639          ----------
10640          -- Main --
10641          ----------
10642
10643          --  pragma Main
10644          --   (MAIN_OPTION [, MAIN_OPTION]);
10645
10646          --  MAIN_OPTION ::=
10647          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10648          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10649          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10650
10651          when Pragma_Main => Main : declare
10652             Args  : Args_List (1 .. 3);
10653             Names : constant Name_List (1 .. 3) := (
10654                       Name_Stack_Size,
10655                       Name_Task_Stack_Size_Default,
10656                       Name_Time_Slicing_Enabled);
10657
10658             Nod : Node_Id;
10659
10660          begin
10661             GNAT_Pragma;
10662             Gather_Associations (Names, Args);
10663
10664             for J in 1 .. 2 loop
10665                if Present (Args (J)) then
10666                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10667                end if;
10668             end loop;
10669
10670             if Present (Args (3)) then
10671                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10672             end if;
10673
10674             Nod := Next (N);
10675             while Present (Nod) loop
10676                if Nkind (Nod) = N_Pragma
10677                  and then Pragma_Name (Nod) = Name_Main
10678                then
10679                   Error_Msg_Name_1 := Pname;
10680                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10681                end if;
10682
10683                Next (Nod);
10684             end loop;
10685          end Main;
10686
10687          ------------------
10688          -- Main_Storage --
10689          ------------------
10690
10691          --  pragma Main_Storage
10692          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10693
10694          --  MAIN_STORAGE_OPTION ::=
10695          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10696          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10697
10698          when Pragma_Main_Storage => Main_Storage : declare
10699             Args  : Args_List (1 .. 2);
10700             Names : constant Name_List (1 .. 2) := (
10701                       Name_Working_Storage,
10702                       Name_Top_Guard);
10703
10704             Nod : Node_Id;
10705
10706          begin
10707             GNAT_Pragma;
10708             Gather_Associations (Names, Args);
10709
10710             for J in 1 .. 2 loop
10711                if Present (Args (J)) then
10712                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10713                end if;
10714             end loop;
10715
10716             Check_In_Main_Program;
10717
10718             Nod := Next (N);
10719             while Present (Nod) loop
10720                if Nkind (Nod) = N_Pragma
10721                  and then Pragma_Name (Nod) = Name_Main_Storage
10722                then
10723                   Error_Msg_Name_1 := Pname;
10724                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10725                end if;
10726
10727                Next (Nod);
10728             end loop;
10729          end Main_Storage;
10730
10731          -----------------
10732          -- Memory_Size --
10733          -----------------
10734
10735          --  pragma Memory_Size (NUMERIC_LITERAL)
10736
10737          when Pragma_Memory_Size =>
10738             GNAT_Pragma;
10739
10740             --  Memory size is simply ignored
10741
10742             Check_No_Identifiers;
10743             Check_Arg_Count (1);
10744             Check_Arg_Is_Integer_Literal (Arg1);
10745
10746          -------------
10747          -- No_Body --
10748          -------------
10749
10750          --  pragma No_Body;
10751
10752          --  The only correct use of this pragma is on its own in a file, in
10753          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10754          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10755          --  check for a file containing nothing but a No_Body pragma). If we
10756          --  attempt to process it during normal semantics processing, it means
10757          --  it was misplaced.
10758
10759          when Pragma_No_Body =>
10760             GNAT_Pragma;
10761             Pragma_Misplaced;
10762
10763          ---------------
10764          -- No_Return --
10765          ---------------
10766
10767          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10768
10769          when Pragma_No_Return => No_Return : declare
10770             Id    : Node_Id;
10771             E     : Entity_Id;
10772             Found : Boolean;
10773             Arg   : Node_Id;
10774
10775          begin
10776             Ada_2005_Pragma;
10777             Check_At_Least_N_Arguments (1);
10778
10779             --  Loop through arguments of pragma
10780
10781             Arg := Arg1;
10782             while Present (Arg) loop
10783                Check_Arg_Is_Local_Name (Arg);
10784                Id := Get_Pragma_Arg (Arg);
10785                Analyze (Id);
10786
10787                if not Is_Entity_Name (Id) then
10788                   Error_Pragma_Arg ("entity name required", Arg);
10789                end if;
10790
10791                if Etype (Id) = Any_Type then
10792                   raise Pragma_Exit;
10793                end if;
10794
10795                --  Loop to find matching procedures
10796
10797                E := Entity (Id);
10798                Found := False;
10799                while Present (E)
10800                  and then Scope (E) = Current_Scope
10801                loop
10802                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10803                      Set_No_Return (E);
10804
10805                      --  Set flag on any alias as well
10806
10807                      if Is_Overloadable (E) and then Present (Alias (E)) then
10808                         Set_No_Return (Alias (E));
10809                      end if;
10810
10811                      Found := True;
10812                   end if;
10813
10814                   exit when From_Aspect_Specification (N);
10815                   E := Homonym (E);
10816                end loop;
10817
10818                if not Found then
10819                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10820                end if;
10821
10822                Next (Arg);
10823             end loop;
10824          end No_Return;
10825
10826          -----------------
10827          -- No_Run_Time --
10828          -----------------
10829
10830          --  pragma No_Run_Time;
10831
10832          --  Note: this pragma is retained for backwards compatibility. See
10833          --  body of Rtsfind for full details on its handling.
10834
10835          when Pragma_No_Run_Time =>
10836             GNAT_Pragma;
10837             Check_Valid_Configuration_Pragma;
10838             Check_Arg_Count (0);
10839
10840             No_Run_Time_Mode           := True;
10841             Configurable_Run_Time_Mode := True;
10842
10843             --  Set Duration to 32 bits if word size is 32
10844
10845             if Ttypes.System_Word_Size = 32 then
10846                Duration_32_Bits_On_Target := True;
10847             end if;
10848
10849             --  Set appropriate restrictions
10850
10851             Set_Restriction (No_Finalization, N);
10852             Set_Restriction (No_Exception_Handlers, N);
10853             Set_Restriction (Max_Tasks, N, 0);
10854             Set_Restriction (No_Tasking, N);
10855
10856          ------------------------
10857          -- No_Strict_Aliasing --
10858          ------------------------
10859
10860          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10861
10862          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10863             E_Id : Entity_Id;
10864
10865          begin
10866             GNAT_Pragma;
10867             Check_At_Most_N_Arguments (1);
10868
10869             if Arg_Count = 0 then
10870                Check_Valid_Configuration_Pragma;
10871                Opt.No_Strict_Aliasing := True;
10872
10873             else
10874                Check_Optional_Identifier (Arg2, Name_Entity);
10875                Check_Arg_Is_Local_Name (Arg1);
10876                E_Id := Entity (Get_Pragma_Arg (Arg1));
10877
10878                if E_Id = Any_Type then
10879                   return;
10880                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10881                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
10882                end if;
10883
10884                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10885             end if;
10886          end No_Strict_Aliasing;
10887
10888          -----------------------
10889          -- Normalize_Scalars --
10890          -----------------------
10891
10892          --  pragma Normalize_Scalars;
10893
10894          when Pragma_Normalize_Scalars =>
10895             Check_Ada_83_Warning;
10896             Check_Arg_Count (0);
10897             Check_Valid_Configuration_Pragma;
10898
10899             --  Normalize_Scalars creates false positives in CodePeer, so
10900             --  ignore this pragma in this mode.
10901
10902             if not CodePeer_Mode then
10903                Normalize_Scalars := True;
10904                Init_Or_Norm_Scalars := True;
10905             end if;
10906
10907          -----------------
10908          -- Obsolescent --
10909          -----------------
10910
10911          --  pragma Obsolescent;
10912
10913          --  pragma Obsolescent (
10914          --    [Message =>] static_string_EXPRESSION
10915          --  [,[Version =>] Ada_05]]);
10916
10917          --  pragma Obsolescent (
10918          --    [Entity  =>] NAME
10919          --  [,[Message =>] static_string_EXPRESSION
10920          --  [,[Version =>] Ada_05]] );
10921
10922          when Pragma_Obsolescent => Obsolescent : declare
10923             Ename : Node_Id;
10924             Decl  : Node_Id;
10925
10926             procedure Set_Obsolescent (E : Entity_Id);
10927             --  Given an entity Ent, mark it as obsolescent if appropriate
10928
10929             ---------------------
10930             -- Set_Obsolescent --
10931             ---------------------
10932
10933             procedure Set_Obsolescent (E : Entity_Id) is
10934                Active : Boolean;
10935                Ent    : Entity_Id;
10936                S      : String_Id;
10937
10938             begin
10939                Active := True;
10940                Ent    := E;
10941
10942                --  Entity name was given
10943
10944                if Present (Ename) then
10945
10946                   --  If entity name matches, we are fine. Save entity in
10947                   --  pragma argument, for ASIS use.
10948
10949                   if Chars (Ename) = Chars (Ent) then
10950                      Set_Entity (Ename, Ent);
10951                      Generate_Reference (Ent, Ename);
10952
10953                   --  If entity name does not match, only possibility is an
10954                   --  enumeration literal from an enumeration type declaration.
10955
10956                   elsif Ekind (Ent) /= E_Enumeration_Type then
10957                      Error_Pragma
10958                        ("pragma % entity name does not match declaration");
10959
10960                   else
10961                      Ent := First_Literal (E);
10962                      loop
10963                         if No (Ent) then
10964                            Error_Pragma
10965                              ("pragma % entity name does not match any " &
10966                               "enumeration literal");
10967
10968                         elsif Chars (Ent) = Chars (Ename) then
10969                            Set_Entity (Ename, Ent);
10970                            Generate_Reference (Ent, Ename);
10971                            exit;
10972
10973                         else
10974                            Ent := Next_Literal (Ent);
10975                         end if;
10976                      end loop;
10977                   end if;
10978                end if;
10979
10980                --  Ent points to entity to be marked
10981
10982                if Arg_Count >= 1 then
10983
10984                   --  Deal with static string argument
10985
10986                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10987                   S := Strval (Get_Pragma_Arg (Arg1));
10988
10989                   for J in 1 .. String_Length (S) loop
10990                      if not In_Character_Range (Get_String_Char (S, J)) then
10991                         Error_Pragma_Arg
10992                           ("pragma% argument does not allow wide characters",
10993                            Arg1);
10994                      end if;
10995                   end loop;
10996
10997                   Obsolescent_Warnings.Append
10998                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
10999
11000                   --  Check for Ada_05 parameter
11001
11002                   if Arg_Count /= 1 then
11003                      Check_Arg_Count (2);
11004
11005                      declare
11006                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11007
11008                      begin
11009                         Check_Arg_Is_Identifier (Argx);
11010
11011                         if Chars (Argx) /= Name_Ada_05 then
11012                            Error_Msg_Name_2 := Name_Ada_05;
11013                            Error_Pragma_Arg
11014                              ("only allowed argument for pragma% is %", Argx);
11015                         end if;
11016
11017                         if Ada_Version_Explicit < Ada_2005
11018                           or else not Warn_On_Ada_2005_Compatibility
11019                         then
11020                            Active := False;
11021                         end if;
11022                      end;
11023                   end if;
11024                end if;
11025
11026                --  Set flag if pragma active
11027
11028                if Active then
11029                   Set_Is_Obsolescent (Ent);
11030                end if;
11031
11032                return;
11033             end Set_Obsolescent;
11034
11035          --  Start of processing for pragma Obsolescent
11036
11037          begin
11038             GNAT_Pragma;
11039
11040             Check_At_Most_N_Arguments (3);
11041
11042             --  See if first argument specifies an entity name
11043
11044             if Arg_Count >= 1
11045               and then
11046                 (Chars (Arg1) = Name_Entity
11047                    or else
11048                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11049                                                       N_Identifier,
11050                                                       N_Operator_Symbol))
11051             then
11052                Ename := Get_Pragma_Arg (Arg1);
11053
11054                --  Eliminate first argument, so we can share processing
11055
11056                Arg1 := Arg2;
11057                Arg2 := Arg3;
11058                Arg_Count := Arg_Count - 1;
11059
11060             --  No Entity name argument given
11061
11062             else
11063                Ename := Empty;
11064             end if;
11065
11066             if Arg_Count >= 1 then
11067                Check_Optional_Identifier (Arg1, Name_Message);
11068
11069                if Arg_Count = 2 then
11070                   Check_Optional_Identifier (Arg2, Name_Version);
11071                end if;
11072             end if;
11073
11074             --  Get immediately preceding declaration
11075
11076             Decl := Prev (N);
11077             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11078                Prev (Decl);
11079             end loop;
11080
11081             --  Cases where we do not follow anything other than another pragma
11082
11083             if No (Decl) then
11084
11085                --  First case: library level compilation unit declaration with
11086                --  the pragma immediately following the declaration.
11087
11088                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11089                   Set_Obsolescent
11090                     (Defining_Entity (Unit (Parent (Parent (N)))));
11091                   return;
11092
11093                --  Case 2: library unit placement for package
11094
11095                else
11096                   declare
11097                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11098                   begin
11099                      if Is_Package_Or_Generic_Package (Ent) then
11100                         Set_Obsolescent (Ent);
11101                         return;
11102                      end if;
11103                   end;
11104                end if;
11105
11106             --  Cases where we must follow a declaration
11107
11108             else
11109                if         Nkind (Decl) not in N_Declaration
11110                  and then Nkind (Decl) not in N_Later_Decl_Item
11111                  and then Nkind (Decl) not in N_Generic_Declaration
11112                  and then Nkind (Decl) not in N_Renaming_Declaration
11113                then
11114                   Error_Pragma
11115                     ("pragma% misplaced, "
11116                      & "must immediately follow a declaration");
11117
11118                else
11119                   Set_Obsolescent (Defining_Entity (Decl));
11120                   return;
11121                end if;
11122             end if;
11123          end Obsolescent;
11124
11125          --------------
11126          -- Optimize --
11127          --------------
11128
11129          --  pragma Optimize (Time | Space | Off);
11130
11131          --  The actual check for optimize is done in Gigi. Note that this
11132          --  pragma does not actually change the optimization setting, it
11133          --  simply checks that it is consistent with the pragma.
11134
11135          when Pragma_Optimize =>
11136             Check_No_Identifiers;
11137             Check_Arg_Count (1);
11138             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11139
11140          ------------------------
11141          -- Optimize_Alignment --
11142          ------------------------
11143
11144          --  pragma Optimize_Alignment (Time | Space | Off);
11145
11146          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11147             GNAT_Pragma;
11148             Check_No_Identifiers;
11149             Check_Arg_Count (1);
11150             Check_Valid_Configuration_Pragma;
11151
11152             declare
11153                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11154             begin
11155                case Nam is
11156                   when Name_Time =>
11157                      Opt.Optimize_Alignment := 'T';
11158                   when Name_Space =>
11159                      Opt.Optimize_Alignment := 'S';
11160                   when Name_Off =>
11161                      Opt.Optimize_Alignment := 'O';
11162                   when others =>
11163                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11164                end case;
11165             end;
11166
11167             --  Set indication that mode is set locally. If we are in fact in a
11168             --  configuration pragma file, this setting is harmless since the
11169             --  switch will get reset anyway at the start of each unit.
11170
11171             Optimize_Alignment_Local := True;
11172          end Optimize_Alignment;
11173
11174          -------------
11175          -- Ordered --
11176          -------------
11177
11178          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11179
11180          when Pragma_Ordered => Ordered : declare
11181             Assoc   : constant Node_Id := Arg1;
11182             Type_Id : Node_Id;
11183             Typ     : Entity_Id;
11184
11185          begin
11186             GNAT_Pragma;
11187             Check_No_Identifiers;
11188             Check_Arg_Count (1);
11189             Check_Arg_Is_Local_Name (Arg1);
11190
11191             Type_Id := Get_Pragma_Arg (Assoc);
11192             Find_Type (Type_Id);
11193             Typ := Entity (Type_Id);
11194
11195             if Typ = Any_Type then
11196                return;
11197             else
11198                Typ := Underlying_Type (Typ);
11199             end if;
11200
11201             if not Is_Enumeration_Type (Typ) then
11202                Error_Pragma ("pragma% must specify enumeration type");
11203             end if;
11204
11205             Check_First_Subtype (Arg1);
11206             Set_Has_Pragma_Ordered (Base_Type (Typ));
11207          end Ordered;
11208
11209          ----------
11210          -- Pack --
11211          ----------
11212
11213          --  pragma Pack (first_subtype_LOCAL_NAME);
11214
11215          when Pragma_Pack => Pack : declare
11216             Assoc   : constant Node_Id := Arg1;
11217             Type_Id : Node_Id;
11218             Typ     : Entity_Id;
11219             Ctyp    : Entity_Id;
11220             Ignore  : Boolean := False;
11221
11222          begin
11223             Check_No_Identifiers;
11224             Check_Arg_Count (1);
11225             Check_Arg_Is_Local_Name (Arg1);
11226
11227             Type_Id := Get_Pragma_Arg (Assoc);
11228             Find_Type (Type_Id);
11229             Typ := Entity (Type_Id);
11230
11231             if Typ = Any_Type
11232               or else Rep_Item_Too_Early (Typ, N)
11233             then
11234                return;
11235             else
11236                Typ := Underlying_Type (Typ);
11237             end if;
11238
11239             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11240                Error_Pragma ("pragma% must specify array or record type");
11241             end if;
11242
11243             Check_First_Subtype (Arg1);
11244             Check_Duplicate_Pragma (Typ);
11245
11246             --  Array type
11247
11248             if Is_Array_Type (Typ) then
11249                Ctyp := Component_Type (Typ);
11250
11251                --  Ignore pack that does nothing
11252
11253                if Known_Static_Esize (Ctyp)
11254                  and then Known_Static_RM_Size (Ctyp)
11255                  and then Esize (Ctyp) = RM_Size (Ctyp)
11256                  and then Addressable (Esize (Ctyp))
11257                then
11258                   Ignore := True;
11259                end if;
11260
11261                --  Process OK pragma Pack. Note that if there is a separate
11262                --  component clause present, the Pack will be cancelled. This
11263                --  processing is in Freeze.
11264
11265                if not Rep_Item_Too_Late (Typ, N) then
11266
11267                   --  In the context of static code analysis, we do not need
11268                   --  complex front-end expansions related to pragma Pack,
11269                   --  so disable handling of pragma Pack in this case.
11270
11271                   if CodePeer_Mode then
11272                      null;
11273
11274                   --  Don't attempt any packing for VM targets. We possibly
11275                   --  could deal with some cases of array bit-packing, but we
11276                   --  don't bother, since this is not a typical kind of
11277                   --  representation in the VM context anyway (and would not
11278                   --  for example work nicely with the debugger).
11279
11280                   elsif VM_Target /= No_VM then
11281                      if not GNAT_Mode then
11282                         Error_Pragma
11283                           ("?pragma% ignored in this configuration");
11284                      end if;
11285
11286                   --  Normal case where we do the pack action
11287
11288                   else
11289                      if not Ignore then
11290                         Set_Is_Packed            (Base_Type (Typ));
11291                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11292                      end if;
11293
11294                      Set_Has_Pragma_Pack (Base_Type (Typ));
11295                   end if;
11296                end if;
11297
11298             --  For record types, the pack is always effective
11299
11300             else pragma Assert (Is_Record_Type (Typ));
11301                if not Rep_Item_Too_Late (Typ, N) then
11302
11303                   --  Ignore pack request with warning in VM mode (skip warning
11304                   --  if we are compiling GNAT run time library).
11305
11306                   if VM_Target /= No_VM then
11307                      if not GNAT_Mode then
11308                         Error_Pragma
11309                           ("?pragma% ignored in this configuration");
11310                      end if;
11311
11312                   --  Normal case of pack request active
11313
11314                   else
11315                      Set_Is_Packed            (Base_Type (Typ));
11316                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11317                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11318                   end if;
11319                end if;
11320             end if;
11321          end Pack;
11322
11323          ----------
11324          -- Page --
11325          ----------
11326
11327          --  pragma Page;
11328
11329          --  There is nothing to do here, since we did all the processing for
11330          --  this pragma in Par.Prag (so that it works properly even in syntax
11331          --  only mode).
11332
11333          when Pragma_Page =>
11334             null;
11335
11336          -------------
11337          -- Passive --
11338          -------------
11339
11340          --  pragma Passive [(PASSIVE_FORM)];
11341
11342          --  PASSIVE_FORM ::= Semaphore | No
11343
11344          when Pragma_Passive =>
11345             GNAT_Pragma;
11346
11347             if Nkind (Parent (N)) /= N_Task_Definition then
11348                Error_Pragma ("pragma% must be within task definition");
11349             end if;
11350
11351             if Arg_Count /= 0 then
11352                Check_Arg_Count (1);
11353                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11354             end if;
11355
11356          ----------------------------------
11357          -- Preelaborable_Initialization --
11358          ----------------------------------
11359
11360          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11361
11362          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11363             Ent : Entity_Id;
11364
11365          begin
11366             Ada_2005_Pragma;
11367             Check_Arg_Count (1);
11368             Check_No_Identifiers;
11369             Check_Arg_Is_Identifier (Arg1);
11370             Check_Arg_Is_Local_Name (Arg1);
11371             Check_First_Subtype (Arg1);
11372             Ent := Entity (Get_Pragma_Arg (Arg1));
11373
11374             if not (Is_Private_Type (Ent)
11375                       or else
11376                     Is_Protected_Type (Ent)
11377                       or else
11378                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11379             then
11380                Error_Pragma_Arg
11381                  ("pragma % can only be applied to private, formal derived or "
11382                   & "protected type",
11383                   Arg1);
11384             end if;
11385
11386             --  Give an error if the pragma is applied to a protected type that
11387             --  does not qualify (due to having entries, or due to components
11388             --  that do not qualify).
11389
11390             if Is_Protected_Type (Ent)
11391               and then not Has_Preelaborable_Initialization (Ent)
11392             then
11393                Error_Msg_N
11394                  ("protected type & does not have preelaborable " &
11395                   "initialization", Ent);
11396
11397             --  Otherwise mark the type as definitely having preelaborable
11398             --  initialization.
11399
11400             else
11401                Set_Known_To_Have_Preelab_Init (Ent);
11402             end if;
11403
11404             if Has_Pragma_Preelab_Init (Ent)
11405               and then Warn_On_Redundant_Constructs
11406             then
11407                Error_Pragma ("?duplicate pragma%!");
11408             else
11409                Set_Has_Pragma_Preelab_Init (Ent);
11410             end if;
11411          end Preelab_Init;
11412
11413          --------------------
11414          -- Persistent_BSS --
11415          --------------------
11416
11417          --  pragma Persistent_BSS [(object_NAME)];
11418
11419          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11420             Decl : Node_Id;
11421             Ent  : Entity_Id;
11422             Prag : Node_Id;
11423
11424          begin
11425             GNAT_Pragma;
11426             Check_At_Most_N_Arguments (1);
11427
11428             --  Case of application to specific object (one argument)
11429
11430             if Arg_Count = 1 then
11431                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11432
11433                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11434                  or else not
11435                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11436                                                             E_Constant)
11437                then
11438                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11439                end if;
11440
11441                Ent := Entity (Get_Pragma_Arg (Arg1));
11442                Decl := Parent (Ent);
11443
11444                if Rep_Item_Too_Late (Ent, N) then
11445                   return;
11446                end if;
11447
11448                if Present (Expression (Decl)) then
11449                   Error_Pragma_Arg
11450                     ("object for pragma% cannot have initialization", Arg1);
11451                end if;
11452
11453                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11454                   Error_Pragma_Arg
11455                     ("object type for pragma% is not potentially persistent",
11456                      Arg1);
11457                end if;
11458
11459                Check_Duplicate_Pragma (Ent);
11460
11461                Prag :=
11462                  Make_Linker_Section_Pragma
11463                    (Ent, Sloc (N), ".persistent.bss");
11464                Insert_After (N, Prag);
11465                Analyze (Prag);
11466
11467             --  Case of use as configuration pragma with no arguments
11468
11469             else
11470                Check_Valid_Configuration_Pragma;
11471                Persistent_BSS_Mode := True;
11472             end if;
11473          end Persistent_BSS;
11474
11475          -------------
11476          -- Polling --
11477          -------------
11478
11479          --  pragma Polling (ON | OFF);
11480
11481          when Pragma_Polling =>
11482             GNAT_Pragma;
11483             Check_Arg_Count (1);
11484             Check_No_Identifiers;
11485             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11486             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11487
11488          -------------------
11489          -- Postcondition --
11490          -------------------
11491
11492          --  pragma Postcondition ([Check   =>] Boolean_Expression
11493          --                      [,[Message =>] String_Expression]);
11494
11495          when Pragma_Postcondition => Postcondition : declare
11496             In_Body : Boolean;
11497             pragma Warnings (Off, In_Body);
11498
11499          begin
11500             GNAT_Pragma;
11501             Check_At_Least_N_Arguments (1);
11502             Check_At_Most_N_Arguments (2);
11503             Check_Optional_Identifier (Arg1, Name_Check);
11504
11505             --  All we need to do here is call the common check procedure,
11506             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11507
11508             Check_Precondition_Postcondition (In_Body);
11509          end Postcondition;
11510
11511          ------------------
11512          -- Precondition --
11513          ------------------
11514
11515          --  pragma Precondition ([Check   =>] Boolean_Expression
11516          --                     [,[Message =>] String_Expression]);
11517
11518          when Pragma_Precondition => Precondition : declare
11519             In_Body : Boolean;
11520
11521          begin
11522             GNAT_Pragma;
11523             Check_At_Least_N_Arguments (1);
11524             Check_At_Most_N_Arguments (2);
11525             Check_Optional_Identifier (Arg1, Name_Check);
11526             Check_Precondition_Postcondition (In_Body);
11527
11528             --  If in spec, nothing more to do. If in body, then we convert the
11529             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11530             --  this whether or not precondition checks are enabled. That works
11531             --  fine since pragma Check will do this check, and will also
11532             --  analyze the condition itself in the proper context.
11533
11534             if In_Body then
11535                Rewrite (N,
11536                  Make_Pragma (Loc,
11537                    Chars => Name_Check,
11538                    Pragma_Argument_Associations => New_List (
11539                      Make_Pragma_Argument_Association (Loc,
11540                        Expression => Make_Identifier (Loc, Name_Precondition)),
11541
11542                      Make_Pragma_Argument_Association (Sloc (Arg1),
11543                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11544
11545                if Arg_Count = 2 then
11546                   Append_To (Pragma_Argument_Associations (N),
11547                     Make_Pragma_Argument_Association (Sloc (Arg2),
11548                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11549                end if;
11550
11551                Analyze (N);
11552             end if;
11553          end Precondition;
11554
11555          ---------------
11556          -- Predicate --
11557          ---------------
11558
11559          --  pragma Predicate
11560          --    ([Entity =>] type_LOCAL_NAME,
11561          --     [Check  =>] EXPRESSION);
11562
11563          when Pragma_Predicate => Predicate : declare
11564             Type_Id : Node_Id;
11565             Typ     : Entity_Id;
11566
11567             Discard : Boolean;
11568             pragma Unreferenced (Discard);
11569
11570          begin
11571             GNAT_Pragma;
11572             Check_Arg_Count (2);
11573             Check_Optional_Identifier (Arg1, Name_Entity);
11574             Check_Optional_Identifier (Arg2, Name_Check);
11575
11576             Check_Arg_Is_Local_Name (Arg1);
11577
11578             Type_Id := Get_Pragma_Arg (Arg1);
11579             Find_Type (Type_Id);
11580             Typ := Entity (Type_Id);
11581
11582             if Typ = Any_Type then
11583                return;
11584             end if;
11585
11586             --  The remaining processing is simply to link the pragma on to
11587             --  the rep item chain, for processing when the type is frozen.
11588             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11589             --  mark the type as having predicates.
11590
11591             Set_Has_Predicates (Typ);
11592             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11593          end Predicate;
11594
11595          ------------------
11596          -- Preelaborate --
11597          ------------------
11598
11599          --  pragma Preelaborate [(library_unit_NAME)];
11600
11601          --  Set the flag Is_Preelaborated of program unit name entity
11602
11603          when Pragma_Preelaborate => Preelaborate : declare
11604             Pa  : constant Node_Id   := Parent (N);
11605             Pk  : constant Node_Kind := Nkind (Pa);
11606             Ent : Entity_Id;
11607
11608          begin
11609             Check_Ada_83_Warning;
11610             Check_Valid_Library_Unit_Pragma;
11611
11612             if Nkind (N) = N_Null_Statement then
11613                return;
11614             end if;
11615
11616             Ent := Find_Lib_Unit_Name;
11617             Check_Duplicate_Pragma (Ent);
11618
11619             --  This filters out pragmas inside generic parent then
11620             --  show up inside instantiation
11621
11622             if Present (Ent)
11623               and then not (Pk = N_Package_Specification
11624                              and then Present (Generic_Parent (Pa)))
11625             then
11626                if not Debug_Flag_U then
11627                   Set_Is_Preelaborated (Ent);
11628                   Set_Suppress_Elaboration_Warnings (Ent);
11629                end if;
11630             end if;
11631          end Preelaborate;
11632
11633          ---------------------
11634          -- Preelaborate_05 --
11635          ---------------------
11636
11637          --  pragma Preelaborate_05 [(library_unit_NAME)];
11638
11639          --  This pragma is useable only in GNAT_Mode, where it is used like
11640          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11641          --  (otherwise it is ignored). This is used to implement AI-362 which
11642          --  recategorizes some run-time packages in Ada 2005 mode.
11643
11644          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11645             Ent : Entity_Id;
11646
11647          begin
11648             GNAT_Pragma;
11649             Check_Valid_Library_Unit_Pragma;
11650
11651             if not GNAT_Mode then
11652                Error_Pragma ("pragma% only available in GNAT mode");
11653             end if;
11654
11655             if Nkind (N) = N_Null_Statement then
11656                return;
11657             end if;
11658
11659             --  This is one of the few cases where we need to test the value of
11660             --  Ada_Version_Explicit rather than Ada_Version (which is always
11661             --  set to Ada_2012 in a predefined unit), we need to know the
11662             --  explicit version set to know if this pragma is active.
11663
11664             if Ada_Version_Explicit >= Ada_2005 then
11665                Ent := Find_Lib_Unit_Name;
11666                Set_Is_Preelaborated (Ent);
11667                Set_Suppress_Elaboration_Warnings (Ent);
11668             end if;
11669          end Preelaborate_05;
11670
11671          --------------
11672          -- Priority --
11673          --------------
11674
11675          --  pragma Priority (EXPRESSION);
11676
11677          when Pragma_Priority => Priority : declare
11678             P   : constant Node_Id := Parent (N);
11679             Arg : Node_Id;
11680
11681          begin
11682             Check_No_Identifiers;
11683             Check_Arg_Count (1);
11684
11685             --  Subprogram case
11686
11687             if Nkind (P) = N_Subprogram_Body then
11688                Check_In_Main_Program;
11689
11690                Arg := Get_Pragma_Arg (Arg1);
11691                Analyze_And_Resolve (Arg, Standard_Integer);
11692
11693                --  Must be static
11694
11695                if not Is_Static_Expression (Arg) then
11696                   Flag_Non_Static_Expr
11697                     ("main subprogram priority is not static!", Arg);
11698                   raise Pragma_Exit;
11699
11700                --  If constraint error, then we already signalled an error
11701
11702                elsif Raises_Constraint_Error (Arg) then
11703                   null;
11704
11705                --  Otherwise check in range
11706
11707                else
11708                   declare
11709                      Val : constant Uint := Expr_Value (Arg);
11710
11711                   begin
11712                      if Val < 0
11713                        or else Val > Expr_Value (Expression
11714                                        (Parent (RTE (RE_Max_Priority))))
11715                      then
11716                         Error_Pragma_Arg
11717                           ("main subprogram priority is out of range", Arg1);
11718                      end if;
11719                   end;
11720                end if;
11721
11722                Set_Main_Priority
11723                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11724
11725                --  Load an arbitrary entity from System.Tasking to make sure
11726                --  this package is implicitly with'ed, since we need to have
11727                --  the tasking run-time active for the pragma Priority to have
11728                --  any effect.
11729
11730                declare
11731                   Discard : Entity_Id;
11732                   pragma Warnings (Off, Discard);
11733                begin
11734                   Discard := RTE (RE_Task_List);
11735                end;
11736
11737             --  Task or Protected, must be of type Integer
11738
11739             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11740                Arg := Get_Pragma_Arg (Arg1);
11741
11742                --  The expression must be analyzed in the special manner
11743                --  described in "Handling of Default and Per-Object
11744                --  Expressions" in sem.ads.
11745
11746                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11747
11748                if not Is_Static_Expression (Arg) then
11749                   Check_Restriction (Static_Priorities, Arg);
11750                end if;
11751
11752             --  Anything else is incorrect
11753
11754             else
11755                Pragma_Misplaced;
11756             end if;
11757
11758             if Has_Pragma_Priority (P) then
11759                Error_Pragma ("duplicate pragma% not allowed");
11760             else
11761                Set_Has_Pragma_Priority (P, True);
11762
11763                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11764                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11765                   --  exp_ch9 should use this ???
11766                end if;
11767             end if;
11768          end Priority;
11769
11770          -----------------------------------
11771          -- Priority_Specific_Dispatching --
11772          -----------------------------------
11773
11774          --  pragma Priority_Specific_Dispatching (
11775          --    policy_IDENTIFIER,
11776          --    first_priority_EXPRESSION,
11777          --    last_priority_EXPRESSION);
11778
11779          when Pragma_Priority_Specific_Dispatching =>
11780          Priority_Specific_Dispatching : declare
11781             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11782             --  This is the entity System.Any_Priority;
11783
11784             DP          : Character;
11785             Lower_Bound : Node_Id;
11786             Upper_Bound : Node_Id;
11787             Lower_Val   : Uint;
11788             Upper_Val   : Uint;
11789
11790          begin
11791             Ada_2005_Pragma;
11792             Check_Arg_Count (3);
11793             Check_No_Identifiers;
11794             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11795             Check_Valid_Configuration_Pragma;
11796             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11797             DP := Fold_Upper (Name_Buffer (1));
11798
11799             Lower_Bound := Get_Pragma_Arg (Arg2);
11800             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11801             Lower_Val := Expr_Value (Lower_Bound);
11802
11803             Upper_Bound := Get_Pragma_Arg (Arg3);
11804             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11805             Upper_Val := Expr_Value (Upper_Bound);
11806
11807             --  It is not allowed to use Task_Dispatching_Policy and
11808             --  Priority_Specific_Dispatching in the same partition.
11809
11810             if Task_Dispatching_Policy /= ' ' then
11811                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11812                Error_Pragma
11813                  ("pragma% incompatible with Task_Dispatching_Policy#");
11814
11815             --  Check lower bound in range
11816
11817             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11818                     or else
11819                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11820             then
11821                Error_Pragma_Arg
11822                  ("first_priority is out of range", Arg2);
11823
11824             --  Check upper bound in range
11825
11826             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11827                     or else
11828                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11829             then
11830                Error_Pragma_Arg
11831                  ("last_priority is out of range", Arg3);
11832
11833             --  Check that the priority range is valid
11834
11835             elsif Lower_Val > Upper_Val then
11836                Error_Pragma
11837                  ("last_priority_expression must be greater than" &
11838                   " or equal to first_priority_expression");
11839
11840             --  Store the new policy, but always preserve System_Location since
11841             --  we like the error message with the run-time name.
11842
11843             else
11844                --  Check overlapping in the priority ranges specified in other
11845                --  Priority_Specific_Dispatching pragmas within the same
11846                --  partition. We can only check those we know about!
11847
11848                for J in
11849                   Specific_Dispatching.First .. Specific_Dispatching.Last
11850                loop
11851                   if Specific_Dispatching.Table (J).First_Priority in
11852                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11853                   or else Specific_Dispatching.Table (J).Last_Priority in
11854                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11855                   then
11856                      Error_Msg_Sloc :=
11857                        Specific_Dispatching.Table (J).Pragma_Loc;
11858                         Error_Pragma
11859                           ("priority range overlaps with "
11860                            & "Priority_Specific_Dispatching#");
11861                   end if;
11862                end loop;
11863
11864                --  The use of Priority_Specific_Dispatching is incompatible
11865                --  with Task_Dispatching_Policy.
11866
11867                if Task_Dispatching_Policy /= ' ' then
11868                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11869                      Error_Pragma
11870                        ("Priority_Specific_Dispatching incompatible "
11871                         & "with Task_Dispatching_Policy#");
11872                end if;
11873
11874                --  The use of Priority_Specific_Dispatching forces ceiling
11875                --  locking policy.
11876
11877                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11878                   Error_Msg_Sloc := Locking_Policy_Sloc;
11879                      Error_Pragma
11880                        ("Priority_Specific_Dispatching incompatible "
11881                         & "with Locking_Policy#");
11882
11883                --  Set the Ceiling_Locking policy, but preserve System_Location
11884                --  since we like the error message with the run time name.
11885
11886                else
11887                   Locking_Policy := 'C';
11888
11889                   if Locking_Policy_Sloc /= System_Location then
11890                      Locking_Policy_Sloc := Loc;
11891                   end if;
11892                end if;
11893
11894                --  Add entry in the table
11895
11896                Specific_Dispatching.Append
11897                     ((Dispatching_Policy => DP,
11898                       First_Priority     => UI_To_Int (Lower_Val),
11899                       Last_Priority      => UI_To_Int (Upper_Val),
11900                       Pragma_Loc         => Loc));
11901             end if;
11902          end Priority_Specific_Dispatching;
11903
11904          -------------
11905          -- Profile --
11906          -------------
11907
11908          --  pragma Profile (profile_IDENTIFIER);
11909
11910          --  profile_IDENTIFIER => Restricted | Ravenscar
11911
11912          when Pragma_Profile =>
11913             Ada_2005_Pragma;
11914             Check_Arg_Count (1);
11915             Check_Valid_Configuration_Pragma;
11916             Check_No_Identifiers;
11917
11918             declare
11919                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11920             begin
11921                if Chars (Argx) = Name_Ravenscar then
11922                   Set_Ravenscar_Profile (N);
11923                elsif Chars (Argx) = Name_Restricted then
11924                   Set_Profile_Restrictions
11925                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11926                else
11927                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11928                end if;
11929             end;
11930
11931          ----------------------
11932          -- Profile_Warnings --
11933          ----------------------
11934
11935          --  pragma Profile_Warnings (profile_IDENTIFIER);
11936
11937          --  profile_IDENTIFIER => Restricted | Ravenscar
11938
11939          when Pragma_Profile_Warnings =>
11940             GNAT_Pragma;
11941             Check_Arg_Count (1);
11942             Check_Valid_Configuration_Pragma;
11943             Check_No_Identifiers;
11944
11945             declare
11946                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11947             begin
11948                if Chars (Argx) = Name_Ravenscar then
11949                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11950                elsif Chars (Argx) = Name_Restricted then
11951                   Set_Profile_Restrictions (Restricted, N, Warn => True);
11952                else
11953                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11954                end if;
11955             end;
11956
11957          --------------------------
11958          -- Propagate_Exceptions --
11959          --------------------------
11960
11961          --  pragma Propagate_Exceptions;
11962
11963          --  Note: this pragma is obsolete and has no effect
11964
11965          when Pragma_Propagate_Exceptions =>
11966             GNAT_Pragma;
11967             Check_Arg_Count (0);
11968
11969             if In_Extended_Main_Source_Unit (N) then
11970                Propagate_Exceptions := True;
11971             end if;
11972
11973          ------------------
11974          -- Psect_Object --
11975          ------------------
11976
11977          --  pragma Psect_Object (
11978          --        [Internal =>] LOCAL_NAME,
11979          --     [, [External =>] EXTERNAL_SYMBOL]
11980          --     [, [Size     =>] EXTERNAL_SYMBOL]);
11981
11982          when Pragma_Psect_Object | Pragma_Common_Object =>
11983          Psect_Object : declare
11984             Args  : Args_List (1 .. 3);
11985             Names : constant Name_List (1 .. 3) := (
11986                       Name_Internal,
11987                       Name_External,
11988                       Name_Size);
11989
11990             Internal : Node_Id renames Args (1);
11991             External : Node_Id renames Args (2);
11992             Size     : Node_Id renames Args (3);
11993
11994             Def_Id : Entity_Id;
11995
11996             procedure Check_Too_Long (Arg : Node_Id);
11997             --  Posts message if the argument is an identifier with more
11998             --  than 31 characters, or a string literal with more than
11999             --  31 characters, and we are operating under VMS
12000
12001             --------------------
12002             -- Check_Too_Long --
12003             --------------------
12004
12005             procedure Check_Too_Long (Arg : Node_Id) is
12006                X : constant Node_Id := Original_Node (Arg);
12007
12008             begin
12009                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12010                   Error_Pragma_Arg
12011                     ("inappropriate argument for pragma %", Arg);
12012                end if;
12013
12014                if OpenVMS_On_Target then
12015                   if (Nkind (X) = N_String_Literal
12016                        and then String_Length (Strval (X)) > 31)
12017                     or else
12018                      (Nkind (X) = N_Identifier
12019                        and then Length_Of_Name (Chars (X)) > 31)
12020                   then
12021                      Error_Pragma_Arg
12022                        ("argument for pragma % is longer than 31 characters",
12023                         Arg);
12024                   end if;
12025                end if;
12026             end Check_Too_Long;
12027
12028          --  Start of processing for Common_Object/Psect_Object
12029
12030          begin
12031             GNAT_Pragma;
12032             Gather_Associations (Names, Args);
12033             Process_Extended_Import_Export_Internal_Arg (Internal);
12034
12035             Def_Id := Entity (Internal);
12036
12037             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12038                Error_Pragma_Arg
12039                  ("pragma% must designate an object", Internal);
12040             end if;
12041
12042             Check_Too_Long (Internal);
12043
12044             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12045                Error_Pragma_Arg
12046                  ("cannot use pragma% for imported/exported object",
12047                   Internal);
12048             end if;
12049
12050             if Is_Concurrent_Type (Etype (Internal)) then
12051                Error_Pragma_Arg
12052                  ("cannot specify pragma % for task/protected object",
12053                   Internal);
12054             end if;
12055
12056             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12057                  or else
12058                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12059             then
12060                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12061             end if;
12062
12063             if Ekind (Def_Id) = E_Constant then
12064                Error_Pragma_Arg
12065                  ("cannot specify pragma % for a constant", Internal);
12066             end if;
12067
12068             if Is_Record_Type (Etype (Internal)) then
12069                declare
12070                   Ent  : Entity_Id;
12071                   Decl : Entity_Id;
12072
12073                begin
12074                   Ent := First_Entity (Etype (Internal));
12075                   while Present (Ent) loop
12076                      Decl := Declaration_Node (Ent);
12077
12078                      if Ekind (Ent) = E_Component
12079                        and then Nkind (Decl) = N_Component_Declaration
12080                        and then Present (Expression (Decl))
12081                        and then Warn_On_Export_Import
12082                      then
12083                         Error_Msg_N
12084                           ("?object for pragma % has defaults", Internal);
12085                         exit;
12086
12087                      else
12088                         Next_Entity (Ent);
12089                      end if;
12090                   end loop;
12091                end;
12092             end if;
12093
12094             if Present (Size) then
12095                Check_Too_Long (Size);
12096             end if;
12097
12098             if Present (External) then
12099                Check_Arg_Is_External_Name (External);
12100                Check_Too_Long (External);
12101             end if;
12102
12103             --  If all error tests pass, link pragma on to the rep item chain
12104
12105             Record_Rep_Item (Def_Id, N);
12106          end Psect_Object;
12107
12108          ----------
12109          -- Pure --
12110          ----------
12111
12112          --  pragma Pure [(library_unit_NAME)];
12113
12114          when Pragma_Pure => Pure : declare
12115             Ent : Entity_Id;
12116
12117          begin
12118             Check_Ada_83_Warning;
12119             Check_Valid_Library_Unit_Pragma;
12120
12121             if Nkind (N) = N_Null_Statement then
12122                return;
12123             end if;
12124
12125             Ent := Find_Lib_Unit_Name;
12126             Set_Is_Pure (Ent);
12127             Set_Has_Pragma_Pure (Ent);
12128             Set_Suppress_Elaboration_Warnings (Ent);
12129          end Pure;
12130
12131          -------------
12132          -- Pure_05 --
12133          -------------
12134
12135          --  pragma Pure_05 [(library_unit_NAME)];
12136
12137          --  This pragma is useable only in GNAT_Mode, where it is used like
12138          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12139          --  it is ignored). It may be used after a pragma Preelaborate, in
12140          --  which case it overrides the effect of the pragma Preelaborate.
12141          --  This is used to implement AI-362 which recategorizes some run-time
12142          --  packages in Ada 2005 mode.
12143
12144          when Pragma_Pure_05 => Pure_05 : declare
12145             Ent : Entity_Id;
12146
12147          begin
12148             GNAT_Pragma;
12149             Check_Valid_Library_Unit_Pragma;
12150
12151             if not GNAT_Mode then
12152                Error_Pragma ("pragma% only available in GNAT mode");
12153             end if;
12154
12155             if Nkind (N) = N_Null_Statement then
12156                return;
12157             end if;
12158
12159             --  This is one of the few cases where we need to test the value of
12160             --  Ada_Version_Explicit rather than Ada_Version (which is always
12161             --  set to Ada_2012 in a predefined unit), we need to know the
12162             --  explicit version set to know if this pragma is active.
12163
12164             if Ada_Version_Explicit >= Ada_2005 then
12165                Ent := Find_Lib_Unit_Name;
12166                Set_Is_Preelaborated (Ent, False);
12167                Set_Is_Pure (Ent);
12168                Set_Suppress_Elaboration_Warnings (Ent);
12169             end if;
12170          end Pure_05;
12171
12172          -------------------
12173          -- Pure_Function --
12174          -------------------
12175
12176          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12177
12178          when Pragma_Pure_Function => Pure_Function : declare
12179             E_Id      : Node_Id;
12180             E         : Entity_Id;
12181             Def_Id    : Entity_Id;
12182             Effective : Boolean := False;
12183
12184          begin
12185             GNAT_Pragma;
12186             Check_Arg_Count (1);
12187             Check_Optional_Identifier (Arg1, Name_Entity);
12188             Check_Arg_Is_Local_Name (Arg1);
12189             E_Id := Get_Pragma_Arg (Arg1);
12190
12191             if Error_Posted (E_Id) then
12192                return;
12193             end if;
12194
12195             --  Loop through homonyms (overloadings) of referenced entity
12196
12197             E := Entity (E_Id);
12198
12199             if Present (E) then
12200                loop
12201                   Def_Id := Get_Base_Subprogram (E);
12202
12203                   if not Ekind_In (Def_Id, E_Function,
12204                                            E_Generic_Function,
12205                                            E_Operator)
12206                   then
12207                      Error_Pragma_Arg
12208                        ("pragma% requires a function name", Arg1);
12209                   end if;
12210
12211                   Set_Is_Pure (Def_Id);
12212
12213                   if not Has_Pragma_Pure_Function (Def_Id) then
12214                      Set_Has_Pragma_Pure_Function (Def_Id);
12215                      Effective := True;
12216                   end if;
12217
12218                   exit when From_Aspect_Specification (N);
12219                   E := Homonym (E);
12220                   exit when No (E) or else Scope (E) /= Current_Scope;
12221                end loop;
12222
12223                if not Effective
12224                  and then Warn_On_Redundant_Constructs
12225                then
12226                   Error_Msg_NE
12227                     ("pragma Pure_Function on& is redundant?",
12228                      N, Entity (E_Id));
12229                end if;
12230             end if;
12231          end Pure_Function;
12232
12233          --------------------
12234          -- Queuing_Policy --
12235          --------------------
12236
12237          --  pragma Queuing_Policy (policy_IDENTIFIER);
12238
12239          when Pragma_Queuing_Policy => declare
12240             QP : Character;
12241
12242          begin
12243             Check_Ada_83_Warning;
12244             Check_Arg_Count (1);
12245             Check_No_Identifiers;
12246             Check_Arg_Is_Queuing_Policy (Arg1);
12247             Check_Valid_Configuration_Pragma;
12248             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12249             QP := Fold_Upper (Name_Buffer (1));
12250
12251             if Queuing_Policy /= ' '
12252               and then Queuing_Policy /= QP
12253             then
12254                Error_Msg_Sloc := Queuing_Policy_Sloc;
12255                Error_Pragma ("queuing policy incompatible with policy#");
12256
12257             --  Set new policy, but always preserve System_Location since we
12258             --  like the error message with the run time name.
12259
12260             else
12261                Queuing_Policy := QP;
12262
12263                if Queuing_Policy_Sloc /= System_Location then
12264                   Queuing_Policy_Sloc := Loc;
12265                end if;
12266             end if;
12267          end;
12268
12269          -----------------------
12270          -- Relative_Deadline --
12271          -----------------------
12272
12273          --  pragma Relative_Deadline (time_span_EXPRESSION);
12274
12275          when Pragma_Relative_Deadline => Relative_Deadline : declare
12276             P   : constant Node_Id := Parent (N);
12277             Arg : Node_Id;
12278
12279          begin
12280             Ada_2005_Pragma;
12281             Check_No_Identifiers;
12282             Check_Arg_Count (1);
12283
12284             Arg := Get_Pragma_Arg (Arg1);
12285
12286             --  The expression must be analyzed in the special manner described
12287             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12288
12289             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12290
12291             --  Subprogram case
12292
12293             if Nkind (P) = N_Subprogram_Body then
12294                Check_In_Main_Program;
12295
12296             --  Tasks
12297
12298             elsif Nkind (P) = N_Task_Definition then
12299                null;
12300
12301             --  Anything else is incorrect
12302
12303             else
12304                Pragma_Misplaced;
12305             end if;
12306
12307             if Has_Relative_Deadline_Pragma (P) then
12308                Error_Pragma ("duplicate pragma% not allowed");
12309             else
12310                Set_Has_Relative_Deadline_Pragma (P, True);
12311
12312                if Nkind (P) = N_Task_Definition then
12313                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12314                end if;
12315             end if;
12316          end Relative_Deadline;
12317
12318          ---------------------------
12319          -- Remote_Call_Interface --
12320          ---------------------------
12321
12322          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12323
12324          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12325             Cunit_Node : Node_Id;
12326             Cunit_Ent  : Entity_Id;
12327             K          : Node_Kind;
12328
12329          begin
12330             Check_Ada_83_Warning;
12331             Check_Valid_Library_Unit_Pragma;
12332
12333             if Nkind (N) = N_Null_Statement then
12334                return;
12335             end if;
12336
12337             Cunit_Node := Cunit (Current_Sem_Unit);
12338             K          := Nkind (Unit (Cunit_Node));
12339             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12340
12341             if K = N_Package_Declaration
12342               or else K = N_Generic_Package_Declaration
12343               or else K = N_Subprogram_Declaration
12344               or else K = N_Generic_Subprogram_Declaration
12345               or else (K = N_Subprogram_Body
12346                          and then Acts_As_Spec (Unit (Cunit_Node)))
12347             then
12348                null;
12349             else
12350                Error_Pragma (
12351                  "pragma% must apply to package or subprogram declaration");
12352             end if;
12353
12354             Set_Is_Remote_Call_Interface (Cunit_Ent);
12355          end Remote_Call_Interface;
12356
12357          ------------------
12358          -- Remote_Types --
12359          ------------------
12360
12361          --  pragma Remote_Types [(library_unit_NAME)];
12362
12363          when Pragma_Remote_Types => Remote_Types : declare
12364             Cunit_Node : Node_Id;
12365             Cunit_Ent  : Entity_Id;
12366
12367          begin
12368             Check_Ada_83_Warning;
12369             Check_Valid_Library_Unit_Pragma;
12370
12371             if Nkind (N) = N_Null_Statement then
12372                return;
12373             end if;
12374
12375             Cunit_Node := Cunit (Current_Sem_Unit);
12376             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12377
12378             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12379                                                 N_Generic_Package_Declaration)
12380             then
12381                Error_Pragma
12382                  ("pragma% can only apply to a package declaration");
12383             end if;
12384
12385             Set_Is_Remote_Types (Cunit_Ent);
12386          end Remote_Types;
12387
12388          ---------------
12389          -- Ravenscar --
12390          ---------------
12391
12392          --  pragma Ravenscar;
12393
12394          when Pragma_Ravenscar =>
12395             GNAT_Pragma;
12396             Check_Arg_Count (0);
12397             Check_Valid_Configuration_Pragma;
12398             Set_Ravenscar_Profile (N);
12399
12400             if Warn_On_Obsolescent_Feature then
12401                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12402                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12403             end if;
12404
12405          -------------------------
12406          -- Restricted_Run_Time --
12407          -------------------------
12408
12409          --  pragma Restricted_Run_Time;
12410
12411          when Pragma_Restricted_Run_Time =>
12412             GNAT_Pragma;
12413             Check_Arg_Count (0);
12414             Check_Valid_Configuration_Pragma;
12415             Set_Profile_Restrictions
12416               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12417
12418             if Warn_On_Obsolescent_Feature then
12419                Error_Msg_N
12420                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12421                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12422             end if;
12423
12424          ------------------
12425          -- Restrictions --
12426          ------------------
12427
12428          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12429
12430          --  RESTRICTION ::=
12431          --    restriction_IDENTIFIER
12432          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12433
12434          when Pragma_Restrictions =>
12435             Process_Restrictions_Or_Restriction_Warnings
12436               (Warn => Treat_Restrictions_As_Warnings);
12437
12438          --------------------------
12439          -- Restriction_Warnings --
12440          --------------------------
12441
12442          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12443
12444          --  RESTRICTION ::=
12445          --    restriction_IDENTIFIER
12446          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12447
12448          when Pragma_Restriction_Warnings =>
12449             GNAT_Pragma;
12450             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12451
12452          ----------------
12453          -- Reviewable --
12454          ----------------
12455
12456          --  pragma Reviewable;
12457
12458          when Pragma_Reviewable =>
12459             Check_Ada_83_Warning;
12460             Check_Arg_Count (0);
12461
12462             --  Call dummy debugging function rv. This is done to assist front
12463             --  end debugging. By placing a Reviewable pragma in the source
12464             --  program, a breakpoint on rv catches this place in the source,
12465             --  allowing convenient stepping to the point of interest.
12466
12467             rv;
12468
12469          --------------------------
12470          -- Short_Circuit_And_Or --
12471          --------------------------
12472
12473          when Pragma_Short_Circuit_And_Or =>
12474             GNAT_Pragma;
12475             Check_Arg_Count (0);
12476             Check_Valid_Configuration_Pragma;
12477             Short_Circuit_And_Or := True;
12478
12479          -------------------
12480          -- Share_Generic --
12481          -------------------
12482
12483          --  pragma Share_Generic (NAME {, NAME});
12484
12485          when Pragma_Share_Generic =>
12486             GNAT_Pragma;
12487             Process_Generic_List;
12488
12489          ------------
12490          -- Shared --
12491          ------------
12492
12493          --  pragma Shared (LOCAL_NAME);
12494
12495          when Pragma_Shared =>
12496             GNAT_Pragma;
12497             Process_Atomic_Shared_Volatile;
12498
12499          --------------------
12500          -- Shared_Passive --
12501          --------------------
12502
12503          --  pragma Shared_Passive [(library_unit_NAME)];
12504
12505          --  Set the flag Is_Shared_Passive of program unit name entity
12506
12507          when Pragma_Shared_Passive => Shared_Passive : declare
12508             Cunit_Node : Node_Id;
12509             Cunit_Ent  : Entity_Id;
12510
12511          begin
12512             Check_Ada_83_Warning;
12513             Check_Valid_Library_Unit_Pragma;
12514
12515             if Nkind (N) = N_Null_Statement then
12516                return;
12517             end if;
12518
12519             Cunit_Node := Cunit (Current_Sem_Unit);
12520             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12521
12522             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12523                                                 N_Generic_Package_Declaration)
12524             then
12525                Error_Pragma
12526                  ("pragma% can only apply to a package declaration");
12527             end if;
12528
12529             Set_Is_Shared_Passive (Cunit_Ent);
12530          end Shared_Passive;
12531
12532          -----------------------
12533          -- Short_Descriptors --
12534          -----------------------
12535
12536          --  pragma Short_Descriptors;
12537
12538          when Pragma_Short_Descriptors =>
12539             GNAT_Pragma;
12540             Check_Arg_Count (0);
12541             Check_Valid_Configuration_Pragma;
12542             Short_Descriptors := True;
12543
12544          ----------------------
12545          -- Source_File_Name --
12546          ----------------------
12547
12548          --  There are five forms for this pragma:
12549
12550          --  pragma Source_File_Name (
12551          --    [UNIT_NAME      =>] unit_NAME,
12552          --     BODY_FILE_NAME =>  STRING_LITERAL
12553          --    [, [INDEX =>] INTEGER_LITERAL]);
12554
12555          --  pragma Source_File_Name (
12556          --    [UNIT_NAME      =>] unit_NAME,
12557          --     SPEC_FILE_NAME =>  STRING_LITERAL
12558          --    [, [INDEX =>] INTEGER_LITERAL]);
12559
12560          --  pragma Source_File_Name (
12561          --     BODY_FILE_NAME  => STRING_LITERAL
12562          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12563          --  [, CASING          => CASING_SPEC]);
12564
12565          --  pragma Source_File_Name (
12566          --     SPEC_FILE_NAME  => STRING_LITERAL
12567          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12568          --  [, CASING          => CASING_SPEC]);
12569
12570          --  pragma Source_File_Name (
12571          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12572          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12573          --  [, CASING             => CASING_SPEC]);
12574
12575          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12576
12577          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12578          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12579          --  only be used when no project file is used, while SFNP can only be
12580          --  used when a project file is used.
12581
12582          --  No processing here. Processing was completed during parsing, since
12583          --  we need to have file names set as early as possible. Units are
12584          --  loaded well before semantic processing starts.
12585
12586          --  The only processing we defer to this point is the check for
12587          --  correct placement.
12588
12589          when Pragma_Source_File_Name =>
12590             GNAT_Pragma;
12591             Check_Valid_Configuration_Pragma;
12592
12593          ------------------------------
12594          -- Source_File_Name_Project --
12595          ------------------------------
12596
12597          --  See Source_File_Name for syntax
12598
12599          --  No processing here. Processing was completed during parsing, since
12600          --  we need to have file names set as early as possible. Units are
12601          --  loaded well before semantic processing starts.
12602
12603          --  The only processing we defer to this point is the check for
12604          --  correct placement.
12605
12606          when Pragma_Source_File_Name_Project =>
12607             GNAT_Pragma;
12608             Check_Valid_Configuration_Pragma;
12609
12610             --  Check that a pragma Source_File_Name_Project is used only in a
12611             --  configuration pragmas file.
12612
12613             --  Pragmas Source_File_Name_Project should only be generated by
12614             --  the Project Manager in configuration pragmas files.
12615
12616             --  This is really an ugly test. It seems to depend on some
12617             --  accidental and undocumented property. At the very least it
12618             --  needs to be documented, but it would be better to have a
12619             --  clean way of testing if we are in a configuration file???
12620
12621             if Present (Parent (N)) then
12622                Error_Pragma
12623                  ("pragma% can only appear in a configuration pragmas file");
12624             end if;
12625
12626          ----------------------
12627          -- Source_Reference --
12628          ----------------------
12629
12630          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12631
12632          --  Nothing to do, all processing completed in Par.Prag, since we need
12633          --  the information for possible parser messages that are output.
12634
12635          when Pragma_Source_Reference =>
12636             GNAT_Pragma;
12637
12638          --------------------------------
12639          -- Static_Elaboration_Desired --
12640          --------------------------------
12641
12642          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12643
12644          when Pragma_Static_Elaboration_Desired =>
12645             GNAT_Pragma;
12646             Check_At_Most_N_Arguments (1);
12647
12648             if Is_Compilation_Unit (Current_Scope)
12649               and then Ekind (Current_Scope) = E_Package
12650             then
12651                Set_Static_Elaboration_Desired (Current_Scope, True);
12652             else
12653                Error_Pragma ("pragma% must apply to a library-level package");
12654             end if;
12655
12656          ------------------
12657          -- Storage_Size --
12658          ------------------
12659
12660          --  pragma Storage_Size (EXPRESSION);
12661
12662          when Pragma_Storage_Size => Storage_Size : declare
12663             P   : constant Node_Id := Parent (N);
12664             Arg : Node_Id;
12665
12666          begin
12667             Check_No_Identifiers;
12668             Check_Arg_Count (1);
12669
12670             --  The expression must be analyzed in the special manner described
12671             --  in "Handling of Default Expressions" in sem.ads.
12672
12673             Arg := Get_Pragma_Arg (Arg1);
12674             Preanalyze_Spec_Expression (Arg, Any_Integer);
12675
12676             if not Is_Static_Expression (Arg) then
12677                Check_Restriction (Static_Storage_Size, Arg);
12678             end if;
12679
12680             if Nkind (P) /= N_Task_Definition then
12681                Pragma_Misplaced;
12682                return;
12683
12684             else
12685                if Has_Storage_Size_Pragma (P) then
12686                   Error_Pragma ("duplicate pragma% not allowed");
12687                else
12688                   Set_Has_Storage_Size_Pragma (P, True);
12689                end if;
12690
12691                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12692                --  ???  exp_ch9 should use this!
12693             end if;
12694          end Storage_Size;
12695
12696          ------------------
12697          -- Storage_Unit --
12698          ------------------
12699
12700          --  pragma Storage_Unit (NUMERIC_LITERAL);
12701
12702          --  Only permitted argument is System'Storage_Unit value
12703
12704          when Pragma_Storage_Unit =>
12705             Check_No_Identifiers;
12706             Check_Arg_Count (1);
12707             Check_Arg_Is_Integer_Literal (Arg1);
12708
12709             if Intval (Get_Pragma_Arg (Arg1)) /=
12710               UI_From_Int (Ttypes.System_Storage_Unit)
12711             then
12712                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12713                Error_Pragma_Arg
12714                  ("the only allowed argument for pragma% is ^", Arg1);
12715             end if;
12716
12717          --------------------
12718          -- Stream_Convert --
12719          --------------------
12720
12721          --  pragma Stream_Convert (
12722          --    [Entity =>] type_LOCAL_NAME,
12723          --    [Read   =>] function_NAME,
12724          --    [Write  =>] function NAME);
12725
12726          when Pragma_Stream_Convert => Stream_Convert : declare
12727
12728             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12729             --  Check that the given argument is the name of a local function
12730             --  of one argument that is not overloaded earlier in the current
12731             --  local scope. A check is also made that the argument is a
12732             --  function with one parameter.
12733
12734             --------------------------------------
12735             -- Check_OK_Stream_Convert_Function --
12736             --------------------------------------
12737
12738             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12739                Ent : Entity_Id;
12740
12741             begin
12742                Check_Arg_Is_Local_Name (Arg);
12743                Ent := Entity (Get_Pragma_Arg (Arg));
12744
12745                if Has_Homonym (Ent) then
12746                   Error_Pragma_Arg
12747                     ("argument for pragma% may not be overloaded", Arg);
12748                end if;
12749
12750                if Ekind (Ent) /= E_Function
12751                  or else No (First_Formal (Ent))
12752                  or else Present (Next_Formal (First_Formal (Ent)))
12753                then
12754                   Error_Pragma_Arg
12755                     ("argument for pragma% must be" &
12756                      " function of one argument", Arg);
12757                end if;
12758             end Check_OK_Stream_Convert_Function;
12759
12760          --  Start of processing for Stream_Convert
12761
12762          begin
12763             GNAT_Pragma;
12764             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12765             Check_Arg_Count (3);
12766             Check_Optional_Identifier (Arg1, Name_Entity);
12767             Check_Optional_Identifier (Arg2, Name_Read);
12768             Check_Optional_Identifier (Arg3, Name_Write);
12769             Check_Arg_Is_Local_Name (Arg1);
12770             Check_OK_Stream_Convert_Function (Arg2);
12771             Check_OK_Stream_Convert_Function (Arg3);
12772
12773             declare
12774                Typ   : constant Entity_Id :=
12775                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12776                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12777                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12778
12779             begin
12780                Check_First_Subtype (Arg1);
12781
12782                --  Check for too early or too late. Note that we don't enforce
12783                --  the rule about primitive operations in this case, since, as
12784                --  is the case for explicit stream attributes themselves, these
12785                --  restrictions are not appropriate. Note that the chaining of
12786                --  the pragma by Rep_Item_Too_Late is actually the critical
12787                --  processing done for this pragma.
12788
12789                if Rep_Item_Too_Early (Typ, N)
12790                     or else
12791                   Rep_Item_Too_Late (Typ, N, FOnly => True)
12792                then
12793                   return;
12794                end if;
12795
12796                --  Return if previous error
12797
12798                if Etype (Typ) = Any_Type
12799                     or else
12800                   Etype (Read) = Any_Type
12801                     or else
12802                   Etype (Write) = Any_Type
12803                then
12804                   return;
12805                end if;
12806
12807                --  Error checks
12808
12809                if Underlying_Type (Etype (Read)) /= Typ then
12810                   Error_Pragma_Arg
12811                     ("incorrect return type for function&", Arg2);
12812                end if;
12813
12814                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12815                   Error_Pragma_Arg
12816                     ("incorrect parameter type for function&", Arg3);
12817                end if;
12818
12819                if Underlying_Type (Etype (First_Formal (Read))) /=
12820                   Underlying_Type (Etype (Write))
12821                then
12822                   Error_Pragma_Arg
12823                     ("result type of & does not match Read parameter type",
12824                      Arg3);
12825                end if;
12826             end;
12827          end Stream_Convert;
12828
12829          -------------------------
12830          -- Style_Checks (GNAT) --
12831          -------------------------
12832
12833          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12834
12835          --  This is processed by the parser since some of the style checks
12836          --  take place during source scanning and parsing. This means that
12837          --  we don't need to issue error messages here.
12838
12839          when Pragma_Style_Checks => Style_Checks : declare
12840             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
12841             S  : String_Id;
12842             C  : Char_Code;
12843
12844          begin
12845             GNAT_Pragma;
12846             Check_No_Identifiers;
12847
12848             --  Two argument form
12849
12850             if Arg_Count = 2 then
12851                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12852
12853                declare
12854                   E_Id : Node_Id;
12855                   E    : Entity_Id;
12856
12857                begin
12858                   E_Id := Get_Pragma_Arg (Arg2);
12859                   Analyze (E_Id);
12860
12861                   if not Is_Entity_Name (E_Id) then
12862                      Error_Pragma_Arg
12863                        ("second argument of pragma% must be entity name",
12864                         Arg2);
12865                   end if;
12866
12867                   E := Entity (E_Id);
12868
12869                   if E = Any_Id then
12870                      return;
12871                   else
12872                      loop
12873                         Set_Suppress_Style_Checks (E,
12874                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12875                         exit when No (Homonym (E));
12876                         E := Homonym (E);
12877                      end loop;
12878                   end if;
12879                end;
12880
12881             --  One argument form
12882
12883             else
12884                Check_Arg_Count (1);
12885
12886                if Nkind (A) = N_String_Literal then
12887                   S   := Strval (A);
12888
12889                   declare
12890                      Slen    : constant Natural := Natural (String_Length (S));
12891                      Options : String (1 .. Slen);
12892                      J       : Natural;
12893
12894                   begin
12895                      J := 1;
12896                      loop
12897                         C := Get_String_Char (S, Int (J));
12898                         exit when not In_Character_Range (C);
12899                         Options (J) := Get_Character (C);
12900
12901                         --  If at end of string, set options. As per discussion
12902                         --  above, no need to check for errors, since we issued
12903                         --  them in the parser.
12904
12905                         if J = Slen then
12906                            Set_Style_Check_Options (Options);
12907                            exit;
12908                         end if;
12909
12910                         J := J + 1;
12911                      end loop;
12912                   end;
12913
12914                elsif Nkind (A) = N_Identifier then
12915                   if Chars (A) = Name_All_Checks then
12916                      if GNAT_Mode then
12917                         Set_GNAT_Style_Check_Options;
12918                      else
12919                         Set_Default_Style_Check_Options;
12920                      end if;
12921
12922                   elsif Chars (A) = Name_On then
12923                      Style_Check := True;
12924
12925                   elsif Chars (A) = Name_Off then
12926                      Style_Check := False;
12927                   end if;
12928                end if;
12929             end if;
12930          end Style_Checks;
12931
12932          --------------
12933          -- Subtitle --
12934          --------------
12935
12936          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12937
12938          when Pragma_Subtitle =>
12939             GNAT_Pragma;
12940             Check_Arg_Count (1);
12941             Check_Optional_Identifier (Arg1, Name_Subtitle);
12942             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12943             Store_Note (N);
12944
12945          --------------
12946          -- Suppress --
12947          --------------
12948
12949          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12950
12951          when Pragma_Suppress =>
12952             Process_Suppress_Unsuppress (True);
12953
12954          ------------------
12955          -- Suppress_All --
12956          ------------------
12957
12958          --  pragma Suppress_All;
12959
12960          --  The only check made here is that the pragma has no arguments.
12961          --  There are no placement rules, and the processing required (setting
12962          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
12963          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
12964          --  then creates and inserts a pragma Suppress (All_Checks).
12965
12966          when Pragma_Suppress_All =>
12967             GNAT_Pragma;
12968             Check_Arg_Count (0);
12969
12970          -------------------------
12971          -- Suppress_Debug_Info --
12972          -------------------------
12973
12974          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12975
12976          when Pragma_Suppress_Debug_Info =>
12977             GNAT_Pragma;
12978             Check_Arg_Count (1);
12979             Check_Optional_Identifier (Arg1, Name_Entity);
12980             Check_Arg_Is_Local_Name (Arg1);
12981             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
12982
12983          ----------------------------------
12984          -- Suppress_Exception_Locations --
12985          ----------------------------------
12986
12987          --  pragma Suppress_Exception_Locations;
12988
12989          when Pragma_Suppress_Exception_Locations =>
12990             GNAT_Pragma;
12991             Check_Arg_Count (0);
12992             Check_Valid_Configuration_Pragma;
12993             Exception_Locations_Suppressed := True;
12994
12995          -----------------------------
12996          -- Suppress_Initialization --
12997          -----------------------------
12998
12999          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13000
13001          when Pragma_Suppress_Initialization => Suppress_Init : declare
13002             E_Id : Node_Id;
13003             E    : Entity_Id;
13004
13005          begin
13006             GNAT_Pragma;
13007             Check_Arg_Count (1);
13008             Check_Optional_Identifier (Arg1, Name_Entity);
13009             Check_Arg_Is_Local_Name (Arg1);
13010
13011             E_Id := Get_Pragma_Arg (Arg1);
13012
13013             if Etype (E_Id) = Any_Type then
13014                return;
13015             end if;
13016
13017             E := Entity (E_Id);
13018
13019             if not Is_Type (E) then
13020                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13021             end if;
13022
13023             if Rep_Item_Too_Early (E, N)
13024                  or else
13025                Rep_Item_Too_Late (E, N, FOnly => True)
13026             then
13027                return;
13028             end if;
13029
13030             --  For incomplete/private type, set flag on full view
13031
13032             if Is_Incomplete_Or_Private_Type (E) then
13033                if No (Full_View (Base_Type (E))) then
13034                   Error_Pragma_Arg
13035                     ("argument of pragma% cannot be an incomplete type", Arg1);
13036                else
13037                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13038                end if;
13039
13040             --  For first subtype, set flag on base type
13041
13042             elsif Is_First_Subtype (E) then
13043                Set_Suppress_Initialization (Base_Type (E));
13044
13045             --  For other than first subtype, set flag on subtype itself
13046
13047             else
13048                Set_Suppress_Initialization (E);
13049             end if;
13050          end Suppress_Init;
13051
13052          -----------------
13053          -- System_Name --
13054          -----------------
13055
13056          --  pragma System_Name (DIRECT_NAME);
13057
13058          --  Syntax check: one argument, which must be the identifier GNAT or
13059          --  the identifier GCC, no other identifiers are acceptable.
13060
13061          when Pragma_System_Name =>
13062             GNAT_Pragma;
13063             Check_No_Identifiers;
13064             Check_Arg_Count (1);
13065             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13066
13067          -----------------------------
13068          -- Task_Dispatching_Policy --
13069          -----------------------------
13070
13071          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13072
13073          when Pragma_Task_Dispatching_Policy => declare
13074             DP : Character;
13075
13076          begin
13077             Check_Ada_83_Warning;
13078             Check_Arg_Count (1);
13079             Check_No_Identifiers;
13080             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13081             Check_Valid_Configuration_Pragma;
13082             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13083             DP := Fold_Upper (Name_Buffer (1));
13084
13085             if Task_Dispatching_Policy /= ' '
13086               and then Task_Dispatching_Policy /= DP
13087             then
13088                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13089                Error_Pragma
13090                  ("task dispatching policy incompatible with policy#");
13091
13092             --  Set new policy, but always preserve System_Location since we
13093             --  like the error message with the run time name.
13094
13095             else
13096                Task_Dispatching_Policy := DP;
13097
13098                if Task_Dispatching_Policy_Sloc /= System_Location then
13099                   Task_Dispatching_Policy_Sloc := Loc;
13100                end if;
13101             end if;
13102          end;
13103
13104          ---------------
13105          -- Task_Info --
13106          ---------------
13107
13108          --  pragma Task_Info (EXPRESSION);
13109
13110          when Pragma_Task_Info => Task_Info : declare
13111             P : constant Node_Id := Parent (N);
13112
13113          begin
13114             GNAT_Pragma;
13115
13116             if Nkind (P) /= N_Task_Definition then
13117                Error_Pragma ("pragma% must appear in task definition");
13118             end if;
13119
13120             Check_No_Identifiers;
13121             Check_Arg_Count (1);
13122
13123             Analyze_And_Resolve
13124               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13125
13126             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13127                return;
13128             end if;
13129
13130             if Has_Task_Info_Pragma (P) then
13131                Error_Pragma ("duplicate pragma% not allowed");
13132             else
13133                Set_Has_Task_Info_Pragma (P, True);
13134             end if;
13135          end Task_Info;
13136
13137          ---------------
13138          -- Task_Name --
13139          ---------------
13140
13141          --  pragma Task_Name (string_EXPRESSION);
13142
13143          when Pragma_Task_Name => Task_Name : declare
13144             P   : constant Node_Id := Parent (N);
13145             Arg : Node_Id;
13146
13147          begin
13148             Check_No_Identifiers;
13149             Check_Arg_Count (1);
13150
13151             Arg := Get_Pragma_Arg (Arg1);
13152
13153             --  The expression is used in the call to Create_Task, and must be
13154             --  expanded there, not in the context of the current spec. It must
13155             --  however be analyzed to capture global references, in case it
13156             --  appears in a generic context.
13157
13158             Preanalyze_And_Resolve (Arg, Standard_String);
13159
13160             if Nkind (P) /= N_Task_Definition then
13161                Pragma_Misplaced;
13162             end if;
13163
13164             if Has_Task_Name_Pragma (P) then
13165                Error_Pragma ("duplicate pragma% not allowed");
13166             else
13167                Set_Has_Task_Name_Pragma (P, True);
13168                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13169             end if;
13170          end Task_Name;
13171
13172          ------------------
13173          -- Task_Storage --
13174          ------------------
13175
13176          --  pragma Task_Storage (
13177          --     [Task_Type =>] LOCAL_NAME,
13178          --     [Top_Guard =>] static_integer_EXPRESSION);
13179
13180          when Pragma_Task_Storage => Task_Storage : declare
13181             Args  : Args_List (1 .. 2);
13182             Names : constant Name_List (1 .. 2) := (
13183                       Name_Task_Type,
13184                       Name_Top_Guard);
13185
13186             Task_Type : Node_Id renames Args (1);
13187             Top_Guard : Node_Id renames Args (2);
13188
13189             Ent : Entity_Id;
13190
13191          begin
13192             GNAT_Pragma;
13193             Gather_Associations (Names, Args);
13194
13195             if No (Task_Type) then
13196                Error_Pragma
13197                  ("missing task_type argument for pragma%");
13198             end if;
13199
13200             Check_Arg_Is_Local_Name (Task_Type);
13201
13202             Ent := Entity (Task_Type);
13203
13204             if not Is_Task_Type (Ent) then
13205                Error_Pragma_Arg
13206                  ("argument for pragma% must be task type", Task_Type);
13207             end if;
13208
13209             if No (Top_Guard) then
13210                Error_Pragma_Arg
13211                  ("pragma% takes two arguments", Task_Type);
13212             else
13213                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13214             end if;
13215
13216             Check_First_Subtype (Task_Type);
13217
13218             if Rep_Item_Too_Late (Ent, N) then
13219                raise Pragma_Exit;
13220             end if;
13221          end Task_Storage;
13222
13223          ---------------
13224          -- Test_Case --
13225          ---------------
13226
13227          --  pragma Test_Case ([Name     =>] String_Expression
13228          --                   ,[Mode     =>] (Normal | Robustness)
13229          --                  [, Requires =>  Boolean_Expression]
13230          --                  [, Ensures  =>  Boolean_Expression]);
13231
13232          when Pragma_Test_Case => Test_Case : declare
13233
13234          begin
13235             GNAT_Pragma;
13236             Check_At_Least_N_Arguments (3);
13237             Check_At_Most_N_Arguments (4);
13238             Check_Arg_Order
13239               ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13240
13241             Check_Optional_Identifier (Arg1, Name_Name);
13242             Check_Arg_Is_String_Literal (Arg1);
13243             Check_Optional_Identifier (Arg2, Name_Mode);
13244             Check_Arg_Is_One_Of (Arg2, Name_Normal, Name_Robustness);
13245             if Arg_Count = 4 then
13246                Check_Identifier (Arg3, Name_Requires);
13247                Check_Identifier (Arg4, Name_Ensures);
13248             else
13249                Check_Arg_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13250             end if;
13251
13252             Check_Test_Case;
13253          end Test_Case;
13254
13255          --------------------------
13256          -- Thread_Local_Storage --
13257          --------------------------
13258
13259          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13260
13261          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13262             Id : Node_Id;
13263             E  : Entity_Id;
13264
13265          begin
13266             GNAT_Pragma;
13267             Check_Arg_Count (1);
13268             Check_Optional_Identifier (Arg1, Name_Entity);
13269             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13270
13271             Id := Get_Pragma_Arg (Arg1);
13272             Analyze (Id);
13273
13274             if not Is_Entity_Name (Id)
13275               or else Ekind (Entity (Id)) /= E_Variable
13276             then
13277                Error_Pragma_Arg ("local variable name required", Arg1);
13278             end if;
13279
13280             E := Entity (Id);
13281
13282             if Rep_Item_Too_Early (E, N)
13283               or else Rep_Item_Too_Late (E, N)
13284             then
13285                raise Pragma_Exit;
13286             end if;
13287
13288             Set_Has_Pragma_Thread_Local_Storage (E);
13289             Set_Has_Gigi_Rep_Item (E);
13290          end Thread_Local_Storage;
13291
13292          ----------------
13293          -- Time_Slice --
13294          ----------------
13295
13296          --  pragma Time_Slice (static_duration_EXPRESSION);
13297
13298          when Pragma_Time_Slice => Time_Slice : declare
13299             Val : Ureal;
13300             Nod : Node_Id;
13301
13302          begin
13303             GNAT_Pragma;
13304             Check_Arg_Count (1);
13305             Check_No_Identifiers;
13306             Check_In_Main_Program;
13307             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13308
13309             if not Error_Posted (Arg1) then
13310                Nod := Next (N);
13311                while Present (Nod) loop
13312                   if Nkind (Nod) = N_Pragma
13313                     and then Pragma_Name (Nod) = Name_Time_Slice
13314                   then
13315                      Error_Msg_Name_1 := Pname;
13316                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13317                   end if;
13318
13319                   Next (Nod);
13320                end loop;
13321             end if;
13322
13323             --  Process only if in main unit
13324
13325             if Get_Source_Unit (Loc) = Main_Unit then
13326                Opt.Time_Slice_Set := True;
13327                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13328
13329                if Val <= Ureal_0 then
13330                   Opt.Time_Slice_Value := 0;
13331
13332                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13333                   Opt.Time_Slice_Value := 1_000_000_000;
13334
13335                else
13336                   Opt.Time_Slice_Value :=
13337                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13338                end if;
13339             end if;
13340          end Time_Slice;
13341
13342          -----------
13343          -- Title --
13344          -----------
13345
13346          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13347
13348          --   TITLING_OPTION ::=
13349          --     [Title =>] STRING_LITERAL
13350          --   | [Subtitle =>] STRING_LITERAL
13351
13352          when Pragma_Title => Title : declare
13353             Args  : Args_List (1 .. 2);
13354             Names : constant Name_List (1 .. 2) := (
13355                       Name_Title,
13356                       Name_Subtitle);
13357
13358          begin
13359             GNAT_Pragma;
13360             Gather_Associations (Names, Args);
13361             Store_Note (N);
13362
13363             for J in 1 .. 2 loop
13364                if Present (Args (J)) then
13365                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13366                end if;
13367             end loop;
13368          end Title;
13369
13370          ---------------------
13371          -- Unchecked_Union --
13372          ---------------------
13373
13374          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13375
13376          when Pragma_Unchecked_Union => Unchecked_Union : declare
13377             Assoc   : constant Node_Id := Arg1;
13378             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13379             Typ     : Entity_Id;
13380             Discr   : Entity_Id;
13381             Tdef    : Node_Id;
13382             Clist   : Node_Id;
13383             Vpart   : Node_Id;
13384             Comp    : Node_Id;
13385             Variant : Node_Id;
13386
13387          begin
13388             Ada_2005_Pragma;
13389             Check_No_Identifiers;
13390             Check_Arg_Count (1);
13391             Check_Arg_Is_Local_Name (Arg1);
13392
13393             Find_Type (Type_Id);
13394             Typ := Entity (Type_Id);
13395
13396             if Typ = Any_Type
13397               or else Rep_Item_Too_Early (Typ, N)
13398             then
13399                return;
13400             else
13401                Typ := Underlying_Type (Typ);
13402             end if;
13403
13404             if Rep_Item_Too_Late (Typ, N) then
13405                return;
13406             end if;
13407
13408             Check_First_Subtype (Arg1);
13409
13410             --  Note remaining cases are references to a type in the current
13411             --  declarative part. If we find an error, we post the error on
13412             --  the relevant type declaration at an appropriate point.
13413
13414             if not Is_Record_Type (Typ) then
13415                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13416                return;
13417
13418             elsif Is_Tagged_Type (Typ) then
13419                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13420                return;
13421
13422             elsif Is_Limited_Type (Typ) then
13423                Error_Msg_N
13424                  ("Unchecked_Union must not be limited record type", Typ);
13425                Explain_Limited_Type (Typ, Typ);
13426                return;
13427
13428             else
13429                if not Has_Discriminants (Typ) then
13430                   Error_Msg_N
13431                     ("Unchecked_Union must have one discriminant", Typ);
13432                   return;
13433                end if;
13434
13435                Discr := First_Discriminant (Typ);
13436                while Present (Discr) loop
13437                   if No (Discriminant_Default_Value (Discr)) then
13438                      Error_Msg_N
13439                        ("Unchecked_Union discriminant must have default value",
13440                         Discr);
13441                   end if;
13442
13443                   Next_Discriminant (Discr);
13444                end loop;
13445
13446                Tdef  := Type_Definition (Declaration_Node (Typ));
13447                Clist := Component_List (Tdef);
13448
13449                Comp := First (Component_Items (Clist));
13450                while Present (Comp) loop
13451                   Check_Component (Comp, Typ);
13452                   Next (Comp);
13453                end loop;
13454
13455                if No (Clist) or else No (Variant_Part (Clist)) then
13456                   Error_Msg_N
13457                     ("Unchecked_Union must have variant part",
13458                      Tdef);
13459                   return;
13460                end if;
13461
13462                Vpart := Variant_Part (Clist);
13463
13464                Variant := First (Variants (Vpart));
13465                while Present (Variant) loop
13466                   Check_Variant (Variant, Typ);
13467                   Next (Variant);
13468                end loop;
13469             end if;
13470
13471             Set_Is_Unchecked_Union  (Typ);
13472             Set_Convention (Typ, Convention_C);
13473             Set_Has_Unchecked_Union (Base_Type (Typ));
13474             Set_Is_Unchecked_Union  (Base_Type (Typ));
13475          end Unchecked_Union;
13476
13477          ------------------------
13478          -- Unimplemented_Unit --
13479          ------------------------
13480
13481          --  pragma Unimplemented_Unit;
13482
13483          --  Note: this only gives an error if we are generating code, or if
13484          --  we are in a generic library unit (where the pragma appears in the
13485          --  body, not in the spec).
13486
13487          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13488             Cunitent : constant Entity_Id :=
13489                          Cunit_Entity (Get_Source_Unit (Loc));
13490             Ent_Kind : constant Entity_Kind :=
13491                          Ekind (Cunitent);
13492
13493          begin
13494             GNAT_Pragma;
13495             Check_Arg_Count (0);
13496
13497             if Operating_Mode = Generate_Code
13498               or else Ent_Kind = E_Generic_Function
13499               or else Ent_Kind = E_Generic_Procedure
13500               or else Ent_Kind = E_Generic_Package
13501             then
13502                Get_Name_String (Chars (Cunitent));
13503                Set_Casing (Mixed_Case);
13504                Write_Str (Name_Buffer (1 .. Name_Len));
13505                Write_Str (" is not supported in this configuration");
13506                Write_Eol;
13507                raise Unrecoverable_Error;
13508             end if;
13509          end Unimplemented_Unit;
13510
13511          ------------------------
13512          -- Universal_Aliasing --
13513          ------------------------
13514
13515          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13516
13517          when Pragma_Universal_Aliasing => Universal_Alias : declare
13518             E_Id : Entity_Id;
13519
13520          begin
13521             GNAT_Pragma;
13522             Check_Arg_Count (1);
13523             Check_Optional_Identifier (Arg2, Name_Entity);
13524             Check_Arg_Is_Local_Name (Arg1);
13525             E_Id := Entity (Get_Pragma_Arg (Arg1));
13526
13527             if E_Id = Any_Type then
13528                return;
13529             elsif No (E_Id) or else not Is_Type (E_Id) then
13530                Error_Pragma_Arg ("pragma% requires type", Arg1);
13531             end if;
13532
13533             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13534          end Universal_Alias;
13535
13536          --------------------
13537          -- Universal_Data --
13538          --------------------
13539
13540          --  pragma Universal_Data [(library_unit_NAME)];
13541
13542          when Pragma_Universal_Data =>
13543             GNAT_Pragma;
13544
13545             --  If this is a configuration pragma, then set the universal
13546             --  addressing option, otherwise confirm that the pragma satisfies
13547             --  the requirements of library unit pragma placement and leave it
13548             --  to the GNAAMP back end to detect the pragma (avoids transitive
13549             --  setting of the option due to withed units).
13550
13551             if Is_Configuration_Pragma then
13552                Universal_Addressing_On_AAMP := True;
13553             else
13554                Check_Valid_Library_Unit_Pragma;
13555             end if;
13556
13557             if not AAMP_On_Target then
13558                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13559             end if;
13560
13561          ----------------
13562          -- Unmodified --
13563          ----------------
13564
13565          --  pragma Unmodified (local_Name {, local_Name});
13566
13567          when Pragma_Unmodified => Unmodified : declare
13568             Arg_Node : Node_Id;
13569             Arg_Expr : Node_Id;
13570             Arg_Ent  : Entity_Id;
13571
13572          begin
13573             GNAT_Pragma;
13574             Check_At_Least_N_Arguments (1);
13575
13576             --  Loop through arguments
13577
13578             Arg_Node := Arg1;
13579             while Present (Arg_Node) loop
13580                Check_No_Identifier (Arg_Node);
13581
13582                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13583                --  in fact generate reference, so that the entity will have a
13584                --  reference, which will inhibit any warnings about it not
13585                --  being referenced, and also properly show up in the ali file
13586                --  as a reference. But this reference is recorded before the
13587                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13588                --  generated for this reference.
13589
13590                Check_Arg_Is_Local_Name (Arg_Node);
13591                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13592
13593                if Is_Entity_Name (Arg_Expr) then
13594                   Arg_Ent := Entity (Arg_Expr);
13595
13596                   if not Is_Assignable (Arg_Ent) then
13597                      Error_Pragma_Arg
13598                        ("pragma% can only be applied to a variable",
13599                         Arg_Expr);
13600                   else
13601                      Set_Has_Pragma_Unmodified (Arg_Ent);
13602                   end if;
13603                end if;
13604
13605                Next (Arg_Node);
13606             end loop;
13607          end Unmodified;
13608
13609          ------------------
13610          -- Unreferenced --
13611          ------------------
13612
13613          --  pragma Unreferenced (local_Name {, local_Name});
13614
13615          --    or when used in a context clause:
13616
13617          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13618
13619          when Pragma_Unreferenced => Unreferenced : declare
13620             Arg_Node : Node_Id;
13621             Arg_Expr : Node_Id;
13622             Arg_Ent  : Entity_Id;
13623             Citem    : Node_Id;
13624
13625          begin
13626             GNAT_Pragma;
13627             Check_At_Least_N_Arguments (1);
13628
13629             --  Check case of appearing within context clause
13630
13631             if Is_In_Context_Clause then
13632
13633                --  The arguments must all be units mentioned in a with clause
13634                --  in the same context clause. Note we already checked (in
13635                --  Par.Prag) that the arguments are either identifiers or
13636                --  selected components.
13637
13638                Arg_Node := Arg1;
13639                while Present (Arg_Node) loop
13640                   Citem := First (List_Containing (N));
13641                   while Citem /= N loop
13642                      if Nkind (Citem) = N_With_Clause
13643                        and then
13644                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13645                      then
13646                         Set_Has_Pragma_Unreferenced
13647                           (Cunit_Entity
13648                              (Get_Source_Unit
13649                                 (Library_Unit (Citem))));
13650                         Set_Unit_Name
13651                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
13652                         exit;
13653                      end if;
13654
13655                      Next (Citem);
13656                   end loop;
13657
13658                   if Citem = N then
13659                      Error_Pragma_Arg
13660                        ("argument of pragma% is not with'ed unit", Arg_Node);
13661                   end if;
13662
13663                   Next (Arg_Node);
13664                end loop;
13665
13666             --  Case of not in list of context items
13667
13668             else
13669                Arg_Node := Arg1;
13670                while Present (Arg_Node) loop
13671                   Check_No_Identifier (Arg_Node);
13672
13673                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
13674                   --  will in fact generate reference, so that the entity will
13675                   --  have a reference, which will inhibit any warnings about
13676                   --  it not being referenced, and also properly show up in the
13677                   --  ali file as a reference. But this reference is recorded
13678                   --  before the Has_Pragma_Unreferenced flag is set, so that
13679                   --  no warning is generated for this reference.
13680
13681                   Check_Arg_Is_Local_Name (Arg_Node);
13682                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
13683
13684                   if Is_Entity_Name (Arg_Expr) then
13685                      Arg_Ent := Entity (Arg_Expr);
13686
13687                      --  If the entity is overloaded, the pragma applies to the
13688                      --  most recent overloading, as documented. In this case,
13689                      --  name resolution does not generate a reference, so it
13690                      --  must be done here explicitly.
13691
13692                      if Is_Overloaded (Arg_Expr) then
13693                         Generate_Reference (Arg_Ent, N);
13694                      end if;
13695
13696                      Set_Has_Pragma_Unreferenced (Arg_Ent);
13697                   end if;
13698
13699                   Next (Arg_Node);
13700                end loop;
13701             end if;
13702          end Unreferenced;
13703
13704          --------------------------
13705          -- Unreferenced_Objects --
13706          --------------------------
13707
13708          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13709
13710          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13711             Arg_Node : Node_Id;
13712             Arg_Expr : Node_Id;
13713
13714          begin
13715             GNAT_Pragma;
13716             Check_At_Least_N_Arguments (1);
13717
13718             Arg_Node := Arg1;
13719             while Present (Arg_Node) loop
13720                Check_No_Identifier (Arg_Node);
13721                Check_Arg_Is_Local_Name (Arg_Node);
13722                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13723
13724                if not Is_Entity_Name (Arg_Expr)
13725                  or else not Is_Type (Entity (Arg_Expr))
13726                then
13727                   Error_Pragma_Arg
13728                     ("argument for pragma% must be type or subtype", Arg_Node);
13729                end if;
13730
13731                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13732                Next (Arg_Node);
13733             end loop;
13734          end Unreferenced_Objects;
13735
13736          ------------------------------
13737          -- Unreserve_All_Interrupts --
13738          ------------------------------
13739
13740          --  pragma Unreserve_All_Interrupts;
13741
13742          when Pragma_Unreserve_All_Interrupts =>
13743             GNAT_Pragma;
13744             Check_Arg_Count (0);
13745
13746             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13747                Unreserve_All_Interrupts := True;
13748             end if;
13749
13750          ----------------
13751          -- Unsuppress --
13752          ----------------
13753
13754          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13755
13756          when Pragma_Unsuppress =>
13757             Ada_2005_Pragma;
13758             Process_Suppress_Unsuppress (False);
13759
13760          -------------------
13761          -- Use_VADS_Size --
13762          -------------------
13763
13764          --  pragma Use_VADS_Size;
13765
13766          when Pragma_Use_VADS_Size =>
13767             GNAT_Pragma;
13768             Check_Arg_Count (0);
13769             Check_Valid_Configuration_Pragma;
13770             Use_VADS_Size := True;
13771
13772          ---------------------
13773          -- Validity_Checks --
13774          ---------------------
13775
13776          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13777
13778          when Pragma_Validity_Checks => Validity_Checks : declare
13779             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13780             S  : String_Id;
13781             C  : Char_Code;
13782
13783          begin
13784             GNAT_Pragma;
13785             Check_Arg_Count (1);
13786             Check_No_Identifiers;
13787
13788             if Nkind (A) = N_String_Literal then
13789                S   := Strval (A);
13790
13791                declare
13792                   Slen    : constant Natural := Natural (String_Length (S));
13793                   Options : String (1 .. Slen);
13794                   J       : Natural;
13795
13796                begin
13797                   J := 1;
13798                   loop
13799                      C := Get_String_Char (S, Int (J));
13800                      exit when not In_Character_Range (C);
13801                      Options (J) := Get_Character (C);
13802
13803                      if J = Slen then
13804                         Set_Validity_Check_Options (Options);
13805                         exit;
13806                      else
13807                         J := J + 1;
13808                      end if;
13809                   end loop;
13810                end;
13811
13812             elsif Nkind (A) = N_Identifier then
13813
13814                if Chars (A) = Name_All_Checks then
13815                   Set_Validity_Check_Options ("a");
13816
13817                elsif Chars (A) = Name_On then
13818                   Validity_Checks_On := True;
13819
13820                elsif Chars (A) = Name_Off then
13821                   Validity_Checks_On := False;
13822
13823                end if;
13824             end if;
13825          end Validity_Checks;
13826
13827          --------------
13828          -- Volatile --
13829          --------------
13830
13831          --  pragma Volatile (LOCAL_NAME);
13832
13833          when Pragma_Volatile =>
13834             Process_Atomic_Shared_Volatile;
13835
13836          -------------------------
13837          -- Volatile_Components --
13838          -------------------------
13839
13840          --  pragma Volatile_Components (array_LOCAL_NAME);
13841
13842          --  Volatile is handled by the same circuit as Atomic_Components
13843
13844          --------------
13845          -- Warnings --
13846          --------------
13847
13848          --  pragma Warnings (On | Off);
13849          --  pragma Warnings (On | Off, LOCAL_NAME);
13850          --  pragma Warnings (static_string_EXPRESSION);
13851          --  pragma Warnings (On | Off, STRING_LITERAL);
13852
13853          when Pragma_Warnings => Warnings : begin
13854             GNAT_Pragma;
13855             Check_At_Least_N_Arguments (1);
13856             Check_No_Identifiers;
13857
13858             --  If debug flag -gnatd.i is set, pragma is ignored
13859
13860             if Debug_Flag_Dot_I then
13861                return;
13862             end if;
13863
13864             --  Process various forms of the pragma
13865
13866             declare
13867                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13868
13869             begin
13870                --  One argument case
13871
13872                if Arg_Count = 1 then
13873
13874                   --  On/Off one argument case was processed by parser
13875
13876                   if Nkind (Argx) = N_Identifier
13877                     and then
13878                       (Chars (Argx) = Name_On
13879                          or else
13880                        Chars (Argx) = Name_Off)
13881                   then
13882                      null;
13883
13884                   --  One argument case must be ON/OFF or static string expr
13885
13886                   elsif not Is_Static_String_Expression (Arg1) then
13887                      Error_Pragma_Arg
13888                        ("argument of pragma% must be On/Off or " &
13889                         "static string expression", Arg1);
13890
13891                   --  One argument string expression case
13892
13893                   else
13894                      declare
13895                         Lit : constant Node_Id   := Expr_Value_S (Argx);
13896                         Str : constant String_Id := Strval (Lit);
13897                         Len : constant Nat       := String_Length (Str);
13898                         C   : Char_Code;
13899                         J   : Nat;
13900                         OK  : Boolean;
13901                         Chr : Character;
13902
13903                      begin
13904                         J := 1;
13905                         while J <= Len loop
13906                            C := Get_String_Char (Str, J);
13907                            OK := In_Character_Range (C);
13908
13909                            if OK then
13910                               Chr := Get_Character (C);
13911
13912                               --  Dot case
13913
13914                               if J < Len and then Chr = '.' then
13915                                  J := J + 1;
13916                                  C := Get_String_Char (Str, J);
13917                                  Chr := Get_Character (C);
13918
13919                                  if not Set_Dot_Warning_Switch (Chr) then
13920                                     Error_Pragma_Arg
13921                                       ("invalid warning switch character " &
13922                                        '.' & Chr, Arg1);
13923                                  end if;
13924
13925                               --  Non-Dot case
13926
13927                               else
13928                                  OK := Set_Warning_Switch (Chr);
13929                               end if;
13930                            end if;
13931
13932                            if not OK then
13933                               Error_Pragma_Arg
13934                                 ("invalid warning switch character " & Chr,
13935                                  Arg1);
13936                            end if;
13937
13938                            J := J + 1;
13939                         end loop;
13940                      end;
13941                   end if;
13942
13943                   --  Two or more arguments (must be two)
13944
13945                else
13946                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13947                   Check_At_Most_N_Arguments (2);
13948
13949                   declare
13950                      E_Id : Node_Id;
13951                      E    : Entity_Id;
13952                      Err  : Boolean;
13953
13954                   begin
13955                      E_Id := Get_Pragma_Arg (Arg2);
13956                      Analyze (E_Id);
13957
13958                      --  In the expansion of an inlined body, a reference to
13959                      --  the formal may be wrapped in a conversion if the
13960                      --  actual is a conversion. Retrieve the real entity name.
13961
13962                      if (In_Instance_Body
13963                          or else In_Inlined_Body)
13964                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13965                      then
13966                         E_Id := Expression (E_Id);
13967                      end if;
13968
13969                      --  Entity name case
13970
13971                      if Is_Entity_Name (E_Id) then
13972                         E := Entity (E_Id);
13973
13974                         if E = Any_Id then
13975                            return;
13976                         else
13977                            loop
13978                               Set_Warnings_Off
13979                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
13980                                                               Name_Off));
13981
13982                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
13983                                 and then Warn_On_Warnings_Off
13984                               then
13985                                  Warnings_Off_Pragmas.Append ((N, E));
13986                               end if;
13987
13988                               if Is_Enumeration_Type (E) then
13989                                  declare
13990                                     Lit : Entity_Id;
13991                                  begin
13992                                     Lit := First_Literal (E);
13993                                     while Present (Lit) loop
13994                                        Set_Warnings_Off (Lit);
13995                                        Next_Literal (Lit);
13996                                     end loop;
13997                                  end;
13998                               end if;
13999
14000                               exit when No (Homonym (E));
14001                               E := Homonym (E);
14002                            end loop;
14003                         end if;
14004
14005                      --  Error if not entity or static string literal case
14006
14007                      elsif not Is_Static_String_Expression (Arg2) then
14008                         Error_Pragma_Arg
14009                           ("second argument of pragma% must be entity " &
14010                            "name or static string expression", Arg2);
14011
14012                      --  String literal case
14013
14014                      else
14015                         String_To_Name_Buffer
14016                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14017
14018                         --  Note on configuration pragma case: If this is a
14019                         --  configuration pragma, then for an OFF pragma, we
14020                         --  just set Config True in the call, which is all
14021                         --  that needs to be done. For the case of ON, this
14022                         --  is normally an error, unless it is canceling the
14023                         --  effect of a previous OFF pragma in the same file.
14024                         --  In any other case, an error will be signalled (ON
14025                         --  with no matching OFF).
14026
14027                         if Chars (Argx) = Name_Off then
14028                            Set_Specific_Warning_Off
14029                              (Loc, Name_Buffer (1 .. Name_Len),
14030                               Config => Is_Configuration_Pragma);
14031
14032                         elsif Chars (Argx) = Name_On then
14033                            Set_Specific_Warning_On
14034                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14035
14036                            if Err then
14037                               Error_Msg
14038                                 ("?pragma Warnings On with no " &
14039                                  "matching Warnings Off",
14040                                  Loc);
14041                            end if;
14042                         end if;
14043                      end if;
14044                   end;
14045                end if;
14046             end;
14047          end Warnings;
14048
14049          -------------------
14050          -- Weak_External --
14051          -------------------
14052
14053          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14054
14055          when Pragma_Weak_External => Weak_External : declare
14056             Ent : Entity_Id;
14057
14058          begin
14059             GNAT_Pragma;
14060             Check_Arg_Count (1);
14061             Check_Optional_Identifier (Arg1, Name_Entity);
14062             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14063             Ent := Entity (Get_Pragma_Arg (Arg1));
14064
14065             if Rep_Item_Too_Early (Ent, N) then
14066                return;
14067             else
14068                Ent := Underlying_Type (Ent);
14069             end if;
14070
14071             --  The only processing required is to link this item on to the
14072             --  list of rep items for the given entity. This is accomplished
14073             --  by the call to Rep_Item_Too_Late (when no error is detected
14074             --  and False is returned).
14075
14076             if Rep_Item_Too_Late (Ent, N) then
14077                return;
14078             else
14079                Set_Has_Gigi_Rep_Item (Ent);
14080             end if;
14081          end Weak_External;
14082
14083          -----------------------------
14084          -- Wide_Character_Encoding --
14085          -----------------------------
14086
14087          --  pragma Wide_Character_Encoding (IDENTIFIER);
14088
14089          when Pragma_Wide_Character_Encoding =>
14090             GNAT_Pragma;
14091
14092             --  Nothing to do, handled in parser. Note that we do not enforce
14093             --  configuration pragma placement, this pragma can appear at any
14094             --  place in the source, allowing mixed encodings within a single
14095             --  source program.
14096
14097             null;
14098
14099          --------------------
14100          -- Unknown_Pragma --
14101          --------------------
14102
14103          --  Should be impossible, since the case of an unknown pragma is
14104          --  separately processed before the case statement is entered.
14105
14106          when Unknown_Pragma =>
14107             raise Program_Error;
14108       end case;
14109
14110       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14111       --  until AI is formally approved.
14112
14113       --  Check_Order_Dependence;
14114
14115    exception
14116       when Pragma_Exit => null;
14117    end Analyze_Pragma;
14118
14119    -----------------------------
14120    -- Analyze_TC_In_Decl_Part --
14121    -----------------------------
14122
14123    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14124    begin
14125       --  Install formals and push subprogram spec onto scope stack so that we
14126       --  can see the formals from the pragma.
14127
14128       Install_Formals (S);
14129       Push_Scope (S);
14130
14131       --  Preanalyze the boolean expressions, we treat these as spec
14132       --  expressions (i.e. similar to a default expression).
14133
14134       Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14135                           Get_Ensures_From_Test_Case_Pragma (N));
14136
14137       --  Remove the subprogram from the scope stack now that the pre-analysis
14138       --  of the expressions in the test-case is done.
14139
14140       End_Scope;
14141    end Analyze_TC_In_Decl_Part;
14142
14143    -------------------
14144    -- Check_Enabled --
14145    -------------------
14146
14147    function Check_Enabled (Nam : Name_Id) return Boolean is
14148       PP : Node_Id;
14149
14150    begin
14151       --  Loop through entries in check policy list
14152
14153       PP := Opt.Check_Policy_List;
14154       loop
14155          --  If there are no specific entries that matched, then we let the
14156          --  setting of assertions govern. Note that this provides the needed
14157          --  compatibility with the RM for the cases of assertion, invariant,
14158          --  precondition, predicate, and postcondition.
14159
14160          if No (PP) then
14161             return Assertions_Enabled;
14162
14163          --  Here we have an entry see if it matches
14164
14165          else
14166             declare
14167                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14168
14169             begin
14170                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14171                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14172                      when Name_On | Name_Check =>
14173                         return True;
14174                      when Name_Off | Name_Ignore =>
14175                         return False;
14176                      when others =>
14177                         raise Program_Error;
14178                   end case;
14179
14180                else
14181                   PP := Next_Pragma (PP);
14182                end if;
14183             end;
14184          end if;
14185       end loop;
14186    end Check_Enabled;
14187
14188    ---------------------------------
14189    -- Delay_Config_Pragma_Analyze --
14190    ---------------------------------
14191
14192    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14193    begin
14194       return Pragma_Name (N) = Name_Interrupt_State
14195                or else
14196              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14197    end Delay_Config_Pragma_Analyze;
14198
14199    -------------------------
14200    -- Get_Base_Subprogram --
14201    -------------------------
14202
14203    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14204       Result : Entity_Id;
14205
14206    begin
14207       --  Follow subprogram renaming chain
14208
14209       Result := Def_Id;
14210       while Is_Subprogram (Result)
14211         and then
14212           Nkind (Parent (Declaration_Node (Result))) =
14213                                          N_Subprogram_Renaming_Declaration
14214         and then Present (Alias (Result))
14215       loop
14216          Result := Alias (Result);
14217       end loop;
14218
14219       return Result;
14220    end Get_Base_Subprogram;
14221
14222    ----------------
14223    -- Initialize --
14224    ----------------
14225
14226    procedure Initialize is
14227    begin
14228       Externals.Init;
14229    end Initialize;
14230
14231    -----------------------------
14232    -- Is_Config_Static_String --
14233    -----------------------------
14234
14235    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14236
14237       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14238       --  This is an internal recursive function that is just like the outer
14239       --  function except that it adds the string to the name buffer rather
14240       --  than placing the string in the name buffer.
14241
14242       ------------------------------
14243       -- Add_Config_Static_String --
14244       ------------------------------
14245
14246       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14247          N : Node_Id;
14248          C : Char_Code;
14249
14250       begin
14251          N := Arg;
14252
14253          if Nkind (N) = N_Op_Concat then
14254             if Add_Config_Static_String (Left_Opnd (N)) then
14255                N := Right_Opnd (N);
14256             else
14257                return False;
14258             end if;
14259          end if;
14260
14261          if Nkind (N) /= N_String_Literal then
14262             Error_Msg_N ("string literal expected for pragma argument", N);
14263             return False;
14264
14265          else
14266             for J in 1 .. String_Length (Strval (N)) loop
14267                C := Get_String_Char (Strval (N), J);
14268
14269                if not In_Character_Range (C) then
14270                   Error_Msg
14271                     ("string literal contains invalid wide character",
14272                      Sloc (N) + 1 + Source_Ptr (J));
14273                   return False;
14274                end if;
14275
14276                Add_Char_To_Name_Buffer (Get_Character (C));
14277             end loop;
14278          end if;
14279
14280          return True;
14281       end Add_Config_Static_String;
14282
14283    --  Start of processing for Is_Config_Static_String
14284
14285    begin
14286
14287       Name_Len := 0;
14288       return Add_Config_Static_String (Arg);
14289    end Is_Config_Static_String;
14290
14291    -----------------------------------------
14292    -- Is_Non_Significant_Pragma_Reference --
14293    -----------------------------------------
14294
14295    --  This function makes use of the following static table which indicates
14296    --  whether a given pragma is significant.
14297
14298    --  -1  indicates that references in any argument position are significant
14299    --  0   indicates that appearance in any argument is not significant
14300    --  +n  indicates that appearance as argument n is significant, but all
14301    --      other arguments are not significant
14302    --  99  special processing required (e.g. for pragma Check)
14303
14304    Sig_Flags : constant array (Pragma_Id) of Int :=
14305      (Pragma_AST_Entry                     => -1,
14306       Pragma_Abort_Defer                   => -1,
14307       Pragma_Ada_83                        => -1,
14308       Pragma_Ada_95                        => -1,
14309       Pragma_Ada_05                        => -1,
14310       Pragma_Ada_2005                      => -1,
14311       Pragma_Ada_12                        => -1,
14312       Pragma_Ada_2012                      => -1,
14313       Pragma_All_Calls_Remote              => -1,
14314       Pragma_Annotate                      => -1,
14315       Pragma_Assert                        => -1,
14316       Pragma_Assertion_Policy              =>  0,
14317       Pragma_Assume_No_Invalid_Values      =>  0,
14318       Pragma_Asynchronous                  => -1,
14319       Pragma_Atomic                        =>  0,
14320       Pragma_Atomic_Components             =>  0,
14321       Pragma_Attach_Handler                => -1,
14322       Pragma_Check                         => 99,
14323       Pragma_Check_Name                    =>  0,
14324       Pragma_Check_Policy                  =>  0,
14325       Pragma_CIL_Constructor               => -1,
14326       Pragma_CPP_Class                     =>  0,
14327       Pragma_CPP_Constructor               =>  0,
14328       Pragma_CPP_Virtual                   =>  0,
14329       Pragma_CPP_Vtable                    =>  0,
14330       Pragma_CPU                           => -1,
14331       Pragma_C_Pass_By_Copy                =>  0,
14332       Pragma_Comment                       =>  0,
14333       Pragma_Common_Object                 => -1,
14334       Pragma_Compile_Time_Error            => -1,
14335       Pragma_Compile_Time_Warning          => -1,
14336       Pragma_Compiler_Unit                 =>  0,
14337       Pragma_Complete_Representation       =>  0,
14338       Pragma_Complex_Representation        =>  0,
14339       Pragma_Component_Alignment           => -1,
14340       Pragma_Controlled                    =>  0,
14341       Pragma_Convention                    =>  0,
14342       Pragma_Convention_Identifier         =>  0,
14343       Pragma_Debug                         => -1,
14344       Pragma_Debug_Policy                  =>  0,
14345       Pragma_Detect_Blocking               => -1,
14346       Pragma_Default_Storage_Pool          => -1,
14347       Pragma_Dimension                     => -1,
14348       Pragma_Discard_Names                 =>  0,
14349       Pragma_Elaborate                     => -1,
14350       Pragma_Elaborate_All                 => -1,
14351       Pragma_Elaborate_Body                => -1,
14352       Pragma_Elaboration_Checks            => -1,
14353       Pragma_Eliminate                     => -1,
14354       Pragma_Export                        => -1,
14355       Pragma_Export_Exception              => -1,
14356       Pragma_Export_Function               => -1,
14357       Pragma_Export_Object                 => -1,
14358       Pragma_Export_Procedure              => -1,
14359       Pragma_Export_Value                  => -1,
14360       Pragma_Export_Valued_Procedure       => -1,
14361       Pragma_Extend_System                 => -1,
14362       Pragma_Extensions_Allowed            => -1,
14363       Pragma_External                      => -1,
14364       Pragma_Favor_Top_Level               => -1,
14365       Pragma_External_Name_Casing          => -1,
14366       Pragma_Fast_Math                     => -1,
14367       Pragma_Finalize_Storage_Only         =>  0,
14368       Pragma_Float_Representation          =>  0,
14369       Pragma_Ident                         => -1,
14370       Pragma_Implemented                   => -1,
14371       Pragma_Implicit_Packing              =>  0,
14372       Pragma_Import                        => +2,
14373       Pragma_Import_Exception              =>  0,
14374       Pragma_Import_Function               =>  0,
14375       Pragma_Import_Object                 =>  0,
14376       Pragma_Import_Procedure              =>  0,
14377       Pragma_Import_Valued_Procedure       =>  0,
14378       Pragma_Independent                   =>  0,
14379       Pragma_Independent_Components        =>  0,
14380       Pragma_Initialize_Scalars            => -1,
14381       Pragma_Inline                        =>  0,
14382       Pragma_Inline_Always                 =>  0,
14383       Pragma_Inline_Generic                =>  0,
14384       Pragma_Inspection_Point              => -1,
14385       Pragma_Interface                     => +2,
14386       Pragma_Interface_Name                => +2,
14387       Pragma_Interrupt_Handler             => -1,
14388       Pragma_Interrupt_Priority            => -1,
14389       Pragma_Interrupt_State               => -1,
14390       Pragma_Invariant                     => -1,
14391       Pragma_Java_Constructor              => -1,
14392       Pragma_Java_Interface                => -1,
14393       Pragma_Keep_Names                    =>  0,
14394       Pragma_License                       => -1,
14395       Pragma_Link_With                     => -1,
14396       Pragma_Linker_Alias                  => -1,
14397       Pragma_Linker_Constructor            => -1,
14398       Pragma_Linker_Destructor             => -1,
14399       Pragma_Linker_Options                => -1,
14400       Pragma_Linker_Section                => -1,
14401       Pragma_List                          => -1,
14402       Pragma_Locking_Policy                => -1,
14403       Pragma_Long_Float                    => -1,
14404       Pragma_Machine_Attribute             => -1,
14405       Pragma_Main                          => -1,
14406       Pragma_Main_Storage                  => -1,
14407       Pragma_Memory_Size                   => -1,
14408       Pragma_No_Return                     =>  0,
14409       Pragma_No_Body                       =>  0,
14410       Pragma_No_Run_Time                   => -1,
14411       Pragma_No_Strict_Aliasing            => -1,
14412       Pragma_Normalize_Scalars             => -1,
14413       Pragma_Obsolescent                   =>  0,
14414       Pragma_Optimize                      => -1,
14415       Pragma_Optimize_Alignment            => -1,
14416       Pragma_Ordered                       =>  0,
14417       Pragma_Pack                          =>  0,
14418       Pragma_Page                          => -1,
14419       Pragma_Passive                       => -1,
14420       Pragma_Preelaborable_Initialization  => -1,
14421       Pragma_Polling                       => -1,
14422       Pragma_Persistent_BSS                =>  0,
14423       Pragma_Postcondition                 => -1,
14424       Pragma_Precondition                  => -1,
14425       Pragma_Predicate                     => -1,
14426       Pragma_Preelaborate                  => -1,
14427       Pragma_Preelaborate_05               => -1,
14428       Pragma_Priority                      => -1,
14429       Pragma_Priority_Specific_Dispatching => -1,
14430       Pragma_Profile                       =>  0,
14431       Pragma_Profile_Warnings              =>  0,
14432       Pragma_Propagate_Exceptions          => -1,
14433       Pragma_Psect_Object                  => -1,
14434       Pragma_Pure                          => -1,
14435       Pragma_Pure_05                       => -1,
14436       Pragma_Pure_Function                 => -1,
14437       Pragma_Queuing_Policy                => -1,
14438       Pragma_Ravenscar                     => -1,
14439       Pragma_Relative_Deadline             => -1,
14440       Pragma_Remote_Call_Interface         => -1,
14441       Pragma_Remote_Types                  => -1,
14442       Pragma_Restricted_Run_Time           => -1,
14443       Pragma_Restriction_Warnings          => -1,
14444       Pragma_Restrictions                  => -1,
14445       Pragma_Reviewable                    => -1,
14446       Pragma_Short_Circuit_And_Or          => -1,
14447       Pragma_Share_Generic                 => -1,
14448       Pragma_Shared                        => -1,
14449       Pragma_Shared_Passive                => -1,
14450       Pragma_Short_Descriptors             =>  0,
14451       Pragma_Source_File_Name              => -1,
14452       Pragma_Source_File_Name_Project      => -1,
14453       Pragma_Source_Reference              => -1,
14454       Pragma_Storage_Size                  => -1,
14455       Pragma_Storage_Unit                  => -1,
14456       Pragma_Static_Elaboration_Desired    => -1,
14457       Pragma_Stream_Convert                => -1,
14458       Pragma_Style_Checks                  => -1,
14459       Pragma_Subtitle                      => -1,
14460       Pragma_Suppress                      =>  0,
14461       Pragma_Suppress_Exception_Locations  =>  0,
14462       Pragma_Suppress_All                  => -1,
14463       Pragma_Suppress_Debug_Info           =>  0,
14464       Pragma_Suppress_Initialization       =>  0,
14465       Pragma_System_Name                   => -1,
14466       Pragma_Task_Dispatching_Policy       => -1,
14467       Pragma_Task_Info                     => -1,
14468       Pragma_Task_Name                     => -1,
14469       Pragma_Task_Storage                  =>  0,
14470       Pragma_Test_Case                     => -1,
14471       Pragma_Thread_Local_Storage          =>  0,
14472       Pragma_Time_Slice                    => -1,
14473       Pragma_Title                         => -1,
14474       Pragma_Unchecked_Union               =>  0,
14475       Pragma_Unimplemented_Unit            => -1,
14476       Pragma_Universal_Aliasing            => -1,
14477       Pragma_Universal_Data                => -1,
14478       Pragma_Unmodified                    => -1,
14479       Pragma_Unreferenced                  => -1,
14480       Pragma_Unreferenced_Objects          => -1,
14481       Pragma_Unreserve_All_Interrupts      => -1,
14482       Pragma_Unsuppress                    =>  0,
14483       Pragma_Use_VADS_Size                 => -1,
14484       Pragma_Validity_Checks               => -1,
14485       Pragma_Volatile                      =>  0,
14486       Pragma_Volatile_Components           =>  0,
14487       Pragma_Warnings                      => -1,
14488       Pragma_Weak_External                 => -1,
14489       Pragma_Wide_Character_Encoding       =>  0,
14490       Unknown_Pragma                       =>  0);
14491
14492    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14493       Id : Pragma_Id;
14494       P  : Node_Id;
14495       C  : Int;
14496       A  : Node_Id;
14497
14498    begin
14499       P := Parent (N);
14500
14501       if Nkind (P) /= N_Pragma_Argument_Association then
14502          return False;
14503
14504       else
14505          Id := Get_Pragma_Id (Parent (P));
14506          C := Sig_Flags (Id);
14507
14508          case C is
14509             when -1 =>
14510                return False;
14511
14512             when 0 =>
14513                return True;
14514
14515             when 99 =>
14516                case Id is
14517
14518                   --  For pragma Check, the first argument is not significant,
14519                   --  the second and the third (if present) arguments are
14520                   --  significant.
14521
14522                   when Pragma_Check =>
14523                      return
14524                        P = First (Pragma_Argument_Associations (Parent (P)));
14525
14526                   when others =>
14527                      raise Program_Error;
14528                end case;
14529
14530             when others =>
14531                A := First (Pragma_Argument_Associations (Parent (P)));
14532                for J in 1 .. C - 1 loop
14533                   if No (A) then
14534                      return False;
14535                   end if;
14536
14537                   Next (A);
14538                end loop;
14539
14540                return A = P; -- is this wrong way round ???
14541          end case;
14542       end if;
14543    end Is_Non_Significant_Pragma_Reference;
14544
14545    ------------------------------
14546    -- Is_Pragma_String_Literal --
14547    ------------------------------
14548
14549    --  This function returns true if the corresponding pragma argument is a
14550    --  static string expression. These are the only cases in which string
14551    --  literals can appear as pragma arguments. We also allow a string literal
14552    --  as the first argument to pragma Assert (although it will of course
14553    --  always generate a type error).
14554
14555    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14556       Pragn : constant Node_Id := Parent (Par);
14557       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14558       Pname : constant Name_Id := Pragma_Name (Pragn);
14559       Argn  : Natural;
14560       N     : Node_Id;
14561
14562    begin
14563       Argn := 1;
14564       N := First (Assoc);
14565       loop
14566          exit when N = Par;
14567          Argn := Argn + 1;
14568          Next (N);
14569       end loop;
14570
14571       if Pname = Name_Assert then
14572          return True;
14573
14574       elsif Pname = Name_Export then
14575          return Argn > 2;
14576
14577       elsif Pname = Name_Ident then
14578          return Argn = 1;
14579
14580       elsif Pname = Name_Import then
14581          return Argn > 2;
14582
14583       elsif Pname = Name_Interface_Name then
14584          return Argn > 1;
14585
14586       elsif Pname = Name_Linker_Alias then
14587          return Argn = 2;
14588
14589       elsif Pname = Name_Linker_Section then
14590          return Argn = 2;
14591
14592       elsif Pname = Name_Machine_Attribute then
14593          return Argn = 2;
14594
14595       elsif Pname = Name_Source_File_Name then
14596          return True;
14597
14598       elsif Pname = Name_Source_Reference then
14599          return Argn = 2;
14600
14601       elsif Pname = Name_Title then
14602          return True;
14603
14604       elsif Pname = Name_Subtitle then
14605          return True;
14606
14607       else
14608          return False;
14609       end if;
14610    end Is_Pragma_String_Literal;
14611
14612    ------------------------
14613    -- Preanalyze_TC_Args --
14614    ------------------------
14615
14616    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14617    begin
14618       --  Preanalyze the boolean expressions, we treat these as spec
14619       --  expressions (i.e. similar to a default expression).
14620
14621       if Present (Arg_Req) then
14622          Preanalyze_Spec_Expression
14623            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14624       end if;
14625
14626       if Present (Arg_Ens) then
14627          Preanalyze_Spec_Expression
14628            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14629       end if;
14630    end Preanalyze_TC_Args;
14631
14632    --------------------------------------
14633    -- Process_Compilation_Unit_Pragmas --
14634    --------------------------------------
14635
14636    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14637    begin
14638       --  A special check for pragma Suppress_All, a very strange DEC pragma,
14639       --  strange because it comes at the end of the unit. Rational has the
14640       --  same name for a pragma, but treats it as a program unit pragma, In
14641       --  GNAT we just decide to allow it anywhere at all. If it appeared then
14642       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
14643       --  node, and we insert a pragma Suppress (All_Checks) at the start of
14644       --  the context clause to ensure the correct processing.
14645
14646       if Has_Pragma_Suppress_All (N) then
14647          Prepend_To (Context_Items (N),
14648            Make_Pragma (Sloc (N),
14649              Chars                        => Name_Suppress,
14650              Pragma_Argument_Associations => New_List (
14651                Make_Pragma_Argument_Association (Sloc (N),
14652                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14653       end if;
14654
14655       --  Nothing else to do at the current time!
14656
14657    end Process_Compilation_Unit_Pragmas;
14658
14659    --------
14660    -- rv --
14661    --------
14662
14663    procedure rv is
14664    begin
14665       null;
14666    end rv;
14667
14668    --------------------------------
14669    -- Set_Encoded_Interface_Name --
14670    --------------------------------
14671
14672    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14673       Str : constant String_Id := Strval (S);
14674       Len : constant Int       := String_Length (Str);
14675       CC  : Char_Code;
14676       C   : Character;
14677       J   : Int;
14678
14679       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14680
14681       procedure Encode;
14682       --  Stores encoded value of character code CC. The encoding we use an
14683       --  underscore followed by four lower case hex digits.
14684
14685       ------------
14686       -- Encode --
14687       ------------
14688
14689       procedure Encode is
14690       begin
14691          Store_String_Char (Get_Char_Code ('_'));
14692          Store_String_Char
14693            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14694          Store_String_Char
14695            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14696          Store_String_Char
14697            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14698          Store_String_Char
14699            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14700       end Encode;
14701
14702    --  Start of processing for Set_Encoded_Interface_Name
14703
14704    begin
14705       --  If first character is asterisk, this is a link name, and we leave it
14706       --  completely unmodified. We also ignore null strings (the latter case
14707       --  happens only in error cases) and no encoding should occur for Java or
14708       --  AAMP interface names.
14709
14710       if Len = 0
14711         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14712         or else VM_Target /= No_VM
14713         or else AAMP_On_Target
14714       then
14715          Set_Interface_Name (E, S);
14716
14717       else
14718          J := 1;
14719          loop
14720             CC := Get_String_Char (Str, J);
14721
14722             exit when not In_Character_Range (CC);
14723
14724             C := Get_Character (CC);
14725
14726             exit when C /= '_' and then C /= '$'
14727               and then C not in '0' .. '9'
14728               and then C not in 'a' .. 'z'
14729               and then C not in 'A' .. 'Z';
14730
14731             if J = Len then
14732                Set_Interface_Name (E, S);
14733                return;
14734
14735             else
14736                J := J + 1;
14737             end if;
14738          end loop;
14739
14740          --  Here we need to encode. The encoding we use as follows:
14741          --     three underscores  + four hex digits (lower case)
14742
14743          Start_String;
14744
14745          for J in 1 .. String_Length (Str) loop
14746             CC := Get_String_Char (Str, J);
14747
14748             if not In_Character_Range (CC) then
14749                Encode;
14750             else
14751                C := Get_Character (CC);
14752
14753                if C = '_' or else C = '$'
14754                  or else C in '0' .. '9'
14755                  or else C in 'a' .. 'z'
14756                  or else C in 'A' .. 'Z'
14757                then
14758                   Store_String_Char (CC);
14759                else
14760                   Encode;
14761                end if;
14762             end if;
14763          end loop;
14764
14765          Set_Interface_Name (E,
14766            Make_String_Literal (Sloc (S),
14767              Strval => End_String));
14768       end if;
14769    end Set_Encoded_Interface_Name;
14770
14771    -------------------
14772    -- Set_Unit_Name --
14773    -------------------
14774
14775    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14776       Pref : Node_Id;
14777       Scop : Entity_Id;
14778
14779    begin
14780       if Nkind (N) = N_Identifier
14781         and then Nkind (With_Item) = N_Identifier
14782       then
14783          Set_Entity (N, Entity (With_Item));
14784
14785       elsif Nkind (N) = N_Selected_Component then
14786          Change_Selected_Component_To_Expanded_Name (N);
14787          Set_Entity (N, Entity (With_Item));
14788          Set_Entity (Selector_Name (N), Entity (N));
14789
14790          Pref := Prefix (N);
14791          Scop := Scope (Entity (N));
14792          while Nkind (Pref) = N_Selected_Component loop
14793             Change_Selected_Component_To_Expanded_Name (Pref);
14794             Set_Entity (Selector_Name (Pref), Scop);
14795             Set_Entity (Pref, Scop);
14796             Pref := Prefix (Pref);
14797             Scop := Scope (Scop);
14798          end loop;
14799
14800          Set_Entity (Pref, Scop);
14801       end if;
14802    end Set_Unit_Name;
14803
14804 end Sem_Prag;