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       Preanalyze_Spec_Expression
262         (Get_Pragma_Arg (Arg1), Standard_Boolean);
263
264       --  Remove the subprogram from the scope stack now that the pre-analysis
265       --  of the precondition/postcondition is done.
266
267       End_Scope;
268    end Analyze_PPC_In_Decl_Part;
269
270    --------------------
271    -- Analyze_Pragma --
272    --------------------
273
274    procedure Analyze_Pragma (N : Node_Id) is
275       Loc     : constant Source_Ptr := Sloc (N);
276       Pname   : constant Name_Id    := Pragma_Name (N);
277       Prag_Id : Pragma_Id;
278
279       Pragma_Exit : exception;
280       --  This exception is used to exit pragma processing completely. It is
281       --  used when an error is detected, and no further processing is
282       --  required. It is also used if an earlier error has left the tree in
283       --  a state where the pragma should not be processed.
284
285       Arg_Count : Nat;
286       --  Number of pragma argument associations
287
288       Arg1 : Node_Id;
289       Arg2 : Node_Id;
290       Arg3 : Node_Id;
291       Arg4 : Node_Id;
292       --  First four pragma arguments (pragma argument association nodes, or
293       --  Empty if the corresponding argument does not exist).
294
295       type Name_List is array (Natural range <>) of Name_Id;
296       type Args_List is array (Natural range <>) of Node_Id;
297       --  Types used for arguments to Check_Arg_Order and Gather_Associations
298
299       procedure Ada_2005_Pragma;
300       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
301       --  Ada 95 mode, these are implementation defined pragmas, so should be
302       --  caught by the No_Implementation_Pragmas restriction.
303
304       procedure Ada_2012_Pragma;
305       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
306       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
307       --  should be caught by the No_Implementation_Pragmas restriction.
308
309       procedure Check_Ada_83_Warning;
310       --  Issues a warning message for the current pragma if operating in Ada
311       --  83 mode (used for language pragmas that are not a standard part of
312       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
313       --  of 95 pragma.
314
315       procedure Check_Arg_Count (Required : Nat);
316       --  Check argument count for pragma is equal to given parameter. If not,
317       --  then issue an error message and raise Pragma_Exit.
318
319       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
320       --  Arg which can either be a pragma argument association, in which case
321       --  the check is applied to the expression of the association or an
322       --  expression directly.
323
324       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
325       --  Check that an argument has the right form for an EXTERNAL_NAME
326       --  parameter of an extended import/export pragma. The rule is that the
327       --  name must be an identifier or string literal (in Ada 83 mode) or a
328       --  static string expression (in Ada 95 mode).
329
330       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
331       --  Check the specified argument Arg to make sure that it is an
332       --  identifier. If not give error and raise Pragma_Exit.
333
334       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
335       --  Check the specified argument Arg to make sure that it is an integer
336       --  literal. If not give error and raise Pragma_Exit.
337
338       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
339       --  Check the specified argument Arg to make sure that it has the proper
340       --  syntactic form for a local name and meets the semantic requirements
341       --  for a local name. The local name is analyzed as part of the
342       --  processing for this call. In addition, the local name is required
343       --  to represent an entity at the library level.
344
345       procedure Check_Arg_Is_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.
350
351       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
352       --  Check the specified argument Arg to make sure that it is a valid
353       --  locking policy name. If not give error and raise Pragma_Exit.
354
355       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
356       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3 : Name_Id);
357       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2, N3, N4 : Name_Id);
358       --  Check the specified argument Arg to make sure that it is an
359       --  identifier whose name matches either N1 or N2 (or N3 if present).
360       --  If not then give error and raise Pragma_Exit.
361
362       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
363       --  Check the specified argument Arg to make sure that it is a valid
364       --  queuing policy name. If not give error and raise Pragma_Exit.
365
366       procedure Check_Arg_Is_Static_Expression
367         (Arg : Node_Id;
368          Typ : Entity_Id := Empty);
369       --  Check the specified argument Arg to make sure that it is a static
370       --  expression of the given type (i.e. it will be analyzed and resolved
371       --  using this type, which can be any valid argument to Resolve, e.g.
372       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
373       --  Typ is left Empty, then any static expression is allowed.
374
375       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
376       --  Check the specified argument Arg to make sure that it is a valid task
377       --  dispatching policy name. If not give error and raise Pragma_Exit.
378
379       procedure Check_Arg_Order (Names : Name_List);
380       --  Checks for an instance of two arguments with identifiers for the
381       --  current pragma which are not in the sequence indicated by Names,
382       --  and if so, generates a fatal message about bad order of arguments.
383
384       procedure Check_At_Least_N_Arguments (N : Nat);
385       --  Check there are at least N arguments present
386
387       procedure Check_At_Most_N_Arguments (N : Nat);
388       --  Check there are no more than N arguments present
389
390       procedure Check_Component
391         (Comp            : Node_Id;
392          UU_Typ          : Entity_Id;
393          In_Variant_Part : Boolean := False);
394       --  Examine an Unchecked_Union component for correct use of per-object
395       --  constrained subtypes, and for restrictions on finalizable components.
396       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
397       --  should be set when Comp comes from a record variant.
398
399       procedure Check_Duplicate_Pragma (E : Entity_Id);
400       --  Check if a pragma of the same name as the current pragma is already
401       --  chained as a rep pragma to the given entity. If so give a message
402       --  about the duplicate, and then raise Pragma_Exit so does not return.
403       --  Also checks for delayed aspect specification node in the chain.
404
405       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
406       --  Nam is an N_String_Literal node containing the external name set by
407       --  an Import or Export pragma (or extended Import or Export pragma).
408       --  This procedure checks for possible duplications if this is the export
409       --  case, and if found, issues an appropriate error message.
410
411       procedure Check_First_Subtype (Arg : Node_Id);
412       --  Checks that Arg, whose expression is an entity name, references a
413       --  first subtype.
414
415       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
416       --  Checks that the given argument has an identifier, and if so, requires
417       --  it to match the given identifier name. If there is no identifier, or
418       --  a non-matching identifier, then an error message is given and
419       --  Pragma_Exit is raised.
420
421       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
422       --  Checks that the given argument has an identifier, and if so, requires
423       --  it to match one of the given identifier names. If there is no
424       --  identifier, or a non-matching identifier, then an error message is
425       --  given and Pragma_Exit is raised. This checks the optional identifier
426       --  of a pragma argument, not the argument itself like
427       --  Check_Arg_Is_One_Of does.
428
429       procedure Check_In_Main_Program;
430       --  Common checks for pragmas that appear within a main program
431       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
432
433       procedure Check_Interrupt_Or_Attach_Handler;
434       --  Common processing for first argument of pragma Interrupt_Handler or
435       --  pragma Attach_Handler.
436
437       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
438       --  Check that pragma appears in a declarative part, or in a package
439       --  specification, i.e. that it does not occur in a statement sequence
440       --  in a body.
441
442       procedure Check_No_Identifier (Arg : Node_Id);
443       --  Checks that the given argument does not have an identifier. If
444       --  an identifier is present, then an error message is issued, and
445       --  Pragma_Exit is raised.
446
447       procedure Check_No_Identifiers;
448       --  Checks that none of the arguments to the pragma has an identifier.
449       --  If any argument has an identifier, then an error message is issued,
450       --  and Pragma_Exit is raised.
451
452       procedure Check_No_Link_Name;
453       --  Checks that no link name is specified
454
455       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
456       --  Checks if the given argument has an identifier, and if so, requires
457       --  it to match the given identifier name. If there is a non-matching
458       --  identifier, then an error message is given and Pragma_Exit is raised.
459
460       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
461       --  Checks if the given argument has an identifier, and if so, requires
462       --  it to match the given identifier name. If there is a non-matching
463       --  identifier, then an error message is given and Pragma_Exit is raised.
464       --  In this version of the procedure, the identifier name is given as
465       --  a string with lower case letters.
466
467       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
468       --  Called to process a precondition or postcondition pragma. There are
469       --  three cases:
470       --
471       --    The pragma appears after a subprogram spec
472       --
473       --      If the corresponding check is not enabled, the pragma is analyzed
474       --      but otherwise ignored and control returns with In_Body set False.
475       --
476       --      If the check is enabled, then the first step is to analyze the
477       --      pragma, but this is skipped if the subprogram spec appears within
478       --      a package specification (because this is the case where we delay
479       --      analysis till the end of the spec). Then (whether or not it was
480       --      analyzed), the pragma is chained to the subprogram in question
481       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
482       --      caller with In_Body set False.
483       --
484       --    The pragma appears at the start of subprogram body declarations
485       --
486       --      In this case an immediate return to the caller is made with
487       --      In_Body set True, and the pragma is NOT analyzed.
488       --
489       --    In all other cases, an error message for bad placement is given
490
491       procedure Check_Static_Constraint (Constr : Node_Id);
492       --  Constr is a constraint from an N_Subtype_Indication node from a
493       --  component constraint in an Unchecked_Union type. This routine checks
494       --  that the constraint is static as required by the restrictions for
495       --  Unchecked_Union.
496
497       procedure Check_Test_Case;
498       --  Called to process a test-case pragma. The treatment is similar to the
499       --  one for pre- and postcondition in Check_Precondition_Postcondition.
500       --  There are three cases:
501       --
502       --    The pragma appears after a subprogram spec
503       --
504       --      The first step is to analyze the pragma, but this is skipped if
505       --      the subprogram spec appears within a package specification
506       --      (because this is the case where we delay analysis till the end of
507       --      the spec). Then (whether or not it was analyzed), the pragma is
508       --      chained to the subprogram in question (using Spec_TC_List and
509       --      Next_Pragma).
510       --
511       --    The pragma appears at the start of subprogram body declarations
512       --
513       --      In this case an immediate return to the caller is made, and the
514       --      pragma is NOT analyzed.
515       --
516       --    In all other cases, an error message for bad placement is given
517
518       procedure Check_Valid_Configuration_Pragma;
519       --  Legality checks for placement of a configuration pragma
520
521       procedure Check_Valid_Library_Unit_Pragma;
522       --  Legality checks for library unit pragmas. A special case arises for
523       --  pragmas in generic instances that come from copies of the original
524       --  library unit pragmas in the generic templates. In the case of other
525       --  than library level instantiations these can appear in contexts which
526       --  would normally be invalid (they only apply to the original template
527       --  and to library level instantiations), and they are simply ignored,
528       --  which is implemented by rewriting them as null statements.
529
530       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
531       --  Check an Unchecked_Union variant for lack of nested variants and
532       --  presence of at least one component. UU_Typ is the related Unchecked_
533       --  Union type.
534
535       procedure Error_Pragma (Msg : String);
536       pragma No_Return (Error_Pragma);
537       --  Outputs error message for current pragma. The message contains a %
538       --  that will be replaced with the pragma name, and the flag is placed
539       --  on the pragma itself. Pragma_Exit is then raised.
540
541       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
542       pragma No_Return (Error_Pragma_Arg);
543       --  Outputs error message for current pragma. The message may contain
544       --  a % that will be replaced with the pragma name. The parameter Arg
545       --  may either be a pragma argument association, in which case the flag
546       --  is placed on the expression of this association, or an expression,
547       --  in which case the flag is placed directly on the expression. The
548       --  message is placed using Error_Msg_N, so the message may also contain
549       --  an & insertion character which will reference the given Arg value.
550       --  After placing the message, Pragma_Exit is raised.
551
552       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
553       pragma No_Return (Error_Pragma_Arg);
554       --  Similar to above form of Error_Pragma_Arg except that two messages
555       --  are provided, the second is a continuation comment starting with \.
556
557       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
558       pragma No_Return (Error_Pragma_Arg_Ident);
559       --  Outputs error message for current pragma. The message may contain
560       --  a % that will be replaced with the pragma name. The parameter Arg
561       --  must be a pragma argument association with a non-empty identifier
562       --  (i.e. its Chars field must be set), and the error message is placed
563       --  on the identifier. The message is placed using Error_Msg_N so
564       --  the message may also contain an & insertion character which will
565       --  reference the identifier. After placing the message, Pragma_Exit
566       --  is raised.
567
568       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
569       pragma No_Return (Error_Pragma_Ref);
570       --  Outputs error message for current pragma. The message may contain
571       --  a % that will be replaced with the pragma name. The parameter Ref
572       --  must be an entity whose name can be referenced by & and sloc by #.
573       --  After placing the message, Pragma_Exit is raised.
574
575       function Find_Lib_Unit_Name return Entity_Id;
576       --  Used for a library unit pragma to find the entity to which the
577       --  library unit pragma applies, returns the entity found.
578
579       procedure Find_Program_Unit_Name (Id : Node_Id);
580       --  If the pragma is a compilation unit pragma, the id must denote the
581       --  compilation unit in the same compilation, and the pragma must appear
582       --  in the list of preceding or trailing pragmas. If it is a program
583       --  unit pragma that is not a compilation unit pragma, then the
584       --  identifier must be visible.
585
586       function Find_Unique_Parameterless_Procedure
587         (Name : Entity_Id;
588          Arg  : Node_Id) return Entity_Id;
589       --  Used for a procedure pragma to find the unique parameterless
590       --  procedure identified by Name, returns it if it exists, otherwise
591       --  errors out and uses Arg as the pragma argument for the message.
592
593       procedure Fix_Error (Msg : in out String);
594       --  This is called prior to issuing an error message. Msg is a string
595       --  which typically contains the substring pragma. If the current pragma
596       --  comes from an aspect, each such "pragma" substring is replaced with
597       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
598       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
599
600       procedure Gather_Associations
601         (Names : Name_List;
602          Args  : out Args_List);
603       --  This procedure is used to gather the arguments for a pragma that
604       --  permits arbitrary ordering of parameters using the normal rules
605       --  for named and positional parameters. The Names argument is a list
606       --  of Name_Id values that corresponds to the allowed pragma argument
607       --  association identifiers in order. The result returned in Args is
608       --  a list of corresponding expressions that are the pragma arguments.
609       --  Note that this is a list of expressions, not of pragma argument
610       --  associations (Gather_Associations has completely checked all the
611       --  optional identifiers when it returns). An entry in Args is Empty
612       --  on return if the corresponding argument is not present.
613
614       procedure GNAT_Pragma;
615       --  Called for all GNAT defined pragmas to check the relevant restriction
616       --  (No_Implementation_Pragmas).
617
618       function Is_Before_First_Decl
619         (Pragma_Node : Node_Id;
620          Decls       : List_Id) return Boolean;
621       --  Return True if Pragma_Node is before the first declarative item in
622       --  Decls where Decls is the list of declarative items.
623
624       function Is_Configuration_Pragma return Boolean;
625       --  Determines if the placement of the current pragma is appropriate
626       --  for a configuration pragma.
627
628       function Is_In_Context_Clause return Boolean;
629       --  Returns True if pragma appears within the context clause of a unit,
630       --  and False for any other placement (does not generate any messages).
631
632       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
633       --  Analyzes the argument, and determines if it is a static string
634       --  expression, returns True if so, False if non-static or not String.
635
636       procedure Pragma_Misplaced;
637       pragma No_Return (Pragma_Misplaced);
638       --  Issue fatal error message for misplaced pragma
639
640       procedure Process_Atomic_Shared_Volatile;
641       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
642       --  Shared is an obsolete Ada 83 pragma, treated as being identical
643       --  in effect to pragma Atomic.
644
645       procedure Process_Compile_Time_Warning_Or_Error;
646       --  Common processing for Compile_Time_Error and Compile_Time_Warning
647
648       procedure Process_Convention
649         (C   : out Convention_Id;
650          Ent : out Entity_Id);
651       --  Common processing for Convention, Interface, Import and Export.
652       --  Checks first two arguments of pragma, and sets the appropriate
653       --  convention value in the specified entity or entities. On return
654       --  C is the convention, Ent is the referenced entity.
655
656       procedure Process_Extended_Import_Export_Exception_Pragma
657         (Arg_Internal : Node_Id;
658          Arg_External : Node_Id;
659          Arg_Form     : Node_Id;
660          Arg_Code     : Node_Id);
661       --  Common processing for the pragmas Import/Export_Exception. The three
662       --  arguments correspond to the three named parameters of the pragma. An
663       --  argument is empty if the corresponding parameter is not present in
664       --  the pragma.
665
666       procedure Process_Extended_Import_Export_Object_Pragma
667         (Arg_Internal : Node_Id;
668          Arg_External : Node_Id;
669          Arg_Size     : Node_Id);
670       --  Common processing for the pragmas Import/Export_Object. The three
671       --  arguments correspond to the three named parameters of the pragmas. An
672       --  argument is empty if the corresponding parameter is not present in
673       --  the pragma.
674
675       procedure Process_Extended_Import_Export_Internal_Arg
676         (Arg_Internal : Node_Id := Empty);
677       --  Common processing for all extended Import and Export pragmas. The
678       --  argument is the pragma parameter for the Internal argument. If
679       --  Arg_Internal is empty or inappropriate, an error message is posted.
680       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
681       --  set to identify the referenced entity.
682
683       procedure Process_Extended_Import_Export_Subprogram_Pragma
684         (Arg_Internal                 : Node_Id;
685          Arg_External                 : Node_Id;
686          Arg_Parameter_Types          : Node_Id;
687          Arg_Result_Type              : Node_Id := Empty;
688          Arg_Mechanism                : Node_Id;
689          Arg_Result_Mechanism         : Node_Id := Empty;
690          Arg_First_Optional_Parameter : Node_Id := Empty);
691       --  Common processing for all extended Import and Export pragmas applying
692       --  to subprograms. The caller omits any arguments that do not apply to
693       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
694       --  only in the Import_Function and Export_Function cases). The argument
695       --  names correspond to the allowed pragma association identifiers.
696
697       procedure Process_Generic_List;
698       --  Common processing for Share_Generic and Inline_Generic
699
700       procedure Process_Import_Or_Interface;
701       --  Common processing for Import of Interface
702
703       procedure Process_Import_Predefined_Type;
704       --  Processing for completing a type with pragma Import. This is used
705       --  to declare types that match predefined C types, especially for cases
706       --  without corresponding Ada predefined type.
707
708       procedure Process_Inline (Active : Boolean);
709       --  Common processing for Inline and Inline_Always. The parameter
710       --  indicates if the inline pragma is active, i.e. if it should actually
711       --  cause inlining to occur.
712
713       procedure Process_Interface_Name
714         (Subprogram_Def : Entity_Id;
715          Ext_Arg        : Node_Id;
716          Link_Arg       : Node_Id);
717       --  Given the last two arguments of pragma Import, pragma Export, or
718       --  pragma Interface_Name, performs validity checks and sets the
719       --  Interface_Name field of the given subprogram entity to the
720       --  appropriate external or link name, depending on the arguments given.
721       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
722       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
723       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
724       --  nor Link_Arg is present, the interface name is set to the default
725       --  from the subprogram name.
726
727       procedure Process_Interrupt_Or_Attach_Handler;
728       --  Common processing for Interrupt and Attach_Handler pragmas
729
730       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
731       --  Common processing for Restrictions and Restriction_Warnings pragmas.
732       --  Warn is True for Restriction_Warnings, or for Restrictions if the
733       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
734       --  is not set in the Restrictions case.
735
736       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
737       --  Common processing for Suppress and Unsuppress. The boolean parameter
738       --  Suppress_Case is True for the Suppress case, and False for the
739       --  Unsuppress case.
740
741       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
742       --  This procedure sets the Is_Exported flag for the given entity,
743       --  checking that the entity was not previously imported. Arg is
744       --  the argument that specified the entity. A check is also made
745       --  for exporting inappropriate entities.
746
747       procedure Set_Extended_Import_Export_External_Name
748         (Internal_Ent : Entity_Id;
749          Arg_External : Node_Id);
750       --  Common processing for all extended import export pragmas. The first
751       --  argument, Internal_Ent, is the internal entity, which has already
752       --  been checked for validity by the caller. Arg_External is from the
753       --  Import or Export pragma, and may be null if no External parameter
754       --  was present. If Arg_External is present and is a non-null string
755       --  (a null string is treated as the default), then the Interface_Name
756       --  field of Internal_Ent is set appropriately.
757
758       procedure Set_Imported (E : Entity_Id);
759       --  This procedure sets the Is_Imported flag for the given entity,
760       --  checking that it is not previously exported or imported.
761
762       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
763       --  Mech is a parameter passing mechanism (see Import_Function syntax
764       --  for MECHANISM_NAME). This routine checks that the mechanism argument
765       --  has the right form, and if not issues an error message. If the
766       --  argument has the right form then the Mechanism field of Ent is
767       --  set appropriately.
768
769       procedure Set_Ravenscar_Profile (N : Node_Id);
770       --  Activate the set of configuration pragmas and restrictions that make
771       --  up the Ravenscar Profile. N is the corresponding pragma node, which
772       --  is used for error messages on any constructs that violate the
773       --  profile.
774
775       ---------------------
776       -- Ada_2005_Pragma --
777       ---------------------
778
779       procedure Ada_2005_Pragma is
780       begin
781          if Ada_Version <= Ada_95 then
782             Check_Restriction (No_Implementation_Pragmas, N);
783          end if;
784       end Ada_2005_Pragma;
785
786       ---------------------
787       -- Ada_2012_Pragma --
788       ---------------------
789
790       procedure Ada_2012_Pragma is
791       begin
792          if Ada_Version <= Ada_2005 then
793             Check_Restriction (No_Implementation_Pragmas, N);
794          end if;
795       end Ada_2012_Pragma;
796
797       --------------------------
798       -- Check_Ada_83_Warning --
799       --------------------------
800
801       procedure Check_Ada_83_Warning is
802       begin
803          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
804             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
805          end if;
806       end Check_Ada_83_Warning;
807
808       ---------------------
809       -- Check_Arg_Count --
810       ---------------------
811
812       procedure Check_Arg_Count (Required : Nat) is
813       begin
814          if Arg_Count /= Required then
815             Error_Pragma ("wrong number of arguments for pragma%");
816          end if;
817       end Check_Arg_Count;
818
819       --------------------------------
820       -- Check_Arg_Is_External_Name --
821       --------------------------------
822
823       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
824          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
825
826       begin
827          if Nkind (Argx) = N_Identifier then
828             return;
829
830          else
831             Analyze_And_Resolve (Argx, Standard_String);
832
833             if Is_OK_Static_Expression (Argx) then
834                return;
835
836             elsif Etype (Argx) = Any_Type then
837                raise Pragma_Exit;
838
839             --  An interesting special case, if we have a string literal and
840             --  we are in Ada 83 mode, then we allow it even though it will
841             --  not be flagged as static. This allows expected Ada 83 mode
842             --  use of external names which are string literals, even though
843             --  technically these are not static in Ada 83.
844
845             elsif Ada_Version = Ada_83
846               and then Nkind (Argx) = N_String_Literal
847             then
848                return;
849
850             --  Static expression that raises Constraint_Error. This has
851             --  already been flagged, so just exit from pragma processing.
852
853             elsif Is_Static_Expression (Argx) then
854                raise Pragma_Exit;
855
856             --  Here we have a real error (non-static expression)
857
858             else
859                Error_Msg_Name_1 := Pname;
860
861                declare
862                   Msg : String :=
863                           "argument for pragma% must be a identifier or "
864                           & "static string expression!";
865                begin
866                   Fix_Error (Msg);
867                   Flag_Non_Static_Expr (Msg, Argx);
868                   raise Pragma_Exit;
869                end;
870             end if;
871          end if;
872       end Check_Arg_Is_External_Name;
873
874       -----------------------------
875       -- Check_Arg_Is_Identifier --
876       -----------------------------
877
878       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
879          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
880       begin
881          if Nkind (Argx) /= N_Identifier then
882             Error_Pragma_Arg
883               ("argument for pragma% must be identifier", Argx);
884          end if;
885       end Check_Arg_Is_Identifier;
886
887       ----------------------------------
888       -- Check_Arg_Is_Integer_Literal --
889       ----------------------------------
890
891       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
892          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
893       begin
894          if Nkind (Argx) /= N_Integer_Literal then
895             Error_Pragma_Arg
896               ("argument for pragma% must be integer literal", Argx);
897          end if;
898       end Check_Arg_Is_Integer_Literal;
899
900       -------------------------------------------
901       -- Check_Arg_Is_Library_Level_Local_Name --
902       -------------------------------------------
903
904       --  LOCAL_NAME ::=
905       --    DIRECT_NAME
906       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
907       --  | library_unit_NAME
908
909       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
910       begin
911          Check_Arg_Is_Local_Name (Arg);
912
913          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
914            and then Comes_From_Source (N)
915          then
916             Error_Pragma_Arg
917               ("argument for pragma% must be library level entity", Arg);
918          end if;
919       end Check_Arg_Is_Library_Level_Local_Name;
920
921       -----------------------------
922       -- Check_Arg_Is_Local_Name --
923       -----------------------------
924
925       --  LOCAL_NAME ::=
926       --    DIRECT_NAME
927       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
928       --  | library_unit_NAME
929
930       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
931          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
932
933       begin
934          Analyze (Argx);
935
936          if Nkind (Argx) not in N_Direct_Name
937            and then (Nkind (Argx) /= N_Attribute_Reference
938                       or else Present (Expressions (Argx))
939                       or else Nkind (Prefix (Argx)) /= N_Identifier)
940            and then (not Is_Entity_Name (Argx)
941                       or else not Is_Compilation_Unit (Entity (Argx)))
942          then
943             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
944          end if;
945
946          --  No further check required if not an entity name
947
948          if not Is_Entity_Name (Argx) then
949             null;
950
951          else
952             declare
953                OK   : Boolean;
954                Ent  : constant Entity_Id := Entity (Argx);
955                Scop : constant Entity_Id := Scope (Ent);
956             begin
957                --  Case of a pragma applied to a compilation unit: pragma must
958                --  occur immediately after the program unit in the compilation.
959
960                if Is_Compilation_Unit (Ent) then
961                   declare
962                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
963                   begin
964                      --  Case of pragma placed immediately after spec
965
966                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
967                         OK := True;
968
969                      --  Case of pragma placed immediately after body
970
971                      elsif Nkind (Decl) = N_Subprogram_Declaration
972                              and then Present (Corresponding_Body (Decl))
973                      then
974                         OK := Parent (N) =
975                                 Aux_Decls_Node
976                                   (Parent (Unit_Declaration_Node
977                                              (Corresponding_Body (Decl))));
978
979                      --  All other cases are illegal
980
981                      else
982                         OK := False;
983                      end if;
984                   end;
985
986                --  Special restricted placement rule from 10.2.1(11.8/2)
987
988                elsif Is_Generic_Formal (Ent)
989                        and then Prag_Id = Pragma_Preelaborable_Initialization
990                then
991                   OK := List_Containing (N) =
992                           Generic_Formal_Declarations
993                             (Unit_Declaration_Node (Scop));
994
995                --  Default case, just check that the pragma occurs in the scope
996                --  of the entity denoted by the name.
997
998                else
999                   OK := Current_Scope = Scop;
1000                end if;
1001
1002                if not OK then
1003                   Error_Pragma_Arg
1004                     ("pragma% argument must be in same declarative part", Arg);
1005                end if;
1006             end;
1007          end if;
1008       end Check_Arg_Is_Local_Name;
1009
1010       ---------------------------------
1011       -- Check_Arg_Is_Locking_Policy --
1012       ---------------------------------
1013
1014       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1015          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1016
1017       begin
1018          Check_Arg_Is_Identifier (Argx);
1019
1020          if not Is_Locking_Policy_Name (Chars (Argx)) then
1021             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1022          end if;
1023       end Check_Arg_Is_Locking_Policy;
1024
1025       -------------------------
1026       -- Check_Arg_Is_One_Of --
1027       -------------------------
1028
1029       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1030          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1031
1032       begin
1033          Check_Arg_Is_Identifier (Argx);
1034
1035          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1036             Error_Msg_Name_2 := N1;
1037             Error_Msg_Name_3 := N2;
1038             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1039          end if;
1040       end Check_Arg_Is_One_Of;
1041
1042       procedure Check_Arg_Is_One_Of
1043         (Arg        : Node_Id;
1044          N1, N2, N3 : Name_Id)
1045       is
1046          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1047
1048       begin
1049          Check_Arg_Is_Identifier (Argx);
1050
1051          if Chars (Argx) /= N1
1052            and then Chars (Argx) /= N2
1053            and then Chars (Argx) /= N3
1054          then
1055             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1056          end if;
1057       end Check_Arg_Is_One_Of;
1058
1059       procedure Check_Arg_Is_One_Of
1060         (Arg            : Node_Id;
1061          N1, N2, N3, N4 : Name_Id)
1062       is
1063          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1064
1065       begin
1066          Check_Arg_Is_Identifier (Argx);
1067
1068          if Chars (Argx) /= N1
1069            and then Chars (Argx) /= N2
1070            and then Chars (Argx) /= N3
1071            and then Chars (Argx) /= N4
1072          then
1073             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1074          end if;
1075       end Check_Arg_Is_One_Of;
1076
1077       ---------------------------------
1078       -- Check_Arg_Is_Queuing_Policy --
1079       ---------------------------------
1080
1081       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1082          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1083
1084       begin
1085          Check_Arg_Is_Identifier (Argx);
1086
1087          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1088             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1089          end if;
1090       end Check_Arg_Is_Queuing_Policy;
1091
1092       ------------------------------------
1093       -- Check_Arg_Is_Static_Expression --
1094       ------------------------------------
1095
1096       procedure Check_Arg_Is_Static_Expression
1097         (Arg : Node_Id;
1098          Typ : Entity_Id := Empty)
1099       is
1100          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1101
1102       begin
1103          if Present (Typ) then
1104             Analyze_And_Resolve (Argx, Typ);
1105          else
1106             Analyze_And_Resolve (Argx);
1107          end if;
1108
1109          if Is_OK_Static_Expression (Argx) then
1110             return;
1111
1112          elsif Etype (Argx) = Any_Type then
1113             raise Pragma_Exit;
1114
1115          --  An interesting special case, if we have a string literal and we
1116          --  are in Ada 83 mode, then we allow it even though it will not be
1117          --  flagged as static. This allows the use of Ada 95 pragmas like
1118          --  Import in Ada 83 mode. They will of course be flagged with
1119          --  warnings as usual, but will not cause errors.
1120
1121          elsif Ada_Version = Ada_83
1122            and then Nkind (Argx) = N_String_Literal
1123          then
1124             return;
1125
1126          --  Static expression that raises Constraint_Error. This has already
1127          --  been flagged, so just exit from pragma processing.
1128
1129          elsif Is_Static_Expression (Argx) then
1130             raise Pragma_Exit;
1131
1132          --  Finally, we have a real error
1133
1134          else
1135             Error_Msg_Name_1 := Pname;
1136
1137             declare
1138                Msg : String :=
1139                        "argument for pragma% must be a static expression!";
1140             begin
1141                Fix_Error (Msg);
1142                Flag_Non_Static_Expr (Msg, Argx);
1143             end;
1144
1145             raise Pragma_Exit;
1146          end if;
1147       end Check_Arg_Is_Static_Expression;
1148
1149       ------------------------------------------
1150       -- Check_Arg_Is_Task_Dispatching_Policy --
1151       ------------------------------------------
1152
1153       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1154          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1155
1156       begin
1157          Check_Arg_Is_Identifier (Argx);
1158
1159          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1160             Error_Pragma_Arg
1161               ("& is not a valid task dispatching policy name", Argx);
1162          end if;
1163       end Check_Arg_Is_Task_Dispatching_Policy;
1164
1165       ---------------------
1166       -- Check_Arg_Order --
1167       ---------------------
1168
1169       procedure Check_Arg_Order (Names : Name_List) is
1170          Arg : Node_Id;
1171
1172          Highest_So_Far : Natural := 0;
1173          --  Highest index in Names seen do far
1174
1175       begin
1176          Arg := Arg1;
1177          for J in 1 .. Arg_Count loop
1178             if Chars (Arg) /= No_Name then
1179                for K in Names'Range loop
1180                   if Chars (Arg) = Names (K) then
1181                      if K < Highest_So_Far then
1182                         Error_Msg_Name_1 := Pname;
1183                         Error_Msg_N
1184                           ("parameters out of order for pragma%", Arg);
1185                         Error_Msg_Name_1 := Names (K);
1186                         Error_Msg_Name_2 := Names (Highest_So_Far);
1187                         Error_Msg_N ("\% must appear before %", Arg);
1188                         raise Pragma_Exit;
1189
1190                      else
1191                         Highest_So_Far := K;
1192                      end if;
1193                   end if;
1194                end loop;
1195             end if;
1196
1197             Arg := Next (Arg);
1198          end loop;
1199       end Check_Arg_Order;
1200
1201       --------------------------------
1202       -- Check_At_Least_N_Arguments --
1203       --------------------------------
1204
1205       procedure Check_At_Least_N_Arguments (N : Nat) is
1206       begin
1207          if Arg_Count < N then
1208             Error_Pragma ("too few arguments for pragma%");
1209          end if;
1210       end Check_At_Least_N_Arguments;
1211
1212       -------------------------------
1213       -- Check_At_Most_N_Arguments --
1214       -------------------------------
1215
1216       procedure Check_At_Most_N_Arguments (N : Nat) is
1217          Arg : Node_Id;
1218       begin
1219          if Arg_Count > N then
1220             Arg := Arg1;
1221             for J in 1 .. N loop
1222                Next (Arg);
1223                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1224             end loop;
1225          end if;
1226       end Check_At_Most_N_Arguments;
1227
1228       ---------------------
1229       -- Check_Component --
1230       ---------------------
1231
1232       procedure Check_Component
1233         (Comp            : Node_Id;
1234          UU_Typ          : Entity_Id;
1235          In_Variant_Part : Boolean := False)
1236       is
1237          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1238          Sindic  : constant Node_Id :=
1239                      Subtype_Indication (Component_Definition (Comp));
1240          Typ     : constant Entity_Id := Etype (Comp_Id);
1241
1242          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1243          --  Determine whether entity Id appears inside a generic body.
1244          --  Shouldn't this be in a more general place ???
1245
1246          -------------------------
1247          -- Inside_Generic_Body --
1248          -------------------------
1249
1250          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1251             S : Entity_Id;
1252
1253          begin
1254             S := Id;
1255             while Present (S) and then S /= Standard_Standard loop
1256                if Ekind (S) = E_Generic_Package
1257                  and then In_Package_Body (S)
1258                then
1259                   return True;
1260                end if;
1261
1262                S := Scope (S);
1263             end loop;
1264
1265             return False;
1266          end Inside_Generic_Body;
1267
1268       --  Start of processing for Check_Component
1269
1270       begin
1271          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1272          --  object constraint, then the component type shall be an Unchecked_
1273          --  Union.
1274
1275          if Nkind (Sindic) = N_Subtype_Indication
1276            and then Has_Per_Object_Constraint (Comp_Id)
1277            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1278          then
1279             Error_Msg_N
1280               ("component subtype subject to per-object constraint " &
1281                "must be an Unchecked_Union", Comp);
1282
1283          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1284          --  the body of a generic unit, or within the body of any of its
1285          --  descendant library units, no part of the type of a component
1286          --  declared in a variant_part of the unchecked union type shall be of
1287          --  a formal private type or formal private extension declared within
1288          --  the formal part of the generic unit.
1289
1290          elsif Ada_Version >= Ada_2012
1291            and then Inside_Generic_Body (UU_Typ)
1292            and then In_Variant_Part
1293            and then Is_Private_Type (Typ)
1294            and then Is_Generic_Type (Typ)
1295          then
1296             Error_Msg_N
1297               ("component of Unchecked_Union cannot be of generic type", Comp);
1298
1299          elsif Needs_Finalization (Typ) then
1300             Error_Msg_N
1301               ("component of Unchecked_Union cannot be controlled", Comp);
1302
1303          elsif Has_Task (Typ) then
1304             Error_Msg_N
1305               ("component of Unchecked_Union cannot have tasks", Comp);
1306          end if;
1307       end Check_Component;
1308
1309       ----------------------------
1310       -- Check_Duplicate_Pragma --
1311       ----------------------------
1312
1313       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1314          P : Node_Id;
1315
1316       begin
1317          --  Nothing to do if this pragma comes from an aspect specification,
1318          --  since we could not be duplicating a pragma, and we dealt with the
1319          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1320
1321          if From_Aspect_Specification (N) then
1322             return;
1323          end if;
1324
1325          --  Otherwise current pragma may duplicate previous pragma or a
1326          --  previously given aspect specification for the same pragma.
1327
1328          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1329
1330          if Present (P) then
1331             Error_Msg_Name_1 := Pragma_Name (N);
1332             Error_Msg_Sloc := Sloc (P);
1333
1334             if Nkind (P) = N_Aspect_Specification
1335               or else From_Aspect_Specification (P)
1336             then
1337                Error_Msg_NE ("aspect% for & previously given#", N, E);
1338             else
1339                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1340             end if;
1341
1342             raise Pragma_Exit;
1343          end if;
1344       end Check_Duplicate_Pragma;
1345
1346       ----------------------------------
1347       -- Check_Duplicated_Export_Name --
1348       ----------------------------------
1349
1350       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1351          String_Val : constant String_Id := Strval (Nam);
1352
1353       begin
1354          --  We are only interested in the export case, and in the case of
1355          --  generics, it is the instance, not the template, that is the
1356          --  problem (the template will generate a warning in any case).
1357
1358          if not Inside_A_Generic
1359            and then (Prag_Id = Pragma_Export
1360                        or else
1361                      Prag_Id = Pragma_Export_Procedure
1362                        or else
1363                      Prag_Id = Pragma_Export_Valued_Procedure
1364                        or else
1365                      Prag_Id = Pragma_Export_Function)
1366          then
1367             for J in Externals.First .. Externals.Last loop
1368                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1369                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1370                   Error_Msg_N ("external name duplicates name given#", Nam);
1371                   exit;
1372                end if;
1373             end loop;
1374
1375             Externals.Append (Nam);
1376          end if;
1377       end Check_Duplicated_Export_Name;
1378
1379       -------------------------
1380       -- Check_First_Subtype --
1381       -------------------------
1382
1383       procedure Check_First_Subtype (Arg : Node_Id) is
1384          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1385          Ent  : constant Entity_Id := Entity (Argx);
1386
1387       begin
1388          if Is_First_Subtype (Ent) then
1389             null;
1390
1391          elsif Is_Type (Ent) then
1392             Error_Pragma_Arg
1393               ("pragma% cannot apply to subtype", Argx);
1394
1395          elsif Is_Object (Ent) then
1396             Error_Pragma_Arg
1397               ("pragma% cannot apply to object, requires a type", Argx);
1398
1399          else
1400             Error_Pragma_Arg
1401               ("pragma% cannot apply to&, requires a type", Argx);
1402          end if;
1403       end Check_First_Subtype;
1404
1405       ----------------------
1406       -- Check_Identifier --
1407       ----------------------
1408
1409       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1410       begin
1411          if Present (Arg)
1412            and then Nkind (Arg) = N_Pragma_Argument_Association
1413          then
1414             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1415                Error_Msg_Name_1 := Pname;
1416                Error_Msg_Name_2 := Id;
1417                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1418                raise Pragma_Exit;
1419             end if;
1420          end if;
1421       end Check_Identifier;
1422
1423       --------------------------------
1424       -- Check_Identifier_Is_One_Of --
1425       --------------------------------
1426
1427       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1428       begin
1429          if Present (Arg)
1430            and then Nkind (Arg) = N_Pragma_Argument_Association
1431          then
1432             if Chars (Arg) = No_Name then
1433                Error_Msg_Name_1 := Pname;
1434                Error_Msg_N ("pragma% argument expects an identifier", Arg);
1435                raise Pragma_Exit;
1436
1437             elsif Chars (Arg) /= N1
1438               and then Chars (Arg) /= N2
1439             then
1440                Error_Msg_Name_1 := Pname;
1441                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1442                raise Pragma_Exit;
1443             end if;
1444          end if;
1445       end Check_Identifier_Is_One_Of;
1446
1447       ---------------------------
1448       -- Check_In_Main_Program --
1449       ---------------------------
1450
1451       procedure Check_In_Main_Program is
1452          P : constant Node_Id := Parent (N);
1453
1454       begin
1455          --  Must be at in subprogram body
1456
1457          if Nkind (P) /= N_Subprogram_Body then
1458             Error_Pragma ("% pragma allowed only in subprogram");
1459
1460          --  Otherwise warn if obviously not main program
1461
1462          elsif Present (Parameter_Specifications (Specification (P)))
1463            or else not Is_Compilation_Unit (Defining_Entity (P))
1464          then
1465             Error_Msg_Name_1 := Pname;
1466             Error_Msg_N
1467               ("?pragma% is only effective in main program", N);
1468          end if;
1469       end Check_In_Main_Program;
1470
1471       ---------------------------------------
1472       -- Check_Interrupt_Or_Attach_Handler --
1473       ---------------------------------------
1474
1475       procedure Check_Interrupt_Or_Attach_Handler is
1476          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1477          Handler_Proc, Proc_Scope : Entity_Id;
1478
1479       begin
1480          Analyze (Arg1_X);
1481
1482          if Prag_Id = Pragma_Interrupt_Handler then
1483             Check_Restriction (No_Dynamic_Attachment, N);
1484          end if;
1485
1486          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1487          Proc_Scope := Scope (Handler_Proc);
1488
1489          --  On AAMP only, a pragma Interrupt_Handler is supported for
1490          --  nonprotected parameterless procedures.
1491
1492          if not AAMP_On_Target
1493            or else Prag_Id = Pragma_Attach_Handler
1494          then
1495             if Ekind (Proc_Scope) /= E_Protected_Type then
1496                Error_Pragma_Arg
1497                  ("argument of pragma% must be protected procedure", Arg1);
1498             end if;
1499
1500             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1501                Error_Pragma ("pragma% must be in protected definition");
1502             end if;
1503          end if;
1504
1505          if not Is_Library_Level_Entity (Proc_Scope)
1506            or else (AAMP_On_Target
1507                      and then not Is_Library_Level_Entity (Handler_Proc))
1508          then
1509             Error_Pragma_Arg
1510               ("argument for pragma% must be library level entity", Arg1);
1511          end if;
1512
1513          --  AI05-0033: A pragma cannot appear within a generic body, because
1514          --  instance can be in a nested scope. The check that protected type
1515          --  is itself a library-level declaration is done elsewhere.
1516
1517          --  Note: we omit this check in Codepeer mode to properly handle code
1518          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1519
1520          if Inside_A_Generic then
1521             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1522               and then In_Package_Body (Scope (Current_Scope))
1523               and then not CodePeer_Mode
1524             then
1525                Error_Pragma ("pragma% cannot be used inside a generic");
1526             end if;
1527          end if;
1528       end Check_Interrupt_Or_Attach_Handler;
1529
1530       -------------------------------------------
1531       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1532       -------------------------------------------
1533
1534       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1535          P : Node_Id;
1536
1537       begin
1538          P := Parent (N);
1539          loop
1540             if No (P) then
1541                exit;
1542
1543             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1544                exit;
1545
1546             elsif Nkind_In (P, N_Package_Specification,
1547                                N_Block_Statement)
1548             then
1549                return;
1550
1551             --  Note: the following tests seem a little peculiar, because
1552             --  they test for bodies, but if we were in the statement part
1553             --  of the body, we would already have hit the handled statement
1554             --  sequence, so the only way we get here is by being in the
1555             --  declarative part of the body.
1556
1557             elsif Nkind_In (P, N_Subprogram_Body,
1558                                N_Package_Body,
1559                                N_Task_Body,
1560                                N_Entry_Body)
1561             then
1562                return;
1563             end if;
1564
1565             P := Parent (P);
1566          end loop;
1567
1568          Error_Pragma ("pragma% is not in declarative part or package spec");
1569       end Check_Is_In_Decl_Part_Or_Package_Spec;
1570
1571       -------------------------
1572       -- Check_No_Identifier --
1573       -------------------------
1574
1575       procedure Check_No_Identifier (Arg : Node_Id) is
1576       begin
1577          if Nkind (Arg) = N_Pragma_Argument_Association
1578            and then Chars (Arg) /= No_Name
1579          then
1580             Error_Pragma_Arg_Ident
1581               ("pragma% does not permit identifier& here", Arg);
1582          end if;
1583       end Check_No_Identifier;
1584
1585       --------------------------
1586       -- Check_No_Identifiers --
1587       --------------------------
1588
1589       procedure Check_No_Identifiers is
1590          Arg_Node : Node_Id;
1591       begin
1592          if Arg_Count > 0 then
1593             Arg_Node := Arg1;
1594             while Present (Arg_Node) loop
1595                Check_No_Identifier (Arg_Node);
1596                Next (Arg_Node);
1597             end loop;
1598          end if;
1599       end Check_No_Identifiers;
1600
1601       ------------------------
1602       -- Check_No_Link_Name --
1603       ------------------------
1604
1605       procedure Check_No_Link_Name is
1606       begin
1607          if Present (Arg3)
1608            and then Chars (Arg3) = Name_Link_Name
1609          then
1610             Arg4 := Arg3;
1611          end if;
1612
1613          if Present (Arg4) then
1614             Error_Pragma_Arg
1615               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1616          end if;
1617       end Check_No_Link_Name;
1618
1619       -------------------------------
1620       -- Check_Optional_Identifier --
1621       -------------------------------
1622
1623       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1624       begin
1625          if Present (Arg)
1626            and then Nkind (Arg) = N_Pragma_Argument_Association
1627            and then Chars (Arg) /= No_Name
1628          then
1629             if Chars (Arg) /= Id then
1630                Error_Msg_Name_1 := Pname;
1631                Error_Msg_Name_2 := Id;
1632                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1633                raise Pragma_Exit;
1634             end if;
1635          end if;
1636       end Check_Optional_Identifier;
1637
1638       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1639       begin
1640          Name_Buffer (1 .. Id'Length) := Id;
1641          Name_Len := Id'Length;
1642          Check_Optional_Identifier (Arg, Name_Find);
1643       end Check_Optional_Identifier;
1644
1645       --------------------------------------
1646       -- Check_Precondition_Postcondition --
1647       --------------------------------------
1648
1649       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1650          P  : Node_Id;
1651          PO : Node_Id;
1652
1653          procedure Chain_PPC (PO : Node_Id);
1654          --  If PO is an entry or a [generic] subprogram declaration node, then
1655          --  the precondition/postcondition applies to this subprogram and the
1656          --  processing for the pragma is completed. Otherwise the pragma is
1657          --  misplaced.
1658
1659          ---------------
1660          -- Chain_PPC --
1661          ---------------
1662
1663          procedure Chain_PPC (PO : Node_Id) is
1664             S   : Entity_Id;
1665             P   : Node_Id;
1666
1667          begin
1668             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1669                if not From_Aspect_Specification (N) then
1670                   Error_Pragma
1671                     ("pragma% cannot be applied to abstract subprogram");
1672
1673                elsif Class_Present (N) then
1674                   null;
1675
1676                else
1677                   Error_Pragma
1678                     ("aspect % requires ''Class for abstract subprogram");
1679                end if;
1680
1681             --  AI05-0230: The same restriction applies to null procedures. For
1682             --  compatibility with earlier uses of the Ada pragma, apply this
1683             --  rule only to aspect specifications.
1684
1685             --  The above discrpency needs documentation. Robert is dubious
1686             --  about whether it is a good idea ???
1687
1688             elsif Nkind (PO) = N_Subprogram_Declaration
1689               and then Nkind (Specification (PO)) = N_Procedure_Specification
1690               and then Null_Present (Specification (PO))
1691               and then From_Aspect_Specification (N)
1692               and then not Class_Present (N)
1693             then
1694                Error_Pragma
1695                  ("aspect % requires ''Class for null procedure");
1696
1697             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1698                                     N_Generic_Subprogram_Declaration,
1699                                     N_Entry_Declaration)
1700             then
1701                Pragma_Misplaced;
1702             end if;
1703
1704             --  Here if we have [generic] subprogram or entry declaration
1705
1706             if Nkind (PO) = N_Entry_Declaration then
1707                S := Defining_Entity (PO);
1708             else
1709                S := Defining_Unit_Name (Specification (PO));
1710             end if;
1711
1712             --  Make sure we do not have the case of a precondition pragma when
1713             --  the Pre'Class aspect is present.
1714
1715             --  We do this by looking at pragmas already chained to the entity
1716             --  since the aspect derived pragma will be put on this list first.
1717
1718             if Pragma_Name (N) = Name_Precondition then
1719                if not From_Aspect_Specification (N) then
1720                   P := Spec_PPC_List (Contract (S));
1721                   while Present (P) loop
1722                      if Pragma_Name (P) = Name_Precondition
1723                        and then From_Aspect_Specification (P)
1724                        and then Class_Present (P)
1725                      then
1726                         Error_Msg_Sloc := Sloc (P);
1727                         Error_Pragma
1728                           ("pragma% not allowed, `Pre''Class` aspect given#");
1729                      end if;
1730
1731                      P := Next_Pragma (P);
1732                   end loop;
1733                end if;
1734             end if;
1735
1736             --  Similarly check for Pre with inherited Pre'Class. Note that
1737             --  we cover the aspect case as well here.
1738
1739             if Pragma_Name (N) = Name_Precondition
1740               and then not Class_Present (N)
1741             then
1742                declare
1743                   Inherited : constant Subprogram_List :=
1744                                 Inherited_Subprograms (S);
1745                   P         : Node_Id;
1746
1747                begin
1748                   for J in Inherited'Range loop
1749                      P := Spec_PPC_List (Contract (Inherited (J)));
1750                      while Present (P) loop
1751                         if Pragma_Name (P) = Name_Precondition
1752                           and then Class_Present (P)
1753                         then
1754                            Error_Msg_Sloc := Sloc (P);
1755                            Error_Pragma
1756                              ("pragma% not allowed, `Pre''Class` "
1757                               & "aspect inherited from#");
1758                         end if;
1759
1760                         P := Next_Pragma (P);
1761                      end loop;
1762                   end loop;
1763                end;
1764             end if;
1765
1766             --  Note: we do not analyze the pragma at this point. Instead we
1767             --  delay this analysis until the end of the declarative part in
1768             --  which the pragma appears. This implements the required delay
1769             --  in this analysis, allowing forward references. The analysis
1770             --  happens at the end of Analyze_Declarations.
1771
1772             --  Chain spec PPC pragma to list for subprogram
1773
1774             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1775             Set_Spec_PPC_List (Contract (S), N);
1776
1777             --  Return indicating spec case
1778
1779             In_Body := False;
1780             return;
1781          end Chain_PPC;
1782
1783       --  Start of processing for Check_Precondition_Postcondition
1784
1785       begin
1786          if not Is_List_Member (N) then
1787             Pragma_Misplaced;
1788          end if;
1789
1790          --  Preanalyze message argument if present. Visibility in this
1791          --  argument is established at the point of pragma occurrence.
1792
1793          if Arg_Count = 2 then
1794             Check_Optional_Identifier (Arg2, Name_Message);
1795             Preanalyze_Spec_Expression
1796               (Get_Pragma_Arg (Arg2), Standard_String);
1797          end if;
1798
1799          --  Record if pragma is enabled
1800
1801          if Check_Enabled (Pname) then
1802             Set_SCO_Pragma_Enabled (Loc);
1803          end if;
1804
1805          --  If we are within an inlined body, the legality of the pragma
1806          --  has been checked already.
1807
1808          if In_Inlined_Body then
1809             In_Body := True;
1810             return;
1811          end if;
1812
1813          --  Search prior declarations
1814
1815          P := N;
1816          while Present (Prev (P)) loop
1817             P := Prev (P);
1818
1819             --  If the previous node is a generic subprogram, do not go to to
1820             --  the original node, which is the unanalyzed tree: we need to
1821             --  attach the pre/postconditions to the analyzed version at this
1822             --  point. They get propagated to the original tree when analyzing
1823             --  the corresponding body.
1824
1825             if Nkind (P) not in N_Generic_Declaration then
1826                PO := Original_Node (P);
1827             else
1828                PO := P;
1829             end if;
1830
1831             --  Skip past prior pragma
1832
1833             if Nkind (PO) = N_Pragma then
1834                null;
1835
1836             --  Skip stuff not coming from source
1837
1838             elsif not Comes_From_Source (PO) then
1839
1840                --  The condition may apply to a subprogram instantiation
1841
1842                if Nkind (PO) = N_Subprogram_Declaration
1843                  and then Present (Generic_Parent (Specification (PO)))
1844                then
1845                   Chain_PPC (PO);
1846                   return;
1847
1848                --  For all other cases of non source code, do nothing
1849
1850                else
1851                   null;
1852                end if;
1853
1854             --  Only remaining possibility is subprogram declaration
1855
1856             else
1857                Chain_PPC (PO);
1858                return;
1859             end if;
1860          end loop;
1861
1862          --  If we fall through loop, pragma is at start of list, so see if it
1863          --  is at the start of declarations of a subprogram body.
1864
1865          if Nkind (Parent (N)) = N_Subprogram_Body
1866            and then List_Containing (N) = Declarations (Parent (N))
1867          then
1868             if Operating_Mode /= Generate_Code
1869               or else Inside_A_Generic
1870             then
1871                --  Analyze pragma expression for correctness and for ASIS use
1872
1873                Preanalyze_Spec_Expression
1874                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
1875             end if;
1876
1877             In_Body := True;
1878             return;
1879
1880          --  See if it is in the pragmas after a library level subprogram
1881
1882          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1883             Chain_PPC (Unit (Parent (Parent (N))));
1884             return;
1885          end if;
1886
1887          --  If we fall through, pragma was misplaced
1888
1889          Pragma_Misplaced;
1890       end Check_Precondition_Postcondition;
1891
1892       -----------------------------
1893       -- Check_Static_Constraint --
1894       -----------------------------
1895
1896       --  Note: for convenience in writing this procedure, in addition to
1897       --  the officially (i.e. by spec) allowed argument which is always a
1898       --  constraint, it also allows ranges and discriminant associations.
1899       --  Above is not clear ???
1900
1901       procedure Check_Static_Constraint (Constr : Node_Id) is
1902
1903          procedure Require_Static (E : Node_Id);
1904          --  Require given expression to be static expression
1905
1906          --------------------
1907          -- Require_Static --
1908          --------------------
1909
1910          procedure Require_Static (E : Node_Id) is
1911          begin
1912             if not Is_OK_Static_Expression (E) then
1913                Flag_Non_Static_Expr
1914                  ("non-static constraint not allowed in Unchecked_Union!", E);
1915                raise Pragma_Exit;
1916             end if;
1917          end Require_Static;
1918
1919       --  Start of processing for Check_Static_Constraint
1920
1921       begin
1922          case Nkind (Constr) is
1923             when N_Discriminant_Association =>
1924                Require_Static (Expression (Constr));
1925
1926             when N_Range =>
1927                Require_Static (Low_Bound (Constr));
1928                Require_Static (High_Bound (Constr));
1929
1930             when N_Attribute_Reference =>
1931                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
1932                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1933
1934             when N_Range_Constraint =>
1935                Check_Static_Constraint (Range_Expression (Constr));
1936
1937             when N_Index_Or_Discriminant_Constraint =>
1938                declare
1939                   IDC : Entity_Id;
1940                begin
1941                   IDC := First (Constraints (Constr));
1942                   while Present (IDC) loop
1943                      Check_Static_Constraint (IDC);
1944                      Next (IDC);
1945                   end loop;
1946                end;
1947
1948             when others =>
1949                null;
1950          end case;
1951       end Check_Static_Constraint;
1952
1953       ---------------------
1954       -- Check_Test_Case --
1955       ---------------------
1956
1957       procedure Check_Test_Case is
1958          P  : Node_Id;
1959          PO : Node_Id;
1960
1961          procedure Chain_TC (PO : Node_Id);
1962          --  If PO is an entry or a [generic] subprogram declaration node, then
1963          --  the test-case applies to this subprogram and the processing for
1964          --  the pragma is completed. Otherwise the pragma is misplaced.
1965
1966          --------------
1967          -- Chain_TC --
1968          --------------
1969
1970          procedure Chain_TC (PO : Node_Id) is
1971             S   : Entity_Id;
1972
1973          begin
1974             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1975                if From_Aspect_Specification (N) then
1976                   Error_Pragma
1977                     ("aspect% cannot be applied to abstract subprogram");
1978                else
1979                   Error_Pragma
1980                     ("pragma% cannot be applied to abstract subprogram");
1981                end if;
1982
1983             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1984                                     N_Generic_Subprogram_Declaration,
1985                                     N_Entry_Declaration)
1986             then
1987                Pragma_Misplaced;
1988             end if;
1989
1990             --  Here if we have [generic] subprogram or entry declaration
1991
1992             if Nkind (PO) = N_Entry_Declaration then
1993                S := Defining_Entity (PO);
1994             else
1995                S := Defining_Unit_Name (Specification (PO));
1996             end if;
1997
1998             --  Note: we do not analyze the pragma at this point. Instead we
1999             --  delay this analysis until the end of the declarative part in
2000             --  which the pragma appears. This implements the required delay
2001             --  in this analysis, allowing forward references. The analysis
2002             --  happens at the end of Analyze_Declarations.
2003
2004             --  There should not be another test case with the same name
2005             --  associated to this subprogram.
2006
2007             declare
2008                Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2009                TC   : Node_Id;
2010
2011             begin
2012                TC := Spec_TC_List (Contract (S));
2013                while Present (TC) loop
2014
2015                   if String_Equal
2016                     (Name, Get_Name_From_Test_Case_Pragma (TC))
2017                   then
2018                      Error_Msg_Sloc := Sloc (TC);
2019
2020                      if From_Aspect_Specification (N) then
2021                         Error_Pragma ("name for aspect% is already used#");
2022                      else
2023                         Error_Pragma ("name for pragma% is already used#");
2024                      end if;
2025                   end if;
2026
2027                   TC := Next_Pragma (TC);
2028                end loop;
2029             end;
2030
2031             --  Chain spec TC pragma to list for subprogram
2032
2033             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2034             Set_Spec_TC_List (Contract (S), N);
2035          end Chain_TC;
2036
2037       --  Start of processing for Check_Test_Case
2038
2039       begin
2040          if not Is_List_Member (N) then
2041             Pragma_Misplaced;
2042          end if;
2043
2044          --  Search prior declarations
2045
2046          P := N;
2047          while Present (Prev (P)) loop
2048             P := Prev (P);
2049
2050             --  If the previous node is a generic subprogram, do not go to to
2051             --  the original node, which is the unanalyzed tree: we need to
2052             --  attach the test-case to the analyzed version at this point.
2053             --  They get propagated to the original tree when analyzing the
2054             --  corresponding body.
2055
2056             if Nkind (P) not in N_Generic_Declaration then
2057                PO := Original_Node (P);
2058             else
2059                PO := P;
2060             end if;
2061
2062             --  Skip past prior pragma
2063
2064             if Nkind (PO) = N_Pragma then
2065                null;
2066
2067             --  Skip stuff not coming from source
2068
2069             elsif not Comes_From_Source (PO) then
2070                null;
2071
2072             --  Only remaining possibility is subprogram declaration
2073
2074             else
2075                Chain_TC (PO);
2076                return;
2077             end if;
2078          end loop;
2079
2080          --  If we fall through loop, pragma is at start of list, so see if it
2081          --  is in the pragmas after a library level subprogram.
2082
2083          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
2084             Chain_TC (Unit (Parent (Parent (N))));
2085             return;
2086          end if;
2087
2088          --  If we fall through, pragma was misplaced
2089
2090          Pragma_Misplaced;
2091       end Check_Test_Case;
2092
2093       --------------------------------------
2094       -- Check_Valid_Configuration_Pragma --
2095       --------------------------------------
2096
2097       --  A configuration pragma must appear in the context clause of a
2098       --  compilation unit, and only other pragmas may precede it. Note that
2099       --  the test also allows use in a configuration pragma file.
2100
2101       procedure Check_Valid_Configuration_Pragma is
2102       begin
2103          if not Is_Configuration_Pragma then
2104             Error_Pragma ("incorrect placement for configuration pragma%");
2105          end if;
2106       end Check_Valid_Configuration_Pragma;
2107
2108       -------------------------------------
2109       -- Check_Valid_Library_Unit_Pragma --
2110       -------------------------------------
2111
2112       procedure Check_Valid_Library_Unit_Pragma is
2113          Plist       : List_Id;
2114          Parent_Node : Node_Id;
2115          Unit_Name   : Entity_Id;
2116          Unit_Kind   : Node_Kind;
2117          Unit_Node   : Node_Id;
2118          Sindex      : Source_File_Index;
2119
2120       begin
2121          if not Is_List_Member (N) then
2122             Pragma_Misplaced;
2123
2124          else
2125             Plist := List_Containing (N);
2126             Parent_Node := Parent (Plist);
2127
2128             if Parent_Node = Empty then
2129                Pragma_Misplaced;
2130
2131             --  Case of pragma appearing after a compilation unit. In this case
2132             --  it must have an argument with the corresponding name and must
2133             --  be part of the following pragmas of its parent.
2134
2135             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2136                if Plist /= Pragmas_After (Parent_Node) then
2137                   Pragma_Misplaced;
2138
2139                elsif Arg_Count = 0 then
2140                   Error_Pragma
2141                     ("argument required if outside compilation unit");
2142
2143                else
2144                   Check_No_Identifiers;
2145                   Check_Arg_Count (1);
2146                   Unit_Node := Unit (Parent (Parent_Node));
2147                   Unit_Kind := Nkind (Unit_Node);
2148
2149                   Analyze (Get_Pragma_Arg (Arg1));
2150
2151                   if Unit_Kind = N_Generic_Subprogram_Declaration
2152                     or else Unit_Kind = N_Subprogram_Declaration
2153                   then
2154                      Unit_Name := Defining_Entity (Unit_Node);
2155
2156                   elsif Unit_Kind in N_Generic_Instantiation then
2157                      Unit_Name := Defining_Entity (Unit_Node);
2158
2159                   else
2160                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2161                   end if;
2162
2163                   if Chars (Unit_Name) /=
2164                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2165                   then
2166                      Error_Pragma_Arg
2167                        ("pragma% argument is not current unit name", Arg1);
2168                   end if;
2169
2170                   if Ekind (Unit_Name) = E_Package
2171                     and then Present (Renamed_Entity (Unit_Name))
2172                   then
2173                      Error_Pragma ("pragma% not allowed for renamed package");
2174                   end if;
2175                end if;
2176
2177             --  Pragma appears other than after a compilation unit
2178
2179             else
2180                --  Here we check for the generic instantiation case and also
2181                --  for the case of processing a generic formal package. We
2182                --  detect these cases by noting that the Sloc on the node
2183                --  does not belong to the current compilation unit.
2184
2185                Sindex := Source_Index (Current_Sem_Unit);
2186
2187                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2188                   Rewrite (N, Make_Null_Statement (Loc));
2189                   return;
2190
2191                --  If before first declaration, the pragma applies to the
2192                --  enclosing unit, and the name if present must be this name.
2193
2194                elsif Is_Before_First_Decl (N, Plist) then
2195                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2196                   Unit_Kind := Nkind (Unit_Node);
2197
2198                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2199                      Pragma_Misplaced;
2200
2201                   elsif Unit_Kind = N_Subprogram_Body
2202                     and then not Acts_As_Spec (Unit_Node)
2203                   then
2204                      Pragma_Misplaced;
2205
2206                   elsif Nkind (Parent_Node) = N_Package_Body then
2207                      Pragma_Misplaced;
2208
2209                   elsif Nkind (Parent_Node) = N_Package_Specification
2210                     and then Plist = Private_Declarations (Parent_Node)
2211                   then
2212                      Pragma_Misplaced;
2213
2214                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2215                            or else Nkind (Parent_Node) =
2216                                              N_Generic_Subprogram_Declaration)
2217                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2218                   then
2219                      Pragma_Misplaced;
2220
2221                   elsif Arg_Count > 0 then
2222                      Analyze (Get_Pragma_Arg (Arg1));
2223
2224                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2225                         Error_Pragma_Arg
2226                           ("name in pragma% must be enclosing unit", Arg1);
2227                      end if;
2228
2229                   --  It is legal to have no argument in this context
2230
2231                   else
2232                      return;
2233                   end if;
2234
2235                --  Error if not before first declaration. This is because a
2236                --  library unit pragma argument must be the name of a library
2237                --  unit (RM 10.1.5(7)), but the only names permitted in this
2238                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2239                --  generic subprogram declarations or generic instantiations.
2240
2241                else
2242                   Error_Pragma
2243                     ("pragma% misplaced, must be before first declaration");
2244                end if;
2245             end if;
2246          end if;
2247       end Check_Valid_Library_Unit_Pragma;
2248
2249       -------------------
2250       -- Check_Variant --
2251       -------------------
2252
2253       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2254          Clist : constant Node_Id := Component_List (Variant);
2255          Comp  : Node_Id;
2256
2257       begin
2258          if not Is_Non_Empty_List (Component_Items (Clist)) then
2259             Error_Msg_N
2260               ("Unchecked_Union may not have empty component list",
2261                Variant);
2262             return;
2263          end if;
2264
2265          Comp := First (Component_Items (Clist));
2266          while Present (Comp) loop
2267             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2268             Next (Comp);
2269          end loop;
2270       end Check_Variant;
2271
2272       ------------------
2273       -- Error_Pragma --
2274       ------------------
2275
2276       procedure Error_Pragma (Msg : String) is
2277          MsgF : String := Msg;
2278       begin
2279          Error_Msg_Name_1 := Pname;
2280          Fix_Error (MsgF);
2281          Error_Msg_N (MsgF, N);
2282          raise Pragma_Exit;
2283       end Error_Pragma;
2284
2285       ----------------------
2286       -- Error_Pragma_Arg --
2287       ----------------------
2288
2289       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2290          MsgF : String := Msg;
2291       begin
2292          Error_Msg_Name_1 := Pname;
2293          Fix_Error (MsgF);
2294          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2295          raise Pragma_Exit;
2296       end Error_Pragma_Arg;
2297
2298       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2299          MsgF : String := Msg1;
2300       begin
2301          Error_Msg_Name_1 := Pname;
2302          Fix_Error (MsgF);
2303          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2304          Error_Pragma_Arg (Msg2, Arg);
2305       end Error_Pragma_Arg;
2306
2307       ----------------------------
2308       -- Error_Pragma_Arg_Ident --
2309       ----------------------------
2310
2311       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2312          MsgF : String := Msg;
2313       begin
2314          Error_Msg_Name_1 := Pname;
2315          Fix_Error (MsgF);
2316          Error_Msg_N (MsgF, Arg);
2317          raise Pragma_Exit;
2318       end Error_Pragma_Arg_Ident;
2319
2320       ----------------------
2321       -- Error_Pragma_Ref --
2322       ----------------------
2323
2324       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2325          MsgF : String := Msg;
2326       begin
2327          Error_Msg_Name_1 := Pname;
2328          Fix_Error (MsgF);
2329          Error_Msg_Sloc   := Sloc (Ref);
2330          Error_Msg_NE (MsgF, N, Ref);
2331          raise Pragma_Exit;
2332       end Error_Pragma_Ref;
2333
2334       ------------------------
2335       -- Find_Lib_Unit_Name --
2336       ------------------------
2337
2338       function Find_Lib_Unit_Name return Entity_Id is
2339       begin
2340          --  Return inner compilation unit entity, for case of nested
2341          --  categorization pragmas. This happens in generic unit.
2342
2343          if Nkind (Parent (N)) = N_Package_Specification
2344            and then Defining_Entity (Parent (N)) /= Current_Scope
2345          then
2346             return Defining_Entity (Parent (N));
2347          else
2348             return Current_Scope;
2349          end if;
2350       end Find_Lib_Unit_Name;
2351
2352       ----------------------------
2353       -- Find_Program_Unit_Name --
2354       ----------------------------
2355
2356       procedure Find_Program_Unit_Name (Id : Node_Id) is
2357          Unit_Name : Entity_Id;
2358          Unit_Kind : Node_Kind;
2359          P         : constant Node_Id := Parent (N);
2360
2361       begin
2362          if Nkind (P) = N_Compilation_Unit then
2363             Unit_Kind := Nkind (Unit (P));
2364
2365             if Unit_Kind = N_Subprogram_Declaration
2366               or else Unit_Kind = N_Package_Declaration
2367               or else Unit_Kind in N_Generic_Declaration
2368             then
2369                Unit_Name := Defining_Entity (Unit (P));
2370
2371                if Chars (Id) = Chars (Unit_Name) then
2372                   Set_Entity (Id, Unit_Name);
2373                   Set_Etype (Id, Etype (Unit_Name));
2374                else
2375                   Set_Etype (Id, Any_Type);
2376                   Error_Pragma
2377                     ("cannot find program unit referenced by pragma%");
2378                end if;
2379
2380             else
2381                Set_Etype (Id, Any_Type);
2382                Error_Pragma ("pragma% inapplicable to this unit");
2383             end if;
2384
2385          else
2386             Analyze (Id);
2387          end if;
2388       end Find_Program_Unit_Name;
2389
2390       -----------------------------------------
2391       -- Find_Unique_Parameterless_Procedure --
2392       -----------------------------------------
2393
2394       function Find_Unique_Parameterless_Procedure
2395         (Name : Entity_Id;
2396          Arg  : Node_Id) return Entity_Id
2397       is
2398          Proc : Entity_Id := Empty;
2399
2400       begin
2401          --  The body of this procedure needs some comments ???
2402
2403          if not Is_Entity_Name (Name) then
2404             Error_Pragma_Arg
2405               ("argument of pragma% must be entity name", Arg);
2406
2407          elsif not Is_Overloaded (Name) then
2408             Proc := Entity (Name);
2409
2410             if Ekind (Proc) /= E_Procedure
2411               or else Present (First_Formal (Proc))
2412             then
2413                Error_Pragma_Arg
2414                  ("argument of pragma% must be parameterless procedure", Arg);
2415             end if;
2416
2417          else
2418             declare
2419                Found : Boolean := False;
2420                It    : Interp;
2421                Index : Interp_Index;
2422
2423             begin
2424                Get_First_Interp (Name, Index, It);
2425                while Present (It.Nam) loop
2426                   Proc := It.Nam;
2427
2428                   if Ekind (Proc) = E_Procedure
2429                     and then No (First_Formal (Proc))
2430                   then
2431                      if not Found then
2432                         Found := True;
2433                         Set_Entity (Name, Proc);
2434                         Set_Is_Overloaded (Name, False);
2435                      else
2436                         Error_Pragma_Arg
2437                           ("ambiguous handler name for pragma% ", Arg);
2438                      end if;
2439                   end if;
2440
2441                   Get_Next_Interp (Index, It);
2442                end loop;
2443
2444                if not Found then
2445                   Error_Pragma_Arg
2446                     ("argument of pragma% must be parameterless procedure",
2447                      Arg);
2448                else
2449                   Proc := Entity (Name);
2450                end if;
2451             end;
2452          end if;
2453
2454          return Proc;
2455       end Find_Unique_Parameterless_Procedure;
2456
2457       ---------------
2458       -- Fix_Error --
2459       ---------------
2460
2461       procedure Fix_Error (Msg : in out String) is
2462       begin
2463          if From_Aspect_Specification (N) then
2464             for J in Msg'First .. Msg'Last - 5 loop
2465                if Msg (J .. J + 5) = "pragma" then
2466                   Msg (J .. J + 5) := "aspect";
2467                end if;
2468             end loop;
2469
2470             if Error_Msg_Name_1 = Name_Precondition then
2471                Error_Msg_Name_1 := Name_Pre;
2472             elsif Error_Msg_Name_1 = Name_Postcondition then
2473                Error_Msg_Name_1 := Name_Post;
2474             end if;
2475          end if;
2476       end Fix_Error;
2477
2478       -------------------------
2479       -- Gather_Associations --
2480       -------------------------
2481
2482       procedure Gather_Associations
2483         (Names : Name_List;
2484          Args  : out Args_List)
2485       is
2486          Arg : Node_Id;
2487
2488       begin
2489          --  Initialize all parameters to Empty
2490
2491          for J in Args'Range loop
2492             Args (J) := Empty;
2493          end loop;
2494
2495          --  That's all we have to do if there are no argument associations
2496
2497          if No (Pragma_Argument_Associations (N)) then
2498             return;
2499          end if;
2500
2501          --  Otherwise first deal with any positional parameters present
2502
2503          Arg := First (Pragma_Argument_Associations (N));
2504          for Index in Args'Range loop
2505             exit when No (Arg) or else Chars (Arg) /= No_Name;
2506             Args (Index) := Get_Pragma_Arg (Arg);
2507             Next (Arg);
2508          end loop;
2509
2510          --  Positional parameters all processed, if any left, then we
2511          --  have too many positional parameters.
2512
2513          if Present (Arg) and then Chars (Arg) = No_Name then
2514             Error_Pragma_Arg
2515               ("too many positional associations for pragma%", Arg);
2516          end if;
2517
2518          --  Process named parameters if any are present
2519
2520          while Present (Arg) loop
2521             if Chars (Arg) = No_Name then
2522                Error_Pragma_Arg
2523                  ("positional association cannot follow named association",
2524                   Arg);
2525
2526             else
2527                for Index in Names'Range loop
2528                   if Names (Index) = Chars (Arg) then
2529                      if Present (Args (Index)) then
2530                         Error_Pragma_Arg
2531                           ("duplicate argument association for pragma%", Arg);
2532                      else
2533                         Args (Index) := Get_Pragma_Arg (Arg);
2534                         exit;
2535                      end if;
2536                   end if;
2537
2538                   if Index = Names'Last then
2539                      Error_Msg_Name_1 := Pname;
2540                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2541
2542                      --  Check for possible misspelling
2543
2544                      for Index1 in Names'Range loop
2545                         if Is_Bad_Spelling_Of
2546                              (Chars (Arg), Names (Index1))
2547                         then
2548                            Error_Msg_Name_1 := Names (Index1);
2549                            Error_Msg_N -- CODEFIX
2550                              ("\possible misspelling of%", Arg);
2551                            exit;
2552                         end if;
2553                      end loop;
2554
2555                      raise Pragma_Exit;
2556                   end if;
2557                end loop;
2558             end if;
2559
2560             Next (Arg);
2561          end loop;
2562       end Gather_Associations;
2563
2564       -----------------
2565       -- GNAT_Pragma --
2566       -----------------
2567
2568       procedure GNAT_Pragma is
2569       begin
2570          Check_Restriction (No_Implementation_Pragmas, N);
2571       end GNAT_Pragma;
2572
2573       --------------------------
2574       -- Is_Before_First_Decl --
2575       --------------------------
2576
2577       function Is_Before_First_Decl
2578         (Pragma_Node : Node_Id;
2579          Decls       : List_Id) return Boolean
2580       is
2581          Item : Node_Id := First (Decls);
2582
2583       begin
2584          --  Only other pragmas can come before this pragma
2585
2586          loop
2587             if No (Item) or else Nkind (Item) /= N_Pragma then
2588                return False;
2589
2590             elsif Item = Pragma_Node then
2591                return True;
2592             end if;
2593
2594             Next (Item);
2595          end loop;
2596       end Is_Before_First_Decl;
2597
2598       -----------------------------
2599       -- Is_Configuration_Pragma --
2600       -----------------------------
2601
2602       --  A configuration pragma must appear in the context clause of a
2603       --  compilation unit, and only other pragmas may precede it. Note that
2604       --  the test below also permits use in a configuration pragma file.
2605
2606       function Is_Configuration_Pragma return Boolean is
2607          Lis : constant List_Id := List_Containing (N);
2608          Par : constant Node_Id := Parent (N);
2609          Prg : Node_Id;
2610
2611       begin
2612          --  If no parent, then we are in the configuration pragma file,
2613          --  so the placement is definitely appropriate.
2614
2615          if No (Par) then
2616             return True;
2617
2618          --  Otherwise we must be in the context clause of a compilation unit
2619          --  and the only thing allowed before us in the context list is more
2620          --  configuration pragmas.
2621
2622          elsif Nkind (Par) = N_Compilation_Unit
2623            and then Context_Items (Par) = Lis
2624          then
2625             Prg := First (Lis);
2626
2627             loop
2628                if Prg = N then
2629                   return True;
2630                elsif Nkind (Prg) /= N_Pragma then
2631                   return False;
2632                end if;
2633
2634                Next (Prg);
2635             end loop;
2636
2637          else
2638             return False;
2639          end if;
2640       end Is_Configuration_Pragma;
2641
2642       --------------------------
2643       -- Is_In_Context_Clause --
2644       --------------------------
2645
2646       function Is_In_Context_Clause return Boolean is
2647          Plist       : List_Id;
2648          Parent_Node : Node_Id;
2649
2650       begin
2651          if not Is_List_Member (N) then
2652             return False;
2653
2654          else
2655             Plist := List_Containing (N);
2656             Parent_Node := Parent (Plist);
2657
2658             if Parent_Node = Empty
2659               or else Nkind (Parent_Node) /= N_Compilation_Unit
2660               or else Context_Items (Parent_Node) /= Plist
2661             then
2662                return False;
2663             end if;
2664          end if;
2665
2666          return True;
2667       end Is_In_Context_Clause;
2668
2669       ---------------------------------
2670       -- Is_Static_String_Expression --
2671       ---------------------------------
2672
2673       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2674          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2675
2676       begin
2677          Analyze_And_Resolve (Argx);
2678          return Is_OK_Static_Expression (Argx)
2679            and then Nkind (Argx) = N_String_Literal;
2680       end Is_Static_String_Expression;
2681
2682       ----------------------
2683       -- Pragma_Misplaced --
2684       ----------------------
2685
2686       procedure Pragma_Misplaced is
2687       begin
2688          Error_Pragma ("incorrect placement of pragma%");
2689       end Pragma_Misplaced;
2690
2691       ------------------------------------
2692       -- Process Atomic_Shared_Volatile --
2693       ------------------------------------
2694
2695       procedure Process_Atomic_Shared_Volatile is
2696          E_Id : Node_Id;
2697          E    : Entity_Id;
2698          D    : Node_Id;
2699          K    : Node_Kind;
2700          Utyp : Entity_Id;
2701
2702          procedure Set_Atomic (E : Entity_Id);
2703          --  Set given type as atomic, and if no explicit alignment was given,
2704          --  set alignment to unknown, since back end knows what the alignment
2705          --  requirements are for atomic arrays. Note: this step is necessary
2706          --  for derived types.
2707
2708          ----------------
2709          -- Set_Atomic --
2710          ----------------
2711
2712          procedure Set_Atomic (E : Entity_Id) is
2713          begin
2714             Set_Is_Atomic (E);
2715
2716             if not Has_Alignment_Clause (E) then
2717                Set_Alignment (E, Uint_0);
2718             end if;
2719          end Set_Atomic;
2720
2721       --  Start of processing for Process_Atomic_Shared_Volatile
2722
2723       begin
2724          Check_Ada_83_Warning;
2725          Check_No_Identifiers;
2726          Check_Arg_Count (1);
2727          Check_Arg_Is_Local_Name (Arg1);
2728          E_Id := Get_Pragma_Arg (Arg1);
2729
2730          if Etype (E_Id) = Any_Type then
2731             return;
2732          end if;
2733
2734          E := Entity (E_Id);
2735          D := Declaration_Node (E);
2736          K := Nkind (D);
2737
2738          --  Check duplicate before we chain ourselves!
2739
2740          Check_Duplicate_Pragma (E);
2741
2742          --  Now check appropriateness of the entity
2743
2744          if Is_Type (E) then
2745             if Rep_Item_Too_Early (E, N)
2746                  or else
2747                Rep_Item_Too_Late (E, N)
2748             then
2749                return;
2750             else
2751                Check_First_Subtype (Arg1);
2752             end if;
2753
2754             if Prag_Id /= Pragma_Volatile then
2755                Set_Atomic (E);
2756                Set_Atomic (Underlying_Type (E));
2757                Set_Atomic (Base_Type (E));
2758             end if;
2759
2760             --  Attribute belongs on the base type. If the view of the type is
2761             --  currently private, it also belongs on the underlying type.
2762
2763             Set_Is_Volatile (Base_Type (E));
2764             Set_Is_Volatile (Underlying_Type (E));
2765
2766             Set_Treat_As_Volatile (E);
2767             Set_Treat_As_Volatile (Underlying_Type (E));
2768
2769          elsif K = N_Object_Declaration
2770            or else (K = N_Component_Declaration
2771                      and then Original_Record_Component (E) = E)
2772          then
2773             if Rep_Item_Too_Late (E, N) then
2774                return;
2775             end if;
2776
2777             if Prag_Id /= Pragma_Volatile then
2778                Set_Is_Atomic (E);
2779
2780                --  If the object declaration has an explicit initialization, a
2781                --  temporary may have to be created to hold the expression, to
2782                --  ensure that access to the object remain atomic.
2783
2784                if Nkind (Parent (E)) = N_Object_Declaration
2785                  and then Present (Expression (Parent (E)))
2786                then
2787                   Set_Has_Delayed_Freeze (E);
2788                end if;
2789
2790                --  An interesting improvement here. If an object of type X is
2791                --  declared atomic, and the type X is not atomic, that's a
2792                --  pity, since it may not have appropriate alignment etc. We
2793                --  can rescue this in the special case where the object and
2794                --  type are in the same unit by just setting the type as
2795                --  atomic, so that the back end will process it as atomic.
2796
2797                Utyp := Underlying_Type (Etype (E));
2798
2799                if Present (Utyp)
2800                  and then Sloc (E) > No_Location
2801                  and then Sloc (Utyp) > No_Location
2802                  and then
2803                    Get_Source_File_Index (Sloc (E)) =
2804                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2805                then
2806                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2807                end if;
2808             end if;
2809
2810             Set_Is_Volatile (E);
2811             Set_Treat_As_Volatile (E);
2812
2813          else
2814             Error_Pragma_Arg
2815               ("inappropriate entity for pragma%", Arg1);
2816          end if;
2817       end Process_Atomic_Shared_Volatile;
2818
2819       -------------------------------------------
2820       -- Process_Compile_Time_Warning_Or_Error --
2821       -------------------------------------------
2822
2823       procedure Process_Compile_Time_Warning_Or_Error is
2824          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2825
2826       begin
2827          Check_Arg_Count (2);
2828          Check_No_Identifiers;
2829          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2830          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2831
2832          if Compile_Time_Known_Value (Arg1x) then
2833             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2834                declare
2835                   Str   : constant String_Id :=
2836                             Strval (Get_Pragma_Arg (Arg2));
2837                   Len   : constant Int := String_Length (Str);
2838                   Cont  : Boolean;
2839                   Ptr   : Nat;
2840                   CC    : Char_Code;
2841                   C     : Character;
2842                   Cent  : constant Entity_Id :=
2843                             Cunit_Entity (Current_Sem_Unit);
2844
2845                   Force : constant Boolean :=
2846                             Prag_Id = Pragma_Compile_Time_Warning
2847                               and then
2848                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2849                               and then (Ekind (Cent) /= E_Package
2850                                           or else not In_Private_Part (Cent));
2851                   --  Set True if this is the warning case, and we are in the
2852                   --  visible part of a package spec, or in a subprogram spec,
2853                   --  in which case we want to force the client to see the
2854                   --  warning, even though it is not in the main unit.
2855
2856                begin
2857                   --  Loop through segments of message separated by line feeds.
2858                   --  We output these segments as separate messages with
2859                   --  continuation marks for all but the first.
2860
2861                   Cont := False;
2862                   Ptr := 1;
2863                   loop
2864                      Error_Msg_Strlen := 0;
2865
2866                      --  Loop to copy characters from argument to error message
2867                      --  string buffer.
2868
2869                      loop
2870                         exit when Ptr > Len;
2871                         CC := Get_String_Char (Str, Ptr);
2872                         Ptr := Ptr + 1;
2873
2874                         --  Ignore wide chars ??? else store character
2875
2876                         if In_Character_Range (CC) then
2877                            C := Get_Character (CC);
2878                            exit when C = ASCII.LF;
2879                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
2880                            Error_Msg_String (Error_Msg_Strlen) := C;
2881                         end if;
2882                      end loop;
2883
2884                      --  Here with one line ready to go
2885
2886                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2887
2888                      --  If this is a warning in a spec, then we want clients
2889                      --  to see the warning, so mark the message with the
2890                      --  special sequence !! to force the warning. In the case
2891                      --  of a package spec, we do not force this if we are in
2892                      --  the private part of the spec.
2893
2894                      if Force then
2895                         if Cont = False then
2896                            Error_Msg_N ("<~!!", Arg1);
2897                            Cont := True;
2898                         else
2899                            Error_Msg_N ("\<~!!", Arg1);
2900                         end if;
2901
2902                      --  Error, rather than warning, or in a body, so we do not
2903                      --  need to force visibility for client (error will be
2904                      --  output in any case, and this is the situation in which
2905                      --  we do not want a client to get a warning, since the
2906                      --  warning is in the body or the spec private part).
2907
2908                      else
2909                         if Cont = False then
2910                            Error_Msg_N ("<~", Arg1);
2911                            Cont := True;
2912                         else
2913                            Error_Msg_N ("\<~", Arg1);
2914                         end if;
2915                      end if;
2916
2917                      exit when Ptr > Len;
2918                   end loop;
2919                end;
2920             end if;
2921          end if;
2922       end Process_Compile_Time_Warning_Or_Error;
2923
2924       ------------------------
2925       -- Process_Convention --
2926       ------------------------
2927
2928       procedure Process_Convention
2929         (C   : out Convention_Id;
2930          Ent : out Entity_Id)
2931       is
2932          Id        : Node_Id;
2933          E         : Entity_Id;
2934          E1        : Entity_Id;
2935          Cname     : Name_Id;
2936          Comp_Unit : Unit_Number_Type;
2937
2938          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2939          --  Called if we have more than one Export/Import/Convention pragma.
2940          --  This is generally illegal, but we have a special case of allowing
2941          --  Import and Interface to coexist if they specify the convention in
2942          --  a consistent manner. We are allowed to do this, since Interface is
2943          --  an implementation defined pragma, and we choose to do it since we
2944          --  know Rational allows this combination. S is the entity id of the
2945          --  subprogram in question. This procedure also sets the special flag
2946          --  Import_Interface_Present in both pragmas in the case where we do
2947          --  have matching Import and Interface pragmas.
2948
2949          procedure Set_Convention_From_Pragma (E : Entity_Id);
2950          --  Set convention in entity E, and also flag that the entity has a
2951          --  convention pragma. If entity is for a private or incomplete type,
2952          --  also set convention and flag on underlying type. This procedure
2953          --  also deals with the special case of C_Pass_By_Copy convention.
2954
2955          -------------------------------
2956          -- Diagnose_Multiple_Pragmas --
2957          -------------------------------
2958
2959          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2960             Pdec : constant Node_Id := Declaration_Node (S);
2961             Decl : Node_Id;
2962             Err  : Boolean;
2963
2964             function Same_Convention (Decl : Node_Id) return Boolean;
2965             --  Decl is a pragma node. This function returns True if this
2966             --  pragma has a first argument that is an identifier with a
2967             --  Chars field corresponding to the Convention_Id C.
2968
2969             function Same_Name (Decl : Node_Id) return Boolean;
2970             --  Decl is a pragma node. This function returns True if this
2971             --  pragma has a second argument that is an identifier with a
2972             --  Chars field that matches the Chars of the current subprogram.
2973
2974             ---------------------
2975             -- Same_Convention --
2976             ---------------------
2977
2978             function Same_Convention (Decl : Node_Id) return Boolean is
2979                Arg1 : constant Node_Id :=
2980                         First (Pragma_Argument_Associations (Decl));
2981
2982             begin
2983                if Present (Arg1) then
2984                   declare
2985                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
2986                   begin
2987                      if Nkind (Arg) = N_Identifier
2988                        and then Is_Convention_Name (Chars (Arg))
2989                        and then Get_Convention_Id (Chars (Arg)) = C
2990                      then
2991                         return True;
2992                      end if;
2993                   end;
2994                end if;
2995
2996                return False;
2997             end Same_Convention;
2998
2999             ---------------
3000             -- Same_Name --
3001             ---------------
3002
3003             function Same_Name (Decl : Node_Id) return Boolean is
3004                Arg1 : constant Node_Id :=
3005                         First (Pragma_Argument_Associations (Decl));
3006                Arg2 : Node_Id;
3007
3008             begin
3009                if No (Arg1) then
3010                   return False;
3011                end if;
3012
3013                Arg2 := Next (Arg1);
3014
3015                if No (Arg2) then
3016                   return False;
3017                end if;
3018
3019                declare
3020                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3021                begin
3022                   if Nkind (Arg) = N_Identifier
3023                     and then Chars (Arg) = Chars (S)
3024                   then
3025                      return True;
3026                   end if;
3027                end;
3028
3029                return False;
3030             end Same_Name;
3031
3032          --  Start of processing for Diagnose_Multiple_Pragmas
3033
3034          begin
3035             Err := True;
3036
3037             --  Definitely give message if we have Convention/Export here
3038
3039             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3040                null;
3041
3042                --  If we have an Import or Export, scan back from pragma to
3043                --  find any previous pragma applying to the same procedure.
3044                --  The scan will be terminated by the start of the list, or
3045                --  hitting the subprogram declaration. This won't allow one
3046                --  pragma to appear in the public part and one in the private
3047                --  part, but that seems very unlikely in practice.
3048
3049             else
3050                Decl := Prev (N);
3051                while Present (Decl) and then Decl /= Pdec loop
3052
3053                   --  Look for pragma with same name as us
3054
3055                   if Nkind (Decl) = N_Pragma
3056                     and then Same_Name (Decl)
3057                   then
3058                      --  Give error if same as our pragma or Export/Convention
3059
3060                      if Pragma_Name (Decl) = Name_Export
3061                           or else
3062                         Pragma_Name (Decl) = Name_Convention
3063                           or else
3064                         Pragma_Name (Decl) = Pragma_Name (N)
3065                      then
3066                         exit;
3067
3068                      --  Case of Import/Interface or the other way round
3069
3070                      elsif Pragma_Name (Decl) = Name_Interface
3071                              or else
3072                            Pragma_Name (Decl) = Name_Import
3073                      then
3074                         --  Here we know that we have Import and Interface. It
3075                         --  doesn't matter which way round they are. See if
3076                         --  they specify the same convention. If so, all OK,
3077                         --  and set special flags to stop other messages
3078
3079                         if Same_Convention (Decl) then
3080                            Set_Import_Interface_Present (N);
3081                            Set_Import_Interface_Present (Decl);
3082                            Err := False;
3083
3084                         --  If different conventions, special message
3085
3086                         else
3087                            Error_Msg_Sloc := Sloc (Decl);
3088                            Error_Pragma_Arg
3089                              ("convention differs from that given#", Arg1);
3090                            return;
3091                         end if;
3092                      end if;
3093                   end if;
3094
3095                   Next (Decl);
3096                end loop;
3097             end if;
3098
3099             --  Give message if needed if we fall through those tests
3100
3101             if Err then
3102                Error_Pragma_Arg
3103                  ("at most one Convention/Export/Import pragma is allowed",
3104                   Arg2);
3105             end if;
3106          end Diagnose_Multiple_Pragmas;
3107
3108          --------------------------------
3109          -- Set_Convention_From_Pragma --
3110          --------------------------------
3111
3112          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3113          begin
3114             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3115             --  for an overridden dispatching operation. Technically this is
3116             --  an amendment and should only be done in Ada 2005 mode. However,
3117             --  this is clearly a mistake, since the problem that is addressed
3118             --  by this AI is that there is a clear gap in the RM!
3119
3120             if Is_Dispatching_Operation (E)
3121               and then Present (Overridden_Operation (E))
3122               and then C /= Convention (Overridden_Operation (E))
3123             then
3124                Error_Pragma_Arg
3125                  ("cannot change convention for " &
3126                   "overridden dispatching operation",
3127                   Arg1);
3128             end if;
3129
3130             --  Set the convention
3131
3132             Set_Convention (E, C);
3133             Set_Has_Convention_Pragma (E);
3134
3135             if Is_Incomplete_Or_Private_Type (E)
3136               and then Present (Underlying_Type (E))
3137             then
3138                Set_Convention            (Underlying_Type (E), C);
3139                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3140             end if;
3141
3142             --  A class-wide type should inherit the convention of the specific
3143             --  root type (although this isn't specified clearly by the RM).
3144
3145             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3146                Set_Convention (Class_Wide_Type (E), C);
3147             end if;
3148
3149             --  If the entity is a record type, then check for special case of
3150             --  C_Pass_By_Copy, which is treated the same as C except that the
3151             --  special record flag is set. This convention is only permitted
3152             --  on record types (see AI95-00131).
3153
3154             if Cname = Name_C_Pass_By_Copy then
3155                if Is_Record_Type (E) then
3156                   Set_C_Pass_By_Copy (Base_Type (E));
3157                elsif Is_Incomplete_Or_Private_Type (E)
3158                  and then Is_Record_Type (Underlying_Type (E))
3159                then
3160                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3161                else
3162                   Error_Pragma_Arg
3163                     ("C_Pass_By_Copy convention allowed only for record type",
3164                      Arg2);
3165                end if;
3166             end if;
3167
3168             --  If the entity is a derived boolean type, check for the special
3169             --  case of convention C, C++, or Fortran, where we consider any
3170             --  nonzero value to represent true.
3171
3172             if Is_Discrete_Type (E)
3173               and then Root_Type (Etype (E)) = Standard_Boolean
3174               and then
3175                 (C = Convention_C
3176                    or else
3177                  C = Convention_CPP
3178                    or else
3179                  C = Convention_Fortran)
3180             then
3181                Set_Nonzero_Is_True (Base_Type (E));
3182             end if;
3183          end Set_Convention_From_Pragma;
3184
3185       --  Start of processing for Process_Convention
3186
3187       begin
3188          Check_At_Least_N_Arguments (2);
3189          Check_Optional_Identifier (Arg1, Name_Convention);
3190          Check_Arg_Is_Identifier (Arg1);
3191          Cname := Chars (Get_Pragma_Arg (Arg1));
3192
3193          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3194          --  tested again below to set the critical flag).
3195
3196          if Cname = Name_C_Pass_By_Copy then
3197             C := Convention_C;
3198
3199          --  Otherwise we must have something in the standard convention list
3200
3201          elsif Is_Convention_Name (Cname) then
3202             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3203
3204          --  In DEC VMS, it seems that there is an undocumented feature that
3205          --  any unrecognized convention is treated as the default, which for
3206          --  us is convention C. It does not seem so terrible to do this
3207          --  unconditionally, silently in the VMS case, and with a warning
3208          --  in the non-VMS case.
3209
3210          else
3211             if Warn_On_Export_Import and not OpenVMS_On_Target then
3212                Error_Msg_N
3213                  ("?unrecognized convention name, C assumed",
3214                   Get_Pragma_Arg (Arg1));
3215             end if;
3216
3217             C := Convention_C;
3218          end if;
3219
3220          Check_Optional_Identifier (Arg2, Name_Entity);
3221          Check_Arg_Is_Local_Name (Arg2);
3222
3223          Id := Get_Pragma_Arg (Arg2);
3224          Analyze (Id);
3225
3226          if not Is_Entity_Name (Id) then
3227             Error_Pragma_Arg ("entity name required", Arg2);
3228          end if;
3229
3230          E := Entity (Id);
3231
3232          --  Set entity to return
3233
3234          Ent := E;
3235
3236          --  Ada_Pass_By_Copy special checking
3237
3238          if C = Convention_Ada_Pass_By_Copy then
3239             if not Is_First_Subtype (E) then
3240                Error_Pragma_Arg
3241                  ("convention `Ada_Pass_By_Copy` only "
3242                   & "allowed for types", Arg2);
3243             end if;
3244
3245             if Is_By_Reference_Type (E) then
3246                Error_Pragma_Arg
3247                  ("convention `Ada_Pass_By_Copy` not allowed for "
3248                   & "by-reference type", Arg1);
3249             end if;
3250          end if;
3251
3252          --  Ada_Pass_By_Reference special checking
3253
3254          if C = Convention_Ada_Pass_By_Reference then
3255             if not Is_First_Subtype (E) then
3256                Error_Pragma_Arg
3257                  ("convention `Ada_Pass_By_Reference` only "
3258                   & "allowed for types", Arg2);
3259             end if;
3260
3261             if Is_By_Copy_Type (E) then
3262                Error_Pragma_Arg
3263                  ("convention `Ada_Pass_By_Reference` not allowed for "
3264                   & "by-copy type", Arg1);
3265             end if;
3266          end if;
3267
3268          --  Go to renamed subprogram if present, since convention applies to
3269          --  the actual renamed entity, not to the renaming entity. If the
3270          --  subprogram is inherited, go to parent subprogram.
3271
3272          if Is_Subprogram (E)
3273            and then Present (Alias (E))
3274          then
3275             if Nkind (Parent (Declaration_Node (E))) =
3276                                        N_Subprogram_Renaming_Declaration
3277             then
3278                if Scope (E) /= Scope (Alias (E)) then
3279                   Error_Pragma_Ref
3280                     ("cannot apply pragma% to non-local entity&#", E);
3281                end if;
3282
3283                E := Alias (E);
3284
3285             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3286                                         N_Private_Extension_Declaration)
3287               and then Scope (E) = Scope (Alias (E))
3288             then
3289                E := Alias (E);
3290
3291                --  Return the parent subprogram the entity was inherited from
3292
3293                Ent := E;
3294             end if;
3295          end if;
3296
3297          --  Check that we are not applying this to a specless body
3298
3299          if Is_Subprogram (E)
3300            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3301          then
3302             Error_Pragma
3303               ("pragma% requires separate spec and must come before body");
3304          end if;
3305
3306          --  Check that we are not applying this to a named constant
3307
3308          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3309             Error_Msg_Name_1 := Pname;
3310             Error_Msg_N
3311               ("cannot apply pragma% to named constant!",
3312                Get_Pragma_Arg (Arg2));
3313             Error_Pragma_Arg
3314               ("\supply appropriate type for&!", Arg2);
3315          end if;
3316
3317          if Ekind (E) = E_Enumeration_Literal then
3318             Error_Pragma ("enumeration literal not allowed for pragma%");
3319          end if;
3320
3321          --  Check for rep item appearing too early or too late
3322
3323          if Etype (E) = Any_Type
3324            or else Rep_Item_Too_Early (E, N)
3325          then
3326             raise Pragma_Exit;
3327
3328          elsif Present (Underlying_Type (E)) then
3329             E := Underlying_Type (E);
3330          end if;
3331
3332          if Rep_Item_Too_Late (E, N) then
3333             raise Pragma_Exit;
3334          end if;
3335
3336          if Has_Convention_Pragma (E) then
3337             Diagnose_Multiple_Pragmas (E);
3338
3339          elsif Convention (E) = Convention_Protected
3340            or else Ekind (Scope (E)) = E_Protected_Type
3341          then
3342             Error_Pragma_Arg
3343               ("a protected operation cannot be given a different convention",
3344                 Arg2);
3345          end if;
3346
3347          --  For Intrinsic, a subprogram is required
3348
3349          if C = Convention_Intrinsic
3350            and then not Is_Subprogram (E)
3351            and then not Is_Generic_Subprogram (E)
3352          then
3353             Error_Pragma_Arg
3354               ("second argument of pragma% must be a subprogram", Arg2);
3355          end if;
3356
3357          --  For Stdcall, a subprogram, variable or subprogram type is required
3358
3359          if C = Convention_Stdcall
3360            and then not Is_Subprogram (E)
3361            and then not Is_Generic_Subprogram (E)
3362            and then Ekind (E) /= E_Variable
3363            and then not
3364              (Is_Access_Type (E)
3365                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3366          then
3367             Error_Pragma_Arg
3368               ("second argument of pragma% must be subprogram (type)",
3369                Arg2);
3370          end if;
3371
3372          if not Is_Subprogram (E)
3373            and then not Is_Generic_Subprogram (E)
3374          then
3375             Set_Convention_From_Pragma (E);
3376
3377             if Is_Type (E) then
3378                Check_First_Subtype (Arg2);
3379                Set_Convention_From_Pragma (Base_Type (E));
3380
3381                --  For subprograms, we must set the convention on the
3382                --  internally generated directly designated type as well.
3383
3384                if Ekind (E) = E_Access_Subprogram_Type then
3385                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3386                end if;
3387             end if;
3388
3389          --  For the subprogram case, set proper convention for all homonyms
3390          --  in same scope and the same declarative part, i.e. the same
3391          --  compilation unit.
3392
3393          else
3394             Comp_Unit := Get_Source_Unit (E);
3395             Set_Convention_From_Pragma (E);
3396
3397             --  Treat a pragma Import as an implicit body, for GPS use
3398
3399             if Prag_Id = Pragma_Import then
3400                Generate_Reference (E, Id, 'b');
3401             end if;
3402
3403             --  Loop through the homonyms of the pragma argument's entity
3404
3405             E1 := Ent;
3406             loop
3407                E1 := Homonym (E1);
3408                exit when No (E1) or else Scope (E1) /= Current_Scope;
3409
3410                --  Do not set the pragma on inherited operations or on formal
3411                --  subprograms.
3412
3413                if Comes_From_Source (E1)
3414                  and then Comp_Unit = Get_Source_Unit (E1)
3415                  and then not Is_Formal_Subprogram (E1)
3416                  and then Nkind (Original_Node (Parent (E1))) /=
3417                                                     N_Full_Type_Declaration
3418                then
3419                   if Present (Alias (E1))
3420                     and then Scope (E1) /= Scope (Alias (E1))
3421                   then
3422                      Error_Pragma_Ref
3423                        ("cannot apply pragma% to non-local entity& declared#",
3424                         E1);
3425                   end if;
3426
3427                   Set_Convention_From_Pragma (E1);
3428
3429                   if Prag_Id = Pragma_Import then
3430                      Generate_Reference (E1, Id, 'b');
3431                   end if;
3432                end if;
3433
3434                --  For aspect case, do NOT apply to homonyms
3435
3436                exit when From_Aspect_Specification (N);
3437             end loop;
3438          end if;
3439       end Process_Convention;
3440
3441       -----------------------------------------------------
3442       -- Process_Extended_Import_Export_Exception_Pragma --
3443       -----------------------------------------------------
3444
3445       procedure Process_Extended_Import_Export_Exception_Pragma
3446         (Arg_Internal : Node_Id;
3447          Arg_External : Node_Id;
3448          Arg_Form     : Node_Id;
3449          Arg_Code     : Node_Id)
3450       is
3451          Def_Id   : Entity_Id;
3452          Code_Val : Uint;
3453
3454       begin
3455          if not OpenVMS_On_Target then
3456             Error_Pragma
3457               ("?pragma% ignored (applies only to Open'V'M'S)");
3458          end if;
3459
3460          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3461          Def_Id := Entity (Arg_Internal);
3462
3463          if Ekind (Def_Id) /= E_Exception then
3464             Error_Pragma_Arg
3465               ("pragma% must refer to declared exception", Arg_Internal);
3466          end if;
3467
3468          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3469
3470          if Present (Arg_Form) then
3471             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3472          end if;
3473
3474          if Present (Arg_Form)
3475            and then Chars (Arg_Form) = Name_Ada
3476          then
3477             null;
3478          else
3479             Set_Is_VMS_Exception (Def_Id);
3480             Set_Exception_Code (Def_Id, No_Uint);
3481          end if;
3482
3483          if Present (Arg_Code) then
3484             if not Is_VMS_Exception (Def_Id) then
3485                Error_Pragma_Arg
3486                  ("Code option for pragma% not allowed for Ada case",
3487                   Arg_Code);
3488             end if;
3489
3490             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3491             Code_Val := Expr_Value (Arg_Code);
3492
3493             if not UI_Is_In_Int_Range (Code_Val) then
3494                Error_Pragma_Arg
3495                  ("Code option for pragma% must be in 32-bit range",
3496                   Arg_Code);
3497
3498             else
3499                Set_Exception_Code (Def_Id, Code_Val);
3500             end if;
3501          end if;
3502       end Process_Extended_Import_Export_Exception_Pragma;
3503
3504       -------------------------------------------------
3505       -- Process_Extended_Import_Export_Internal_Arg --
3506       -------------------------------------------------
3507
3508       procedure Process_Extended_Import_Export_Internal_Arg
3509         (Arg_Internal : Node_Id := Empty)
3510       is
3511       begin
3512          if No (Arg_Internal) then
3513             Error_Pragma ("Internal parameter required for pragma%");
3514          end if;
3515
3516          if Nkind (Arg_Internal) = N_Identifier then
3517             null;
3518
3519          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3520            and then (Prag_Id = Pragma_Import_Function
3521                        or else
3522                      Prag_Id = Pragma_Export_Function)
3523          then
3524             null;
3525
3526          else
3527             Error_Pragma_Arg
3528               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3529          end if;
3530
3531          Check_Arg_Is_Local_Name (Arg_Internal);
3532       end Process_Extended_Import_Export_Internal_Arg;
3533
3534       --------------------------------------------------
3535       -- Process_Extended_Import_Export_Object_Pragma --
3536       --------------------------------------------------
3537
3538       procedure Process_Extended_Import_Export_Object_Pragma
3539         (Arg_Internal : Node_Id;
3540          Arg_External : Node_Id;
3541          Arg_Size     : Node_Id)
3542       is
3543          Def_Id : Entity_Id;
3544
3545       begin
3546          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3547          Def_Id := Entity (Arg_Internal);
3548
3549          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3550             Error_Pragma_Arg
3551               ("pragma% must designate an object", Arg_Internal);
3552          end if;
3553
3554          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3555               or else
3556             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3557          then
3558             Error_Pragma_Arg
3559               ("previous Common/Psect_Object applies, pragma % not permitted",
3560                Arg_Internal);
3561          end if;
3562
3563          if Rep_Item_Too_Late (Def_Id, N) then
3564             raise Pragma_Exit;
3565          end if;
3566
3567          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3568
3569          if Present (Arg_Size) then
3570             Check_Arg_Is_External_Name (Arg_Size);
3571          end if;
3572
3573          --  Export_Object case
3574
3575          if Prag_Id = Pragma_Export_Object then
3576             if not Is_Library_Level_Entity (Def_Id) then
3577                Error_Pragma_Arg
3578                  ("argument for pragma% must be library level entity",
3579                   Arg_Internal);
3580             end if;
3581
3582             if Ekind (Current_Scope) = E_Generic_Package then
3583                Error_Pragma ("pragma& cannot appear in a generic unit");
3584             end if;
3585
3586             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3587                Error_Pragma_Arg
3588                  ("exported object must have compile time known size",
3589                   Arg_Internal);
3590             end if;
3591
3592             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3593                Error_Msg_N ("?duplicate Export_Object pragma", N);
3594             else
3595                Set_Exported (Def_Id, Arg_Internal);
3596             end if;
3597
3598          --  Import_Object case
3599
3600          else
3601             if Is_Concurrent_Type (Etype (Def_Id)) then
3602                Error_Pragma_Arg
3603                  ("cannot use pragma% for task/protected object",
3604                   Arg_Internal);
3605             end if;
3606
3607             if Ekind (Def_Id) = E_Constant then
3608                Error_Pragma_Arg
3609                  ("cannot import a constant", Arg_Internal);
3610             end if;
3611
3612             if Warn_On_Export_Import
3613               and then Has_Discriminants (Etype (Def_Id))
3614             then
3615                Error_Msg_N
3616                  ("imported value must be initialized?", Arg_Internal);
3617             end if;
3618
3619             if Warn_On_Export_Import
3620               and then Is_Access_Type (Etype (Def_Id))
3621             then
3622                Error_Pragma_Arg
3623                  ("cannot import object of an access type?", Arg_Internal);
3624             end if;
3625
3626             if Warn_On_Export_Import
3627               and then Is_Imported (Def_Id)
3628             then
3629                Error_Msg_N
3630                  ("?duplicate Import_Object pragma", N);
3631
3632             --  Check for explicit initialization present. Note that an
3633             --  initialization generated by the code generator, e.g. for an
3634             --  access type, does not count here.
3635
3636             elsif Present (Expression (Parent (Def_Id)))
3637                and then
3638                  Comes_From_Source
3639                    (Original_Node (Expression (Parent (Def_Id))))
3640             then
3641                Error_Msg_Sloc := Sloc (Def_Id);
3642                Error_Pragma_Arg
3643                  ("imported entities cannot be initialized (RM B.1(24))",
3644                   "\no initialization allowed for & declared#", Arg1);
3645             else
3646                Set_Imported (Def_Id);
3647                Note_Possible_Modification (Arg_Internal, Sure => False);
3648             end if;
3649          end if;
3650       end Process_Extended_Import_Export_Object_Pragma;
3651
3652       ------------------------------------------------------
3653       -- Process_Extended_Import_Export_Subprogram_Pragma --
3654       ------------------------------------------------------
3655
3656       procedure Process_Extended_Import_Export_Subprogram_Pragma
3657         (Arg_Internal                 : Node_Id;
3658          Arg_External                 : Node_Id;
3659          Arg_Parameter_Types          : Node_Id;
3660          Arg_Result_Type              : Node_Id := Empty;
3661          Arg_Mechanism                : Node_Id;
3662          Arg_Result_Mechanism         : Node_Id := Empty;
3663          Arg_First_Optional_Parameter : Node_Id := Empty)
3664       is
3665          Ent       : Entity_Id;
3666          Def_Id    : Entity_Id;
3667          Hom_Id    : Entity_Id;
3668          Formal    : Entity_Id;
3669          Ambiguous : Boolean;
3670          Match     : Boolean;
3671          Dval      : Node_Id;
3672
3673          function Same_Base_Type
3674           (Ptype  : Node_Id;
3675            Formal : Entity_Id) return Boolean;
3676          --  Determines if Ptype references the type of Formal. Note that only
3677          --  the base types need to match according to the spec. Ptype here is
3678          --  the argument from the pragma, which is either a type name, or an
3679          --  access attribute.
3680
3681          --------------------
3682          -- Same_Base_Type --
3683          --------------------
3684
3685          function Same_Base_Type
3686            (Ptype  : Node_Id;
3687             Formal : Entity_Id) return Boolean
3688          is
3689             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3690             Pref : Node_Id;
3691
3692          begin
3693             --  Case where pragma argument is typ'Access
3694
3695             if Nkind (Ptype) = N_Attribute_Reference
3696               and then Attribute_Name (Ptype) = Name_Access
3697             then
3698                Pref := Prefix (Ptype);
3699                Find_Type (Pref);
3700
3701                if not Is_Entity_Name (Pref)
3702                  or else Entity (Pref) = Any_Type
3703                then
3704                   raise Pragma_Exit;
3705                end if;
3706
3707                --  We have a match if the corresponding argument is of an
3708                --  anonymous access type, and its designated type matches the
3709                --  type of the prefix of the access attribute
3710
3711                return Ekind (Ftyp) = E_Anonymous_Access_Type
3712                  and then Base_Type (Entity (Pref)) =
3713                             Base_Type (Etype (Designated_Type (Ftyp)));
3714
3715             --  Case where pragma argument is a type name
3716
3717             else
3718                Find_Type (Ptype);
3719
3720                if not Is_Entity_Name (Ptype)
3721                  or else Entity (Ptype) = Any_Type
3722                then
3723                   raise Pragma_Exit;
3724                end if;
3725
3726                --  We have a match if the corresponding argument is of the type
3727                --  given in the pragma (comparing base types)
3728
3729                return Base_Type (Entity (Ptype)) = Ftyp;
3730             end if;
3731          end Same_Base_Type;
3732
3733       --  Start of processing for
3734       --  Process_Extended_Import_Export_Subprogram_Pragma
3735
3736       begin
3737          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3738          Ent := Empty;
3739          Ambiguous := False;
3740
3741          --  Loop through homonyms (overloadings) of the entity
3742
3743          Hom_Id := Entity (Arg_Internal);
3744          while Present (Hom_Id) loop
3745             Def_Id := Get_Base_Subprogram (Hom_Id);
3746
3747             --  We need a subprogram in the current scope
3748
3749             if not Is_Subprogram (Def_Id)
3750               or else Scope (Def_Id) /= Current_Scope
3751             then
3752                null;
3753
3754             else
3755                Match := True;
3756
3757                --  Pragma cannot apply to subprogram body
3758
3759                if Is_Subprogram (Def_Id)
3760                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3761                                                              N_Subprogram_Body
3762                then
3763                   Error_Pragma
3764                     ("pragma% requires separate spec"
3765                       & " and must come before body");
3766                end if;
3767
3768                --  Test result type if given, note that the result type
3769                --  parameter can only be present for the function cases.
3770
3771                if Present (Arg_Result_Type)
3772                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3773                then
3774                   Match := False;
3775
3776                elsif Etype (Def_Id) /= Standard_Void_Type
3777                  and then
3778                    (Pname = Name_Export_Procedure
3779                       or else
3780                     Pname = Name_Import_Procedure)
3781                then
3782                   Match := False;
3783
3784                --  Test parameter types if given. Note that this parameter
3785                --  has not been analyzed (and must not be, since it is
3786                --  semantic nonsense), so we get it as the parser left it.
3787
3788                elsif Present (Arg_Parameter_Types) then
3789                   Check_Matching_Types : declare
3790                      Formal : Entity_Id;
3791                      Ptype  : Node_Id;
3792
3793                   begin
3794                      Formal := First_Formal (Def_Id);
3795
3796                      if Nkind (Arg_Parameter_Types) = N_Null then
3797                         if Present (Formal) then
3798                            Match := False;
3799                         end if;
3800
3801                      --  A list of one type, e.g. (List) is parsed as
3802                      --  a parenthesized expression.
3803
3804                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3805                        and then Paren_Count (Arg_Parameter_Types) = 1
3806                      then
3807                         if No (Formal)
3808                           or else Present (Next_Formal (Formal))
3809                         then
3810                            Match := False;
3811                         else
3812                            Match :=
3813                              Same_Base_Type (Arg_Parameter_Types, Formal);
3814                         end if;
3815
3816                      --  A list of more than one type is parsed as a aggregate
3817
3818                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3819                        and then Paren_Count (Arg_Parameter_Types) = 0
3820                      then
3821                         Ptype := First (Expressions (Arg_Parameter_Types));
3822                         while Present (Ptype) or else Present (Formal) loop
3823                            if No (Ptype)
3824                              or else No (Formal)
3825                              or else not Same_Base_Type (Ptype, Formal)
3826                            then
3827                               Match := False;
3828                               exit;
3829                            else
3830                               Next_Formal (Formal);
3831                               Next (Ptype);
3832                            end if;
3833                         end loop;
3834
3835                      --  Anything else is of the wrong form
3836
3837                      else
3838                         Error_Pragma_Arg
3839                           ("wrong form for Parameter_Types parameter",
3840                            Arg_Parameter_Types);
3841                      end if;
3842                   end Check_Matching_Types;
3843                end if;
3844
3845                --  Match is now False if the entry we found did not match
3846                --  either a supplied Parameter_Types or Result_Types argument
3847
3848                if Match then
3849                   if No (Ent) then
3850                      Ent := Def_Id;
3851
3852                   --  Ambiguous case, the flag Ambiguous shows if we already
3853                   --  detected this and output the initial messages.
3854
3855                   else
3856                      if not Ambiguous then
3857                         Ambiguous := True;
3858                         Error_Msg_Name_1 := Pname;
3859                         Error_Msg_N
3860                           ("pragma% does not uniquely identify subprogram!",
3861                            N);
3862                         Error_Msg_Sloc := Sloc (Ent);
3863                         Error_Msg_N ("matching subprogram #!", N);
3864                         Ent := Empty;
3865                      end if;
3866
3867                      Error_Msg_Sloc := Sloc (Def_Id);
3868                      Error_Msg_N ("matching subprogram #!", N);
3869                   end if;
3870                end if;
3871             end if;
3872
3873             Hom_Id := Homonym (Hom_Id);
3874          end loop;
3875
3876          --  See if we found an entry
3877
3878          if No (Ent) then
3879             if not Ambiguous then
3880                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3881                   Error_Pragma
3882                     ("pragma% cannot be given for generic subprogram");
3883                else
3884                   Error_Pragma
3885                     ("pragma% does not identify local subprogram");
3886                end if;
3887             end if;
3888
3889             return;
3890          end if;
3891
3892          --  Import pragmas must be for imported entities
3893
3894          if Prag_Id = Pragma_Import_Function
3895               or else
3896             Prag_Id = Pragma_Import_Procedure
3897               or else
3898             Prag_Id = Pragma_Import_Valued_Procedure
3899          then
3900             if not Is_Imported (Ent) then
3901                Error_Pragma
3902                  ("pragma Import or Interface must precede pragma%");
3903             end if;
3904
3905          --  Here we have the Export case which can set the entity as exported
3906
3907          --  But does not do so if the specified external name is null, since
3908          --  that is taken as a signal in DEC Ada 83 (with which we want to be
3909          --  compatible) to request no external name.
3910
3911          elsif Nkind (Arg_External) = N_String_Literal
3912            and then String_Length (Strval (Arg_External)) = 0
3913          then
3914             null;
3915
3916          --  In all other cases, set entity as exported
3917
3918          else
3919             Set_Exported (Ent, Arg_Internal);
3920          end if;
3921
3922          --  Special processing for Valued_Procedure cases
3923
3924          if Prag_Id = Pragma_Import_Valued_Procedure
3925            or else
3926             Prag_Id = Pragma_Export_Valued_Procedure
3927          then
3928             Formal := First_Formal (Ent);
3929
3930             if No (Formal) then
3931                Error_Pragma ("at least one parameter required for pragma%");
3932
3933             elsif Ekind (Formal) /= E_Out_Parameter then
3934                Error_Pragma ("first parameter must have mode out for pragma%");
3935
3936             else
3937                Set_Is_Valued_Procedure (Ent);
3938             end if;
3939          end if;
3940
3941          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3942
3943          --  Process Result_Mechanism argument if present. We have already
3944          --  checked that this is only allowed for the function case.
3945
3946          if Present (Arg_Result_Mechanism) then
3947             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3948          end if;
3949
3950          --  Process Mechanism parameter if present. Note that this parameter
3951          --  is not analyzed, and must not be analyzed since it is semantic
3952          --  nonsense, so we get it in exactly as the parser left it.
3953
3954          if Present (Arg_Mechanism) then
3955             declare
3956                Formal : Entity_Id;
3957                Massoc : Node_Id;
3958                Mname  : Node_Id;
3959                Choice : Node_Id;
3960
3961             begin
3962                --  A single mechanism association without a formal parameter
3963                --  name is parsed as a parenthesized expression. All other
3964                --  cases are parsed as aggregates, so we rewrite the single
3965                --  parameter case as an aggregate for consistency.
3966
3967                if Nkind (Arg_Mechanism) /= N_Aggregate
3968                  and then Paren_Count (Arg_Mechanism) = 1
3969                then
3970                   Rewrite (Arg_Mechanism,
3971                     Make_Aggregate (Sloc (Arg_Mechanism),
3972                       Expressions => New_List (
3973                         Relocate_Node (Arg_Mechanism))));
3974                end if;
3975
3976                --  Case of only mechanism name given, applies to all formals
3977
3978                if Nkind (Arg_Mechanism) /= N_Aggregate then
3979                   Formal := First_Formal (Ent);
3980                   while Present (Formal) loop
3981                      Set_Mechanism_Value (Formal, Arg_Mechanism);
3982                      Next_Formal (Formal);
3983                   end loop;
3984
3985                --  Case of list of mechanism associations given
3986
3987                else
3988                   if Null_Record_Present (Arg_Mechanism) then
3989                      Error_Pragma_Arg
3990                        ("inappropriate form for Mechanism parameter",
3991                         Arg_Mechanism);
3992                   end if;
3993
3994                   --  Deal with positional ones first
3995
3996                   Formal := First_Formal (Ent);
3997
3998                   if Present (Expressions (Arg_Mechanism)) then
3999                      Mname := First (Expressions (Arg_Mechanism));
4000                      while Present (Mname) loop
4001                         if No (Formal) then
4002                            Error_Pragma_Arg
4003                              ("too many mechanism associations", Mname);
4004                         end if;
4005
4006                         Set_Mechanism_Value (Formal, Mname);
4007                         Next_Formal (Formal);
4008                         Next (Mname);
4009                      end loop;
4010                   end if;
4011
4012                   --  Deal with named entries
4013
4014                   if Present (Component_Associations (Arg_Mechanism)) then
4015                      Massoc := First (Component_Associations (Arg_Mechanism));
4016                      while Present (Massoc) loop
4017                         Choice := First (Choices (Massoc));
4018
4019                         if Nkind (Choice) /= N_Identifier
4020                           or else Present (Next (Choice))
4021                         then
4022                            Error_Pragma_Arg
4023                              ("incorrect form for mechanism association",
4024                               Massoc);
4025                         end if;
4026
4027                         Formal := First_Formal (Ent);
4028                         loop
4029                            if No (Formal) then
4030                               Error_Pragma_Arg
4031                                 ("parameter name & not present", Choice);
4032                            end if;
4033
4034                            if Chars (Choice) = Chars (Formal) then
4035                               Set_Mechanism_Value
4036                                 (Formal, Expression (Massoc));
4037
4038                               --  Set entity on identifier (needed by ASIS)
4039
4040                               Set_Entity (Choice, Formal);
4041
4042                               exit;
4043                            end if;
4044
4045                            Next_Formal (Formal);
4046                         end loop;
4047
4048                         Next (Massoc);
4049                      end loop;
4050                   end if;
4051                end if;
4052             end;
4053          end if;
4054
4055          --  Process First_Optional_Parameter argument if present. We have
4056          --  already checked that this is only allowed for the Import case.
4057
4058          if Present (Arg_First_Optional_Parameter) then
4059             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4060                Error_Pragma_Arg
4061                  ("first optional parameter must be formal parameter name",
4062                   Arg_First_Optional_Parameter);
4063             end if;
4064
4065             Formal := First_Formal (Ent);
4066             loop
4067                if No (Formal) then
4068                   Error_Pragma_Arg
4069                     ("specified formal parameter& not found",
4070                      Arg_First_Optional_Parameter);
4071                end if;
4072
4073                exit when Chars (Formal) =
4074                          Chars (Arg_First_Optional_Parameter);
4075
4076                Next_Formal (Formal);
4077             end loop;
4078
4079             Set_First_Optional_Parameter (Ent, Formal);
4080
4081             --  Check specified and all remaining formals have right form
4082
4083             while Present (Formal) loop
4084                if Ekind (Formal) /= E_In_Parameter then
4085                   Error_Msg_NE
4086                     ("optional formal& is not of mode in!",
4087                      Arg_First_Optional_Parameter, Formal);
4088
4089                else
4090                   Dval := Default_Value (Formal);
4091
4092                   if No (Dval) then
4093                      Error_Msg_NE
4094                        ("optional formal& does not have default value!",
4095                         Arg_First_Optional_Parameter, Formal);
4096
4097                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4098                      null;
4099
4100                   else
4101                      Error_Msg_FE
4102                        ("default value for optional formal& is non-static!",
4103                         Arg_First_Optional_Parameter, Formal);
4104                   end if;
4105                end if;
4106
4107                Set_Is_Optional_Parameter (Formal);
4108                Next_Formal (Formal);
4109             end loop;
4110          end if;
4111       end Process_Extended_Import_Export_Subprogram_Pragma;
4112
4113       --------------------------
4114       -- Process_Generic_List --
4115       --------------------------
4116
4117       procedure Process_Generic_List is
4118          Arg : Node_Id;
4119          Exp : Node_Id;
4120
4121       begin
4122          Check_No_Identifiers;
4123          Check_At_Least_N_Arguments (1);
4124
4125          Arg := Arg1;
4126          while Present (Arg) loop
4127             Exp := Get_Pragma_Arg (Arg);
4128             Analyze (Exp);
4129
4130             if not Is_Entity_Name (Exp)
4131               or else
4132                 (not Is_Generic_Instance (Entity (Exp))
4133                   and then
4134                  not Is_Generic_Unit (Entity (Exp)))
4135             then
4136                Error_Pragma_Arg
4137                  ("pragma% argument must be name of generic unit/instance",
4138                   Arg);
4139             end if;
4140
4141             Next (Arg);
4142          end loop;
4143       end Process_Generic_List;
4144
4145       ------------------------------------
4146       -- Process_Import_Predefined_Type --
4147       ------------------------------------
4148
4149       procedure Process_Import_Predefined_Type is
4150          Loc  : constant Source_Ptr := Sloc (N);
4151          Elmt : Elmt_Id;
4152          Ftyp : Node_Id := Empty;
4153          Decl : Node_Id;
4154          Def  : Node_Id;
4155          Nam  : Name_Id;
4156
4157       begin
4158          String_To_Name_Buffer (Strval (Expression (Arg3)));
4159          Nam := Name_Find;
4160
4161          Elmt := First_Elmt (Predefined_Float_Types);
4162          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4163             Next_Elmt (Elmt);
4164          end loop;
4165
4166          Ftyp := Node (Elmt);
4167
4168          if Present (Ftyp) then
4169
4170             --  Don't build a derived type declaration, because predefined C
4171             --  types have no declaration anywhere, so cannot really be named.
4172             --  Instead build a full type declaration, starting with an
4173             --  appropriate type definition is built
4174
4175             if Is_Floating_Point_Type (Ftyp) then
4176                Def := Make_Floating_Point_Definition (Loc,
4177                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4178                  Make_Real_Range_Specification (Loc,
4179                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4180                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4181
4182             --  Should never have a predefined type we cannot handle
4183
4184             else
4185                raise Program_Error;
4186             end if;
4187
4188             --  Build and insert a Full_Type_Declaration, which will be
4189             --  analyzed as soon as this list entry has been analyzed.
4190
4191             Decl := Make_Full_Type_Declaration (Loc,
4192               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4193               Type_Definition => Def);
4194
4195             Insert_After (N, Decl);
4196             Mark_Rewrite_Insertion (Decl);
4197
4198          else
4199             Error_Pragma_Arg ("no matching type found for pragma%",
4200             Arg2);
4201          end if;
4202       end Process_Import_Predefined_Type;
4203
4204       ---------------------------------
4205       -- Process_Import_Or_Interface --
4206       ---------------------------------
4207
4208       procedure Process_Import_Or_Interface is
4209          C      : Convention_Id;
4210          Def_Id : Entity_Id;
4211          Hom_Id : Entity_Id;
4212
4213       begin
4214          Process_Convention (C, Def_Id);
4215          Kill_Size_Check_Code (Def_Id);
4216          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4217
4218          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4219
4220             --  We do not permit Import to apply to a renaming declaration
4221
4222             if Present (Renamed_Object (Def_Id)) then
4223                Error_Pragma_Arg
4224                  ("pragma% not allowed for object renaming", Arg2);
4225
4226             --  User initialization is not allowed for imported object, but
4227             --  the object declaration may contain a default initialization,
4228             --  that will be discarded. Note that an explicit initialization
4229             --  only counts if it comes from source, otherwise it is simply
4230             --  the code generator making an implicit initialization explicit.
4231
4232             elsif Present (Expression (Parent (Def_Id)))
4233               and then Comes_From_Source (Expression (Parent (Def_Id)))
4234             then
4235                Error_Msg_Sloc := Sloc (Def_Id);
4236                Error_Pragma_Arg
4237                  ("no initialization allowed for declaration of& #",
4238                   "\imported entities cannot be initialized (RM B.1(24))",
4239                   Arg2);
4240
4241             else
4242                Set_Imported (Def_Id);
4243                Process_Interface_Name (Def_Id, Arg3, Arg4);
4244
4245                --  Note that we do not set Is_Public here. That's because we
4246                --  only want to set it if there is no address clause, and we
4247                --  don't know that yet, so we delay that processing till
4248                --  freeze time.
4249
4250                --  pragma Import completes deferred constants
4251
4252                if Ekind (Def_Id) = E_Constant then
4253                   Set_Has_Completion (Def_Id);
4254                end if;
4255
4256                --  It is not possible to import a constant of an unconstrained
4257                --  array type (e.g. string) because there is no simple way to
4258                --  write a meaningful subtype for it.
4259
4260                if Is_Array_Type (Etype (Def_Id))
4261                  and then not Is_Constrained (Etype (Def_Id))
4262                then
4263                   Error_Msg_NE
4264                     ("imported constant& must have a constrained subtype",
4265                       N, Def_Id);
4266                end if;
4267             end if;
4268
4269          elsif Is_Subprogram (Def_Id)
4270            or else Is_Generic_Subprogram (Def_Id)
4271          then
4272             --  If the name is overloaded, pragma applies to all of the denoted
4273             --  entities in the same declarative part.
4274
4275             Hom_Id := Def_Id;
4276             while Present (Hom_Id) loop
4277                Def_Id := Get_Base_Subprogram (Hom_Id);
4278
4279                --  Ignore inherited subprograms because the pragma will apply
4280                --  to the parent operation, which is the one called.
4281
4282                if Is_Overloadable (Def_Id)
4283                  and then Present (Alias (Def_Id))
4284                then
4285                   null;
4286
4287                --  If it is not a subprogram, it must be in an outer scope and
4288                --  pragma does not apply.
4289
4290                elsif not Is_Subprogram (Def_Id)
4291                  and then not Is_Generic_Subprogram (Def_Id)
4292                then
4293                   null;
4294
4295                --  The pragma does not apply to primitives of interfaces
4296
4297                elsif Is_Dispatching_Operation (Def_Id)
4298                  and then Present (Find_Dispatching_Type (Def_Id))
4299                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4300                then
4301                   null;
4302
4303                --  Verify that the homonym is in the same declarative part (not
4304                --  just the same scope).
4305
4306                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4307                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4308                then
4309                   exit;
4310
4311                else
4312                   Set_Imported (Def_Id);
4313
4314                   --  Reject an Import applied to an abstract subprogram
4315
4316                   if Is_Subprogram (Def_Id)
4317                     and then Is_Abstract_Subprogram (Def_Id)
4318                   then
4319                      Error_Msg_Sloc := Sloc (Def_Id);
4320                      Error_Msg_NE
4321                        ("cannot import abstract subprogram& declared#",
4322                         Arg2, Def_Id);
4323                   end if;
4324
4325                   --  Special processing for Convention_Intrinsic
4326
4327                   if C = Convention_Intrinsic then
4328
4329                      --  Link_Name argument not allowed for intrinsic
4330
4331                      Check_No_Link_Name;
4332
4333                      Set_Is_Intrinsic_Subprogram (Def_Id);
4334
4335                      --  If no external name is present, then check that this
4336                      --  is a valid intrinsic subprogram. If an external name
4337                      --  is present, then this is handled by the back end.
4338
4339                      if No (Arg3) then
4340                         Check_Intrinsic_Subprogram
4341                           (Def_Id, Get_Pragma_Arg (Arg2));
4342                      end if;
4343                   end if;
4344
4345                   --  All interfaced procedures need an external symbol created
4346                   --  for them since they are always referenced from another
4347                   --  object file.
4348
4349                   Set_Is_Public (Def_Id);
4350
4351                   --  Verify that the subprogram does not have a completion
4352                   --  through a renaming declaration. For other completions the
4353                   --  pragma appears as a too late representation.
4354
4355                   declare
4356                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4357
4358                   begin
4359                      if Present (Decl)
4360                        and then Nkind (Decl) = N_Subprogram_Declaration
4361                        and then Present (Corresponding_Body (Decl))
4362                        and then Nkind (Unit_Declaration_Node
4363                                         (Corresponding_Body (Decl))) =
4364                                              N_Subprogram_Renaming_Declaration
4365                      then
4366                         Error_Msg_Sloc := Sloc (Def_Id);
4367                         Error_Msg_NE
4368                           ("cannot import&, renaming already provided for " &
4369                            "declaration #", N, Def_Id);
4370                      end if;
4371                   end;
4372
4373                   Set_Has_Completion (Def_Id);
4374                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4375                end if;
4376
4377                if Is_Compilation_Unit (Hom_Id) then
4378
4379                   --  Its possible homonyms are not affected by the pragma.
4380                   --  Such homonyms might be present in the context of other
4381                   --  units being compiled.
4382
4383                   exit;
4384
4385                else
4386                   Hom_Id := Homonym (Hom_Id);
4387                end if;
4388             end loop;
4389
4390          --  When the convention is Java or CIL, we also allow Import to be
4391          --  given for packages, generic packages, exceptions, record
4392          --  components, and access to subprograms.
4393
4394          elsif (C = Convention_Java or else C = Convention_CIL)
4395            and then
4396              (Is_Package_Or_Generic_Package (Def_Id)
4397                or else Ekind (Def_Id) = E_Exception
4398                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4399                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4400          then
4401             Set_Imported (Def_Id);
4402             Set_Is_Public (Def_Id);
4403             Process_Interface_Name (Def_Id, Arg3, Arg4);
4404
4405          --  Import a CPP class
4406
4407          elsif Is_Record_Type (Def_Id)
4408            and then C = Convention_CPP
4409          then
4410             --  Types treated as CPP classes must be declared limited (note:
4411             --  this used to be a warning but there is no real benefit to it
4412             --  since we did effectively intend to treat the type as limited
4413             --  anyway).
4414
4415             if not Is_Limited_Type (Def_Id) then
4416                Error_Msg_N
4417                  ("imported 'C'P'P type must be limited",
4418                   Get_Pragma_Arg (Arg2));
4419             end if;
4420
4421             Set_Is_CPP_Class (Def_Id);
4422
4423             --  Imported CPP types must not have discriminants (because C++
4424             --  classes do not have discriminants).
4425
4426             if Has_Discriminants (Def_Id) then
4427                Error_Msg_N
4428                  ("imported 'C'P'P type cannot have discriminants",
4429                   First (Discriminant_Specifications
4430                           (Declaration_Node (Def_Id))));
4431             end if;
4432
4433             --  Components of imported CPP types must not have default
4434             --  expressions because the constructor (if any) is on the
4435             --  C++ side.
4436
4437             declare
4438                Tdef  : constant Node_Id :=
4439                          Type_Definition (Declaration_Node (Def_Id));
4440                Clist : Node_Id;
4441                Comp  : Node_Id;
4442
4443             begin
4444                if Nkind (Tdef) = N_Record_Definition then
4445                   Clist := Component_List (Tdef);
4446
4447                else
4448                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4449                   Clist := Component_List (Record_Extension_Part (Tdef));
4450                end if;
4451
4452                if Present (Clist) then
4453                   Comp := First (Component_Items (Clist));
4454                   while Present (Comp) loop
4455                      if Present (Expression (Comp)) then
4456                         Error_Msg_N
4457                           ("component of imported 'C'P'P type cannot have" &
4458                            " default expression", Expression (Comp));
4459                      end if;
4460
4461                      Next (Comp);
4462                   end loop;
4463                end if;
4464             end;
4465
4466          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4467             Check_No_Link_Name;
4468             Check_Arg_Count (3);
4469             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4470
4471             Process_Import_Predefined_Type;
4472
4473          else
4474             Error_Pragma_Arg
4475               ("second argument of pragma% must be object, subprogram" &
4476                " or incomplete type",
4477                Arg2);
4478          end if;
4479
4480          --  If this pragma applies to a compilation unit, then the unit, which
4481          --  is a subprogram, does not require (or allow) a body. We also do
4482          --  not need to elaborate imported procedures.
4483
4484          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4485             declare
4486                Cunit : constant Node_Id := Parent (Parent (N));
4487             begin
4488                Set_Body_Required (Cunit, False);
4489             end;
4490          end if;
4491       end Process_Import_Or_Interface;
4492
4493       --------------------
4494       -- Process_Inline --
4495       --------------------
4496
4497       procedure Process_Inline (Active : Boolean) is
4498          Assoc     : Node_Id;
4499          Decl      : Node_Id;
4500          Subp_Id   : Node_Id;
4501          Subp      : Entity_Id;
4502          Applies   : Boolean;
4503
4504          Effective : Boolean := False;
4505          --  Set True if inline has some effect, i.e. if there is at least one
4506          --  subprogram set as inlined as a result of the use of the pragma.
4507
4508          procedure Make_Inline (Subp : Entity_Id);
4509          --  Subp is the defining unit name of the subprogram declaration. Set
4510          --  the flag, as well as the flag in the corresponding body, if there
4511          --  is one present.
4512
4513          procedure Set_Inline_Flags (Subp : Entity_Id);
4514          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4515          --  Has_Pragma_Inline_Always for the Inline_Always case.
4516
4517          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4518          --  Returns True if it can be determined at this stage that inlining
4519          --  is not possible, for example if the body is available and contains
4520          --  exception handlers, we prevent inlining, since otherwise we can
4521          --  get undefined symbols at link time. This function also emits a
4522          --  warning if front-end inlining is enabled and the pragma appears
4523          --  too late.
4524          --
4525          --  ??? is business with link symbols still valid, or does it relate
4526          --  to front end ZCX which is being phased out ???
4527
4528          ---------------------------
4529          -- Inlining_Not_Possible --
4530          ---------------------------
4531
4532          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4533             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4534             Stats : Node_Id;
4535
4536          begin
4537             if Nkind (Decl) = N_Subprogram_Body then
4538                Stats := Handled_Statement_Sequence (Decl);
4539                return Present (Exception_Handlers (Stats))
4540                  or else Present (At_End_Proc (Stats));
4541
4542             elsif Nkind (Decl) = N_Subprogram_Declaration
4543               and then Present (Corresponding_Body (Decl))
4544             then
4545                if Front_End_Inlining
4546                  and then Analyzed (Corresponding_Body (Decl))
4547                then
4548                   Error_Msg_N ("pragma appears too late, ignored?", N);
4549                   return True;
4550
4551                --  If the subprogram is a renaming as body, the body is just a
4552                --  call to the renamed subprogram, and inlining is trivially
4553                --  possible.
4554
4555                elsif
4556                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4557                                              N_Subprogram_Renaming_Declaration
4558                then
4559                   return False;
4560
4561                else
4562                   Stats :=
4563                     Handled_Statement_Sequence
4564                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4565
4566                   return
4567                     Present (Exception_Handlers (Stats))
4568                       or else Present (At_End_Proc (Stats));
4569                end if;
4570
4571             else
4572                --  If body is not available, assume the best, the check is
4573                --  performed again when compiling enclosing package bodies.
4574
4575                return False;
4576             end if;
4577          end Inlining_Not_Possible;
4578
4579          -----------------
4580          -- Make_Inline --
4581          -----------------
4582
4583          procedure Make_Inline (Subp : Entity_Id) is
4584             Kind       : constant Entity_Kind := Ekind (Subp);
4585             Inner_Subp : Entity_Id   := Subp;
4586
4587          begin
4588             --  Ignore if bad type, avoid cascaded error
4589
4590             if Etype (Subp) = Any_Type then
4591                Applies := True;
4592                return;
4593
4594             --  Ignore if all inlining is suppressed
4595
4596             elsif Suppress_All_Inlining then
4597                Applies := True;
4598                return;
4599
4600             --  If inlining is not possible, for now do not treat as an error
4601
4602             elsif Inlining_Not_Possible (Subp) then
4603                Applies := True;
4604                return;
4605
4606             --  Here we have a candidate for inlining, but we must exclude
4607             --  derived operations. Otherwise we would end up trying to inline
4608             --  a phantom declaration, and the result would be to drag in a
4609             --  body which has no direct inlining associated with it. That
4610             --  would not only be inefficient but would also result in the
4611             --  backend doing cross-unit inlining in cases where it was
4612             --  definitely inappropriate to do so.
4613
4614             --  However, a simple Comes_From_Source test is insufficient, since
4615             --  we do want to allow inlining of generic instances which also do
4616             --  not come from source. We also need to recognize specs generated
4617             --  by the front-end for bodies that carry the pragma. Finally,
4618             --  predefined operators do not come from source but are not
4619             --  inlineable either.
4620
4621             elsif Is_Generic_Instance (Subp)
4622               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4623             then
4624                null;
4625
4626             elsif not Comes_From_Source (Subp)
4627               and then Scope (Subp) /= Standard_Standard
4628             then
4629                Applies := True;
4630                return;
4631             end if;
4632
4633             --  The referenced entity must either be the enclosing entity, or
4634             --  an entity declared within the current open scope.
4635
4636             if Present (Scope (Subp))
4637               and then Scope (Subp) /= Current_Scope
4638               and then Subp /= Current_Scope
4639             then
4640                Error_Pragma_Arg
4641                  ("argument of% must be entity in current scope", Assoc);
4642                return;
4643             end if;
4644
4645             --  Processing for procedure, operator or function. If subprogram
4646             --  is aliased (as for an instance) indicate that the renamed
4647             --  entity (if declared in the same unit) is inlined.
4648
4649             if Is_Subprogram (Subp) then
4650                Inner_Subp := Ultimate_Alias (Inner_Subp);
4651
4652                if In_Same_Source_Unit (Subp, Inner_Subp) then
4653                   Set_Inline_Flags (Inner_Subp);
4654
4655                   Decl := Parent (Parent (Inner_Subp));
4656
4657                   if Nkind (Decl) = N_Subprogram_Declaration
4658                     and then Present (Corresponding_Body (Decl))
4659                   then
4660                      Set_Inline_Flags (Corresponding_Body (Decl));
4661
4662                   elsif Is_Generic_Instance (Subp) then
4663
4664                      --  Indicate that the body needs to be created for
4665                      --  inlining subsequent calls. The instantiation node
4666                      --  follows the declaration of the wrapper package
4667                      --  created for it.
4668
4669                      if Scope (Subp) /= Standard_Standard
4670                        and then
4671                          Need_Subprogram_Instance_Body
4672                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4673                               Subp)
4674                      then
4675                         null;
4676                      end if;
4677                   end if;
4678                end if;
4679
4680                Applies := True;
4681
4682             --  For a generic subprogram set flag as well, for use at the point
4683             --  of instantiation, to determine whether the body should be
4684             --  generated.
4685
4686             elsif Is_Generic_Subprogram (Subp) then
4687                Set_Inline_Flags (Subp);
4688                Applies := True;
4689
4690             --  Literals are by definition inlined
4691
4692             elsif Kind = E_Enumeration_Literal then
4693                null;
4694
4695             --  Anything else is an error
4696
4697             else
4698                Error_Pragma_Arg
4699                  ("expect subprogram name for pragma%", Assoc);
4700             end if;
4701          end Make_Inline;
4702
4703          ----------------------
4704          -- Set_Inline_Flags --
4705          ----------------------
4706
4707          procedure Set_Inline_Flags (Subp : Entity_Id) is
4708          begin
4709             if Active then
4710                Set_Is_Inlined (Subp);
4711             end if;
4712
4713             if not Has_Pragma_Inline (Subp) then
4714                Set_Has_Pragma_Inline (Subp);
4715                Effective := True;
4716             end if;
4717
4718             if Prag_Id = Pragma_Inline_Always then
4719                Set_Has_Pragma_Inline_Always (Subp);
4720             end if;
4721          end Set_Inline_Flags;
4722
4723       --  Start of processing for Process_Inline
4724
4725       begin
4726          Check_No_Identifiers;
4727          Check_At_Least_N_Arguments (1);
4728
4729          if Active then
4730             Inline_Processing_Required := True;
4731          end if;
4732
4733          Assoc := Arg1;
4734          while Present (Assoc) loop
4735             Subp_Id := Get_Pragma_Arg (Assoc);
4736             Analyze (Subp_Id);
4737             Applies := False;
4738
4739             if Is_Entity_Name (Subp_Id) then
4740                Subp := Entity (Subp_Id);
4741
4742                if Subp = Any_Id then
4743
4744                   --  If previous error, avoid cascaded errors
4745
4746                   Applies := True;
4747                   Effective := True;
4748
4749                else
4750                   Make_Inline (Subp);
4751
4752                   --  For the pragma case, climb homonym chain. This is
4753                   --  what implements allowing the pragma in the renaming
4754                   --  case, with the result applying to the ancestors.
4755
4756                   if not From_Aspect_Specification (N) then
4757                      while Present (Homonym (Subp))
4758                        and then Scope (Homonym (Subp)) = Current_Scope
4759                      loop
4760                         Make_Inline (Homonym (Subp));
4761                         Subp := Homonym (Subp);
4762                      end loop;
4763                   end if;
4764                end if;
4765             end if;
4766
4767             if not Applies then
4768                Error_Pragma_Arg
4769                  ("inappropriate argument for pragma%", Assoc);
4770
4771             elsif not Effective
4772               and then Warn_On_Redundant_Constructs
4773               and then not Suppress_All_Inlining
4774             then
4775                if Inlining_Not_Possible (Subp) then
4776                   Error_Msg_NE
4777                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4778                else
4779                   Error_Msg_NE
4780                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4781                end if;
4782             end if;
4783
4784             Next (Assoc);
4785          end loop;
4786       end Process_Inline;
4787
4788       ----------------------------
4789       -- Process_Interface_Name --
4790       ----------------------------
4791
4792       procedure Process_Interface_Name
4793         (Subprogram_Def : Entity_Id;
4794          Ext_Arg        : Node_Id;
4795          Link_Arg       : Node_Id)
4796       is
4797          Ext_Nam    : Node_Id;
4798          Link_Nam   : Node_Id;
4799          String_Val : String_Id;
4800
4801          procedure Check_Form_Of_Interface_Name
4802            (SN            : Node_Id;
4803             Ext_Name_Case : Boolean);
4804          --  SN is a string literal node for an interface name. This routine
4805          --  performs some minimal checks that the name is reasonable. In
4806          --  particular that no spaces or other obviously incorrect characters
4807          --  appear. This is only a warning, since any characters are allowed.
4808          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4809
4810          ----------------------------------
4811          -- Check_Form_Of_Interface_Name --
4812          ----------------------------------
4813
4814          procedure Check_Form_Of_Interface_Name
4815            (SN            : Node_Id;
4816             Ext_Name_Case : Boolean)
4817          is
4818             S  : constant String_Id := Strval (Expr_Value_S (SN));
4819             SL : constant Nat       := String_Length (S);
4820             C  : Char_Code;
4821
4822          begin
4823             if SL = 0 then
4824                Error_Msg_N ("interface name cannot be null string", SN);
4825             end if;
4826
4827             for J in 1 .. SL loop
4828                C := Get_String_Char (S, J);
4829
4830                --  Look for dubious character and issue unconditional warning.
4831                --  Definitely dubious if not in character range.
4832
4833                if not In_Character_Range (C)
4834
4835                   --  For all cases except CLI target,
4836                   --  commas, spaces and slashes are dubious (in CLI, we use
4837                   --  commas and backslashes in external names to specify
4838                   --  assembly version and public key, while slashes and spaces
4839                   --  can be used in names to mark nested classes and
4840                   --  valuetypes).
4841
4842                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4843                              and then (Get_Character (C) = ','
4844                                          or else
4845                                        Get_Character (C) = '\'))
4846                  or else (VM_Target /= CLI_Target
4847                             and then (Get_Character (C) = ' '
4848                                         or else
4849                                       Get_Character (C) = '/'))
4850                then
4851                   Error_Msg
4852                     ("?interface name contains illegal character",
4853                      Sloc (SN) + Source_Ptr (J));
4854                end if;
4855             end loop;
4856          end Check_Form_Of_Interface_Name;
4857
4858       --  Start of processing for Process_Interface_Name
4859
4860       begin
4861          if No (Link_Arg) then
4862             if No (Ext_Arg) then
4863                if VM_Target = CLI_Target
4864                  and then Ekind (Subprogram_Def) = E_Package
4865                  and then Nkind (Parent (Subprogram_Def)) =
4866                                                  N_Package_Specification
4867                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
4868                then
4869                   Set_Interface_Name
4870                      (Subprogram_Def,
4871                       Interface_Name
4872                         (Generic_Parent (Parent (Subprogram_Def))));
4873                end if;
4874
4875                return;
4876
4877             elsif Chars (Ext_Arg) = Name_Link_Name then
4878                Ext_Nam  := Empty;
4879                Link_Nam := Expression (Ext_Arg);
4880
4881             else
4882                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4883                Ext_Nam  := Expression (Ext_Arg);
4884                Link_Nam := Empty;
4885             end if;
4886
4887          else
4888             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
4889             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4890             Ext_Nam  := Expression (Ext_Arg);
4891             Link_Nam := Expression (Link_Arg);
4892          end if;
4893
4894          --  Check expressions for external name and link name are static
4895
4896          if Present (Ext_Nam) then
4897             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4898             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4899
4900             --  Verify that external name is not the name of a local entity,
4901             --  which would hide the imported one and could lead to run-time
4902             --  surprises. The problem can only arise for entities declared in
4903             --  a package body (otherwise the external name is fully qualified
4904             --  and will not conflict).
4905
4906             declare
4907                Nam : Name_Id;
4908                E   : Entity_Id;
4909                Par : Node_Id;
4910
4911             begin
4912                if Prag_Id = Pragma_Import then
4913                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4914                   Nam := Name_Find;
4915                   E   := Entity_Id (Get_Name_Table_Info (Nam));
4916
4917                   if Nam /= Chars (Subprogram_Def)
4918                     and then Present (E)
4919                     and then not Is_Overloadable (E)
4920                     and then Is_Immediately_Visible (E)
4921                     and then not Is_Imported (E)
4922                     and then Ekind (Scope (E)) = E_Package
4923                   then
4924                      Par := Parent (E);
4925                      while Present (Par) loop
4926                         if Nkind (Par) = N_Package_Body then
4927                            Error_Msg_Sloc := Sloc (E);
4928                            Error_Msg_NE
4929                              ("imported entity is hidden by & declared#",
4930                               Ext_Arg, E);
4931                            exit;
4932                         end if;
4933
4934                         Par := Parent (Par);
4935                      end loop;
4936                   end if;
4937                end if;
4938             end;
4939          end if;
4940
4941          if Present (Link_Nam) then
4942             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4943             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4944          end if;
4945
4946          --  If there is no link name, just set the external name
4947
4948          if No (Link_Nam) then
4949             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4950
4951          --  For the Link_Name case, the given literal is preceded by an
4952          --  asterisk, which indicates to GCC that the given name should be
4953          --  taken literally, and in particular that no prepending of
4954          --  underlines should occur, even in systems where this is the
4955          --  normal default.
4956
4957          else
4958             Start_String;
4959
4960             if VM_Target = No_VM then
4961                Store_String_Char (Get_Char_Code ('*'));
4962             end if;
4963
4964             String_Val := Strval (Expr_Value_S (Link_Nam));
4965             Store_String_Chars (String_Val);
4966             Link_Nam :=
4967               Make_String_Literal (Sloc (Link_Nam),
4968                 Strval => End_String);
4969          end if;
4970
4971          --  Set the interface name. If the entity is a generic instance, use
4972          --  its alias, which is the callable entity.
4973
4974          if Is_Generic_Instance (Subprogram_Def) then
4975             Set_Encoded_Interface_Name
4976               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
4977          else
4978             Set_Encoded_Interface_Name
4979               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
4980          end if;
4981
4982          --  We allow duplicated export names in CIL/Java, as they are always
4983          --  enclosed in a namespace that differentiates them, and overloaded
4984          --  entities are supported by the VM.
4985
4986          if Convention (Subprogram_Def) /= Convention_CIL
4987               and then
4988             Convention (Subprogram_Def) /= Convention_Java
4989          then
4990             Check_Duplicated_Export_Name (Link_Nam);
4991          end if;
4992       end Process_Interface_Name;
4993
4994       -----------------------------------------
4995       -- Process_Interrupt_Or_Attach_Handler --
4996       -----------------------------------------
4997
4998       procedure Process_Interrupt_Or_Attach_Handler is
4999          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5000          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5001          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5002
5003       begin
5004          Set_Is_Interrupt_Handler (Handler_Proc);
5005
5006          --  If the pragma is not associated with a handler procedure within a
5007          --  protected type, then it must be for a nonprotected procedure for
5008          --  the AAMP target, in which case we don't associate a representation
5009          --  item with the procedure's scope.
5010
5011          if Ekind (Proc_Scope) = E_Protected_Type then
5012             if Prag_Id = Pragma_Interrupt_Handler
5013                  or else
5014                Prag_Id = Pragma_Attach_Handler
5015             then
5016                Record_Rep_Item (Proc_Scope, N);
5017             end if;
5018          end if;
5019       end Process_Interrupt_Or_Attach_Handler;
5020
5021       --------------------------------------------------
5022       -- Process_Restrictions_Or_Restriction_Warnings --
5023       --------------------------------------------------
5024
5025       --  Note: some of the simple identifier cases were handled in par-prag,
5026       --  but it is harmless (and more straightforward) to simply handle all
5027       --  cases here, even if it means we repeat a bit of work in some cases.
5028
5029       procedure Process_Restrictions_Or_Restriction_Warnings
5030         (Warn : Boolean)
5031       is
5032          Arg   : Node_Id;
5033          R_Id  : Restriction_Id;
5034          Id    : Name_Id;
5035          Expr  : Node_Id;
5036          Val   : Uint;
5037
5038          procedure Check_Unit_Name (N : Node_Id);
5039          --  Checks unit name parameter for No_Dependence. Returns if it has
5040          --  an appropriate form, otherwise raises pragma argument error.
5041
5042          ---------------------
5043          -- Check_Unit_Name --
5044          ---------------------
5045
5046          procedure Check_Unit_Name (N : Node_Id) is
5047          begin
5048             if Nkind (N) = N_Selected_Component then
5049                Check_Unit_Name (Prefix (N));
5050                Check_Unit_Name (Selector_Name (N));
5051
5052             elsif Nkind (N) = N_Identifier then
5053                return;
5054
5055             else
5056                Error_Pragma_Arg
5057                  ("wrong form for unit name for No_Dependence", N);
5058             end if;
5059          end Check_Unit_Name;
5060
5061       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5062
5063       begin
5064          --  Ignore all Restrictions pragma in CodePeer mode
5065
5066          if CodePeer_Mode then
5067             return;
5068          end if;
5069
5070          Check_Ada_83_Warning;
5071          Check_At_Least_N_Arguments (1);
5072          Check_Valid_Configuration_Pragma;
5073
5074          Arg := Arg1;
5075          while Present (Arg) loop
5076             Id := Chars (Arg);
5077             Expr := Get_Pragma_Arg (Arg);
5078
5079             --  Case of no restriction identifier present
5080
5081             if Id = No_Name then
5082                if Nkind (Expr) /= N_Identifier then
5083                   Error_Pragma_Arg
5084                     ("invalid form for restriction", Arg);
5085                end if;
5086
5087                R_Id :=
5088                  Get_Restriction_Id
5089                    (Process_Restriction_Synonyms (Expr));
5090
5091                if R_Id not in All_Boolean_Restrictions then
5092                   Error_Msg_Name_1 := Pname;
5093                   Error_Msg_N
5094                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5095
5096                   --  Check for possible misspelling
5097
5098                   for J in Restriction_Id loop
5099                      declare
5100                         Rnm : constant String := Restriction_Id'Image (J);
5101
5102                      begin
5103                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5104                         Name_Len := Rnm'Length;
5105                         Set_Casing (All_Lower_Case);
5106
5107                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5108                            Set_Casing
5109                              (Identifier_Casing (Current_Source_File));
5110                            Error_Msg_String (1 .. Rnm'Length) :=
5111                              Name_Buffer (1 .. Name_Len);
5112                            Error_Msg_Strlen := Rnm'Length;
5113                            Error_Msg_N -- CODEFIX
5114                              ("\possible misspelling of ""~""",
5115                               Get_Pragma_Arg (Arg));
5116                            exit;
5117                         end if;
5118                      end;
5119                   end loop;
5120
5121                   raise Pragma_Exit;
5122                end if;
5123
5124                if Implementation_Restriction (R_Id) then
5125                   Check_Restriction (No_Implementation_Restrictions, Arg);
5126                end if;
5127
5128                --  If this is a warning, then set the warning unless we already
5129                --  have a real restriction active (we never want a warning to
5130                --  override a real restriction).
5131
5132                if Warn then
5133                   if not Restriction_Active (R_Id) then
5134                      Set_Restriction (R_Id, N);
5135                      Restriction_Warnings (R_Id) := True;
5136                   end if;
5137
5138                --  If real restriction case, then set it and make sure that the
5139                --  restriction warning flag is off, since a real restriction
5140                --  always overrides a warning.
5141
5142                else
5143                   Set_Restriction (R_Id, N);
5144                   Restriction_Warnings (R_Id) := False;
5145                end if;
5146
5147                --  Check for obsolescent restrictions in Ada 2005 mode
5148
5149                if not Warn
5150                  and then Ada_Version >= Ada_2005
5151                  and then (R_Id = No_Asynchronous_Control
5152                             or else
5153                            R_Id = No_Unchecked_Deallocation
5154                             or else
5155                            R_Id = No_Unchecked_Conversion)
5156                then
5157                   Check_Restriction (No_Obsolescent_Features, N);
5158                end if;
5159
5160                --  A very special case that must be processed here: pragma
5161                --  Restrictions (No_Exceptions) turns off all run-time
5162                --  checking. This is a bit dubious in terms of the formal
5163                --  language definition, but it is what is intended by RM
5164                --  H.4(12). Restriction_Warnings never affects generated code
5165                --  so this is done only in the real restriction case.
5166
5167                if R_Id = No_Exceptions and then not Warn then
5168                   Scope_Suppress := (others => True);
5169                end if;
5170
5171             --  Case of No_Dependence => unit-name. Note that the parser
5172             --  already made the necessary entry in the No_Dependence table.
5173
5174             elsif Id = Name_No_Dependence then
5175                Check_Unit_Name (Expr);
5176
5177             --  All other cases of restriction identifier present
5178
5179             else
5180                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5181                Analyze_And_Resolve (Expr, Any_Integer);
5182
5183                if R_Id not in All_Parameter_Restrictions then
5184                   Error_Pragma_Arg
5185                     ("invalid restriction parameter identifier", Arg);
5186
5187                elsif not Is_OK_Static_Expression (Expr) then
5188                   Flag_Non_Static_Expr
5189                     ("value must be static expression!", Expr);
5190                   raise Pragma_Exit;
5191
5192                elsif not Is_Integer_Type (Etype (Expr))
5193                  or else Expr_Value (Expr) < 0
5194                then
5195                   Error_Pragma_Arg
5196                     ("value must be non-negative integer", Arg);
5197                end if;
5198
5199                --  Restriction pragma is active
5200
5201                Val := Expr_Value (Expr);
5202
5203                if not UI_Is_In_Int_Range (Val) then
5204                   Error_Pragma_Arg
5205                     ("pragma ignored, value too large?", Arg);
5206                end if;
5207
5208                --  Warning case. If the real restriction is active, then we
5209                --  ignore the request, since warning never overrides a real
5210                --  restriction. Otherwise we set the proper warning. Note that
5211                --  this circuit sets the warning again if it is already set,
5212                --  which is what we want, since the constant may have changed.
5213
5214                if Warn then
5215                   if not Restriction_Active (R_Id) then
5216                      Set_Restriction
5217                        (R_Id, N, Integer (UI_To_Int (Val)));
5218                      Restriction_Warnings (R_Id) := True;
5219                   end if;
5220
5221                --  Real restriction case, set restriction and make sure warning
5222                --  flag is off since real restriction always overrides warning.
5223
5224                else
5225                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5226                   Restriction_Warnings (R_Id) := False;
5227                end if;
5228             end if;
5229
5230             Next (Arg);
5231          end loop;
5232       end Process_Restrictions_Or_Restriction_Warnings;
5233
5234       ---------------------------------
5235       -- Process_Suppress_Unsuppress --
5236       ---------------------------------
5237
5238       --  Note: this procedure makes entries in the check suppress data
5239       --  structures managed by Sem. See spec of package Sem for full
5240       --  details on how we handle recording of check suppression.
5241
5242       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5243          C    : Check_Id;
5244          E_Id : Node_Id;
5245          E    : Entity_Id;
5246
5247          In_Package_Spec : constant Boolean :=
5248                              Is_Package_Or_Generic_Package (Current_Scope)
5249                                and then not In_Package_Body (Current_Scope);
5250
5251          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5252          --  Used to suppress a single check on the given entity
5253
5254          --------------------------------
5255          -- Suppress_Unsuppress_Echeck --
5256          --------------------------------
5257
5258          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5259          begin
5260             Set_Checks_May_Be_Suppressed (E);
5261
5262             if In_Package_Spec then
5263                Push_Global_Suppress_Stack_Entry
5264                  (Entity   => E,
5265                   Check    => C,
5266                   Suppress => Suppress_Case);
5267
5268             else
5269                Push_Local_Suppress_Stack_Entry
5270                  (Entity   => E,
5271                   Check    => C,
5272                   Suppress => Suppress_Case);
5273             end if;
5274
5275             --  If this is a first subtype, and the base type is distinct,
5276             --  then also set the suppress flags on the base type.
5277
5278             if Is_First_Subtype (E)
5279               and then Etype (E) /= E
5280             then
5281                Suppress_Unsuppress_Echeck (Etype (E), C);
5282             end if;
5283          end Suppress_Unsuppress_Echeck;
5284
5285       --  Start of processing for Process_Suppress_Unsuppress
5286
5287       begin
5288          --  Ignore pragma Suppress/Unsuppress in codepeer mode on user code:
5289          --  we want to generate checks for analysis purposes, as set by -gnatC
5290
5291          if CodePeer_Mode and then Comes_From_Source (N) then
5292             return;
5293          end if;
5294
5295          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5296          --  declarative part or a package spec (RM 11.5(5)).
5297
5298          if not Is_Configuration_Pragma then
5299             Check_Is_In_Decl_Part_Or_Package_Spec;
5300          end if;
5301
5302          Check_At_Least_N_Arguments (1);
5303          Check_At_Most_N_Arguments (2);
5304          Check_No_Identifier (Arg1);
5305          Check_Arg_Is_Identifier (Arg1);
5306
5307          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5308
5309          if C = No_Check_Id then
5310             Error_Pragma_Arg
5311               ("argument of pragma% is not valid check name", Arg1);
5312          end if;
5313
5314          if not Suppress_Case
5315            and then (C = All_Checks or else C = Overflow_Check)
5316          then
5317             Opt.Overflow_Checks_Unsuppressed := True;
5318          end if;
5319
5320          if Arg_Count = 1 then
5321
5322             --  Make an entry in the local scope suppress table. This is the
5323             --  table that directly shows the current value of the scope
5324             --  suppress check for any check id value.
5325
5326             if C = All_Checks then
5327
5328                --  For All_Checks, we set all specific predefined checks with
5329                --  the exception of Elaboration_Check, which is handled
5330                --  specially because of not wanting All_Checks to have the
5331                --  effect of deactivating static elaboration order processing.
5332
5333                for J in Scope_Suppress'Range loop
5334                   if J /= Elaboration_Check then
5335                      Scope_Suppress (J) := Suppress_Case;
5336                   end if;
5337                end loop;
5338
5339             --  If not All_Checks, and predefined check, then set appropriate
5340             --  scope entry. Note that we will set Elaboration_Check if this
5341             --  is explicitly specified.
5342
5343             elsif C in Predefined_Check_Id then
5344                Scope_Suppress (C) := Suppress_Case;
5345             end if;
5346
5347             --  Also make an entry in the Local_Entity_Suppress table
5348
5349             Push_Local_Suppress_Stack_Entry
5350               (Entity   => Empty,
5351                Check    => C,
5352                Suppress => Suppress_Case);
5353
5354          --  Case of two arguments present, where the check is suppressed for
5355          --  a specified entity (given as the second argument of the pragma)
5356
5357          else
5358             --  This is obsolescent in Ada 2005 mode
5359
5360             if Ada_Version >= Ada_2005 then
5361                Check_Restriction (No_Obsolescent_Features, Arg2);
5362             end if;
5363
5364             Check_Optional_Identifier (Arg2, Name_On);
5365             E_Id := Get_Pragma_Arg (Arg2);
5366             Analyze (E_Id);
5367
5368             if not Is_Entity_Name (E_Id) then
5369                Error_Pragma_Arg
5370                  ("second argument of pragma% must be entity name", Arg2);
5371             end if;
5372
5373             E := Entity (E_Id);
5374
5375             if E = Any_Id then
5376                return;
5377             end if;
5378
5379             --  Enforce RM 11.5(7) which requires that for a pragma that
5380             --  appears within a package spec, the named entity must be
5381             --  within the package spec. We allow the package name itself
5382             --  to be mentioned since that makes sense, although it is not
5383             --  strictly allowed by 11.5(7).
5384
5385             if In_Package_Spec
5386               and then E /= Current_Scope
5387               and then Scope (E) /= Current_Scope
5388             then
5389                Error_Pragma_Arg
5390                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5391                   Arg2);
5392             end if;
5393
5394             --  Loop through homonyms. As noted below, in the case of a package
5395             --  spec, only homonyms within the package spec are considered.
5396
5397             loop
5398                Suppress_Unsuppress_Echeck (E, C);
5399
5400                if Is_Generic_Instance (E)
5401                  and then Is_Subprogram (E)
5402                  and then Present (Alias (E))
5403                then
5404                   Suppress_Unsuppress_Echeck (Alias (E), C);
5405                end if;
5406
5407                --  Move to next homonym if not aspect spec case
5408
5409                exit when From_Aspect_Specification (N);
5410                E := Homonym (E);
5411                exit when No (E);
5412
5413                --  If we are within a package specification, the pragma only
5414                --  applies to homonyms in the same scope.
5415
5416                exit when In_Package_Spec
5417                  and then Scope (E) /= Current_Scope;
5418             end loop;
5419          end if;
5420       end Process_Suppress_Unsuppress;
5421
5422       ------------------
5423       -- Set_Exported --
5424       ------------------
5425
5426       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5427       begin
5428          if Is_Imported (E) then
5429             Error_Pragma_Arg
5430               ("cannot export entity& that was previously imported", Arg);
5431
5432          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5433             Error_Pragma_Arg
5434               ("cannot export entity& that has an address clause", Arg);
5435          end if;
5436
5437          Set_Is_Exported (E);
5438
5439          --  Generate a reference for entity explicitly, because the
5440          --  identifier may be overloaded and name resolution will not
5441          --  generate one.
5442
5443          Generate_Reference (E, Arg);
5444
5445          --  Deal with exporting non-library level entity
5446
5447          if not Is_Library_Level_Entity (E) then
5448
5449             --  Not allowed at all for subprograms
5450
5451             if Is_Subprogram (E) then
5452                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5453
5454             --  Otherwise set public and statically allocated
5455
5456             else
5457                Set_Is_Public (E);
5458                Set_Is_Statically_Allocated (E);
5459
5460                --  Warn if the corresponding W flag is set and the pragma comes
5461                --  from source. The latter may not be true e.g. on VMS where we
5462                --  expand export pragmas for exception codes associated with
5463                --  imported or exported exceptions. We do not want to generate
5464                --  a warning for something that the user did not write.
5465
5466                if Warn_On_Export_Import
5467                  and then Comes_From_Source (Arg)
5468                then
5469                   Error_Msg_NE
5470                     ("?& has been made static as a result of Export", Arg, E);
5471                   Error_Msg_N
5472                     ("\this usage is non-standard and non-portable", Arg);
5473                end if;
5474             end if;
5475          end if;
5476
5477          if Warn_On_Export_Import and then Is_Type (E) then
5478             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5479          end if;
5480
5481          if Warn_On_Export_Import and Inside_A_Generic then
5482             Error_Msg_NE
5483               ("all instances of& will have the same external name?", Arg, E);
5484          end if;
5485       end Set_Exported;
5486
5487       ----------------------------------------------
5488       -- Set_Extended_Import_Export_External_Name --
5489       ----------------------------------------------
5490
5491       procedure Set_Extended_Import_Export_External_Name
5492         (Internal_Ent : Entity_Id;
5493          Arg_External : Node_Id)
5494       is
5495          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5496          New_Name : Node_Id;
5497
5498       begin
5499          if No (Arg_External) then
5500             return;
5501          end if;
5502
5503          Check_Arg_Is_External_Name (Arg_External);
5504
5505          if Nkind (Arg_External) = N_String_Literal then
5506             if String_Length (Strval (Arg_External)) = 0 then
5507                return;
5508             else
5509                New_Name := Adjust_External_Name_Case (Arg_External);
5510             end if;
5511
5512          elsif Nkind (Arg_External) = N_Identifier then
5513             New_Name := Get_Default_External_Name (Arg_External);
5514
5515          --  Check_Arg_Is_External_Name should let through only identifiers and
5516          --  string literals or static string expressions (which are folded to
5517          --  string literals).
5518
5519          else
5520             raise Program_Error;
5521          end if;
5522
5523          --  If we already have an external name set (by a prior normal Import
5524          --  or Export pragma), then the external names must match
5525
5526          if Present (Interface_Name (Internal_Ent)) then
5527             Check_Matching_Internal_Names : declare
5528                S1 : constant String_Id := Strval (Old_Name);
5529                S2 : constant String_Id := Strval (New_Name);
5530
5531                procedure Mismatch;
5532                --  Called if names do not match
5533
5534                --------------
5535                -- Mismatch --
5536                --------------
5537
5538                procedure Mismatch is
5539                begin
5540                   Error_Msg_Sloc := Sloc (Old_Name);
5541                   Error_Pragma_Arg
5542                     ("external name does not match that given #",
5543                      Arg_External);
5544                end Mismatch;
5545
5546             --  Start of processing for Check_Matching_Internal_Names
5547
5548             begin
5549                if String_Length (S1) /= String_Length (S2) then
5550                   Mismatch;
5551
5552                else
5553                   for J in 1 .. String_Length (S1) loop
5554                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5555                         Mismatch;
5556                      end if;
5557                   end loop;
5558                end if;
5559             end Check_Matching_Internal_Names;
5560
5561          --  Otherwise set the given name
5562
5563          else
5564             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5565             Check_Duplicated_Export_Name (New_Name);
5566          end if;
5567       end Set_Extended_Import_Export_External_Name;
5568
5569       ------------------
5570       -- Set_Imported --
5571       ------------------
5572
5573       procedure Set_Imported (E : Entity_Id) is
5574       begin
5575          --  Error message if already imported or exported
5576
5577          if Is_Exported (E) or else Is_Imported (E) then
5578
5579             --  Error if being set Exported twice
5580
5581             if Is_Exported (E) then
5582                Error_Msg_NE ("entity& was previously exported", N, E);
5583
5584             --  OK if Import/Interface case
5585
5586             elsif Import_Interface_Present (N) then
5587                goto OK;
5588
5589             --  Error if being set Imported twice
5590
5591             else
5592                Error_Msg_NE ("entity& was previously imported", N, E);
5593             end if;
5594
5595             Error_Msg_Name_1 := Pname;
5596             Error_Msg_N
5597               ("\(pragma% applies to all previous entities)", N);
5598
5599             Error_Msg_Sloc  := Sloc (E);
5600             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5601
5602          --  Here if not previously imported or exported, OK to import
5603
5604          else
5605             Set_Is_Imported (E);
5606
5607             --  If the entity is an object that is not at the library level,
5608             --  then it is statically allocated. We do not worry about objects
5609             --  with address clauses in this context since they are not really
5610             --  imported in the linker sense.
5611
5612             if Is_Object (E)
5613               and then not Is_Library_Level_Entity (E)
5614               and then No (Address_Clause (E))
5615             then
5616                Set_Is_Statically_Allocated (E);
5617             end if;
5618          end if;
5619
5620          <<OK>> null;
5621       end Set_Imported;
5622
5623       -------------------------
5624       -- Set_Mechanism_Value --
5625       -------------------------
5626
5627       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5628       --  analyzed, since it is semantic nonsense), so we get it in the exact
5629       --  form created by the parser.
5630
5631       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5632          Class        : Node_Id;
5633          Param        : Node_Id;
5634          Mech_Name_Id : Name_Id;
5635
5636          procedure Bad_Class;
5637          --  Signal bad descriptor class name
5638
5639          procedure Bad_Mechanism;
5640          --  Signal bad mechanism name
5641
5642          ---------------
5643          -- Bad_Class --
5644          ---------------
5645
5646          procedure Bad_Class is
5647          begin
5648             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5649          end Bad_Class;
5650
5651          -------------------------
5652          -- Bad_Mechanism_Value --
5653          -------------------------
5654
5655          procedure Bad_Mechanism is
5656          begin
5657             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5658          end Bad_Mechanism;
5659
5660       --  Start of processing for Set_Mechanism_Value
5661
5662       begin
5663          if Mechanism (Ent) /= Default_Mechanism then
5664             Error_Msg_NE
5665               ("mechanism for & has already been set", Mech_Name, Ent);
5666          end if;
5667
5668          --  MECHANISM_NAME ::= value | reference | descriptor |
5669          --                     short_descriptor
5670
5671          if Nkind (Mech_Name) = N_Identifier then
5672             if Chars (Mech_Name) = Name_Value then
5673                Set_Mechanism (Ent, By_Copy);
5674                return;
5675
5676             elsif Chars (Mech_Name) = Name_Reference then
5677                Set_Mechanism (Ent, By_Reference);
5678                return;
5679
5680             elsif Chars (Mech_Name) = Name_Descriptor then
5681                Check_VMS (Mech_Name);
5682
5683                --  Descriptor => Short_Descriptor if pragma was given
5684
5685                if Short_Descriptors then
5686                   Set_Mechanism (Ent, By_Short_Descriptor);
5687                else
5688                   Set_Mechanism (Ent, By_Descriptor);
5689                end if;
5690
5691                return;
5692
5693             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5694                Check_VMS (Mech_Name);
5695                Set_Mechanism (Ent, By_Short_Descriptor);
5696                return;
5697
5698             elsif Chars (Mech_Name) = Name_Copy then
5699                Error_Pragma_Arg
5700                  ("bad mechanism name, Value assumed", Mech_Name);
5701
5702             else
5703                Bad_Mechanism;
5704             end if;
5705
5706          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5707          --                     short_descriptor (CLASS_NAME)
5708          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5709
5710          --  Note: this form is parsed as an indexed component
5711
5712          elsif Nkind (Mech_Name) = N_Indexed_Component then
5713             Class := First (Expressions (Mech_Name));
5714
5715             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5716              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5717                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5718              or else Present (Next (Class))
5719             then
5720                Bad_Mechanism;
5721             else
5722                Mech_Name_Id := Chars (Prefix (Mech_Name));
5723
5724                --  Change Descriptor => Short_Descriptor if pragma was given
5725
5726                if Mech_Name_Id = Name_Descriptor
5727                  and then Short_Descriptors
5728                then
5729                   Mech_Name_Id := Name_Short_Descriptor;
5730                end if;
5731             end if;
5732
5733          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5734          --                     short_descriptor (Class => CLASS_NAME)
5735          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5736
5737          --  Note: this form is parsed as a function call
5738
5739          elsif Nkind (Mech_Name) = N_Function_Call then
5740             Param := First (Parameter_Associations (Mech_Name));
5741
5742             if Nkind (Name (Mech_Name)) /= N_Identifier
5743               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5744                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5745               or else Present (Next (Param))
5746               or else No (Selector_Name (Param))
5747               or else Chars (Selector_Name (Param)) /= Name_Class
5748             then
5749                Bad_Mechanism;
5750             else
5751                Class := Explicit_Actual_Parameter (Param);
5752                Mech_Name_Id := Chars (Name (Mech_Name));
5753             end if;
5754
5755          else
5756             Bad_Mechanism;
5757          end if;
5758
5759          --  Fall through here with Class set to descriptor class name
5760
5761          Check_VMS (Mech_Name);
5762
5763          if Nkind (Class) /= N_Identifier then
5764             Bad_Class;
5765
5766          elsif Mech_Name_Id = Name_Descriptor
5767            and then Chars (Class) = Name_UBS
5768          then
5769             Set_Mechanism (Ent, By_Descriptor_UBS);
5770
5771          elsif Mech_Name_Id = Name_Descriptor
5772            and then Chars (Class) = Name_UBSB
5773          then
5774             Set_Mechanism (Ent, By_Descriptor_UBSB);
5775
5776          elsif Mech_Name_Id = Name_Descriptor
5777            and then Chars (Class) = Name_UBA
5778          then
5779             Set_Mechanism (Ent, By_Descriptor_UBA);
5780
5781          elsif Mech_Name_Id = Name_Descriptor
5782            and then Chars (Class) = Name_S
5783          then
5784             Set_Mechanism (Ent, By_Descriptor_S);
5785
5786          elsif Mech_Name_Id = Name_Descriptor
5787            and then Chars (Class) = Name_SB
5788          then
5789             Set_Mechanism (Ent, By_Descriptor_SB);
5790
5791          elsif Mech_Name_Id = Name_Descriptor
5792            and then Chars (Class) = Name_A
5793          then
5794             Set_Mechanism (Ent, By_Descriptor_A);
5795
5796          elsif Mech_Name_Id = Name_Descriptor
5797            and then Chars (Class) = Name_NCA
5798          then
5799             Set_Mechanism (Ent, By_Descriptor_NCA);
5800
5801          elsif Mech_Name_Id = Name_Short_Descriptor
5802            and then Chars (Class) = Name_UBS
5803          then
5804             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5805
5806          elsif Mech_Name_Id = Name_Short_Descriptor
5807            and then Chars (Class) = Name_UBSB
5808          then
5809             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5810
5811          elsif Mech_Name_Id = Name_Short_Descriptor
5812            and then Chars (Class) = Name_UBA
5813          then
5814             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5815
5816          elsif Mech_Name_Id = Name_Short_Descriptor
5817            and then Chars (Class) = Name_S
5818          then
5819             Set_Mechanism (Ent, By_Short_Descriptor_S);
5820
5821          elsif Mech_Name_Id = Name_Short_Descriptor
5822            and then Chars (Class) = Name_SB
5823          then
5824             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5825
5826          elsif Mech_Name_Id = Name_Short_Descriptor
5827            and then Chars (Class) = Name_A
5828          then
5829             Set_Mechanism (Ent, By_Short_Descriptor_A);
5830
5831          elsif Mech_Name_Id = Name_Short_Descriptor
5832            and then Chars (Class) = Name_NCA
5833          then
5834             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5835
5836          else
5837             Bad_Class;
5838          end if;
5839       end Set_Mechanism_Value;
5840
5841       ---------------------------
5842       -- Set_Ravenscar_Profile --
5843       ---------------------------
5844
5845       --  The tasks to be done here are
5846
5847       --    Set required policies
5848
5849       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5850       --      pragma Locking_Policy (Ceiling_Locking)
5851
5852       --    Set Detect_Blocking mode
5853
5854       --    Set required restrictions (see System.Rident for detailed list)
5855
5856       --    Set the No_Dependence rules
5857       --      No_Dependence => Ada.Asynchronous_Task_Control
5858       --      No_Dependence => Ada.Calendar
5859       --      No_Dependence => Ada.Execution_Time.Group_Budget
5860       --      No_Dependence => Ada.Execution_Time.Timers
5861       --      No_Dependence => Ada.Task_Attributes
5862       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
5863
5864       procedure Set_Ravenscar_Profile (N : Node_Id) is
5865          Prefix_Entity   : Entity_Id;
5866          Selector_Entity : Entity_Id;
5867          Prefix_Node     : Node_Id;
5868          Node            : Node_Id;
5869
5870       begin
5871          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5872
5873          if Task_Dispatching_Policy /= ' '
5874            and then Task_Dispatching_Policy /= 'F'
5875          then
5876             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5877             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5878
5879          --  Set the FIFO_Within_Priorities policy, but always preserve
5880          --  System_Location since we like the error message with the run time
5881          --  name.
5882
5883          else
5884             Task_Dispatching_Policy := 'F';
5885
5886             if Task_Dispatching_Policy_Sloc /= System_Location then
5887                Task_Dispatching_Policy_Sloc := Loc;
5888             end if;
5889          end if;
5890
5891          --  pragma Locking_Policy (Ceiling_Locking)
5892
5893          if Locking_Policy /= ' '
5894            and then Locking_Policy /= 'C'
5895          then
5896             Error_Msg_Sloc := Locking_Policy_Sloc;
5897             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5898
5899          --  Set the Ceiling_Locking policy, but preserve System_Location since
5900          --  we like the error message with the run time name.
5901
5902          else
5903             Locking_Policy := 'C';
5904
5905             if Locking_Policy_Sloc /= System_Location then
5906                Locking_Policy_Sloc := Loc;
5907             end if;
5908          end if;
5909
5910          --  pragma Detect_Blocking
5911
5912          Detect_Blocking := True;
5913
5914          --  Set the corresponding restrictions
5915
5916          Set_Profile_Restrictions
5917            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5918
5919          --  Set the No_Dependence restrictions
5920
5921          --  The following No_Dependence restrictions:
5922          --    No_Dependence => Ada.Asynchronous_Task_Control
5923          --    No_Dependence => Ada.Calendar
5924          --    No_Dependence => Ada.Task_Attributes
5925          --  are already set by previous call to Set_Profile_Restrictions.
5926
5927          --  Set the following restrictions which were added to Ada 2005:
5928          --    No_Dependence => Ada.Execution_Time.Group_Budget
5929          --    No_Dependence => Ada.Execution_Time.Timers
5930
5931          if Ada_Version >= Ada_2005 then
5932             Name_Buffer (1 .. 3) := "ada";
5933             Name_Len := 3;
5934
5935             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5936
5937             Name_Buffer (1 .. 14) := "execution_time";
5938             Name_Len := 14;
5939
5940             Selector_Entity := Make_Identifier (Loc, Name_Find);
5941
5942             Prefix_Node :=
5943               Make_Selected_Component
5944                 (Sloc          => Loc,
5945                  Prefix        => Prefix_Entity,
5946                  Selector_Name => Selector_Entity);
5947
5948             Name_Buffer (1 .. 13) := "group_budgets";
5949             Name_Len := 13;
5950
5951             Selector_Entity := Make_Identifier (Loc, Name_Find);
5952
5953             Node :=
5954               Make_Selected_Component
5955                 (Sloc          => Loc,
5956                  Prefix        => Prefix_Node,
5957                  Selector_Name => Selector_Entity);
5958
5959             Set_Restriction_No_Dependence
5960               (Unit    => Node,
5961                Warn    => Treat_Restrictions_As_Warnings,
5962                Profile => Ravenscar);
5963
5964             Name_Buffer (1 .. 6) := "timers";
5965             Name_Len := 6;
5966
5967             Selector_Entity := Make_Identifier (Loc, Name_Find);
5968
5969             Node :=
5970               Make_Selected_Component
5971                 (Sloc          => Loc,
5972                  Prefix        => Prefix_Node,
5973                  Selector_Name => Selector_Entity);
5974
5975             Set_Restriction_No_Dependence
5976               (Unit    => Node,
5977                Warn    => Treat_Restrictions_As_Warnings,
5978                Profile => Ravenscar);
5979          end if;
5980
5981          --  Set the following restrictions which was added to Ada 2012 (see
5982          --  AI-0171):
5983          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
5984
5985          if Ada_Version >= Ada_2012 then
5986             Name_Buffer (1 .. 6) := "system";
5987             Name_Len := 6;
5988
5989             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5990
5991             Name_Buffer (1 .. 15) := "multiprocessors";
5992             Name_Len := 15;
5993
5994             Selector_Entity := Make_Identifier (Loc, Name_Find);
5995
5996             Prefix_Node :=
5997               Make_Selected_Component
5998                 (Sloc          => Loc,
5999                  Prefix        => Prefix_Entity,
6000                  Selector_Name => Selector_Entity);
6001
6002             Name_Buffer (1 .. 19) := "dispatching_domains";
6003             Name_Len := 19;
6004
6005             Selector_Entity := Make_Identifier (Loc, Name_Find);
6006
6007             Node :=
6008               Make_Selected_Component
6009                 (Sloc          => Loc,
6010                  Prefix        => Prefix_Node,
6011                  Selector_Name => Selector_Entity);
6012
6013             Set_Restriction_No_Dependence
6014               (Unit    => Node,
6015                Warn    => Treat_Restrictions_As_Warnings,
6016                Profile => Ravenscar);
6017          end if;
6018       end Set_Ravenscar_Profile;
6019
6020    --  Start of processing for Analyze_Pragma
6021
6022    begin
6023       --  The following code is a defense against recursion. Not clear that
6024       --  this can happen legitimately, but perhaps some error situations
6025       --  can cause it, and we did see this recursion during testing.
6026
6027       if Analyzed (N) then
6028          return;
6029       else
6030          Set_Analyzed (N, True);
6031       end if;
6032
6033       --  Deal with unrecognized pragma
6034
6035       if not Is_Pragma_Name (Pname) then
6036          if Warn_On_Unrecognized_Pragma then
6037             Error_Msg_Name_1 := Pname;
6038             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6039
6040             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6041                if Is_Bad_Spelling_Of (Pname, PN) then
6042                   Error_Msg_Name_1 := PN;
6043                   Error_Msg_N -- CODEFIX
6044                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6045                   exit;
6046                end if;
6047             end loop;
6048          end if;
6049
6050          return;
6051       end if;
6052
6053       --  Here to start processing for recognized pragma
6054
6055       Prag_Id := Get_Pragma_Id (Pname);
6056
6057       --  Preset arguments
6058
6059       Arg_Count := 0;
6060       Arg1      := Empty;
6061       Arg2      := Empty;
6062       Arg3      := Empty;
6063       Arg4      := Empty;
6064
6065       if Present (Pragma_Argument_Associations (N)) then
6066          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6067          Arg1 := First (Pragma_Argument_Associations (N));
6068
6069          if Present (Arg1) then
6070             Arg2 := Next (Arg1);
6071
6072             if Present (Arg2) then
6073                Arg3 := Next (Arg2);
6074
6075                if Present (Arg3) then
6076                   Arg4 := Next (Arg3);
6077                end if;
6078             end if;
6079          end if;
6080       end if;
6081
6082       --  An enumeration type defines the pragmas that are supported by the
6083       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6084       --  into the corresponding enumeration value for the following case.
6085
6086       case Prag_Id is
6087
6088          -----------------
6089          -- Abort_Defer --
6090          -----------------
6091
6092          --  pragma Abort_Defer;
6093
6094          when Pragma_Abort_Defer =>
6095             GNAT_Pragma;
6096             Check_Arg_Count (0);
6097
6098             --  The only required semantic processing is to check the
6099             --  placement. This pragma must appear at the start of the
6100             --  statement sequence of a handled sequence of statements.
6101
6102             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6103               or else N /= First (Statements (Parent (N)))
6104             then
6105                Pragma_Misplaced;
6106             end if;
6107
6108          ------------
6109          -- Ada_83 --
6110          ------------
6111
6112          --  pragma Ada_83;
6113
6114          --  Note: this pragma also has some specific processing in Par.Prag
6115          --  because we want to set the Ada version mode during parsing.
6116
6117          when Pragma_Ada_83 =>
6118             GNAT_Pragma;
6119             Check_Arg_Count (0);
6120
6121             --  We really should check unconditionally for proper configuration
6122             --  pragma placement, since we really don't want mixed Ada modes
6123             --  within a single unit, and the GNAT reference manual has always
6124             --  said this was a configuration pragma, but we did not check and
6125             --  are hesitant to add the check now.
6126
6127             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6128             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6129             --  or Ada 2012 mode.
6130
6131             if Ada_Version >= Ada_2005 then
6132                Check_Valid_Configuration_Pragma;
6133             end if;
6134
6135             --  Now set Ada 83 mode
6136
6137             Ada_Version := Ada_83;
6138             Ada_Version_Explicit := Ada_Version;
6139
6140          ------------
6141          -- Ada_95 --
6142          ------------
6143
6144          --  pragma Ada_95;
6145
6146          --  Note: this pragma also has some specific processing in Par.Prag
6147          --  because we want to set the Ada 83 version mode during parsing.
6148
6149          when Pragma_Ada_95 =>
6150             GNAT_Pragma;
6151             Check_Arg_Count (0);
6152
6153             --  We really should check unconditionally for proper configuration
6154             --  pragma placement, since we really don't want mixed Ada modes
6155             --  within a single unit, and the GNAT reference manual has always
6156             --  said this was a configuration pragma, but we did not check and
6157             --  are hesitant to add the check now.
6158
6159             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6160             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6161
6162             if Ada_Version >= Ada_2005 then
6163                Check_Valid_Configuration_Pragma;
6164             end if;
6165
6166             --  Now set Ada 95 mode
6167
6168             Ada_Version := Ada_95;
6169             Ada_Version_Explicit := Ada_Version;
6170
6171          ---------------------
6172          -- Ada_05/Ada_2005 --
6173          ---------------------
6174
6175          --  pragma Ada_05;
6176          --  pragma Ada_05 (LOCAL_NAME);
6177
6178          --  pragma Ada_2005;
6179          --  pragma Ada_2005 (LOCAL_NAME):
6180
6181          --  Note: these pragmas also have some specific processing in Par.Prag
6182          --  because we want to set the Ada 2005 version mode during parsing.
6183
6184          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6185             E_Id : Node_Id;
6186
6187          begin
6188             GNAT_Pragma;
6189
6190             if Arg_Count = 1 then
6191                Check_Arg_Is_Local_Name (Arg1);
6192                E_Id := Get_Pragma_Arg (Arg1);
6193
6194                if Etype (E_Id) = Any_Type then
6195                   return;
6196                end if;
6197
6198                Set_Is_Ada_2005_Only (Entity (E_Id));
6199
6200             else
6201                Check_Arg_Count (0);
6202
6203                --  For Ada_2005 we unconditionally enforce the documented
6204                --  configuration pragma placement, since we do not want to
6205                --  tolerate mixed modes in a unit involving Ada 2005. That
6206                --  would cause real difficulties for those cases where there
6207                --  are incompatibilities between Ada 95 and Ada 2005.
6208
6209                Check_Valid_Configuration_Pragma;
6210
6211                --  Now set appropriate Ada mode
6212
6213                Ada_Version          := Ada_2005;
6214                Ada_Version_Explicit := Ada_2005;
6215             end if;
6216          end;
6217
6218          ---------------------
6219          -- Ada_12/Ada_2012 --
6220          ---------------------
6221
6222          --  pragma Ada_12;
6223          --  pragma Ada_12 (LOCAL_NAME);
6224
6225          --  pragma Ada_2012;
6226          --  pragma Ada_2012 (LOCAL_NAME):
6227
6228          --  Note: these pragmas also have some specific processing in Par.Prag
6229          --  because we want to set the Ada 2012 version mode during parsing.
6230
6231          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6232             E_Id : Node_Id;
6233
6234          begin
6235             GNAT_Pragma;
6236
6237             if Arg_Count = 1 then
6238                Check_Arg_Is_Local_Name (Arg1);
6239                E_Id := Get_Pragma_Arg (Arg1);
6240
6241                if Etype (E_Id) = Any_Type then
6242                   return;
6243                end if;
6244
6245                Set_Is_Ada_2012_Only (Entity (E_Id));
6246
6247             else
6248                Check_Arg_Count (0);
6249
6250                --  For Ada_2012 we unconditionally enforce the documented
6251                --  configuration pragma placement, since we do not want to
6252                --  tolerate mixed modes in a unit involving Ada 2012. That
6253                --  would cause real difficulties for those cases where there
6254                --  are incompatibilities between Ada 95 and Ada 2012. We could
6255                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6256
6257                Check_Valid_Configuration_Pragma;
6258
6259                --  Now set appropriate Ada mode
6260
6261                Ada_Version          := Ada_2012;
6262                Ada_Version_Explicit := Ada_2012;
6263             end if;
6264          end;
6265
6266          ----------------------
6267          -- All_Calls_Remote --
6268          ----------------------
6269
6270          --  pragma All_Calls_Remote [(library_package_NAME)];
6271
6272          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6273             Lib_Entity : Entity_Id;
6274
6275          begin
6276             Check_Ada_83_Warning;
6277             Check_Valid_Library_Unit_Pragma;
6278
6279             if Nkind (N) = N_Null_Statement then
6280                return;
6281             end if;
6282
6283             Lib_Entity := Find_Lib_Unit_Name;
6284
6285             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6286
6287             if Present (Lib_Entity)
6288               and then not Debug_Flag_U
6289             then
6290                if not Is_Remote_Call_Interface (Lib_Entity) then
6291                   Error_Pragma ("pragma% only apply to rci unit");
6292
6293                --  Set flag for entity of the library unit
6294
6295                else
6296                   Set_Has_All_Calls_Remote (Lib_Entity);
6297                end if;
6298
6299             end if;
6300          end All_Calls_Remote;
6301
6302          --------------
6303          -- Annotate --
6304          --------------
6305
6306          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6307          --  ARG ::= NAME | EXPRESSION
6308
6309          --  The first two arguments are by convention intended to refer to an
6310          --  external tool and a tool-specific function. These arguments are
6311          --  not analyzed.
6312
6313          when Pragma_Annotate => Annotate : declare
6314             Arg : Node_Id;
6315             Exp : Node_Id;
6316
6317          begin
6318             GNAT_Pragma;
6319             Check_At_Least_N_Arguments (1);
6320             Check_Arg_Is_Identifier (Arg1);
6321             Check_No_Identifiers;
6322             Store_Note (N);
6323
6324             --  Second parameter is optional, it is never analyzed
6325
6326             if No (Arg2) then
6327                null;
6328
6329             --  Here if we have a second parameter
6330
6331             else
6332                --  Second parameter must be identifier
6333
6334                Check_Arg_Is_Identifier (Arg2);
6335
6336                --  Process remaining parameters if any
6337
6338                Arg := Next (Arg2);
6339                while Present (Arg) loop
6340                   Exp := Get_Pragma_Arg (Arg);
6341                   Analyze (Exp);
6342
6343                   if Is_Entity_Name (Exp) then
6344                      null;
6345
6346                   --  For string literals, we assume Standard_String as the
6347                   --  type, unless the string contains wide or wide_wide
6348                   --  characters.
6349
6350                   elsif Nkind (Exp) = N_String_Literal then
6351                      if Has_Wide_Wide_Character (Exp) then
6352                         Resolve (Exp, Standard_Wide_Wide_String);
6353                      elsif Has_Wide_Character (Exp) then
6354                         Resolve (Exp, Standard_Wide_String);
6355                      else
6356                         Resolve (Exp, Standard_String);
6357                      end if;
6358
6359                   elsif Is_Overloaded (Exp) then
6360                         Error_Pragma_Arg
6361                           ("ambiguous argument for pragma%", Exp);
6362
6363                   else
6364                      Resolve (Exp);
6365                   end if;
6366
6367                   Next (Arg);
6368                end loop;
6369             end if;
6370          end Annotate;
6371
6372          ------------
6373          -- Assert --
6374          ------------
6375
6376          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6377          --                 [, [Message =>] Static_String_EXPRESSION]);
6378
6379          when Pragma_Assert => Assert : declare
6380             Expr : Node_Id;
6381             Newa : List_Id;
6382
6383          begin
6384             Ada_2005_Pragma;
6385             Check_At_Least_N_Arguments (1);
6386             Check_At_Most_N_Arguments (2);
6387             Check_Arg_Order ((Name_Check, Name_Message));
6388             Check_Optional_Identifier (Arg1, Name_Check);
6389
6390             --  We treat pragma Assert as equivalent to:
6391
6392             --    pragma Check (Assertion, condition [, msg]);
6393
6394             --  So rewrite pragma in this manner, and analyze the result
6395
6396             Expr := Get_Pragma_Arg (Arg1);
6397             Newa := New_List (
6398               Make_Pragma_Argument_Association (Loc,
6399                 Expression => Make_Identifier (Loc, Name_Assertion)),
6400
6401               Make_Pragma_Argument_Association (Sloc (Expr),
6402                 Expression => Expr));
6403
6404             if Arg_Count > 1 then
6405                Check_Optional_Identifier (Arg2, Name_Message);
6406                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6407                Append_To (Newa, Relocate_Node (Arg2));
6408             end if;
6409
6410             Rewrite (N,
6411               Make_Pragma (Loc,
6412                 Chars => Name_Check,
6413                 Pragma_Argument_Associations => Newa));
6414             Analyze (N);
6415          end Assert;
6416
6417          ----------------------
6418          -- Assertion_Policy --
6419          ----------------------
6420
6421          --  pragma Assertion_Policy (Check | Ignore)
6422
6423          when Pragma_Assertion_Policy => Assertion_Policy : declare
6424             Policy : Node_Id;
6425
6426          begin
6427             Ada_2005_Pragma;
6428             Check_Valid_Configuration_Pragma;
6429             Check_Arg_Count (1);
6430             Check_No_Identifiers;
6431             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
6432
6433             --  We treat pragma Assertion_Policy as equivalent to:
6434
6435             --    pragma Check_Policy (Assertion, policy)
6436
6437             --  So rewrite the pragma in that manner and link on to the chain
6438             --  of Check_Policy pragmas, marking the pragma as analyzed.
6439
6440             Policy := Get_Pragma_Arg (Arg1);
6441
6442             Rewrite (N,
6443               Make_Pragma (Loc,
6444                 Chars => Name_Check_Policy,
6445
6446                 Pragma_Argument_Associations => New_List (
6447                   Make_Pragma_Argument_Association (Loc,
6448                     Expression => Make_Identifier (Loc, Name_Assertion)),
6449
6450                   Make_Pragma_Argument_Association (Loc,
6451                     Expression =>
6452                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6453
6454             Set_Analyzed (N);
6455             Set_Next_Pragma (N, Opt.Check_Policy_List);
6456             Opt.Check_Policy_List := N;
6457          end Assertion_Policy;
6458
6459          ------------------------------
6460          -- Assume_No_Invalid_Values --
6461          ------------------------------
6462
6463          --  pragma Assume_No_Invalid_Values (On | Off);
6464
6465          when Pragma_Assume_No_Invalid_Values =>
6466             GNAT_Pragma;
6467             Check_Valid_Configuration_Pragma;
6468             Check_Arg_Count (1);
6469             Check_No_Identifiers;
6470             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6471
6472             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6473                Assume_No_Invalid_Values := True;
6474             else
6475                Assume_No_Invalid_Values := False;
6476             end if;
6477
6478          ---------------
6479          -- AST_Entry --
6480          ---------------
6481
6482          --  pragma AST_Entry (entry_IDENTIFIER);
6483
6484          when Pragma_AST_Entry => AST_Entry : declare
6485             Ent : Node_Id;
6486
6487          begin
6488             GNAT_Pragma;
6489             Check_VMS (N);
6490             Check_Arg_Count (1);
6491             Check_No_Identifiers;
6492             Check_Arg_Is_Local_Name (Arg1);
6493             Ent := Entity (Get_Pragma_Arg (Arg1));
6494
6495             --  Note: the implementation of the AST_Entry pragma could handle
6496             --  the entry family case fine, but for now we are consistent with
6497             --  the DEC rules, and do not allow the pragma, which of course
6498             --  has the effect of also forbidding the attribute.
6499
6500             if Ekind (Ent) /= E_Entry then
6501                Error_Pragma_Arg
6502                  ("pragma% argument must be simple entry name", Arg1);
6503
6504             elsif Is_AST_Entry (Ent) then
6505                Error_Pragma_Arg
6506                  ("duplicate % pragma for entry", Arg1);
6507
6508             elsif Has_Homonym (Ent) then
6509                Error_Pragma_Arg
6510                  ("pragma% argument cannot specify overloaded entry", Arg1);
6511
6512             else
6513                declare
6514                   FF : constant Entity_Id := First_Formal (Ent);
6515
6516                begin
6517                   if Present (FF) then
6518                      if Present (Next_Formal (FF)) then
6519                         Error_Pragma_Arg
6520                           ("entry for pragma% can have only one argument",
6521                            Arg1);
6522
6523                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6524                         Error_Pragma_Arg
6525                           ("entry parameter for pragma% must have mode IN",
6526                            Arg1);
6527                      end if;
6528                   end if;
6529                end;
6530
6531                Set_Is_AST_Entry (Ent);
6532             end if;
6533          end AST_Entry;
6534
6535          ------------------
6536          -- Asynchronous --
6537          ------------------
6538
6539          --  pragma Asynchronous (LOCAL_NAME);
6540
6541          when Pragma_Asynchronous => Asynchronous : declare
6542             Nm     : Entity_Id;
6543             C_Ent  : Entity_Id;
6544             L      : List_Id;
6545             S      : Node_Id;
6546             N      : Node_Id;
6547             Formal : Entity_Id;
6548
6549             procedure Process_Async_Pragma;
6550             --  Common processing for procedure and access-to-procedure case
6551
6552             --------------------------
6553             -- Process_Async_Pragma --
6554             --------------------------
6555
6556             procedure Process_Async_Pragma is
6557             begin
6558                if No (L) then
6559                   Set_Is_Asynchronous (Nm);
6560                   return;
6561                end if;
6562
6563                --  The formals should be of mode IN (RM E.4.1(6))
6564
6565                S := First (L);
6566                while Present (S) loop
6567                   Formal := Defining_Identifier (S);
6568
6569                   if Nkind (Formal) = N_Defining_Identifier
6570                     and then Ekind (Formal) /= E_In_Parameter
6571                   then
6572                      Error_Pragma_Arg
6573                        ("pragma% procedure can only have IN parameter",
6574                         Arg1);
6575                   end if;
6576
6577                   Next (S);
6578                end loop;
6579
6580                Set_Is_Asynchronous (Nm);
6581             end Process_Async_Pragma;
6582
6583          --  Start of processing for pragma Asynchronous
6584
6585          begin
6586             Check_Ada_83_Warning;
6587             Check_No_Identifiers;
6588             Check_Arg_Count (1);
6589             Check_Arg_Is_Local_Name (Arg1);
6590
6591             if Debug_Flag_U then
6592                return;
6593             end if;
6594
6595             C_Ent := Cunit_Entity (Current_Sem_Unit);
6596             Analyze (Get_Pragma_Arg (Arg1));
6597             Nm := Entity (Get_Pragma_Arg (Arg1));
6598
6599             if not Is_Remote_Call_Interface (C_Ent)
6600               and then not Is_Remote_Types (C_Ent)
6601             then
6602                --  This pragma should only appear in an RCI or Remote Types
6603                --  unit (RM E.4.1(4)).
6604
6605                Error_Pragma
6606                  ("pragma% not in Remote_Call_Interface or " &
6607                   "Remote_Types unit");
6608             end if;
6609
6610             if Ekind (Nm) = E_Procedure
6611               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6612             then
6613                if not Is_Remote_Call_Interface (Nm) then
6614                   Error_Pragma_Arg
6615                     ("pragma% cannot be applied on non-remote procedure",
6616                      Arg1);
6617                end if;
6618
6619                L := Parameter_Specifications (Parent (Nm));
6620                Process_Async_Pragma;
6621                return;
6622
6623             elsif Ekind (Nm) = E_Function then
6624                Error_Pragma_Arg
6625                  ("pragma% cannot be applied to function", Arg1);
6626
6627             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6628                   if Is_Record_Type (Nm) then
6629
6630                   --  A record type that is the Equivalent_Type for a remote
6631                   --  access-to-subprogram type.
6632
6633                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6634
6635                   else
6636                      --  A non-expanded RAS type (distribution is not enabled)
6637
6638                      N := Declaration_Node (Nm);
6639                   end if;
6640
6641                if Nkind (N) = N_Full_Type_Declaration
6642                  and then Nkind (Type_Definition (N)) =
6643                                      N_Access_Procedure_Definition
6644                then
6645                   L := Parameter_Specifications (Type_Definition (N));
6646                   Process_Async_Pragma;
6647
6648                   if Is_Asynchronous (Nm)
6649                     and then Expander_Active
6650                     and then Get_PCS_Name /= Name_No_DSA
6651                   then
6652                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6653                   end if;
6654
6655                else
6656                   Error_Pragma_Arg
6657                     ("pragma% cannot reference access-to-function type",
6658                     Arg1);
6659                end if;
6660
6661             --  Only other possibility is Access-to-class-wide type
6662
6663             elsif Is_Access_Type (Nm)
6664               and then Is_Class_Wide_Type (Designated_Type (Nm))
6665             then
6666                Check_First_Subtype (Arg1);
6667                Set_Is_Asynchronous (Nm);
6668                if Expander_Active then
6669                   RACW_Type_Is_Asynchronous (Nm);
6670                end if;
6671
6672             else
6673                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6674             end if;
6675          end Asynchronous;
6676
6677          ------------
6678          -- Atomic --
6679          ------------
6680
6681          --  pragma Atomic (LOCAL_NAME);
6682
6683          when Pragma_Atomic =>
6684             Process_Atomic_Shared_Volatile;
6685
6686          -----------------------
6687          -- Atomic_Components --
6688          -----------------------
6689
6690          --  pragma Atomic_Components (array_LOCAL_NAME);
6691
6692          --  This processing is shared by Volatile_Components
6693
6694          when Pragma_Atomic_Components   |
6695               Pragma_Volatile_Components =>
6696
6697          Atomic_Components : declare
6698             E_Id : Node_Id;
6699             E    : Entity_Id;
6700             D    : Node_Id;
6701             K    : Node_Kind;
6702
6703          begin
6704             Check_Ada_83_Warning;
6705             Check_No_Identifiers;
6706             Check_Arg_Count (1);
6707             Check_Arg_Is_Local_Name (Arg1);
6708             E_Id := Get_Pragma_Arg (Arg1);
6709
6710             if Etype (E_Id) = Any_Type then
6711                return;
6712             end if;
6713
6714             E := Entity (E_Id);
6715
6716             Check_Duplicate_Pragma (E);
6717
6718             if Rep_Item_Too_Early (E, N)
6719                  or else
6720                Rep_Item_Too_Late (E, N)
6721             then
6722                return;
6723             end if;
6724
6725             D := Declaration_Node (E);
6726             K := Nkind (D);
6727
6728             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6729               or else
6730                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6731                    and then Nkind (D) = N_Object_Declaration
6732                    and then Nkind (Object_Definition (D)) =
6733                                        N_Constrained_Array_Definition)
6734             then
6735                --  The flag is set on the object, or on the base type
6736
6737                if Nkind (D) /= N_Object_Declaration then
6738                   E := Base_Type (E);
6739                end if;
6740
6741                Set_Has_Volatile_Components (E);
6742
6743                if Prag_Id = Pragma_Atomic_Components then
6744                   Set_Has_Atomic_Components (E);
6745                end if;
6746
6747             else
6748                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6749             end if;
6750          end Atomic_Components;
6751
6752          --------------------
6753          -- Attach_Handler --
6754          --------------------
6755
6756          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6757
6758          when Pragma_Attach_Handler =>
6759             Check_Ada_83_Warning;
6760             Check_No_Identifiers;
6761             Check_Arg_Count (2);
6762
6763             if No_Run_Time_Mode then
6764                Error_Msg_CRT ("Attach_Handler pragma", N);
6765             else
6766                Check_Interrupt_Or_Attach_Handler;
6767
6768                --  The expression that designates the attribute may depend on a
6769                --  discriminant, and is therefore a per- object expression, to
6770                --  be expanded in the init proc. If expansion is enabled, then
6771                --  perform semantic checks on a copy only.
6772
6773                if Expander_Active then
6774                   declare
6775                      Temp : constant Node_Id :=
6776                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6777                   begin
6778                      Set_Parent (Temp, N);
6779                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6780                   end;
6781
6782                else
6783                   Analyze (Get_Pragma_Arg (Arg2));
6784                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6785                end if;
6786
6787                Process_Interrupt_Or_Attach_Handler;
6788             end if;
6789
6790          --------------------
6791          -- C_Pass_By_Copy --
6792          --------------------
6793
6794          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6795
6796          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6797             Arg : Node_Id;
6798             Val : Uint;
6799
6800          begin
6801             GNAT_Pragma;
6802             Check_Valid_Configuration_Pragma;
6803             Check_Arg_Count (1);
6804             Check_Optional_Identifier (Arg1, "max_size");
6805
6806             Arg := Get_Pragma_Arg (Arg1);
6807             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6808
6809             Val := Expr_Value (Arg);
6810
6811             if Val <= 0 then
6812                Error_Pragma_Arg
6813                  ("maximum size for pragma% must be positive", Arg1);
6814
6815             elsif UI_Is_In_Int_Range (Val) then
6816                Default_C_Record_Mechanism := UI_To_Int (Val);
6817
6818             --  If a giant value is given, Int'Last will do well enough.
6819             --  If sometime someone complains that a record larger than
6820             --  two gigabytes is not copied, we will worry about it then!
6821
6822             else
6823                Default_C_Record_Mechanism := Mechanism_Type'Last;
6824             end if;
6825          end C_Pass_By_Copy;
6826
6827          -----------
6828          -- Check --
6829          -----------
6830
6831          --  pragma Check ([Name    =>] IDENTIFIER,
6832          --                [Check   =>] Boolean_EXPRESSION
6833          --              [,[Message =>] String_EXPRESSION]);
6834
6835          when Pragma_Check => Check : declare
6836             Expr : Node_Id;
6837             Eloc : Source_Ptr;
6838
6839             Check_On : Boolean;
6840             --  Set True if category of assertions referenced by Name enabled
6841
6842          begin
6843             GNAT_Pragma;
6844             Check_At_Least_N_Arguments (2);
6845             Check_At_Most_N_Arguments (3);
6846             Check_Optional_Identifier (Arg1, Name_Name);
6847             Check_Optional_Identifier (Arg2, Name_Check);
6848
6849             if Arg_Count = 3 then
6850                Check_Optional_Identifier (Arg3, Name_Message);
6851                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6852             end if;
6853
6854             Check_Arg_Is_Identifier (Arg1);
6855
6856             --  Indicate if pragma is enabled. The Original_Node reference here
6857             --  is to deal with pragma Assert rewritten as a Check pragma.
6858
6859             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6860
6861             if Check_On then
6862                Set_SCO_Pragma_Enabled (Loc);
6863             end if;
6864
6865             --  If expansion is active and the check is not enabled then we
6866             --  rewrite the Check as:
6867
6868             --    if False and then condition then
6869             --       null;
6870             --    end if;
6871
6872             --  The reason we do this rewriting during semantic analysis rather
6873             --  than as part of normal expansion is that we cannot analyze and
6874             --  expand the code for the boolean expression directly, or it may
6875             --  cause insertion of actions that would escape the attempt to
6876             --  suppress the check code.
6877
6878             --  Note that the Sloc for the if statement corresponds to the
6879             --  argument condition, not the pragma itself. The reason for this
6880             --  is that we may generate a warning if the condition is False at
6881             --  compile time, and we do not want to delete this warning when we
6882             --  delete the if statement.
6883
6884             Expr := Get_Pragma_Arg (Arg2);
6885
6886             if Expander_Active and then not Check_On then
6887                Eloc := Sloc (Expr);
6888
6889                Rewrite (N,
6890                  Make_If_Statement (Eloc,
6891                    Condition =>
6892                      Make_And_Then (Eloc,
6893                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
6894                        Right_Opnd => Expr),
6895                    Then_Statements => New_List (
6896                      Make_Null_Statement (Eloc))));
6897
6898                Analyze (N);
6899
6900             --  Check is active
6901
6902             else
6903                Analyze_And_Resolve (Expr, Any_Boolean);
6904             end if;
6905          end Check;
6906
6907          ----------------
6908          -- Check_Name --
6909          ----------------
6910
6911          --  pragma Check_Name (check_IDENTIFIER);
6912
6913          when Pragma_Check_Name =>
6914             Check_No_Identifiers;
6915             GNAT_Pragma;
6916             Check_Valid_Configuration_Pragma;
6917             Check_Arg_Count (1);
6918             Check_Arg_Is_Identifier (Arg1);
6919
6920             declare
6921                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6922
6923             begin
6924                for J in Check_Names.First .. Check_Names.Last loop
6925                   if Check_Names.Table (J) = Nam then
6926                      return;
6927                   end if;
6928                end loop;
6929
6930                Check_Names.Append (Nam);
6931             end;
6932
6933          ------------------
6934          -- Check_Policy --
6935          ------------------
6936
6937          --  pragma Check_Policy (
6938          --    [Name   =>] IDENTIFIER,
6939          --    [Policy =>] POLICY_IDENTIFIER);
6940
6941          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | IGNORE
6942
6943          --  Note: this is a configuration pragma, but it is allowed to appear
6944          --  anywhere else.
6945
6946          when Pragma_Check_Policy =>
6947             GNAT_Pragma;
6948             Check_Arg_Count (2);
6949             Check_Optional_Identifier (Arg1, Name_Name);
6950             Check_Optional_Identifier (Arg2, Name_Policy);
6951             Check_Arg_Is_One_Of
6952               (Arg2, Name_On, Name_Off, Name_Check, Name_Ignore);
6953
6954             --  A Check_Policy pragma can appear either as a configuration
6955             --  pragma, or in a declarative part or a package spec (see RM
6956             --  11.5(5) for rules for Suppress/Unsuppress which are also
6957             --  followed for Check_Policy).
6958
6959             if not Is_Configuration_Pragma then
6960                Check_Is_In_Decl_Part_Or_Package_Spec;
6961             end if;
6962
6963             Set_Next_Pragma (N, Opt.Check_Policy_List);
6964             Opt.Check_Policy_List := N;
6965
6966          ---------------------
6967          -- CIL_Constructor --
6968          ---------------------
6969
6970          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
6971
6972          --  Processing for this pragma is shared with Java_Constructor
6973
6974          -------------
6975          -- Comment --
6976          -------------
6977
6978          --  pragma Comment (static_string_EXPRESSION)
6979
6980          --  Processing for pragma Comment shares the circuitry for pragma
6981          --  Ident. The only differences are that Ident enforces a limit of 31
6982          --  characters on its argument, and also enforces limitations on
6983          --  placement for DEC compatibility. Pragma Comment shares neither of
6984          --  these restrictions.
6985
6986          -------------------
6987          -- Common_Object --
6988          -------------------
6989
6990          --  pragma Common_Object (
6991          --        [Internal =>] LOCAL_NAME
6992          --     [, [External =>] EXTERNAL_SYMBOL]
6993          --     [, [Size     =>] EXTERNAL_SYMBOL]);
6994
6995          --  Processing for this pragma is shared with Psect_Object
6996
6997          ------------------------
6998          -- Compile_Time_Error --
6999          ------------------------
7000
7001          --  pragma Compile_Time_Error
7002          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7003
7004          when Pragma_Compile_Time_Error =>
7005             GNAT_Pragma;
7006             Process_Compile_Time_Warning_Or_Error;
7007
7008          --------------------------
7009          -- Compile_Time_Warning --
7010          --------------------------
7011
7012          --  pragma Compile_Time_Warning
7013          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7014
7015          when Pragma_Compile_Time_Warning =>
7016             GNAT_Pragma;
7017             Process_Compile_Time_Warning_Or_Error;
7018
7019          -------------------
7020          -- Compiler_Unit --
7021          -------------------
7022
7023          when Pragma_Compiler_Unit =>
7024             GNAT_Pragma;
7025             Check_Arg_Count (0);
7026             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7027
7028          -----------------------------
7029          -- Complete_Representation --
7030          -----------------------------
7031
7032          --  pragma Complete_Representation;
7033
7034          when Pragma_Complete_Representation =>
7035             GNAT_Pragma;
7036             Check_Arg_Count (0);
7037
7038             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7039                Error_Pragma
7040                  ("pragma & must appear within record representation clause");
7041             end if;
7042
7043          ----------------------------
7044          -- Complex_Representation --
7045          ----------------------------
7046
7047          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7048
7049          when Pragma_Complex_Representation => Complex_Representation : declare
7050             E_Id : Entity_Id;
7051             E    : Entity_Id;
7052             Ent  : Entity_Id;
7053
7054          begin
7055             GNAT_Pragma;
7056             Check_Arg_Count (1);
7057             Check_Optional_Identifier (Arg1, Name_Entity);
7058             Check_Arg_Is_Local_Name (Arg1);
7059             E_Id := Get_Pragma_Arg (Arg1);
7060
7061             if Etype (E_Id) = Any_Type then
7062                return;
7063             end if;
7064
7065             E := Entity (E_Id);
7066
7067             if not Is_Record_Type (E) then
7068                Error_Pragma_Arg
7069                  ("argument for pragma% must be record type", Arg1);
7070             end if;
7071
7072             Ent := First_Entity (E);
7073
7074             if No (Ent)
7075               or else No (Next_Entity (Ent))
7076               or else Present (Next_Entity (Next_Entity (Ent)))
7077               or else not Is_Floating_Point_Type (Etype (Ent))
7078               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7079             then
7080                Error_Pragma_Arg
7081                  ("record for pragma% must have two fields of the same "
7082                   & "floating-point type", Arg1);
7083
7084             else
7085                Set_Has_Complex_Representation (Base_Type (E));
7086
7087                --  We need to treat the type has having a non-standard
7088                --  representation, for back-end purposes, even though in
7089                --  general a complex will have the default representation
7090                --  of a record with two real components.
7091
7092                Set_Has_Non_Standard_Rep (Base_Type (E));
7093             end if;
7094          end Complex_Representation;
7095
7096          -------------------------
7097          -- Component_Alignment --
7098          -------------------------
7099
7100          --  pragma Component_Alignment (
7101          --        [Form =>] ALIGNMENT_CHOICE
7102          --     [, [Name =>] type_LOCAL_NAME]);
7103          --
7104          --   ALIGNMENT_CHOICE ::=
7105          --     Component_Size
7106          --   | Component_Size_4
7107          --   | Storage_Unit
7108          --   | Default
7109
7110          when Pragma_Component_Alignment => Component_AlignmentP : declare
7111             Args  : Args_List (1 .. 2);
7112             Names : constant Name_List (1 .. 2) := (
7113                       Name_Form,
7114                       Name_Name);
7115
7116             Form  : Node_Id renames Args (1);
7117             Name  : Node_Id renames Args (2);
7118
7119             Atype : Component_Alignment_Kind;
7120             Typ   : Entity_Id;
7121
7122          begin
7123             GNAT_Pragma;
7124             Gather_Associations (Names, Args);
7125
7126             if No (Form) then
7127                Error_Pragma ("missing Form argument for pragma%");
7128             end if;
7129
7130             Check_Arg_Is_Identifier (Form);
7131
7132             --  Get proper alignment, note that Default = Component_Size on all
7133             --  machines we have so far, and we want to set this value rather
7134             --  than the default value to indicate that it has been explicitly
7135             --  set (and thus will not get overridden by the default component
7136             --  alignment for the current scope)
7137
7138             if Chars (Form) = Name_Component_Size then
7139                Atype := Calign_Component_Size;
7140
7141             elsif Chars (Form) = Name_Component_Size_4 then
7142                Atype := Calign_Component_Size_4;
7143
7144             elsif Chars (Form) = Name_Default then
7145                Atype := Calign_Component_Size;
7146
7147             elsif Chars (Form) = Name_Storage_Unit then
7148                Atype := Calign_Storage_Unit;
7149
7150             else
7151                Error_Pragma_Arg
7152                  ("invalid Form parameter for pragma%", Form);
7153             end if;
7154
7155             --  Case with no name, supplied, affects scope table entry
7156
7157             if No (Name) then
7158                Scope_Stack.Table
7159                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7160
7161             --  Case of name supplied
7162
7163             else
7164                Check_Arg_Is_Local_Name (Name);
7165                Find_Type (Name);
7166                Typ := Entity (Name);
7167
7168                if Typ = Any_Type
7169                  or else Rep_Item_Too_Early (Typ, N)
7170                then
7171                   return;
7172                else
7173                   Typ := Underlying_Type (Typ);
7174                end if;
7175
7176                if not Is_Record_Type (Typ)
7177                  and then not Is_Array_Type (Typ)
7178                then
7179                   Error_Pragma_Arg
7180                     ("Name parameter of pragma% must identify record or " &
7181                      "array type", Name);
7182                end if;
7183
7184                --  An explicit Component_Alignment pragma overrides an
7185                --  implicit pragma Pack, but not an explicit one.
7186
7187                if not Has_Pragma_Pack (Base_Type (Typ)) then
7188                   Set_Is_Packed (Base_Type (Typ), False);
7189                   Set_Component_Alignment (Base_Type (Typ), Atype);
7190                end if;
7191             end if;
7192          end Component_AlignmentP;
7193
7194          ----------------
7195          -- Controlled --
7196          ----------------
7197
7198          --  pragma Controlled (first_subtype_LOCAL_NAME);
7199
7200          when Pragma_Controlled => Controlled : declare
7201             Arg : Node_Id;
7202
7203          begin
7204             Check_No_Identifiers;
7205             Check_Arg_Count (1);
7206             Check_Arg_Is_Local_Name (Arg1);
7207             Arg := Get_Pragma_Arg (Arg1);
7208
7209             if not Is_Entity_Name (Arg)
7210               or else not Is_Access_Type (Entity (Arg))
7211             then
7212                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7213             else
7214                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7215             end if;
7216          end Controlled;
7217
7218          ----------------
7219          -- Convention --
7220          ----------------
7221
7222          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7223          --    [Entity =>] LOCAL_NAME);
7224
7225          when Pragma_Convention => Convention : declare
7226             C : Convention_Id;
7227             E : Entity_Id;
7228             pragma Warnings (Off, C);
7229             pragma Warnings (Off, E);
7230          begin
7231             Check_Arg_Order ((Name_Convention, Name_Entity));
7232             Check_Ada_83_Warning;
7233             Check_Arg_Count (2);
7234             Process_Convention (C, E);
7235          end Convention;
7236
7237          ---------------------------
7238          -- Convention_Identifier --
7239          ---------------------------
7240
7241          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7242          --    [Convention =>] convention_IDENTIFIER);
7243
7244          when Pragma_Convention_Identifier => Convention_Identifier : declare
7245             Idnam : Name_Id;
7246             Cname : Name_Id;
7247
7248          begin
7249             GNAT_Pragma;
7250             Check_Arg_Order ((Name_Name, Name_Convention));
7251             Check_Arg_Count (2);
7252             Check_Optional_Identifier (Arg1, Name_Name);
7253             Check_Optional_Identifier (Arg2, Name_Convention);
7254             Check_Arg_Is_Identifier (Arg1);
7255             Check_Arg_Is_Identifier (Arg2);
7256             Idnam := Chars (Get_Pragma_Arg (Arg1));
7257             Cname := Chars (Get_Pragma_Arg (Arg2));
7258
7259             if Is_Convention_Name (Cname) then
7260                Record_Convention_Identifier
7261                  (Idnam, Get_Convention_Id (Cname));
7262             else
7263                Error_Pragma_Arg
7264                  ("second arg for % pragma must be convention", Arg2);
7265             end if;
7266          end Convention_Identifier;
7267
7268          ---------------
7269          -- CPP_Class --
7270          ---------------
7271
7272          --  pragma CPP_Class ([Entity =>] local_NAME)
7273
7274          when Pragma_CPP_Class => CPP_Class : declare
7275             Arg : Node_Id;
7276             Typ : Entity_Id;
7277
7278          begin
7279             if Warn_On_Obsolescent_Feature then
7280                Error_Msg_N
7281                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7282                   " by pragma import?", N);
7283             end if;
7284
7285             GNAT_Pragma;
7286             Check_Arg_Count (1);
7287             Check_Optional_Identifier (Arg1, Name_Entity);
7288             Check_Arg_Is_Local_Name (Arg1);
7289
7290             Arg := Get_Pragma_Arg (Arg1);
7291             Analyze (Arg);
7292
7293             if Etype (Arg) = Any_Type then
7294                return;
7295             end if;
7296
7297             if not Is_Entity_Name (Arg)
7298               or else not Is_Type (Entity (Arg))
7299             then
7300                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7301             end if;
7302
7303             Typ := Entity (Arg);
7304
7305             if not Is_Tagged_Type (Typ) then
7306                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7307             end if;
7308
7309             --  Types treated as CPP classes must be declared limited (note:
7310             --  this used to be a warning but there is no real benefit to it
7311             --  since we did effectively intend to treat the type as limited
7312             --  anyway).
7313
7314             if not Is_Limited_Type (Typ) then
7315                Error_Msg_N
7316                  ("imported 'C'P'P type must be limited",
7317                   Get_Pragma_Arg (Arg1));
7318             end if;
7319
7320             Set_Is_CPP_Class      (Typ);
7321             Set_Convention        (Typ, Convention_CPP);
7322
7323             --  Imported CPP types must not have discriminants (because C++
7324             --  classes do not have discriminants).
7325
7326             if Has_Discriminants (Typ) then
7327                Error_Msg_N
7328                  ("imported 'C'P'P type cannot have discriminants",
7329                   First (Discriminant_Specifications
7330                           (Declaration_Node (Typ))));
7331             end if;
7332
7333             --  Components of imported CPP types must not have default
7334             --  expressions because the constructor (if any) is in the
7335             --  C++ side.
7336
7337             if Is_Incomplete_Or_Private_Type (Typ)
7338               and then No (Underlying_Type (Typ))
7339             then
7340                --  It should be an error to apply pragma CPP to a private
7341                --  type if the underlying type is not visible (as it is
7342                --  for any representation item). For now, for backward
7343                --  compatibility we do nothing but we cannot check components
7344                --  because they are not available at this stage. All this code
7345                --  will be removed when we cleanup this obsolete GNAT pragma???
7346
7347                null;
7348
7349             else
7350                declare
7351                   Tdef  : constant Node_Id :=
7352                             Type_Definition (Declaration_Node (Typ));
7353                   Clist : Node_Id;
7354                   Comp  : Node_Id;
7355
7356                begin
7357                   if Nkind (Tdef) = N_Record_Definition then
7358                      Clist := Component_List (Tdef);
7359                   else
7360                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7361                      Clist := Component_List (Record_Extension_Part (Tdef));
7362                   end if;
7363
7364                   if Present (Clist) then
7365                      Comp := First (Component_Items (Clist));
7366                      while Present (Comp) loop
7367                         if Present (Expression (Comp)) then
7368                            Error_Msg_N
7369                              ("component of imported 'C'P'P type cannot have" &
7370                               " default expression", Expression (Comp));
7371                         end if;
7372
7373                         Next (Comp);
7374                      end loop;
7375                   end if;
7376                end;
7377             end if;
7378          end CPP_Class;
7379
7380          ---------------------
7381          -- CPP_Constructor --
7382          ---------------------
7383
7384          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7385          --    [, [External_Name =>] static_string_EXPRESSION ]
7386          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7387
7388          when Pragma_CPP_Constructor => CPP_Constructor : declare
7389             Elmt    : Elmt_Id;
7390             Id      : Entity_Id;
7391             Def_Id  : Entity_Id;
7392             Tag_Typ : Entity_Id;
7393
7394          begin
7395             GNAT_Pragma;
7396             Check_At_Least_N_Arguments (1);
7397             Check_At_Most_N_Arguments (3);
7398             Check_Optional_Identifier (Arg1, Name_Entity);
7399             Check_Arg_Is_Local_Name (Arg1);
7400
7401             Id := Get_Pragma_Arg (Arg1);
7402             Find_Program_Unit_Name (Id);
7403
7404             --  If we did not find the name, we are done
7405
7406             if Etype (Id) = Any_Type then
7407                return;
7408             end if;
7409
7410             Def_Id := Entity (Id);
7411
7412             --  Check if already defined as constructor
7413
7414             if Is_Constructor (Def_Id) then
7415                Error_Msg_N
7416                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7417                return;
7418             end if;
7419
7420             if Ekind (Def_Id) = E_Function
7421               and then (Is_CPP_Class (Etype (Def_Id))
7422                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7423                                    and then
7424                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7425             then
7426                if Arg_Count >= 2 then
7427                   Set_Imported (Def_Id);
7428                   Set_Is_Public (Def_Id);
7429                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7430                end if;
7431
7432                Set_Has_Completion (Def_Id);
7433                Set_Is_Constructor (Def_Id);
7434
7435                --  Imported C++ constructors are not dispatching primitives
7436                --  because in C++ they don't have a dispatch table slot.
7437                --  However, in Ada the constructor has the profile of a
7438                --  function that returns a tagged type and therefore it has
7439                --  been treated as a primitive operation during semantic
7440                --  analysis. We now remove it from the list of primitive
7441                --  operations of the type.
7442
7443                if Is_Tagged_Type (Etype (Def_Id))
7444                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7445                then
7446                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7447                   Tag_Typ := Etype (Def_Id);
7448
7449                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7450                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7451                      Next_Elmt (Elmt);
7452                   end loop;
7453
7454                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7455                   Set_Is_Dispatching_Operation (Def_Id, False);
7456                end if;
7457
7458                --  For backward compatibility, if the constructor returns a
7459                --  class wide type, and we internally change the return type to
7460                --  the corresponding root type.
7461
7462                if Is_Class_Wide_Type (Etype (Def_Id)) then
7463                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7464                end if;
7465             else
7466                Error_Pragma_Arg
7467                  ("pragma% requires function returning a 'C'P'P_Class type",
7468                    Arg1);
7469             end if;
7470          end CPP_Constructor;
7471
7472          -----------------
7473          -- CPP_Virtual --
7474          -----------------
7475
7476          when Pragma_CPP_Virtual => CPP_Virtual : declare
7477          begin
7478             GNAT_Pragma;
7479
7480             if Warn_On_Obsolescent_Feature then
7481                Error_Msg_N
7482                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7483                   "no effect?", N);
7484             end if;
7485          end CPP_Virtual;
7486
7487          ----------------
7488          -- CPP_Vtable --
7489          ----------------
7490
7491          when Pragma_CPP_Vtable => CPP_Vtable : declare
7492          begin
7493             GNAT_Pragma;
7494
7495             if Warn_On_Obsolescent_Feature then
7496                Error_Msg_N
7497                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7498                   "no effect?", N);
7499             end if;
7500          end CPP_Vtable;
7501
7502          ---------
7503          -- CPU --
7504          ---------
7505
7506          --  pragma CPU (EXPRESSION);
7507
7508          when Pragma_CPU => CPU : declare
7509             P   : constant Node_Id := Parent (N);
7510             Arg : Node_Id;
7511
7512          begin
7513             Ada_2012_Pragma;
7514             Check_No_Identifiers;
7515             Check_Arg_Count (1);
7516
7517             --  Subprogram case
7518
7519             if Nkind (P) = N_Subprogram_Body then
7520                Check_In_Main_Program;
7521
7522                Arg := Get_Pragma_Arg (Arg1);
7523                Analyze_And_Resolve (Arg, Any_Integer);
7524
7525                --  Must be static
7526
7527                if not Is_Static_Expression (Arg) then
7528                   Flag_Non_Static_Expr
7529                     ("main subprogram affinity is not static!", Arg);
7530                   raise Pragma_Exit;
7531
7532                --  If constraint error, then we already signalled an error
7533
7534                elsif Raises_Constraint_Error (Arg) then
7535                   null;
7536
7537                --  Otherwise check in range
7538
7539                else
7540                   declare
7541                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7542                      --  This is the entity System.Multiprocessors.CPU_Range;
7543
7544                      Val : constant Uint := Expr_Value (Arg);
7545
7546                   begin
7547                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7548                           or else
7549                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7550                      then
7551                         Error_Pragma_Arg
7552                           ("main subprogram CPU is out of range", Arg1);
7553                      end if;
7554                   end;
7555                end if;
7556
7557                Set_Main_CPU
7558                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7559
7560             --  Task case
7561
7562             elsif Nkind (P) = N_Task_Definition then
7563                Arg := Get_Pragma_Arg (Arg1);
7564
7565                --  The expression must be analyzed in the special manner
7566                --  described in "Handling of Default and Per-Object
7567                --  Expressions" in sem.ads.
7568
7569                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7570
7571             --  Anything else is incorrect
7572
7573             else
7574                Pragma_Misplaced;
7575             end if;
7576
7577             if Has_Pragma_CPU (P) then
7578                Error_Pragma ("duplicate pragma% not allowed");
7579             else
7580                Set_Has_Pragma_CPU (P, True);
7581
7582                if Nkind (P) = N_Task_Definition then
7583                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7584                end if;
7585             end if;
7586          end CPU;
7587
7588          -----------
7589          -- Debug --
7590          -----------
7591
7592          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7593
7594          when Pragma_Debug => Debug : declare
7595             Cond : Node_Id;
7596             Call : Node_Id;
7597
7598          begin
7599             GNAT_Pragma;
7600
7601             Cond :=
7602               New_Occurrence_Of
7603                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7604                  Loc);
7605
7606             if Arg_Count = 2 then
7607                Cond :=
7608                  Make_And_Then (Loc,
7609                    Left_Opnd  => Relocate_Node (Cond),
7610                    Right_Opnd => Get_Pragma_Arg (Arg1));
7611                Call := Get_Pragma_Arg (Arg2);
7612             else
7613                Call := Get_Pragma_Arg (Arg1);
7614             end if;
7615
7616             if Nkind_In (Call,
7617                  N_Indexed_Component,
7618                  N_Function_Call,
7619                  N_Identifier,
7620                  N_Selected_Component)
7621             then
7622                --  If this pragma Debug comes from source, its argument was
7623                --  parsed as a name form (which is syntactically identical).
7624                --  Change it to a procedure call statement now.
7625
7626                Change_Name_To_Procedure_Call_Statement (Call);
7627
7628             elsif Nkind (Call) = N_Procedure_Call_Statement then
7629
7630                --  Already in the form of a procedure call statement: nothing
7631                --  to do (could happen in case of an internally generated
7632                --  pragma Debug).
7633
7634                null;
7635
7636             else
7637                --  All other cases: diagnose error
7638
7639                Error_Msg
7640                  ("argument of pragma% is not procedure call", Sloc (Call));
7641                return;
7642             end if;
7643
7644             --  Rewrite into a conditional with an appropriate condition. We
7645             --  wrap the procedure call in a block so that overhead from e.g.
7646             --  use of the secondary stack does not generate execution overhead
7647             --  for suppressed conditions.
7648
7649             Rewrite (N, Make_Implicit_If_Statement (N,
7650               Condition => Cond,
7651                  Then_Statements => New_List (
7652                    Make_Block_Statement (Loc,
7653                      Handled_Statement_Sequence =>
7654                        Make_Handled_Sequence_Of_Statements (Loc,
7655                          Statements => New_List (Relocate_Node (Call)))))));
7656             Analyze (N);
7657          end Debug;
7658
7659          ------------------
7660          -- Debug_Policy --
7661          ------------------
7662
7663          --  pragma Debug_Policy (Check | Ignore)
7664
7665          when Pragma_Debug_Policy =>
7666             GNAT_Pragma;
7667             Check_Arg_Count (1);
7668             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Ignore);
7669             Debug_Pragmas_Enabled :=
7670               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7671
7672          ---------------------
7673          -- Detect_Blocking --
7674          ---------------------
7675
7676          --  pragma Detect_Blocking;
7677
7678          when Pragma_Detect_Blocking =>
7679             Ada_2005_Pragma;
7680             Check_Arg_Count (0);
7681             Check_Valid_Configuration_Pragma;
7682             Detect_Blocking := True;
7683
7684          --------------------------
7685          -- Default_Storage_Pool --
7686          --------------------------
7687
7688          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7689
7690          when Pragma_Default_Storage_Pool =>
7691             Ada_2012_Pragma;
7692             Check_Arg_Count (1);
7693
7694             --  Default_Storage_Pool can appear as a configuration pragma, or
7695             --  in a declarative part or a package spec.
7696
7697             if not Is_Configuration_Pragma then
7698                Check_Is_In_Decl_Part_Or_Package_Spec;
7699             end if;
7700
7701             --  Case of Default_Storage_Pool (null);
7702
7703             if Nkind (Expression (Arg1)) = N_Null then
7704                Analyze (Expression (Arg1));
7705
7706                --  This is an odd case, this is not really an expression, so
7707                --  we don't have a type for it. So just set the type to Empty.
7708
7709                Set_Etype (Expression (Arg1), Empty);
7710
7711             --  Case of Default_Storage_Pool (storage_pool_NAME);
7712
7713             else
7714                --  If it's a configuration pragma, then the only allowed
7715                --  argument is "null".
7716
7717                if Is_Configuration_Pragma then
7718                   Error_Pragma_Arg ("NULL expected", Arg1);
7719                end if;
7720
7721                --  The expected type for a non-"null" argument is
7722                --  Root_Storage_Pool'Class.
7723
7724                Analyze_And_Resolve
7725                  (Get_Pragma_Arg (Arg1),
7726                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7727             end if;
7728
7729             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7730             --  for an access type will use this information to set the
7731             --  appropriate attributes of the access type.
7732
7733             Default_Pool := Expression (Arg1);
7734
7735          ---------------
7736          -- Dimension --
7737          ---------------
7738
7739          when Pragma_Dimension =>
7740             GNAT_Pragma;
7741             Check_Arg_Count (4);
7742             Check_No_Identifiers;
7743             Check_Arg_Is_Local_Name (Arg1);
7744
7745             if not Is_Type (Arg1) then
7746                Error_Pragma ("first argument for pragma% must be subtype");
7747             end if;
7748
7749             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7750             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7751             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7752
7753          -------------------
7754          -- Discard_Names --
7755          -------------------
7756
7757          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7758
7759          when Pragma_Discard_Names => Discard_Names : declare
7760             E    : Entity_Id;
7761             E_Id : Entity_Id;
7762
7763          begin
7764             Check_Ada_83_Warning;
7765
7766             --  Deal with configuration pragma case
7767
7768             if Arg_Count = 0 and then Is_Configuration_Pragma then
7769                Global_Discard_Names := True;
7770                return;
7771
7772             --  Otherwise, check correct appropriate context
7773
7774             else
7775                Check_Is_In_Decl_Part_Or_Package_Spec;
7776
7777                if Arg_Count = 0 then
7778
7779                   --  If there is no parameter, then from now on this pragma
7780                   --  applies to any enumeration, exception or tagged type
7781                   --  defined in the current declarative part, and recursively
7782                   --  to any nested scope.
7783
7784                   Set_Discard_Names (Current_Scope);
7785                   return;
7786
7787                else
7788                   Check_Arg_Count (1);
7789                   Check_Optional_Identifier (Arg1, Name_On);
7790                   Check_Arg_Is_Local_Name (Arg1);
7791
7792                   E_Id := Get_Pragma_Arg (Arg1);
7793
7794                   if Etype (E_Id) = Any_Type then
7795                      return;
7796                   else
7797                      E := Entity (E_Id);
7798                   end if;
7799
7800                   if (Is_First_Subtype (E)
7801                       and then
7802                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7803                     or else Ekind (E) = E_Exception
7804                   then
7805                      Set_Discard_Names (E);
7806                   else
7807                      Error_Pragma_Arg
7808                        ("inappropriate entity for pragma%", Arg1);
7809                   end if;
7810
7811                end if;
7812             end if;
7813          end Discard_Names;
7814
7815          ---------------
7816          -- Elaborate --
7817          ---------------
7818
7819          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7820
7821          when Pragma_Elaborate => Elaborate : declare
7822             Arg   : Node_Id;
7823             Citem : Node_Id;
7824
7825          begin
7826             --  Pragma must be in context items list of a compilation unit
7827
7828             if not Is_In_Context_Clause then
7829                Pragma_Misplaced;
7830             end if;
7831
7832             --  Must be at least one argument
7833
7834             if Arg_Count = 0 then
7835                Error_Pragma ("pragma% requires at least one argument");
7836             end if;
7837
7838             --  In Ada 83 mode, there can be no items following it in the
7839             --  context list except other pragmas and implicit with clauses
7840             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7841             --  placement rule does not apply.
7842
7843             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7844                Citem := Next (N);
7845                while Present (Citem) loop
7846                   if Nkind (Citem) = N_Pragma
7847                     or else (Nkind (Citem) = N_With_Clause
7848                               and then Implicit_With (Citem))
7849                   then
7850                      null;
7851                   else
7852                      Error_Pragma
7853                        ("(Ada 83) pragma% must be at end of context clause");
7854                   end if;
7855
7856                   Next (Citem);
7857                end loop;
7858             end if;
7859
7860             --  Finally, the arguments must all be units mentioned in a with
7861             --  clause in the same context clause. Note we already checked (in
7862             --  Par.Prag) that the arguments are all identifiers or selected
7863             --  components.
7864
7865             Arg := Arg1;
7866             Outer : while Present (Arg) loop
7867                Citem := First (List_Containing (N));
7868                Inner : while Citem /= N loop
7869                   if Nkind (Citem) = N_With_Clause
7870                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7871                   then
7872                      Set_Elaborate_Present (Citem, True);
7873                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7874                      Generate_Reference (Entity (Name (Citem)), Citem);
7875
7876                      --  With the pragma present, elaboration calls on
7877                      --  subprograms from the named unit need no further
7878                      --  checks, as long as the pragma appears in the current
7879                      --  compilation unit. If the pragma appears in some unit
7880                      --  in the context, there might still be a need for an
7881                      --  Elaborate_All_Desirable from the current compilation
7882                      --  to the named unit, so we keep the check enabled.
7883
7884                      if In_Extended_Main_Source_Unit (N) then
7885                         Set_Suppress_Elaboration_Warnings
7886                           (Entity (Name (Citem)));
7887                      end if;
7888
7889                      exit Inner;
7890                   end if;
7891
7892                   Next (Citem);
7893                end loop Inner;
7894
7895                if Citem = N then
7896                   Error_Pragma_Arg
7897                     ("argument of pragma% is not with'ed unit", Arg);
7898                end if;
7899
7900                Next (Arg);
7901             end loop Outer;
7902
7903             --  Give a warning if operating in static mode with -gnatwl
7904             --  (elaboration warnings enabled) switch set.
7905
7906             if Elab_Warnings and not Dynamic_Elaboration_Checks then
7907                Error_Msg_N
7908                  ("?use of pragma Elaborate may not be safe", N);
7909                Error_Msg_N
7910                  ("?use pragma Elaborate_All instead if possible", N);
7911             end if;
7912          end Elaborate;
7913
7914          -------------------
7915          -- Elaborate_All --
7916          -------------------
7917
7918          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7919
7920          when Pragma_Elaborate_All => Elaborate_All : declare
7921             Arg   : Node_Id;
7922             Citem : Node_Id;
7923
7924          begin
7925             Check_Ada_83_Warning;
7926
7927             --  Pragma must be in context items list of a compilation unit
7928
7929             if not Is_In_Context_Clause then
7930                Pragma_Misplaced;
7931             end if;
7932
7933             --  Must be at least one argument
7934
7935             if Arg_Count = 0 then
7936                Error_Pragma ("pragma% requires at least one argument");
7937             end if;
7938
7939             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
7940             --  have to appear at the end of the context clause, but may
7941             --  appear mixed in with other items, even in Ada 83 mode.
7942
7943             --  Final check: the arguments must all be units mentioned in
7944             --  a with clause in the same context clause. Note that we
7945             --  already checked (in Par.Prag) that all the arguments are
7946             --  either identifiers or selected components.
7947
7948             Arg := Arg1;
7949             Outr : while Present (Arg) loop
7950                Citem := First (List_Containing (N));
7951                Innr : while Citem /= N loop
7952                   if Nkind (Citem) = N_With_Clause
7953                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7954                   then
7955                      Set_Elaborate_All_Present (Citem, True);
7956                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7957
7958                      --  Suppress warnings and elaboration checks on the named
7959                      --  unit if the pragma is in the current compilation, as
7960                      --  for pragma Elaborate.
7961
7962                      if In_Extended_Main_Source_Unit (N) then
7963                         Set_Suppress_Elaboration_Warnings
7964                           (Entity (Name (Citem)));
7965                      end if;
7966                      exit Innr;
7967                   end if;
7968
7969                   Next (Citem);
7970                end loop Innr;
7971
7972                if Citem = N then
7973                   Set_Error_Posted (N);
7974                   Error_Pragma_Arg
7975                     ("argument of pragma% is not with'ed unit", Arg);
7976                end if;
7977
7978                Next (Arg);
7979             end loop Outr;
7980          end Elaborate_All;
7981
7982          --------------------
7983          -- Elaborate_Body --
7984          --------------------
7985
7986          --  pragma Elaborate_Body [( library_unit_NAME )];
7987
7988          when Pragma_Elaborate_Body => Elaborate_Body : declare
7989             Cunit_Node : Node_Id;
7990             Cunit_Ent  : Entity_Id;
7991
7992          begin
7993             Check_Ada_83_Warning;
7994             Check_Valid_Library_Unit_Pragma;
7995
7996             if Nkind (N) = N_Null_Statement then
7997                return;
7998             end if;
7999
8000             Cunit_Node := Cunit (Current_Sem_Unit);
8001             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8002
8003             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8004                                             N_Subprogram_Body)
8005             then
8006                Error_Pragma ("pragma% must refer to a spec, not a body");
8007             else
8008                Set_Body_Required (Cunit_Node, True);
8009                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8010
8011                --  If we are in dynamic elaboration mode, then we suppress
8012                --  elaboration warnings for the unit, since it is definitely
8013                --  fine NOT to do dynamic checks at the first level (and such
8014                --  checks will be suppressed because no elaboration boolean
8015                --  is created for Elaborate_Body packages).
8016
8017                --  But in the static model of elaboration, Elaborate_Body is
8018                --  definitely NOT good enough to ensure elaboration safety on
8019                --  its own, since the body may WITH other units that are not
8020                --  safe from an elaboration point of view, so a client must
8021                --  still do an Elaborate_All on such units.
8022
8023                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8024                --  Elaborate_Body always suppressed elab warnings.
8025
8026                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8027                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8028                end if;
8029             end if;
8030          end Elaborate_Body;
8031
8032          ------------------------
8033          -- Elaboration_Checks --
8034          ------------------------
8035
8036          --  pragma Elaboration_Checks (Static | Dynamic);
8037
8038          when Pragma_Elaboration_Checks =>
8039             GNAT_Pragma;
8040             Check_Arg_Count (1);
8041             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8042             Dynamic_Elaboration_Checks :=
8043               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8044
8045          ---------------
8046          -- Eliminate --
8047          ---------------
8048
8049          --  pragma Eliminate (
8050          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8051          --    [,[Entity     =>] IDENTIFIER |
8052          --                      SELECTED_COMPONENT |
8053          --                      STRING_LITERAL]
8054          --    [,                OVERLOADING_RESOLUTION]);
8055
8056          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8057          --                             SOURCE_LOCATION
8058
8059          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8060          --                                        FUNCTION_PROFILE
8061
8062          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8063
8064          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8065          --                       Result_Type => result_SUBTYPE_NAME]
8066
8067          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8068          --  SUBTYPE_NAME    ::= STRING_LITERAL
8069
8070          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8071          --  SOURCE_TRACE    ::= STRING_LITERAL
8072
8073          when Pragma_Eliminate => Eliminate : declare
8074             Args  : Args_List (1 .. 5);
8075             Names : constant Name_List (1 .. 5) := (
8076                       Name_Unit_Name,
8077                       Name_Entity,
8078                       Name_Parameter_Types,
8079                       Name_Result_Type,
8080                       Name_Source_Location);
8081
8082             Unit_Name       : Node_Id renames Args (1);
8083             Entity          : Node_Id renames Args (2);
8084             Parameter_Types : Node_Id renames Args (3);
8085             Result_Type     : Node_Id renames Args (4);
8086             Source_Location : Node_Id renames Args (5);
8087
8088          begin
8089             GNAT_Pragma;
8090             Check_Valid_Configuration_Pragma;
8091             Gather_Associations (Names, Args);
8092
8093             if No (Unit_Name) then
8094                Error_Pragma ("missing Unit_Name argument for pragma%");
8095             end if;
8096
8097             if No (Entity)
8098               and then (Present (Parameter_Types)
8099                           or else
8100                         Present (Result_Type)
8101                           or else
8102                         Present (Source_Location))
8103             then
8104                Error_Pragma ("missing Entity argument for pragma%");
8105             end if;
8106
8107             if (Present (Parameter_Types)
8108                   or else
8109                 Present (Result_Type))
8110               and then
8111                 Present (Source_Location)
8112             then
8113                Error_Pragma
8114                  ("parameter profile and source location cannot " &
8115                   "be used together in pragma%");
8116             end if;
8117
8118             Process_Eliminate_Pragma
8119               (N,
8120                Unit_Name,
8121                Entity,
8122                Parameter_Types,
8123                Result_Type,
8124                Source_Location);
8125          end Eliminate;
8126
8127          ------------
8128          -- Export --
8129          ------------
8130
8131          --  pragma Export (
8132          --    [   Convention    =>] convention_IDENTIFIER,
8133          --    [   Entity        =>] local_NAME
8134          --    [, [External_Name =>] static_string_EXPRESSION ]
8135          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8136
8137          when Pragma_Export => Export : declare
8138             C      : Convention_Id;
8139             Def_Id : Entity_Id;
8140
8141             pragma Warnings (Off, C);
8142
8143          begin
8144             Check_Ada_83_Warning;
8145             Check_Arg_Order
8146               ((Name_Convention,
8147                 Name_Entity,
8148                 Name_External_Name,
8149                 Name_Link_Name));
8150             Check_At_Least_N_Arguments (2);
8151             Check_At_Most_N_Arguments  (4);
8152             Process_Convention (C, Def_Id);
8153
8154             if Ekind (Def_Id) /= E_Constant then
8155                Note_Possible_Modification
8156                  (Get_Pragma_Arg (Arg2), Sure => False);
8157             end if;
8158
8159             Process_Interface_Name (Def_Id, Arg3, Arg4);
8160             Set_Exported (Def_Id, Arg2);
8161
8162             --  If the entity is a deferred constant, propagate the information
8163             --  to the full view, because gigi elaborates the full view only.
8164
8165             if Ekind (Def_Id) = E_Constant
8166               and then Present (Full_View (Def_Id))
8167             then
8168                declare
8169                   Id2 : constant Entity_Id := Full_View (Def_Id);
8170                begin
8171                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8172                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8173                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8174                end;
8175             end if;
8176          end Export;
8177
8178          ----------------------
8179          -- Export_Exception --
8180          ----------------------
8181
8182          --  pragma Export_Exception (
8183          --        [Internal         =>] LOCAL_NAME
8184          --     [, [External         =>] EXTERNAL_SYMBOL]
8185          --     [, [Form     =>] Ada | VMS]
8186          --     [, [Code     =>] static_integer_EXPRESSION]);
8187
8188          when Pragma_Export_Exception => Export_Exception : declare
8189             Args  : Args_List (1 .. 4);
8190             Names : constant Name_List (1 .. 4) := (
8191                       Name_Internal,
8192                       Name_External,
8193                       Name_Form,
8194                       Name_Code);
8195
8196             Internal : Node_Id renames Args (1);
8197             External : Node_Id renames Args (2);
8198             Form     : Node_Id renames Args (3);
8199             Code     : Node_Id renames Args (4);
8200
8201          begin
8202             GNAT_Pragma;
8203
8204             if Inside_A_Generic then
8205                Error_Pragma ("pragma% cannot be used for generic entities");
8206             end if;
8207
8208             Gather_Associations (Names, Args);
8209             Process_Extended_Import_Export_Exception_Pragma (
8210               Arg_Internal => Internal,
8211               Arg_External => External,
8212               Arg_Form     => Form,
8213               Arg_Code     => Code);
8214
8215             if not Is_VMS_Exception (Entity (Internal)) then
8216                Set_Exported (Entity (Internal), Internal);
8217             end if;
8218          end Export_Exception;
8219
8220          ---------------------
8221          -- Export_Function --
8222          ---------------------
8223
8224          --  pragma Export_Function (
8225          --        [Internal         =>] LOCAL_NAME
8226          --     [, [External         =>] EXTERNAL_SYMBOL]
8227          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8228          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8229          --     [, [Mechanism        =>] MECHANISM]
8230          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8231
8232          --  EXTERNAL_SYMBOL ::=
8233          --    IDENTIFIER
8234          --  | static_string_EXPRESSION
8235
8236          --  PARAMETER_TYPES ::=
8237          --    null
8238          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8239
8240          --  TYPE_DESIGNATOR ::=
8241          --    subtype_NAME
8242          --  | subtype_Name ' Access
8243
8244          --  MECHANISM ::=
8245          --    MECHANISM_NAME
8246          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8247
8248          --  MECHANISM_ASSOCIATION ::=
8249          --    [formal_parameter_NAME =>] MECHANISM_NAME
8250
8251          --  MECHANISM_NAME ::=
8252          --    Value
8253          --  | Reference
8254          --  | Descriptor [([Class =>] CLASS_NAME)]
8255
8256          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8257
8258          when Pragma_Export_Function => Export_Function : declare
8259             Args  : Args_List (1 .. 6);
8260             Names : constant Name_List (1 .. 6) := (
8261                       Name_Internal,
8262                       Name_External,
8263                       Name_Parameter_Types,
8264                       Name_Result_Type,
8265                       Name_Mechanism,
8266                       Name_Result_Mechanism);
8267
8268             Internal         : Node_Id renames Args (1);
8269             External         : Node_Id renames Args (2);
8270             Parameter_Types  : Node_Id renames Args (3);
8271             Result_Type      : Node_Id renames Args (4);
8272             Mechanism        : Node_Id renames Args (5);
8273             Result_Mechanism : Node_Id renames Args (6);
8274
8275          begin
8276             GNAT_Pragma;
8277             Gather_Associations (Names, Args);
8278             Process_Extended_Import_Export_Subprogram_Pragma (
8279               Arg_Internal         => Internal,
8280               Arg_External         => External,
8281               Arg_Parameter_Types  => Parameter_Types,
8282               Arg_Result_Type      => Result_Type,
8283               Arg_Mechanism        => Mechanism,
8284               Arg_Result_Mechanism => Result_Mechanism);
8285          end Export_Function;
8286
8287          -------------------
8288          -- Export_Object --
8289          -------------------
8290
8291          --  pragma Export_Object (
8292          --        [Internal =>] LOCAL_NAME
8293          --     [, [External =>] EXTERNAL_SYMBOL]
8294          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8295
8296          --  EXTERNAL_SYMBOL ::=
8297          --    IDENTIFIER
8298          --  | static_string_EXPRESSION
8299
8300          --  PARAMETER_TYPES ::=
8301          --    null
8302          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8303
8304          --  TYPE_DESIGNATOR ::=
8305          --    subtype_NAME
8306          --  | subtype_Name ' Access
8307
8308          --  MECHANISM ::=
8309          --    MECHANISM_NAME
8310          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8311
8312          --  MECHANISM_ASSOCIATION ::=
8313          --    [formal_parameter_NAME =>] MECHANISM_NAME
8314
8315          --  MECHANISM_NAME ::=
8316          --    Value
8317          --  | Reference
8318          --  | Descriptor [([Class =>] CLASS_NAME)]
8319
8320          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8321
8322          when Pragma_Export_Object => Export_Object : declare
8323             Args  : Args_List (1 .. 3);
8324             Names : constant Name_List (1 .. 3) := (
8325                       Name_Internal,
8326                       Name_External,
8327                       Name_Size);
8328
8329             Internal : Node_Id renames Args (1);
8330             External : Node_Id renames Args (2);
8331             Size     : Node_Id renames Args (3);
8332
8333          begin
8334             GNAT_Pragma;
8335             Gather_Associations (Names, Args);
8336             Process_Extended_Import_Export_Object_Pragma (
8337               Arg_Internal => Internal,
8338               Arg_External => External,
8339               Arg_Size     => Size);
8340          end Export_Object;
8341
8342          ----------------------
8343          -- Export_Procedure --
8344          ----------------------
8345
8346          --  pragma Export_Procedure (
8347          --        [Internal         =>] LOCAL_NAME
8348          --     [, [External         =>] EXTERNAL_SYMBOL]
8349          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8350          --     [, [Mechanism        =>] MECHANISM]);
8351
8352          --  EXTERNAL_SYMBOL ::=
8353          --    IDENTIFIER
8354          --  | static_string_EXPRESSION
8355
8356          --  PARAMETER_TYPES ::=
8357          --    null
8358          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8359
8360          --  TYPE_DESIGNATOR ::=
8361          --    subtype_NAME
8362          --  | subtype_Name ' Access
8363
8364          --  MECHANISM ::=
8365          --    MECHANISM_NAME
8366          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8367
8368          --  MECHANISM_ASSOCIATION ::=
8369          --    [formal_parameter_NAME =>] MECHANISM_NAME
8370
8371          --  MECHANISM_NAME ::=
8372          --    Value
8373          --  | Reference
8374          --  | Descriptor [([Class =>] CLASS_NAME)]
8375
8376          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8377
8378          when Pragma_Export_Procedure => Export_Procedure : declare
8379             Args  : Args_List (1 .. 4);
8380             Names : constant Name_List (1 .. 4) := (
8381                       Name_Internal,
8382                       Name_External,
8383                       Name_Parameter_Types,
8384                       Name_Mechanism);
8385
8386             Internal        : Node_Id renames Args (1);
8387             External        : Node_Id renames Args (2);
8388             Parameter_Types : Node_Id renames Args (3);
8389             Mechanism       : Node_Id renames Args (4);
8390
8391          begin
8392             GNAT_Pragma;
8393             Gather_Associations (Names, Args);
8394             Process_Extended_Import_Export_Subprogram_Pragma (
8395               Arg_Internal        => Internal,
8396               Arg_External        => External,
8397               Arg_Parameter_Types => Parameter_Types,
8398               Arg_Mechanism       => Mechanism);
8399          end Export_Procedure;
8400
8401          ------------------
8402          -- Export_Value --
8403          ------------------
8404
8405          --  pragma Export_Value (
8406          --     [Value     =>] static_integer_EXPRESSION,
8407          --     [Link_Name =>] static_string_EXPRESSION);
8408
8409          when Pragma_Export_Value =>
8410             GNAT_Pragma;
8411             Check_Arg_Order ((Name_Value, Name_Link_Name));
8412             Check_Arg_Count (2);
8413
8414             Check_Optional_Identifier (Arg1, Name_Value);
8415             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8416
8417             Check_Optional_Identifier (Arg2, Name_Link_Name);
8418             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8419
8420          -----------------------------
8421          -- Export_Valued_Procedure --
8422          -----------------------------
8423
8424          --  pragma Export_Valued_Procedure (
8425          --        [Internal         =>] LOCAL_NAME
8426          --     [, [External         =>] EXTERNAL_SYMBOL,]
8427          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8428          --     [, [Mechanism        =>] MECHANISM]);
8429
8430          --  EXTERNAL_SYMBOL ::=
8431          --    IDENTIFIER
8432          --  | static_string_EXPRESSION
8433
8434          --  PARAMETER_TYPES ::=
8435          --    null
8436          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8437
8438          --  TYPE_DESIGNATOR ::=
8439          --    subtype_NAME
8440          --  | subtype_Name ' Access
8441
8442          --  MECHANISM ::=
8443          --    MECHANISM_NAME
8444          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8445
8446          --  MECHANISM_ASSOCIATION ::=
8447          --    [formal_parameter_NAME =>] MECHANISM_NAME
8448
8449          --  MECHANISM_NAME ::=
8450          --    Value
8451          --  | Reference
8452          --  | Descriptor [([Class =>] CLASS_NAME)]
8453
8454          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8455
8456          when Pragma_Export_Valued_Procedure =>
8457          Export_Valued_Procedure : declare
8458             Args  : Args_List (1 .. 4);
8459             Names : constant Name_List (1 .. 4) := (
8460                       Name_Internal,
8461                       Name_External,
8462                       Name_Parameter_Types,
8463                       Name_Mechanism);
8464
8465             Internal        : Node_Id renames Args (1);
8466             External        : Node_Id renames Args (2);
8467             Parameter_Types : Node_Id renames Args (3);
8468             Mechanism       : Node_Id renames Args (4);
8469
8470          begin
8471             GNAT_Pragma;
8472             Gather_Associations (Names, Args);
8473             Process_Extended_Import_Export_Subprogram_Pragma (
8474               Arg_Internal        => Internal,
8475               Arg_External        => External,
8476               Arg_Parameter_Types => Parameter_Types,
8477               Arg_Mechanism       => Mechanism);
8478          end Export_Valued_Procedure;
8479
8480          -------------------
8481          -- Extend_System --
8482          -------------------
8483
8484          --  pragma Extend_System ([Name =>] Identifier);
8485
8486          when Pragma_Extend_System => Extend_System : declare
8487          begin
8488             GNAT_Pragma;
8489             Check_Valid_Configuration_Pragma;
8490             Check_Arg_Count (1);
8491             Check_Optional_Identifier (Arg1, Name_Name);
8492             Check_Arg_Is_Identifier (Arg1);
8493
8494             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8495
8496             if Name_Len > 4
8497               and then Name_Buffer (1 .. 4) = "aux_"
8498             then
8499                if Present (System_Extend_Pragma_Arg) then
8500                   if Chars (Get_Pragma_Arg (Arg1)) =
8501                      Chars (Expression (System_Extend_Pragma_Arg))
8502                   then
8503                      null;
8504                   else
8505                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8506                      Error_Pragma ("pragma% conflicts with that #");
8507                   end if;
8508
8509                else
8510                   System_Extend_Pragma_Arg := Arg1;
8511
8512                   if not GNAT_Mode then
8513                      System_Extend_Unit := Arg1;
8514                   end if;
8515                end if;
8516             else
8517                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8518             end if;
8519          end Extend_System;
8520
8521          ------------------------
8522          -- Extensions_Allowed --
8523          ------------------------
8524
8525          --  pragma Extensions_Allowed (ON | OFF);
8526
8527          when Pragma_Extensions_Allowed =>
8528             GNAT_Pragma;
8529             Check_Arg_Count (1);
8530             Check_No_Identifiers;
8531             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8532
8533             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8534                Extensions_Allowed := True;
8535                Ada_Version := Ada_Version_Type'Last;
8536
8537             else
8538                Extensions_Allowed := False;
8539                Ada_Version := Ada_Version_Explicit;
8540             end if;
8541
8542          --------------
8543          -- External --
8544          --------------
8545
8546          --  pragma External (
8547          --    [   Convention    =>] convention_IDENTIFIER,
8548          --    [   Entity        =>] local_NAME
8549          --    [, [External_Name =>] static_string_EXPRESSION ]
8550          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8551
8552          when Pragma_External => External : declare
8553                Def_Id : Entity_Id;
8554
8555                C : Convention_Id;
8556                pragma Warnings (Off, C);
8557
8558          begin
8559             GNAT_Pragma;
8560             Check_Arg_Order
8561               ((Name_Convention,
8562                 Name_Entity,
8563                 Name_External_Name,
8564                 Name_Link_Name));
8565             Check_At_Least_N_Arguments (2);
8566             Check_At_Most_N_Arguments  (4);
8567             Process_Convention (C, Def_Id);
8568             Note_Possible_Modification
8569               (Get_Pragma_Arg (Arg2), Sure => False);
8570             Process_Interface_Name (Def_Id, Arg3, Arg4);
8571             Set_Exported (Def_Id, Arg2);
8572          end External;
8573
8574          --------------------------
8575          -- External_Name_Casing --
8576          --------------------------
8577
8578          --  pragma External_Name_Casing (
8579          --    UPPERCASE | LOWERCASE
8580          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8581
8582          when Pragma_External_Name_Casing => External_Name_Casing : declare
8583          begin
8584             GNAT_Pragma;
8585             Check_No_Identifiers;
8586
8587             if Arg_Count = 2 then
8588                Check_Arg_Is_One_Of
8589                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8590
8591                case Chars (Get_Pragma_Arg (Arg2)) is
8592                   when Name_As_Is     =>
8593                      Opt.External_Name_Exp_Casing := As_Is;
8594
8595                   when Name_Uppercase =>
8596                      Opt.External_Name_Exp_Casing := Uppercase;
8597
8598                   when Name_Lowercase =>
8599                      Opt.External_Name_Exp_Casing := Lowercase;
8600
8601                   when others =>
8602                      null;
8603                end case;
8604
8605             else
8606                Check_Arg_Count (1);
8607             end if;
8608
8609             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8610
8611             case Chars (Get_Pragma_Arg (Arg1)) is
8612                when Name_Uppercase =>
8613                   Opt.External_Name_Imp_Casing := Uppercase;
8614
8615                when Name_Lowercase =>
8616                   Opt.External_Name_Imp_Casing := Lowercase;
8617
8618                when others =>
8619                   null;
8620             end case;
8621          end External_Name_Casing;
8622
8623          --------------------------
8624          -- Favor_Top_Level --
8625          --------------------------
8626
8627          --  pragma Favor_Top_Level (type_NAME);
8628
8629          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8630                Named_Entity : Entity_Id;
8631
8632          begin
8633             GNAT_Pragma;
8634             Check_No_Identifiers;
8635             Check_Arg_Count (1);
8636             Check_Arg_Is_Local_Name (Arg1);
8637             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8638
8639             --  If it's an access-to-subprogram type (in particular, not a
8640             --  subtype), set the flag on that type.
8641
8642             if Is_Access_Subprogram_Type (Named_Entity) then
8643                Set_Can_Use_Internal_Rep (Named_Entity, False);
8644
8645             --  Otherwise it's an error (name denotes the wrong sort of entity)
8646
8647             else
8648                Error_Pragma_Arg
8649                  ("access-to-subprogram type expected",
8650                   Get_Pragma_Arg (Arg1));
8651             end if;
8652          end Favor_Top_Level;
8653
8654          ---------------
8655          -- Fast_Math --
8656          ---------------
8657
8658          --  pragma Fast_Math;
8659
8660          when Pragma_Fast_Math =>
8661             GNAT_Pragma;
8662             Check_No_Identifiers;
8663             Check_Valid_Configuration_Pragma;
8664             Fast_Math := True;
8665
8666          ---------------------------
8667          -- Finalize_Storage_Only --
8668          ---------------------------
8669
8670          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8671
8672          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8673             Assoc   : constant Node_Id := Arg1;
8674             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8675             Typ     : Entity_Id;
8676
8677          begin
8678             GNAT_Pragma;
8679             Check_No_Identifiers;
8680             Check_Arg_Count (1);
8681             Check_Arg_Is_Local_Name (Arg1);
8682
8683             Find_Type (Type_Id);
8684             Typ := Entity (Type_Id);
8685
8686             if Typ = Any_Type
8687               or else Rep_Item_Too_Early (Typ, N)
8688             then
8689                return;
8690             else
8691                Typ := Underlying_Type (Typ);
8692             end if;
8693
8694             if not Is_Controlled (Typ) then
8695                Error_Pragma ("pragma% must specify controlled type");
8696             end if;
8697
8698             Check_First_Subtype (Arg1);
8699
8700             if Finalize_Storage_Only (Typ) then
8701                Error_Pragma ("duplicate pragma%, only one allowed");
8702
8703             elsif not Rep_Item_Too_Late (Typ, N) then
8704                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8705             end if;
8706          end Finalize_Storage;
8707
8708          --------------------------
8709          -- Float_Representation --
8710          --------------------------
8711
8712          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8713
8714          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8715
8716          when Pragma_Float_Representation => Float_Representation : declare
8717             Argx : Node_Id;
8718             Digs : Nat;
8719             Ent  : Entity_Id;
8720
8721          begin
8722             GNAT_Pragma;
8723
8724             if Arg_Count = 1 then
8725                Check_Valid_Configuration_Pragma;
8726             else
8727                Check_Arg_Count (2);
8728                Check_Optional_Identifier (Arg2, Name_Entity);
8729                Check_Arg_Is_Local_Name (Arg2);
8730             end if;
8731
8732             Check_No_Identifier (Arg1);
8733             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8734
8735             if not OpenVMS_On_Target then
8736                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8737                   Error_Pragma
8738                     ("?pragma% ignored (applies only to Open'V'M'S)");
8739                end if;
8740
8741                return;
8742             end if;
8743
8744             --  One argument case
8745
8746             if Arg_Count = 1 then
8747                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8748                   if Opt.Float_Format = 'I' then
8749                      Error_Pragma ("'I'E'E'E format previously specified");
8750                   end if;
8751
8752                   Opt.Float_Format := 'V';
8753
8754                else
8755                   if Opt.Float_Format = 'V' then
8756                      Error_Pragma ("'V'A'X format previously specified");
8757                   end if;
8758
8759                   Opt.Float_Format := 'I';
8760                end if;
8761
8762                Set_Standard_Fpt_Formats;
8763
8764             --  Two argument case
8765
8766             else
8767                Argx := Get_Pragma_Arg (Arg2);
8768
8769                if not Is_Entity_Name (Argx)
8770                  or else not Is_Floating_Point_Type (Entity (Argx))
8771                then
8772                   Error_Pragma_Arg
8773                     ("second argument of% pragma must be floating-point type",
8774                      Arg2);
8775                end if;
8776
8777                Ent  := Entity (Argx);
8778                Digs := UI_To_Int (Digits_Value (Ent));
8779
8780                --  Two arguments, VAX_Float case
8781
8782                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8783                   case Digs is
8784                      when  6 => Set_F_Float (Ent);
8785                      when  9 => Set_D_Float (Ent);
8786                      when 15 => Set_G_Float (Ent);
8787
8788                      when others =>
8789                         Error_Pragma_Arg
8790                           ("wrong digits value, must be 6,9 or 15", Arg2);
8791                   end case;
8792
8793                --  Two arguments, IEEE_Float case
8794
8795                else
8796                   case Digs is
8797                      when  6 => Set_IEEE_Short (Ent);
8798                      when 15 => Set_IEEE_Long  (Ent);
8799
8800                      when others =>
8801                         Error_Pragma_Arg
8802                           ("wrong digits value, must be 6 or 15", Arg2);
8803                   end case;
8804                end if;
8805             end if;
8806          end Float_Representation;
8807
8808          -----------
8809          -- Ident --
8810          -----------
8811
8812          --  pragma Ident (static_string_EXPRESSION)
8813
8814          --  Note: pragma Comment shares this processing. Pragma Comment is
8815          --  identical to Ident, except that the restriction of the argument to
8816          --  31 characters and the placement restrictions are not enforced for
8817          --  pragma Comment.
8818
8819          when Pragma_Ident | Pragma_Comment => Ident : declare
8820             Str : Node_Id;
8821
8822          begin
8823             GNAT_Pragma;
8824             Check_Arg_Count (1);
8825             Check_No_Identifiers;
8826             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8827             Store_Note (N);
8828
8829             --  For pragma Ident, preserve DEC compatibility by requiring the
8830             --  pragma to appear in a declarative part or package spec.
8831
8832             if Prag_Id = Pragma_Ident then
8833                Check_Is_In_Decl_Part_Or_Package_Spec;
8834             end if;
8835
8836             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8837
8838             declare
8839                CS : Node_Id;
8840                GP : Node_Id;
8841
8842             begin
8843                GP := Parent (Parent (N));
8844
8845                if Nkind_In (GP, N_Package_Declaration,
8846                                 N_Generic_Package_Declaration)
8847                then
8848                   GP := Parent (GP);
8849                end if;
8850
8851                --  If we have a compilation unit, then record the ident value,
8852                --  checking for improper duplication.
8853
8854                if Nkind (GP) = N_Compilation_Unit then
8855                   CS := Ident_String (Current_Sem_Unit);
8856
8857                   if Present (CS) then
8858
8859                      --  For Ident, we do not permit multiple instances
8860
8861                      if Prag_Id = Pragma_Ident then
8862                         Error_Pragma ("duplicate% pragma not permitted");
8863
8864                      --  For Comment, we concatenate the string, unless we want
8865                      --  to preserve the tree structure for ASIS.
8866
8867                      elsif not ASIS_Mode then
8868                         Start_String (Strval (CS));
8869                         Store_String_Char (' ');
8870                         Store_String_Chars (Strval (Str));
8871                         Set_Strval (CS, End_String);
8872                      end if;
8873
8874                   else
8875                      --  In VMS, the effect of IDENT is achieved by passing
8876                      --  --identification=name as a --for-linker switch.
8877
8878                      if OpenVMS_On_Target then
8879                         Start_String;
8880                         Store_String_Chars
8881                           ("--for-linker=--identification=");
8882                         String_To_Name_Buffer (Strval (Str));
8883                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
8884
8885                         --  Only the last processed IDENT is saved. The main
8886                         --  purpose is so an IDENT associated with a main
8887                         --  procedure will be used in preference to an IDENT
8888                         --  associated with a with'd package.
8889
8890                         Replace_Linker_Option_String
8891                           (End_String, "--for-linker=--identification=");
8892                      end if;
8893
8894                      Set_Ident_String (Current_Sem_Unit, Str);
8895                   end if;
8896
8897                --  For subunits, we just ignore the Ident, since in GNAT these
8898                --  are not separate object files, and hence not separate units
8899                --  in the unit table.
8900
8901                elsif Nkind (GP) = N_Subunit then
8902                   null;
8903
8904                --  Otherwise we have a misplaced pragma Ident, but we ignore
8905                --  this if we are in an instantiation, since it comes from
8906                --  a generic, and has no relevance to the instantiation.
8907
8908                elsif Prag_Id = Pragma_Ident then
8909                   if Instantiation_Location (Loc) = No_Location then
8910                      Error_Pragma ("pragma% only allowed at outer level");
8911                   end if;
8912                end if;
8913             end;
8914          end Ident;
8915
8916          -----------------
8917          -- Implemented --
8918          -----------------
8919
8920          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8921          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8922
8923          when Pragma_Implemented => Implemented : declare
8924             Proc_Id : Entity_Id;
8925             Typ     : Entity_Id;
8926
8927          begin
8928             Ada_2012_Pragma;
8929             Check_Arg_Count (2);
8930             Check_No_Identifiers;
8931             Check_Arg_Is_Identifier (Arg1);
8932             Check_Arg_Is_Local_Name (Arg1);
8933             Check_Arg_Is_One_Of
8934               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8935
8936             --  Extract the name of the local procedure
8937
8938             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8939
8940             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8941             --  primitive procedure of a synchronized tagged type.
8942
8943             if Ekind (Proc_Id) = E_Procedure
8944               and then Is_Primitive (Proc_Id)
8945               and then Present (First_Formal (Proc_Id))
8946             then
8947                Typ := Etype (First_Formal (Proc_Id));
8948
8949                if Is_Tagged_Type (Typ)
8950                  and then
8951
8952                   --  Check for a protected, a synchronized or a task interface
8953
8954                    ((Is_Interface (Typ)
8955                        and then Is_Synchronized_Interface (Typ))
8956
8957                   --  Check for a protected type or a task type that implements
8958                   --  an interface.
8959
8960                    or else
8961                     (Is_Concurrent_Record_Type (Typ)
8962                        and then Present (Interfaces (Typ)))
8963
8964                   --  Check for a private record extension with keyword
8965                   --  "synchronized".
8966
8967                    or else
8968                     (Ekind_In (Typ, E_Record_Type_With_Private,
8969                                     E_Record_Subtype_With_Private)
8970                        and then Synchronized_Present (Parent (Typ))))
8971                then
8972                   null;
8973                else
8974                   Error_Pragma_Arg
8975                     ("controlling formal must be of synchronized " &
8976                      "tagged type", Arg1);
8977                   return;
8978                end if;
8979
8980             --  Procedures declared inside a protected type must be accepted
8981
8982             elsif Ekind (Proc_Id) = E_Procedure
8983               and then Is_Protected_Type (Scope (Proc_Id))
8984             then
8985                null;
8986
8987             --  The first argument is not a primitive procedure
8988
8989             else
8990                Error_Pragma_Arg
8991                  ("pragma % must be applied to a primitive procedure", Arg1);
8992                return;
8993             end if;
8994
8995             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
8996             --  By_Protected_Procedure to the primitive procedure of a task
8997             --  interface.
8998
8999             if Chars (Arg2) = Name_By_Protected_Procedure
9000               and then Is_Interface (Typ)
9001               and then Is_Task_Interface (Typ)
9002             then
9003                Error_Pragma_Arg
9004                  ("implementation kind By_Protected_Procedure cannot be " &
9005                   "applied to a task interface primitive", Arg2);
9006                return;
9007             end if;
9008
9009             Record_Rep_Item (Proc_Id, N);
9010          end Implemented;
9011
9012          ----------------------
9013          -- Implicit_Packing --
9014          ----------------------
9015
9016          --  pragma Implicit_Packing;
9017
9018          when Pragma_Implicit_Packing =>
9019             GNAT_Pragma;
9020             Check_Arg_Count (0);
9021             Implicit_Packing := True;
9022
9023          ------------
9024          -- Import --
9025          ------------
9026
9027          --  pragma Import (
9028          --       [Convention    =>] convention_IDENTIFIER,
9029          --       [Entity        =>] local_NAME
9030          --    [, [External_Name =>] static_string_EXPRESSION ]
9031          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9032
9033          when Pragma_Import =>
9034             Check_Ada_83_Warning;
9035             Check_Arg_Order
9036               ((Name_Convention,
9037                 Name_Entity,
9038                 Name_External_Name,
9039                 Name_Link_Name));
9040             Check_At_Least_N_Arguments (2);
9041             Check_At_Most_N_Arguments  (4);
9042             Process_Import_Or_Interface;
9043
9044          ----------------------
9045          -- Import_Exception --
9046          ----------------------
9047
9048          --  pragma Import_Exception (
9049          --        [Internal         =>] LOCAL_NAME
9050          --     [, [External         =>] EXTERNAL_SYMBOL]
9051          --     [, [Form     =>] Ada | VMS]
9052          --     [, [Code     =>] static_integer_EXPRESSION]);
9053
9054          when Pragma_Import_Exception => Import_Exception : declare
9055             Args  : Args_List (1 .. 4);
9056             Names : constant Name_List (1 .. 4) := (
9057                       Name_Internal,
9058                       Name_External,
9059                       Name_Form,
9060                       Name_Code);
9061
9062             Internal : Node_Id renames Args (1);
9063             External : Node_Id renames Args (2);
9064             Form     : Node_Id renames Args (3);
9065             Code     : Node_Id renames Args (4);
9066
9067          begin
9068             GNAT_Pragma;
9069             Gather_Associations (Names, Args);
9070
9071             if Present (External) and then Present (Code) then
9072                Error_Pragma
9073                  ("cannot give both External and Code options for pragma%");
9074             end if;
9075
9076             Process_Extended_Import_Export_Exception_Pragma (
9077               Arg_Internal => Internal,
9078               Arg_External => External,
9079               Arg_Form     => Form,
9080               Arg_Code     => Code);
9081
9082             if not Is_VMS_Exception (Entity (Internal)) then
9083                Set_Imported (Entity (Internal));
9084             end if;
9085          end Import_Exception;
9086
9087          ---------------------
9088          -- Import_Function --
9089          ---------------------
9090
9091          --  pragma Import_Function (
9092          --        [Internal                 =>] LOCAL_NAME,
9093          --     [, [External                 =>] EXTERNAL_SYMBOL]
9094          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9095          --     [, [Result_Type              =>] SUBTYPE_MARK]
9096          --     [, [Mechanism                =>] MECHANISM]
9097          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9098          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9099
9100          --  EXTERNAL_SYMBOL ::=
9101          --    IDENTIFIER
9102          --  | static_string_EXPRESSION
9103
9104          --  PARAMETER_TYPES ::=
9105          --    null
9106          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9107
9108          --  TYPE_DESIGNATOR ::=
9109          --    subtype_NAME
9110          --  | subtype_Name ' Access
9111
9112          --  MECHANISM ::=
9113          --    MECHANISM_NAME
9114          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9115
9116          --  MECHANISM_ASSOCIATION ::=
9117          --    [formal_parameter_NAME =>] MECHANISM_NAME
9118
9119          --  MECHANISM_NAME ::=
9120          --    Value
9121          --  | Reference
9122          --  | Descriptor [([Class =>] CLASS_NAME)]
9123
9124          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9125
9126          when Pragma_Import_Function => Import_Function : declare
9127             Args  : Args_List (1 .. 7);
9128             Names : constant Name_List (1 .. 7) := (
9129                       Name_Internal,
9130                       Name_External,
9131                       Name_Parameter_Types,
9132                       Name_Result_Type,
9133                       Name_Mechanism,
9134                       Name_Result_Mechanism,
9135                       Name_First_Optional_Parameter);
9136
9137             Internal                 : Node_Id renames Args (1);
9138             External                 : Node_Id renames Args (2);
9139             Parameter_Types          : Node_Id renames Args (3);
9140             Result_Type              : Node_Id renames Args (4);
9141             Mechanism                : Node_Id renames Args (5);
9142             Result_Mechanism         : Node_Id renames Args (6);
9143             First_Optional_Parameter : Node_Id renames Args (7);
9144
9145          begin
9146             GNAT_Pragma;
9147             Gather_Associations (Names, Args);
9148             Process_Extended_Import_Export_Subprogram_Pragma (
9149               Arg_Internal                 => Internal,
9150               Arg_External                 => External,
9151               Arg_Parameter_Types          => Parameter_Types,
9152               Arg_Result_Type              => Result_Type,
9153               Arg_Mechanism                => Mechanism,
9154               Arg_Result_Mechanism         => Result_Mechanism,
9155               Arg_First_Optional_Parameter => First_Optional_Parameter);
9156          end Import_Function;
9157
9158          -------------------
9159          -- Import_Object --
9160          -------------------
9161
9162          --  pragma Import_Object (
9163          --        [Internal =>] LOCAL_NAME
9164          --     [, [External =>] EXTERNAL_SYMBOL]
9165          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9166
9167          --  EXTERNAL_SYMBOL ::=
9168          --    IDENTIFIER
9169          --  | static_string_EXPRESSION
9170
9171          when Pragma_Import_Object => Import_Object : declare
9172             Args  : Args_List (1 .. 3);
9173             Names : constant Name_List (1 .. 3) := (
9174                       Name_Internal,
9175                       Name_External,
9176                       Name_Size);
9177
9178             Internal : Node_Id renames Args (1);
9179             External : Node_Id renames Args (2);
9180             Size     : Node_Id renames Args (3);
9181
9182          begin
9183             GNAT_Pragma;
9184             Gather_Associations (Names, Args);
9185             Process_Extended_Import_Export_Object_Pragma (
9186               Arg_Internal => Internal,
9187               Arg_External => External,
9188               Arg_Size     => Size);
9189          end Import_Object;
9190
9191          ----------------------
9192          -- Import_Procedure --
9193          ----------------------
9194
9195          --  pragma Import_Procedure (
9196          --        [Internal                 =>] LOCAL_NAME
9197          --     [, [External                 =>] EXTERNAL_SYMBOL]
9198          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9199          --     [, [Mechanism                =>] MECHANISM]
9200          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9201
9202          --  EXTERNAL_SYMBOL ::=
9203          --    IDENTIFIER
9204          --  | static_string_EXPRESSION
9205
9206          --  PARAMETER_TYPES ::=
9207          --    null
9208          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9209
9210          --  TYPE_DESIGNATOR ::=
9211          --    subtype_NAME
9212          --  | subtype_Name ' Access
9213
9214          --  MECHANISM ::=
9215          --    MECHANISM_NAME
9216          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9217
9218          --  MECHANISM_ASSOCIATION ::=
9219          --    [formal_parameter_NAME =>] MECHANISM_NAME
9220
9221          --  MECHANISM_NAME ::=
9222          --    Value
9223          --  | Reference
9224          --  | Descriptor [([Class =>] CLASS_NAME)]
9225
9226          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9227
9228          when Pragma_Import_Procedure => Import_Procedure : declare
9229             Args  : Args_List (1 .. 5);
9230             Names : constant Name_List (1 .. 5) := (
9231                       Name_Internal,
9232                       Name_External,
9233                       Name_Parameter_Types,
9234                       Name_Mechanism,
9235                       Name_First_Optional_Parameter);
9236
9237             Internal                 : Node_Id renames Args (1);
9238             External                 : Node_Id renames Args (2);
9239             Parameter_Types          : Node_Id renames Args (3);
9240             Mechanism                : Node_Id renames Args (4);
9241             First_Optional_Parameter : Node_Id renames Args (5);
9242
9243          begin
9244             GNAT_Pragma;
9245             Gather_Associations (Names, Args);
9246             Process_Extended_Import_Export_Subprogram_Pragma (
9247               Arg_Internal                 => Internal,
9248               Arg_External                 => External,
9249               Arg_Parameter_Types          => Parameter_Types,
9250               Arg_Mechanism                => Mechanism,
9251               Arg_First_Optional_Parameter => First_Optional_Parameter);
9252          end Import_Procedure;
9253
9254          -----------------------------
9255          -- Import_Valued_Procedure --
9256          -----------------------------
9257
9258          --  pragma Import_Valued_Procedure (
9259          --        [Internal                 =>] LOCAL_NAME
9260          --     [, [External                 =>] EXTERNAL_SYMBOL]
9261          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9262          --     [, [Mechanism                =>] MECHANISM]
9263          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9264
9265          --  EXTERNAL_SYMBOL ::=
9266          --    IDENTIFIER
9267          --  | static_string_EXPRESSION
9268
9269          --  PARAMETER_TYPES ::=
9270          --    null
9271          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9272
9273          --  TYPE_DESIGNATOR ::=
9274          --    subtype_NAME
9275          --  | subtype_Name ' Access
9276
9277          --  MECHANISM ::=
9278          --    MECHANISM_NAME
9279          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9280
9281          --  MECHANISM_ASSOCIATION ::=
9282          --    [formal_parameter_NAME =>] MECHANISM_NAME
9283
9284          --  MECHANISM_NAME ::=
9285          --    Value
9286          --  | Reference
9287          --  | Descriptor [([Class =>] CLASS_NAME)]
9288
9289          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9290
9291          when Pragma_Import_Valued_Procedure =>
9292          Import_Valued_Procedure : declare
9293             Args  : Args_List (1 .. 5);
9294             Names : constant Name_List (1 .. 5) := (
9295                       Name_Internal,
9296                       Name_External,
9297                       Name_Parameter_Types,
9298                       Name_Mechanism,
9299                       Name_First_Optional_Parameter);
9300
9301             Internal                 : Node_Id renames Args (1);
9302             External                 : Node_Id renames Args (2);
9303             Parameter_Types          : Node_Id renames Args (3);
9304             Mechanism                : Node_Id renames Args (4);
9305             First_Optional_Parameter : Node_Id renames Args (5);
9306
9307          begin
9308             GNAT_Pragma;
9309             Gather_Associations (Names, Args);
9310             Process_Extended_Import_Export_Subprogram_Pragma (
9311               Arg_Internal                 => Internal,
9312               Arg_External                 => External,
9313               Arg_Parameter_Types          => Parameter_Types,
9314               Arg_Mechanism                => Mechanism,
9315               Arg_First_Optional_Parameter => First_Optional_Parameter);
9316          end Import_Valued_Procedure;
9317
9318          -----------------
9319          -- Independent --
9320          -----------------
9321
9322          --  pragma Independent (LOCAL_NAME);
9323
9324          when Pragma_Independent => Independent : declare
9325             E_Id : Node_Id;
9326             E    : Entity_Id;
9327             D    : Node_Id;
9328             K    : Node_Kind;
9329
9330          begin
9331             Check_Ada_83_Warning;
9332             Ada_2012_Pragma;
9333             Check_No_Identifiers;
9334             Check_Arg_Count (1);
9335             Check_Arg_Is_Local_Name (Arg1);
9336             E_Id := Get_Pragma_Arg (Arg1);
9337
9338             if Etype (E_Id) = Any_Type then
9339                return;
9340             end if;
9341
9342             E := Entity (E_Id);
9343             D := Declaration_Node (E);
9344             K := Nkind (D);
9345
9346             --  Check duplicate before we chain ourselves!
9347
9348             Check_Duplicate_Pragma (E);
9349
9350             --  Check appropriate entity
9351
9352             if Is_Type (E) then
9353                if Rep_Item_Too_Early (E, N)
9354                     or else
9355                   Rep_Item_Too_Late (E, N)
9356                then
9357                   return;
9358                else
9359                   Check_First_Subtype (Arg1);
9360                end if;
9361
9362             elsif K = N_Object_Declaration
9363               or else (K = N_Component_Declaration
9364                        and then Original_Record_Component (E) = E)
9365             then
9366                if Rep_Item_Too_Late (E, N) then
9367                   return;
9368                end if;
9369
9370             else
9371                Error_Pragma_Arg
9372                  ("inappropriate entity for pragma%", Arg1);
9373             end if;
9374
9375             Independence_Checks.Append ((N, E));
9376          end Independent;
9377
9378          ----------------------------
9379          -- Independent_Components --
9380          ----------------------------
9381
9382          --  pragma Atomic_Components (array_LOCAL_NAME);
9383
9384          --  This processing is shared by Volatile_Components
9385
9386          when Pragma_Independent_Components => Independent_Components : declare
9387             E_Id : Node_Id;
9388             E    : Entity_Id;
9389             D    : Node_Id;
9390             K    : Node_Kind;
9391
9392          begin
9393             Check_Ada_83_Warning;
9394             Ada_2012_Pragma;
9395             Check_No_Identifiers;
9396             Check_Arg_Count (1);
9397             Check_Arg_Is_Local_Name (Arg1);
9398             E_Id := Get_Pragma_Arg (Arg1);
9399
9400             if Etype (E_Id) = Any_Type then
9401                return;
9402             end if;
9403
9404             E := Entity (E_Id);
9405
9406             --  Check duplicate before we chain ourselves!
9407
9408             Check_Duplicate_Pragma (E);
9409
9410             --  Check appropriate entity
9411
9412             if Rep_Item_Too_Early (E, N)
9413                  or else
9414                Rep_Item_Too_Late (E, N)
9415             then
9416                return;
9417             end if;
9418
9419             D := Declaration_Node (E);
9420             K := Nkind (D);
9421
9422             if (K = N_Full_Type_Declaration
9423                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9424               or else
9425                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9426                    and then Nkind (D) = N_Object_Declaration
9427                    and then Nkind (Object_Definition (D)) =
9428                                        N_Constrained_Array_Definition)
9429             then
9430                Independence_Checks.Append ((N, E));
9431
9432             else
9433                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9434             end if;
9435          end Independent_Components;
9436
9437          ------------------------
9438          -- Initialize_Scalars --
9439          ------------------------
9440
9441          --  pragma Initialize_Scalars;
9442
9443          when Pragma_Initialize_Scalars =>
9444             GNAT_Pragma;
9445             Check_Arg_Count (0);
9446             Check_Valid_Configuration_Pragma;
9447             Check_Restriction (No_Initialize_Scalars, N);
9448
9449             --  Initialize_Scalars creates false positives in CodePeer,
9450             --  so ignore this pragma in this mode.
9451
9452             if not Restriction_Active (No_Initialize_Scalars)
9453               and then not CodePeer_Mode
9454             then
9455                Init_Or_Norm_Scalars := True;
9456                Initialize_Scalars := True;
9457             end if;
9458
9459          ------------
9460          -- Inline --
9461          ------------
9462
9463          --  pragma Inline ( NAME {, NAME} );
9464
9465          when Pragma_Inline =>
9466
9467             --  Pragma is active if inlining option is active
9468
9469             Process_Inline (Inline_Active);
9470
9471          -------------------
9472          -- Inline_Always --
9473          -------------------
9474
9475          --  pragma Inline_Always ( NAME {, NAME} );
9476
9477          when Pragma_Inline_Always =>
9478             GNAT_Pragma;
9479
9480             --  Pragma always active unless in CodePeer mode, since this causes
9481             --  walk order issues.
9482
9483             if not CodePeer_Mode then
9484                Process_Inline (True);
9485             end if;
9486
9487          --------------------
9488          -- Inline_Generic --
9489          --------------------
9490
9491          --  pragma Inline_Generic (NAME {, NAME});
9492
9493          when Pragma_Inline_Generic =>
9494             GNAT_Pragma;
9495             Process_Generic_List;
9496
9497          ----------------------
9498          -- Inspection_Point --
9499          ----------------------
9500
9501          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9502
9503          when Pragma_Inspection_Point => Inspection_Point : declare
9504             Arg : Node_Id;
9505             Exp : Node_Id;
9506
9507          begin
9508             if Arg_Count > 0 then
9509                Arg := Arg1;
9510                loop
9511                   Exp := Get_Pragma_Arg (Arg);
9512                   Analyze (Exp);
9513
9514                   if not Is_Entity_Name (Exp)
9515                     or else not Is_Object (Entity (Exp))
9516                   then
9517                      Error_Pragma_Arg ("object name required", Arg);
9518                   end if;
9519
9520                   Next (Arg);
9521                   exit when No (Arg);
9522                end loop;
9523             end if;
9524          end Inspection_Point;
9525
9526          ---------------
9527          -- Interface --
9528          ---------------
9529
9530          --  pragma Interface (
9531          --    [   Convention    =>] convention_IDENTIFIER,
9532          --    [   Entity        =>] local_NAME
9533          --    [, [External_Name =>] static_string_EXPRESSION ]
9534          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9535
9536          when Pragma_Interface =>
9537             GNAT_Pragma;
9538             Check_Arg_Order
9539               ((Name_Convention,
9540                 Name_Entity,
9541                 Name_External_Name,
9542                 Name_Link_Name));
9543             Check_At_Least_N_Arguments (2);
9544             Check_At_Most_N_Arguments  (4);
9545             Process_Import_Or_Interface;
9546
9547             --  In Ada 2005, the permission to use Interface (a reserved word)
9548             --  as a pragma name is considered an obsolescent feature.
9549
9550             if Ada_Version >= Ada_2005 then
9551                Check_Restriction
9552                  (No_Obsolescent_Features, Pragma_Identifier (N));
9553             end if;
9554
9555          --------------------
9556          -- Interface_Name --
9557          --------------------
9558
9559          --  pragma Interface_Name (
9560          --    [  Entity        =>] local_NAME
9561          --    [,[External_Name =>] static_string_EXPRESSION ]
9562          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9563
9564          when Pragma_Interface_Name => Interface_Name : declare
9565             Id     : Node_Id;
9566             Def_Id : Entity_Id;
9567             Hom_Id : Entity_Id;
9568             Found  : Boolean;
9569
9570          begin
9571             GNAT_Pragma;
9572             Check_Arg_Order
9573               ((Name_Entity, Name_External_Name, Name_Link_Name));
9574             Check_At_Least_N_Arguments (2);
9575             Check_At_Most_N_Arguments  (3);
9576             Id := Get_Pragma_Arg (Arg1);
9577             Analyze (Id);
9578
9579             if not Is_Entity_Name (Id) then
9580                Error_Pragma_Arg
9581                  ("first argument for pragma% must be entity name", Arg1);
9582             elsif Etype (Id) = Any_Type then
9583                return;
9584             else
9585                Def_Id := Entity (Id);
9586             end if;
9587
9588             --  Special DEC-compatible processing for the object case, forces
9589             --  object to be imported.
9590
9591             if Ekind (Def_Id) = E_Variable then
9592                Kill_Size_Check_Code (Def_Id);
9593                Note_Possible_Modification (Id, Sure => False);
9594
9595                --  Initialization is not allowed for imported variable
9596
9597                if Present (Expression (Parent (Def_Id)))
9598                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9599                then
9600                   Error_Msg_Sloc := Sloc (Def_Id);
9601                   Error_Pragma_Arg
9602                     ("no initialization allowed for declaration of& #",
9603                      Arg2);
9604
9605                else
9606                   --  For compatibility, support VADS usage of providing both
9607                   --  pragmas Interface and Interface_Name to obtain the effect
9608                   --  of a single Import pragma.
9609
9610                   if Is_Imported (Def_Id)
9611                     and then Present (First_Rep_Item (Def_Id))
9612                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9613                     and then
9614                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9615                   then
9616                      null;
9617                   else
9618                      Set_Imported (Def_Id);
9619                   end if;
9620
9621                   Set_Is_Public (Def_Id);
9622                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9623                end if;
9624
9625             --  Otherwise must be subprogram
9626
9627             elsif not Is_Subprogram (Def_Id) then
9628                Error_Pragma_Arg
9629                  ("argument of pragma% is not subprogram", Arg1);
9630
9631             else
9632                Check_At_Most_N_Arguments (3);
9633                Hom_Id := Def_Id;
9634                Found := False;
9635
9636                --  Loop through homonyms
9637
9638                loop
9639                   Def_Id := Get_Base_Subprogram (Hom_Id);
9640
9641                   if Is_Imported (Def_Id) then
9642                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9643                      Found := True;
9644                   end if;
9645
9646                   exit when From_Aspect_Specification (N);
9647                   Hom_Id := Homonym (Hom_Id);
9648
9649                   exit when No (Hom_Id)
9650                     or else Scope (Hom_Id) /= Current_Scope;
9651                end loop;
9652
9653                if not Found then
9654                   Error_Pragma_Arg
9655                     ("argument of pragma% is not imported subprogram",
9656                      Arg1);
9657                end if;
9658             end if;
9659          end Interface_Name;
9660
9661          -----------------------
9662          -- Interrupt_Handler --
9663          -----------------------
9664
9665          --  pragma Interrupt_Handler (handler_NAME);
9666
9667          when Pragma_Interrupt_Handler =>
9668             Check_Ada_83_Warning;
9669             Check_Arg_Count (1);
9670             Check_No_Identifiers;
9671
9672             if No_Run_Time_Mode then
9673                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9674             else
9675                Check_Interrupt_Or_Attach_Handler;
9676                Process_Interrupt_Or_Attach_Handler;
9677             end if;
9678
9679          ------------------------
9680          -- Interrupt_Priority --
9681          ------------------------
9682
9683          --  pragma Interrupt_Priority [(EXPRESSION)];
9684
9685          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9686             P   : constant Node_Id := Parent (N);
9687             Arg : Node_Id;
9688
9689          begin
9690             Check_Ada_83_Warning;
9691
9692             if Arg_Count /= 0 then
9693                Arg := Get_Pragma_Arg (Arg1);
9694                Check_Arg_Count (1);
9695                Check_No_Identifiers;
9696
9697                --  The expression must be analyzed in the special manner
9698                --  described in "Handling of Default and Per-Object
9699                --  Expressions" in sem.ads.
9700
9701                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9702             end if;
9703
9704             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9705                Pragma_Misplaced;
9706                return;
9707
9708             elsif Has_Pragma_Priority (P) then
9709                Error_Pragma ("duplicate pragma% not allowed");
9710
9711             else
9712                Set_Has_Pragma_Priority (P, True);
9713                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9714             end if;
9715          end Interrupt_Priority;
9716
9717          ---------------------
9718          -- Interrupt_State --
9719          ---------------------
9720
9721          --  pragma Interrupt_State (
9722          --    [Name  =>] INTERRUPT_ID,
9723          --    [State =>] INTERRUPT_STATE);
9724
9725          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9726          --  INTERRUPT_STATE => System | Runtime | User
9727
9728          --  Note: if the interrupt id is given as an identifier, then it must
9729          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9730          --  given as a static integer expression which must be in the range of
9731          --  Ada.Interrupts.Interrupt_ID.
9732
9733          when Pragma_Interrupt_State => Interrupt_State : declare
9734
9735             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9736             --  This is the entity Ada.Interrupts.Interrupt_ID;
9737
9738             State_Type : Character;
9739             --  Set to 's'/'r'/'u' for System/Runtime/User
9740
9741             IST_Num : Pos;
9742             --  Index to entry in Interrupt_States table
9743
9744             Int_Val : Uint;
9745             --  Value of interrupt
9746
9747             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9748             --  The first argument to the pragma
9749
9750             Int_Ent : Entity_Id;
9751             --  Interrupt entity in Ada.Interrupts.Names
9752
9753          begin
9754             GNAT_Pragma;
9755             Check_Arg_Order ((Name_Name, Name_State));
9756             Check_Arg_Count (2);
9757
9758             Check_Optional_Identifier (Arg1, Name_Name);
9759             Check_Optional_Identifier (Arg2, Name_State);
9760             Check_Arg_Is_Identifier (Arg2);
9761
9762             --  First argument is identifier
9763
9764             if Nkind (Arg1X) = N_Identifier then
9765
9766                --  Search list of names in Ada.Interrupts.Names
9767
9768                Int_Ent := First_Entity (RTE (RE_Names));
9769                loop
9770                   if No (Int_Ent) then
9771                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9772
9773                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9774                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9775                      exit;
9776                   end if;
9777
9778                   Next_Entity (Int_Ent);
9779                end loop;
9780
9781             --  First argument is not an identifier, so it must be a static
9782             --  expression of type Ada.Interrupts.Interrupt_ID.
9783
9784             else
9785                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9786                Int_Val := Expr_Value (Arg1X);
9787
9788                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9789                     or else
9790                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9791                then
9792                   Error_Pragma_Arg
9793                     ("value not in range of type " &
9794                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9795                end if;
9796             end if;
9797
9798             --  Check OK state
9799
9800             case Chars (Get_Pragma_Arg (Arg2)) is
9801                when Name_Runtime => State_Type := 'r';
9802                when Name_System  => State_Type := 's';
9803                when Name_User    => State_Type := 'u';
9804
9805                when others =>
9806                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
9807             end case;
9808
9809             --  Check if entry is already stored
9810
9811             IST_Num := Interrupt_States.First;
9812             loop
9813                --  If entry not found, add it
9814
9815                if IST_Num > Interrupt_States.Last then
9816                   Interrupt_States.Append
9817                     ((Interrupt_Number => UI_To_Int (Int_Val),
9818                       Interrupt_State  => State_Type,
9819                       Pragma_Loc       => Loc));
9820                   exit;
9821
9822                --  Case of entry for the same entry
9823
9824                elsif Int_Val = Interrupt_States.Table (IST_Num).
9825                                                            Interrupt_Number
9826                then
9827                   --  If state matches, done, no need to make redundant entry
9828
9829                   exit when
9830                     State_Type = Interrupt_States.Table (IST_Num).
9831                                                            Interrupt_State;
9832
9833                   --  Otherwise if state does not match, error
9834
9835                   Error_Msg_Sloc :=
9836                     Interrupt_States.Table (IST_Num).Pragma_Loc;
9837                   Error_Pragma_Arg
9838                     ("state conflicts with that given #", Arg2);
9839                   exit;
9840                end if;
9841
9842                IST_Num := IST_Num + 1;
9843             end loop;
9844          end Interrupt_State;
9845
9846          ---------------
9847          -- Invariant --
9848          ---------------
9849
9850          --  pragma Invariant
9851          --    ([Entity =>]    type_LOCAL_NAME,
9852          --     [Check  =>]    EXPRESSION
9853          --     [,[Message =>] String_Expression]);
9854
9855          when Pragma_Invariant => Invariant : declare
9856             Type_Id : Node_Id;
9857             Typ     : Entity_Id;
9858
9859             Discard : Boolean;
9860             pragma Unreferenced (Discard);
9861
9862          begin
9863             GNAT_Pragma;
9864             Check_At_Least_N_Arguments (2);
9865             Check_At_Most_N_Arguments (3);
9866             Check_Optional_Identifier (Arg1, Name_Entity);
9867             Check_Optional_Identifier (Arg2, Name_Check);
9868
9869             if Arg_Count = 3 then
9870                Check_Optional_Identifier (Arg3, Name_Message);
9871                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9872             end if;
9873
9874             Check_Arg_Is_Local_Name (Arg1);
9875
9876             Type_Id := Get_Pragma_Arg (Arg1);
9877             Find_Type (Type_Id);
9878             Typ := Entity (Type_Id);
9879
9880             if Typ = Any_Type then
9881                return;
9882
9883             elsif not Ekind_In (Typ, E_Private_Type,
9884                                      E_Record_Type_With_Private,
9885                                      E_Limited_Private_Type)
9886             then
9887                Error_Pragma_Arg
9888                  ("pragma% only allowed for private type", Arg1);
9889             end if;
9890
9891             --  Note that the type has at least one invariant, and also that
9892             --  it has inheritable invariants if we have Invariant'Class.
9893
9894             Set_Has_Invariants (Typ);
9895
9896             if Class_Present (N) then
9897                Set_Has_Inheritable_Invariants (Typ);
9898             end if;
9899
9900             --  The remaining processing is simply to link the pragma on to
9901             --  the rep item chain, for processing when the type is frozen.
9902             --  This is accomplished by a call to Rep_Item_Too_Late.
9903
9904             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9905          end Invariant;
9906
9907          ----------------------
9908          -- Java_Constructor --
9909          ----------------------
9910
9911          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9912
9913          --  Also handles pragma CIL_Constructor
9914
9915          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9916          Java_Constructor : declare
9917             Convention  : Convention_Id;
9918             Def_Id      : Entity_Id;
9919             Hom_Id      : Entity_Id;
9920             Id          : Entity_Id;
9921             This_Formal : Entity_Id;
9922
9923          begin
9924             GNAT_Pragma;
9925             Check_Arg_Count (1);
9926             Check_Optional_Identifier (Arg1, Name_Entity);
9927             Check_Arg_Is_Local_Name (Arg1);
9928
9929             Id := Get_Pragma_Arg (Arg1);
9930             Find_Program_Unit_Name (Id);
9931
9932             --  If we did not find the name, we are done
9933
9934             if Etype (Id) = Any_Type then
9935                return;
9936             end if;
9937
9938             --  Check wrong use of pragma in wrong VM target
9939
9940             if VM_Target = No_VM then
9941                return;
9942
9943             elsif VM_Target = CLI_Target
9944               and then Prag_Id = Pragma_Java_Constructor
9945             then
9946                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
9947
9948             elsif VM_Target = JVM_Target
9949               and then Prag_Id = Pragma_CIL_Constructor
9950             then
9951                Error_Pragma ("must use pragma 'Java_'Constructor");
9952             end if;
9953
9954             case Prag_Id is
9955                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
9956                when Pragma_Java_Constructor => Convention := Convention_Java;
9957                when others                  => null;
9958             end case;
9959
9960             Hom_Id := Entity (Id);
9961
9962             --  Loop through homonyms
9963
9964             loop
9965                Def_Id := Get_Base_Subprogram (Hom_Id);
9966
9967                --  The constructor is required to be a function
9968
9969                if Ekind (Def_Id) /= E_Function then
9970                   if VM_Target = JVM_Target then
9971                      Error_Pragma_Arg
9972                        ("pragma% requires function returning a " &
9973                         "'Java access type", Def_Id);
9974                   else
9975                      Error_Pragma_Arg
9976                        ("pragma% requires function returning a " &
9977                         "'C'I'L access type", Def_Id);
9978                   end if;
9979                end if;
9980
9981                --  Check arguments: For tagged type the first formal must be
9982                --  named "this" and its type must be a named access type
9983                --  designating a class-wide tagged type that has convention
9984                --  CIL/Java. The first formal must also have a null default
9985                --  value. For example:
9986
9987                --      type Typ is tagged ...
9988                --      type Ref is access all Typ;
9989                --      pragma Convention (CIL, Typ);
9990
9991                --      function New_Typ (This : Ref) return Ref;
9992                --      function New_Typ (This : Ref; I : Integer) return Ref;
9993                --      pragma Cil_Constructor (New_Typ);
9994
9995                --  Reason: The first formal must NOT be a primitive of the
9996                --  tagged type.
9997
9998                --  This rule also applies to constructors of delegates used
9999                --  to interface with standard target libraries. For example:
10000
10001                --      type Delegate is access procedure ...
10002                --      pragma Import (CIL, Delegate, ...);
10003
10004                --      function new_Delegate
10005                --        (This : Delegate := null; ... ) return Delegate;
10006
10007                --  For value-types this rule does not apply.
10008
10009                if not Is_Value_Type (Etype (Def_Id)) then
10010                   if No (First_Formal (Def_Id)) then
10011                      Error_Msg_Name_1 := Pname;
10012                      Error_Msg_N ("% function must have parameters", Def_Id);
10013                      return;
10014                   end if;
10015
10016                   --  In the JRE library we have several occurrences in which
10017                   --  the "this" parameter is not the first formal.
10018
10019                   This_Formal := First_Formal (Def_Id);
10020
10021                   --  In the JRE library we have several occurrences in which
10022                   --  the "this" parameter is not the first formal. Search for
10023                   --  it.
10024
10025                   if VM_Target = JVM_Target then
10026                      while Present (This_Formal)
10027                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10028                      loop
10029                         Next_Formal (This_Formal);
10030                      end loop;
10031
10032                      if No (This_Formal) then
10033                         This_Formal := First_Formal (Def_Id);
10034                      end if;
10035                   end if;
10036
10037                   --  Warning: The first parameter should be named "this".
10038                   --  We temporarily allow it because we have the following
10039                   --  case in the Java runtime (file s-osinte.ads) ???
10040
10041                   --    function new_Thread
10042                   --      (Self_Id : System.Address) return Thread_Id;
10043                   --    pragma Java_Constructor (new_Thread);
10044
10045                   if VM_Target = JVM_Target
10046                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10047                                = "self_id"
10048                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10049                   then
10050                      null;
10051
10052                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10053                      Error_Msg_Name_1 := Pname;
10054                      Error_Msg_N
10055                        ("first formal of % function must be named `this`",
10056                         Parent (This_Formal));
10057
10058                   elsif not Is_Access_Type (Etype (This_Formal)) then
10059                      Error_Msg_Name_1 := Pname;
10060                      Error_Msg_N
10061                        ("first formal of % function must be an access type",
10062                         Parameter_Type (Parent (This_Formal)));
10063
10064                   --  For delegates the type of the first formal must be a
10065                   --  named access-to-subprogram type (see previous example)
10066
10067                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10068                     and then Ekind (Etype (This_Formal))
10069                                /= E_Access_Subprogram_Type
10070                   then
10071                      Error_Msg_Name_1 := Pname;
10072                      Error_Msg_N
10073                        ("first formal of % function must be a named access" &
10074                         " to subprogram type",
10075                         Parameter_Type (Parent (This_Formal)));
10076
10077                   --  Warning: We should reject anonymous access types because
10078                   --  the constructor must not be handled as a primitive of the
10079                   --  tagged type. We temporarily allow it because this profile
10080                   --  is currently generated by cil2ada???
10081
10082                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10083                     and then not Ekind_In (Etype (This_Formal),
10084                                              E_Access_Type,
10085                                              E_General_Access_Type,
10086                                              E_Anonymous_Access_Type)
10087                   then
10088                      Error_Msg_Name_1 := Pname;
10089                      Error_Msg_N
10090                        ("first formal of % function must be a named access" &
10091                         " type",
10092                         Parameter_Type (Parent (This_Formal)));
10093
10094                   elsif Atree.Convention
10095                          (Designated_Type (Etype (This_Formal))) /= Convention
10096                   then
10097                      Error_Msg_Name_1 := Pname;
10098
10099                      if Convention = Convention_Java then
10100                         Error_Msg_N
10101                           ("pragma% requires convention 'Cil in designated" &
10102                            " type",
10103                            Parameter_Type (Parent (This_Formal)));
10104                      else
10105                         Error_Msg_N
10106                           ("pragma% requires convention 'Java in designated" &
10107                            " type",
10108                            Parameter_Type (Parent (This_Formal)));
10109                      end if;
10110
10111                   elsif No (Expression (Parent (This_Formal)))
10112                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10113                   then
10114                      Error_Msg_Name_1 := Pname;
10115                      Error_Msg_N
10116                        ("pragma% requires first formal with default `null`",
10117                         Parameter_Type (Parent (This_Formal)));
10118                   end if;
10119                end if;
10120
10121                --  Check result type: the constructor must be a function
10122                --  returning:
10123                --   * a value type (only allowed in the CIL compiler)
10124                --   * an access-to-subprogram type with convention Java/CIL
10125                --   * an access-type designating a type that has convention
10126                --     Java/CIL.
10127
10128                if Is_Value_Type (Etype (Def_Id)) then
10129                   null;
10130
10131                --  Access-to-subprogram type with convention Java/CIL
10132
10133                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10134                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10135                      if Convention = Convention_Java then
10136                         Error_Pragma_Arg
10137                           ("pragma% requires function returning a " &
10138                            "'Java access type", Arg1);
10139                      else
10140                         pragma Assert (Convention = Convention_CIL);
10141                         Error_Pragma_Arg
10142                           ("pragma% requires function returning a " &
10143                            "'C'I'L access type", Arg1);
10144                      end if;
10145                   end if;
10146
10147                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10148                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10149                                                    E_General_Access_Type)
10150                     or else
10151                       Atree.Convention
10152                         (Designated_Type (Etype (Def_Id))) /= Convention
10153                   then
10154                      Error_Msg_Name_1 := Pname;
10155
10156                      if Convention = Convention_Java then
10157                         Error_Pragma_Arg
10158                           ("pragma% requires function returning a named" &
10159                            "'Java access type", Arg1);
10160                      else
10161                         Error_Pragma_Arg
10162                           ("pragma% requires function returning a named" &
10163                            "'C'I'L access type", Arg1);
10164                      end if;
10165                   end if;
10166                end if;
10167
10168                Set_Is_Constructor (Def_Id);
10169                Set_Convention     (Def_Id, Convention);
10170                Set_Is_Imported    (Def_Id);
10171
10172                exit when From_Aspect_Specification (N);
10173                Hom_Id := Homonym (Hom_Id);
10174
10175                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10176             end loop;
10177          end Java_Constructor;
10178
10179          ----------------------
10180          -- Java_Interface --
10181          ----------------------
10182
10183          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10184
10185          when Pragma_Java_Interface => Java_Interface : declare
10186             Arg : Node_Id;
10187             Typ : Entity_Id;
10188
10189          begin
10190             GNAT_Pragma;
10191             Check_Arg_Count (1);
10192             Check_Optional_Identifier (Arg1, Name_Entity);
10193             Check_Arg_Is_Local_Name (Arg1);
10194
10195             Arg := Get_Pragma_Arg (Arg1);
10196             Analyze (Arg);
10197
10198             if Etype (Arg) = Any_Type then
10199                return;
10200             end if;
10201
10202             if not Is_Entity_Name (Arg)
10203               or else not Is_Type (Entity (Arg))
10204             then
10205                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10206             end if;
10207
10208             Typ := Underlying_Type (Entity (Arg));
10209
10210             --  For now simply check some of the semantic constraints on the
10211             --  type. This currently leaves out some restrictions on interface
10212             --  types, namely that the parent type must be java.lang.Object.Typ
10213             --  and that all primitives of the type should be declared
10214             --  abstract. ???
10215
10216             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10217                Error_Pragma_Arg ("pragma% requires an abstract "
10218                  & "tagged type", Arg1);
10219
10220             elsif not Has_Discriminants (Typ)
10221               or else Ekind (Etype (First_Discriminant (Typ)))
10222                         /= E_Anonymous_Access_Type
10223               or else
10224                 not Is_Class_Wide_Type
10225                       (Designated_Type (Etype (First_Discriminant (Typ))))
10226             then
10227                Error_Pragma_Arg
10228                  ("type must have a class-wide access discriminant", Arg1);
10229             end if;
10230          end Java_Interface;
10231
10232          ----------------
10233          -- Keep_Names --
10234          ----------------
10235
10236          --  pragma Keep_Names ([On => ] local_NAME);
10237
10238          when Pragma_Keep_Names => Keep_Names : declare
10239             Arg : Node_Id;
10240
10241          begin
10242             GNAT_Pragma;
10243             Check_Arg_Count (1);
10244             Check_Optional_Identifier (Arg1, Name_On);
10245             Check_Arg_Is_Local_Name (Arg1);
10246
10247             Arg := Get_Pragma_Arg (Arg1);
10248             Analyze (Arg);
10249
10250             if Etype (Arg) = Any_Type then
10251                return;
10252             end if;
10253
10254             if not Is_Entity_Name (Arg)
10255               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10256             then
10257                Error_Pragma_Arg
10258                  ("pragma% requires a local enumeration type", Arg1);
10259             end if;
10260
10261             Set_Discard_Names (Entity (Arg), False);
10262          end Keep_Names;
10263
10264          -------------
10265          -- License --
10266          -------------
10267
10268          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10269
10270          when Pragma_License =>
10271             GNAT_Pragma;
10272             Check_Arg_Count (1);
10273             Check_No_Identifiers;
10274             Check_Valid_Configuration_Pragma;
10275             Check_Arg_Is_Identifier (Arg1);
10276
10277             declare
10278                Sind : constant Source_File_Index :=
10279                         Source_Index (Current_Sem_Unit);
10280
10281             begin
10282                case Chars (Get_Pragma_Arg (Arg1)) is
10283                   when Name_GPL =>
10284                      Set_License (Sind, GPL);
10285
10286                   when Name_Modified_GPL =>
10287                      Set_License (Sind, Modified_GPL);
10288
10289                   when Name_Restricted =>
10290                      Set_License (Sind, Restricted);
10291
10292                   when Name_Unrestricted =>
10293                      Set_License (Sind, Unrestricted);
10294
10295                   when others =>
10296                      Error_Pragma_Arg ("invalid license name", Arg1);
10297                end case;
10298             end;
10299
10300          ---------------
10301          -- Link_With --
10302          ---------------
10303
10304          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10305
10306          when Pragma_Link_With => Link_With : declare
10307             Arg : Node_Id;
10308
10309          begin
10310             GNAT_Pragma;
10311
10312             if Operating_Mode = Generate_Code
10313               and then In_Extended_Main_Source_Unit (N)
10314             then
10315                Check_At_Least_N_Arguments (1);
10316                Check_No_Identifiers;
10317                Check_Is_In_Decl_Part_Or_Package_Spec;
10318                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10319                Start_String;
10320
10321                Arg := Arg1;
10322                while Present (Arg) loop
10323                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10324
10325                   --  Store argument, converting sequences of spaces to a
10326                   --  single null character (this is one of the differences
10327                   --  in processing between Link_With and Linker_Options).
10328
10329                   Arg_Store : declare
10330                      C : constant Char_Code := Get_Char_Code (' ');
10331                      S : constant String_Id :=
10332                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10333                      L : constant Nat := String_Length (S);
10334                      F : Nat := 1;
10335
10336                      procedure Skip_Spaces;
10337                      --  Advance F past any spaces
10338
10339                      -----------------
10340                      -- Skip_Spaces --
10341                      -----------------
10342
10343                      procedure Skip_Spaces is
10344                      begin
10345                         while F <= L and then Get_String_Char (S, F) = C loop
10346                            F := F + 1;
10347                         end loop;
10348                      end Skip_Spaces;
10349
10350                   --  Start of processing for Arg_Store
10351
10352                   begin
10353                      Skip_Spaces; -- skip leading spaces
10354
10355                      --  Loop through characters, changing any embedded
10356                      --  sequence of spaces to a single null character (this
10357                      --  is how Link_With/Linker_Options differ)
10358
10359                      while F <= L loop
10360                         if Get_String_Char (S, F) = C then
10361                            Skip_Spaces;
10362                            exit when F > L;
10363                            Store_String_Char (ASCII.NUL);
10364
10365                         else
10366                            Store_String_Char (Get_String_Char (S, F));
10367                            F := F + 1;
10368                         end if;
10369                      end loop;
10370                   end Arg_Store;
10371
10372                   Arg := Next (Arg);
10373
10374                   if Present (Arg) then
10375                      Store_String_Char (ASCII.NUL);
10376                   end if;
10377                end loop;
10378
10379                Store_Linker_Option_String (End_String);
10380             end if;
10381          end Link_With;
10382
10383          ------------------
10384          -- Linker_Alias --
10385          ------------------
10386
10387          --  pragma Linker_Alias (
10388          --      [Entity =>]  LOCAL_NAME
10389          --      [Target =>]  static_string_EXPRESSION);
10390
10391          when Pragma_Linker_Alias =>
10392             GNAT_Pragma;
10393             Check_Arg_Order ((Name_Entity, Name_Target));
10394             Check_Arg_Count (2);
10395             Check_Optional_Identifier (Arg1, Name_Entity);
10396             Check_Optional_Identifier (Arg2, Name_Target);
10397             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10398             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10399
10400             --  The only processing required is to link this item on to the
10401             --  list of rep items for the given entity. This is accomplished
10402             --  by the call to Rep_Item_Too_Late (when no error is detected
10403             --  and False is returned).
10404
10405             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10406                return;
10407             else
10408                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10409             end if;
10410
10411          ------------------------
10412          -- Linker_Constructor --
10413          ------------------------
10414
10415          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10416
10417          --  Code is shared with Linker_Destructor
10418
10419          -----------------------
10420          -- Linker_Destructor --
10421          -----------------------
10422
10423          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10424
10425          when Pragma_Linker_Constructor |
10426               Pragma_Linker_Destructor =>
10427          Linker_Constructor : declare
10428             Arg1_X : Node_Id;
10429             Proc   : Entity_Id;
10430
10431          begin
10432             GNAT_Pragma;
10433             Check_Arg_Count (1);
10434             Check_No_Identifiers;
10435             Check_Arg_Is_Local_Name (Arg1);
10436             Arg1_X := Get_Pragma_Arg (Arg1);
10437             Analyze (Arg1_X);
10438             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10439
10440             if not Is_Library_Level_Entity (Proc) then
10441                Error_Pragma_Arg
10442                 ("argument for pragma% must be library level entity", Arg1);
10443             end if;
10444
10445             --  The only processing required is to link this item on to the
10446             --  list of rep items for the given entity. This is accomplished
10447             --  by the call to Rep_Item_Too_Late (when no error is detected
10448             --  and False is returned).
10449
10450             if Rep_Item_Too_Late (Proc, N) then
10451                return;
10452             else
10453                Set_Has_Gigi_Rep_Item (Proc);
10454             end if;
10455          end Linker_Constructor;
10456
10457          --------------------
10458          -- Linker_Options --
10459          --------------------
10460
10461          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10462
10463          when Pragma_Linker_Options => Linker_Options : declare
10464             Arg : Node_Id;
10465
10466          begin
10467             Check_Ada_83_Warning;
10468             Check_No_Identifiers;
10469             Check_Arg_Count (1);
10470             Check_Is_In_Decl_Part_Or_Package_Spec;
10471             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10472             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10473
10474             Arg := Arg2;
10475             while Present (Arg) loop
10476                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10477                Store_String_Char (ASCII.NUL);
10478                Store_String_Chars
10479                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10480                Arg := Next (Arg);
10481             end loop;
10482
10483             if Operating_Mode = Generate_Code
10484               and then In_Extended_Main_Source_Unit (N)
10485             then
10486                Store_Linker_Option_String (End_String);
10487             end if;
10488          end Linker_Options;
10489
10490          --------------------
10491          -- Linker_Section --
10492          --------------------
10493
10494          --  pragma Linker_Section (
10495          --      [Entity  =>]  LOCAL_NAME
10496          --      [Section =>]  static_string_EXPRESSION);
10497
10498          when Pragma_Linker_Section =>
10499             GNAT_Pragma;
10500             Check_Arg_Order ((Name_Entity, Name_Section));
10501             Check_Arg_Count (2);
10502             Check_Optional_Identifier (Arg1, Name_Entity);
10503             Check_Optional_Identifier (Arg2, Name_Section);
10504             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10505             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10506
10507             --  This pragma applies only to objects
10508
10509             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10510                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10511             end if;
10512
10513             --  The only processing required is to link this item on to the
10514             --  list of rep items for the given entity. This is accomplished
10515             --  by the call to Rep_Item_Too_Late (when no error is detected
10516             --  and False is returned).
10517
10518             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10519                return;
10520             else
10521                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10522             end if;
10523
10524          ----------
10525          -- List --
10526          ----------
10527
10528          --  pragma List (On | Off)
10529
10530          --  There is nothing to do here, since we did all the processing for
10531          --  this pragma in Par.Prag (so that it works properly even in syntax
10532          --  only mode).
10533
10534          when Pragma_List =>
10535             null;
10536
10537          --------------------
10538          -- Locking_Policy --
10539          --------------------
10540
10541          --  pragma Locking_Policy (policy_IDENTIFIER);
10542
10543          when Pragma_Locking_Policy => declare
10544             LP : Character;
10545
10546          begin
10547             Check_Ada_83_Warning;
10548             Check_Arg_Count (1);
10549             Check_No_Identifiers;
10550             Check_Arg_Is_Locking_Policy (Arg1);
10551             Check_Valid_Configuration_Pragma;
10552             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10553             LP := Fold_Upper (Name_Buffer (1));
10554
10555             if Locking_Policy /= ' '
10556               and then Locking_Policy /= LP
10557             then
10558                Error_Msg_Sloc := Locking_Policy_Sloc;
10559                Error_Pragma ("locking policy incompatible with policy#");
10560
10561             --  Set new policy, but always preserve System_Location since we
10562             --  like the error message with the run time name.
10563
10564             else
10565                Locking_Policy := LP;
10566
10567                if Locking_Policy_Sloc /= System_Location then
10568                   Locking_Policy_Sloc := Loc;
10569                end if;
10570             end if;
10571          end;
10572
10573          ----------------
10574          -- Long_Float --
10575          ----------------
10576
10577          --  pragma Long_Float (D_Float | G_Float);
10578
10579          when Pragma_Long_Float =>
10580             GNAT_Pragma;
10581             Check_Valid_Configuration_Pragma;
10582             Check_Arg_Count (1);
10583             Check_No_Identifier (Arg1);
10584             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10585
10586             if not OpenVMS_On_Target then
10587                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10588             end if;
10589
10590             --  D_Float case
10591
10592             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10593                if Opt.Float_Format_Long = 'G' then
10594                   Error_Pragma ("G_Float previously specified");
10595                end if;
10596
10597                Opt.Float_Format_Long := 'D';
10598
10599             --  G_Float case (this is the default, does not need overriding)
10600
10601             else
10602                if Opt.Float_Format_Long = 'D' then
10603                   Error_Pragma ("D_Float previously specified");
10604                end if;
10605
10606                Opt.Float_Format_Long := 'G';
10607             end if;
10608
10609             Set_Standard_Fpt_Formats;
10610
10611          -----------------------
10612          -- Machine_Attribute --
10613          -----------------------
10614
10615          --  pragma Machine_Attribute (
10616          --       [Entity         =>] LOCAL_NAME,
10617          --       [Attribute_Name =>] static_string_EXPRESSION
10618          --    [, [Info           =>] static_EXPRESSION] );
10619
10620          when Pragma_Machine_Attribute => Machine_Attribute : declare
10621             Def_Id : Entity_Id;
10622
10623          begin
10624             GNAT_Pragma;
10625             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10626
10627             if Arg_Count = 3 then
10628                Check_Optional_Identifier (Arg3, Name_Info);
10629                Check_Arg_Is_Static_Expression (Arg3);
10630             else
10631                Check_Arg_Count (2);
10632             end if;
10633
10634             Check_Optional_Identifier (Arg1, Name_Entity);
10635             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10636             Check_Arg_Is_Local_Name (Arg1);
10637             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10638             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10639
10640             if Is_Access_Type (Def_Id) then
10641                Def_Id := Designated_Type (Def_Id);
10642             end if;
10643
10644             if Rep_Item_Too_Early (Def_Id, N) then
10645                return;
10646             end if;
10647
10648             Def_Id := Underlying_Type (Def_Id);
10649
10650             --  The only processing required is to link this item on to the
10651             --  list of rep items for the given entity. This is accomplished
10652             --  by the call to Rep_Item_Too_Late (when no error is detected
10653             --  and False is returned).
10654
10655             if Rep_Item_Too_Late (Def_Id, N) then
10656                return;
10657             else
10658                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10659             end if;
10660          end Machine_Attribute;
10661
10662          ----------
10663          -- Main --
10664          ----------
10665
10666          --  pragma Main
10667          --   (MAIN_OPTION [, MAIN_OPTION]);
10668
10669          --  MAIN_OPTION ::=
10670          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10671          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10672          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10673
10674          when Pragma_Main => Main : declare
10675             Args  : Args_List (1 .. 3);
10676             Names : constant Name_List (1 .. 3) := (
10677                       Name_Stack_Size,
10678                       Name_Task_Stack_Size_Default,
10679                       Name_Time_Slicing_Enabled);
10680
10681             Nod : Node_Id;
10682
10683          begin
10684             GNAT_Pragma;
10685             Gather_Associations (Names, Args);
10686
10687             for J in 1 .. 2 loop
10688                if Present (Args (J)) then
10689                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10690                end if;
10691             end loop;
10692
10693             if Present (Args (3)) then
10694                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10695             end if;
10696
10697             Nod := Next (N);
10698             while Present (Nod) loop
10699                if Nkind (Nod) = N_Pragma
10700                  and then Pragma_Name (Nod) = Name_Main
10701                then
10702                   Error_Msg_Name_1 := Pname;
10703                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10704                end if;
10705
10706                Next (Nod);
10707             end loop;
10708          end Main;
10709
10710          ------------------
10711          -- Main_Storage --
10712          ------------------
10713
10714          --  pragma Main_Storage
10715          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10716
10717          --  MAIN_STORAGE_OPTION ::=
10718          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10719          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10720
10721          when Pragma_Main_Storage => Main_Storage : declare
10722             Args  : Args_List (1 .. 2);
10723             Names : constant Name_List (1 .. 2) := (
10724                       Name_Working_Storage,
10725                       Name_Top_Guard);
10726
10727             Nod : Node_Id;
10728
10729          begin
10730             GNAT_Pragma;
10731             Gather_Associations (Names, Args);
10732
10733             for J in 1 .. 2 loop
10734                if Present (Args (J)) then
10735                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10736                end if;
10737             end loop;
10738
10739             Check_In_Main_Program;
10740
10741             Nod := Next (N);
10742             while Present (Nod) loop
10743                if Nkind (Nod) = N_Pragma
10744                  and then Pragma_Name (Nod) = Name_Main_Storage
10745                then
10746                   Error_Msg_Name_1 := Pname;
10747                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10748                end if;
10749
10750                Next (Nod);
10751             end loop;
10752          end Main_Storage;
10753
10754          -----------------
10755          -- Memory_Size --
10756          -----------------
10757
10758          --  pragma Memory_Size (NUMERIC_LITERAL)
10759
10760          when Pragma_Memory_Size =>
10761             GNAT_Pragma;
10762
10763             --  Memory size is simply ignored
10764
10765             Check_No_Identifiers;
10766             Check_Arg_Count (1);
10767             Check_Arg_Is_Integer_Literal (Arg1);
10768
10769          -------------
10770          -- No_Body --
10771          -------------
10772
10773          --  pragma No_Body;
10774
10775          --  The only correct use of this pragma is on its own in a file, in
10776          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10777          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10778          --  check for a file containing nothing but a No_Body pragma). If we
10779          --  attempt to process it during normal semantics processing, it means
10780          --  it was misplaced.
10781
10782          when Pragma_No_Body =>
10783             GNAT_Pragma;
10784             Pragma_Misplaced;
10785
10786          ---------------
10787          -- No_Return --
10788          ---------------
10789
10790          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10791
10792          when Pragma_No_Return => No_Return : declare
10793             Id    : Node_Id;
10794             E     : Entity_Id;
10795             Found : Boolean;
10796             Arg   : Node_Id;
10797
10798          begin
10799             Ada_2005_Pragma;
10800             Check_At_Least_N_Arguments (1);
10801
10802             --  Loop through arguments of pragma
10803
10804             Arg := Arg1;
10805             while Present (Arg) loop
10806                Check_Arg_Is_Local_Name (Arg);
10807                Id := Get_Pragma_Arg (Arg);
10808                Analyze (Id);
10809
10810                if not Is_Entity_Name (Id) then
10811                   Error_Pragma_Arg ("entity name required", Arg);
10812                end if;
10813
10814                if Etype (Id) = Any_Type then
10815                   raise Pragma_Exit;
10816                end if;
10817
10818                --  Loop to find matching procedures
10819
10820                E := Entity (Id);
10821                Found := False;
10822                while Present (E)
10823                  and then Scope (E) = Current_Scope
10824                loop
10825                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10826                      Set_No_Return (E);
10827
10828                      --  Set flag on any alias as well
10829
10830                      if Is_Overloadable (E) and then Present (Alias (E)) then
10831                         Set_No_Return (Alias (E));
10832                      end if;
10833
10834                      Found := True;
10835                   end if;
10836
10837                   exit when From_Aspect_Specification (N);
10838                   E := Homonym (E);
10839                end loop;
10840
10841                if not Found then
10842                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10843                end if;
10844
10845                Next (Arg);
10846             end loop;
10847          end No_Return;
10848
10849          -----------------
10850          -- No_Run_Time --
10851          -----------------
10852
10853          --  pragma No_Run_Time;
10854
10855          --  Note: this pragma is retained for backwards compatibility. See
10856          --  body of Rtsfind for full details on its handling.
10857
10858          when Pragma_No_Run_Time =>
10859             GNAT_Pragma;
10860             Check_Valid_Configuration_Pragma;
10861             Check_Arg_Count (0);
10862
10863             No_Run_Time_Mode           := True;
10864             Configurable_Run_Time_Mode := True;
10865
10866             --  Set Duration to 32 bits if word size is 32
10867
10868             if Ttypes.System_Word_Size = 32 then
10869                Duration_32_Bits_On_Target := True;
10870             end if;
10871
10872             --  Set appropriate restrictions
10873
10874             Set_Restriction (No_Finalization, N);
10875             Set_Restriction (No_Exception_Handlers, N);
10876             Set_Restriction (Max_Tasks, N, 0);
10877             Set_Restriction (No_Tasking, N);
10878
10879          ------------------------
10880          -- No_Strict_Aliasing --
10881          ------------------------
10882
10883          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10884
10885          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10886             E_Id : Entity_Id;
10887
10888          begin
10889             GNAT_Pragma;
10890             Check_At_Most_N_Arguments (1);
10891
10892             if Arg_Count = 0 then
10893                Check_Valid_Configuration_Pragma;
10894                Opt.No_Strict_Aliasing := True;
10895
10896             else
10897                Check_Optional_Identifier (Arg2, Name_Entity);
10898                Check_Arg_Is_Local_Name (Arg1);
10899                E_Id := Entity (Get_Pragma_Arg (Arg1));
10900
10901                if E_Id = Any_Type then
10902                   return;
10903                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10904                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
10905                end if;
10906
10907                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10908             end if;
10909          end No_Strict_Aliasing;
10910
10911          -----------------------
10912          -- Normalize_Scalars --
10913          -----------------------
10914
10915          --  pragma Normalize_Scalars;
10916
10917          when Pragma_Normalize_Scalars =>
10918             Check_Ada_83_Warning;
10919             Check_Arg_Count (0);
10920             Check_Valid_Configuration_Pragma;
10921
10922             --  Normalize_Scalars creates false positives in CodePeer, so
10923             --  ignore this pragma in this mode.
10924
10925             if not CodePeer_Mode then
10926                Normalize_Scalars := True;
10927                Init_Or_Norm_Scalars := True;
10928             end if;
10929
10930          -----------------
10931          -- Obsolescent --
10932          -----------------
10933
10934          --  pragma Obsolescent;
10935
10936          --  pragma Obsolescent (
10937          --    [Message =>] static_string_EXPRESSION
10938          --  [,[Version =>] Ada_05]]);
10939
10940          --  pragma Obsolescent (
10941          --    [Entity  =>] NAME
10942          --  [,[Message =>] static_string_EXPRESSION
10943          --  [,[Version =>] Ada_05]] );
10944
10945          when Pragma_Obsolescent => Obsolescent : declare
10946             Ename : Node_Id;
10947             Decl  : Node_Id;
10948
10949             procedure Set_Obsolescent (E : Entity_Id);
10950             --  Given an entity Ent, mark it as obsolescent if appropriate
10951
10952             ---------------------
10953             -- Set_Obsolescent --
10954             ---------------------
10955
10956             procedure Set_Obsolescent (E : Entity_Id) is
10957                Active : Boolean;
10958                Ent    : Entity_Id;
10959                S      : String_Id;
10960
10961             begin
10962                Active := True;
10963                Ent    := E;
10964
10965                --  Entity name was given
10966
10967                if Present (Ename) then
10968
10969                   --  If entity name matches, we are fine. Save entity in
10970                   --  pragma argument, for ASIS use.
10971
10972                   if Chars (Ename) = Chars (Ent) then
10973                      Set_Entity (Ename, Ent);
10974                      Generate_Reference (Ent, Ename);
10975
10976                   --  If entity name does not match, only possibility is an
10977                   --  enumeration literal from an enumeration type declaration.
10978
10979                   elsif Ekind (Ent) /= E_Enumeration_Type then
10980                      Error_Pragma
10981                        ("pragma % entity name does not match declaration");
10982
10983                   else
10984                      Ent := First_Literal (E);
10985                      loop
10986                         if No (Ent) then
10987                            Error_Pragma
10988                              ("pragma % entity name does not match any " &
10989                               "enumeration literal");
10990
10991                         elsif Chars (Ent) = Chars (Ename) then
10992                            Set_Entity (Ename, Ent);
10993                            Generate_Reference (Ent, Ename);
10994                            exit;
10995
10996                         else
10997                            Ent := Next_Literal (Ent);
10998                         end if;
10999                      end loop;
11000                   end if;
11001                end if;
11002
11003                --  Ent points to entity to be marked
11004
11005                if Arg_Count >= 1 then
11006
11007                   --  Deal with static string argument
11008
11009                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11010                   S := Strval (Get_Pragma_Arg (Arg1));
11011
11012                   for J in 1 .. String_Length (S) loop
11013                      if not In_Character_Range (Get_String_Char (S, J)) then
11014                         Error_Pragma_Arg
11015                           ("pragma% argument does not allow wide characters",
11016                            Arg1);
11017                      end if;
11018                   end loop;
11019
11020                   Obsolescent_Warnings.Append
11021                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11022
11023                   --  Check for Ada_05 parameter
11024
11025                   if Arg_Count /= 1 then
11026                      Check_Arg_Count (2);
11027
11028                      declare
11029                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11030
11031                      begin
11032                         Check_Arg_Is_Identifier (Argx);
11033
11034                         if Chars (Argx) /= Name_Ada_05 then
11035                            Error_Msg_Name_2 := Name_Ada_05;
11036                            Error_Pragma_Arg
11037                              ("only allowed argument for pragma% is %", Argx);
11038                         end if;
11039
11040                         if Ada_Version_Explicit < Ada_2005
11041                           or else not Warn_On_Ada_2005_Compatibility
11042                         then
11043                            Active := False;
11044                         end if;
11045                      end;
11046                   end if;
11047                end if;
11048
11049                --  Set flag if pragma active
11050
11051                if Active then
11052                   Set_Is_Obsolescent (Ent);
11053                end if;
11054
11055                return;
11056             end Set_Obsolescent;
11057
11058          --  Start of processing for pragma Obsolescent
11059
11060          begin
11061             GNAT_Pragma;
11062
11063             Check_At_Most_N_Arguments (3);
11064
11065             --  See if first argument specifies an entity name
11066
11067             if Arg_Count >= 1
11068               and then
11069                 (Chars (Arg1) = Name_Entity
11070                    or else
11071                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11072                                                       N_Identifier,
11073                                                       N_Operator_Symbol))
11074             then
11075                Ename := Get_Pragma_Arg (Arg1);
11076
11077                --  Eliminate first argument, so we can share processing
11078
11079                Arg1 := Arg2;
11080                Arg2 := Arg3;
11081                Arg_Count := Arg_Count - 1;
11082
11083             --  No Entity name argument given
11084
11085             else
11086                Ename := Empty;
11087             end if;
11088
11089             if Arg_Count >= 1 then
11090                Check_Optional_Identifier (Arg1, Name_Message);
11091
11092                if Arg_Count = 2 then
11093                   Check_Optional_Identifier (Arg2, Name_Version);
11094                end if;
11095             end if;
11096
11097             --  Get immediately preceding declaration
11098
11099             Decl := Prev (N);
11100             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11101                Prev (Decl);
11102             end loop;
11103
11104             --  Cases where we do not follow anything other than another pragma
11105
11106             if No (Decl) then
11107
11108                --  First case: library level compilation unit declaration with
11109                --  the pragma immediately following the declaration.
11110
11111                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11112                   Set_Obsolescent
11113                     (Defining_Entity (Unit (Parent (Parent (N)))));
11114                   return;
11115
11116                --  Case 2: library unit placement for package
11117
11118                else
11119                   declare
11120                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11121                   begin
11122                      if Is_Package_Or_Generic_Package (Ent) then
11123                         Set_Obsolescent (Ent);
11124                         return;
11125                      end if;
11126                   end;
11127                end if;
11128
11129             --  Cases where we must follow a declaration
11130
11131             else
11132                if         Nkind (Decl) not in N_Declaration
11133                  and then Nkind (Decl) not in N_Later_Decl_Item
11134                  and then Nkind (Decl) not in N_Generic_Declaration
11135                  and then Nkind (Decl) not in N_Renaming_Declaration
11136                then
11137                   Error_Pragma
11138                     ("pragma% misplaced, "
11139                      & "must immediately follow a declaration");
11140
11141                else
11142                   Set_Obsolescent (Defining_Entity (Decl));
11143                   return;
11144                end if;
11145             end if;
11146          end Obsolescent;
11147
11148          --------------
11149          -- Optimize --
11150          --------------
11151
11152          --  pragma Optimize (Time | Space | Off);
11153
11154          --  The actual check for optimize is done in Gigi. Note that this
11155          --  pragma does not actually change the optimization setting, it
11156          --  simply checks that it is consistent with the pragma.
11157
11158          when Pragma_Optimize =>
11159             Check_No_Identifiers;
11160             Check_Arg_Count (1);
11161             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11162
11163          ------------------------
11164          -- Optimize_Alignment --
11165          ------------------------
11166
11167          --  pragma Optimize_Alignment (Time | Space | Off);
11168
11169          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11170             GNAT_Pragma;
11171             Check_No_Identifiers;
11172             Check_Arg_Count (1);
11173             Check_Valid_Configuration_Pragma;
11174
11175             declare
11176                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11177             begin
11178                case Nam is
11179                   when Name_Time =>
11180                      Opt.Optimize_Alignment := 'T';
11181                   when Name_Space =>
11182                      Opt.Optimize_Alignment := 'S';
11183                   when Name_Off =>
11184                      Opt.Optimize_Alignment := 'O';
11185                   when others =>
11186                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11187                end case;
11188             end;
11189
11190             --  Set indication that mode is set locally. If we are in fact in a
11191             --  configuration pragma file, this setting is harmless since the
11192             --  switch will get reset anyway at the start of each unit.
11193
11194             Optimize_Alignment_Local := True;
11195          end Optimize_Alignment;
11196
11197          -------------
11198          -- Ordered --
11199          -------------
11200
11201          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11202
11203          when Pragma_Ordered => Ordered : declare
11204             Assoc   : constant Node_Id := Arg1;
11205             Type_Id : Node_Id;
11206             Typ     : Entity_Id;
11207
11208          begin
11209             GNAT_Pragma;
11210             Check_No_Identifiers;
11211             Check_Arg_Count (1);
11212             Check_Arg_Is_Local_Name (Arg1);
11213
11214             Type_Id := Get_Pragma_Arg (Assoc);
11215             Find_Type (Type_Id);
11216             Typ := Entity (Type_Id);
11217
11218             if Typ = Any_Type then
11219                return;
11220             else
11221                Typ := Underlying_Type (Typ);
11222             end if;
11223
11224             if not Is_Enumeration_Type (Typ) then
11225                Error_Pragma ("pragma% must specify enumeration type");
11226             end if;
11227
11228             Check_First_Subtype (Arg1);
11229             Set_Has_Pragma_Ordered (Base_Type (Typ));
11230          end Ordered;
11231
11232          ----------
11233          -- Pack --
11234          ----------
11235
11236          --  pragma Pack (first_subtype_LOCAL_NAME);
11237
11238          when Pragma_Pack => Pack : declare
11239             Assoc   : constant Node_Id := Arg1;
11240             Type_Id : Node_Id;
11241             Typ     : Entity_Id;
11242             Ctyp    : Entity_Id;
11243             Ignore  : Boolean := False;
11244
11245          begin
11246             Check_No_Identifiers;
11247             Check_Arg_Count (1);
11248             Check_Arg_Is_Local_Name (Arg1);
11249
11250             Type_Id := Get_Pragma_Arg (Assoc);
11251             Find_Type (Type_Id);
11252             Typ := Entity (Type_Id);
11253
11254             if Typ = Any_Type
11255               or else Rep_Item_Too_Early (Typ, N)
11256             then
11257                return;
11258             else
11259                Typ := Underlying_Type (Typ);
11260             end if;
11261
11262             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11263                Error_Pragma ("pragma% must specify array or record type");
11264             end if;
11265
11266             Check_First_Subtype (Arg1);
11267             Check_Duplicate_Pragma (Typ);
11268
11269             --  Array type
11270
11271             if Is_Array_Type (Typ) then
11272                Ctyp := Component_Type (Typ);
11273
11274                --  Ignore pack that does nothing
11275
11276                if Known_Static_Esize (Ctyp)
11277                  and then Known_Static_RM_Size (Ctyp)
11278                  and then Esize (Ctyp) = RM_Size (Ctyp)
11279                  and then Addressable (Esize (Ctyp))
11280                then
11281                   Ignore := True;
11282                end if;
11283
11284                --  Process OK pragma Pack. Note that if there is a separate
11285                --  component clause present, the Pack will be cancelled. This
11286                --  processing is in Freeze.
11287
11288                if not Rep_Item_Too_Late (Typ, N) then
11289
11290                   --  In the context of static code analysis, we do not need
11291                   --  complex front-end expansions related to pragma Pack,
11292                   --  so disable handling of pragma Pack in this case.
11293
11294                   if CodePeer_Mode then
11295                      null;
11296
11297                   --  Don't attempt any packing for VM targets. We possibly
11298                   --  could deal with some cases of array bit-packing, but we
11299                   --  don't bother, since this is not a typical kind of
11300                   --  representation in the VM context anyway (and would not
11301                   --  for example work nicely with the debugger).
11302
11303                   elsif VM_Target /= No_VM then
11304                      if not GNAT_Mode then
11305                         Error_Pragma
11306                           ("?pragma% ignored in this configuration");
11307                      end if;
11308
11309                   --  Normal case where we do the pack action
11310
11311                   else
11312                      if not Ignore then
11313                         Set_Is_Packed            (Base_Type (Typ));
11314                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11315                      end if;
11316
11317                      Set_Has_Pragma_Pack (Base_Type (Typ));
11318                   end if;
11319                end if;
11320
11321             --  For record types, the pack is always effective
11322
11323             else pragma Assert (Is_Record_Type (Typ));
11324                if not Rep_Item_Too_Late (Typ, N) then
11325
11326                   --  Ignore pack request with warning in VM mode (skip warning
11327                   --  if we are compiling GNAT run time library).
11328
11329                   if VM_Target /= No_VM then
11330                      if not GNAT_Mode then
11331                         Error_Pragma
11332                           ("?pragma% ignored in this configuration");
11333                      end if;
11334
11335                   --  Normal case of pack request active
11336
11337                   else
11338                      Set_Is_Packed            (Base_Type (Typ));
11339                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11340                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11341                   end if;
11342                end if;
11343             end if;
11344          end Pack;
11345
11346          ----------
11347          -- Page --
11348          ----------
11349
11350          --  pragma Page;
11351
11352          --  There is nothing to do here, since we did all the processing for
11353          --  this pragma in Par.Prag (so that it works properly even in syntax
11354          --  only mode).
11355
11356          when Pragma_Page =>
11357             null;
11358
11359          -------------
11360          -- Passive --
11361          -------------
11362
11363          --  pragma Passive [(PASSIVE_FORM)];
11364
11365          --  PASSIVE_FORM ::= Semaphore | No
11366
11367          when Pragma_Passive =>
11368             GNAT_Pragma;
11369
11370             if Nkind (Parent (N)) /= N_Task_Definition then
11371                Error_Pragma ("pragma% must be within task definition");
11372             end if;
11373
11374             if Arg_Count /= 0 then
11375                Check_Arg_Count (1);
11376                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11377             end if;
11378
11379          ----------------------------------
11380          -- Preelaborable_Initialization --
11381          ----------------------------------
11382
11383          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11384
11385          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11386             Ent : Entity_Id;
11387
11388          begin
11389             Ada_2005_Pragma;
11390             Check_Arg_Count (1);
11391             Check_No_Identifiers;
11392             Check_Arg_Is_Identifier (Arg1);
11393             Check_Arg_Is_Local_Name (Arg1);
11394             Check_First_Subtype (Arg1);
11395             Ent := Entity (Get_Pragma_Arg (Arg1));
11396
11397             if not (Is_Private_Type (Ent)
11398                       or else
11399                     Is_Protected_Type (Ent)
11400                       or else
11401                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11402             then
11403                Error_Pragma_Arg
11404                  ("pragma % can only be applied to private, formal derived or "
11405                   & "protected type",
11406                   Arg1);
11407             end if;
11408
11409             --  Give an error if the pragma is applied to a protected type that
11410             --  does not qualify (due to having entries, or due to components
11411             --  that do not qualify).
11412
11413             if Is_Protected_Type (Ent)
11414               and then not Has_Preelaborable_Initialization (Ent)
11415             then
11416                Error_Msg_N
11417                  ("protected type & does not have preelaborable " &
11418                   "initialization", Ent);
11419
11420             --  Otherwise mark the type as definitely having preelaborable
11421             --  initialization.
11422
11423             else
11424                Set_Known_To_Have_Preelab_Init (Ent);
11425             end if;
11426
11427             if Has_Pragma_Preelab_Init (Ent)
11428               and then Warn_On_Redundant_Constructs
11429             then
11430                Error_Pragma ("?duplicate pragma%!");
11431             else
11432                Set_Has_Pragma_Preelab_Init (Ent);
11433             end if;
11434          end Preelab_Init;
11435
11436          --------------------
11437          -- Persistent_BSS --
11438          --------------------
11439
11440          --  pragma Persistent_BSS [(object_NAME)];
11441
11442          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11443             Decl : Node_Id;
11444             Ent  : Entity_Id;
11445             Prag : Node_Id;
11446
11447          begin
11448             GNAT_Pragma;
11449             Check_At_Most_N_Arguments (1);
11450
11451             --  Case of application to specific object (one argument)
11452
11453             if Arg_Count = 1 then
11454                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11455
11456                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11457                  or else not
11458                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11459                                                             E_Constant)
11460                then
11461                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11462                end if;
11463
11464                Ent := Entity (Get_Pragma_Arg (Arg1));
11465                Decl := Parent (Ent);
11466
11467                if Rep_Item_Too_Late (Ent, N) then
11468                   return;
11469                end if;
11470
11471                if Present (Expression (Decl)) then
11472                   Error_Pragma_Arg
11473                     ("object for pragma% cannot have initialization", Arg1);
11474                end if;
11475
11476                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11477                   Error_Pragma_Arg
11478                     ("object type for pragma% is not potentially persistent",
11479                      Arg1);
11480                end if;
11481
11482                Check_Duplicate_Pragma (Ent);
11483
11484                Prag :=
11485                  Make_Linker_Section_Pragma
11486                    (Ent, Sloc (N), ".persistent.bss");
11487                Insert_After (N, Prag);
11488                Analyze (Prag);
11489
11490             --  Case of use as configuration pragma with no arguments
11491
11492             else
11493                Check_Valid_Configuration_Pragma;
11494                Persistent_BSS_Mode := True;
11495             end if;
11496          end Persistent_BSS;
11497
11498          -------------
11499          -- Polling --
11500          -------------
11501
11502          --  pragma Polling (ON | OFF);
11503
11504          when Pragma_Polling =>
11505             GNAT_Pragma;
11506             Check_Arg_Count (1);
11507             Check_No_Identifiers;
11508             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11509             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11510
11511          -------------------
11512          -- Postcondition --
11513          -------------------
11514
11515          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11516          --                      [,[Message =>] String_EXPRESSION]);
11517
11518          when Pragma_Postcondition => Postcondition : declare
11519             In_Body : Boolean;
11520             pragma Warnings (Off, In_Body);
11521
11522          begin
11523             GNAT_Pragma;
11524             Check_At_Least_N_Arguments (1);
11525             Check_At_Most_N_Arguments (2);
11526             Check_Optional_Identifier (Arg1, Name_Check);
11527
11528             --  All we need to do here is call the common check procedure,
11529             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11530
11531             Check_Precondition_Postcondition (In_Body);
11532          end Postcondition;
11533
11534          ------------------
11535          -- Precondition --
11536          ------------------
11537
11538          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11539          --                     [,[Message =>] String_EXPRESSION]);
11540
11541          when Pragma_Precondition => Precondition : declare
11542             In_Body : Boolean;
11543
11544          begin
11545             GNAT_Pragma;
11546             Check_At_Least_N_Arguments (1);
11547             Check_At_Most_N_Arguments (2);
11548             Check_Optional_Identifier (Arg1, Name_Check);
11549             Check_Precondition_Postcondition (In_Body);
11550
11551             --  If in spec, nothing more to do. If in body, then we convert the
11552             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11553             --  this whether or not precondition checks are enabled. That works
11554             --  fine since pragma Check will do this check, and will also
11555             --  analyze the condition itself in the proper context.
11556
11557             if In_Body then
11558                Rewrite (N,
11559                  Make_Pragma (Loc,
11560                    Chars => Name_Check,
11561                    Pragma_Argument_Associations => New_List (
11562                      Make_Pragma_Argument_Association (Loc,
11563                        Expression => Make_Identifier (Loc, Name_Precondition)),
11564
11565                      Make_Pragma_Argument_Association (Sloc (Arg1),
11566                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11567
11568                if Arg_Count = 2 then
11569                   Append_To (Pragma_Argument_Associations (N),
11570                     Make_Pragma_Argument_Association (Sloc (Arg2),
11571                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11572                end if;
11573
11574                Analyze (N);
11575             end if;
11576          end Precondition;
11577
11578          ---------------
11579          -- Predicate --
11580          ---------------
11581
11582          --  pragma Predicate
11583          --    ([Entity =>] type_LOCAL_NAME,
11584          --     [Check  =>] EXPRESSION);
11585
11586          when Pragma_Predicate => Predicate : declare
11587             Type_Id : Node_Id;
11588             Typ     : Entity_Id;
11589
11590             Discard : Boolean;
11591             pragma Unreferenced (Discard);
11592
11593          begin
11594             GNAT_Pragma;
11595             Check_Arg_Count (2);
11596             Check_Optional_Identifier (Arg1, Name_Entity);
11597             Check_Optional_Identifier (Arg2, Name_Check);
11598
11599             Check_Arg_Is_Local_Name (Arg1);
11600
11601             Type_Id := Get_Pragma_Arg (Arg1);
11602             Find_Type (Type_Id);
11603             Typ := Entity (Type_Id);
11604
11605             if Typ = Any_Type then
11606                return;
11607             end if;
11608
11609             --  The remaining processing is simply to link the pragma on to
11610             --  the rep item chain, for processing when the type is frozen.
11611             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11612             --  mark the type as having predicates.
11613
11614             Set_Has_Predicates (Typ);
11615             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11616          end Predicate;
11617
11618          ------------------
11619          -- Preelaborate --
11620          ------------------
11621
11622          --  pragma Preelaborate [(library_unit_NAME)];
11623
11624          --  Set the flag Is_Preelaborated of program unit name entity
11625
11626          when Pragma_Preelaborate => Preelaborate : declare
11627             Pa  : constant Node_Id   := Parent (N);
11628             Pk  : constant Node_Kind := Nkind (Pa);
11629             Ent : Entity_Id;
11630
11631          begin
11632             Check_Ada_83_Warning;
11633             Check_Valid_Library_Unit_Pragma;
11634
11635             if Nkind (N) = N_Null_Statement then
11636                return;
11637             end if;
11638
11639             Ent := Find_Lib_Unit_Name;
11640             Check_Duplicate_Pragma (Ent);
11641
11642             --  This filters out pragmas inside generic parent then
11643             --  show up inside instantiation
11644
11645             if Present (Ent)
11646               and then not (Pk = N_Package_Specification
11647                              and then Present (Generic_Parent (Pa)))
11648             then
11649                if not Debug_Flag_U then
11650                   Set_Is_Preelaborated (Ent);
11651                   Set_Suppress_Elaboration_Warnings (Ent);
11652                end if;
11653             end if;
11654          end Preelaborate;
11655
11656          ---------------------
11657          -- Preelaborate_05 --
11658          ---------------------
11659
11660          --  pragma Preelaborate_05 [(library_unit_NAME)];
11661
11662          --  This pragma is useable only in GNAT_Mode, where it is used like
11663          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11664          --  (otherwise it is ignored). This is used to implement AI-362 which
11665          --  recategorizes some run-time packages in Ada 2005 mode.
11666
11667          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11668             Ent : Entity_Id;
11669
11670          begin
11671             GNAT_Pragma;
11672             Check_Valid_Library_Unit_Pragma;
11673
11674             if not GNAT_Mode then
11675                Error_Pragma ("pragma% only available in GNAT mode");
11676             end if;
11677
11678             if Nkind (N) = N_Null_Statement then
11679                return;
11680             end if;
11681
11682             --  This is one of the few cases where we need to test the value of
11683             --  Ada_Version_Explicit rather than Ada_Version (which is always
11684             --  set to Ada_2012 in a predefined unit), we need to know the
11685             --  explicit version set to know if this pragma is active.
11686
11687             if Ada_Version_Explicit >= Ada_2005 then
11688                Ent := Find_Lib_Unit_Name;
11689                Set_Is_Preelaborated (Ent);
11690                Set_Suppress_Elaboration_Warnings (Ent);
11691             end if;
11692          end Preelaborate_05;
11693
11694          --------------
11695          -- Priority --
11696          --------------
11697
11698          --  pragma Priority (EXPRESSION);
11699
11700          when Pragma_Priority => Priority : declare
11701             P   : constant Node_Id := Parent (N);
11702             Arg : Node_Id;
11703
11704          begin
11705             Check_No_Identifiers;
11706             Check_Arg_Count (1);
11707
11708             --  Subprogram case
11709
11710             if Nkind (P) = N_Subprogram_Body then
11711                Check_In_Main_Program;
11712
11713                Arg := Get_Pragma_Arg (Arg1);
11714                Analyze_And_Resolve (Arg, Standard_Integer);
11715
11716                --  Must be static
11717
11718                if not Is_Static_Expression (Arg) then
11719                   Flag_Non_Static_Expr
11720                     ("main subprogram priority is not static!", Arg);
11721                   raise Pragma_Exit;
11722
11723                --  If constraint error, then we already signalled an error
11724
11725                elsif Raises_Constraint_Error (Arg) then
11726                   null;
11727
11728                --  Otherwise check in range
11729
11730                else
11731                   declare
11732                      Val : constant Uint := Expr_Value (Arg);
11733
11734                   begin
11735                      if Val < 0
11736                        or else Val > Expr_Value (Expression
11737                                        (Parent (RTE (RE_Max_Priority))))
11738                      then
11739                         Error_Pragma_Arg
11740                           ("main subprogram priority is out of range", Arg1);
11741                      end if;
11742                   end;
11743                end if;
11744
11745                Set_Main_Priority
11746                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11747
11748                --  Load an arbitrary entity from System.Tasking to make sure
11749                --  this package is implicitly with'ed, since we need to have
11750                --  the tasking run-time active for the pragma Priority to have
11751                --  any effect.
11752
11753                declare
11754                   Discard : Entity_Id;
11755                   pragma Warnings (Off, Discard);
11756                begin
11757                   Discard := RTE (RE_Task_List);
11758                end;
11759
11760             --  Task or Protected, must be of type Integer
11761
11762             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11763                Arg := Get_Pragma_Arg (Arg1);
11764
11765                --  The expression must be analyzed in the special manner
11766                --  described in "Handling of Default and Per-Object
11767                --  Expressions" in sem.ads.
11768
11769                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11770
11771                if not Is_Static_Expression (Arg) then
11772                   Check_Restriction (Static_Priorities, Arg);
11773                end if;
11774
11775             --  Anything else is incorrect
11776
11777             else
11778                Pragma_Misplaced;
11779             end if;
11780
11781             if Has_Pragma_Priority (P) then
11782                Error_Pragma ("duplicate pragma% not allowed");
11783             else
11784                Set_Has_Pragma_Priority (P, True);
11785
11786                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11787                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11788                   --  exp_ch9 should use this ???
11789                end if;
11790             end if;
11791          end Priority;
11792
11793          -----------------------------------
11794          -- Priority_Specific_Dispatching --
11795          -----------------------------------
11796
11797          --  pragma Priority_Specific_Dispatching (
11798          --    policy_IDENTIFIER,
11799          --    first_priority_EXPRESSION,
11800          --    last_priority_EXPRESSION);
11801
11802          when Pragma_Priority_Specific_Dispatching =>
11803          Priority_Specific_Dispatching : declare
11804             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11805             --  This is the entity System.Any_Priority;
11806
11807             DP          : Character;
11808             Lower_Bound : Node_Id;
11809             Upper_Bound : Node_Id;
11810             Lower_Val   : Uint;
11811             Upper_Val   : Uint;
11812
11813          begin
11814             Ada_2005_Pragma;
11815             Check_Arg_Count (3);
11816             Check_No_Identifiers;
11817             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11818             Check_Valid_Configuration_Pragma;
11819             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11820             DP := Fold_Upper (Name_Buffer (1));
11821
11822             Lower_Bound := Get_Pragma_Arg (Arg2);
11823             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11824             Lower_Val := Expr_Value (Lower_Bound);
11825
11826             Upper_Bound := Get_Pragma_Arg (Arg3);
11827             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11828             Upper_Val := Expr_Value (Upper_Bound);
11829
11830             --  It is not allowed to use Task_Dispatching_Policy and
11831             --  Priority_Specific_Dispatching in the same partition.
11832
11833             if Task_Dispatching_Policy /= ' ' then
11834                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11835                Error_Pragma
11836                  ("pragma% incompatible with Task_Dispatching_Policy#");
11837
11838             --  Check lower bound in range
11839
11840             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11841                     or else
11842                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11843             then
11844                Error_Pragma_Arg
11845                  ("first_priority is out of range", Arg2);
11846
11847             --  Check upper bound in range
11848
11849             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11850                     or else
11851                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11852             then
11853                Error_Pragma_Arg
11854                  ("last_priority is out of range", Arg3);
11855
11856             --  Check that the priority range is valid
11857
11858             elsif Lower_Val > Upper_Val then
11859                Error_Pragma
11860                  ("last_priority_expression must be greater than" &
11861                   " or equal to first_priority_expression");
11862
11863             --  Store the new policy, but always preserve System_Location since
11864             --  we like the error message with the run-time name.
11865
11866             else
11867                --  Check overlapping in the priority ranges specified in other
11868                --  Priority_Specific_Dispatching pragmas within the same
11869                --  partition. We can only check those we know about!
11870
11871                for J in
11872                   Specific_Dispatching.First .. Specific_Dispatching.Last
11873                loop
11874                   if Specific_Dispatching.Table (J).First_Priority in
11875                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11876                   or else Specific_Dispatching.Table (J).Last_Priority in
11877                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11878                   then
11879                      Error_Msg_Sloc :=
11880                        Specific_Dispatching.Table (J).Pragma_Loc;
11881                         Error_Pragma
11882                           ("priority range overlaps with "
11883                            & "Priority_Specific_Dispatching#");
11884                   end if;
11885                end loop;
11886
11887                --  The use of Priority_Specific_Dispatching is incompatible
11888                --  with Task_Dispatching_Policy.
11889
11890                if Task_Dispatching_Policy /= ' ' then
11891                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11892                      Error_Pragma
11893                        ("Priority_Specific_Dispatching incompatible "
11894                         & "with Task_Dispatching_Policy#");
11895                end if;
11896
11897                --  The use of Priority_Specific_Dispatching forces ceiling
11898                --  locking policy.
11899
11900                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11901                   Error_Msg_Sloc := Locking_Policy_Sloc;
11902                      Error_Pragma
11903                        ("Priority_Specific_Dispatching incompatible "
11904                         & "with Locking_Policy#");
11905
11906                --  Set the Ceiling_Locking policy, but preserve System_Location
11907                --  since we like the error message with the run time name.
11908
11909                else
11910                   Locking_Policy := 'C';
11911
11912                   if Locking_Policy_Sloc /= System_Location then
11913                      Locking_Policy_Sloc := Loc;
11914                   end if;
11915                end if;
11916
11917                --  Add entry in the table
11918
11919                Specific_Dispatching.Append
11920                     ((Dispatching_Policy => DP,
11921                       First_Priority     => UI_To_Int (Lower_Val),
11922                       Last_Priority      => UI_To_Int (Upper_Val),
11923                       Pragma_Loc         => Loc));
11924             end if;
11925          end Priority_Specific_Dispatching;
11926
11927          -------------
11928          -- Profile --
11929          -------------
11930
11931          --  pragma Profile (profile_IDENTIFIER);
11932
11933          --  profile_IDENTIFIER => Restricted | Ravenscar
11934
11935          when Pragma_Profile =>
11936             Ada_2005_Pragma;
11937             Check_Arg_Count (1);
11938             Check_Valid_Configuration_Pragma;
11939             Check_No_Identifiers;
11940
11941             declare
11942                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11943             begin
11944                if Chars (Argx) = Name_Ravenscar then
11945                   Set_Ravenscar_Profile (N);
11946                elsif Chars (Argx) = Name_Restricted then
11947                   Set_Profile_Restrictions
11948                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
11949                else
11950                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11951                end if;
11952             end;
11953
11954          ----------------------
11955          -- Profile_Warnings --
11956          ----------------------
11957
11958          --  pragma Profile_Warnings (profile_IDENTIFIER);
11959
11960          --  profile_IDENTIFIER => Restricted | Ravenscar
11961
11962          when Pragma_Profile_Warnings =>
11963             GNAT_Pragma;
11964             Check_Arg_Count (1);
11965             Check_Valid_Configuration_Pragma;
11966             Check_No_Identifiers;
11967
11968             declare
11969                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11970             begin
11971                if Chars (Argx) = Name_Ravenscar then
11972                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
11973                elsif Chars (Argx) = Name_Restricted then
11974                   Set_Profile_Restrictions (Restricted, N, Warn => True);
11975                else
11976                   Error_Pragma_Arg ("& is not a valid profile", Argx);
11977                end if;
11978             end;
11979
11980          --------------------------
11981          -- Propagate_Exceptions --
11982          --------------------------
11983
11984          --  pragma Propagate_Exceptions;
11985
11986          --  Note: this pragma is obsolete and has no effect
11987
11988          when Pragma_Propagate_Exceptions =>
11989             GNAT_Pragma;
11990             Check_Arg_Count (0);
11991
11992             if In_Extended_Main_Source_Unit (N) then
11993                Propagate_Exceptions := True;
11994             end if;
11995
11996          ------------------
11997          -- Psect_Object --
11998          ------------------
11999
12000          --  pragma Psect_Object (
12001          --        [Internal =>] LOCAL_NAME,
12002          --     [, [External =>] EXTERNAL_SYMBOL]
12003          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12004
12005          when Pragma_Psect_Object | Pragma_Common_Object =>
12006          Psect_Object : declare
12007             Args  : Args_List (1 .. 3);
12008             Names : constant Name_List (1 .. 3) := (
12009                       Name_Internal,
12010                       Name_External,
12011                       Name_Size);
12012
12013             Internal : Node_Id renames Args (1);
12014             External : Node_Id renames Args (2);
12015             Size     : Node_Id renames Args (3);
12016
12017             Def_Id : Entity_Id;
12018
12019             procedure Check_Too_Long (Arg : Node_Id);
12020             --  Posts message if the argument is an identifier with more
12021             --  than 31 characters, or a string literal with more than
12022             --  31 characters, and we are operating under VMS
12023
12024             --------------------
12025             -- Check_Too_Long --
12026             --------------------
12027
12028             procedure Check_Too_Long (Arg : Node_Id) is
12029                X : constant Node_Id := Original_Node (Arg);
12030
12031             begin
12032                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12033                   Error_Pragma_Arg
12034                     ("inappropriate argument for pragma %", Arg);
12035                end if;
12036
12037                if OpenVMS_On_Target then
12038                   if (Nkind (X) = N_String_Literal
12039                        and then String_Length (Strval (X)) > 31)
12040                     or else
12041                      (Nkind (X) = N_Identifier
12042                        and then Length_Of_Name (Chars (X)) > 31)
12043                   then
12044                      Error_Pragma_Arg
12045                        ("argument for pragma % is longer than 31 characters",
12046                         Arg);
12047                   end if;
12048                end if;
12049             end Check_Too_Long;
12050
12051          --  Start of processing for Common_Object/Psect_Object
12052
12053          begin
12054             GNAT_Pragma;
12055             Gather_Associations (Names, Args);
12056             Process_Extended_Import_Export_Internal_Arg (Internal);
12057
12058             Def_Id := Entity (Internal);
12059
12060             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12061                Error_Pragma_Arg
12062                  ("pragma% must designate an object", Internal);
12063             end if;
12064
12065             Check_Too_Long (Internal);
12066
12067             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12068                Error_Pragma_Arg
12069                  ("cannot use pragma% for imported/exported object",
12070                   Internal);
12071             end if;
12072
12073             if Is_Concurrent_Type (Etype (Internal)) then
12074                Error_Pragma_Arg
12075                  ("cannot specify pragma % for task/protected object",
12076                   Internal);
12077             end if;
12078
12079             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12080                  or else
12081                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12082             then
12083                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12084             end if;
12085
12086             if Ekind (Def_Id) = E_Constant then
12087                Error_Pragma_Arg
12088                  ("cannot specify pragma % for a constant", Internal);
12089             end if;
12090
12091             if Is_Record_Type (Etype (Internal)) then
12092                declare
12093                   Ent  : Entity_Id;
12094                   Decl : Entity_Id;
12095
12096                begin
12097                   Ent := First_Entity (Etype (Internal));
12098                   while Present (Ent) loop
12099                      Decl := Declaration_Node (Ent);
12100
12101                      if Ekind (Ent) = E_Component
12102                        and then Nkind (Decl) = N_Component_Declaration
12103                        and then Present (Expression (Decl))
12104                        and then Warn_On_Export_Import
12105                      then
12106                         Error_Msg_N
12107                           ("?object for pragma % has defaults", Internal);
12108                         exit;
12109
12110                      else
12111                         Next_Entity (Ent);
12112                      end if;
12113                   end loop;
12114                end;
12115             end if;
12116
12117             if Present (Size) then
12118                Check_Too_Long (Size);
12119             end if;
12120
12121             if Present (External) then
12122                Check_Arg_Is_External_Name (External);
12123                Check_Too_Long (External);
12124             end if;
12125
12126             --  If all error tests pass, link pragma on to the rep item chain
12127
12128             Record_Rep_Item (Def_Id, N);
12129          end Psect_Object;
12130
12131          ----------
12132          -- Pure --
12133          ----------
12134
12135          --  pragma Pure [(library_unit_NAME)];
12136
12137          when Pragma_Pure => Pure : declare
12138             Ent : Entity_Id;
12139
12140          begin
12141             Check_Ada_83_Warning;
12142             Check_Valid_Library_Unit_Pragma;
12143
12144             if Nkind (N) = N_Null_Statement then
12145                return;
12146             end if;
12147
12148             Ent := Find_Lib_Unit_Name;
12149             Set_Is_Pure (Ent);
12150             Set_Has_Pragma_Pure (Ent);
12151             Set_Suppress_Elaboration_Warnings (Ent);
12152          end Pure;
12153
12154          -------------
12155          -- Pure_05 --
12156          -------------
12157
12158          --  pragma Pure_05 [(library_unit_NAME)];
12159
12160          --  This pragma is useable only in GNAT_Mode, where it is used like
12161          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12162          --  it is ignored). It may be used after a pragma Preelaborate, in
12163          --  which case it overrides the effect of the pragma Preelaborate.
12164          --  This is used to implement AI-362 which recategorizes some run-time
12165          --  packages in Ada 2005 mode.
12166
12167          when Pragma_Pure_05 => Pure_05 : declare
12168             Ent : Entity_Id;
12169
12170          begin
12171             GNAT_Pragma;
12172             Check_Valid_Library_Unit_Pragma;
12173
12174             if not GNAT_Mode then
12175                Error_Pragma ("pragma% only available in GNAT mode");
12176             end if;
12177
12178             if Nkind (N) = N_Null_Statement then
12179                return;
12180             end if;
12181
12182             --  This is one of the few cases where we need to test the value of
12183             --  Ada_Version_Explicit rather than Ada_Version (which is always
12184             --  set to Ada_2012 in a predefined unit), we need to know the
12185             --  explicit version set to know if this pragma is active.
12186
12187             if Ada_Version_Explicit >= Ada_2005 then
12188                Ent := Find_Lib_Unit_Name;
12189                Set_Is_Preelaborated (Ent, False);
12190                Set_Is_Pure (Ent);
12191                Set_Suppress_Elaboration_Warnings (Ent);
12192             end if;
12193          end Pure_05;
12194
12195          -------------------
12196          -- Pure_Function --
12197          -------------------
12198
12199          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12200
12201          when Pragma_Pure_Function => Pure_Function : declare
12202             E_Id      : Node_Id;
12203             E         : Entity_Id;
12204             Def_Id    : Entity_Id;
12205             Effective : Boolean := False;
12206
12207          begin
12208             GNAT_Pragma;
12209             Check_Arg_Count (1);
12210             Check_Optional_Identifier (Arg1, Name_Entity);
12211             Check_Arg_Is_Local_Name (Arg1);
12212             E_Id := Get_Pragma_Arg (Arg1);
12213
12214             if Error_Posted (E_Id) then
12215                return;
12216             end if;
12217
12218             --  Loop through homonyms (overloadings) of referenced entity
12219
12220             E := Entity (E_Id);
12221
12222             if Present (E) then
12223                loop
12224                   Def_Id := Get_Base_Subprogram (E);
12225
12226                   if not Ekind_In (Def_Id, E_Function,
12227                                            E_Generic_Function,
12228                                            E_Operator)
12229                   then
12230                      Error_Pragma_Arg
12231                        ("pragma% requires a function name", Arg1);
12232                   end if;
12233
12234                   Set_Is_Pure (Def_Id);
12235
12236                   if not Has_Pragma_Pure_Function (Def_Id) then
12237                      Set_Has_Pragma_Pure_Function (Def_Id);
12238                      Effective := True;
12239                   end if;
12240
12241                   exit when From_Aspect_Specification (N);
12242                   E := Homonym (E);
12243                   exit when No (E) or else Scope (E) /= Current_Scope;
12244                end loop;
12245
12246                if not Effective
12247                  and then Warn_On_Redundant_Constructs
12248                then
12249                   Error_Msg_NE
12250                     ("pragma Pure_Function on& is redundant?",
12251                      N, Entity (E_Id));
12252                end if;
12253             end if;
12254          end Pure_Function;
12255
12256          --------------------
12257          -- Queuing_Policy --
12258          --------------------
12259
12260          --  pragma Queuing_Policy (policy_IDENTIFIER);
12261
12262          when Pragma_Queuing_Policy => declare
12263             QP : Character;
12264
12265          begin
12266             Check_Ada_83_Warning;
12267             Check_Arg_Count (1);
12268             Check_No_Identifiers;
12269             Check_Arg_Is_Queuing_Policy (Arg1);
12270             Check_Valid_Configuration_Pragma;
12271             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12272             QP := Fold_Upper (Name_Buffer (1));
12273
12274             if Queuing_Policy /= ' '
12275               and then Queuing_Policy /= QP
12276             then
12277                Error_Msg_Sloc := Queuing_Policy_Sloc;
12278                Error_Pragma ("queuing policy incompatible with policy#");
12279
12280             --  Set new policy, but always preserve System_Location since we
12281             --  like the error message with the run time name.
12282
12283             else
12284                Queuing_Policy := QP;
12285
12286                if Queuing_Policy_Sloc /= System_Location then
12287                   Queuing_Policy_Sloc := Loc;
12288                end if;
12289             end if;
12290          end;
12291
12292          -----------------------
12293          -- Relative_Deadline --
12294          -----------------------
12295
12296          --  pragma Relative_Deadline (time_span_EXPRESSION);
12297
12298          when Pragma_Relative_Deadline => Relative_Deadline : declare
12299             P   : constant Node_Id := Parent (N);
12300             Arg : Node_Id;
12301
12302          begin
12303             Ada_2005_Pragma;
12304             Check_No_Identifiers;
12305             Check_Arg_Count (1);
12306
12307             Arg := Get_Pragma_Arg (Arg1);
12308
12309             --  The expression must be analyzed in the special manner described
12310             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12311
12312             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12313
12314             --  Subprogram case
12315
12316             if Nkind (P) = N_Subprogram_Body then
12317                Check_In_Main_Program;
12318
12319             --  Tasks
12320
12321             elsif Nkind (P) = N_Task_Definition then
12322                null;
12323
12324             --  Anything else is incorrect
12325
12326             else
12327                Pragma_Misplaced;
12328             end if;
12329
12330             if Has_Relative_Deadline_Pragma (P) then
12331                Error_Pragma ("duplicate pragma% not allowed");
12332             else
12333                Set_Has_Relative_Deadline_Pragma (P, True);
12334
12335                if Nkind (P) = N_Task_Definition then
12336                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12337                end if;
12338             end if;
12339          end Relative_Deadline;
12340
12341          ---------------------------
12342          -- Remote_Call_Interface --
12343          ---------------------------
12344
12345          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12346
12347          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12348             Cunit_Node : Node_Id;
12349             Cunit_Ent  : Entity_Id;
12350             K          : Node_Kind;
12351
12352          begin
12353             Check_Ada_83_Warning;
12354             Check_Valid_Library_Unit_Pragma;
12355
12356             if Nkind (N) = N_Null_Statement then
12357                return;
12358             end if;
12359
12360             Cunit_Node := Cunit (Current_Sem_Unit);
12361             K          := Nkind (Unit (Cunit_Node));
12362             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12363
12364             if K = N_Package_Declaration
12365               or else K = N_Generic_Package_Declaration
12366               or else K = N_Subprogram_Declaration
12367               or else K = N_Generic_Subprogram_Declaration
12368               or else (K = N_Subprogram_Body
12369                          and then Acts_As_Spec (Unit (Cunit_Node)))
12370             then
12371                null;
12372             else
12373                Error_Pragma (
12374                  "pragma% must apply to package or subprogram declaration");
12375             end if;
12376
12377             Set_Is_Remote_Call_Interface (Cunit_Ent);
12378          end Remote_Call_Interface;
12379
12380          ------------------
12381          -- Remote_Types --
12382          ------------------
12383
12384          --  pragma Remote_Types [(library_unit_NAME)];
12385
12386          when Pragma_Remote_Types => Remote_Types : declare
12387             Cunit_Node : Node_Id;
12388             Cunit_Ent  : Entity_Id;
12389
12390          begin
12391             Check_Ada_83_Warning;
12392             Check_Valid_Library_Unit_Pragma;
12393
12394             if Nkind (N) = N_Null_Statement then
12395                return;
12396             end if;
12397
12398             Cunit_Node := Cunit (Current_Sem_Unit);
12399             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12400
12401             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12402                                                 N_Generic_Package_Declaration)
12403             then
12404                Error_Pragma
12405                  ("pragma% can only apply to a package declaration");
12406             end if;
12407
12408             Set_Is_Remote_Types (Cunit_Ent);
12409          end Remote_Types;
12410
12411          ---------------
12412          -- Ravenscar --
12413          ---------------
12414
12415          --  pragma Ravenscar;
12416
12417          when Pragma_Ravenscar =>
12418             GNAT_Pragma;
12419             Check_Arg_Count (0);
12420             Check_Valid_Configuration_Pragma;
12421             Set_Ravenscar_Profile (N);
12422
12423             if Warn_On_Obsolescent_Feature then
12424                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12425                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12426             end if;
12427
12428          -------------------------
12429          -- Restricted_Run_Time --
12430          -------------------------
12431
12432          --  pragma Restricted_Run_Time;
12433
12434          when Pragma_Restricted_Run_Time =>
12435             GNAT_Pragma;
12436             Check_Arg_Count (0);
12437             Check_Valid_Configuration_Pragma;
12438             Set_Profile_Restrictions
12439               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12440
12441             if Warn_On_Obsolescent_Feature then
12442                Error_Msg_N
12443                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12444                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12445             end if;
12446
12447          ------------------
12448          -- Restrictions --
12449          ------------------
12450
12451          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12452
12453          --  RESTRICTION ::=
12454          --    restriction_IDENTIFIER
12455          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12456
12457          when Pragma_Restrictions =>
12458             Process_Restrictions_Or_Restriction_Warnings
12459               (Warn => Treat_Restrictions_As_Warnings);
12460
12461          --------------------------
12462          -- Restriction_Warnings --
12463          --------------------------
12464
12465          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12466
12467          --  RESTRICTION ::=
12468          --    restriction_IDENTIFIER
12469          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12470
12471          when Pragma_Restriction_Warnings =>
12472             GNAT_Pragma;
12473             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12474
12475          ----------------
12476          -- Reviewable --
12477          ----------------
12478
12479          --  pragma Reviewable;
12480
12481          when Pragma_Reviewable =>
12482             Check_Ada_83_Warning;
12483             Check_Arg_Count (0);
12484
12485             --  Call dummy debugging function rv. This is done to assist front
12486             --  end debugging. By placing a Reviewable pragma in the source
12487             --  program, a breakpoint on rv catches this place in the source,
12488             --  allowing convenient stepping to the point of interest.
12489
12490             rv;
12491
12492          --------------------------
12493          -- Short_Circuit_And_Or --
12494          --------------------------
12495
12496          when Pragma_Short_Circuit_And_Or =>
12497             GNAT_Pragma;
12498             Check_Arg_Count (0);
12499             Check_Valid_Configuration_Pragma;
12500             Short_Circuit_And_Or := True;
12501
12502          -------------------
12503          -- Share_Generic --
12504          -------------------
12505
12506          --  pragma Share_Generic (NAME {, NAME});
12507
12508          when Pragma_Share_Generic =>
12509             GNAT_Pragma;
12510             Process_Generic_List;
12511
12512          ------------
12513          -- Shared --
12514          ------------
12515
12516          --  pragma Shared (LOCAL_NAME);
12517
12518          when Pragma_Shared =>
12519             GNAT_Pragma;
12520             Process_Atomic_Shared_Volatile;
12521
12522          --------------------
12523          -- Shared_Passive --
12524          --------------------
12525
12526          --  pragma Shared_Passive [(library_unit_NAME)];
12527
12528          --  Set the flag Is_Shared_Passive of program unit name entity
12529
12530          when Pragma_Shared_Passive => Shared_Passive : declare
12531             Cunit_Node : Node_Id;
12532             Cunit_Ent  : Entity_Id;
12533
12534          begin
12535             Check_Ada_83_Warning;
12536             Check_Valid_Library_Unit_Pragma;
12537
12538             if Nkind (N) = N_Null_Statement then
12539                return;
12540             end if;
12541
12542             Cunit_Node := Cunit (Current_Sem_Unit);
12543             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12544
12545             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12546                                                 N_Generic_Package_Declaration)
12547             then
12548                Error_Pragma
12549                  ("pragma% can only apply to a package declaration");
12550             end if;
12551
12552             Set_Is_Shared_Passive (Cunit_Ent);
12553          end Shared_Passive;
12554
12555          -----------------------
12556          -- Short_Descriptors --
12557          -----------------------
12558
12559          --  pragma Short_Descriptors;
12560
12561          when Pragma_Short_Descriptors =>
12562             GNAT_Pragma;
12563             Check_Arg_Count (0);
12564             Check_Valid_Configuration_Pragma;
12565             Short_Descriptors := True;
12566
12567          ----------------------
12568          -- Source_File_Name --
12569          ----------------------
12570
12571          --  There are five forms for this pragma:
12572
12573          --  pragma Source_File_Name (
12574          --    [UNIT_NAME      =>] unit_NAME,
12575          --     BODY_FILE_NAME =>  STRING_LITERAL
12576          --    [, [INDEX =>] INTEGER_LITERAL]);
12577
12578          --  pragma Source_File_Name (
12579          --    [UNIT_NAME      =>] unit_NAME,
12580          --     SPEC_FILE_NAME =>  STRING_LITERAL
12581          --    [, [INDEX =>] INTEGER_LITERAL]);
12582
12583          --  pragma Source_File_Name (
12584          --     BODY_FILE_NAME  => STRING_LITERAL
12585          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12586          --  [, CASING          => CASING_SPEC]);
12587
12588          --  pragma Source_File_Name (
12589          --     SPEC_FILE_NAME  => STRING_LITERAL
12590          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12591          --  [, CASING          => CASING_SPEC]);
12592
12593          --  pragma Source_File_Name (
12594          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12595          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12596          --  [, CASING             => CASING_SPEC]);
12597
12598          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12599
12600          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12601          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12602          --  only be used when no project file is used, while SFNP can only be
12603          --  used when a project file is used.
12604
12605          --  No processing here. Processing was completed during parsing, since
12606          --  we need to have file names set as early as possible. Units are
12607          --  loaded well before semantic processing starts.
12608
12609          --  The only processing we defer to this point is the check for
12610          --  correct placement.
12611
12612          when Pragma_Source_File_Name =>
12613             GNAT_Pragma;
12614             Check_Valid_Configuration_Pragma;
12615
12616          ------------------------------
12617          -- Source_File_Name_Project --
12618          ------------------------------
12619
12620          --  See Source_File_Name for syntax
12621
12622          --  No processing here. Processing was completed during parsing, since
12623          --  we need to have file names set as early as possible. Units are
12624          --  loaded well before semantic processing starts.
12625
12626          --  The only processing we defer to this point is the check for
12627          --  correct placement.
12628
12629          when Pragma_Source_File_Name_Project =>
12630             GNAT_Pragma;
12631             Check_Valid_Configuration_Pragma;
12632
12633             --  Check that a pragma Source_File_Name_Project is used only in a
12634             --  configuration pragmas file.
12635
12636             --  Pragmas Source_File_Name_Project should only be generated by
12637             --  the Project Manager in configuration pragmas files.
12638
12639             --  This is really an ugly test. It seems to depend on some
12640             --  accidental and undocumented property. At the very least it
12641             --  needs to be documented, but it would be better to have a
12642             --  clean way of testing if we are in a configuration file???
12643
12644             if Present (Parent (N)) then
12645                Error_Pragma
12646                  ("pragma% can only appear in a configuration pragmas file");
12647             end if;
12648
12649          ----------------------
12650          -- Source_Reference --
12651          ----------------------
12652
12653          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12654
12655          --  Nothing to do, all processing completed in Par.Prag, since we need
12656          --  the information for possible parser messages that are output.
12657
12658          when Pragma_Source_Reference =>
12659             GNAT_Pragma;
12660
12661          --------------------------------
12662          -- Static_Elaboration_Desired --
12663          --------------------------------
12664
12665          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12666
12667          when Pragma_Static_Elaboration_Desired =>
12668             GNAT_Pragma;
12669             Check_At_Most_N_Arguments (1);
12670
12671             if Is_Compilation_Unit (Current_Scope)
12672               and then Ekind (Current_Scope) = E_Package
12673             then
12674                Set_Static_Elaboration_Desired (Current_Scope, True);
12675             else
12676                Error_Pragma ("pragma% must apply to a library-level package");
12677             end if;
12678
12679          ------------------
12680          -- Storage_Size --
12681          ------------------
12682
12683          --  pragma Storage_Size (EXPRESSION);
12684
12685          when Pragma_Storage_Size => Storage_Size : declare
12686             P   : constant Node_Id := Parent (N);
12687             Arg : Node_Id;
12688
12689          begin
12690             Check_No_Identifiers;
12691             Check_Arg_Count (1);
12692
12693             --  The expression must be analyzed in the special manner described
12694             --  in "Handling of Default Expressions" in sem.ads.
12695
12696             Arg := Get_Pragma_Arg (Arg1);
12697             Preanalyze_Spec_Expression (Arg, Any_Integer);
12698
12699             if not Is_Static_Expression (Arg) then
12700                Check_Restriction (Static_Storage_Size, Arg);
12701             end if;
12702
12703             if Nkind (P) /= N_Task_Definition then
12704                Pragma_Misplaced;
12705                return;
12706
12707             else
12708                if Has_Storage_Size_Pragma (P) then
12709                   Error_Pragma ("duplicate pragma% not allowed");
12710                else
12711                   Set_Has_Storage_Size_Pragma (P, True);
12712                end if;
12713
12714                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12715                --  ???  exp_ch9 should use this!
12716             end if;
12717          end Storage_Size;
12718
12719          ------------------
12720          -- Storage_Unit --
12721          ------------------
12722
12723          --  pragma Storage_Unit (NUMERIC_LITERAL);
12724
12725          --  Only permitted argument is System'Storage_Unit value
12726
12727          when Pragma_Storage_Unit =>
12728             Check_No_Identifiers;
12729             Check_Arg_Count (1);
12730             Check_Arg_Is_Integer_Literal (Arg1);
12731
12732             if Intval (Get_Pragma_Arg (Arg1)) /=
12733               UI_From_Int (Ttypes.System_Storage_Unit)
12734             then
12735                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12736                Error_Pragma_Arg
12737                  ("the only allowed argument for pragma% is ^", Arg1);
12738             end if;
12739
12740          --------------------
12741          -- Stream_Convert --
12742          --------------------
12743
12744          --  pragma Stream_Convert (
12745          --    [Entity =>] type_LOCAL_NAME,
12746          --    [Read   =>] function_NAME,
12747          --    [Write  =>] function NAME);
12748
12749          when Pragma_Stream_Convert => Stream_Convert : declare
12750
12751             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12752             --  Check that the given argument is the name of a local function
12753             --  of one argument that is not overloaded earlier in the current
12754             --  local scope. A check is also made that the argument is a
12755             --  function with one parameter.
12756
12757             --------------------------------------
12758             -- Check_OK_Stream_Convert_Function --
12759             --------------------------------------
12760
12761             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12762                Ent : Entity_Id;
12763
12764             begin
12765                Check_Arg_Is_Local_Name (Arg);
12766                Ent := Entity (Get_Pragma_Arg (Arg));
12767
12768                if Has_Homonym (Ent) then
12769                   Error_Pragma_Arg
12770                     ("argument for pragma% may not be overloaded", Arg);
12771                end if;
12772
12773                if Ekind (Ent) /= E_Function
12774                  or else No (First_Formal (Ent))
12775                  or else Present (Next_Formal (First_Formal (Ent)))
12776                then
12777                   Error_Pragma_Arg
12778                     ("argument for pragma% must be" &
12779                      " function of one argument", Arg);
12780                end if;
12781             end Check_OK_Stream_Convert_Function;
12782
12783          --  Start of processing for Stream_Convert
12784
12785          begin
12786             GNAT_Pragma;
12787             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12788             Check_Arg_Count (3);
12789             Check_Optional_Identifier (Arg1, Name_Entity);
12790             Check_Optional_Identifier (Arg2, Name_Read);
12791             Check_Optional_Identifier (Arg3, Name_Write);
12792             Check_Arg_Is_Local_Name (Arg1);
12793             Check_OK_Stream_Convert_Function (Arg2);
12794             Check_OK_Stream_Convert_Function (Arg3);
12795
12796             declare
12797                Typ   : constant Entity_Id :=
12798                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12799                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12800                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12801
12802             begin
12803                Check_First_Subtype (Arg1);
12804
12805                --  Check for too early or too late. Note that we don't enforce
12806                --  the rule about primitive operations in this case, since, as
12807                --  is the case for explicit stream attributes themselves, these
12808                --  restrictions are not appropriate. Note that the chaining of
12809                --  the pragma by Rep_Item_Too_Late is actually the critical
12810                --  processing done for this pragma.
12811
12812                if Rep_Item_Too_Early (Typ, N)
12813                     or else
12814                   Rep_Item_Too_Late (Typ, N, FOnly => True)
12815                then
12816                   return;
12817                end if;
12818
12819                --  Return if previous error
12820
12821                if Etype (Typ) = Any_Type
12822                     or else
12823                   Etype (Read) = Any_Type
12824                     or else
12825                   Etype (Write) = Any_Type
12826                then
12827                   return;
12828                end if;
12829
12830                --  Error checks
12831
12832                if Underlying_Type (Etype (Read)) /= Typ then
12833                   Error_Pragma_Arg
12834                     ("incorrect return type for function&", Arg2);
12835                end if;
12836
12837                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12838                   Error_Pragma_Arg
12839                     ("incorrect parameter type for function&", Arg3);
12840                end if;
12841
12842                if Underlying_Type (Etype (First_Formal (Read))) /=
12843                   Underlying_Type (Etype (Write))
12844                then
12845                   Error_Pragma_Arg
12846                     ("result type of & does not match Read parameter type",
12847                      Arg3);
12848                end if;
12849             end;
12850          end Stream_Convert;
12851
12852          -------------------------
12853          -- Style_Checks (GNAT) --
12854          -------------------------
12855
12856          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12857
12858          --  This is processed by the parser since some of the style checks
12859          --  take place during source scanning and parsing. This means that
12860          --  we don't need to issue error messages here.
12861
12862          when Pragma_Style_Checks => Style_Checks : declare
12863             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
12864             S  : String_Id;
12865             C  : Char_Code;
12866
12867          begin
12868             GNAT_Pragma;
12869             Check_No_Identifiers;
12870
12871             --  Two argument form
12872
12873             if Arg_Count = 2 then
12874                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12875
12876                declare
12877                   E_Id : Node_Id;
12878                   E    : Entity_Id;
12879
12880                begin
12881                   E_Id := Get_Pragma_Arg (Arg2);
12882                   Analyze (E_Id);
12883
12884                   if not Is_Entity_Name (E_Id) then
12885                      Error_Pragma_Arg
12886                        ("second argument of pragma% must be entity name",
12887                         Arg2);
12888                   end if;
12889
12890                   E := Entity (E_Id);
12891
12892                   if E = Any_Id then
12893                      return;
12894                   else
12895                      loop
12896                         Set_Suppress_Style_Checks (E,
12897                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12898                         exit when No (Homonym (E));
12899                         E := Homonym (E);
12900                      end loop;
12901                   end if;
12902                end;
12903
12904             --  One argument form
12905
12906             else
12907                Check_Arg_Count (1);
12908
12909                if Nkind (A) = N_String_Literal then
12910                   S   := Strval (A);
12911
12912                   declare
12913                      Slen    : constant Natural := Natural (String_Length (S));
12914                      Options : String (1 .. Slen);
12915                      J       : Natural;
12916
12917                   begin
12918                      J := 1;
12919                      loop
12920                         C := Get_String_Char (S, Int (J));
12921                         exit when not In_Character_Range (C);
12922                         Options (J) := Get_Character (C);
12923
12924                         --  If at end of string, set options. As per discussion
12925                         --  above, no need to check for errors, since we issued
12926                         --  them in the parser.
12927
12928                         if J = Slen then
12929                            Set_Style_Check_Options (Options);
12930                            exit;
12931                         end if;
12932
12933                         J := J + 1;
12934                      end loop;
12935                   end;
12936
12937                elsif Nkind (A) = N_Identifier then
12938                   if Chars (A) = Name_All_Checks then
12939                      if GNAT_Mode then
12940                         Set_GNAT_Style_Check_Options;
12941                      else
12942                         Set_Default_Style_Check_Options;
12943                      end if;
12944
12945                   elsif Chars (A) = Name_On then
12946                      Style_Check := True;
12947
12948                   elsif Chars (A) = Name_Off then
12949                      Style_Check := False;
12950                   end if;
12951                end if;
12952             end if;
12953          end Style_Checks;
12954
12955          --------------
12956          -- Subtitle --
12957          --------------
12958
12959          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
12960
12961          when Pragma_Subtitle =>
12962             GNAT_Pragma;
12963             Check_Arg_Count (1);
12964             Check_Optional_Identifier (Arg1, Name_Subtitle);
12965             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
12966             Store_Note (N);
12967
12968          --------------
12969          -- Suppress --
12970          --------------
12971
12972          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
12973
12974          when Pragma_Suppress =>
12975             Process_Suppress_Unsuppress (True);
12976
12977          ------------------
12978          -- Suppress_All --
12979          ------------------
12980
12981          --  pragma Suppress_All;
12982
12983          --  The only check made here is that the pragma has no arguments.
12984          --  There are no placement rules, and the processing required (setting
12985          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
12986          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
12987          --  then creates and inserts a pragma Suppress (All_Checks).
12988
12989          when Pragma_Suppress_All =>
12990             GNAT_Pragma;
12991             Check_Arg_Count (0);
12992
12993          -------------------------
12994          -- Suppress_Debug_Info --
12995          -------------------------
12996
12997          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
12998
12999          when Pragma_Suppress_Debug_Info =>
13000             GNAT_Pragma;
13001             Check_Arg_Count (1);
13002             Check_Optional_Identifier (Arg1, Name_Entity);
13003             Check_Arg_Is_Local_Name (Arg1);
13004             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13005
13006          ----------------------------------
13007          -- Suppress_Exception_Locations --
13008          ----------------------------------
13009
13010          --  pragma Suppress_Exception_Locations;
13011
13012          when Pragma_Suppress_Exception_Locations =>
13013             GNAT_Pragma;
13014             Check_Arg_Count (0);
13015             Check_Valid_Configuration_Pragma;
13016             Exception_Locations_Suppressed := True;
13017
13018          -----------------------------
13019          -- Suppress_Initialization --
13020          -----------------------------
13021
13022          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13023
13024          when Pragma_Suppress_Initialization => Suppress_Init : declare
13025             E_Id : Node_Id;
13026             E    : Entity_Id;
13027
13028          begin
13029             GNAT_Pragma;
13030             Check_Arg_Count (1);
13031             Check_Optional_Identifier (Arg1, Name_Entity);
13032             Check_Arg_Is_Local_Name (Arg1);
13033
13034             E_Id := Get_Pragma_Arg (Arg1);
13035
13036             if Etype (E_Id) = Any_Type then
13037                return;
13038             end if;
13039
13040             E := Entity (E_Id);
13041
13042             if not Is_Type (E) then
13043                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13044             end if;
13045
13046             if Rep_Item_Too_Early (E, N)
13047                  or else
13048                Rep_Item_Too_Late (E, N, FOnly => True)
13049             then
13050                return;
13051             end if;
13052
13053             --  For incomplete/private type, set flag on full view
13054
13055             if Is_Incomplete_Or_Private_Type (E) then
13056                if No (Full_View (Base_Type (E))) then
13057                   Error_Pragma_Arg
13058                     ("argument of pragma% cannot be an incomplete type", Arg1);
13059                else
13060                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13061                end if;
13062
13063             --  For first subtype, set flag on base type
13064
13065             elsif Is_First_Subtype (E) then
13066                Set_Suppress_Initialization (Base_Type (E));
13067
13068             --  For other than first subtype, set flag on subtype itself
13069
13070             else
13071                Set_Suppress_Initialization (E);
13072             end if;
13073          end Suppress_Init;
13074
13075          -----------------
13076          -- System_Name --
13077          -----------------
13078
13079          --  pragma System_Name (DIRECT_NAME);
13080
13081          --  Syntax check: one argument, which must be the identifier GNAT or
13082          --  the identifier GCC, no other identifiers are acceptable.
13083
13084          when Pragma_System_Name =>
13085             GNAT_Pragma;
13086             Check_No_Identifiers;
13087             Check_Arg_Count (1);
13088             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13089
13090          -----------------------------
13091          -- Task_Dispatching_Policy --
13092          -----------------------------
13093
13094          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13095
13096          when Pragma_Task_Dispatching_Policy => declare
13097             DP : Character;
13098
13099          begin
13100             Check_Ada_83_Warning;
13101             Check_Arg_Count (1);
13102             Check_No_Identifiers;
13103             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13104             Check_Valid_Configuration_Pragma;
13105             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13106             DP := Fold_Upper (Name_Buffer (1));
13107
13108             if Task_Dispatching_Policy /= ' '
13109               and then Task_Dispatching_Policy /= DP
13110             then
13111                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13112                Error_Pragma
13113                  ("task dispatching policy incompatible with policy#");
13114
13115             --  Set new policy, but always preserve System_Location since we
13116             --  like the error message with the run time name.
13117
13118             else
13119                Task_Dispatching_Policy := DP;
13120
13121                if Task_Dispatching_Policy_Sloc /= System_Location then
13122                   Task_Dispatching_Policy_Sloc := Loc;
13123                end if;
13124             end if;
13125          end;
13126
13127          ---------------
13128          -- Task_Info --
13129          ---------------
13130
13131          --  pragma Task_Info (EXPRESSION);
13132
13133          when Pragma_Task_Info => Task_Info : declare
13134             P : constant Node_Id := Parent (N);
13135
13136          begin
13137             GNAT_Pragma;
13138
13139             if Nkind (P) /= N_Task_Definition then
13140                Error_Pragma ("pragma% must appear in task definition");
13141             end if;
13142
13143             Check_No_Identifiers;
13144             Check_Arg_Count (1);
13145
13146             Analyze_And_Resolve
13147               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13148
13149             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13150                return;
13151             end if;
13152
13153             if Has_Task_Info_Pragma (P) then
13154                Error_Pragma ("duplicate pragma% not allowed");
13155             else
13156                Set_Has_Task_Info_Pragma (P, True);
13157             end if;
13158          end Task_Info;
13159
13160          ---------------
13161          -- Task_Name --
13162          ---------------
13163
13164          --  pragma Task_Name (string_EXPRESSION);
13165
13166          when Pragma_Task_Name => Task_Name : declare
13167             P   : constant Node_Id := Parent (N);
13168             Arg : Node_Id;
13169
13170          begin
13171             Check_No_Identifiers;
13172             Check_Arg_Count (1);
13173
13174             Arg := Get_Pragma_Arg (Arg1);
13175
13176             --  The expression is used in the call to Create_Task, and must be
13177             --  expanded there, not in the context of the current spec. It must
13178             --  however be analyzed to capture global references, in case it
13179             --  appears in a generic context.
13180
13181             Preanalyze_And_Resolve (Arg, Standard_String);
13182
13183             if Nkind (P) /= N_Task_Definition then
13184                Pragma_Misplaced;
13185             end if;
13186
13187             if Has_Task_Name_Pragma (P) then
13188                Error_Pragma ("duplicate pragma% not allowed");
13189             else
13190                Set_Has_Task_Name_Pragma (P, True);
13191                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13192             end if;
13193          end Task_Name;
13194
13195          ------------------
13196          -- Task_Storage --
13197          ------------------
13198
13199          --  pragma Task_Storage (
13200          --     [Task_Type =>] LOCAL_NAME,
13201          --     [Top_Guard =>] static_integer_EXPRESSION);
13202
13203          when Pragma_Task_Storage => Task_Storage : declare
13204             Args  : Args_List (1 .. 2);
13205             Names : constant Name_List (1 .. 2) := (
13206                       Name_Task_Type,
13207                       Name_Top_Guard);
13208
13209             Task_Type : Node_Id renames Args (1);
13210             Top_Guard : Node_Id renames Args (2);
13211
13212             Ent : Entity_Id;
13213
13214          begin
13215             GNAT_Pragma;
13216             Gather_Associations (Names, Args);
13217
13218             if No (Task_Type) then
13219                Error_Pragma
13220                  ("missing task_type argument for pragma%");
13221             end if;
13222
13223             Check_Arg_Is_Local_Name (Task_Type);
13224
13225             Ent := Entity (Task_Type);
13226
13227             if not Is_Task_Type (Ent) then
13228                Error_Pragma_Arg
13229                  ("argument for pragma% must be task type", Task_Type);
13230             end if;
13231
13232             if No (Top_Guard) then
13233                Error_Pragma_Arg
13234                  ("pragma% takes two arguments", Task_Type);
13235             else
13236                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13237             end if;
13238
13239             Check_First_Subtype (Task_Type);
13240
13241             if Rep_Item_Too_Late (Ent, N) then
13242                raise Pragma_Exit;
13243             end if;
13244          end Task_Storage;
13245
13246          ---------------
13247          -- Test_Case --
13248          ---------------
13249
13250          --  pragma Test_Case ([Name     =>] static_string_EXPRESSION
13251          --                   ,[Mode     =>] (Normal | Robustness)
13252          --                  [, Requires =>  Boolean_EXPRESSION]
13253          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13254
13255          when Pragma_Test_Case => Test_Case : declare
13256          begin
13257             GNAT_Pragma;
13258             Check_At_Least_N_Arguments (3);
13259             Check_At_Most_N_Arguments (4);
13260             Check_Arg_Order
13261               ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13262
13263             Check_Optional_Identifier (Arg1, Name_Name);
13264             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13265             Check_Optional_Identifier (Arg2, Name_Mode);
13266             Check_Arg_Is_One_Of (Arg2, Name_Normal, Name_Robustness);
13267
13268             if Arg_Count = 4 then
13269                Check_Identifier (Arg3, Name_Requires);
13270                Check_Identifier (Arg4, Name_Ensures);
13271             else
13272                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13273             end if;
13274
13275             Check_Test_Case;
13276          end Test_Case;
13277
13278          --------------------------
13279          -- Thread_Local_Storage --
13280          --------------------------
13281
13282          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13283
13284          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13285             Id : Node_Id;
13286             E  : Entity_Id;
13287
13288          begin
13289             GNAT_Pragma;
13290             Check_Arg_Count (1);
13291             Check_Optional_Identifier (Arg1, Name_Entity);
13292             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13293
13294             Id := Get_Pragma_Arg (Arg1);
13295             Analyze (Id);
13296
13297             if not Is_Entity_Name (Id)
13298               or else Ekind (Entity (Id)) /= E_Variable
13299             then
13300                Error_Pragma_Arg ("local variable name required", Arg1);
13301             end if;
13302
13303             E := Entity (Id);
13304
13305             if Rep_Item_Too_Early (E, N)
13306               or else Rep_Item_Too_Late (E, N)
13307             then
13308                raise Pragma_Exit;
13309             end if;
13310
13311             Set_Has_Pragma_Thread_Local_Storage (E);
13312             Set_Has_Gigi_Rep_Item (E);
13313          end Thread_Local_Storage;
13314
13315          ----------------
13316          -- Time_Slice --
13317          ----------------
13318
13319          --  pragma Time_Slice (static_duration_EXPRESSION);
13320
13321          when Pragma_Time_Slice => Time_Slice : declare
13322             Val : Ureal;
13323             Nod : Node_Id;
13324
13325          begin
13326             GNAT_Pragma;
13327             Check_Arg_Count (1);
13328             Check_No_Identifiers;
13329             Check_In_Main_Program;
13330             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13331
13332             if not Error_Posted (Arg1) then
13333                Nod := Next (N);
13334                while Present (Nod) loop
13335                   if Nkind (Nod) = N_Pragma
13336                     and then Pragma_Name (Nod) = Name_Time_Slice
13337                   then
13338                      Error_Msg_Name_1 := Pname;
13339                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13340                   end if;
13341
13342                   Next (Nod);
13343                end loop;
13344             end if;
13345
13346             --  Process only if in main unit
13347
13348             if Get_Source_Unit (Loc) = Main_Unit then
13349                Opt.Time_Slice_Set := True;
13350                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13351
13352                if Val <= Ureal_0 then
13353                   Opt.Time_Slice_Value := 0;
13354
13355                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13356                   Opt.Time_Slice_Value := 1_000_000_000;
13357
13358                else
13359                   Opt.Time_Slice_Value :=
13360                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13361                end if;
13362             end if;
13363          end Time_Slice;
13364
13365          -----------
13366          -- Title --
13367          -----------
13368
13369          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13370
13371          --   TITLING_OPTION ::=
13372          --     [Title =>] STRING_LITERAL
13373          --   | [Subtitle =>] STRING_LITERAL
13374
13375          when Pragma_Title => Title : declare
13376             Args  : Args_List (1 .. 2);
13377             Names : constant Name_List (1 .. 2) := (
13378                       Name_Title,
13379                       Name_Subtitle);
13380
13381          begin
13382             GNAT_Pragma;
13383             Gather_Associations (Names, Args);
13384             Store_Note (N);
13385
13386             for J in 1 .. 2 loop
13387                if Present (Args (J)) then
13388                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13389                end if;
13390             end loop;
13391          end Title;
13392
13393          ---------------------
13394          -- Unchecked_Union --
13395          ---------------------
13396
13397          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13398
13399          when Pragma_Unchecked_Union => Unchecked_Union : declare
13400             Assoc   : constant Node_Id := Arg1;
13401             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13402             Typ     : Entity_Id;
13403             Discr   : Entity_Id;
13404             Tdef    : Node_Id;
13405             Clist   : Node_Id;
13406             Vpart   : Node_Id;
13407             Comp    : Node_Id;
13408             Variant : Node_Id;
13409
13410          begin
13411             Ada_2005_Pragma;
13412             Check_No_Identifiers;
13413             Check_Arg_Count (1);
13414             Check_Arg_Is_Local_Name (Arg1);
13415
13416             Find_Type (Type_Id);
13417             Typ := Entity (Type_Id);
13418
13419             if Typ = Any_Type
13420               or else Rep_Item_Too_Early (Typ, N)
13421             then
13422                return;
13423             else
13424                Typ := Underlying_Type (Typ);
13425             end if;
13426
13427             if Rep_Item_Too_Late (Typ, N) then
13428                return;
13429             end if;
13430
13431             Check_First_Subtype (Arg1);
13432
13433             --  Note remaining cases are references to a type in the current
13434             --  declarative part. If we find an error, we post the error on
13435             --  the relevant type declaration at an appropriate point.
13436
13437             if not Is_Record_Type (Typ) then
13438                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13439                return;
13440
13441             elsif Is_Tagged_Type (Typ) then
13442                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13443                return;
13444
13445             elsif Is_Limited_Type (Typ) then
13446                Error_Msg_N
13447                  ("Unchecked_Union must not be limited record type", Typ);
13448                Explain_Limited_Type (Typ, Typ);
13449                return;
13450
13451             else
13452                if not Has_Discriminants (Typ) then
13453                   Error_Msg_N
13454                     ("Unchecked_Union must have one discriminant", Typ);
13455                   return;
13456                end if;
13457
13458                Discr := First_Discriminant (Typ);
13459                while Present (Discr) loop
13460                   if No (Discriminant_Default_Value (Discr)) then
13461                      Error_Msg_N
13462                        ("Unchecked_Union discriminant must have default value",
13463                         Discr);
13464                   end if;
13465
13466                   Next_Discriminant (Discr);
13467                end loop;
13468
13469                Tdef  := Type_Definition (Declaration_Node (Typ));
13470                Clist := Component_List (Tdef);
13471
13472                Comp := First (Component_Items (Clist));
13473                while Present (Comp) loop
13474                   Check_Component (Comp, Typ);
13475                   Next (Comp);
13476                end loop;
13477
13478                if No (Clist) or else No (Variant_Part (Clist)) then
13479                   Error_Msg_N
13480                     ("Unchecked_Union must have variant part",
13481                      Tdef);
13482                   return;
13483                end if;
13484
13485                Vpart := Variant_Part (Clist);
13486
13487                Variant := First (Variants (Vpart));
13488                while Present (Variant) loop
13489                   Check_Variant (Variant, Typ);
13490                   Next (Variant);
13491                end loop;
13492             end if;
13493
13494             Set_Is_Unchecked_Union  (Typ);
13495             Set_Convention (Typ, Convention_C);
13496             Set_Has_Unchecked_Union (Base_Type (Typ));
13497             Set_Is_Unchecked_Union  (Base_Type (Typ));
13498          end Unchecked_Union;
13499
13500          ------------------------
13501          -- Unimplemented_Unit --
13502          ------------------------
13503
13504          --  pragma Unimplemented_Unit;
13505
13506          --  Note: this only gives an error if we are generating code, or if
13507          --  we are in a generic library unit (where the pragma appears in the
13508          --  body, not in the spec).
13509
13510          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13511             Cunitent : constant Entity_Id :=
13512                          Cunit_Entity (Get_Source_Unit (Loc));
13513             Ent_Kind : constant Entity_Kind :=
13514                          Ekind (Cunitent);
13515
13516          begin
13517             GNAT_Pragma;
13518             Check_Arg_Count (0);
13519
13520             if Operating_Mode = Generate_Code
13521               or else Ent_Kind = E_Generic_Function
13522               or else Ent_Kind = E_Generic_Procedure
13523               or else Ent_Kind = E_Generic_Package
13524             then
13525                Get_Name_String (Chars (Cunitent));
13526                Set_Casing (Mixed_Case);
13527                Write_Str (Name_Buffer (1 .. Name_Len));
13528                Write_Str (" is not supported in this configuration");
13529                Write_Eol;
13530                raise Unrecoverable_Error;
13531             end if;
13532          end Unimplemented_Unit;
13533
13534          ------------------------
13535          -- Universal_Aliasing --
13536          ------------------------
13537
13538          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13539
13540          when Pragma_Universal_Aliasing => Universal_Alias : declare
13541             E_Id : Entity_Id;
13542
13543          begin
13544             GNAT_Pragma;
13545             Check_Arg_Count (1);
13546             Check_Optional_Identifier (Arg2, Name_Entity);
13547             Check_Arg_Is_Local_Name (Arg1);
13548             E_Id := Entity (Get_Pragma_Arg (Arg1));
13549
13550             if E_Id = Any_Type then
13551                return;
13552             elsif No (E_Id) or else not Is_Type (E_Id) then
13553                Error_Pragma_Arg ("pragma% requires type", Arg1);
13554             end if;
13555
13556             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13557          end Universal_Alias;
13558
13559          --------------------
13560          -- Universal_Data --
13561          --------------------
13562
13563          --  pragma Universal_Data [(library_unit_NAME)];
13564
13565          when Pragma_Universal_Data =>
13566             GNAT_Pragma;
13567
13568             --  If this is a configuration pragma, then set the universal
13569             --  addressing option, otherwise confirm that the pragma satisfies
13570             --  the requirements of library unit pragma placement and leave it
13571             --  to the GNAAMP back end to detect the pragma (avoids transitive
13572             --  setting of the option due to withed units).
13573
13574             if Is_Configuration_Pragma then
13575                Universal_Addressing_On_AAMP := True;
13576             else
13577                Check_Valid_Library_Unit_Pragma;
13578             end if;
13579
13580             if not AAMP_On_Target then
13581                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13582             end if;
13583
13584          ----------------
13585          -- Unmodified --
13586          ----------------
13587
13588          --  pragma Unmodified (local_Name {, local_Name});
13589
13590          when Pragma_Unmodified => Unmodified : declare
13591             Arg_Node : Node_Id;
13592             Arg_Expr : Node_Id;
13593             Arg_Ent  : Entity_Id;
13594
13595          begin
13596             GNAT_Pragma;
13597             Check_At_Least_N_Arguments (1);
13598
13599             --  Loop through arguments
13600
13601             Arg_Node := Arg1;
13602             while Present (Arg_Node) loop
13603                Check_No_Identifier (Arg_Node);
13604
13605                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13606                --  in fact generate reference, so that the entity will have a
13607                --  reference, which will inhibit any warnings about it not
13608                --  being referenced, and also properly show up in the ali file
13609                --  as a reference. But this reference is recorded before the
13610                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13611                --  generated for this reference.
13612
13613                Check_Arg_Is_Local_Name (Arg_Node);
13614                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13615
13616                if Is_Entity_Name (Arg_Expr) then
13617                   Arg_Ent := Entity (Arg_Expr);
13618
13619                   if not Is_Assignable (Arg_Ent) then
13620                      Error_Pragma_Arg
13621                        ("pragma% can only be applied to a variable",
13622                         Arg_Expr);
13623                   else
13624                      Set_Has_Pragma_Unmodified (Arg_Ent);
13625                   end if;
13626                end if;
13627
13628                Next (Arg_Node);
13629             end loop;
13630          end Unmodified;
13631
13632          ------------------
13633          -- Unreferenced --
13634          ------------------
13635
13636          --  pragma Unreferenced (local_Name {, local_Name});
13637
13638          --    or when used in a context clause:
13639
13640          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13641
13642          when Pragma_Unreferenced => Unreferenced : declare
13643             Arg_Node : Node_Id;
13644             Arg_Expr : Node_Id;
13645             Arg_Ent  : Entity_Id;
13646             Citem    : Node_Id;
13647
13648          begin
13649             GNAT_Pragma;
13650             Check_At_Least_N_Arguments (1);
13651
13652             --  Check case of appearing within context clause
13653
13654             if Is_In_Context_Clause then
13655
13656                --  The arguments must all be units mentioned in a with clause
13657                --  in the same context clause. Note we already checked (in
13658                --  Par.Prag) that the arguments are either identifiers or
13659                --  selected components.
13660
13661                Arg_Node := Arg1;
13662                while Present (Arg_Node) loop
13663                   Citem := First (List_Containing (N));
13664                   while Citem /= N loop
13665                      if Nkind (Citem) = N_With_Clause
13666                        and then
13667                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13668                      then
13669                         Set_Has_Pragma_Unreferenced
13670                           (Cunit_Entity
13671                              (Get_Source_Unit
13672                                 (Library_Unit (Citem))));
13673                         Set_Unit_Name
13674                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
13675                         exit;
13676                      end if;
13677
13678                      Next (Citem);
13679                   end loop;
13680
13681                   if Citem = N then
13682                      Error_Pragma_Arg
13683                        ("argument of pragma% is not with'ed unit", Arg_Node);
13684                   end if;
13685
13686                   Next (Arg_Node);
13687                end loop;
13688
13689             --  Case of not in list of context items
13690
13691             else
13692                Arg_Node := Arg1;
13693                while Present (Arg_Node) loop
13694                   Check_No_Identifier (Arg_Node);
13695
13696                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
13697                   --  will in fact generate reference, so that the entity will
13698                   --  have a reference, which will inhibit any warnings about
13699                   --  it not being referenced, and also properly show up in the
13700                   --  ali file as a reference. But this reference is recorded
13701                   --  before the Has_Pragma_Unreferenced flag is set, so that
13702                   --  no warning is generated for this reference.
13703
13704                   Check_Arg_Is_Local_Name (Arg_Node);
13705                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
13706
13707                   if Is_Entity_Name (Arg_Expr) then
13708                      Arg_Ent := Entity (Arg_Expr);
13709
13710                      --  If the entity is overloaded, the pragma applies to the
13711                      --  most recent overloading, as documented. In this case,
13712                      --  name resolution does not generate a reference, so it
13713                      --  must be done here explicitly.
13714
13715                      if Is_Overloaded (Arg_Expr) then
13716                         Generate_Reference (Arg_Ent, N);
13717                      end if;
13718
13719                      Set_Has_Pragma_Unreferenced (Arg_Ent);
13720                   end if;
13721
13722                   Next (Arg_Node);
13723                end loop;
13724             end if;
13725          end Unreferenced;
13726
13727          --------------------------
13728          -- Unreferenced_Objects --
13729          --------------------------
13730
13731          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13732
13733          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13734             Arg_Node : Node_Id;
13735             Arg_Expr : Node_Id;
13736
13737          begin
13738             GNAT_Pragma;
13739             Check_At_Least_N_Arguments (1);
13740
13741             Arg_Node := Arg1;
13742             while Present (Arg_Node) loop
13743                Check_No_Identifier (Arg_Node);
13744                Check_Arg_Is_Local_Name (Arg_Node);
13745                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13746
13747                if not Is_Entity_Name (Arg_Expr)
13748                  or else not Is_Type (Entity (Arg_Expr))
13749                then
13750                   Error_Pragma_Arg
13751                     ("argument for pragma% must be type or subtype", Arg_Node);
13752                end if;
13753
13754                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13755                Next (Arg_Node);
13756             end loop;
13757          end Unreferenced_Objects;
13758
13759          ------------------------------
13760          -- Unreserve_All_Interrupts --
13761          ------------------------------
13762
13763          --  pragma Unreserve_All_Interrupts;
13764
13765          when Pragma_Unreserve_All_Interrupts =>
13766             GNAT_Pragma;
13767             Check_Arg_Count (0);
13768
13769             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13770                Unreserve_All_Interrupts := True;
13771             end if;
13772
13773          ----------------
13774          -- Unsuppress --
13775          ----------------
13776
13777          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13778
13779          when Pragma_Unsuppress =>
13780             Ada_2005_Pragma;
13781             Process_Suppress_Unsuppress (False);
13782
13783          -------------------
13784          -- Use_VADS_Size --
13785          -------------------
13786
13787          --  pragma Use_VADS_Size;
13788
13789          when Pragma_Use_VADS_Size =>
13790             GNAT_Pragma;
13791             Check_Arg_Count (0);
13792             Check_Valid_Configuration_Pragma;
13793             Use_VADS_Size := True;
13794
13795          ---------------------
13796          -- Validity_Checks --
13797          ---------------------
13798
13799          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13800
13801          when Pragma_Validity_Checks => Validity_Checks : declare
13802             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13803             S  : String_Id;
13804             C  : Char_Code;
13805
13806          begin
13807             GNAT_Pragma;
13808             Check_Arg_Count (1);
13809             Check_No_Identifiers;
13810
13811             if Nkind (A) = N_String_Literal then
13812                S   := Strval (A);
13813
13814                declare
13815                   Slen    : constant Natural := Natural (String_Length (S));
13816                   Options : String (1 .. Slen);
13817                   J       : Natural;
13818
13819                begin
13820                   J := 1;
13821                   loop
13822                      C := Get_String_Char (S, Int (J));
13823                      exit when not In_Character_Range (C);
13824                      Options (J) := Get_Character (C);
13825
13826                      if J = Slen then
13827                         Set_Validity_Check_Options (Options);
13828                         exit;
13829                      else
13830                         J := J + 1;
13831                      end if;
13832                   end loop;
13833                end;
13834
13835             elsif Nkind (A) = N_Identifier then
13836
13837                if Chars (A) = Name_All_Checks then
13838                   Set_Validity_Check_Options ("a");
13839
13840                elsif Chars (A) = Name_On then
13841                   Validity_Checks_On := True;
13842
13843                elsif Chars (A) = Name_Off then
13844                   Validity_Checks_On := False;
13845
13846                end if;
13847             end if;
13848          end Validity_Checks;
13849
13850          --------------
13851          -- Volatile --
13852          --------------
13853
13854          --  pragma Volatile (LOCAL_NAME);
13855
13856          when Pragma_Volatile =>
13857             Process_Atomic_Shared_Volatile;
13858
13859          -------------------------
13860          -- Volatile_Components --
13861          -------------------------
13862
13863          --  pragma Volatile_Components (array_LOCAL_NAME);
13864
13865          --  Volatile is handled by the same circuit as Atomic_Components
13866
13867          --------------
13868          -- Warnings --
13869          --------------
13870
13871          --  pragma Warnings (On | Off);
13872          --  pragma Warnings (On | Off, LOCAL_NAME);
13873          --  pragma Warnings (static_string_EXPRESSION);
13874          --  pragma Warnings (On | Off, STRING_LITERAL);
13875
13876          when Pragma_Warnings => Warnings : begin
13877             GNAT_Pragma;
13878             Check_At_Least_N_Arguments (1);
13879             Check_No_Identifiers;
13880
13881             --  If debug flag -gnatd.i is set, pragma is ignored
13882
13883             if Debug_Flag_Dot_I then
13884                return;
13885             end if;
13886
13887             --  Process various forms of the pragma
13888
13889             declare
13890                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13891
13892             begin
13893                --  One argument case
13894
13895                if Arg_Count = 1 then
13896
13897                   --  On/Off one argument case was processed by parser
13898
13899                   if Nkind (Argx) = N_Identifier
13900                     and then
13901                       (Chars (Argx) = Name_On
13902                          or else
13903                        Chars (Argx) = Name_Off)
13904                   then
13905                      null;
13906
13907                   --  One argument case must be ON/OFF or static string expr
13908
13909                   elsif not Is_Static_String_Expression (Arg1) then
13910                      Error_Pragma_Arg
13911                        ("argument of pragma% must be On/Off or " &
13912                         "static string expression", Arg1);
13913
13914                   --  One argument string expression case
13915
13916                   else
13917                      declare
13918                         Lit : constant Node_Id   := Expr_Value_S (Argx);
13919                         Str : constant String_Id := Strval (Lit);
13920                         Len : constant Nat       := String_Length (Str);
13921                         C   : Char_Code;
13922                         J   : Nat;
13923                         OK  : Boolean;
13924                         Chr : Character;
13925
13926                      begin
13927                         J := 1;
13928                         while J <= Len loop
13929                            C := Get_String_Char (Str, J);
13930                            OK := In_Character_Range (C);
13931
13932                            if OK then
13933                               Chr := Get_Character (C);
13934
13935                               --  Dot case
13936
13937                               if J < Len and then Chr = '.' then
13938                                  J := J + 1;
13939                                  C := Get_String_Char (Str, J);
13940                                  Chr := Get_Character (C);
13941
13942                                  if not Set_Dot_Warning_Switch (Chr) then
13943                                     Error_Pragma_Arg
13944                                       ("invalid warning switch character " &
13945                                        '.' & Chr, Arg1);
13946                                  end if;
13947
13948                               --  Non-Dot case
13949
13950                               else
13951                                  OK := Set_Warning_Switch (Chr);
13952                               end if;
13953                            end if;
13954
13955                            if not OK then
13956                               Error_Pragma_Arg
13957                                 ("invalid warning switch character " & Chr,
13958                                  Arg1);
13959                            end if;
13960
13961                            J := J + 1;
13962                         end loop;
13963                      end;
13964                   end if;
13965
13966                   --  Two or more arguments (must be two)
13967
13968                else
13969                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
13970                   Check_At_Most_N_Arguments (2);
13971
13972                   declare
13973                      E_Id : Node_Id;
13974                      E    : Entity_Id;
13975                      Err  : Boolean;
13976
13977                   begin
13978                      E_Id := Get_Pragma_Arg (Arg2);
13979                      Analyze (E_Id);
13980
13981                      --  In the expansion of an inlined body, a reference to
13982                      --  the formal may be wrapped in a conversion if the
13983                      --  actual is a conversion. Retrieve the real entity name.
13984
13985                      if (In_Instance_Body
13986                          or else In_Inlined_Body)
13987                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
13988                      then
13989                         E_Id := Expression (E_Id);
13990                      end if;
13991
13992                      --  Entity name case
13993
13994                      if Is_Entity_Name (E_Id) then
13995                         E := Entity (E_Id);
13996
13997                         if E = Any_Id then
13998                            return;
13999                         else
14000                            loop
14001                               Set_Warnings_Off
14002                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14003                                                               Name_Off));
14004
14005                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14006                                 and then Warn_On_Warnings_Off
14007                               then
14008                                  Warnings_Off_Pragmas.Append ((N, E));
14009                               end if;
14010
14011                               if Is_Enumeration_Type (E) then
14012                                  declare
14013                                     Lit : Entity_Id;
14014                                  begin
14015                                     Lit := First_Literal (E);
14016                                     while Present (Lit) loop
14017                                        Set_Warnings_Off (Lit);
14018                                        Next_Literal (Lit);
14019                                     end loop;
14020                                  end;
14021                               end if;
14022
14023                               exit when No (Homonym (E));
14024                               E := Homonym (E);
14025                            end loop;
14026                         end if;
14027
14028                      --  Error if not entity or static string literal case
14029
14030                      elsif not Is_Static_String_Expression (Arg2) then
14031                         Error_Pragma_Arg
14032                           ("second argument of pragma% must be entity " &
14033                            "name or static string expression", Arg2);
14034
14035                      --  String literal case
14036
14037                      else
14038                         String_To_Name_Buffer
14039                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14040
14041                         --  Note on configuration pragma case: If this is a
14042                         --  configuration pragma, then for an OFF pragma, we
14043                         --  just set Config True in the call, which is all
14044                         --  that needs to be done. For the case of ON, this
14045                         --  is normally an error, unless it is canceling the
14046                         --  effect of a previous OFF pragma in the same file.
14047                         --  In any other case, an error will be signalled (ON
14048                         --  with no matching OFF).
14049
14050                         if Chars (Argx) = Name_Off then
14051                            Set_Specific_Warning_Off
14052                              (Loc, Name_Buffer (1 .. Name_Len),
14053                               Config => Is_Configuration_Pragma);
14054
14055                         elsif Chars (Argx) = Name_On then
14056                            Set_Specific_Warning_On
14057                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14058
14059                            if Err then
14060                               Error_Msg
14061                                 ("?pragma Warnings On with no " &
14062                                  "matching Warnings Off",
14063                                  Loc);
14064                            end if;
14065                         end if;
14066                      end if;
14067                   end;
14068                end if;
14069             end;
14070          end Warnings;
14071
14072          -------------------
14073          -- Weak_External --
14074          -------------------
14075
14076          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14077
14078          when Pragma_Weak_External => Weak_External : declare
14079             Ent : Entity_Id;
14080
14081          begin
14082             GNAT_Pragma;
14083             Check_Arg_Count (1);
14084             Check_Optional_Identifier (Arg1, Name_Entity);
14085             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14086             Ent := Entity (Get_Pragma_Arg (Arg1));
14087
14088             if Rep_Item_Too_Early (Ent, N) then
14089                return;
14090             else
14091                Ent := Underlying_Type (Ent);
14092             end if;
14093
14094             --  The only processing required is to link this item on to the
14095             --  list of rep items for the given entity. This is accomplished
14096             --  by the call to Rep_Item_Too_Late (when no error is detected
14097             --  and False is returned).
14098
14099             if Rep_Item_Too_Late (Ent, N) then
14100                return;
14101             else
14102                Set_Has_Gigi_Rep_Item (Ent);
14103             end if;
14104          end Weak_External;
14105
14106          -----------------------------
14107          -- Wide_Character_Encoding --
14108          -----------------------------
14109
14110          --  pragma Wide_Character_Encoding (IDENTIFIER);
14111
14112          when Pragma_Wide_Character_Encoding =>
14113             GNAT_Pragma;
14114
14115             --  Nothing to do, handled in parser. Note that we do not enforce
14116             --  configuration pragma placement, this pragma can appear at any
14117             --  place in the source, allowing mixed encodings within a single
14118             --  source program.
14119
14120             null;
14121
14122          --------------------
14123          -- Unknown_Pragma --
14124          --------------------
14125
14126          --  Should be impossible, since the case of an unknown pragma is
14127          --  separately processed before the case statement is entered.
14128
14129          when Unknown_Pragma =>
14130             raise Program_Error;
14131       end case;
14132
14133       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14134       --  until AI is formally approved.
14135
14136       --  Check_Order_Dependence;
14137
14138    exception
14139       when Pragma_Exit => null;
14140    end Analyze_Pragma;
14141
14142    -----------------------------
14143    -- Analyze_TC_In_Decl_Part --
14144    -----------------------------
14145
14146    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14147    begin
14148       --  Install formals and push subprogram spec onto scope stack so that we
14149       --  can see the formals from the pragma.
14150
14151       Install_Formals (S);
14152       Push_Scope (S);
14153
14154       --  Preanalyze the boolean expressions, we treat these as spec
14155       --  expressions (i.e. similar to a default expression).
14156
14157       Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14158                           Get_Ensures_From_Test_Case_Pragma (N));
14159
14160       --  Remove the subprogram from the scope stack now that the pre-analysis
14161       --  of the expressions in the test-case is done.
14162
14163       End_Scope;
14164    end Analyze_TC_In_Decl_Part;
14165
14166    -------------------
14167    -- Check_Enabled --
14168    -------------------
14169
14170    function Check_Enabled (Nam : Name_Id) return Boolean is
14171       PP : Node_Id;
14172
14173    begin
14174       --  Loop through entries in check policy list
14175
14176       PP := Opt.Check_Policy_List;
14177       loop
14178          --  If there are no specific entries that matched, then we let the
14179          --  setting of assertions govern. Note that this provides the needed
14180          --  compatibility with the RM for the cases of assertion, invariant,
14181          --  precondition, predicate, and postcondition.
14182
14183          if No (PP) then
14184             return Assertions_Enabled;
14185
14186          --  Here we have an entry see if it matches
14187
14188          else
14189             declare
14190                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14191
14192             begin
14193                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14194                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14195                      when Name_On | Name_Check =>
14196                         return True;
14197                      when Name_Off | Name_Ignore =>
14198                         return False;
14199                      when others =>
14200                         raise Program_Error;
14201                   end case;
14202
14203                else
14204                   PP := Next_Pragma (PP);
14205                end if;
14206             end;
14207          end if;
14208       end loop;
14209    end Check_Enabled;
14210
14211    ---------------------------------
14212    -- Delay_Config_Pragma_Analyze --
14213    ---------------------------------
14214
14215    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14216    begin
14217       return Pragma_Name (N) = Name_Interrupt_State
14218                or else
14219              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14220    end Delay_Config_Pragma_Analyze;
14221
14222    -------------------------
14223    -- Get_Base_Subprogram --
14224    -------------------------
14225
14226    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14227       Result : Entity_Id;
14228
14229    begin
14230       --  Follow subprogram renaming chain
14231
14232       Result := Def_Id;
14233       while Is_Subprogram (Result)
14234         and then
14235           Nkind (Parent (Declaration_Node (Result))) =
14236                                          N_Subprogram_Renaming_Declaration
14237         and then Present (Alias (Result))
14238       loop
14239          Result := Alias (Result);
14240       end loop;
14241
14242       return Result;
14243    end Get_Base_Subprogram;
14244
14245    ----------------
14246    -- Initialize --
14247    ----------------
14248
14249    procedure Initialize is
14250    begin
14251       Externals.Init;
14252    end Initialize;
14253
14254    -----------------------------
14255    -- Is_Config_Static_String --
14256    -----------------------------
14257
14258    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14259
14260       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14261       --  This is an internal recursive function that is just like the outer
14262       --  function except that it adds the string to the name buffer rather
14263       --  than placing the string in the name buffer.
14264
14265       ------------------------------
14266       -- Add_Config_Static_String --
14267       ------------------------------
14268
14269       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14270          N : Node_Id;
14271          C : Char_Code;
14272
14273       begin
14274          N := Arg;
14275
14276          if Nkind (N) = N_Op_Concat then
14277             if Add_Config_Static_String (Left_Opnd (N)) then
14278                N := Right_Opnd (N);
14279             else
14280                return False;
14281             end if;
14282          end if;
14283
14284          if Nkind (N) /= N_String_Literal then
14285             Error_Msg_N ("string literal expected for pragma argument", N);
14286             return False;
14287
14288          else
14289             for J in 1 .. String_Length (Strval (N)) loop
14290                C := Get_String_Char (Strval (N), J);
14291
14292                if not In_Character_Range (C) then
14293                   Error_Msg
14294                     ("string literal contains invalid wide character",
14295                      Sloc (N) + 1 + Source_Ptr (J));
14296                   return False;
14297                end if;
14298
14299                Add_Char_To_Name_Buffer (Get_Character (C));
14300             end loop;
14301          end if;
14302
14303          return True;
14304       end Add_Config_Static_String;
14305
14306    --  Start of processing for Is_Config_Static_String
14307
14308    begin
14309
14310       Name_Len := 0;
14311       return Add_Config_Static_String (Arg);
14312    end Is_Config_Static_String;
14313
14314    -----------------------------------------
14315    -- Is_Non_Significant_Pragma_Reference --
14316    -----------------------------------------
14317
14318    --  This function makes use of the following static table which indicates
14319    --  whether a given pragma is significant.
14320
14321    --  -1  indicates that references in any argument position are significant
14322    --  0   indicates that appearance in any argument is not significant
14323    --  +n  indicates that appearance as argument n is significant, but all
14324    --      other arguments are not significant
14325    --  99  special processing required (e.g. for pragma Check)
14326
14327    Sig_Flags : constant array (Pragma_Id) of Int :=
14328      (Pragma_AST_Entry                     => -1,
14329       Pragma_Abort_Defer                   => -1,
14330       Pragma_Ada_83                        => -1,
14331       Pragma_Ada_95                        => -1,
14332       Pragma_Ada_05                        => -1,
14333       Pragma_Ada_2005                      => -1,
14334       Pragma_Ada_12                        => -1,
14335       Pragma_Ada_2012                      => -1,
14336       Pragma_All_Calls_Remote              => -1,
14337       Pragma_Annotate                      => -1,
14338       Pragma_Assert                        => -1,
14339       Pragma_Assertion_Policy              =>  0,
14340       Pragma_Assume_No_Invalid_Values      =>  0,
14341       Pragma_Asynchronous                  => -1,
14342       Pragma_Atomic                        =>  0,
14343       Pragma_Atomic_Components             =>  0,
14344       Pragma_Attach_Handler                => -1,
14345       Pragma_Check                         => 99,
14346       Pragma_Check_Name                    =>  0,
14347       Pragma_Check_Policy                  =>  0,
14348       Pragma_CIL_Constructor               => -1,
14349       Pragma_CPP_Class                     =>  0,
14350       Pragma_CPP_Constructor               =>  0,
14351       Pragma_CPP_Virtual                   =>  0,
14352       Pragma_CPP_Vtable                    =>  0,
14353       Pragma_CPU                           => -1,
14354       Pragma_C_Pass_By_Copy                =>  0,
14355       Pragma_Comment                       =>  0,
14356       Pragma_Common_Object                 => -1,
14357       Pragma_Compile_Time_Error            => -1,
14358       Pragma_Compile_Time_Warning          => -1,
14359       Pragma_Compiler_Unit                 =>  0,
14360       Pragma_Complete_Representation       =>  0,
14361       Pragma_Complex_Representation        =>  0,
14362       Pragma_Component_Alignment           => -1,
14363       Pragma_Controlled                    =>  0,
14364       Pragma_Convention                    =>  0,
14365       Pragma_Convention_Identifier         =>  0,
14366       Pragma_Debug                         => -1,
14367       Pragma_Debug_Policy                  =>  0,
14368       Pragma_Detect_Blocking               => -1,
14369       Pragma_Default_Storage_Pool          => -1,
14370       Pragma_Dimension                     => -1,
14371       Pragma_Discard_Names                 =>  0,
14372       Pragma_Elaborate                     => -1,
14373       Pragma_Elaborate_All                 => -1,
14374       Pragma_Elaborate_Body                => -1,
14375       Pragma_Elaboration_Checks            => -1,
14376       Pragma_Eliminate                     => -1,
14377       Pragma_Export                        => -1,
14378       Pragma_Export_Exception              => -1,
14379       Pragma_Export_Function               => -1,
14380       Pragma_Export_Object                 => -1,
14381       Pragma_Export_Procedure              => -1,
14382       Pragma_Export_Value                  => -1,
14383       Pragma_Export_Valued_Procedure       => -1,
14384       Pragma_Extend_System                 => -1,
14385       Pragma_Extensions_Allowed            => -1,
14386       Pragma_External                      => -1,
14387       Pragma_Favor_Top_Level               => -1,
14388       Pragma_External_Name_Casing          => -1,
14389       Pragma_Fast_Math                     => -1,
14390       Pragma_Finalize_Storage_Only         =>  0,
14391       Pragma_Float_Representation          =>  0,
14392       Pragma_Ident                         => -1,
14393       Pragma_Implemented                   => -1,
14394       Pragma_Implicit_Packing              =>  0,
14395       Pragma_Import                        => +2,
14396       Pragma_Import_Exception              =>  0,
14397       Pragma_Import_Function               =>  0,
14398       Pragma_Import_Object                 =>  0,
14399       Pragma_Import_Procedure              =>  0,
14400       Pragma_Import_Valued_Procedure       =>  0,
14401       Pragma_Independent                   =>  0,
14402       Pragma_Independent_Components        =>  0,
14403       Pragma_Initialize_Scalars            => -1,
14404       Pragma_Inline                        =>  0,
14405       Pragma_Inline_Always                 =>  0,
14406       Pragma_Inline_Generic                =>  0,
14407       Pragma_Inspection_Point              => -1,
14408       Pragma_Interface                     => +2,
14409       Pragma_Interface_Name                => +2,
14410       Pragma_Interrupt_Handler             => -1,
14411       Pragma_Interrupt_Priority            => -1,
14412       Pragma_Interrupt_State               => -1,
14413       Pragma_Invariant                     => -1,
14414       Pragma_Java_Constructor              => -1,
14415       Pragma_Java_Interface                => -1,
14416       Pragma_Keep_Names                    =>  0,
14417       Pragma_License                       => -1,
14418       Pragma_Link_With                     => -1,
14419       Pragma_Linker_Alias                  => -1,
14420       Pragma_Linker_Constructor            => -1,
14421       Pragma_Linker_Destructor             => -1,
14422       Pragma_Linker_Options                => -1,
14423       Pragma_Linker_Section                => -1,
14424       Pragma_List                          => -1,
14425       Pragma_Locking_Policy                => -1,
14426       Pragma_Long_Float                    => -1,
14427       Pragma_Machine_Attribute             => -1,
14428       Pragma_Main                          => -1,
14429       Pragma_Main_Storage                  => -1,
14430       Pragma_Memory_Size                   => -1,
14431       Pragma_No_Return                     =>  0,
14432       Pragma_No_Body                       =>  0,
14433       Pragma_No_Run_Time                   => -1,
14434       Pragma_No_Strict_Aliasing            => -1,
14435       Pragma_Normalize_Scalars             => -1,
14436       Pragma_Obsolescent                   =>  0,
14437       Pragma_Optimize                      => -1,
14438       Pragma_Optimize_Alignment            => -1,
14439       Pragma_Ordered                       =>  0,
14440       Pragma_Pack                          =>  0,
14441       Pragma_Page                          => -1,
14442       Pragma_Passive                       => -1,
14443       Pragma_Preelaborable_Initialization  => -1,
14444       Pragma_Polling                       => -1,
14445       Pragma_Persistent_BSS                =>  0,
14446       Pragma_Postcondition                 => -1,
14447       Pragma_Precondition                  => -1,
14448       Pragma_Predicate                     => -1,
14449       Pragma_Preelaborate                  => -1,
14450       Pragma_Preelaborate_05               => -1,
14451       Pragma_Priority                      => -1,
14452       Pragma_Priority_Specific_Dispatching => -1,
14453       Pragma_Profile                       =>  0,
14454       Pragma_Profile_Warnings              =>  0,
14455       Pragma_Propagate_Exceptions          => -1,
14456       Pragma_Psect_Object                  => -1,
14457       Pragma_Pure                          => -1,
14458       Pragma_Pure_05                       => -1,
14459       Pragma_Pure_Function                 => -1,
14460       Pragma_Queuing_Policy                => -1,
14461       Pragma_Ravenscar                     => -1,
14462       Pragma_Relative_Deadline             => -1,
14463       Pragma_Remote_Call_Interface         => -1,
14464       Pragma_Remote_Types                  => -1,
14465       Pragma_Restricted_Run_Time           => -1,
14466       Pragma_Restriction_Warnings          => -1,
14467       Pragma_Restrictions                  => -1,
14468       Pragma_Reviewable                    => -1,
14469       Pragma_Short_Circuit_And_Or          => -1,
14470       Pragma_Share_Generic                 => -1,
14471       Pragma_Shared                        => -1,
14472       Pragma_Shared_Passive                => -1,
14473       Pragma_Short_Descriptors             =>  0,
14474       Pragma_Source_File_Name              => -1,
14475       Pragma_Source_File_Name_Project      => -1,
14476       Pragma_Source_Reference              => -1,
14477       Pragma_Storage_Size                  => -1,
14478       Pragma_Storage_Unit                  => -1,
14479       Pragma_Static_Elaboration_Desired    => -1,
14480       Pragma_Stream_Convert                => -1,
14481       Pragma_Style_Checks                  => -1,
14482       Pragma_Subtitle                      => -1,
14483       Pragma_Suppress                      =>  0,
14484       Pragma_Suppress_Exception_Locations  =>  0,
14485       Pragma_Suppress_All                  => -1,
14486       Pragma_Suppress_Debug_Info           =>  0,
14487       Pragma_Suppress_Initialization       =>  0,
14488       Pragma_System_Name                   => -1,
14489       Pragma_Task_Dispatching_Policy       => -1,
14490       Pragma_Task_Info                     => -1,
14491       Pragma_Task_Name                     => -1,
14492       Pragma_Task_Storage                  =>  0,
14493       Pragma_Test_Case                     => -1,
14494       Pragma_Thread_Local_Storage          =>  0,
14495       Pragma_Time_Slice                    => -1,
14496       Pragma_Title                         => -1,
14497       Pragma_Unchecked_Union               =>  0,
14498       Pragma_Unimplemented_Unit            => -1,
14499       Pragma_Universal_Aliasing            => -1,
14500       Pragma_Universal_Data                => -1,
14501       Pragma_Unmodified                    => -1,
14502       Pragma_Unreferenced                  => -1,
14503       Pragma_Unreferenced_Objects          => -1,
14504       Pragma_Unreserve_All_Interrupts      => -1,
14505       Pragma_Unsuppress                    =>  0,
14506       Pragma_Use_VADS_Size                 => -1,
14507       Pragma_Validity_Checks               => -1,
14508       Pragma_Volatile                      =>  0,
14509       Pragma_Volatile_Components           =>  0,
14510       Pragma_Warnings                      => -1,
14511       Pragma_Weak_External                 => -1,
14512       Pragma_Wide_Character_Encoding       =>  0,
14513       Unknown_Pragma                       =>  0);
14514
14515    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14516       Id : Pragma_Id;
14517       P  : Node_Id;
14518       C  : Int;
14519       A  : Node_Id;
14520
14521    begin
14522       P := Parent (N);
14523
14524       if Nkind (P) /= N_Pragma_Argument_Association then
14525          return False;
14526
14527       else
14528          Id := Get_Pragma_Id (Parent (P));
14529          C := Sig_Flags (Id);
14530
14531          case C is
14532             when -1 =>
14533                return False;
14534
14535             when 0 =>
14536                return True;
14537
14538             when 99 =>
14539                case Id is
14540
14541                   --  For pragma Check, the first argument is not significant,
14542                   --  the second and the third (if present) arguments are
14543                   --  significant.
14544
14545                   when Pragma_Check =>
14546                      return
14547                        P = First (Pragma_Argument_Associations (Parent (P)));
14548
14549                   when others =>
14550                      raise Program_Error;
14551                end case;
14552
14553             when others =>
14554                A := First (Pragma_Argument_Associations (Parent (P)));
14555                for J in 1 .. C - 1 loop
14556                   if No (A) then
14557                      return False;
14558                   end if;
14559
14560                   Next (A);
14561                end loop;
14562
14563                return A = P; -- is this wrong way round ???
14564          end case;
14565       end if;
14566    end Is_Non_Significant_Pragma_Reference;
14567
14568    ------------------------------
14569    -- Is_Pragma_String_Literal --
14570    ------------------------------
14571
14572    --  This function returns true if the corresponding pragma argument is a
14573    --  static string expression. These are the only cases in which string
14574    --  literals can appear as pragma arguments. We also allow a string literal
14575    --  as the first argument to pragma Assert (although it will of course
14576    --  always generate a type error).
14577
14578    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14579       Pragn : constant Node_Id := Parent (Par);
14580       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14581       Pname : constant Name_Id := Pragma_Name (Pragn);
14582       Argn  : Natural;
14583       N     : Node_Id;
14584
14585    begin
14586       Argn := 1;
14587       N := First (Assoc);
14588       loop
14589          exit when N = Par;
14590          Argn := Argn + 1;
14591          Next (N);
14592       end loop;
14593
14594       if Pname = Name_Assert then
14595          return True;
14596
14597       elsif Pname = Name_Export then
14598          return Argn > 2;
14599
14600       elsif Pname = Name_Ident then
14601          return Argn = 1;
14602
14603       elsif Pname = Name_Import then
14604          return Argn > 2;
14605
14606       elsif Pname = Name_Interface_Name then
14607          return Argn > 1;
14608
14609       elsif Pname = Name_Linker_Alias then
14610          return Argn = 2;
14611
14612       elsif Pname = Name_Linker_Section then
14613          return Argn = 2;
14614
14615       elsif Pname = Name_Machine_Attribute then
14616          return Argn = 2;
14617
14618       elsif Pname = Name_Source_File_Name then
14619          return True;
14620
14621       elsif Pname = Name_Source_Reference then
14622          return Argn = 2;
14623
14624       elsif Pname = Name_Title then
14625          return True;
14626
14627       elsif Pname = Name_Subtitle then
14628          return True;
14629
14630       else
14631          return False;
14632       end if;
14633    end Is_Pragma_String_Literal;
14634
14635    ------------------------
14636    -- Preanalyze_TC_Args --
14637    ------------------------
14638
14639    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14640    begin
14641       --  Preanalyze the boolean expressions, we treat these as spec
14642       --  expressions (i.e. similar to a default expression).
14643
14644       if Present (Arg_Req) then
14645          Preanalyze_Spec_Expression
14646            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14647       end if;
14648
14649       if Present (Arg_Ens) then
14650          Preanalyze_Spec_Expression
14651            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14652       end if;
14653    end Preanalyze_TC_Args;
14654
14655    --------------------------------------
14656    -- Process_Compilation_Unit_Pragmas --
14657    --------------------------------------
14658
14659    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14660    begin
14661       --  A special check for pragma Suppress_All, a very strange DEC pragma,
14662       --  strange because it comes at the end of the unit. Rational has the
14663       --  same name for a pragma, but treats it as a program unit pragma, In
14664       --  GNAT we just decide to allow it anywhere at all. If it appeared then
14665       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
14666       --  node, and we insert a pragma Suppress (All_Checks) at the start of
14667       --  the context clause to ensure the correct processing.
14668
14669       if Has_Pragma_Suppress_All (N) then
14670          Prepend_To (Context_Items (N),
14671            Make_Pragma (Sloc (N),
14672              Chars                        => Name_Suppress,
14673              Pragma_Argument_Associations => New_List (
14674                Make_Pragma_Argument_Association (Sloc (N),
14675                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14676       end if;
14677
14678       --  Nothing else to do at the current time!
14679
14680    end Process_Compilation_Unit_Pragmas;
14681
14682    --------
14683    -- rv --
14684    --------
14685
14686    procedure rv is
14687    begin
14688       null;
14689    end rv;
14690
14691    --------------------------------
14692    -- Set_Encoded_Interface_Name --
14693    --------------------------------
14694
14695    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14696       Str : constant String_Id := Strval (S);
14697       Len : constant Int       := String_Length (Str);
14698       CC  : Char_Code;
14699       C   : Character;
14700       J   : Int;
14701
14702       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14703
14704       procedure Encode;
14705       --  Stores encoded value of character code CC. The encoding we use an
14706       --  underscore followed by four lower case hex digits.
14707
14708       ------------
14709       -- Encode --
14710       ------------
14711
14712       procedure Encode is
14713       begin
14714          Store_String_Char (Get_Char_Code ('_'));
14715          Store_String_Char
14716            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14717          Store_String_Char
14718            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14719          Store_String_Char
14720            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14721          Store_String_Char
14722            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14723       end Encode;
14724
14725    --  Start of processing for Set_Encoded_Interface_Name
14726
14727    begin
14728       --  If first character is asterisk, this is a link name, and we leave it
14729       --  completely unmodified. We also ignore null strings (the latter case
14730       --  happens only in error cases) and no encoding should occur for Java or
14731       --  AAMP interface names.
14732
14733       if Len = 0
14734         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14735         or else VM_Target /= No_VM
14736         or else AAMP_On_Target
14737       then
14738          Set_Interface_Name (E, S);
14739
14740       else
14741          J := 1;
14742          loop
14743             CC := Get_String_Char (Str, J);
14744
14745             exit when not In_Character_Range (CC);
14746
14747             C := Get_Character (CC);
14748
14749             exit when C /= '_' and then C /= '$'
14750               and then C not in '0' .. '9'
14751               and then C not in 'a' .. 'z'
14752               and then C not in 'A' .. 'Z';
14753
14754             if J = Len then
14755                Set_Interface_Name (E, S);
14756                return;
14757
14758             else
14759                J := J + 1;
14760             end if;
14761          end loop;
14762
14763          --  Here we need to encode. The encoding we use as follows:
14764          --     three underscores  + four hex digits (lower case)
14765
14766          Start_String;
14767
14768          for J in 1 .. String_Length (Str) loop
14769             CC := Get_String_Char (Str, J);
14770
14771             if not In_Character_Range (CC) then
14772                Encode;
14773             else
14774                C := Get_Character (CC);
14775
14776                if C = '_' or else C = '$'
14777                  or else C in '0' .. '9'
14778                  or else C in 'a' .. 'z'
14779                  or else C in 'A' .. 'Z'
14780                then
14781                   Store_String_Char (CC);
14782                else
14783                   Encode;
14784                end if;
14785             end if;
14786          end loop;
14787
14788          Set_Interface_Name (E,
14789            Make_String_Literal (Sloc (S),
14790              Strval => End_String));
14791       end if;
14792    end Set_Encoded_Interface_Name;
14793
14794    -------------------
14795    -- Set_Unit_Name --
14796    -------------------
14797
14798    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14799       Pref : Node_Id;
14800       Scop : Entity_Id;
14801
14802    begin
14803       if Nkind (N) = N_Identifier
14804         and then Nkind (With_Item) = N_Identifier
14805       then
14806          Set_Entity (N, Entity (With_Item));
14807
14808       elsif Nkind (N) = N_Selected_Component then
14809          Change_Selected_Component_To_Expanded_Name (N);
14810          Set_Entity (N, Entity (With_Item));
14811          Set_Entity (Selector_Name (N), Entity (N));
14812
14813          Pref := Prefix (N);
14814          Scop := Scope (Entity (N));
14815          while Nkind (Pref) = N_Selected_Component loop
14816             Change_Selected_Component_To_Expanded_Name (Pref);
14817             Set_Entity (Selector_Name (Pref), Scop);
14818             Set_Entity (Pref, Scop);
14819             Pref := Prefix (Pref);
14820             Scop := Scope (Scop);
14821          end loop;
14822
14823          Set_Entity (Pref, Scop);
14824       end if;
14825    end Set_Unit_Name;
14826
14827 end Sem_Prag;