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