OSDN Git Service

2011-08-31 Tristan Gingold <gingold@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_prag.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             S E M _ P R A G                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
20 --                                                                          --
21 -- GNAT was originally developed  by the GNAT team at  New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 --  This unit contains the semantic processing for all pragmas, both language
27 --  and implementation defined. For most pragmas, the parser only does the
28 --  most basic job of checking the syntax, so Sem_Prag also contains the code
29 --  to complete the syntax checks. Certain pragmas are handled partially or
30 --  completely by the parser (see Par.Prag for further details).
31
32 with Atree;    use Atree;
33 with Casing;   use Casing;
34 with Checks;   use Checks;
35 with Csets;    use Csets;
36 with Debug;    use Debug;
37 with Einfo;    use Einfo;
38 with Elists;   use Elists;
39 with Errout;   use Errout;
40 with Exp_Dist; use Exp_Dist;
41 with Exp_Util; use Exp_Util;
42 with Lib;      use Lib;
43 with Lib.Writ; use Lib.Writ;
44 with Lib.Xref; use Lib.Xref;
45 with Namet.Sp; use Namet.Sp;
46 with Nlists;   use Nlists;
47 with Nmake;    use Nmake;
48 with Opt;      use Opt;
49 with Output;   use Output;
50 with Par_SCO;  use Par_SCO;
51 with Restrict; use Restrict;
52 with Rident;   use Rident;
53 with Rtsfind;  use Rtsfind;
54 with Sem;      use Sem;
55 with Sem_Aux;  use Sem_Aux;
56 with Sem_Ch3;  use Sem_Ch3;
57 with Sem_Ch6;  use Sem_Ch6;
58 with Sem_Ch8;  use Sem_Ch8;
59 with Sem_Ch12; use Sem_Ch12;
60 with Sem_Ch13; use Sem_Ch13;
61 with Sem_Disp; use Sem_Disp;
62 with Sem_Dist; use Sem_Dist;
63 with Sem_Elim; use Sem_Elim;
64 with Sem_Eval; use Sem_Eval;
65 with Sem_Intr; use Sem_Intr;
66 with Sem_Mech; use Sem_Mech;
67 with Sem_Res;  use Sem_Res;
68 with Sem_Type; use Sem_Type;
69 with Sem_Util; use Sem_Util;
70 with Sem_VFpt; use Sem_VFpt;
71 with Sem_Warn; use Sem_Warn;
72 with Stand;    use Stand;
73 with Sinfo;    use Sinfo;
74 with Sinfo.CN; use Sinfo.CN;
75 with Sinput;   use Sinput;
76 with Snames;   use Snames;
77 with Stringt;  use Stringt;
78 with Stylesw;  use Stylesw;
79 with Table;
80 with Targparm; use Targparm;
81 with Tbuild;   use Tbuild;
82 with Ttypes;
83 with Uintp;    use Uintp;
84 with Uname;    use Uname;
85 with Urealp;   use Urealp;
86 with Validsw;  use Validsw;
87 with Warnsw;   use Warnsw;
88
89 package body Sem_Prag is
90
91    ----------------------------------------------
92    -- Common Handling of Import-Export Pragmas --
93    ----------------------------------------------
94
95    --  In the following section, a number of Import_xxx and Export_xxx pragmas
96    --  are defined by GNAT. These are compatible with the DEC pragmas of the
97    --  same name, and all have the following common form and processing:
98
99    --  pragma Export_xxx
100    --        [Internal                 =>] LOCAL_NAME
101    --     [, [External                 =>] EXTERNAL_SYMBOL]
102    --     [, other optional parameters   ]);
103
104    --  pragma Import_xxx
105    --        [Internal                 =>] LOCAL_NAME
106    --     [, [External                 =>] EXTERNAL_SYMBOL]
107    --     [, other optional parameters   ]);
108
109    --   EXTERNAL_SYMBOL ::=
110    --     IDENTIFIER
111    --   | static_string_EXPRESSION
112
113    --  The internal LOCAL_NAME designates the entity that is imported or
114    --  exported, and must refer to an entity in the current declarative
115    --  part (as required by the rules for LOCAL_NAME).
116
117    --  The external linker name is designated by the External parameter if
118    --  given, or the Internal parameter if not (if there is no External
119    --  parameter, the External parameter is a copy of the Internal name).
120
121    --  If the External parameter is given as a string, then this string is
122    --  treated as an external name (exactly as though it had been given as an
123    --  External_Name parameter for a normal Import pragma).
124
125    --  If the External parameter is given as an identifier (or there is no
126    --  External parameter, so that the Internal identifier is used), then
127    --  the external name is the characters of the identifier, translated
128    --  to all upper case letters for OpenVMS versions of GNAT, and to all
129    --  lower case letters for all other versions
130
131    --  Note: the external name specified or implied by any of these special
132    --  Import_xxx or Export_xxx pragmas override an external or link name
133    --  specified in a previous Import or Export pragma.
134
135    --  Note: these and all other DEC-compatible GNAT pragmas allow full use of
136    --  named notation, following the standard rules for subprogram calls, i.e.
137    --  parameters can be given in any order if named notation is used, and
138    --  positional and named notation can be mixed, subject to the rule that all
139    --  positional parameters must appear first.
140
141    --  Note: All these pragmas are implemented exactly following the DEC design
142    --  and implementation and are intended to be fully compatible with the use
143    --  of these pragmas in the DEC Ada compiler.
144
145    --------------------------------------------
146    -- Checking for Duplicated External Names --
147    --------------------------------------------
148
149    --  It is suspicious if two separate Export pragmas use the same external
150    --  name. The following table is used to diagnose this situation so that
151    --  an appropriate warning can be issued.
152
153    --  The Node_Id stored is for the N_String_Literal node created to hold
154    --  the value of the external name. The Sloc of this node is used to
155    --  cross-reference the location of the duplication.
156
157    package Externals is new Table.Table (
158      Table_Component_Type => Node_Id,
159      Table_Index_Type     => Int,
160      Table_Low_Bound      => 0,
161      Table_Initial        => 100,
162      Table_Increment      => 100,
163      Table_Name           => "Name_Externals");
164
165    -------------------------------------
166    -- Local Subprograms and Variables --
167    -------------------------------------
168
169    function Adjust_External_Name_Case (N : Node_Id) return Node_Id;
170    --  This routine is used for possible casing adjustment of an explicit
171    --  external name supplied as a string literal (the node N), according to
172    --  the casing requirement of Opt.External_Name_Casing. If this is set to
173    --  As_Is, then the string literal is returned unchanged, but if it is set
174    --  to Uppercase or Lowercase, then a new string literal with appropriate
175    --  casing is constructed.
176
177    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id;
178    --  If Def_Id refers to a renamed subprogram, then the base subprogram (the
179    --  original one, following the renaming chain) is returned. Otherwise the
180    --  entity is returned unchanged. Should be in Einfo???
181
182    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id);
183    --  Preanalyze the boolean expressions in the Requires and Ensures arguments
184    --  of a Test_Case pragma if present (possibly Empty). We treat these as
185    --  spec expressions (i.e. similar to a default expression).
186
187    procedure rv;
188    --  This is a dummy function called by the processing for pragma Reviewable.
189    --  It is there for assisting front end debugging. By placing a Reviewable
190    --  pragma in the source program, a breakpoint on rv catches this place in
191    --  the source, allowing convenient stepping to the point of interest.
192
193    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id);
194    --  Place semantic information on the argument of an Elaborate/Elaborate_All
195    --  pragma. Entity name for unit and its parents is taken from item in
196    --  previous with_clause that mentions the unit.
197
198    -------------------------------
199    -- Adjust_External_Name_Case --
200    -------------------------------
201
202    function Adjust_External_Name_Case (N : Node_Id) return Node_Id is
203       CC : Char_Code;
204
205    begin
206       --  Adjust case of literal if required
207
208       if Opt.External_Name_Exp_Casing = As_Is then
209          return N;
210
211       else
212          --  Copy existing string
213
214          Start_String;
215
216          --  Set proper casing
217
218          for J in 1 .. String_Length (Strval (N)) loop
219             CC := Get_String_Char (Strval (N), J);
220
221             if Opt.External_Name_Exp_Casing = Uppercase
222               and then CC >= Get_Char_Code ('a')
223               and then CC <= Get_Char_Code ('z')
224             then
225                Store_String_Char (CC - 32);
226
227             elsif Opt.External_Name_Exp_Casing = Lowercase
228               and then CC >= Get_Char_Code ('A')
229               and then CC <= Get_Char_Code ('Z')
230             then
231                Store_String_Char (CC + 32);
232
233             else
234                Store_String_Char (CC);
235             end if;
236          end loop;
237
238          return
239            Make_String_Literal (Sloc (N),
240              Strval => End_String);
241       end if;
242    end Adjust_External_Name_Case;
243
244    ------------------------------
245    -- Analyze_PPC_In_Decl_Part --
246    ------------------------------
247
248    procedure Analyze_PPC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
249       Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N));
250
251    begin
252       --  Install formals and push subprogram spec onto scope stack so that we
253       --  can see the formals from the pragma.
254
255       Install_Formals (S);
256       Push_Scope (S);
257
258       --  Preanalyze the boolean expression, we treat this as a spec expression
259       --  (i.e. similar to a default expression).
260
261       Preanalyze_Spec_Expression
262         (Get_Pragma_Arg (Arg1), Standard_Boolean);
263
264       --  Remove the subprogram from the scope stack now that the pre-analysis
265       --  of the precondition/postcondition is done.
266
267       End_Scope;
268    end Analyze_PPC_In_Decl_Part;
269
270    --------------------
271    -- Analyze_Pragma --
272    --------------------
273
274    procedure Analyze_Pragma (N : Node_Id) is
275       Loc     : constant Source_Ptr := Sloc (N);
276       Pname   : constant Name_Id    := Pragma_Name (N);
277       Prag_Id : Pragma_Id;
278
279       Pragma_Exit : exception;
280       --  This exception is used to exit pragma processing completely. It is
281       --  used when an error is detected, and no further processing is
282       --  required. It is also used if an earlier error has left the tree in
283       --  a state where the pragma should not be processed.
284
285       Arg_Count : Nat;
286       --  Number of pragma argument associations
287
288       Arg1 : Node_Id;
289       Arg2 : Node_Id;
290       Arg3 : Node_Id;
291       Arg4 : Node_Id;
292       --  First four pragma arguments (pragma argument association nodes, or
293       --  Empty if the corresponding argument does not exist).
294
295       type Name_List is array (Natural range <>) of Name_Id;
296       type Args_List is array (Natural range <>) of Node_Id;
297       --  Types used for arguments to Check_Arg_Order and Gather_Associations
298
299       procedure Ada_2005_Pragma;
300       --  Called for pragmas defined in Ada 2005, that are not in Ada 95. In
301       --  Ada 95 mode, these are implementation defined pragmas, so should be
302       --  caught by the No_Implementation_Pragmas restriction.
303
304       procedure Ada_2012_Pragma;
305       --  Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
306       --  In Ada 95 or 05 mode, these are implementation defined pragmas, so
307       --  should be caught by the No_Implementation_Pragmas restriction.
308
309       procedure Check_Ada_83_Warning;
310       --  Issues a warning message for the current pragma if operating in Ada
311       --  83 mode (used for language pragmas that are not a standard part of
312       --  Ada 83). This procedure does not raise Error_Pragma. Also notes use
313       --  of 95 pragma.
314
315       procedure Check_Arg_Count (Required : Nat);
316       --  Check argument count for pragma is equal to given parameter. If not,
317       --  then issue an error message and raise Pragma_Exit.
318
319       --  Note: all routines whose name is Check_Arg_Is_xxx take an argument
320       --  Arg which can either be a pragma argument association, in which case
321       --  the check is applied to the expression of the association or an
322       --  expression directly.
323
324       procedure Check_Arg_Is_External_Name (Arg : Node_Id);
325       --  Check that an argument has the right form for an EXTERNAL_NAME
326       --  parameter of an extended import/export pragma. The rule is that the
327       --  name must be an identifier or string literal (in Ada 83 mode) or a
328       --  static string expression (in Ada 95 mode).
329
330       procedure Check_Arg_Is_Identifier (Arg : Node_Id);
331       --  Check the specified argument Arg to make sure that it is an
332       --  identifier. If not give error and raise Pragma_Exit.
333
334       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id);
335       --  Check the specified argument Arg to make sure that it is an integer
336       --  literal. If not give error and raise Pragma_Exit.
337
338       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id);
339       --  Check the specified argument Arg to make sure that it has the proper
340       --  syntactic form for a local name and meets the semantic requirements
341       --  for a local name. The local name is analyzed as part of the
342       --  processing for this call. In addition, the local name is required
343       --  to represent an entity at the library level.
344
345       procedure Check_Arg_Is_Local_Name (Arg : Node_Id);
346       --  Check the specified argument Arg to make sure that it has the proper
347       --  syntactic form for a local name and meets the semantic requirements
348       --  for a local name. The local name is analyzed as part of the
349       --  processing for this call.
350
351       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id);
352       --  Check the specified argument Arg to make sure that it is a valid
353       --  locking policy name. If not give error and raise Pragma_Exit.
354
355       procedure Check_Arg_Is_One_Of
356         (Arg                : Node_Id;
357          N1, N2             : Name_Id);
358       procedure Check_Arg_Is_One_Of
359         (Arg                : Node_Id;
360          N1, N2, N3         : Name_Id);
361       procedure Check_Arg_Is_One_Of
362         (Arg                : Node_Id;
363          N1, N2, N3, N4, N5 : Name_Id);
364       --  Check the specified argument Arg to make sure that it is an
365       --  identifier whose name matches either N1 or N2 (or N3, N4, N5 if
366       --  present). If not then give error and raise Pragma_Exit.
367
368       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id);
369       --  Check the specified argument Arg to make sure that it is a valid
370       --  queuing policy name. If not give error and raise Pragma_Exit.
371
372       procedure Check_Arg_Is_Static_Expression
373         (Arg : Node_Id;
374          Typ : Entity_Id := Empty);
375       --  Check the specified argument Arg to make sure that it is a static
376       --  expression of the given type (i.e. it will be analyzed and resolved
377       --  using this type, which can be any valid argument to Resolve, e.g.
378       --  Any_Integer is OK). If not, given error and raise Pragma_Exit. If
379       --  Typ is left Empty, then any static expression is allowed.
380
381       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id);
382       --  Check the specified argument Arg to make sure that it is a valid task
383       --  dispatching policy name. If not give error and raise Pragma_Exit.
384
385       procedure Check_Arg_Order (Names : Name_List);
386       --  Checks for an instance of two arguments with identifiers for the
387       --  current pragma which are not in the sequence indicated by Names,
388       --  and if so, generates a fatal message about bad order of arguments.
389
390       procedure Check_At_Least_N_Arguments (N : Nat);
391       --  Check there are at least N arguments present
392
393       procedure Check_At_Most_N_Arguments (N : Nat);
394       --  Check there are no more than N arguments present
395
396       procedure Check_Component
397         (Comp            : Node_Id;
398          UU_Typ          : Entity_Id;
399          In_Variant_Part : Boolean := False);
400       --  Examine an Unchecked_Union component for correct use of per-object
401       --  constrained subtypes, and for restrictions on finalizable components.
402       --  UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
403       --  should be set when Comp comes from a record variant.
404
405       procedure Check_Duplicate_Pragma (E : Entity_Id);
406       --  Check if a pragma of the same name as the current pragma is already
407       --  chained as a rep pragma to the given entity. If so give a message
408       --  about the duplicate, and then raise Pragma_Exit so does not return.
409       --  Also checks for delayed aspect specification node in the chain.
410
411       procedure Check_Duplicated_Export_Name (Nam : Node_Id);
412       --  Nam is an N_String_Literal node containing the external name set by
413       --  an Import or Export pragma (or extended Import or Export pragma).
414       --  This procedure checks for possible duplications if this is the export
415       --  case, and if found, issues an appropriate error message.
416
417       procedure Check_First_Subtype (Arg : Node_Id);
418       --  Checks that Arg, whose expression is an entity name, references a
419       --  first subtype.
420
421       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id);
422       --  Checks that the given argument has an identifier, and if so, requires
423       --  it to match the given identifier name. If there is no identifier, or
424       --  a non-matching identifier, then an error message is given and
425       --  Pragma_Exit is raised.
426
427       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id);
428       --  Checks that the given argument has an identifier, and if so, requires
429       --  it to match one of the given identifier names. If there is no
430       --  identifier, or a non-matching identifier, then an error message is
431       --  given and Pragma_Exit is raised.
432
433       procedure Check_In_Main_Program;
434       --  Common checks for pragmas that appear within a main program
435       --  (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
436
437       procedure Check_Interrupt_Or_Attach_Handler;
438       --  Common processing for first argument of pragma Interrupt_Handler or
439       --  pragma Attach_Handler.
440
441       procedure Check_Is_In_Decl_Part_Or_Package_Spec;
442       --  Check that pragma appears in a declarative part, or in a package
443       --  specification, i.e. that it does not occur in a statement sequence
444       --  in a body.
445
446       procedure Check_No_Identifier (Arg : Node_Id);
447       --  Checks that the given argument does not have an identifier. If
448       --  an identifier is present, then an error message is issued, and
449       --  Pragma_Exit is raised.
450
451       procedure Check_No_Identifiers;
452       --  Checks that none of the arguments to the pragma has an identifier.
453       --  If any argument has an identifier, then an error message is issued,
454       --  and Pragma_Exit is raised.
455
456       procedure Check_No_Link_Name;
457       --  Checks that no link name is specified
458
459       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id);
460       --  Checks if the given argument has an identifier, and if so, requires
461       --  it to match the given identifier name. If there is a non-matching
462       --  identifier, then an error message is given and Pragma_Exit is raised.
463
464       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String);
465       --  Checks if the given argument has an identifier, and if so, requires
466       --  it to match the given identifier name. If there is a non-matching
467       --  identifier, then an error message is given and Pragma_Exit is raised.
468       --  In this version of the procedure, the identifier name is given as
469       --  a string with lower case letters.
470
471       procedure Check_Precondition_Postcondition (In_Body : out Boolean);
472       --  Called to process a precondition or postcondition pragma. There are
473       --  three cases:
474       --
475       --    The pragma appears after a subprogram spec
476       --
477       --      If the corresponding check is not enabled, the pragma is analyzed
478       --      but otherwise ignored and control returns with In_Body set False.
479       --
480       --      If the check is enabled, then the first step is to analyze the
481       --      pragma, but this is skipped if the subprogram spec appears within
482       --      a package specification (because this is the case where we delay
483       --      analysis till the end of the spec). Then (whether or not it was
484       --      analyzed), the pragma is chained to the subprogram in question
485       --      (using Spec_PPC_List and Next_Pragma) and control returns to the
486       --      caller with In_Body set False.
487       --
488       --    The pragma appears at the start of subprogram body declarations
489       --
490       --      In this case an immediate return to the caller is made with
491       --      In_Body set True, and the pragma is NOT analyzed.
492       --
493       --    In all other cases, an error message for bad placement is given
494
495       procedure Check_Static_Constraint (Constr : Node_Id);
496       --  Constr is a constraint from an N_Subtype_Indication node from a
497       --  component constraint in an Unchecked_Union type. This routine checks
498       --  that the constraint is static as required by the restrictions for
499       --  Unchecked_Union.
500
501       procedure Check_Test_Case;
502       --  Called to process a test-case pragma. The treatment is similar to the
503       --  one for pre- and postcondition in Check_Precondition_Postcondition,
504       --  except the placement rules for the test-case pragma are stricter.
505       --  This pragma may only occur after a subprogram spec declared directly
506       --  in a package spec unit. In this case, the pragma is chained to the
507       --  subprogram in question (using Spec_TC_List and Next_Pragma) and
508       --  analysis of the pragma is delayed till the end of the spec. In
509       --  all other cases, an error message for bad placement is given.
510
511       procedure Check_Valid_Configuration_Pragma;
512       --  Legality checks for placement of a configuration pragma
513
514       procedure Check_Valid_Library_Unit_Pragma;
515       --  Legality checks for library unit pragmas. A special case arises for
516       --  pragmas in generic instances that come from copies of the original
517       --  library unit pragmas in the generic templates. In the case of other
518       --  than library level instantiations these can appear in contexts which
519       --  would normally be invalid (they only apply to the original template
520       --  and to library level instantiations), and they are simply ignored,
521       --  which is implemented by rewriting them as null statements.
522
523       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id);
524       --  Check an Unchecked_Union variant for lack of nested variants and
525       --  presence of at least one component. UU_Typ is the related Unchecked_
526       --  Union type.
527
528       procedure Error_Pragma (Msg : String);
529       pragma No_Return (Error_Pragma);
530       --  Outputs error message for current pragma. The message contains a %
531       --  that will be replaced with the pragma name, and the flag is placed
532       --  on the pragma itself. Pragma_Exit is then raised.
533
534       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id);
535       pragma No_Return (Error_Pragma_Arg);
536       --  Outputs error message for current pragma. The message may contain
537       --  a % that will be replaced with the pragma name. The parameter Arg
538       --  may either be a pragma argument association, in which case the flag
539       --  is placed on the expression of this association, or an expression,
540       --  in which case the flag is placed directly on the expression. The
541       --  message is placed using Error_Msg_N, so the message may also contain
542       --  an & insertion character which will reference the given Arg value.
543       --  After placing the message, Pragma_Exit is raised.
544
545       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id);
546       pragma No_Return (Error_Pragma_Arg);
547       --  Similar to above form of Error_Pragma_Arg except that two messages
548       --  are provided, the second is a continuation comment starting with \.
549
550       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id);
551       pragma No_Return (Error_Pragma_Arg_Ident);
552       --  Outputs error message for current pragma. The message may contain
553       --  a % that will be replaced with the pragma name. The parameter Arg
554       --  must be a pragma argument association with a non-empty identifier
555       --  (i.e. its Chars field must be set), and the error message is placed
556       --  on the identifier. The message is placed using Error_Msg_N so
557       --  the message may also contain an & insertion character which will
558       --  reference the identifier. After placing the message, Pragma_Exit
559       --  is raised.
560
561       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id);
562       pragma No_Return (Error_Pragma_Ref);
563       --  Outputs error message for current pragma. The message may contain
564       --  a % that will be replaced with the pragma name. The parameter Ref
565       --  must be an entity whose name can be referenced by & and sloc by #.
566       --  After placing the message, Pragma_Exit is raised.
567
568       function Find_Lib_Unit_Name return Entity_Id;
569       --  Used for a library unit pragma to find the entity to which the
570       --  library unit pragma applies, returns the entity found.
571
572       procedure Find_Program_Unit_Name (Id : Node_Id);
573       --  If the pragma is a compilation unit pragma, the id must denote the
574       --  compilation unit in the same compilation, and the pragma must appear
575       --  in the list of preceding or trailing pragmas. If it is a program
576       --  unit pragma that is not a compilation unit pragma, then the
577       --  identifier must be visible.
578
579       function Find_Unique_Parameterless_Procedure
580         (Name : Entity_Id;
581          Arg  : Node_Id) return Entity_Id;
582       --  Used for a procedure pragma to find the unique parameterless
583       --  procedure identified by Name, returns it if it exists, otherwise
584       --  errors out and uses Arg as the pragma argument for the message.
585
586       procedure Fix_Error (Msg : in out String);
587       --  This is called prior to issuing an error message. Msg is a string
588       --  which typically contains the substring pragma. If the current pragma
589       --  comes from an aspect, each such "pragma" substring is replaced with
590       --  the characters "aspect", and if Error_Msg_Name_1 is Name_Precondition
591       --  (resp Name_Postcondition) it is changed to Name_Pre (resp Name_Post).
592
593       procedure Gather_Associations
594         (Names : Name_List;
595          Args  : out Args_List);
596       --  This procedure is used to gather the arguments for a pragma that
597       --  permits arbitrary ordering of parameters using the normal rules
598       --  for named and positional parameters. The Names argument is a list
599       --  of Name_Id values that corresponds to the allowed pragma argument
600       --  association identifiers in order. The result returned in Args is
601       --  a list of corresponding expressions that are the pragma arguments.
602       --  Note that this is a list of expressions, not of pragma argument
603       --  associations (Gather_Associations has completely checked all the
604       --  optional identifiers when it returns). An entry in Args is Empty
605       --  on return if the corresponding argument is not present.
606
607       procedure GNAT_Pragma;
608       --  Called for all GNAT defined pragmas to check the relevant restriction
609       --  (No_Implementation_Pragmas).
610
611       function Is_Before_First_Decl
612         (Pragma_Node : Node_Id;
613          Decls       : List_Id) return Boolean;
614       --  Return True if Pragma_Node is before the first declarative item in
615       --  Decls where Decls is the list of declarative items.
616
617       function Is_Configuration_Pragma return Boolean;
618       --  Determines if the placement of the current pragma is appropriate
619       --  for a configuration pragma.
620
621       function Is_In_Context_Clause return Boolean;
622       --  Returns True if pragma appears within the context clause of a unit,
623       --  and False for any other placement (does not generate any messages).
624
625       function Is_Static_String_Expression (Arg : Node_Id) return Boolean;
626       --  Analyzes the argument, and determines if it is a static string
627       --  expression, returns True if so, False if non-static or not String.
628
629       procedure Pragma_Misplaced;
630       pragma No_Return (Pragma_Misplaced);
631       --  Issue fatal error message for misplaced pragma
632
633       procedure Process_Atomic_Shared_Volatile;
634       --  Common processing for pragmas Atomic, Shared, Volatile. Note that
635       --  Shared is an obsolete Ada 83 pragma, treated as being identical
636       --  in effect to pragma Atomic.
637
638       procedure Process_Compile_Time_Warning_Or_Error;
639       --  Common processing for Compile_Time_Error and Compile_Time_Warning
640
641       procedure Process_Convention
642         (C   : out Convention_Id;
643          Ent : out Entity_Id);
644       --  Common processing for Convention, Interface, Import and Export.
645       --  Checks first two arguments of pragma, and sets the appropriate
646       --  convention value in the specified entity or entities. On return
647       --  C is the convention, Ent is the referenced entity.
648
649       procedure Process_Extended_Import_Export_Exception_Pragma
650         (Arg_Internal : Node_Id;
651          Arg_External : Node_Id;
652          Arg_Form     : Node_Id;
653          Arg_Code     : Node_Id);
654       --  Common processing for the pragmas Import/Export_Exception. The three
655       --  arguments correspond to the three named parameters of the pragma. An
656       --  argument is empty if the corresponding parameter is not present in
657       --  the pragma.
658
659       procedure Process_Extended_Import_Export_Object_Pragma
660         (Arg_Internal : Node_Id;
661          Arg_External : Node_Id;
662          Arg_Size     : Node_Id);
663       --  Common processing for the pragmas Import/Export_Object. The three
664       --  arguments correspond to the three named parameters of the pragmas. An
665       --  argument is empty if the corresponding parameter is not present in
666       --  the pragma.
667
668       procedure Process_Extended_Import_Export_Internal_Arg
669         (Arg_Internal : Node_Id := Empty);
670       --  Common processing for all extended Import and Export pragmas. The
671       --  argument is the pragma parameter for the Internal argument. If
672       --  Arg_Internal is empty or inappropriate, an error message is posted.
673       --  Otherwise, on normal return, the Entity_Field of Arg_Internal is
674       --  set to identify the referenced entity.
675
676       procedure Process_Extended_Import_Export_Subprogram_Pragma
677         (Arg_Internal                 : Node_Id;
678          Arg_External                 : Node_Id;
679          Arg_Parameter_Types          : Node_Id;
680          Arg_Result_Type              : Node_Id := Empty;
681          Arg_Mechanism                : Node_Id;
682          Arg_Result_Mechanism         : Node_Id := Empty;
683          Arg_First_Optional_Parameter : Node_Id := Empty);
684       --  Common processing for all extended Import and Export pragmas applying
685       --  to subprograms. The caller omits any arguments that do not apply to
686       --  the pragma in question (for example, Arg_Result_Type can be non-Empty
687       --  only in the Import_Function and Export_Function cases). The argument
688       --  names correspond to the allowed pragma association identifiers.
689
690       procedure Process_Generic_List;
691       --  Common processing for Share_Generic and Inline_Generic
692
693       procedure Process_Import_Or_Interface;
694       --  Common processing for Import of Interface
695
696       procedure Process_Import_Predefined_Type;
697       --  Processing for completing a type with pragma Import. This is used
698       --  to declare types that match predefined C types, especially for cases
699       --  without corresponding Ada predefined type.
700
701       procedure Process_Inline (Active : Boolean);
702       --  Common processing for Inline and Inline_Always. The parameter
703       --  indicates if the inline pragma is active, i.e. if it should actually
704       --  cause inlining to occur.
705
706       procedure Process_Interface_Name
707         (Subprogram_Def : Entity_Id;
708          Ext_Arg        : Node_Id;
709          Link_Arg       : Node_Id);
710       --  Given the last two arguments of pragma Import, pragma Export, or
711       --  pragma Interface_Name, performs validity checks and sets the
712       --  Interface_Name field of the given subprogram entity to the
713       --  appropriate external or link name, depending on the arguments given.
714       --  Ext_Arg is always present, but Link_Arg may be missing. Note that
715       --  Ext_Arg may represent the Link_Name if Link_Arg is missing, and
716       --  appropriate named notation is used for Ext_Arg. If neither Ext_Arg
717       --  nor Link_Arg is present, the interface name is set to the default
718       --  from the subprogram name.
719
720       procedure Process_Interrupt_Or_Attach_Handler;
721       --  Common processing for Interrupt and Attach_Handler pragmas
722
723       procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean);
724       --  Common processing for Restrictions and Restriction_Warnings pragmas.
725       --  Warn is True for Restriction_Warnings, or for Restrictions if the
726       --  flag Treat_Restrictions_As_Warnings is set, and False if this flag
727       --  is not set in the Restrictions case.
728
729       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean);
730       --  Common processing for Suppress and Unsuppress. The boolean parameter
731       --  Suppress_Case is True for the Suppress case, and False for the
732       --  Unsuppress case.
733
734       procedure Set_Exported (E : Entity_Id; Arg : Node_Id);
735       --  This procedure sets the Is_Exported flag for the given entity,
736       --  checking that the entity was not previously imported. Arg is
737       --  the argument that specified the entity. A check is also made
738       --  for exporting inappropriate entities.
739
740       procedure Set_Extended_Import_Export_External_Name
741         (Internal_Ent : Entity_Id;
742          Arg_External : Node_Id);
743       --  Common processing for all extended import export pragmas. The first
744       --  argument, Internal_Ent, is the internal entity, which has already
745       --  been checked for validity by the caller. Arg_External is from the
746       --  Import or Export pragma, and may be null if no External parameter
747       --  was present. If Arg_External is present and is a non-null string
748       --  (a null string is treated as the default), then the Interface_Name
749       --  field of Internal_Ent is set appropriately.
750
751       procedure Set_Imported (E : Entity_Id);
752       --  This procedure sets the Is_Imported flag for the given entity,
753       --  checking that it is not previously exported or imported.
754
755       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id);
756       --  Mech is a parameter passing mechanism (see Import_Function syntax
757       --  for MECHANISM_NAME). This routine checks that the mechanism argument
758       --  has the right form, and if not issues an error message. If the
759       --  argument has the right form then the Mechanism field of Ent is
760       --  set appropriately.
761
762       procedure Set_Ravenscar_Profile (N : Node_Id);
763       --  Activate the set of configuration pragmas and restrictions that make
764       --  up the Ravenscar Profile. N is the corresponding pragma node, which
765       --  is used for error messages on any constructs that violate the
766       --  profile.
767
768       ---------------------
769       -- Ada_2005_Pragma --
770       ---------------------
771
772       procedure Ada_2005_Pragma is
773       begin
774          if Ada_Version <= Ada_95 then
775             Check_Restriction (No_Implementation_Pragmas, N);
776          end if;
777       end Ada_2005_Pragma;
778
779       ---------------------
780       -- Ada_2012_Pragma --
781       ---------------------
782
783       procedure Ada_2012_Pragma is
784       begin
785          if Ada_Version <= Ada_2005 then
786             Check_Restriction (No_Implementation_Pragmas, N);
787          end if;
788       end Ada_2012_Pragma;
789
790       --------------------------
791       -- Check_Ada_83_Warning --
792       --------------------------
793
794       procedure Check_Ada_83_Warning is
795       begin
796          if Ada_Version = Ada_83 and then Comes_From_Source (N) then
797             Error_Msg_N ("(Ada 83) pragma& is non-standard?", N);
798          end if;
799       end Check_Ada_83_Warning;
800
801       ---------------------
802       -- Check_Arg_Count --
803       ---------------------
804
805       procedure Check_Arg_Count (Required : Nat) is
806       begin
807          if Arg_Count /= Required then
808             Error_Pragma ("wrong number of arguments for pragma%");
809          end if;
810       end Check_Arg_Count;
811
812       --------------------------------
813       -- Check_Arg_Is_External_Name --
814       --------------------------------
815
816       procedure Check_Arg_Is_External_Name (Arg : Node_Id) is
817          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
818
819       begin
820          if Nkind (Argx) = N_Identifier then
821             return;
822
823          else
824             Analyze_And_Resolve (Argx, Standard_String);
825
826             if Is_OK_Static_Expression (Argx) then
827                return;
828
829             elsif Etype (Argx) = Any_Type then
830                raise Pragma_Exit;
831
832             --  An interesting special case, if we have a string literal and
833             --  we are in Ada 83 mode, then we allow it even though it will
834             --  not be flagged as static. This allows expected Ada 83 mode
835             --  use of external names which are string literals, even though
836             --  technically these are not static in Ada 83.
837
838             elsif Ada_Version = Ada_83
839               and then Nkind (Argx) = N_String_Literal
840             then
841                return;
842
843             --  Static expression that raises Constraint_Error. This has
844             --  already been flagged, so just exit from pragma processing.
845
846             elsif Is_Static_Expression (Argx) then
847                raise Pragma_Exit;
848
849             --  Here we have a real error (non-static expression)
850
851             else
852                Error_Msg_Name_1 := Pname;
853
854                declare
855                   Msg : String :=
856                           "argument for pragma% must be a identifier or "
857                           & "static string expression!";
858                begin
859                   Fix_Error (Msg);
860                   Flag_Non_Static_Expr (Msg, Argx);
861                   raise Pragma_Exit;
862                end;
863             end if;
864          end if;
865       end Check_Arg_Is_External_Name;
866
867       -----------------------------
868       -- Check_Arg_Is_Identifier --
869       -----------------------------
870
871       procedure Check_Arg_Is_Identifier (Arg : Node_Id) is
872          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
873       begin
874          if Nkind (Argx) /= N_Identifier then
875             Error_Pragma_Arg
876               ("argument for pragma% must be identifier", Argx);
877          end if;
878       end Check_Arg_Is_Identifier;
879
880       ----------------------------------
881       -- Check_Arg_Is_Integer_Literal --
882       ----------------------------------
883
884       procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is
885          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
886       begin
887          if Nkind (Argx) /= N_Integer_Literal then
888             Error_Pragma_Arg
889               ("argument for pragma% must be integer literal", Argx);
890          end if;
891       end Check_Arg_Is_Integer_Literal;
892
893       -------------------------------------------
894       -- Check_Arg_Is_Library_Level_Local_Name --
895       -------------------------------------------
896
897       --  LOCAL_NAME ::=
898       --    DIRECT_NAME
899       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
900       --  | library_unit_NAME
901
902       procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is
903       begin
904          Check_Arg_Is_Local_Name (Arg);
905
906          if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg)))
907            and then Comes_From_Source (N)
908          then
909             Error_Pragma_Arg
910               ("argument for pragma% must be library level entity", Arg);
911          end if;
912       end Check_Arg_Is_Library_Level_Local_Name;
913
914       -----------------------------
915       -- Check_Arg_Is_Local_Name --
916       -----------------------------
917
918       --  LOCAL_NAME ::=
919       --    DIRECT_NAME
920       --  | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
921       --  | library_unit_NAME
922
923       procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is
924          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
925
926       begin
927          Analyze (Argx);
928
929          if Nkind (Argx) not in N_Direct_Name
930            and then (Nkind (Argx) /= N_Attribute_Reference
931                       or else Present (Expressions (Argx))
932                       or else Nkind (Prefix (Argx)) /= N_Identifier)
933            and then (not Is_Entity_Name (Argx)
934                       or else not Is_Compilation_Unit (Entity (Argx)))
935          then
936             Error_Pragma_Arg ("argument for pragma% must be local name", Argx);
937          end if;
938
939          --  No further check required if not an entity name
940
941          if not Is_Entity_Name (Argx) then
942             null;
943
944          else
945             declare
946                OK   : Boolean;
947                Ent  : constant Entity_Id := Entity (Argx);
948                Scop : constant Entity_Id := Scope (Ent);
949             begin
950                --  Case of a pragma applied to a compilation unit: pragma must
951                --  occur immediately after the program unit in the compilation.
952
953                if Is_Compilation_Unit (Ent) then
954                   declare
955                      Decl : constant Node_Id := Unit_Declaration_Node (Ent);
956                   begin
957                      --  Case of pragma placed immediately after spec
958
959                      if Parent (N) = Aux_Decls_Node (Parent (Decl)) then
960                         OK := True;
961
962                      --  Case of pragma placed immediately after body
963
964                      elsif Nkind (Decl) = N_Subprogram_Declaration
965                              and then Present (Corresponding_Body (Decl))
966                      then
967                         OK := Parent (N) =
968                                 Aux_Decls_Node
969                                   (Parent (Unit_Declaration_Node
970                                              (Corresponding_Body (Decl))));
971
972                      --  All other cases are illegal
973
974                      else
975                         OK := False;
976                      end if;
977                   end;
978
979                --  Special restricted placement rule from 10.2.1(11.8/2)
980
981                elsif Is_Generic_Formal (Ent)
982                        and then Prag_Id = Pragma_Preelaborable_Initialization
983                then
984                   OK := List_Containing (N) =
985                           Generic_Formal_Declarations
986                             (Unit_Declaration_Node (Scop));
987
988                --  Default case, just check that the pragma occurs in the scope
989                --  of the entity denoted by the name.
990
991                else
992                   OK := Current_Scope = Scop;
993                end if;
994
995                if not OK then
996                   Error_Pragma_Arg
997                     ("pragma% argument must be in same declarative part", Arg);
998                end if;
999             end;
1000          end if;
1001       end Check_Arg_Is_Local_Name;
1002
1003       ---------------------------------
1004       -- Check_Arg_Is_Locking_Policy --
1005       ---------------------------------
1006
1007       procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is
1008          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1009
1010       begin
1011          Check_Arg_Is_Identifier (Argx);
1012
1013          if not Is_Locking_Policy_Name (Chars (Argx)) then
1014             Error_Pragma_Arg ("& is not a valid locking policy name", Argx);
1015          end if;
1016       end Check_Arg_Is_Locking_Policy;
1017
1018       -------------------------
1019       -- Check_Arg_Is_One_Of --
1020       -------------------------
1021
1022       procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1023          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1024
1025       begin
1026          Check_Arg_Is_Identifier (Argx);
1027
1028          if Chars (Argx) /= N1 and then Chars (Argx) /= N2 then
1029             Error_Msg_Name_2 := N1;
1030             Error_Msg_Name_3 := N2;
1031             Error_Pragma_Arg ("argument for pragma% must be% or%", Argx);
1032          end if;
1033       end Check_Arg_Is_One_Of;
1034
1035       procedure Check_Arg_Is_One_Of
1036         (Arg        : Node_Id;
1037          N1, N2, N3 : Name_Id)
1038       is
1039          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1040
1041       begin
1042          Check_Arg_Is_Identifier (Argx);
1043
1044          if Chars (Argx) /= N1
1045            and then Chars (Argx) /= N2
1046            and then Chars (Argx) /= N3
1047          then
1048             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1049          end if;
1050       end Check_Arg_Is_One_Of;
1051
1052       procedure Check_Arg_Is_One_Of
1053         (Arg                : Node_Id;
1054          N1, N2, N3, N4, N5 : Name_Id)
1055       is
1056          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1057
1058       begin
1059          Check_Arg_Is_Identifier (Argx);
1060
1061          if Chars (Argx) /= N1
1062            and then Chars (Argx) /= N2
1063            and then Chars (Argx) /= N3
1064            and then Chars (Argx) /= N4
1065            and then Chars (Argx) /= N5
1066          then
1067             Error_Pragma_Arg ("invalid argument for pragma%", Argx);
1068          end if;
1069       end Check_Arg_Is_One_Of;
1070       ---------------------------------
1071       -- Check_Arg_Is_Queuing_Policy --
1072       ---------------------------------
1073
1074       procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is
1075          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1076
1077       begin
1078          Check_Arg_Is_Identifier (Argx);
1079
1080          if not Is_Queuing_Policy_Name (Chars (Argx)) then
1081             Error_Pragma_Arg ("& is not a valid queuing policy name", Argx);
1082          end if;
1083       end Check_Arg_Is_Queuing_Policy;
1084
1085       ------------------------------------
1086       -- Check_Arg_Is_Static_Expression --
1087       ------------------------------------
1088
1089       procedure Check_Arg_Is_Static_Expression
1090         (Arg : Node_Id;
1091          Typ : Entity_Id := Empty)
1092       is
1093          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1094
1095       begin
1096          if Present (Typ) then
1097             Analyze_And_Resolve (Argx, Typ);
1098          else
1099             Analyze_And_Resolve (Argx);
1100          end if;
1101
1102          if Is_OK_Static_Expression (Argx) then
1103             return;
1104
1105          elsif Etype (Argx) = Any_Type then
1106             raise Pragma_Exit;
1107
1108          --  An interesting special case, if we have a string literal and we
1109          --  are in Ada 83 mode, then we allow it even though it will not be
1110          --  flagged as static. This allows the use of Ada 95 pragmas like
1111          --  Import in Ada 83 mode. They will of course be flagged with
1112          --  warnings as usual, but will not cause errors.
1113
1114          elsif Ada_Version = Ada_83
1115            and then Nkind (Argx) = N_String_Literal
1116          then
1117             return;
1118
1119          --  Static expression that raises Constraint_Error. This has already
1120          --  been flagged, so just exit from pragma processing.
1121
1122          elsif Is_Static_Expression (Argx) then
1123             raise Pragma_Exit;
1124
1125          --  Finally, we have a real error
1126
1127          else
1128             Error_Msg_Name_1 := Pname;
1129
1130             declare
1131                Msg : String :=
1132                        "argument for pragma% must be a static expression!";
1133             begin
1134                Fix_Error (Msg);
1135                Flag_Non_Static_Expr (Msg, Argx);
1136             end;
1137
1138             raise Pragma_Exit;
1139          end if;
1140       end Check_Arg_Is_Static_Expression;
1141
1142       ------------------------------------------
1143       -- Check_Arg_Is_Task_Dispatching_Policy --
1144       ------------------------------------------
1145
1146       procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is
1147          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1148
1149       begin
1150          Check_Arg_Is_Identifier (Argx);
1151
1152          if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then
1153             Error_Pragma_Arg
1154               ("& is not a valid task dispatching policy name", Argx);
1155          end if;
1156       end Check_Arg_Is_Task_Dispatching_Policy;
1157
1158       ---------------------
1159       -- Check_Arg_Order --
1160       ---------------------
1161
1162       procedure Check_Arg_Order (Names : Name_List) is
1163          Arg : Node_Id;
1164
1165          Highest_So_Far : Natural := 0;
1166          --  Highest index in Names seen do far
1167
1168       begin
1169          Arg := Arg1;
1170          for J in 1 .. Arg_Count loop
1171             if Chars (Arg) /= No_Name then
1172                for K in Names'Range loop
1173                   if Chars (Arg) = Names (K) then
1174                      if K < Highest_So_Far then
1175                         Error_Msg_Name_1 := Pname;
1176                         Error_Msg_N
1177                           ("parameters out of order for pragma%", Arg);
1178                         Error_Msg_Name_1 := Names (K);
1179                         Error_Msg_Name_2 := Names (Highest_So_Far);
1180                         Error_Msg_N ("\% must appear before %", Arg);
1181                         raise Pragma_Exit;
1182
1183                      else
1184                         Highest_So_Far := K;
1185                      end if;
1186                   end if;
1187                end loop;
1188             end if;
1189
1190             Arg := Next (Arg);
1191          end loop;
1192       end Check_Arg_Order;
1193
1194       --------------------------------
1195       -- Check_At_Least_N_Arguments --
1196       --------------------------------
1197
1198       procedure Check_At_Least_N_Arguments (N : Nat) is
1199       begin
1200          if Arg_Count < N then
1201             Error_Pragma ("too few arguments for pragma%");
1202          end if;
1203       end Check_At_Least_N_Arguments;
1204
1205       -------------------------------
1206       -- Check_At_Most_N_Arguments --
1207       -------------------------------
1208
1209       procedure Check_At_Most_N_Arguments (N : Nat) is
1210          Arg : Node_Id;
1211       begin
1212          if Arg_Count > N then
1213             Arg := Arg1;
1214             for J in 1 .. N loop
1215                Next (Arg);
1216                Error_Pragma_Arg ("too many arguments for pragma%", Arg);
1217             end loop;
1218          end if;
1219       end Check_At_Most_N_Arguments;
1220
1221       ---------------------
1222       -- Check_Component --
1223       ---------------------
1224
1225       procedure Check_Component
1226         (Comp            : Node_Id;
1227          UU_Typ          : Entity_Id;
1228          In_Variant_Part : Boolean := False)
1229       is
1230          Comp_Id : constant Entity_Id := Defining_Identifier (Comp);
1231          Sindic  : constant Node_Id :=
1232                      Subtype_Indication (Component_Definition (Comp));
1233          Typ     : constant Entity_Id := Etype (Comp_Id);
1234
1235          function Inside_Generic_Body (Id : Entity_Id) return Boolean;
1236          --  Determine whether entity Id appears inside a generic body.
1237          --  Shouldn't this be in a more general place ???
1238
1239          -------------------------
1240          -- Inside_Generic_Body --
1241          -------------------------
1242
1243          function Inside_Generic_Body (Id : Entity_Id) return Boolean is
1244             S : Entity_Id;
1245
1246          begin
1247             S := Id;
1248             while Present (S) and then S /= Standard_Standard loop
1249                if Ekind (S) = E_Generic_Package
1250                  and then In_Package_Body (S)
1251                then
1252                   return True;
1253                end if;
1254
1255                S := Scope (S);
1256             end loop;
1257
1258             return False;
1259          end Inside_Generic_Body;
1260
1261       --  Start of processing for Check_Component
1262
1263       begin
1264          --  Ada 2005 (AI-216): If a component subtype is subject to a per-
1265          --  object constraint, then the component type shall be an Unchecked_
1266          --  Union.
1267
1268          if Nkind (Sindic) = N_Subtype_Indication
1269            and then Has_Per_Object_Constraint (Comp_Id)
1270            and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic)))
1271          then
1272             Error_Msg_N
1273               ("component subtype subject to per-object constraint " &
1274                "must be an Unchecked_Union", Comp);
1275
1276          --  Ada 2012 (AI05-0026): For an unchecked union type declared within
1277          --  the body of a generic unit, or within the body of any of its
1278          --  descendant library units, no part of the type of a component
1279          --  declared in a variant_part of the unchecked union type shall be of
1280          --  a formal private type or formal private extension declared within
1281          --  the formal part of the generic unit.
1282
1283          elsif Ada_Version >= Ada_2012
1284            and then Inside_Generic_Body (UU_Typ)
1285            and then In_Variant_Part
1286            and then Is_Private_Type (Typ)
1287            and then Is_Generic_Type (Typ)
1288          then
1289             Error_Msg_N
1290               ("component of Unchecked_Union cannot be of generic type", Comp);
1291
1292          elsif Needs_Finalization (Typ) then
1293             Error_Msg_N
1294               ("component of Unchecked_Union cannot be controlled", Comp);
1295
1296          elsif Has_Task (Typ) then
1297             Error_Msg_N
1298               ("component of Unchecked_Union cannot have tasks", Comp);
1299          end if;
1300       end Check_Component;
1301
1302       ----------------------------
1303       -- Check_Duplicate_Pragma --
1304       ----------------------------
1305
1306       procedure Check_Duplicate_Pragma (E : Entity_Id) is
1307          P : Node_Id;
1308
1309       begin
1310          --  Nothing to do if this pragma comes from an aspect specification,
1311          --  since we could not be duplicating a pragma, and we dealt with the
1312          --  case of duplicated aspects in Analyze_Aspect_Specifications.
1313
1314          if From_Aspect_Specification (N) then
1315             return;
1316          end if;
1317
1318          --  Otherwise current pragma may duplicate previous pragma or a
1319          --  previously given aspect specification for the same pragma.
1320
1321          P := Get_Rep_Item_For_Entity (E, Pragma_Name (N));
1322
1323          if Present (P) then
1324             Error_Msg_Name_1 := Pragma_Name (N);
1325             Error_Msg_Sloc := Sloc (P);
1326
1327             if Nkind (P) = N_Aspect_Specification
1328               or else From_Aspect_Specification (P)
1329             then
1330                Error_Msg_NE ("aspect% for & previously given#", N, E);
1331             else
1332                Error_Msg_NE ("pragma% for & duplicates pragma#", N, E);
1333             end if;
1334
1335             raise Pragma_Exit;
1336          end if;
1337       end Check_Duplicate_Pragma;
1338
1339       ----------------------------------
1340       -- Check_Duplicated_Export_Name --
1341       ----------------------------------
1342
1343       procedure Check_Duplicated_Export_Name (Nam : Node_Id) is
1344          String_Val : constant String_Id := Strval (Nam);
1345
1346       begin
1347          --  We are only interested in the export case, and in the case of
1348          --  generics, it is the instance, not the template, that is the
1349          --  problem (the template will generate a warning in any case).
1350
1351          if not Inside_A_Generic
1352            and then (Prag_Id = Pragma_Export
1353                        or else
1354                      Prag_Id = Pragma_Export_Procedure
1355                        or else
1356                      Prag_Id = Pragma_Export_Valued_Procedure
1357                        or else
1358                      Prag_Id = Pragma_Export_Function)
1359          then
1360             for J in Externals.First .. Externals.Last loop
1361                if String_Equal (String_Val, Strval (Externals.Table (J))) then
1362                   Error_Msg_Sloc := Sloc (Externals.Table (J));
1363                   Error_Msg_N ("external name duplicates name given#", Nam);
1364                   exit;
1365                end if;
1366             end loop;
1367
1368             Externals.Append (Nam);
1369          end if;
1370       end Check_Duplicated_Export_Name;
1371
1372       -------------------------
1373       -- Check_First_Subtype --
1374       -------------------------
1375
1376       procedure Check_First_Subtype (Arg : Node_Id) is
1377          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
1378          Ent  : constant Entity_Id := Entity (Argx);
1379
1380       begin
1381          if Is_First_Subtype (Ent) then
1382             null;
1383
1384          elsif Is_Type (Ent) then
1385             Error_Pragma_Arg
1386               ("pragma% cannot apply to subtype", Argx);
1387
1388          elsif Is_Object (Ent) then
1389             Error_Pragma_Arg
1390               ("pragma% cannot apply to object, requires a type", Argx);
1391
1392          else
1393             Error_Pragma_Arg
1394               ("pragma% cannot apply to&, requires a type", Argx);
1395          end if;
1396       end Check_First_Subtype;
1397
1398       ----------------------
1399       -- Check_Identifier --
1400       ----------------------
1401
1402       procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is
1403       begin
1404          if Present (Arg)
1405            and then Nkind (Arg) = N_Pragma_Argument_Association
1406          then
1407             if Chars (Arg) = No_Name or else Chars (Arg) /= Id then
1408                Error_Msg_Name_1 := Pname;
1409                Error_Msg_Name_2 := Id;
1410                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1411                raise Pragma_Exit;
1412             end if;
1413          end if;
1414       end Check_Identifier;
1415
1416       --------------------------------
1417       -- Check_Identifier_Is_One_Of --
1418       --------------------------------
1419
1420       procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is
1421       begin
1422          if Present (Arg)
1423            and then Nkind (Arg) = N_Pragma_Argument_Association
1424          then
1425             if Chars (Arg) = No_Name then
1426                Error_Msg_Name_1 := Pname;
1427                Error_Msg_N ("pragma% argument expects an identifier", Arg);
1428                raise Pragma_Exit;
1429
1430             elsif Chars (Arg) /= N1
1431               and then Chars (Arg) /= N2
1432             then
1433                Error_Msg_Name_1 := Pname;
1434                Error_Msg_N ("invalid identifier for pragma% argument", Arg);
1435                raise Pragma_Exit;
1436             end if;
1437          end if;
1438       end Check_Identifier_Is_One_Of;
1439
1440       ---------------------------
1441       -- Check_In_Main_Program --
1442       ---------------------------
1443
1444       procedure Check_In_Main_Program is
1445          P : constant Node_Id := Parent (N);
1446
1447       begin
1448          --  Must be at in subprogram body
1449
1450          if Nkind (P) /= N_Subprogram_Body then
1451             Error_Pragma ("% pragma allowed only in subprogram");
1452
1453          --  Otherwise warn if obviously not main program
1454
1455          elsif Present (Parameter_Specifications (Specification (P)))
1456            or else not Is_Compilation_Unit (Defining_Entity (P))
1457          then
1458             Error_Msg_Name_1 := Pname;
1459             Error_Msg_N
1460               ("?pragma% is only effective in main program", N);
1461          end if;
1462       end Check_In_Main_Program;
1463
1464       ---------------------------------------
1465       -- Check_Interrupt_Or_Attach_Handler --
1466       ---------------------------------------
1467
1468       procedure Check_Interrupt_Or_Attach_Handler is
1469          Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1);
1470          Handler_Proc, Proc_Scope : Entity_Id;
1471
1472       begin
1473          Analyze (Arg1_X);
1474
1475          if Prag_Id = Pragma_Interrupt_Handler then
1476             Check_Restriction (No_Dynamic_Attachment, N);
1477          end if;
1478
1479          Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
1480          Proc_Scope := Scope (Handler_Proc);
1481
1482          --  On AAMP only, a pragma Interrupt_Handler is supported for
1483          --  nonprotected parameterless procedures.
1484
1485          if not AAMP_On_Target
1486            or else Prag_Id = Pragma_Attach_Handler
1487          then
1488             if Ekind (Proc_Scope) /= E_Protected_Type then
1489                Error_Pragma_Arg
1490                  ("argument of pragma% must be protected procedure", Arg1);
1491             end if;
1492
1493             if Parent (N) /= Protected_Definition (Parent (Proc_Scope)) then
1494                Error_Pragma ("pragma% must be in protected definition");
1495             end if;
1496          end if;
1497
1498          if not Is_Library_Level_Entity (Proc_Scope)
1499            or else (AAMP_On_Target
1500                      and then not Is_Library_Level_Entity (Handler_Proc))
1501          then
1502             Error_Pragma_Arg
1503               ("argument for pragma% must be library level entity", Arg1);
1504          end if;
1505
1506          --  AI05-0033: A pragma cannot appear within a generic body, because
1507          --  instance can be in a nested scope. The check that protected type
1508          --  is itself a library-level declaration is done elsewhere.
1509
1510          --  Note: we omit this check in Codepeer mode to properly handle code
1511          --  prior to AI-0033 (pragmas don't matter to codepeer in any case).
1512
1513          if Inside_A_Generic then
1514             if Ekind (Scope (Current_Scope)) = E_Generic_Package
1515               and then In_Package_Body (Scope (Current_Scope))
1516               and then not CodePeer_Mode
1517             then
1518                Error_Pragma ("pragma% cannot be used inside a generic");
1519             end if;
1520          end if;
1521       end Check_Interrupt_Or_Attach_Handler;
1522
1523       -------------------------------------------
1524       -- Check_Is_In_Decl_Part_Or_Package_Spec --
1525       -------------------------------------------
1526
1527       procedure Check_Is_In_Decl_Part_Or_Package_Spec is
1528          P : Node_Id;
1529
1530       begin
1531          P := Parent (N);
1532          loop
1533             if No (P) then
1534                exit;
1535
1536             elsif Nkind (P) = N_Handled_Sequence_Of_Statements then
1537                exit;
1538
1539             elsif Nkind_In (P, N_Package_Specification,
1540                                N_Block_Statement)
1541             then
1542                return;
1543
1544             --  Note: the following tests seem a little peculiar, because
1545             --  they test for bodies, but if we were in the statement part
1546             --  of the body, we would already have hit the handled statement
1547             --  sequence, so the only way we get here is by being in the
1548             --  declarative part of the body.
1549
1550             elsif Nkind_In (P, N_Subprogram_Body,
1551                                N_Package_Body,
1552                                N_Task_Body,
1553                                N_Entry_Body)
1554             then
1555                return;
1556             end if;
1557
1558             P := Parent (P);
1559          end loop;
1560
1561          Error_Pragma ("pragma% is not in declarative part or package spec");
1562       end Check_Is_In_Decl_Part_Or_Package_Spec;
1563
1564       -------------------------
1565       -- Check_No_Identifier --
1566       -------------------------
1567
1568       procedure Check_No_Identifier (Arg : Node_Id) is
1569       begin
1570          if Nkind (Arg) = N_Pragma_Argument_Association
1571            and then Chars (Arg) /= No_Name
1572          then
1573             Error_Pragma_Arg_Ident
1574               ("pragma% does not permit identifier& here", Arg);
1575          end if;
1576       end Check_No_Identifier;
1577
1578       --------------------------
1579       -- Check_No_Identifiers --
1580       --------------------------
1581
1582       procedure Check_No_Identifiers is
1583          Arg_Node : Node_Id;
1584       begin
1585          if Arg_Count > 0 then
1586             Arg_Node := Arg1;
1587             while Present (Arg_Node) loop
1588                Check_No_Identifier (Arg_Node);
1589                Next (Arg_Node);
1590             end loop;
1591          end if;
1592       end Check_No_Identifiers;
1593
1594       ------------------------
1595       -- Check_No_Link_Name --
1596       ------------------------
1597
1598       procedure Check_No_Link_Name is
1599       begin
1600          if Present (Arg3)
1601            and then Chars (Arg3) = Name_Link_Name
1602          then
1603             Arg4 := Arg3;
1604          end if;
1605
1606          if Present (Arg4) then
1607             Error_Pragma_Arg
1608               ("Link_Name argument not allowed for Import Intrinsic", Arg4);
1609          end if;
1610       end Check_No_Link_Name;
1611
1612       -------------------------------
1613       -- Check_Optional_Identifier --
1614       -------------------------------
1615
1616       procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is
1617       begin
1618          if Present (Arg)
1619            and then Nkind (Arg) = N_Pragma_Argument_Association
1620            and then Chars (Arg) /= No_Name
1621          then
1622             if Chars (Arg) /= Id then
1623                Error_Msg_Name_1 := Pname;
1624                Error_Msg_Name_2 := Id;
1625                Error_Msg_N ("pragma% argument expects identifier%", Arg);
1626                raise Pragma_Exit;
1627             end if;
1628          end if;
1629       end Check_Optional_Identifier;
1630
1631       procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is
1632       begin
1633          Name_Buffer (1 .. Id'Length) := Id;
1634          Name_Len := Id'Length;
1635          Check_Optional_Identifier (Arg, Name_Find);
1636       end Check_Optional_Identifier;
1637
1638       --------------------------------------
1639       -- Check_Precondition_Postcondition --
1640       --------------------------------------
1641
1642       procedure Check_Precondition_Postcondition (In_Body : out Boolean) is
1643          P  : Node_Id;
1644          PO : Node_Id;
1645
1646          procedure Chain_PPC (PO : Node_Id);
1647          --  If PO is an entry or a [generic] subprogram declaration node, then
1648          --  the precondition/postcondition applies to this subprogram and the
1649          --  processing for the pragma is completed. Otherwise the pragma is
1650          --  misplaced.
1651
1652          ---------------
1653          -- Chain_PPC --
1654          ---------------
1655
1656          procedure Chain_PPC (PO : Node_Id) is
1657             S   : Entity_Id;
1658             P   : Node_Id;
1659
1660          begin
1661             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1662                if not From_Aspect_Specification (N) then
1663                   Error_Pragma
1664                     ("pragma% cannot be applied to abstract subprogram");
1665
1666                elsif Class_Present (N) then
1667                   null;
1668
1669                else
1670                   Error_Pragma
1671                     ("aspect % requires ''Class for abstract subprogram");
1672                end if;
1673
1674             --  AI05-0230: The same restriction applies to null procedures. For
1675             --  compatibility with earlier uses of the Ada pragma, apply this
1676             --  rule only to aspect specifications.
1677
1678             --  The above discrpency needs documentation. Robert is dubious
1679             --  about whether it is a good idea ???
1680
1681             elsif Nkind (PO) = N_Subprogram_Declaration
1682               and then Nkind (Specification (PO)) = N_Procedure_Specification
1683               and then Null_Present (Specification (PO))
1684               and then From_Aspect_Specification (N)
1685               and then not Class_Present (N)
1686             then
1687                Error_Pragma
1688                  ("aspect % requires ''Class for null procedure");
1689
1690             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1691                                     N_Generic_Subprogram_Declaration,
1692                                     N_Entry_Declaration)
1693             then
1694                Pragma_Misplaced;
1695             end if;
1696
1697             --  Here if we have [generic] subprogram or entry declaration
1698
1699             if Nkind (PO) = N_Entry_Declaration then
1700                S := Defining_Entity (PO);
1701             else
1702                S := Defining_Unit_Name (Specification (PO));
1703             end if;
1704
1705             --  Make sure we do not have the case of a precondition pragma when
1706             --  the Pre'Class aspect is present.
1707
1708             --  We do this by looking at pragmas already chained to the entity
1709             --  since the aspect derived pragma will be put on this list first.
1710
1711             if Pragma_Name (N) = Name_Precondition then
1712                if not From_Aspect_Specification (N) then
1713                   P := Spec_PPC_List (Contract (S));
1714                   while Present (P) loop
1715                      if Pragma_Name (P) = Name_Precondition
1716                        and then From_Aspect_Specification (P)
1717                        and then Class_Present (P)
1718                      then
1719                         Error_Msg_Sloc := Sloc (P);
1720                         Error_Pragma
1721                           ("pragma% not allowed, `Pre''Class` aspect given#");
1722                      end if;
1723
1724                      P := Next_Pragma (P);
1725                   end loop;
1726                end if;
1727             end if;
1728
1729             --  Similarly check for Pre with inherited Pre'Class. Note that
1730             --  we cover the aspect case as well here.
1731
1732             if Pragma_Name (N) = Name_Precondition
1733               and then not Class_Present (N)
1734             then
1735                declare
1736                   Inherited : constant Subprogram_List :=
1737                                 Inherited_Subprograms (S);
1738                   P         : Node_Id;
1739
1740                begin
1741                   for J in Inherited'Range loop
1742                      P := Spec_PPC_List (Contract (Inherited (J)));
1743                      while Present (P) loop
1744                         if Pragma_Name (P) = Name_Precondition
1745                           and then Class_Present (P)
1746                         then
1747                            Error_Msg_Sloc := Sloc (P);
1748                            Error_Pragma
1749                              ("pragma% not allowed, `Pre''Class` "
1750                               & "aspect inherited from#");
1751                         end if;
1752
1753                         P := Next_Pragma (P);
1754                      end loop;
1755                   end loop;
1756                end;
1757             end if;
1758
1759             --  Note: we do not analyze the pragma at this point. Instead we
1760             --  delay this analysis until the end of the declarative part in
1761             --  which the pragma appears. This implements the required delay
1762             --  in this analysis, allowing forward references. The analysis
1763             --  happens at the end of Analyze_Declarations.
1764
1765             --  Chain spec PPC pragma to list for subprogram
1766
1767             Set_Next_Pragma (N, Spec_PPC_List (Contract (S)));
1768             Set_Spec_PPC_List (Contract (S), N);
1769
1770             --  Return indicating spec case
1771
1772             In_Body := False;
1773             return;
1774          end Chain_PPC;
1775
1776       --  Start of processing for Check_Precondition_Postcondition
1777
1778       begin
1779          if not Is_List_Member (N) then
1780             Pragma_Misplaced;
1781          end if;
1782
1783          --  Preanalyze message argument if present. Visibility in this
1784          --  argument is established at the point of pragma occurrence.
1785
1786          if Arg_Count = 2 then
1787             Check_Optional_Identifier (Arg2, Name_Message);
1788             Preanalyze_Spec_Expression
1789               (Get_Pragma_Arg (Arg2), Standard_String);
1790          end if;
1791
1792          --  Record if pragma is disabled
1793
1794          if Check_Enabled (Pname) then
1795             Set_SCO_Pragma_Enabled (Loc);
1796          end if;
1797
1798          --  If we are within an inlined body, the legality of the pragma
1799          --  has been checked already.
1800
1801          if In_Inlined_Body then
1802             In_Body := True;
1803             return;
1804          end if;
1805
1806          --  Search prior declarations
1807
1808          P := N;
1809          while Present (Prev (P)) loop
1810             P := Prev (P);
1811
1812             --  If the previous node is a generic subprogram, do not go to to
1813             --  the original node, which is the unanalyzed tree: we need to
1814             --  attach the pre/postconditions to the analyzed version at this
1815             --  point. They get propagated to the original tree when analyzing
1816             --  the corresponding body.
1817
1818             if Nkind (P) not in N_Generic_Declaration then
1819                PO := Original_Node (P);
1820             else
1821                PO := P;
1822             end if;
1823
1824             --  Skip past prior pragma
1825
1826             if Nkind (PO) = N_Pragma then
1827                null;
1828
1829             --  Skip stuff not coming from source
1830
1831             elsif not Comes_From_Source (PO) then
1832
1833                --  The condition may apply to a subprogram instantiation
1834
1835                if Nkind (PO) = N_Subprogram_Declaration
1836                  and then Present (Generic_Parent (Specification (PO)))
1837                then
1838                   Chain_PPC (PO);
1839                   return;
1840
1841                --  For all other cases of non source code, do nothing
1842
1843                else
1844                   null;
1845                end if;
1846
1847             --  Only remaining possibility is subprogram declaration
1848
1849             else
1850                Chain_PPC (PO);
1851                return;
1852             end if;
1853          end loop;
1854
1855          --  If we fall through loop, pragma is at start of list, so see if it
1856          --  is at the start of declarations of a subprogram body.
1857
1858          if Nkind (Parent (N)) = N_Subprogram_Body
1859            and then List_Containing (N) = Declarations (Parent (N))
1860          then
1861             if Operating_Mode /= Generate_Code
1862               or else Inside_A_Generic
1863             then
1864                --  Analyze pragma expression for correctness and for ASIS use
1865
1866                Preanalyze_Spec_Expression
1867                  (Get_Pragma_Arg (Arg1), Standard_Boolean);
1868             end if;
1869
1870             In_Body := True;
1871             return;
1872
1873          --  See if it is in the pragmas after a library level subprogram
1874
1875          elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then
1876
1877             --  In formal verification mode, analyze pragma expression for
1878             --  correctness, as it is not expanded later.
1879
1880             if Alfa_Mode then
1881                Analyze_PPC_In_Decl_Part
1882                  (N, Defining_Entity (Unit (Parent (Parent (N)))));
1883             end if;
1884
1885             Chain_PPC (Unit (Parent (Parent (N))));
1886             return;
1887          end if;
1888
1889          --  If we fall through, pragma was misplaced
1890
1891          Pragma_Misplaced;
1892       end Check_Precondition_Postcondition;
1893
1894       -----------------------------
1895       -- Check_Static_Constraint --
1896       -----------------------------
1897
1898       --  Note: for convenience in writing this procedure, in addition to
1899       --  the officially (i.e. by spec) allowed argument which is always a
1900       --  constraint, it also allows ranges and discriminant associations.
1901       --  Above is not clear ???
1902
1903       procedure Check_Static_Constraint (Constr : Node_Id) is
1904
1905          procedure Require_Static (E : Node_Id);
1906          --  Require given expression to be static expression
1907
1908          --------------------
1909          -- Require_Static --
1910          --------------------
1911
1912          procedure Require_Static (E : Node_Id) is
1913          begin
1914             if not Is_OK_Static_Expression (E) then
1915                Flag_Non_Static_Expr
1916                  ("non-static constraint not allowed in Unchecked_Union!", E);
1917                raise Pragma_Exit;
1918             end if;
1919          end Require_Static;
1920
1921       --  Start of processing for Check_Static_Constraint
1922
1923       begin
1924          case Nkind (Constr) is
1925             when N_Discriminant_Association =>
1926                Require_Static (Expression (Constr));
1927
1928             when N_Range =>
1929                Require_Static (Low_Bound (Constr));
1930                Require_Static (High_Bound (Constr));
1931
1932             when N_Attribute_Reference =>
1933                Require_Static (Type_Low_Bound  (Etype (Prefix (Constr))));
1934                Require_Static (Type_High_Bound (Etype (Prefix (Constr))));
1935
1936             when N_Range_Constraint =>
1937                Check_Static_Constraint (Range_Expression (Constr));
1938
1939             when N_Index_Or_Discriminant_Constraint =>
1940                declare
1941                   IDC : Entity_Id;
1942                begin
1943                   IDC := First (Constraints (Constr));
1944                   while Present (IDC) loop
1945                      Check_Static_Constraint (IDC);
1946                      Next (IDC);
1947                   end loop;
1948                end;
1949
1950             when others =>
1951                null;
1952          end case;
1953       end Check_Static_Constraint;
1954
1955       ---------------------
1956       -- Check_Test_Case --
1957       ---------------------
1958
1959       procedure Check_Test_Case is
1960          P  : Node_Id;
1961          PO : Node_Id;
1962
1963          procedure Chain_TC (PO : Node_Id);
1964          --  If PO is a [generic] subprogram declaration node, then the
1965          --  test-case applies to this subprogram and the processing for the
1966          --  pragma is completed. Otherwise the pragma is misplaced.
1967
1968          --------------
1969          -- Chain_TC --
1970          --------------
1971
1972          procedure Chain_TC (PO : Node_Id) is
1973             S   : Entity_Id;
1974
1975          begin
1976             if Nkind (PO) = N_Abstract_Subprogram_Declaration then
1977                if From_Aspect_Specification (N) then
1978                   Error_Pragma
1979                     ("aspect% cannot be applied to abstract subprogram");
1980                else
1981                   Error_Pragma
1982                     ("pragma% cannot be applied to abstract subprogram");
1983                end if;
1984
1985             elsif Nkind (PO) = N_Entry_Declaration then
1986                if From_Aspect_Specification (N) then
1987                   Error_Pragma ("aspect% cannot be applied to entry");
1988                else
1989                   Error_Pragma ("pragma% cannot be applied to entry");
1990                end if;
1991
1992             elsif not Nkind_In (PO, N_Subprogram_Declaration,
1993                                     N_Generic_Subprogram_Declaration)
1994             then
1995                Pragma_Misplaced;
1996             end if;
1997
1998             --  Here if we have [generic] subprogram declaration
1999
2000             S := Defining_Unit_Name (Specification (PO));
2001
2002             --  Note: we do not analyze the pragma at this point. Instead we
2003             --  delay this analysis until the end of the declarative part in
2004             --  which the pragma appears. This implements the required delay
2005             --  in this analysis, allowing forward references. The analysis
2006             --  happens at the end of Analyze_Declarations.
2007
2008             --  There should not be another test case with the same name
2009             --  associated to this subprogram.
2010
2011             declare
2012                Name : constant String_Id := Get_Name_From_Test_Case_Pragma (N);
2013                TC   : Node_Id;
2014
2015             begin
2016                TC := Spec_TC_List (Contract (S));
2017                while Present (TC) loop
2018
2019                   if String_Equal
2020                     (Name, Get_Name_From_Test_Case_Pragma (TC))
2021                   then
2022                      Error_Msg_Sloc := Sloc (TC);
2023
2024                      if From_Aspect_Specification (N) then
2025                         Error_Pragma ("name for aspect% is already used#");
2026                      else
2027                         Error_Pragma ("name for pragma% is already used#");
2028                      end if;
2029                   end if;
2030
2031                   TC := Next_Pragma (TC);
2032                end loop;
2033             end;
2034
2035             --  Chain spec TC pragma to list for subprogram
2036
2037             Set_Next_Pragma (N, Spec_TC_List (Contract (S)));
2038             Set_Spec_TC_List (Contract (S), N);
2039          end Chain_TC;
2040
2041       --  Start of processing for Check_Test_Case
2042
2043       begin
2044          if not Is_List_Member (N) then
2045             Pragma_Misplaced;
2046          end if;
2047
2048          --  Test cases should only appear in package spec unit
2049
2050          if Get_Source_Unit (N) = No_Unit
2051            or else not Nkind_In (Sinfo.Unit (Cunit (Get_Source_Unit (N))),
2052                                  N_Package_Declaration,
2053                                  N_Generic_Package_Declaration)
2054          then
2055             Pragma_Misplaced;
2056          end if;
2057
2058          --  Search prior declarations
2059
2060          P := N;
2061          while Present (Prev (P)) loop
2062             P := Prev (P);
2063
2064             --  If the previous node is a generic subprogram, do not go to to
2065             --  the original node, which is the unanalyzed tree: we need to
2066             --  attach the test-case to the analyzed version at this point.
2067             --  They get propagated to the original tree when analyzing the
2068             --  corresponding body.
2069
2070             if Nkind (P) not in N_Generic_Declaration then
2071                PO := Original_Node (P);
2072             else
2073                PO := P;
2074             end if;
2075
2076             --  Skip past prior pragma
2077
2078             if Nkind (PO) = N_Pragma then
2079                null;
2080
2081             --  Skip stuff not coming from source
2082
2083             elsif not Comes_From_Source (PO) then
2084                null;
2085
2086             --  Only remaining possibility is subprogram declaration. First
2087             --  check that it is declared directly in a package declaration.
2088             --  This may be either the package declaration for the current unit
2089             --  being defined or a local package declaration.
2090
2091             elsif not Present (Parent (Parent (PO)))
2092               or else not Present (Parent (Parent (Parent (PO))))
2093               or else not Nkind_In (Parent (Parent (PO)),
2094                                     N_Package_Declaration,
2095                                     N_Generic_Package_Declaration)
2096             then
2097                Pragma_Misplaced;
2098
2099             else
2100                Chain_TC (PO);
2101                return;
2102             end if;
2103          end loop;
2104
2105          --  If we fall through, pragma was misplaced
2106
2107          Pragma_Misplaced;
2108       end Check_Test_Case;
2109
2110       --------------------------------------
2111       -- Check_Valid_Configuration_Pragma --
2112       --------------------------------------
2113
2114       --  A configuration pragma must appear in the context clause of a
2115       --  compilation unit, and only other pragmas may precede it. Note that
2116       --  the test also allows use in a configuration pragma file.
2117
2118       procedure Check_Valid_Configuration_Pragma is
2119       begin
2120          if not Is_Configuration_Pragma then
2121             Error_Pragma ("incorrect placement for configuration pragma%");
2122          end if;
2123       end Check_Valid_Configuration_Pragma;
2124
2125       -------------------------------------
2126       -- Check_Valid_Library_Unit_Pragma --
2127       -------------------------------------
2128
2129       procedure Check_Valid_Library_Unit_Pragma is
2130          Plist       : List_Id;
2131          Parent_Node : Node_Id;
2132          Unit_Name   : Entity_Id;
2133          Unit_Kind   : Node_Kind;
2134          Unit_Node   : Node_Id;
2135          Sindex      : Source_File_Index;
2136
2137       begin
2138          if not Is_List_Member (N) then
2139             Pragma_Misplaced;
2140
2141          else
2142             Plist := List_Containing (N);
2143             Parent_Node := Parent (Plist);
2144
2145             if Parent_Node = Empty then
2146                Pragma_Misplaced;
2147
2148             --  Case of pragma appearing after a compilation unit. In this case
2149             --  it must have an argument with the corresponding name and must
2150             --  be part of the following pragmas of its parent.
2151
2152             elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then
2153                if Plist /= Pragmas_After (Parent_Node) then
2154                   Pragma_Misplaced;
2155
2156                elsif Arg_Count = 0 then
2157                   Error_Pragma
2158                     ("argument required if outside compilation unit");
2159
2160                else
2161                   Check_No_Identifiers;
2162                   Check_Arg_Count (1);
2163                   Unit_Node := Unit (Parent (Parent_Node));
2164                   Unit_Kind := Nkind (Unit_Node);
2165
2166                   Analyze (Get_Pragma_Arg (Arg1));
2167
2168                   if Unit_Kind = N_Generic_Subprogram_Declaration
2169                     or else Unit_Kind = N_Subprogram_Declaration
2170                   then
2171                      Unit_Name := Defining_Entity (Unit_Node);
2172
2173                   elsif Unit_Kind in N_Generic_Instantiation then
2174                      Unit_Name := Defining_Entity (Unit_Node);
2175
2176                   else
2177                      Unit_Name := Cunit_Entity (Current_Sem_Unit);
2178                   end if;
2179
2180                   if Chars (Unit_Name) /=
2181                      Chars (Entity (Get_Pragma_Arg (Arg1)))
2182                   then
2183                      Error_Pragma_Arg
2184                        ("pragma% argument is not current unit name", Arg1);
2185                   end if;
2186
2187                   if Ekind (Unit_Name) = E_Package
2188                     and then Present (Renamed_Entity (Unit_Name))
2189                   then
2190                      Error_Pragma ("pragma% not allowed for renamed package");
2191                   end if;
2192                end if;
2193
2194             --  Pragma appears other than after a compilation unit
2195
2196             else
2197                --  Here we check for the generic instantiation case and also
2198                --  for the case of processing a generic formal package. We
2199                --  detect these cases by noting that the Sloc on the node
2200                --  does not belong to the current compilation unit.
2201
2202                Sindex := Source_Index (Current_Sem_Unit);
2203
2204                if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then
2205                   Rewrite (N, Make_Null_Statement (Loc));
2206                   return;
2207
2208                --  If before first declaration, the pragma applies to the
2209                --  enclosing unit, and the name if present must be this name.
2210
2211                elsif Is_Before_First_Decl (N, Plist) then
2212                   Unit_Node := Unit_Declaration_Node (Current_Scope);
2213                   Unit_Kind := Nkind (Unit_Node);
2214
2215                   if Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then
2216                      Pragma_Misplaced;
2217
2218                   elsif Unit_Kind = N_Subprogram_Body
2219                     and then not Acts_As_Spec (Unit_Node)
2220                   then
2221                      Pragma_Misplaced;
2222
2223                   elsif Nkind (Parent_Node) = N_Package_Body then
2224                      Pragma_Misplaced;
2225
2226                   elsif Nkind (Parent_Node) = N_Package_Specification
2227                     and then Plist = Private_Declarations (Parent_Node)
2228                   then
2229                      Pragma_Misplaced;
2230
2231                   elsif (Nkind (Parent_Node) = N_Generic_Package_Declaration
2232                            or else Nkind (Parent_Node) =
2233                                              N_Generic_Subprogram_Declaration)
2234                     and then Plist = Generic_Formal_Declarations (Parent_Node)
2235                   then
2236                      Pragma_Misplaced;
2237
2238                   elsif Arg_Count > 0 then
2239                      Analyze (Get_Pragma_Arg (Arg1));
2240
2241                      if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then
2242                         Error_Pragma_Arg
2243                           ("name in pragma% must be enclosing unit", Arg1);
2244                      end if;
2245
2246                   --  It is legal to have no argument in this context
2247
2248                   else
2249                      return;
2250                   end if;
2251
2252                --  Error if not before first declaration. This is because a
2253                --  library unit pragma argument must be the name of a library
2254                --  unit (RM 10.1.5(7)), but the only names permitted in this
2255                --  context are (RM 10.1.5(6)) names of subprogram declarations,
2256                --  generic subprogram declarations or generic instantiations.
2257
2258                else
2259                   Error_Pragma
2260                     ("pragma% misplaced, must be before first declaration");
2261                end if;
2262             end if;
2263          end if;
2264       end Check_Valid_Library_Unit_Pragma;
2265
2266       -------------------
2267       -- Check_Variant --
2268       -------------------
2269
2270       procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is
2271          Clist : constant Node_Id := Component_List (Variant);
2272          Comp  : Node_Id;
2273
2274       begin
2275          if not Is_Non_Empty_List (Component_Items (Clist)) then
2276             Error_Msg_N
2277               ("Unchecked_Union may not have empty component list",
2278                Variant);
2279             return;
2280          end if;
2281
2282          Comp := First (Component_Items (Clist));
2283          while Present (Comp) loop
2284             Check_Component (Comp, UU_Typ, In_Variant_Part => True);
2285             Next (Comp);
2286          end loop;
2287       end Check_Variant;
2288
2289       ------------------
2290       -- Error_Pragma --
2291       ------------------
2292
2293       procedure Error_Pragma (Msg : String) is
2294          MsgF : String := Msg;
2295       begin
2296          Error_Msg_Name_1 := Pname;
2297          Fix_Error (MsgF);
2298          Error_Msg_N (MsgF, N);
2299          raise Pragma_Exit;
2300       end Error_Pragma;
2301
2302       ----------------------
2303       -- Error_Pragma_Arg --
2304       ----------------------
2305
2306       procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is
2307          MsgF : String := Msg;
2308       begin
2309          Error_Msg_Name_1 := Pname;
2310          Fix_Error (MsgF);
2311          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2312          raise Pragma_Exit;
2313       end Error_Pragma_Arg;
2314
2315       procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is
2316          MsgF : String := Msg1;
2317       begin
2318          Error_Msg_Name_1 := Pname;
2319          Fix_Error (MsgF);
2320          Error_Msg_N (MsgF, Get_Pragma_Arg (Arg));
2321          Error_Pragma_Arg (Msg2, Arg);
2322       end Error_Pragma_Arg;
2323
2324       ----------------------------
2325       -- Error_Pragma_Arg_Ident --
2326       ----------------------------
2327
2328       procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is
2329          MsgF : String := Msg;
2330       begin
2331          Error_Msg_Name_1 := Pname;
2332          Fix_Error (MsgF);
2333          Error_Msg_N (MsgF, Arg);
2334          raise Pragma_Exit;
2335       end Error_Pragma_Arg_Ident;
2336
2337       ----------------------
2338       -- Error_Pragma_Ref --
2339       ----------------------
2340
2341       procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is
2342          MsgF : String := Msg;
2343       begin
2344          Error_Msg_Name_1 := Pname;
2345          Fix_Error (MsgF);
2346          Error_Msg_Sloc   := Sloc (Ref);
2347          Error_Msg_NE (MsgF, N, Ref);
2348          raise Pragma_Exit;
2349       end Error_Pragma_Ref;
2350
2351       ------------------------
2352       -- Find_Lib_Unit_Name --
2353       ------------------------
2354
2355       function Find_Lib_Unit_Name return Entity_Id is
2356       begin
2357          --  Return inner compilation unit entity, for case of nested
2358          --  categorization pragmas. This happens in generic unit.
2359
2360          if Nkind (Parent (N)) = N_Package_Specification
2361            and then Defining_Entity (Parent (N)) /= Current_Scope
2362          then
2363             return Defining_Entity (Parent (N));
2364          else
2365             return Current_Scope;
2366          end if;
2367       end Find_Lib_Unit_Name;
2368
2369       ----------------------------
2370       -- Find_Program_Unit_Name --
2371       ----------------------------
2372
2373       procedure Find_Program_Unit_Name (Id : Node_Id) is
2374          Unit_Name : Entity_Id;
2375          Unit_Kind : Node_Kind;
2376          P         : constant Node_Id := Parent (N);
2377
2378       begin
2379          if Nkind (P) = N_Compilation_Unit then
2380             Unit_Kind := Nkind (Unit (P));
2381
2382             if Unit_Kind = N_Subprogram_Declaration
2383               or else Unit_Kind = N_Package_Declaration
2384               or else Unit_Kind in N_Generic_Declaration
2385             then
2386                Unit_Name := Defining_Entity (Unit (P));
2387
2388                if Chars (Id) = Chars (Unit_Name) then
2389                   Set_Entity (Id, Unit_Name);
2390                   Set_Etype (Id, Etype (Unit_Name));
2391                else
2392                   Set_Etype (Id, Any_Type);
2393                   Error_Pragma
2394                     ("cannot find program unit referenced by pragma%");
2395                end if;
2396
2397             else
2398                Set_Etype (Id, Any_Type);
2399                Error_Pragma ("pragma% inapplicable to this unit");
2400             end if;
2401
2402          else
2403             Analyze (Id);
2404          end if;
2405       end Find_Program_Unit_Name;
2406
2407       -----------------------------------------
2408       -- Find_Unique_Parameterless_Procedure --
2409       -----------------------------------------
2410
2411       function Find_Unique_Parameterless_Procedure
2412         (Name : Entity_Id;
2413          Arg  : Node_Id) return Entity_Id
2414       is
2415          Proc : Entity_Id := Empty;
2416
2417       begin
2418          --  The body of this procedure needs some comments ???
2419
2420          if not Is_Entity_Name (Name) then
2421             Error_Pragma_Arg
2422               ("argument of pragma% must be entity name", Arg);
2423
2424          elsif not Is_Overloaded (Name) then
2425             Proc := Entity (Name);
2426
2427             if Ekind (Proc) /= E_Procedure
2428               or else Present (First_Formal (Proc))
2429             then
2430                Error_Pragma_Arg
2431                  ("argument of pragma% must be parameterless procedure", Arg);
2432             end if;
2433
2434          else
2435             declare
2436                Found : Boolean := False;
2437                It    : Interp;
2438                Index : Interp_Index;
2439
2440             begin
2441                Get_First_Interp (Name, Index, It);
2442                while Present (It.Nam) loop
2443                   Proc := It.Nam;
2444
2445                   if Ekind (Proc) = E_Procedure
2446                     and then No (First_Formal (Proc))
2447                   then
2448                      if not Found then
2449                         Found := True;
2450                         Set_Entity (Name, Proc);
2451                         Set_Is_Overloaded (Name, False);
2452                      else
2453                         Error_Pragma_Arg
2454                           ("ambiguous handler name for pragma% ", Arg);
2455                      end if;
2456                   end if;
2457
2458                   Get_Next_Interp (Index, It);
2459                end loop;
2460
2461                if not Found then
2462                   Error_Pragma_Arg
2463                     ("argument of pragma% must be parameterless procedure",
2464                      Arg);
2465                else
2466                   Proc := Entity (Name);
2467                end if;
2468             end;
2469          end if;
2470
2471          return Proc;
2472       end Find_Unique_Parameterless_Procedure;
2473
2474       ---------------
2475       -- Fix_Error --
2476       ---------------
2477
2478       procedure Fix_Error (Msg : in out String) is
2479       begin
2480          if From_Aspect_Specification (N) then
2481             for J in Msg'First .. Msg'Last - 5 loop
2482                if Msg (J .. J + 5) = "pragma" then
2483                   Msg (J .. J + 5) := "aspect";
2484                end if;
2485             end loop;
2486
2487             if Error_Msg_Name_1 = Name_Precondition then
2488                Error_Msg_Name_1 := Name_Pre;
2489             elsif Error_Msg_Name_1 = Name_Postcondition then
2490                Error_Msg_Name_1 := Name_Post;
2491             end if;
2492          end if;
2493       end Fix_Error;
2494
2495       -------------------------
2496       -- Gather_Associations --
2497       -------------------------
2498
2499       procedure Gather_Associations
2500         (Names : Name_List;
2501          Args  : out Args_List)
2502       is
2503          Arg : Node_Id;
2504
2505       begin
2506          --  Initialize all parameters to Empty
2507
2508          for J in Args'Range loop
2509             Args (J) := Empty;
2510          end loop;
2511
2512          --  That's all we have to do if there are no argument associations
2513
2514          if No (Pragma_Argument_Associations (N)) then
2515             return;
2516          end if;
2517
2518          --  Otherwise first deal with any positional parameters present
2519
2520          Arg := First (Pragma_Argument_Associations (N));
2521          for Index in Args'Range loop
2522             exit when No (Arg) or else Chars (Arg) /= No_Name;
2523             Args (Index) := Get_Pragma_Arg (Arg);
2524             Next (Arg);
2525          end loop;
2526
2527          --  Positional parameters all processed, if any left, then we
2528          --  have too many positional parameters.
2529
2530          if Present (Arg) and then Chars (Arg) = No_Name then
2531             Error_Pragma_Arg
2532               ("too many positional associations for pragma%", Arg);
2533          end if;
2534
2535          --  Process named parameters if any are present
2536
2537          while Present (Arg) loop
2538             if Chars (Arg) = No_Name then
2539                Error_Pragma_Arg
2540                  ("positional association cannot follow named association",
2541                   Arg);
2542
2543             else
2544                for Index in Names'Range loop
2545                   if Names (Index) = Chars (Arg) then
2546                      if Present (Args (Index)) then
2547                         Error_Pragma_Arg
2548                           ("duplicate argument association for pragma%", Arg);
2549                      else
2550                         Args (Index) := Get_Pragma_Arg (Arg);
2551                         exit;
2552                      end if;
2553                   end if;
2554
2555                   if Index = Names'Last then
2556                      Error_Msg_Name_1 := Pname;
2557                      Error_Msg_N ("pragma% does not allow & argument", Arg);
2558
2559                      --  Check for possible misspelling
2560
2561                      for Index1 in Names'Range loop
2562                         if Is_Bad_Spelling_Of
2563                              (Chars (Arg), Names (Index1))
2564                         then
2565                            Error_Msg_Name_1 := Names (Index1);
2566                            Error_Msg_N -- CODEFIX
2567                              ("\possible misspelling of%", Arg);
2568                            exit;
2569                         end if;
2570                      end loop;
2571
2572                      raise Pragma_Exit;
2573                   end if;
2574                end loop;
2575             end if;
2576
2577             Next (Arg);
2578          end loop;
2579       end Gather_Associations;
2580
2581       -----------------
2582       -- GNAT_Pragma --
2583       -----------------
2584
2585       procedure GNAT_Pragma is
2586       begin
2587          Check_Restriction (No_Implementation_Pragmas, N);
2588       end GNAT_Pragma;
2589
2590       --------------------------
2591       -- Is_Before_First_Decl --
2592       --------------------------
2593
2594       function Is_Before_First_Decl
2595         (Pragma_Node : Node_Id;
2596          Decls       : List_Id) return Boolean
2597       is
2598          Item : Node_Id := First (Decls);
2599
2600       begin
2601          --  Only other pragmas can come before this pragma
2602
2603          loop
2604             if No (Item) or else Nkind (Item) /= N_Pragma then
2605                return False;
2606
2607             elsif Item = Pragma_Node then
2608                return True;
2609             end if;
2610
2611             Next (Item);
2612          end loop;
2613       end Is_Before_First_Decl;
2614
2615       -----------------------------
2616       -- Is_Configuration_Pragma --
2617       -----------------------------
2618
2619       --  A configuration pragma must appear in the context clause of a
2620       --  compilation unit, and only other pragmas may precede it. Note that
2621       --  the test below also permits use in a configuration pragma file.
2622
2623       function Is_Configuration_Pragma return Boolean is
2624          Lis : constant List_Id := List_Containing (N);
2625          Par : constant Node_Id := Parent (N);
2626          Prg : Node_Id;
2627
2628       begin
2629          --  If no parent, then we are in the configuration pragma file,
2630          --  so the placement is definitely appropriate.
2631
2632          if No (Par) then
2633             return True;
2634
2635          --  Otherwise we must be in the context clause of a compilation unit
2636          --  and the only thing allowed before us in the context list is more
2637          --  configuration pragmas.
2638
2639          elsif Nkind (Par) = N_Compilation_Unit
2640            and then Context_Items (Par) = Lis
2641          then
2642             Prg := First (Lis);
2643
2644             loop
2645                if Prg = N then
2646                   return True;
2647                elsif Nkind (Prg) /= N_Pragma then
2648                   return False;
2649                end if;
2650
2651                Next (Prg);
2652             end loop;
2653
2654          else
2655             return False;
2656          end if;
2657       end Is_Configuration_Pragma;
2658
2659       --------------------------
2660       -- Is_In_Context_Clause --
2661       --------------------------
2662
2663       function Is_In_Context_Clause return Boolean is
2664          Plist       : List_Id;
2665          Parent_Node : Node_Id;
2666
2667       begin
2668          if not Is_List_Member (N) then
2669             return False;
2670
2671          else
2672             Plist := List_Containing (N);
2673             Parent_Node := Parent (Plist);
2674
2675             if Parent_Node = Empty
2676               or else Nkind (Parent_Node) /= N_Compilation_Unit
2677               or else Context_Items (Parent_Node) /= Plist
2678             then
2679                return False;
2680             end if;
2681          end if;
2682
2683          return True;
2684       end Is_In_Context_Clause;
2685
2686       ---------------------------------
2687       -- Is_Static_String_Expression --
2688       ---------------------------------
2689
2690       function Is_Static_String_Expression (Arg : Node_Id) return Boolean is
2691          Argx : constant Node_Id := Get_Pragma_Arg (Arg);
2692
2693       begin
2694          Analyze_And_Resolve (Argx);
2695          return Is_OK_Static_Expression (Argx)
2696            and then Nkind (Argx) = N_String_Literal;
2697       end Is_Static_String_Expression;
2698
2699       ----------------------
2700       -- Pragma_Misplaced --
2701       ----------------------
2702
2703       procedure Pragma_Misplaced is
2704       begin
2705          Error_Pragma ("incorrect placement of pragma%");
2706       end Pragma_Misplaced;
2707
2708       ------------------------------------
2709       -- Process Atomic_Shared_Volatile --
2710       ------------------------------------
2711
2712       procedure Process_Atomic_Shared_Volatile is
2713          E_Id : Node_Id;
2714          E    : Entity_Id;
2715          D    : Node_Id;
2716          K    : Node_Kind;
2717          Utyp : Entity_Id;
2718
2719          procedure Set_Atomic (E : Entity_Id);
2720          --  Set given type as atomic, and if no explicit alignment was given,
2721          --  set alignment to unknown, since back end knows what the alignment
2722          --  requirements are for atomic arrays. Note: this step is necessary
2723          --  for derived types.
2724
2725          ----------------
2726          -- Set_Atomic --
2727          ----------------
2728
2729          procedure Set_Atomic (E : Entity_Id) is
2730          begin
2731             Set_Is_Atomic (E);
2732
2733             if not Has_Alignment_Clause (E) then
2734                Set_Alignment (E, Uint_0);
2735             end if;
2736          end Set_Atomic;
2737
2738       --  Start of processing for Process_Atomic_Shared_Volatile
2739
2740       begin
2741          Check_Ada_83_Warning;
2742          Check_No_Identifiers;
2743          Check_Arg_Count (1);
2744          Check_Arg_Is_Local_Name (Arg1);
2745          E_Id := Get_Pragma_Arg (Arg1);
2746
2747          if Etype (E_Id) = Any_Type then
2748             return;
2749          end if;
2750
2751          E := Entity (E_Id);
2752          D := Declaration_Node (E);
2753          K := Nkind (D);
2754
2755          --  Check duplicate before we chain ourselves!
2756
2757          Check_Duplicate_Pragma (E);
2758
2759          --  Now check appropriateness of the entity
2760
2761          if Is_Type (E) then
2762             if Rep_Item_Too_Early (E, N)
2763                  or else
2764                Rep_Item_Too_Late (E, N)
2765             then
2766                return;
2767             else
2768                Check_First_Subtype (Arg1);
2769             end if;
2770
2771             if Prag_Id /= Pragma_Volatile then
2772                Set_Atomic (E);
2773                Set_Atomic (Underlying_Type (E));
2774                Set_Atomic (Base_Type (E));
2775             end if;
2776
2777             --  Attribute belongs on the base type. If the view of the type is
2778             --  currently private, it also belongs on the underlying type.
2779
2780             Set_Is_Volatile (Base_Type (E));
2781             Set_Is_Volatile (Underlying_Type (E));
2782
2783             Set_Treat_As_Volatile (E);
2784             Set_Treat_As_Volatile (Underlying_Type (E));
2785
2786          elsif K = N_Object_Declaration
2787            or else (K = N_Component_Declaration
2788                      and then Original_Record_Component (E) = E)
2789          then
2790             if Rep_Item_Too_Late (E, N) then
2791                return;
2792             end if;
2793
2794             if Prag_Id /= Pragma_Volatile then
2795                Set_Is_Atomic (E);
2796
2797                --  If the object declaration has an explicit initialization, a
2798                --  temporary may have to be created to hold the expression, to
2799                --  ensure that access to the object remain atomic.
2800
2801                if Nkind (Parent (E)) = N_Object_Declaration
2802                  and then Present (Expression (Parent (E)))
2803                then
2804                   Set_Has_Delayed_Freeze (E);
2805                end if;
2806
2807                --  An interesting improvement here. If an object of type X is
2808                --  declared atomic, and the type X is not atomic, that's a
2809                --  pity, since it may not have appropriate alignment etc. We
2810                --  can rescue this in the special case where the object and
2811                --  type are in the same unit by just setting the type as
2812                --  atomic, so that the back end will process it as atomic.
2813
2814                Utyp := Underlying_Type (Etype (E));
2815
2816                if Present (Utyp)
2817                  and then Sloc (E) > No_Location
2818                  and then Sloc (Utyp) > No_Location
2819                  and then
2820                    Get_Source_File_Index (Sloc (E)) =
2821                    Get_Source_File_Index (Sloc (Underlying_Type (Etype (E))))
2822                then
2823                   Set_Is_Atomic (Underlying_Type (Etype (E)));
2824                end if;
2825             end if;
2826
2827             Set_Is_Volatile (E);
2828             Set_Treat_As_Volatile (E);
2829
2830          else
2831             Error_Pragma_Arg
2832               ("inappropriate entity for pragma%", Arg1);
2833          end if;
2834       end Process_Atomic_Shared_Volatile;
2835
2836       -------------------------------------------
2837       -- Process_Compile_Time_Warning_Or_Error --
2838       -------------------------------------------
2839
2840       procedure Process_Compile_Time_Warning_Or_Error is
2841          Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1);
2842
2843       begin
2844          Check_Arg_Count (2);
2845          Check_No_Identifiers;
2846          Check_Arg_Is_Static_Expression (Arg2, Standard_String);
2847          Analyze_And_Resolve (Arg1x, Standard_Boolean);
2848
2849          if Compile_Time_Known_Value (Arg1x) then
2850             if Is_True (Expr_Value (Get_Pragma_Arg (Arg1))) then
2851                declare
2852                   Str   : constant String_Id :=
2853                             Strval (Get_Pragma_Arg (Arg2));
2854                   Len   : constant Int := String_Length (Str);
2855                   Cont  : Boolean;
2856                   Ptr   : Nat;
2857                   CC    : Char_Code;
2858                   C     : Character;
2859                   Cent  : constant Entity_Id :=
2860                             Cunit_Entity (Current_Sem_Unit);
2861
2862                   Force : constant Boolean :=
2863                             Prag_Id = Pragma_Compile_Time_Warning
2864                               and then
2865                                 Is_Spec_Name (Unit_Name (Current_Sem_Unit))
2866                               and then (Ekind (Cent) /= E_Package
2867                                           or else not In_Private_Part (Cent));
2868                   --  Set True if this is the warning case, and we are in the
2869                   --  visible part of a package spec, or in a subprogram spec,
2870                   --  in which case we want to force the client to see the
2871                   --  warning, even though it is not in the main unit.
2872
2873                begin
2874                   --  Loop through segments of message separated by line feeds.
2875                   --  We output these segments as separate messages with
2876                   --  continuation marks for all but the first.
2877
2878                   Cont := False;
2879                   Ptr := 1;
2880                   loop
2881                      Error_Msg_Strlen := 0;
2882
2883                      --  Loop to copy characters from argument to error message
2884                      --  string buffer.
2885
2886                      loop
2887                         exit when Ptr > Len;
2888                         CC := Get_String_Char (Str, Ptr);
2889                         Ptr := Ptr + 1;
2890
2891                         --  Ignore wide chars ??? else store character
2892
2893                         if In_Character_Range (CC) then
2894                            C := Get_Character (CC);
2895                            exit when C = ASCII.LF;
2896                            Error_Msg_Strlen := Error_Msg_Strlen + 1;
2897                            Error_Msg_String (Error_Msg_Strlen) := C;
2898                         end if;
2899                      end loop;
2900
2901                      --  Here with one line ready to go
2902
2903                      Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning;
2904
2905                      --  If this is a warning in a spec, then we want clients
2906                      --  to see the warning, so mark the message with the
2907                      --  special sequence !! to force the warning. In the case
2908                      --  of a package spec, we do not force this if we are in
2909                      --  the private part of the spec.
2910
2911                      if Force then
2912                         if Cont = False then
2913                            Error_Msg_N ("<~!!", Arg1);
2914                            Cont := True;
2915                         else
2916                            Error_Msg_N ("\<~!!", Arg1);
2917                         end if;
2918
2919                      --  Error, rather than warning, or in a body, so we do not
2920                      --  need to force visibility for client (error will be
2921                      --  output in any case, and this is the situation in which
2922                      --  we do not want a client to get a warning, since the
2923                      --  warning is in the body or the spec private part).
2924
2925                      else
2926                         if Cont = False then
2927                            Error_Msg_N ("<~", Arg1);
2928                            Cont := True;
2929                         else
2930                            Error_Msg_N ("\<~", Arg1);
2931                         end if;
2932                      end if;
2933
2934                      exit when Ptr > Len;
2935                   end loop;
2936                end;
2937             end if;
2938          end if;
2939       end Process_Compile_Time_Warning_Or_Error;
2940
2941       ------------------------
2942       -- Process_Convention --
2943       ------------------------
2944
2945       procedure Process_Convention
2946         (C   : out Convention_Id;
2947          Ent : out Entity_Id)
2948       is
2949          Id        : Node_Id;
2950          E         : Entity_Id;
2951          E1        : Entity_Id;
2952          Cname     : Name_Id;
2953          Comp_Unit : Unit_Number_Type;
2954
2955          procedure Diagnose_Multiple_Pragmas (S : Entity_Id);
2956          --  Called if we have more than one Export/Import/Convention pragma.
2957          --  This is generally illegal, but we have a special case of allowing
2958          --  Import and Interface to coexist if they specify the convention in
2959          --  a consistent manner. We are allowed to do this, since Interface is
2960          --  an implementation defined pragma, and we choose to do it since we
2961          --  know Rational allows this combination. S is the entity id of the
2962          --  subprogram in question. This procedure also sets the special flag
2963          --  Import_Interface_Present in both pragmas in the case where we do
2964          --  have matching Import and Interface pragmas.
2965
2966          procedure Set_Convention_From_Pragma (E : Entity_Id);
2967          --  Set convention in entity E, and also flag that the entity has a
2968          --  convention pragma. If entity is for a private or incomplete type,
2969          --  also set convention and flag on underlying type. This procedure
2970          --  also deals with the special case of C_Pass_By_Copy convention.
2971
2972          -------------------------------
2973          -- Diagnose_Multiple_Pragmas --
2974          -------------------------------
2975
2976          procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is
2977             Pdec : constant Node_Id := Declaration_Node (S);
2978             Decl : Node_Id;
2979             Err  : Boolean;
2980
2981             function Same_Convention (Decl : Node_Id) return Boolean;
2982             --  Decl is a pragma node. This function returns True if this
2983             --  pragma has a first argument that is an identifier with a
2984             --  Chars field corresponding to the Convention_Id C.
2985
2986             function Same_Name (Decl : Node_Id) return Boolean;
2987             --  Decl is a pragma node. This function returns True if this
2988             --  pragma has a second argument that is an identifier with a
2989             --  Chars field that matches the Chars of the current subprogram.
2990
2991             ---------------------
2992             -- Same_Convention --
2993             ---------------------
2994
2995             function Same_Convention (Decl : Node_Id) return Boolean is
2996                Arg1 : constant Node_Id :=
2997                         First (Pragma_Argument_Associations (Decl));
2998
2999             begin
3000                if Present (Arg1) then
3001                   declare
3002                      Arg : constant Node_Id := Get_Pragma_Arg (Arg1);
3003                   begin
3004                      if Nkind (Arg) = N_Identifier
3005                        and then Is_Convention_Name (Chars (Arg))
3006                        and then Get_Convention_Id (Chars (Arg)) = C
3007                      then
3008                         return True;
3009                      end if;
3010                   end;
3011                end if;
3012
3013                return False;
3014             end Same_Convention;
3015
3016             ---------------
3017             -- Same_Name --
3018             ---------------
3019
3020             function Same_Name (Decl : Node_Id) return Boolean is
3021                Arg1 : constant Node_Id :=
3022                         First (Pragma_Argument_Associations (Decl));
3023                Arg2 : Node_Id;
3024
3025             begin
3026                if No (Arg1) then
3027                   return False;
3028                end if;
3029
3030                Arg2 := Next (Arg1);
3031
3032                if No (Arg2) then
3033                   return False;
3034                end if;
3035
3036                declare
3037                   Arg : constant Node_Id := Get_Pragma_Arg (Arg2);
3038                begin
3039                   if Nkind (Arg) = N_Identifier
3040                     and then Chars (Arg) = Chars (S)
3041                   then
3042                      return True;
3043                   end if;
3044                end;
3045
3046                return False;
3047             end Same_Name;
3048
3049          --  Start of processing for Diagnose_Multiple_Pragmas
3050
3051          begin
3052             Err := True;
3053
3054             --  Definitely give message if we have Convention/Export here
3055
3056             if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then
3057                null;
3058
3059                --  If we have an Import or Export, scan back from pragma to
3060                --  find any previous pragma applying to the same procedure.
3061                --  The scan will be terminated by the start of the list, or
3062                --  hitting the subprogram declaration. This won't allow one
3063                --  pragma to appear in the public part and one in the private
3064                --  part, but that seems very unlikely in practice.
3065
3066             else
3067                Decl := Prev (N);
3068                while Present (Decl) and then Decl /= Pdec loop
3069
3070                   --  Look for pragma with same name as us
3071
3072                   if Nkind (Decl) = N_Pragma
3073                     and then Same_Name (Decl)
3074                   then
3075                      --  Give error if same as our pragma or Export/Convention
3076
3077                      if Pragma_Name (Decl) = Name_Export
3078                           or else
3079                         Pragma_Name (Decl) = Name_Convention
3080                           or else
3081                         Pragma_Name (Decl) = Pragma_Name (N)
3082                      then
3083                         exit;
3084
3085                      --  Case of Import/Interface or the other way round
3086
3087                      elsif Pragma_Name (Decl) = Name_Interface
3088                              or else
3089                            Pragma_Name (Decl) = Name_Import
3090                      then
3091                         --  Here we know that we have Import and Interface. It
3092                         --  doesn't matter which way round they are. See if
3093                         --  they specify the same convention. If so, all OK,
3094                         --  and set special flags to stop other messages
3095
3096                         if Same_Convention (Decl) then
3097                            Set_Import_Interface_Present (N);
3098                            Set_Import_Interface_Present (Decl);
3099                            Err := False;
3100
3101                         --  If different conventions, special message
3102
3103                         else
3104                            Error_Msg_Sloc := Sloc (Decl);
3105                            Error_Pragma_Arg
3106                              ("convention differs from that given#", Arg1);
3107                            return;
3108                         end if;
3109                      end if;
3110                   end if;
3111
3112                   Next (Decl);
3113                end loop;
3114             end if;
3115
3116             --  Give message if needed if we fall through those tests
3117
3118             if Err then
3119                Error_Pragma_Arg
3120                  ("at most one Convention/Export/Import pragma is allowed",
3121                   Arg2);
3122             end if;
3123          end Diagnose_Multiple_Pragmas;
3124
3125          --------------------------------
3126          -- Set_Convention_From_Pragma --
3127          --------------------------------
3128
3129          procedure Set_Convention_From_Pragma (E : Entity_Id) is
3130          begin
3131             --  Ada 2005 (AI-430): Check invalid attempt to change convention
3132             --  for an overridden dispatching operation. Technically this is
3133             --  an amendment and should only be done in Ada 2005 mode. However,
3134             --  this is clearly a mistake, since the problem that is addressed
3135             --  by this AI is that there is a clear gap in the RM!
3136
3137             if Is_Dispatching_Operation (E)
3138               and then Present (Overridden_Operation (E))
3139               and then C /= Convention (Overridden_Operation (E))
3140             then
3141                Error_Pragma_Arg
3142                  ("cannot change convention for " &
3143                   "overridden dispatching operation",
3144                   Arg1);
3145             end if;
3146
3147             --  Set the convention
3148
3149             Set_Convention (E, C);
3150             Set_Has_Convention_Pragma (E);
3151
3152             if Is_Incomplete_Or_Private_Type (E)
3153               and then Present (Underlying_Type (E))
3154             then
3155                Set_Convention            (Underlying_Type (E), C);
3156                Set_Has_Convention_Pragma (Underlying_Type (E), True);
3157             end if;
3158
3159             --  A class-wide type should inherit the convention of the specific
3160             --  root type (although this isn't specified clearly by the RM).
3161
3162             if Is_Type (E) and then Present (Class_Wide_Type (E)) then
3163                Set_Convention (Class_Wide_Type (E), C);
3164             end if;
3165
3166             --  If the entity is a record type, then check for special case of
3167             --  C_Pass_By_Copy, which is treated the same as C except that the
3168             --  special record flag is set. This convention is only permitted
3169             --  on record types (see AI95-00131).
3170
3171             if Cname = Name_C_Pass_By_Copy then
3172                if Is_Record_Type (E) then
3173                   Set_C_Pass_By_Copy (Base_Type (E));
3174                elsif Is_Incomplete_Or_Private_Type (E)
3175                  and then Is_Record_Type (Underlying_Type (E))
3176                then
3177                   Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E)));
3178                else
3179                   Error_Pragma_Arg
3180                     ("C_Pass_By_Copy convention allowed only for record type",
3181                      Arg2);
3182                end if;
3183             end if;
3184
3185             --  If the entity is a derived boolean type, check for the special
3186             --  case of convention C, C++, or Fortran, where we consider any
3187             --  nonzero value to represent true.
3188
3189             if Is_Discrete_Type (E)
3190               and then Root_Type (Etype (E)) = Standard_Boolean
3191               and then
3192                 (C = Convention_C
3193                    or else
3194                  C = Convention_CPP
3195                    or else
3196                  C = Convention_Fortran)
3197             then
3198                Set_Nonzero_Is_True (Base_Type (E));
3199             end if;
3200          end Set_Convention_From_Pragma;
3201
3202       --  Start of processing for Process_Convention
3203
3204       begin
3205          Check_At_Least_N_Arguments (2);
3206          Check_Optional_Identifier (Arg1, Name_Convention);
3207          Check_Arg_Is_Identifier (Arg1);
3208          Cname := Chars (Get_Pragma_Arg (Arg1));
3209
3210          --  C_Pass_By_Copy is treated as a synonym for convention C (this is
3211          --  tested again below to set the critical flag).
3212
3213          if Cname = Name_C_Pass_By_Copy then
3214             C := Convention_C;
3215
3216          --  Otherwise we must have something in the standard convention list
3217
3218          elsif Is_Convention_Name (Cname) then
3219             C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1)));
3220
3221          --  In DEC VMS, it seems that there is an undocumented feature that
3222          --  any unrecognized convention is treated as the default, which for
3223          --  us is convention C. It does not seem so terrible to do this
3224          --  unconditionally, silently in the VMS case, and with a warning
3225          --  in the non-VMS case.
3226
3227          else
3228             if Warn_On_Export_Import and not OpenVMS_On_Target then
3229                Error_Msg_N
3230                  ("?unrecognized convention name, C assumed",
3231                   Get_Pragma_Arg (Arg1));
3232             end if;
3233
3234             C := Convention_C;
3235          end if;
3236
3237          Check_Optional_Identifier (Arg2, Name_Entity);
3238          Check_Arg_Is_Local_Name (Arg2);
3239
3240          Id := Get_Pragma_Arg (Arg2);
3241          Analyze (Id);
3242
3243          if not Is_Entity_Name (Id) then
3244             Error_Pragma_Arg ("entity name required", Arg2);
3245          end if;
3246
3247          E := Entity (Id);
3248
3249          --  Set entity to return
3250
3251          Ent := E;
3252
3253          --  Ada_Pass_By_Copy special checking
3254
3255          if C = Convention_Ada_Pass_By_Copy then
3256             if not Is_First_Subtype (E) then
3257                Error_Pragma_Arg
3258                  ("convention `Ada_Pass_By_Copy` only "
3259                   & "allowed for types", Arg2);
3260             end if;
3261
3262             if Is_By_Reference_Type (E) then
3263                Error_Pragma_Arg
3264                  ("convention `Ada_Pass_By_Copy` not allowed for "
3265                   & "by-reference type", Arg1);
3266             end if;
3267          end if;
3268
3269          --  Ada_Pass_By_Reference special checking
3270
3271          if C = Convention_Ada_Pass_By_Reference then
3272             if not Is_First_Subtype (E) then
3273                Error_Pragma_Arg
3274                  ("convention `Ada_Pass_By_Reference` only "
3275                   & "allowed for types", Arg2);
3276             end if;
3277
3278             if Is_By_Copy_Type (E) then
3279                Error_Pragma_Arg
3280                  ("convention `Ada_Pass_By_Reference` not allowed for "
3281                   & "by-copy type", Arg1);
3282             end if;
3283          end if;
3284
3285          --  Go to renamed subprogram if present, since convention applies to
3286          --  the actual renamed entity, not to the renaming entity. If the
3287          --  subprogram is inherited, go to parent subprogram.
3288
3289          if Is_Subprogram (E)
3290            and then Present (Alias (E))
3291          then
3292             if Nkind (Parent (Declaration_Node (E))) =
3293                                        N_Subprogram_Renaming_Declaration
3294             then
3295                if Scope (E) /= Scope (Alias (E)) then
3296                   Error_Pragma_Ref
3297                     ("cannot apply pragma% to non-local entity&#", E);
3298                end if;
3299
3300                E := Alias (E);
3301
3302             elsif Nkind_In (Parent (E), N_Full_Type_Declaration,
3303                                         N_Private_Extension_Declaration)
3304               and then Scope (E) = Scope (Alias (E))
3305             then
3306                E := Alias (E);
3307
3308                --  Return the parent subprogram the entity was inherited from
3309
3310                Ent := E;
3311             end if;
3312          end if;
3313
3314          --  Check that we are not applying this to a specless body
3315
3316          if Is_Subprogram (E)
3317            and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body
3318          then
3319             Error_Pragma
3320               ("pragma% requires separate spec and must come before body");
3321          end if;
3322
3323          --  Check that we are not applying this to a named constant
3324
3325          if Ekind_In (E, E_Named_Integer, E_Named_Real) then
3326             Error_Msg_Name_1 := Pname;
3327             Error_Msg_N
3328               ("cannot apply pragma% to named constant!",
3329                Get_Pragma_Arg (Arg2));
3330             Error_Pragma_Arg
3331               ("\supply appropriate type for&!", Arg2);
3332          end if;
3333
3334          if Ekind (E) = E_Enumeration_Literal then
3335             Error_Pragma ("enumeration literal not allowed for pragma%");
3336          end if;
3337
3338          --  Check for rep item appearing too early or too late
3339
3340          if Etype (E) = Any_Type
3341            or else Rep_Item_Too_Early (E, N)
3342          then
3343             raise Pragma_Exit;
3344
3345          elsif Present (Underlying_Type (E)) then
3346             E := Underlying_Type (E);
3347          end if;
3348
3349          if Rep_Item_Too_Late (E, N) then
3350             raise Pragma_Exit;
3351          end if;
3352
3353          if Has_Convention_Pragma (E) then
3354             Diagnose_Multiple_Pragmas (E);
3355
3356          elsif Convention (E) = Convention_Protected
3357            or else Ekind (Scope (E)) = E_Protected_Type
3358          then
3359             Error_Pragma_Arg
3360               ("a protected operation cannot be given a different convention",
3361                 Arg2);
3362          end if;
3363
3364          --  For Intrinsic, a subprogram is required
3365
3366          if C = Convention_Intrinsic
3367            and then not Is_Subprogram (E)
3368            and then not Is_Generic_Subprogram (E)
3369          then
3370             Error_Pragma_Arg
3371               ("second argument of pragma% must be a subprogram", Arg2);
3372          end if;
3373
3374          --  For Stdcall, a subprogram, variable or subprogram type is required
3375
3376          if C = Convention_Stdcall
3377            and then not Is_Subprogram (E)
3378            and then not Is_Generic_Subprogram (E)
3379            and then Ekind (E) /= E_Variable
3380            and then not
3381              (Is_Access_Type (E)
3382                and then Ekind (Designated_Type (E)) = E_Subprogram_Type)
3383          then
3384             Error_Pragma_Arg
3385               ("second argument of pragma% must be subprogram (type)",
3386                Arg2);
3387          end if;
3388
3389          if not Is_Subprogram (E)
3390            and then not Is_Generic_Subprogram (E)
3391          then
3392             Set_Convention_From_Pragma (E);
3393
3394             if Is_Type (E) then
3395                Check_First_Subtype (Arg2);
3396                Set_Convention_From_Pragma (Base_Type (E));
3397
3398                --  For subprograms, we must set the convention on the
3399                --  internally generated directly designated type as well.
3400
3401                if Ekind (E) = E_Access_Subprogram_Type then
3402                   Set_Convention_From_Pragma (Directly_Designated_Type (E));
3403                end if;
3404             end if;
3405
3406          --  For the subprogram case, set proper convention for all homonyms
3407          --  in same scope and the same declarative part, i.e. the same
3408          --  compilation unit.
3409
3410          else
3411             Comp_Unit := Get_Source_Unit (E);
3412             Set_Convention_From_Pragma (E);
3413
3414             --  Treat a pragma Import as an implicit body, for GPS use
3415
3416             if Prag_Id = Pragma_Import then
3417                Generate_Reference (E, Id, 'b');
3418             end if;
3419
3420             --  Loop through the homonyms of the pragma argument's entity
3421
3422             E1 := Ent;
3423             loop
3424                E1 := Homonym (E1);
3425                exit when No (E1) or else Scope (E1) /= Current_Scope;
3426
3427                --  Do not set the pragma on inherited operations or on formal
3428                --  subprograms.
3429
3430                if Comes_From_Source (E1)
3431                  and then Comp_Unit = Get_Source_Unit (E1)
3432                  and then not Is_Formal_Subprogram (E1)
3433                  and then Nkind (Original_Node (Parent (E1))) /=
3434                                                     N_Full_Type_Declaration
3435                then
3436                   if Present (Alias (E1))
3437                     and then Scope (E1) /= Scope (Alias (E1))
3438                   then
3439                      Error_Pragma_Ref
3440                        ("cannot apply pragma% to non-local entity& declared#",
3441                         E1);
3442                   end if;
3443
3444                   Set_Convention_From_Pragma (E1);
3445
3446                   if Prag_Id = Pragma_Import then
3447                      Generate_Reference (E1, Id, 'b');
3448                   end if;
3449                end if;
3450
3451                --  For aspect case, do NOT apply to homonyms
3452
3453                exit when From_Aspect_Specification (N);
3454             end loop;
3455          end if;
3456       end Process_Convention;
3457
3458       -----------------------------------------------------
3459       -- Process_Extended_Import_Export_Exception_Pragma --
3460       -----------------------------------------------------
3461
3462       procedure Process_Extended_Import_Export_Exception_Pragma
3463         (Arg_Internal : Node_Id;
3464          Arg_External : Node_Id;
3465          Arg_Form     : Node_Id;
3466          Arg_Code     : Node_Id)
3467       is
3468          Def_Id   : Entity_Id;
3469          Code_Val : Uint;
3470
3471       begin
3472          if not OpenVMS_On_Target then
3473             Error_Pragma
3474               ("?pragma% ignored (applies only to Open'V'M'S)");
3475          end if;
3476
3477          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3478          Def_Id := Entity (Arg_Internal);
3479
3480          if Ekind (Def_Id) /= E_Exception then
3481             Error_Pragma_Arg
3482               ("pragma% must refer to declared exception", Arg_Internal);
3483          end if;
3484
3485          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3486
3487          if Present (Arg_Form) then
3488             Check_Arg_Is_One_Of (Arg_Form, Name_Ada, Name_VMS);
3489          end if;
3490
3491          if Present (Arg_Form)
3492            and then Chars (Arg_Form) = Name_Ada
3493          then
3494             null;
3495          else
3496             Set_Is_VMS_Exception (Def_Id);
3497             Set_Exception_Code (Def_Id, No_Uint);
3498          end if;
3499
3500          if Present (Arg_Code) then
3501             if not Is_VMS_Exception (Def_Id) then
3502                Error_Pragma_Arg
3503                  ("Code option for pragma% not allowed for Ada case",
3504                   Arg_Code);
3505             end if;
3506
3507             Check_Arg_Is_Static_Expression (Arg_Code, Any_Integer);
3508             Code_Val := Expr_Value (Arg_Code);
3509
3510             if not UI_Is_In_Int_Range (Code_Val) then
3511                Error_Pragma_Arg
3512                  ("Code option for pragma% must be in 32-bit range",
3513                   Arg_Code);
3514
3515             else
3516                Set_Exception_Code (Def_Id, Code_Val);
3517             end if;
3518          end if;
3519       end Process_Extended_Import_Export_Exception_Pragma;
3520
3521       -------------------------------------------------
3522       -- Process_Extended_Import_Export_Internal_Arg --
3523       -------------------------------------------------
3524
3525       procedure Process_Extended_Import_Export_Internal_Arg
3526         (Arg_Internal : Node_Id := Empty)
3527       is
3528       begin
3529          if No (Arg_Internal) then
3530             Error_Pragma ("Internal parameter required for pragma%");
3531          end if;
3532
3533          if Nkind (Arg_Internal) = N_Identifier then
3534             null;
3535
3536          elsif Nkind (Arg_Internal) = N_Operator_Symbol
3537            and then (Prag_Id = Pragma_Import_Function
3538                        or else
3539                      Prag_Id = Pragma_Export_Function)
3540          then
3541             null;
3542
3543          else
3544             Error_Pragma_Arg
3545               ("wrong form for Internal parameter for pragma%", Arg_Internal);
3546          end if;
3547
3548          Check_Arg_Is_Local_Name (Arg_Internal);
3549       end Process_Extended_Import_Export_Internal_Arg;
3550
3551       --------------------------------------------------
3552       -- Process_Extended_Import_Export_Object_Pragma --
3553       --------------------------------------------------
3554
3555       procedure Process_Extended_Import_Export_Object_Pragma
3556         (Arg_Internal : Node_Id;
3557          Arg_External : Node_Id;
3558          Arg_Size     : Node_Id)
3559       is
3560          Def_Id : Entity_Id;
3561
3562       begin
3563          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3564          Def_Id := Entity (Arg_Internal);
3565
3566          if not Ekind_In (Def_Id, E_Constant, E_Variable) then
3567             Error_Pragma_Arg
3568               ("pragma% must designate an object", Arg_Internal);
3569          end if;
3570
3571          if Has_Rep_Pragma (Def_Id, Name_Common_Object)
3572               or else
3573             Has_Rep_Pragma (Def_Id, Name_Psect_Object)
3574          then
3575             Error_Pragma_Arg
3576               ("previous Common/Psect_Object applies, pragma % not permitted",
3577                Arg_Internal);
3578          end if;
3579
3580          if Rep_Item_Too_Late (Def_Id, N) then
3581             raise Pragma_Exit;
3582          end if;
3583
3584          Set_Extended_Import_Export_External_Name (Def_Id, Arg_External);
3585
3586          if Present (Arg_Size) then
3587             Check_Arg_Is_External_Name (Arg_Size);
3588          end if;
3589
3590          --  Export_Object case
3591
3592          if Prag_Id = Pragma_Export_Object then
3593             if not Is_Library_Level_Entity (Def_Id) then
3594                Error_Pragma_Arg
3595                  ("argument for pragma% must be library level entity",
3596                   Arg_Internal);
3597             end if;
3598
3599             if Ekind (Current_Scope) = E_Generic_Package then
3600                Error_Pragma ("pragma& cannot appear in a generic unit");
3601             end if;
3602
3603             if not Size_Known_At_Compile_Time (Etype (Def_Id)) then
3604                Error_Pragma_Arg
3605                  ("exported object must have compile time known size",
3606                   Arg_Internal);
3607             end if;
3608
3609             if Warn_On_Export_Import and then Is_Exported (Def_Id) then
3610                Error_Msg_N ("?duplicate Export_Object pragma", N);
3611             else
3612                Set_Exported (Def_Id, Arg_Internal);
3613             end if;
3614
3615          --  Import_Object case
3616
3617          else
3618             if Is_Concurrent_Type (Etype (Def_Id)) then
3619                Error_Pragma_Arg
3620                  ("cannot use pragma% for task/protected object",
3621                   Arg_Internal);
3622             end if;
3623
3624             if Ekind (Def_Id) = E_Constant then
3625                Error_Pragma_Arg
3626                  ("cannot import a constant", Arg_Internal);
3627             end if;
3628
3629             if Warn_On_Export_Import
3630               and then Has_Discriminants (Etype (Def_Id))
3631             then
3632                Error_Msg_N
3633                  ("imported value must be initialized?", Arg_Internal);
3634             end if;
3635
3636             if Warn_On_Export_Import
3637               and then Is_Access_Type (Etype (Def_Id))
3638             then
3639                Error_Pragma_Arg
3640                  ("cannot import object of an access type?", Arg_Internal);
3641             end if;
3642
3643             if Warn_On_Export_Import
3644               and then Is_Imported (Def_Id)
3645             then
3646                Error_Msg_N
3647                  ("?duplicate Import_Object pragma", N);
3648
3649             --  Check for explicit initialization present. Note that an
3650             --  initialization generated by the code generator, e.g. for an
3651             --  access type, does not count here.
3652
3653             elsif Present (Expression (Parent (Def_Id)))
3654                and then
3655                  Comes_From_Source
3656                    (Original_Node (Expression (Parent (Def_Id))))
3657             then
3658                Error_Msg_Sloc := Sloc (Def_Id);
3659                Error_Pragma_Arg
3660                  ("imported entities cannot be initialized (RM B.1(24))",
3661                   "\no initialization allowed for & declared#", Arg1);
3662             else
3663                Set_Imported (Def_Id);
3664                Note_Possible_Modification (Arg_Internal, Sure => False);
3665             end if;
3666          end if;
3667       end Process_Extended_Import_Export_Object_Pragma;
3668
3669       ------------------------------------------------------
3670       -- Process_Extended_Import_Export_Subprogram_Pragma --
3671       ------------------------------------------------------
3672
3673       procedure Process_Extended_Import_Export_Subprogram_Pragma
3674         (Arg_Internal                 : Node_Id;
3675          Arg_External                 : Node_Id;
3676          Arg_Parameter_Types          : Node_Id;
3677          Arg_Result_Type              : Node_Id := Empty;
3678          Arg_Mechanism                : Node_Id;
3679          Arg_Result_Mechanism         : Node_Id := Empty;
3680          Arg_First_Optional_Parameter : Node_Id := Empty)
3681       is
3682          Ent       : Entity_Id;
3683          Def_Id    : Entity_Id;
3684          Hom_Id    : Entity_Id;
3685          Formal    : Entity_Id;
3686          Ambiguous : Boolean;
3687          Match     : Boolean;
3688          Dval      : Node_Id;
3689
3690          function Same_Base_Type
3691           (Ptype  : Node_Id;
3692            Formal : Entity_Id) return Boolean;
3693          --  Determines if Ptype references the type of Formal. Note that only
3694          --  the base types need to match according to the spec. Ptype here is
3695          --  the argument from the pragma, which is either a type name, or an
3696          --  access attribute.
3697
3698          --------------------
3699          -- Same_Base_Type --
3700          --------------------
3701
3702          function Same_Base_Type
3703            (Ptype  : Node_Id;
3704             Formal : Entity_Id) return Boolean
3705          is
3706             Ftyp : constant Entity_Id := Base_Type (Etype (Formal));
3707             Pref : Node_Id;
3708
3709          begin
3710             --  Case where pragma argument is typ'Access
3711
3712             if Nkind (Ptype) = N_Attribute_Reference
3713               and then Attribute_Name (Ptype) = Name_Access
3714             then
3715                Pref := Prefix (Ptype);
3716                Find_Type (Pref);
3717
3718                if not Is_Entity_Name (Pref)
3719                  or else Entity (Pref) = Any_Type
3720                then
3721                   raise Pragma_Exit;
3722                end if;
3723
3724                --  We have a match if the corresponding argument is of an
3725                --  anonymous access type, and its designated type matches the
3726                --  type of the prefix of the access attribute
3727
3728                return Ekind (Ftyp) = E_Anonymous_Access_Type
3729                  and then Base_Type (Entity (Pref)) =
3730                             Base_Type (Etype (Designated_Type (Ftyp)));
3731
3732             --  Case where pragma argument is a type name
3733
3734             else
3735                Find_Type (Ptype);
3736
3737                if not Is_Entity_Name (Ptype)
3738                  or else Entity (Ptype) = Any_Type
3739                then
3740                   raise Pragma_Exit;
3741                end if;
3742
3743                --  We have a match if the corresponding argument is of the type
3744                --  given in the pragma (comparing base types)
3745
3746                return Base_Type (Entity (Ptype)) = Ftyp;
3747             end if;
3748          end Same_Base_Type;
3749
3750       --  Start of processing for
3751       --  Process_Extended_Import_Export_Subprogram_Pragma
3752
3753       begin
3754          Process_Extended_Import_Export_Internal_Arg (Arg_Internal);
3755          Ent := Empty;
3756          Ambiguous := False;
3757
3758          --  Loop through homonyms (overloadings) of the entity
3759
3760          Hom_Id := Entity (Arg_Internal);
3761          while Present (Hom_Id) loop
3762             Def_Id := Get_Base_Subprogram (Hom_Id);
3763
3764             --  We need a subprogram in the current scope
3765
3766             if not Is_Subprogram (Def_Id)
3767               or else Scope (Def_Id) /= Current_Scope
3768             then
3769                null;
3770
3771             else
3772                Match := True;
3773
3774                --  Pragma cannot apply to subprogram body
3775
3776                if Is_Subprogram (Def_Id)
3777                  and then Nkind (Parent (Declaration_Node (Def_Id))) =
3778                                                              N_Subprogram_Body
3779                then
3780                   Error_Pragma
3781                     ("pragma% requires separate spec"
3782                       & " and must come before body");
3783                end if;
3784
3785                --  Test result type if given, note that the result type
3786                --  parameter can only be present for the function cases.
3787
3788                if Present (Arg_Result_Type)
3789                  and then not Same_Base_Type (Arg_Result_Type, Def_Id)
3790                then
3791                   Match := False;
3792
3793                elsif Etype (Def_Id) /= Standard_Void_Type
3794                  and then
3795                    (Pname = Name_Export_Procedure
3796                       or else
3797                     Pname = Name_Import_Procedure)
3798                then
3799                   Match := False;
3800
3801                --  Test parameter types if given. Note that this parameter
3802                --  has not been analyzed (and must not be, since it is
3803                --  semantic nonsense), so we get it as the parser left it.
3804
3805                elsif Present (Arg_Parameter_Types) then
3806                   Check_Matching_Types : declare
3807                      Formal : Entity_Id;
3808                      Ptype  : Node_Id;
3809
3810                   begin
3811                      Formal := First_Formal (Def_Id);
3812
3813                      if Nkind (Arg_Parameter_Types) = N_Null then
3814                         if Present (Formal) then
3815                            Match := False;
3816                         end if;
3817
3818                      --  A list of one type, e.g. (List) is parsed as
3819                      --  a parenthesized expression.
3820
3821                      elsif Nkind (Arg_Parameter_Types) /= N_Aggregate
3822                        and then Paren_Count (Arg_Parameter_Types) = 1
3823                      then
3824                         if No (Formal)
3825                           or else Present (Next_Formal (Formal))
3826                         then
3827                            Match := False;
3828                         else
3829                            Match :=
3830                              Same_Base_Type (Arg_Parameter_Types, Formal);
3831                         end if;
3832
3833                      --  A list of more than one type is parsed as a aggregate
3834
3835                      elsif Nkind (Arg_Parameter_Types) = N_Aggregate
3836                        and then Paren_Count (Arg_Parameter_Types) = 0
3837                      then
3838                         Ptype := First (Expressions (Arg_Parameter_Types));
3839                         while Present (Ptype) or else Present (Formal) loop
3840                            if No (Ptype)
3841                              or else No (Formal)
3842                              or else not Same_Base_Type (Ptype, Formal)
3843                            then
3844                               Match := False;
3845                               exit;
3846                            else
3847                               Next_Formal (Formal);
3848                               Next (Ptype);
3849                            end if;
3850                         end loop;
3851
3852                      --  Anything else is of the wrong form
3853
3854                      else
3855                         Error_Pragma_Arg
3856                           ("wrong form for Parameter_Types parameter",
3857                            Arg_Parameter_Types);
3858                      end if;
3859                   end Check_Matching_Types;
3860                end if;
3861
3862                --  Match is now False if the entry we found did not match
3863                --  either a supplied Parameter_Types or Result_Types argument
3864
3865                if Match then
3866                   if No (Ent) then
3867                      Ent := Def_Id;
3868
3869                   --  Ambiguous case, the flag Ambiguous shows if we already
3870                   --  detected this and output the initial messages.
3871
3872                   else
3873                      if not Ambiguous then
3874                         Ambiguous := True;
3875                         Error_Msg_Name_1 := Pname;
3876                         Error_Msg_N
3877                           ("pragma% does not uniquely identify subprogram!",
3878                            N);
3879                         Error_Msg_Sloc := Sloc (Ent);
3880                         Error_Msg_N ("matching subprogram #!", N);
3881                         Ent := Empty;
3882                      end if;
3883
3884                      Error_Msg_Sloc := Sloc (Def_Id);
3885                      Error_Msg_N ("matching subprogram #!", N);
3886                   end if;
3887                end if;
3888             end if;
3889
3890             Hom_Id := Homonym (Hom_Id);
3891          end loop;
3892
3893          --  See if we found an entry
3894
3895          if No (Ent) then
3896             if not Ambiguous then
3897                if Is_Generic_Subprogram (Entity (Arg_Internal)) then
3898                   Error_Pragma
3899                     ("pragma% cannot be given for generic subprogram");
3900                else
3901                   Error_Pragma
3902                     ("pragma% does not identify local subprogram");
3903                end if;
3904             end if;
3905
3906             return;
3907          end if;
3908
3909          --  Import pragmas must be for imported entities
3910
3911          if Prag_Id = Pragma_Import_Function
3912               or else
3913             Prag_Id = Pragma_Import_Procedure
3914               or else
3915             Prag_Id = Pragma_Import_Valued_Procedure
3916          then
3917             if not Is_Imported (Ent) then
3918                Error_Pragma
3919                  ("pragma Import or Interface must precede pragma%");
3920             end if;
3921
3922          --  Here we have the Export case which can set the entity as exported
3923
3924          --  But does not do so if the specified external name is null, since
3925          --  that is taken as a signal in DEC Ada 83 (with which we want to be
3926          --  compatible) to request no external name.
3927
3928          elsif Nkind (Arg_External) = N_String_Literal
3929            and then String_Length (Strval (Arg_External)) = 0
3930          then
3931             null;
3932
3933          --  In all other cases, set entity as exported
3934
3935          else
3936             Set_Exported (Ent, Arg_Internal);
3937          end if;
3938
3939          --  Special processing for Valued_Procedure cases
3940
3941          if Prag_Id = Pragma_Import_Valued_Procedure
3942            or else
3943             Prag_Id = Pragma_Export_Valued_Procedure
3944          then
3945             Formal := First_Formal (Ent);
3946
3947             if No (Formal) then
3948                Error_Pragma ("at least one parameter required for pragma%");
3949
3950             elsif Ekind (Formal) /= E_Out_Parameter then
3951                Error_Pragma ("first parameter must have mode out for pragma%");
3952
3953             else
3954                Set_Is_Valued_Procedure (Ent);
3955             end if;
3956          end if;
3957
3958          Set_Extended_Import_Export_External_Name (Ent, Arg_External);
3959
3960          --  Process Result_Mechanism argument if present. We have already
3961          --  checked that this is only allowed for the function case.
3962
3963          if Present (Arg_Result_Mechanism) then
3964             Set_Mechanism_Value (Ent, Arg_Result_Mechanism);
3965          end if;
3966
3967          --  Process Mechanism parameter if present. Note that this parameter
3968          --  is not analyzed, and must not be analyzed since it is semantic
3969          --  nonsense, so we get it in exactly as the parser left it.
3970
3971          if Present (Arg_Mechanism) then
3972             declare
3973                Formal : Entity_Id;
3974                Massoc : Node_Id;
3975                Mname  : Node_Id;
3976                Choice : Node_Id;
3977
3978             begin
3979                --  A single mechanism association without a formal parameter
3980                --  name is parsed as a parenthesized expression. All other
3981                --  cases are parsed as aggregates, so we rewrite the single
3982                --  parameter case as an aggregate for consistency.
3983
3984                if Nkind (Arg_Mechanism) /= N_Aggregate
3985                  and then Paren_Count (Arg_Mechanism) = 1
3986                then
3987                   Rewrite (Arg_Mechanism,
3988                     Make_Aggregate (Sloc (Arg_Mechanism),
3989                       Expressions => New_List (
3990                         Relocate_Node (Arg_Mechanism))));
3991                end if;
3992
3993                --  Case of only mechanism name given, applies to all formals
3994
3995                if Nkind (Arg_Mechanism) /= N_Aggregate then
3996                   Formal := First_Formal (Ent);
3997                   while Present (Formal) loop
3998                      Set_Mechanism_Value (Formal, Arg_Mechanism);
3999                      Next_Formal (Formal);
4000                   end loop;
4001
4002                --  Case of list of mechanism associations given
4003
4004                else
4005                   if Null_Record_Present (Arg_Mechanism) then
4006                      Error_Pragma_Arg
4007                        ("inappropriate form for Mechanism parameter",
4008                         Arg_Mechanism);
4009                   end if;
4010
4011                   --  Deal with positional ones first
4012
4013                   Formal := First_Formal (Ent);
4014
4015                   if Present (Expressions (Arg_Mechanism)) then
4016                      Mname := First (Expressions (Arg_Mechanism));
4017                      while Present (Mname) loop
4018                         if No (Formal) then
4019                            Error_Pragma_Arg
4020                              ("too many mechanism associations", Mname);
4021                         end if;
4022
4023                         Set_Mechanism_Value (Formal, Mname);
4024                         Next_Formal (Formal);
4025                         Next (Mname);
4026                      end loop;
4027                   end if;
4028
4029                   --  Deal with named entries
4030
4031                   if Present (Component_Associations (Arg_Mechanism)) then
4032                      Massoc := First (Component_Associations (Arg_Mechanism));
4033                      while Present (Massoc) loop
4034                         Choice := First (Choices (Massoc));
4035
4036                         if Nkind (Choice) /= N_Identifier
4037                           or else Present (Next (Choice))
4038                         then
4039                            Error_Pragma_Arg
4040                              ("incorrect form for mechanism association",
4041                               Massoc);
4042                         end if;
4043
4044                         Formal := First_Formal (Ent);
4045                         loop
4046                            if No (Formal) then
4047                               Error_Pragma_Arg
4048                                 ("parameter name & not present", Choice);
4049                            end if;
4050
4051                            if Chars (Choice) = Chars (Formal) then
4052                               Set_Mechanism_Value
4053                                 (Formal, Expression (Massoc));
4054
4055                               --  Set entity on identifier (needed by ASIS)
4056
4057                               Set_Entity (Choice, Formal);
4058
4059                               exit;
4060                            end if;
4061
4062                            Next_Formal (Formal);
4063                         end loop;
4064
4065                         Next (Massoc);
4066                      end loop;
4067                   end if;
4068                end if;
4069             end;
4070          end if;
4071
4072          --  Process First_Optional_Parameter argument if present. We have
4073          --  already checked that this is only allowed for the Import case.
4074
4075          if Present (Arg_First_Optional_Parameter) then
4076             if Nkind (Arg_First_Optional_Parameter) /= N_Identifier then
4077                Error_Pragma_Arg
4078                  ("first optional parameter must be formal parameter name",
4079                   Arg_First_Optional_Parameter);
4080             end if;
4081
4082             Formal := First_Formal (Ent);
4083             loop
4084                if No (Formal) then
4085                   Error_Pragma_Arg
4086                     ("specified formal parameter& not found",
4087                      Arg_First_Optional_Parameter);
4088                end if;
4089
4090                exit when Chars (Formal) =
4091                          Chars (Arg_First_Optional_Parameter);
4092
4093                Next_Formal (Formal);
4094             end loop;
4095
4096             Set_First_Optional_Parameter (Ent, Formal);
4097
4098             --  Check specified and all remaining formals have right form
4099
4100             while Present (Formal) loop
4101                if Ekind (Formal) /= E_In_Parameter then
4102                   Error_Msg_NE
4103                     ("optional formal& is not of mode in!",
4104                      Arg_First_Optional_Parameter, Formal);
4105
4106                else
4107                   Dval := Default_Value (Formal);
4108
4109                   if No (Dval) then
4110                      Error_Msg_NE
4111                        ("optional formal& does not have default value!",
4112                         Arg_First_Optional_Parameter, Formal);
4113
4114                   elsif Compile_Time_Known_Value_Or_Aggr (Dval) then
4115                      null;
4116
4117                   else
4118                      Error_Msg_FE
4119                        ("default value for optional formal& is non-static!",
4120                         Arg_First_Optional_Parameter, Formal);
4121                   end if;
4122                end if;
4123
4124                Set_Is_Optional_Parameter (Formal);
4125                Next_Formal (Formal);
4126             end loop;
4127          end if;
4128       end Process_Extended_Import_Export_Subprogram_Pragma;
4129
4130       --------------------------
4131       -- Process_Generic_List --
4132       --------------------------
4133
4134       procedure Process_Generic_List is
4135          Arg : Node_Id;
4136          Exp : Node_Id;
4137
4138       begin
4139          Check_No_Identifiers;
4140          Check_At_Least_N_Arguments (1);
4141
4142          Arg := Arg1;
4143          while Present (Arg) loop
4144             Exp := Get_Pragma_Arg (Arg);
4145             Analyze (Exp);
4146
4147             if not Is_Entity_Name (Exp)
4148               or else
4149                 (not Is_Generic_Instance (Entity (Exp))
4150                   and then
4151                  not Is_Generic_Unit (Entity (Exp)))
4152             then
4153                Error_Pragma_Arg
4154                  ("pragma% argument must be name of generic unit/instance",
4155                   Arg);
4156             end if;
4157
4158             Next (Arg);
4159          end loop;
4160       end Process_Generic_List;
4161
4162       ------------------------------------
4163       -- Process_Import_Predefined_Type --
4164       ------------------------------------
4165
4166       procedure Process_Import_Predefined_Type is
4167          Loc  : constant Source_Ptr := Sloc (N);
4168          Elmt : Elmt_Id;
4169          Ftyp : Node_Id := Empty;
4170          Decl : Node_Id;
4171          Def  : Node_Id;
4172          Nam  : Name_Id;
4173
4174       begin
4175          String_To_Name_Buffer (Strval (Expression (Arg3)));
4176          Nam := Name_Find;
4177
4178          Elmt := First_Elmt (Predefined_Float_Types);
4179          while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop
4180             Next_Elmt (Elmt);
4181          end loop;
4182
4183          Ftyp := Node (Elmt);
4184
4185          if Present (Ftyp) then
4186
4187             --  Don't build a derived type declaration, because predefined C
4188             --  types have no declaration anywhere, so cannot really be named.
4189             --  Instead build a full type declaration, starting with an
4190             --  appropriate type definition is built
4191
4192             if Is_Floating_Point_Type (Ftyp) then
4193                Def := Make_Floating_Point_Definition (Loc,
4194                  Make_Integer_Literal (Loc, Digits_Value (Ftyp)),
4195                  Make_Real_Range_Specification (Loc,
4196                    Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))),
4197                    Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp)))));
4198
4199             --  Should never have a predefined type we cannot handle
4200
4201             else
4202                raise Program_Error;
4203             end if;
4204
4205             --  Build and insert a Full_Type_Declaration, which will be
4206             --  analyzed as soon as this list entry has been analyzed.
4207
4208             Decl := Make_Full_Type_Declaration (Loc,
4209               Make_Defining_Identifier (Loc, Chars (Expression (Arg2))),
4210               Type_Definition => Def);
4211
4212             Insert_After (N, Decl);
4213             Mark_Rewrite_Insertion (Decl);
4214
4215          else
4216             Error_Pragma_Arg ("no matching type found for pragma%",
4217             Arg2);
4218          end if;
4219       end Process_Import_Predefined_Type;
4220
4221       ---------------------------------
4222       -- Process_Import_Or_Interface --
4223       ---------------------------------
4224
4225       procedure Process_Import_Or_Interface is
4226          C      : Convention_Id;
4227          Def_Id : Entity_Id;
4228          Hom_Id : Entity_Id;
4229
4230       begin
4231          Process_Convention (C, Def_Id);
4232          Kill_Size_Check_Code (Def_Id);
4233          Note_Possible_Modification (Get_Pragma_Arg (Arg2), Sure => False);
4234
4235          if Ekind_In (Def_Id, E_Variable, E_Constant) then
4236
4237             --  We do not permit Import to apply to a renaming declaration
4238
4239             if Present (Renamed_Object (Def_Id)) then
4240                Error_Pragma_Arg
4241                  ("pragma% not allowed for object renaming", Arg2);
4242
4243             --  User initialization is not allowed for imported object, but
4244             --  the object declaration may contain a default initialization,
4245             --  that will be discarded. Note that an explicit initialization
4246             --  only counts if it comes from source, otherwise it is simply
4247             --  the code generator making an implicit initialization explicit.
4248
4249             elsif Present (Expression (Parent (Def_Id)))
4250               and then Comes_From_Source (Expression (Parent (Def_Id)))
4251             then
4252                Error_Msg_Sloc := Sloc (Def_Id);
4253                Error_Pragma_Arg
4254                  ("no initialization allowed for declaration of& #",
4255                   "\imported entities cannot be initialized (RM B.1(24))",
4256                   Arg2);
4257
4258             else
4259                Set_Imported (Def_Id);
4260                Process_Interface_Name (Def_Id, Arg3, Arg4);
4261
4262                --  Note that we do not set Is_Public here. That's because we
4263                --  only want to set it if there is no address clause, and we
4264                --  don't know that yet, so we delay that processing till
4265                --  freeze time.
4266
4267                --  pragma Import completes deferred constants
4268
4269                if Ekind (Def_Id) = E_Constant then
4270                   Set_Has_Completion (Def_Id);
4271                end if;
4272
4273                --  It is not possible to import a constant of an unconstrained
4274                --  array type (e.g. string) because there is no simple way to
4275                --  write a meaningful subtype for it.
4276
4277                if Is_Array_Type (Etype (Def_Id))
4278                  and then not Is_Constrained (Etype (Def_Id))
4279                then
4280                   Error_Msg_NE
4281                     ("imported constant& must have a constrained subtype",
4282                       N, Def_Id);
4283                end if;
4284             end if;
4285
4286          elsif Is_Subprogram (Def_Id)
4287            or else Is_Generic_Subprogram (Def_Id)
4288          then
4289             --  If the name is overloaded, pragma applies to all of the denoted
4290             --  entities in the same declarative part.
4291
4292             Hom_Id := Def_Id;
4293             while Present (Hom_Id) loop
4294                Def_Id := Get_Base_Subprogram (Hom_Id);
4295
4296                --  Ignore inherited subprograms because the pragma will apply
4297                --  to the parent operation, which is the one called.
4298
4299                if Is_Overloadable (Def_Id)
4300                  and then Present (Alias (Def_Id))
4301                then
4302                   null;
4303
4304                --  If it is not a subprogram, it must be in an outer scope and
4305                --  pragma does not apply.
4306
4307                elsif not Is_Subprogram (Def_Id)
4308                  and then not Is_Generic_Subprogram (Def_Id)
4309                then
4310                   null;
4311
4312                --  The pragma does not apply to primitives of interfaces
4313
4314                elsif Is_Dispatching_Operation (Def_Id)
4315                  and then Present (Find_Dispatching_Type (Def_Id))
4316                  and then Is_Interface (Find_Dispatching_Type (Def_Id))
4317                then
4318                   null;
4319
4320                --  Verify that the homonym is in the same declarative part (not
4321                --  just the same scope).
4322
4323                elsif Parent (Unit_Declaration_Node (Def_Id)) /= Parent (N)
4324                  and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux
4325                then
4326                   exit;
4327
4328                else
4329                   Set_Imported (Def_Id);
4330
4331                   --  Reject an Import applied to an abstract subprogram
4332
4333                   if Is_Subprogram (Def_Id)
4334                     and then Is_Abstract_Subprogram (Def_Id)
4335                   then
4336                      Error_Msg_Sloc := Sloc (Def_Id);
4337                      Error_Msg_NE
4338                        ("cannot import abstract subprogram& declared#",
4339                         Arg2, Def_Id);
4340                   end if;
4341
4342                   --  Special processing for Convention_Intrinsic
4343
4344                   if C = Convention_Intrinsic then
4345
4346                      --  Link_Name argument not allowed for intrinsic
4347
4348                      Check_No_Link_Name;
4349
4350                      Set_Is_Intrinsic_Subprogram (Def_Id);
4351
4352                      --  If no external name is present, then check that this
4353                      --  is a valid intrinsic subprogram. If an external name
4354                      --  is present, then this is handled by the back end.
4355
4356                      if No (Arg3) then
4357                         Check_Intrinsic_Subprogram
4358                           (Def_Id, Get_Pragma_Arg (Arg2));
4359                      end if;
4360                   end if;
4361
4362                   --  All interfaced procedures need an external symbol created
4363                   --  for them since they are always referenced from another
4364                   --  object file.
4365
4366                   Set_Is_Public (Def_Id);
4367
4368                   --  Verify that the subprogram does not have a completion
4369                   --  through a renaming declaration. For other completions the
4370                   --  pragma appears as a too late representation.
4371
4372                   declare
4373                      Decl : constant Node_Id := Unit_Declaration_Node (Def_Id);
4374
4375                   begin
4376                      if Present (Decl)
4377                        and then Nkind (Decl) = N_Subprogram_Declaration
4378                        and then Present (Corresponding_Body (Decl))
4379                        and then Nkind (Unit_Declaration_Node
4380                                         (Corresponding_Body (Decl))) =
4381                                              N_Subprogram_Renaming_Declaration
4382                      then
4383                         Error_Msg_Sloc := Sloc (Def_Id);
4384                         Error_Msg_NE
4385                           ("cannot import&, renaming already provided for " &
4386                            "declaration #", N, Def_Id);
4387                      end if;
4388                   end;
4389
4390                   Set_Has_Completion (Def_Id);
4391                   Process_Interface_Name (Def_Id, Arg3, Arg4);
4392                end if;
4393
4394                if Is_Compilation_Unit (Hom_Id) then
4395
4396                   --  Its possible homonyms are not affected by the pragma.
4397                   --  Such homonyms might be present in the context of other
4398                   --  units being compiled.
4399
4400                   exit;
4401
4402                else
4403                   Hom_Id := Homonym (Hom_Id);
4404                end if;
4405             end loop;
4406
4407          --  When the convention is Java or CIL, we also allow Import to be
4408          --  given for packages, generic packages, exceptions, record
4409          --  components, and access to subprograms.
4410
4411          elsif (C = Convention_Java or else C = Convention_CIL)
4412            and then
4413              (Is_Package_Or_Generic_Package (Def_Id)
4414                or else Ekind (Def_Id) = E_Exception
4415                or else Ekind (Def_Id) = E_Access_Subprogram_Type
4416                or else Nkind (Parent (Def_Id)) = N_Component_Declaration)
4417          then
4418             Set_Imported (Def_Id);
4419             Set_Is_Public (Def_Id);
4420             Process_Interface_Name (Def_Id, Arg3, Arg4);
4421
4422          --  Import a CPP class
4423
4424          elsif Is_Record_Type (Def_Id)
4425            and then C = Convention_CPP
4426          then
4427             --  Types treated as CPP classes must be declared limited (note:
4428             --  this used to be a warning but there is no real benefit to it
4429             --  since we did effectively intend to treat the type as limited
4430             --  anyway).
4431
4432             if not Is_Limited_Type (Def_Id) then
4433                Error_Msg_N
4434                  ("imported 'C'P'P type must be limited",
4435                   Get_Pragma_Arg (Arg2));
4436             end if;
4437
4438             Set_Is_CPP_Class (Def_Id);
4439
4440             --  Imported CPP types must not have discriminants (because C++
4441             --  classes do not have discriminants).
4442
4443             if Has_Discriminants (Def_Id) then
4444                Error_Msg_N
4445                  ("imported 'C'P'P type cannot have discriminants",
4446                   First (Discriminant_Specifications
4447                           (Declaration_Node (Def_Id))));
4448             end if;
4449
4450             --  Components of imported CPP types must not have default
4451             --  expressions because the constructor (if any) is on the
4452             --  C++ side.
4453
4454             declare
4455                Tdef  : constant Node_Id :=
4456                          Type_Definition (Declaration_Node (Def_Id));
4457                Clist : Node_Id;
4458                Comp  : Node_Id;
4459
4460             begin
4461                if Nkind (Tdef) = N_Record_Definition then
4462                   Clist := Component_List (Tdef);
4463
4464                else
4465                   pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
4466                   Clist := Component_List (Record_Extension_Part (Tdef));
4467                end if;
4468
4469                if Present (Clist) then
4470                   Comp := First (Component_Items (Clist));
4471                   while Present (Comp) loop
4472                      if Present (Expression (Comp)) then
4473                         Error_Msg_N
4474                           ("component of imported 'C'P'P type cannot have" &
4475                            " default expression", Expression (Comp));
4476                      end if;
4477
4478                      Next (Comp);
4479                   end loop;
4480                end if;
4481             end;
4482
4483          elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then
4484             Check_No_Link_Name;
4485             Check_Arg_Count (3);
4486             Check_Arg_Is_Static_Expression (Arg3, Standard_String);
4487
4488             Process_Import_Predefined_Type;
4489
4490          else
4491             Error_Pragma_Arg
4492               ("second argument of pragma% must be object, subprogram" &
4493                " or incomplete type",
4494                Arg2);
4495          end if;
4496
4497          --  If this pragma applies to a compilation unit, then the unit, which
4498          --  is a subprogram, does not require (or allow) a body. We also do
4499          --  not need to elaborate imported procedures.
4500
4501          if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
4502             declare
4503                Cunit : constant Node_Id := Parent (Parent (N));
4504             begin
4505                Set_Body_Required (Cunit, False);
4506             end;
4507          end if;
4508       end Process_Import_Or_Interface;
4509
4510       --------------------
4511       -- Process_Inline --
4512       --------------------
4513
4514       procedure Process_Inline (Active : Boolean) is
4515          Assoc     : Node_Id;
4516          Decl      : Node_Id;
4517          Subp_Id   : Node_Id;
4518          Subp      : Entity_Id;
4519          Applies   : Boolean;
4520
4521          Effective : Boolean := False;
4522          --  Set True if inline has some effect, i.e. if there is at least one
4523          --  subprogram set as inlined as a result of the use of the pragma.
4524
4525          procedure Make_Inline (Subp : Entity_Id);
4526          --  Subp is the defining unit name of the subprogram declaration. Set
4527          --  the flag, as well as the flag in the corresponding body, if there
4528          --  is one present.
4529
4530          procedure Set_Inline_Flags (Subp : Entity_Id);
4531          --  Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
4532          --  Has_Pragma_Inline_Always for the Inline_Always case.
4533
4534          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean;
4535          --  Returns True if it can be determined at this stage that inlining
4536          --  is not possible, for example if the body is available and contains
4537          --  exception handlers, we prevent inlining, since otherwise we can
4538          --  get undefined symbols at link time. This function also emits a
4539          --  warning if front-end inlining is enabled and the pragma appears
4540          --  too late.
4541          --
4542          --  ??? is business with link symbols still valid, or does it relate
4543          --  to front end ZCX which is being phased out ???
4544
4545          ---------------------------
4546          -- Inlining_Not_Possible --
4547          ---------------------------
4548
4549          function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is
4550             Decl  : constant Node_Id := Unit_Declaration_Node (Subp);
4551             Stats : Node_Id;
4552
4553          begin
4554             if Nkind (Decl) = N_Subprogram_Body then
4555                Stats := Handled_Statement_Sequence (Decl);
4556                return Present (Exception_Handlers (Stats))
4557                  or else Present (At_End_Proc (Stats));
4558
4559             elsif Nkind (Decl) = N_Subprogram_Declaration
4560               and then Present (Corresponding_Body (Decl))
4561             then
4562                if Front_End_Inlining
4563                  and then Analyzed (Corresponding_Body (Decl))
4564                then
4565                   Error_Msg_N ("pragma appears too late, ignored?", N);
4566                   return True;
4567
4568                --  If the subprogram is a renaming as body, the body is just a
4569                --  call to the renamed subprogram, and inlining is trivially
4570                --  possible.
4571
4572                elsif
4573                  Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) =
4574                                              N_Subprogram_Renaming_Declaration
4575                then
4576                   return False;
4577
4578                else
4579                   Stats :=
4580                     Handled_Statement_Sequence
4581                         (Unit_Declaration_Node (Corresponding_Body (Decl)));
4582
4583                   return
4584                     Present (Exception_Handlers (Stats))
4585                       or else Present (At_End_Proc (Stats));
4586                end if;
4587
4588             else
4589                --  If body is not available, assume the best, the check is
4590                --  performed again when compiling enclosing package bodies.
4591
4592                return False;
4593             end if;
4594          end Inlining_Not_Possible;
4595
4596          -----------------
4597          -- Make_Inline --
4598          -----------------
4599
4600          procedure Make_Inline (Subp : Entity_Id) is
4601             Kind       : constant Entity_Kind := Ekind (Subp);
4602             Inner_Subp : Entity_Id   := Subp;
4603
4604          begin
4605             --  Ignore if bad type, avoid cascaded error
4606
4607             if Etype (Subp) = Any_Type then
4608                Applies := True;
4609                return;
4610
4611             --  Ignore if all inlining is suppressed
4612
4613             elsif Suppress_All_Inlining then
4614                Applies := True;
4615                return;
4616
4617             --  If inlining is not possible, for now do not treat as an error
4618
4619             elsif Inlining_Not_Possible (Subp) then
4620                Applies := True;
4621                return;
4622
4623             --  Here we have a candidate for inlining, but we must exclude
4624             --  derived operations. Otherwise we would end up trying to inline
4625             --  a phantom declaration, and the result would be to drag in a
4626             --  body which has no direct inlining associated with it. That
4627             --  would not only be inefficient but would also result in the
4628             --  backend doing cross-unit inlining in cases where it was
4629             --  definitely inappropriate to do so.
4630
4631             --  However, a simple Comes_From_Source test is insufficient, since
4632             --  we do want to allow inlining of generic instances which also do
4633             --  not come from source. We also need to recognize specs generated
4634             --  by the front-end for bodies that carry the pragma. Finally,
4635             --  predefined operators do not come from source but are not
4636             --  inlineable either.
4637
4638             elsif Is_Generic_Instance (Subp)
4639               or else Nkind (Parent (Parent (Subp))) = N_Subprogram_Declaration
4640             then
4641                null;
4642
4643             elsif not Comes_From_Source (Subp)
4644               and then Scope (Subp) /= Standard_Standard
4645             then
4646                Applies := True;
4647                return;
4648             end if;
4649
4650             --  The referenced entity must either be the enclosing entity, or
4651             --  an entity declared within the current open scope.
4652
4653             if Present (Scope (Subp))
4654               and then Scope (Subp) /= Current_Scope
4655               and then Subp /= Current_Scope
4656             then
4657                Error_Pragma_Arg
4658                  ("argument of% must be entity in current scope", Assoc);
4659                return;
4660             end if;
4661
4662             --  Processing for procedure, operator or function. If subprogram
4663             --  is aliased (as for an instance) indicate that the renamed
4664             --  entity (if declared in the same unit) is inlined.
4665
4666             if Is_Subprogram (Subp) then
4667                Inner_Subp := Ultimate_Alias (Inner_Subp);
4668
4669                if In_Same_Source_Unit (Subp, Inner_Subp) then
4670                   Set_Inline_Flags (Inner_Subp);
4671
4672                   Decl := Parent (Parent (Inner_Subp));
4673
4674                   if Nkind (Decl) = N_Subprogram_Declaration
4675                     and then Present (Corresponding_Body (Decl))
4676                   then
4677                      Set_Inline_Flags (Corresponding_Body (Decl));
4678
4679                   elsif Is_Generic_Instance (Subp) then
4680
4681                      --  Indicate that the body needs to be created for
4682                      --  inlining subsequent calls. The instantiation node
4683                      --  follows the declaration of the wrapper package
4684                      --  created for it.
4685
4686                      if Scope (Subp) /= Standard_Standard
4687                        and then
4688                          Need_Subprogram_Instance_Body
4689                           (Next (Unit_Declaration_Node (Scope (Alias (Subp)))),
4690                               Subp)
4691                      then
4692                         null;
4693                      end if;
4694
4695                   --  Inline is a program unit pragma (RM 10.1.5) and cannot
4696                   --  appear in a formal part to apply to a formal subprogram.
4697                   --  Do not apply check within an instance or a formal package
4698                   --  the test will have been applied to the original generic.
4699
4700                   elsif Nkind (Decl) in N_Formal_Subprogram_Declaration
4701                     and then List_Containing (Decl) = List_Containing (N)
4702                     and then not In_Instance
4703                   then
4704                      Error_Msg_N
4705                        ("Inline cannot apply to a formal subprogram", N);
4706                   end if;
4707                end if;
4708
4709                Applies := True;
4710
4711             --  For a generic subprogram set flag as well, for use at the point
4712             --  of instantiation, to determine whether the body should be
4713             --  generated.
4714
4715             elsif Is_Generic_Subprogram (Subp) then
4716                Set_Inline_Flags (Subp);
4717                Applies := True;
4718
4719             --  Literals are by definition inlined
4720
4721             elsif Kind = E_Enumeration_Literal then
4722                null;
4723
4724             --  Anything else is an error
4725
4726             else
4727                Error_Pragma_Arg
4728                  ("expect subprogram name for pragma%", Assoc);
4729             end if;
4730          end Make_Inline;
4731
4732          ----------------------
4733          -- Set_Inline_Flags --
4734          ----------------------
4735
4736          procedure Set_Inline_Flags (Subp : Entity_Id) is
4737          begin
4738             if Active then
4739                Set_Is_Inlined (Subp);
4740             end if;
4741
4742             if not Has_Pragma_Inline (Subp) then
4743                Set_Has_Pragma_Inline (Subp);
4744                Effective := True;
4745             end if;
4746
4747             if Prag_Id = Pragma_Inline_Always then
4748                Set_Has_Pragma_Inline_Always (Subp);
4749             end if;
4750          end Set_Inline_Flags;
4751
4752       --  Start of processing for Process_Inline
4753
4754       begin
4755          Check_No_Identifiers;
4756          Check_At_Least_N_Arguments (1);
4757
4758          if Active then
4759             Inline_Processing_Required := True;
4760          end if;
4761
4762          Assoc := Arg1;
4763          while Present (Assoc) loop
4764             Subp_Id := Get_Pragma_Arg (Assoc);
4765             Analyze (Subp_Id);
4766             Applies := False;
4767
4768             if Is_Entity_Name (Subp_Id) then
4769                Subp := Entity (Subp_Id);
4770
4771                if Subp = Any_Id then
4772
4773                   --  If previous error, avoid cascaded errors
4774
4775                   Applies := True;
4776                   Effective := True;
4777
4778                else
4779                   Make_Inline (Subp);
4780
4781                   --  For the pragma case, climb homonym chain. This is
4782                   --  what implements allowing the pragma in the renaming
4783                   --  case, with the result applying to the ancestors.
4784
4785                   if not From_Aspect_Specification (N) then
4786                      while Present (Homonym (Subp))
4787                        and then Scope (Homonym (Subp)) = Current_Scope
4788                      loop
4789                         Make_Inline (Homonym (Subp));
4790                         Subp := Homonym (Subp);
4791                      end loop;
4792                   end if;
4793                end if;
4794             end if;
4795
4796             if not Applies then
4797                Error_Pragma_Arg
4798                  ("inappropriate argument for pragma%", Assoc);
4799
4800             elsif not Effective
4801               and then Warn_On_Redundant_Constructs
4802               and then not Suppress_All_Inlining
4803             then
4804                if Inlining_Not_Possible (Subp) then
4805                   Error_Msg_NE
4806                     ("pragma Inline for& is ignored?", N, Entity (Subp_Id));
4807                else
4808                   Error_Msg_NE
4809                     ("pragma Inline for& is redundant?", N, Entity (Subp_Id));
4810                end if;
4811             end if;
4812
4813             Next (Assoc);
4814          end loop;
4815       end Process_Inline;
4816
4817       ----------------------------
4818       -- Process_Interface_Name --
4819       ----------------------------
4820
4821       procedure Process_Interface_Name
4822         (Subprogram_Def : Entity_Id;
4823          Ext_Arg        : Node_Id;
4824          Link_Arg       : Node_Id)
4825       is
4826          Ext_Nam    : Node_Id;
4827          Link_Nam   : Node_Id;
4828          String_Val : String_Id;
4829
4830          procedure Check_Form_Of_Interface_Name
4831            (SN            : Node_Id;
4832             Ext_Name_Case : Boolean);
4833          --  SN is a string literal node for an interface name. This routine
4834          --  performs some minimal checks that the name is reasonable. In
4835          --  particular that no spaces or other obviously incorrect characters
4836          --  appear. This is only a warning, since any characters are allowed.
4837          --  Ext_Name_Case is True for an External_Name, False for a Link_Name.
4838
4839          ----------------------------------
4840          -- Check_Form_Of_Interface_Name --
4841          ----------------------------------
4842
4843          procedure Check_Form_Of_Interface_Name
4844            (SN            : Node_Id;
4845             Ext_Name_Case : Boolean)
4846          is
4847             S  : constant String_Id := Strval (Expr_Value_S (SN));
4848             SL : constant Nat       := String_Length (S);
4849             C  : Char_Code;
4850
4851          begin
4852             if SL = 0 then
4853                Error_Msg_N ("interface name cannot be null string", SN);
4854             end if;
4855
4856             for J in 1 .. SL loop
4857                C := Get_String_Char (S, J);
4858
4859                --  Look for dubious character and issue unconditional warning.
4860                --  Definitely dubious if not in character range.
4861
4862                if not In_Character_Range (C)
4863
4864                   --  For all cases except CLI target,
4865                   --  commas, spaces and slashes are dubious (in CLI, we use
4866                   --  commas and backslashes in external names to specify
4867                   --  assembly version and public key, while slashes and spaces
4868                   --  can be used in names to mark nested classes and
4869                   --  valuetypes).
4870
4871                   or else ((not Ext_Name_Case or else VM_Target /= CLI_Target)
4872                              and then (Get_Character (C) = ','
4873                                          or else
4874                                        Get_Character (C) = '\'))
4875                  or else (VM_Target /= CLI_Target
4876                             and then (Get_Character (C) = ' '
4877                                         or else
4878                                       Get_Character (C) = '/'))
4879                then
4880                   Error_Msg
4881                     ("?interface name contains illegal character",
4882                      Sloc (SN) + Source_Ptr (J));
4883                end if;
4884             end loop;
4885          end Check_Form_Of_Interface_Name;
4886
4887       --  Start of processing for Process_Interface_Name
4888
4889       begin
4890          if No (Link_Arg) then
4891             if No (Ext_Arg) then
4892                if VM_Target = CLI_Target
4893                  and then Ekind (Subprogram_Def) = E_Package
4894                  and then Nkind (Parent (Subprogram_Def)) =
4895                                                  N_Package_Specification
4896                  and then Present (Generic_Parent (Parent (Subprogram_Def)))
4897                then
4898                   Set_Interface_Name
4899                      (Subprogram_Def,
4900                       Interface_Name
4901                         (Generic_Parent (Parent (Subprogram_Def))));
4902                end if;
4903
4904                return;
4905
4906             elsif Chars (Ext_Arg) = Name_Link_Name then
4907                Ext_Nam  := Empty;
4908                Link_Nam := Expression (Ext_Arg);
4909
4910             else
4911                Check_Optional_Identifier (Ext_Arg, Name_External_Name);
4912                Ext_Nam  := Expression (Ext_Arg);
4913                Link_Nam := Empty;
4914             end if;
4915
4916          else
4917             Check_Optional_Identifier (Ext_Arg,  Name_External_Name);
4918             Check_Optional_Identifier (Link_Arg, Name_Link_Name);
4919             Ext_Nam  := Expression (Ext_Arg);
4920             Link_Nam := Expression (Link_Arg);
4921          end if;
4922
4923          --  Check expressions for external name and link name are static
4924
4925          if Present (Ext_Nam) then
4926             Check_Arg_Is_Static_Expression (Ext_Nam, Standard_String);
4927             Check_Form_Of_Interface_Name (Ext_Nam, Ext_Name_Case => True);
4928
4929             --  Verify that external name is not the name of a local entity,
4930             --  which would hide the imported one and could lead to run-time
4931             --  surprises. The problem can only arise for entities declared in
4932             --  a package body (otherwise the external name is fully qualified
4933             --  and will not conflict).
4934
4935             declare
4936                Nam : Name_Id;
4937                E   : Entity_Id;
4938                Par : Node_Id;
4939
4940             begin
4941                if Prag_Id = Pragma_Import then
4942                   String_To_Name_Buffer (Strval (Expr_Value_S (Ext_Nam)));
4943                   Nam := Name_Find;
4944                   E   := Entity_Id (Get_Name_Table_Info (Nam));
4945
4946                   if Nam /= Chars (Subprogram_Def)
4947                     and then Present (E)
4948                     and then not Is_Overloadable (E)
4949                     and then Is_Immediately_Visible (E)
4950                     and then not Is_Imported (E)
4951                     and then Ekind (Scope (E)) = E_Package
4952                   then
4953                      Par := Parent (E);
4954                      while Present (Par) loop
4955                         if Nkind (Par) = N_Package_Body then
4956                            Error_Msg_Sloc := Sloc (E);
4957                            Error_Msg_NE
4958                              ("imported entity is hidden by & declared#",
4959                               Ext_Arg, E);
4960                            exit;
4961                         end if;
4962
4963                         Par := Parent (Par);
4964                      end loop;
4965                   end if;
4966                end if;
4967             end;
4968          end if;
4969
4970          if Present (Link_Nam) then
4971             Check_Arg_Is_Static_Expression (Link_Nam, Standard_String);
4972             Check_Form_Of_Interface_Name (Link_Nam, Ext_Name_Case => False);
4973          end if;
4974
4975          --  If there is no link name, just set the external name
4976
4977          if No (Link_Nam) then
4978             Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam));
4979
4980          --  For the Link_Name case, the given literal is preceded by an
4981          --  asterisk, which indicates to GCC that the given name should be
4982          --  taken literally, and in particular that no prepending of
4983          --  underlines should occur, even in systems where this is the
4984          --  normal default.
4985
4986          else
4987             Start_String;
4988
4989             if VM_Target = No_VM then
4990                Store_String_Char (Get_Char_Code ('*'));
4991             end if;
4992
4993             String_Val := Strval (Expr_Value_S (Link_Nam));
4994             Store_String_Chars (String_Val);
4995             Link_Nam :=
4996               Make_String_Literal (Sloc (Link_Nam),
4997                 Strval => End_String);
4998          end if;
4999
5000          --  Set the interface name. If the entity is a generic instance, use
5001          --  its alias, which is the callable entity.
5002
5003          if Is_Generic_Instance (Subprogram_Def) then
5004             Set_Encoded_Interface_Name
5005               (Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam);
5006          else
5007             Set_Encoded_Interface_Name
5008               (Get_Base_Subprogram (Subprogram_Def), Link_Nam);
5009          end if;
5010
5011          --  We allow duplicated export names in CIL/Java, as they are always
5012          --  enclosed in a namespace that differentiates them, and overloaded
5013          --  entities are supported by the VM.
5014
5015          if Convention (Subprogram_Def) /= Convention_CIL
5016               and then
5017             Convention (Subprogram_Def) /= Convention_Java
5018          then
5019             Check_Duplicated_Export_Name (Link_Nam);
5020          end if;
5021       end Process_Interface_Name;
5022
5023       -----------------------------------------
5024       -- Process_Interrupt_Or_Attach_Handler --
5025       -----------------------------------------
5026
5027       procedure Process_Interrupt_Or_Attach_Handler is
5028          Arg1_X       : constant Node_Id   := Get_Pragma_Arg (Arg1);
5029          Handler_Proc : constant Entity_Id := Entity (Arg1_X);
5030          Proc_Scope   : constant Entity_Id := Scope (Handler_Proc);
5031
5032       begin
5033          Set_Is_Interrupt_Handler (Handler_Proc);
5034
5035          --  If the pragma is not associated with a handler procedure within a
5036          --  protected type, then it must be for a nonprotected procedure for
5037          --  the AAMP target, in which case we don't associate a representation
5038          --  item with the procedure's scope.
5039
5040          if Ekind (Proc_Scope) = E_Protected_Type then
5041             if Prag_Id = Pragma_Interrupt_Handler
5042                  or else
5043                Prag_Id = Pragma_Attach_Handler
5044             then
5045                Record_Rep_Item (Proc_Scope, N);
5046             end if;
5047          end if;
5048       end Process_Interrupt_Or_Attach_Handler;
5049
5050       --------------------------------------------------
5051       -- Process_Restrictions_Or_Restriction_Warnings --
5052       --------------------------------------------------
5053
5054       --  Note: some of the simple identifier cases were handled in par-prag,
5055       --  but it is harmless (and more straightforward) to simply handle all
5056       --  cases here, even if it means we repeat a bit of work in some cases.
5057
5058       procedure Process_Restrictions_Or_Restriction_Warnings
5059         (Warn : Boolean)
5060       is
5061          Arg   : Node_Id;
5062          R_Id  : Restriction_Id;
5063          Id    : Name_Id;
5064          Expr  : Node_Id;
5065          Val   : Uint;
5066
5067          procedure Check_Unit_Name (N : Node_Id);
5068          --  Checks unit name parameter for No_Dependence. Returns if it has
5069          --  an appropriate form, otherwise raises pragma argument error.
5070
5071          ---------------------
5072          -- Check_Unit_Name --
5073          ---------------------
5074
5075          procedure Check_Unit_Name (N : Node_Id) is
5076          begin
5077             if Nkind (N) = N_Selected_Component then
5078                Check_Unit_Name (Prefix (N));
5079                Check_Unit_Name (Selector_Name (N));
5080
5081             elsif Nkind (N) = N_Identifier then
5082                return;
5083
5084             else
5085                Error_Pragma_Arg
5086                  ("wrong form for unit name for No_Dependence", N);
5087             end if;
5088          end Check_Unit_Name;
5089
5090       --  Start of processing for Process_Restrictions_Or_Restriction_Warnings
5091
5092       begin
5093          --  Ignore all Restrictions pragma in CodePeer mode
5094
5095          if CodePeer_Mode then
5096             return;
5097          end if;
5098
5099          Check_Ada_83_Warning;
5100          Check_At_Least_N_Arguments (1);
5101          Check_Valid_Configuration_Pragma;
5102
5103          Arg := Arg1;
5104          while Present (Arg) loop
5105             Id := Chars (Arg);
5106             Expr := Get_Pragma_Arg (Arg);
5107
5108             --  Case of no restriction identifier present
5109
5110             if Id = No_Name then
5111                if Nkind (Expr) /= N_Identifier then
5112                   Error_Pragma_Arg
5113                     ("invalid form for restriction", Arg);
5114                end if;
5115
5116                R_Id :=
5117                  Get_Restriction_Id
5118                    (Process_Restriction_Synonyms (Expr));
5119
5120                if R_Id not in All_Boolean_Restrictions then
5121                   Error_Msg_Name_1 := Pname;
5122                   Error_Msg_N
5123                     ("invalid restriction identifier&", Get_Pragma_Arg (Arg));
5124
5125                   --  Check for possible misspelling
5126
5127                   for J in Restriction_Id loop
5128                      declare
5129                         Rnm : constant String := Restriction_Id'Image (J);
5130
5131                      begin
5132                         Name_Buffer (1 .. Rnm'Length) := Rnm;
5133                         Name_Len := Rnm'Length;
5134                         Set_Casing (All_Lower_Case);
5135
5136                         if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then
5137                            Set_Casing
5138                              (Identifier_Casing (Current_Source_File));
5139                            Error_Msg_String (1 .. Rnm'Length) :=
5140                              Name_Buffer (1 .. Name_Len);
5141                            Error_Msg_Strlen := Rnm'Length;
5142                            Error_Msg_N -- CODEFIX
5143                              ("\possible misspelling of ""~""",
5144                               Get_Pragma_Arg (Arg));
5145                            exit;
5146                         end if;
5147                      end;
5148                   end loop;
5149
5150                   raise Pragma_Exit;
5151                end if;
5152
5153                if Implementation_Restriction (R_Id) then
5154                   Check_Restriction (No_Implementation_Restrictions, Arg);
5155                end if;
5156
5157                --  If this is a warning, then set the warning unless we already
5158                --  have a real restriction active (we never want a warning to
5159                --  override a real restriction).
5160
5161                if Warn then
5162                   if not Restriction_Active (R_Id) then
5163                      Set_Restriction (R_Id, N);
5164                      Restriction_Warnings (R_Id) := True;
5165                   end if;
5166
5167                --  If real restriction case, then set it and make sure that the
5168                --  restriction warning flag is off, since a real restriction
5169                --  always overrides a warning.
5170
5171                else
5172                   Set_Restriction (R_Id, N);
5173                   Restriction_Warnings (R_Id) := False;
5174                end if;
5175
5176                --  Check for obsolescent restrictions in Ada 2005 mode
5177
5178                if not Warn
5179                  and then Ada_Version >= Ada_2005
5180                  and then (R_Id = No_Asynchronous_Control
5181                             or else
5182                            R_Id = No_Unchecked_Deallocation
5183                             or else
5184                            R_Id = No_Unchecked_Conversion)
5185                then
5186                   Check_Restriction (No_Obsolescent_Features, N);
5187                end if;
5188
5189                --  A very special case that must be processed here: pragma
5190                --  Restrictions (No_Exceptions) turns off all run-time
5191                --  checking. This is a bit dubious in terms of the formal
5192                --  language definition, but it is what is intended by RM
5193                --  H.4(12). Restriction_Warnings never affects generated code
5194                --  so this is done only in the real restriction case.
5195
5196                if R_Id = No_Exceptions and then not Warn then
5197                   Scope_Suppress := (others => True);
5198                end if;
5199
5200             --  Case of No_Dependence => unit-name. Note that the parser
5201             --  already made the necessary entry in the No_Dependence table.
5202
5203             elsif Id = Name_No_Dependence then
5204                Check_Unit_Name (Expr);
5205
5206             --  All other cases of restriction identifier present
5207
5208             else
5209                R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg));
5210                Analyze_And_Resolve (Expr, Any_Integer);
5211
5212                if R_Id not in All_Parameter_Restrictions then
5213                   Error_Pragma_Arg
5214                     ("invalid restriction parameter identifier", Arg);
5215
5216                elsif not Is_OK_Static_Expression (Expr) then
5217                   Flag_Non_Static_Expr
5218                     ("value must be static expression!", Expr);
5219                   raise Pragma_Exit;
5220
5221                elsif not Is_Integer_Type (Etype (Expr))
5222                  or else Expr_Value (Expr) < 0
5223                then
5224                   Error_Pragma_Arg
5225                     ("value must be non-negative integer", Arg);
5226                end if;
5227
5228                --  Restriction pragma is active
5229
5230                Val := Expr_Value (Expr);
5231
5232                if not UI_Is_In_Int_Range (Val) then
5233                   Error_Pragma_Arg
5234                     ("pragma ignored, value too large?", Arg);
5235                end if;
5236
5237                --  Warning case. If the real restriction is active, then we
5238                --  ignore the request, since warning never overrides a real
5239                --  restriction. Otherwise we set the proper warning. Note that
5240                --  this circuit sets the warning again if it is already set,
5241                --  which is what we want, since the constant may have changed.
5242
5243                if Warn then
5244                   if not Restriction_Active (R_Id) then
5245                      Set_Restriction
5246                        (R_Id, N, Integer (UI_To_Int (Val)));
5247                      Restriction_Warnings (R_Id) := True;
5248                   end if;
5249
5250                --  Real restriction case, set restriction and make sure warning
5251                --  flag is off since real restriction always overrides warning.
5252
5253                else
5254                   Set_Restriction (R_Id, N, Integer (UI_To_Int (Val)));
5255                   Restriction_Warnings (R_Id) := False;
5256                end if;
5257             end if;
5258
5259             Next (Arg);
5260          end loop;
5261       end Process_Restrictions_Or_Restriction_Warnings;
5262
5263       ---------------------------------
5264       -- Process_Suppress_Unsuppress --
5265       ---------------------------------
5266
5267       --  Note: this procedure makes entries in the check suppress data
5268       --  structures managed by Sem. See spec of package Sem for full
5269       --  details on how we handle recording of check suppression.
5270
5271       procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is
5272          C    : Check_Id;
5273          E_Id : Node_Id;
5274          E    : Entity_Id;
5275
5276          In_Package_Spec : constant Boolean :=
5277                              Is_Package_Or_Generic_Package (Current_Scope)
5278                                and then not In_Package_Body (Current_Scope);
5279
5280          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id);
5281          --  Used to suppress a single check on the given entity
5282
5283          --------------------------------
5284          -- Suppress_Unsuppress_Echeck --
5285          --------------------------------
5286
5287          procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is
5288          begin
5289             Set_Checks_May_Be_Suppressed (E);
5290
5291             if In_Package_Spec then
5292                Push_Global_Suppress_Stack_Entry
5293                  (Entity   => E,
5294                   Check    => C,
5295                   Suppress => Suppress_Case);
5296
5297             else
5298                Push_Local_Suppress_Stack_Entry
5299                  (Entity   => E,
5300                   Check    => C,
5301                   Suppress => Suppress_Case);
5302             end if;
5303
5304             --  If this is a first subtype, and the base type is distinct,
5305             --  then also set the suppress flags on the base type.
5306
5307             if Is_First_Subtype (E)
5308               and then Etype (E) /= E
5309             then
5310                Suppress_Unsuppress_Echeck (Etype (E), C);
5311             end if;
5312          end Suppress_Unsuppress_Echeck;
5313
5314       --  Start of processing for Process_Suppress_Unsuppress
5315
5316       begin
5317          --  Ignore pragma Suppress/Unsuppress in CodePeer and Alfa modes on
5318          --  user code: we want to generate checks for analysis purposes, as
5319          --  set respectively by -gnatC and -gnatd.F
5320
5321          if (CodePeer_Mode or Alfa_Mode)
5322            and then Comes_From_Source (N)
5323          then
5324             return;
5325          end if;
5326
5327          --  Suppress/Unsuppress can appear as a configuration pragma, or in a
5328          --  declarative part or a package spec (RM 11.5(5)).
5329
5330          if not Is_Configuration_Pragma then
5331             Check_Is_In_Decl_Part_Or_Package_Spec;
5332          end if;
5333
5334          Check_At_Least_N_Arguments (1);
5335          Check_At_Most_N_Arguments (2);
5336          Check_No_Identifier (Arg1);
5337          Check_Arg_Is_Identifier (Arg1);
5338
5339          C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1)));
5340
5341          if C = No_Check_Id then
5342             Error_Pragma_Arg
5343               ("argument of pragma% is not valid check name", Arg1);
5344          end if;
5345
5346          if not Suppress_Case
5347            and then (C = All_Checks or else C = Overflow_Check)
5348          then
5349             Opt.Overflow_Checks_Unsuppressed := True;
5350          end if;
5351
5352          if Arg_Count = 1 then
5353
5354             --  Make an entry in the local scope suppress table. This is the
5355             --  table that directly shows the current value of the scope
5356             --  suppress check for any check id value.
5357
5358             if C = All_Checks then
5359
5360                --  For All_Checks, we set all specific predefined checks with
5361                --  the exception of Elaboration_Check, which is handled
5362                --  specially because of not wanting All_Checks to have the
5363                --  effect of deactivating static elaboration order processing.
5364
5365                for J in Scope_Suppress'Range loop
5366                   if J /= Elaboration_Check then
5367                      Scope_Suppress (J) := Suppress_Case;
5368                   end if;
5369                end loop;
5370
5371             --  If not All_Checks, and predefined check, then set appropriate
5372             --  scope entry. Note that we will set Elaboration_Check if this
5373             --  is explicitly specified.
5374
5375             elsif C in Predefined_Check_Id then
5376                Scope_Suppress (C) := Suppress_Case;
5377             end if;
5378
5379             --  Also make an entry in the Local_Entity_Suppress table
5380
5381             Push_Local_Suppress_Stack_Entry
5382               (Entity   => Empty,
5383                Check    => C,
5384                Suppress => Suppress_Case);
5385
5386          --  Case of two arguments present, where the check is suppressed for
5387          --  a specified entity (given as the second argument of the pragma)
5388
5389          else
5390             --  This is obsolescent in Ada 2005 mode
5391
5392             if Ada_Version >= Ada_2005 then
5393                Check_Restriction (No_Obsolescent_Features, Arg2);
5394             end if;
5395
5396             Check_Optional_Identifier (Arg2, Name_On);
5397             E_Id := Get_Pragma_Arg (Arg2);
5398             Analyze (E_Id);
5399
5400             if not Is_Entity_Name (E_Id) then
5401                Error_Pragma_Arg
5402                  ("second argument of pragma% must be entity name", Arg2);
5403             end if;
5404
5405             E := Entity (E_Id);
5406
5407             if E = Any_Id then
5408                return;
5409             end if;
5410
5411             --  Enforce RM 11.5(7) which requires that for a pragma that
5412             --  appears within a package spec, the named entity must be
5413             --  within the package spec. We allow the package name itself
5414             --  to be mentioned since that makes sense, although it is not
5415             --  strictly allowed by 11.5(7).
5416
5417             if In_Package_Spec
5418               and then E /= Current_Scope
5419               and then Scope (E) /= Current_Scope
5420             then
5421                Error_Pragma_Arg
5422                  ("entity in pragma% is not in package spec (RM 11.5(7))",
5423                   Arg2);
5424             end if;
5425
5426             --  Loop through homonyms. As noted below, in the case of a package
5427             --  spec, only homonyms within the package spec are considered.
5428
5429             loop
5430                Suppress_Unsuppress_Echeck (E, C);
5431
5432                if Is_Generic_Instance (E)
5433                  and then Is_Subprogram (E)
5434                  and then Present (Alias (E))
5435                then
5436                   Suppress_Unsuppress_Echeck (Alias (E), C);
5437                end if;
5438
5439                --  Move to next homonym if not aspect spec case
5440
5441                exit when From_Aspect_Specification (N);
5442                E := Homonym (E);
5443                exit when No (E);
5444
5445                --  If we are within a package specification, the pragma only
5446                --  applies to homonyms in the same scope.
5447
5448                exit when In_Package_Spec
5449                  and then Scope (E) /= Current_Scope;
5450             end loop;
5451          end if;
5452       end Process_Suppress_Unsuppress;
5453
5454       ------------------
5455       -- Set_Exported --
5456       ------------------
5457
5458       procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is
5459       begin
5460          if Is_Imported (E) then
5461             Error_Pragma_Arg
5462               ("cannot export entity& that was previously imported", Arg);
5463
5464          elsif Present (Address_Clause (E)) and then not CodePeer_Mode then
5465             Error_Pragma_Arg
5466               ("cannot export entity& that has an address clause", Arg);
5467          end if;
5468
5469          Set_Is_Exported (E);
5470
5471          --  Generate a reference for entity explicitly, because the
5472          --  identifier may be overloaded and name resolution will not
5473          --  generate one.
5474
5475          Generate_Reference (E, Arg);
5476
5477          --  Deal with exporting non-library level entity
5478
5479          if not Is_Library_Level_Entity (E) then
5480
5481             --  Not allowed at all for subprograms
5482
5483             if Is_Subprogram (E) then
5484                Error_Pragma_Arg ("local subprogram& cannot be exported", Arg);
5485
5486             --  Otherwise set public and statically allocated
5487
5488             else
5489                Set_Is_Public (E);
5490                Set_Is_Statically_Allocated (E);
5491
5492                --  Warn if the corresponding W flag is set and the pragma comes
5493                --  from source. The latter may not be true e.g. on VMS where we
5494                --  expand export pragmas for exception codes associated with
5495                --  imported or exported exceptions. We do not want to generate
5496                --  a warning for something that the user did not write.
5497
5498                if Warn_On_Export_Import
5499                  and then Comes_From_Source (Arg)
5500                then
5501                   Error_Msg_NE
5502                     ("?& has been made static as a result of Export", Arg, E);
5503                   Error_Msg_N
5504                     ("\this usage is non-standard and non-portable", Arg);
5505                end if;
5506             end if;
5507          end if;
5508
5509          if Warn_On_Export_Import and then Is_Type (E) then
5510             Error_Msg_NE ("exporting a type has no effect?", Arg, E);
5511          end if;
5512
5513          if Warn_On_Export_Import and Inside_A_Generic then
5514             Error_Msg_NE
5515               ("all instances of& will have the same external name?", Arg, E);
5516          end if;
5517       end Set_Exported;
5518
5519       ----------------------------------------------
5520       -- Set_Extended_Import_Export_External_Name --
5521       ----------------------------------------------
5522
5523       procedure Set_Extended_Import_Export_External_Name
5524         (Internal_Ent : Entity_Id;
5525          Arg_External : Node_Id)
5526       is
5527          Old_Name : constant Node_Id := Interface_Name (Internal_Ent);
5528          New_Name : Node_Id;
5529
5530       begin
5531          if No (Arg_External) then
5532             return;
5533          end if;
5534
5535          Check_Arg_Is_External_Name (Arg_External);
5536
5537          if Nkind (Arg_External) = N_String_Literal then
5538             if String_Length (Strval (Arg_External)) = 0 then
5539                return;
5540             else
5541                New_Name := Adjust_External_Name_Case (Arg_External);
5542             end if;
5543
5544          elsif Nkind (Arg_External) = N_Identifier then
5545             New_Name := Get_Default_External_Name (Arg_External);
5546
5547          --  Check_Arg_Is_External_Name should let through only identifiers and
5548          --  string literals or static string expressions (which are folded to
5549          --  string literals).
5550
5551          else
5552             raise Program_Error;
5553          end if;
5554
5555          --  If we already have an external name set (by a prior normal Import
5556          --  or Export pragma), then the external names must match
5557
5558          if Present (Interface_Name (Internal_Ent)) then
5559             Check_Matching_Internal_Names : declare
5560                S1 : constant String_Id := Strval (Old_Name);
5561                S2 : constant String_Id := Strval (New_Name);
5562
5563                procedure Mismatch;
5564                --  Called if names do not match
5565
5566                --------------
5567                -- Mismatch --
5568                --------------
5569
5570                procedure Mismatch is
5571                begin
5572                   Error_Msg_Sloc := Sloc (Old_Name);
5573                   Error_Pragma_Arg
5574                     ("external name does not match that given #",
5575                      Arg_External);
5576                end Mismatch;
5577
5578             --  Start of processing for Check_Matching_Internal_Names
5579
5580             begin
5581                if String_Length (S1) /= String_Length (S2) then
5582                   Mismatch;
5583
5584                else
5585                   for J in 1 .. String_Length (S1) loop
5586                      if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then
5587                         Mismatch;
5588                      end if;
5589                   end loop;
5590                end if;
5591             end Check_Matching_Internal_Names;
5592
5593          --  Otherwise set the given name
5594
5595          else
5596             Set_Encoded_Interface_Name (Internal_Ent, New_Name);
5597             Check_Duplicated_Export_Name (New_Name);
5598          end if;
5599       end Set_Extended_Import_Export_External_Name;
5600
5601       ------------------
5602       -- Set_Imported --
5603       ------------------
5604
5605       procedure Set_Imported (E : Entity_Id) is
5606       begin
5607          --  Error message if already imported or exported
5608
5609          if Is_Exported (E) or else Is_Imported (E) then
5610
5611             --  Error if being set Exported twice
5612
5613             if Is_Exported (E) then
5614                Error_Msg_NE ("entity& was previously exported", N, E);
5615
5616             --  OK if Import/Interface case
5617
5618             elsif Import_Interface_Present (N) then
5619                goto OK;
5620
5621             --  Error if being set Imported twice
5622
5623             else
5624                Error_Msg_NE ("entity& was previously imported", N, E);
5625             end if;
5626
5627             Error_Msg_Name_1 := Pname;
5628             Error_Msg_N
5629               ("\(pragma% applies to all previous entities)", N);
5630
5631             Error_Msg_Sloc  := Sloc (E);
5632             Error_Msg_NE ("\import not allowed for& declared#", N, E);
5633
5634          --  Here if not previously imported or exported, OK to import
5635
5636          else
5637             Set_Is_Imported (E);
5638
5639             --  If the entity is an object that is not at the library level,
5640             --  then it is statically allocated. We do not worry about objects
5641             --  with address clauses in this context since they are not really
5642             --  imported in the linker sense.
5643
5644             if Is_Object (E)
5645               and then not Is_Library_Level_Entity (E)
5646               and then No (Address_Clause (E))
5647             then
5648                Set_Is_Statically_Allocated (E);
5649             end if;
5650          end if;
5651
5652          <<OK>> null;
5653       end Set_Imported;
5654
5655       -------------------------
5656       -- Set_Mechanism_Value --
5657       -------------------------
5658
5659       --  Note: the mechanism name has not been analyzed (and cannot indeed be
5660       --  analyzed, since it is semantic nonsense), so we get it in the exact
5661       --  form created by the parser.
5662
5663       procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is
5664          Class        : Node_Id;
5665          Param        : Node_Id;
5666          Mech_Name_Id : Name_Id;
5667
5668          procedure Bad_Class;
5669          --  Signal bad descriptor class name
5670
5671          procedure Bad_Mechanism;
5672          --  Signal bad mechanism name
5673
5674          ---------------
5675          -- Bad_Class --
5676          ---------------
5677
5678          procedure Bad_Class is
5679          begin
5680             Error_Pragma_Arg ("unrecognized descriptor class name", Class);
5681          end Bad_Class;
5682
5683          -------------------------
5684          -- Bad_Mechanism_Value --
5685          -------------------------
5686
5687          procedure Bad_Mechanism is
5688          begin
5689             Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name);
5690          end Bad_Mechanism;
5691
5692       --  Start of processing for Set_Mechanism_Value
5693
5694       begin
5695          if Mechanism (Ent) /= Default_Mechanism then
5696             Error_Msg_NE
5697               ("mechanism for & has already been set", Mech_Name, Ent);
5698          end if;
5699
5700          --  MECHANISM_NAME ::= value | reference | descriptor |
5701          --                     short_descriptor
5702
5703          if Nkind (Mech_Name) = N_Identifier then
5704             if Chars (Mech_Name) = Name_Value then
5705                Set_Mechanism (Ent, By_Copy);
5706                return;
5707
5708             elsif Chars (Mech_Name) = Name_Reference then
5709                Set_Mechanism (Ent, By_Reference);
5710                return;
5711
5712             elsif Chars (Mech_Name) = Name_Descriptor then
5713                Check_VMS (Mech_Name);
5714
5715                --  Descriptor => Short_Descriptor if pragma was given
5716
5717                if Short_Descriptors then
5718                   Set_Mechanism (Ent, By_Short_Descriptor);
5719                else
5720                   Set_Mechanism (Ent, By_Descriptor);
5721                end if;
5722
5723                return;
5724
5725             elsif Chars (Mech_Name) = Name_Short_Descriptor then
5726                Check_VMS (Mech_Name);
5727                Set_Mechanism (Ent, By_Short_Descriptor);
5728                return;
5729
5730             elsif Chars (Mech_Name) = Name_Copy then
5731                Error_Pragma_Arg
5732                  ("bad mechanism name, Value assumed", Mech_Name);
5733
5734             else
5735                Bad_Mechanism;
5736             end if;
5737
5738          --  MECHANISM_NAME ::= descriptor (CLASS_NAME) |
5739          --                     short_descriptor (CLASS_NAME)
5740          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5741
5742          --  Note: this form is parsed as an indexed component
5743
5744          elsif Nkind (Mech_Name) = N_Indexed_Component then
5745             Class := First (Expressions (Mech_Name));
5746
5747             if Nkind (Prefix (Mech_Name)) /= N_Identifier
5748              or else not (Chars (Prefix (Mech_Name)) = Name_Descriptor or else
5749                           Chars (Prefix (Mech_Name)) = Name_Short_Descriptor)
5750              or else Present (Next (Class))
5751             then
5752                Bad_Mechanism;
5753             else
5754                Mech_Name_Id := Chars (Prefix (Mech_Name));
5755
5756                --  Change Descriptor => Short_Descriptor if pragma was given
5757
5758                if Mech_Name_Id = Name_Descriptor
5759                  and then Short_Descriptors
5760                then
5761                   Mech_Name_Id := Name_Short_Descriptor;
5762                end if;
5763             end if;
5764
5765          --  MECHANISM_NAME ::= descriptor (Class => CLASS_NAME) |
5766          --                     short_descriptor (Class => CLASS_NAME)
5767          --  CLASS_NAME     ::= ubs | ubsb | uba | s | sb | a | nca
5768
5769          --  Note: this form is parsed as a function call
5770
5771          elsif Nkind (Mech_Name) = N_Function_Call then
5772             Param := First (Parameter_Associations (Mech_Name));
5773
5774             if Nkind (Name (Mech_Name)) /= N_Identifier
5775               or else not (Chars (Name (Mech_Name)) = Name_Descriptor or else
5776                            Chars (Name (Mech_Name)) = Name_Short_Descriptor)
5777               or else Present (Next (Param))
5778               or else No (Selector_Name (Param))
5779               or else Chars (Selector_Name (Param)) /= Name_Class
5780             then
5781                Bad_Mechanism;
5782             else
5783                Class := Explicit_Actual_Parameter (Param);
5784                Mech_Name_Id := Chars (Name (Mech_Name));
5785             end if;
5786
5787          else
5788             Bad_Mechanism;
5789          end if;
5790
5791          --  Fall through here with Class set to descriptor class name
5792
5793          Check_VMS (Mech_Name);
5794
5795          if Nkind (Class) /= N_Identifier then
5796             Bad_Class;
5797
5798          elsif Mech_Name_Id = Name_Descriptor
5799            and then Chars (Class) = Name_UBS
5800          then
5801             Set_Mechanism (Ent, By_Descriptor_UBS);
5802
5803          elsif Mech_Name_Id = Name_Descriptor
5804            and then Chars (Class) = Name_UBSB
5805          then
5806             Set_Mechanism (Ent, By_Descriptor_UBSB);
5807
5808          elsif Mech_Name_Id = Name_Descriptor
5809            and then Chars (Class) = Name_UBA
5810          then
5811             Set_Mechanism (Ent, By_Descriptor_UBA);
5812
5813          elsif Mech_Name_Id = Name_Descriptor
5814            and then Chars (Class) = Name_S
5815          then
5816             Set_Mechanism (Ent, By_Descriptor_S);
5817
5818          elsif Mech_Name_Id = Name_Descriptor
5819            and then Chars (Class) = Name_SB
5820          then
5821             Set_Mechanism (Ent, By_Descriptor_SB);
5822
5823          elsif Mech_Name_Id = Name_Descriptor
5824            and then Chars (Class) = Name_A
5825          then
5826             Set_Mechanism (Ent, By_Descriptor_A);
5827
5828          elsif Mech_Name_Id = Name_Descriptor
5829            and then Chars (Class) = Name_NCA
5830          then
5831             Set_Mechanism (Ent, By_Descriptor_NCA);
5832
5833          elsif Mech_Name_Id = Name_Short_Descriptor
5834            and then Chars (Class) = Name_UBS
5835          then
5836             Set_Mechanism (Ent, By_Short_Descriptor_UBS);
5837
5838          elsif Mech_Name_Id = Name_Short_Descriptor
5839            and then Chars (Class) = Name_UBSB
5840          then
5841             Set_Mechanism (Ent, By_Short_Descriptor_UBSB);
5842
5843          elsif Mech_Name_Id = Name_Short_Descriptor
5844            and then Chars (Class) = Name_UBA
5845          then
5846             Set_Mechanism (Ent, By_Short_Descriptor_UBA);
5847
5848          elsif Mech_Name_Id = Name_Short_Descriptor
5849            and then Chars (Class) = Name_S
5850          then
5851             Set_Mechanism (Ent, By_Short_Descriptor_S);
5852
5853          elsif Mech_Name_Id = Name_Short_Descriptor
5854            and then Chars (Class) = Name_SB
5855          then
5856             Set_Mechanism (Ent, By_Short_Descriptor_SB);
5857
5858          elsif Mech_Name_Id = Name_Short_Descriptor
5859            and then Chars (Class) = Name_A
5860          then
5861             Set_Mechanism (Ent, By_Short_Descriptor_A);
5862
5863          elsif Mech_Name_Id = Name_Short_Descriptor
5864            and then Chars (Class) = Name_NCA
5865          then
5866             Set_Mechanism (Ent, By_Short_Descriptor_NCA);
5867
5868          else
5869             Bad_Class;
5870          end if;
5871       end Set_Mechanism_Value;
5872
5873       ---------------------------
5874       -- Set_Ravenscar_Profile --
5875       ---------------------------
5876
5877       --  The tasks to be done here are
5878
5879       --    Set required policies
5880
5881       --      pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5882       --      pragma Locking_Policy (Ceiling_Locking)
5883
5884       --    Set Detect_Blocking mode
5885
5886       --    Set required restrictions (see System.Rident for detailed list)
5887
5888       --    Set the No_Dependence rules
5889       --      No_Dependence => Ada.Asynchronous_Task_Control
5890       --      No_Dependence => Ada.Calendar
5891       --      No_Dependence => Ada.Execution_Time.Group_Budget
5892       --      No_Dependence => Ada.Execution_Time.Timers
5893       --      No_Dependence => Ada.Task_Attributes
5894       --      No_Dependence => System.Multiprocessors.Dispatching_Domains
5895
5896       procedure Set_Ravenscar_Profile (N : Node_Id) is
5897          Prefix_Entity   : Entity_Id;
5898          Selector_Entity : Entity_Id;
5899          Prefix_Node     : Node_Id;
5900          Node            : Node_Id;
5901
5902       begin
5903          --  pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
5904
5905          if Task_Dispatching_Policy /= ' '
5906            and then Task_Dispatching_Policy /= 'F'
5907          then
5908             Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
5909             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5910
5911          --  Set the FIFO_Within_Priorities policy, but always preserve
5912          --  System_Location since we like the error message with the run time
5913          --  name.
5914
5915          else
5916             Task_Dispatching_Policy := 'F';
5917
5918             if Task_Dispatching_Policy_Sloc /= System_Location then
5919                Task_Dispatching_Policy_Sloc := Loc;
5920             end if;
5921          end if;
5922
5923          --  pragma Locking_Policy (Ceiling_Locking)
5924
5925          if Locking_Policy /= ' '
5926            and then Locking_Policy /= 'C'
5927          then
5928             Error_Msg_Sloc := Locking_Policy_Sloc;
5929             Error_Pragma ("Profile (Ravenscar) incompatible with policy#");
5930
5931          --  Set the Ceiling_Locking policy, but preserve System_Location since
5932          --  we like the error message with the run time name.
5933
5934          else
5935             Locking_Policy := 'C';
5936
5937             if Locking_Policy_Sloc /= System_Location then
5938                Locking_Policy_Sloc := Loc;
5939             end if;
5940          end if;
5941
5942          --  pragma Detect_Blocking
5943
5944          Detect_Blocking := True;
5945
5946          --  Set the corresponding restrictions
5947
5948          Set_Profile_Restrictions
5949            (Ravenscar, N, Warn => Treat_Restrictions_As_Warnings);
5950
5951          --  Set the No_Dependence restrictions
5952
5953          --  The following No_Dependence restrictions:
5954          --    No_Dependence => Ada.Asynchronous_Task_Control
5955          --    No_Dependence => Ada.Calendar
5956          --    No_Dependence => Ada.Task_Attributes
5957          --  are already set by previous call to Set_Profile_Restrictions.
5958
5959          --  Set the following restrictions which were added to Ada 2005:
5960          --    No_Dependence => Ada.Execution_Time.Group_Budget
5961          --    No_Dependence => Ada.Execution_Time.Timers
5962
5963          if Ada_Version >= Ada_2005 then
5964             Name_Buffer (1 .. 3) := "ada";
5965             Name_Len := 3;
5966
5967             Prefix_Entity := Make_Identifier (Loc, Name_Find);
5968
5969             Name_Buffer (1 .. 14) := "execution_time";
5970             Name_Len := 14;
5971
5972             Selector_Entity := Make_Identifier (Loc, Name_Find);
5973
5974             Prefix_Node :=
5975               Make_Selected_Component
5976                 (Sloc          => Loc,
5977                  Prefix        => Prefix_Entity,
5978                  Selector_Name => Selector_Entity);
5979
5980             Name_Buffer (1 .. 13) := "group_budgets";
5981             Name_Len := 13;
5982
5983             Selector_Entity := Make_Identifier (Loc, Name_Find);
5984
5985             Node :=
5986               Make_Selected_Component
5987                 (Sloc          => Loc,
5988                  Prefix        => Prefix_Node,
5989                  Selector_Name => Selector_Entity);
5990
5991             Set_Restriction_No_Dependence
5992               (Unit    => Node,
5993                Warn    => Treat_Restrictions_As_Warnings,
5994                Profile => Ravenscar);
5995
5996             Name_Buffer (1 .. 6) := "timers";
5997             Name_Len := 6;
5998
5999             Selector_Entity := Make_Identifier (Loc, Name_Find);
6000
6001             Node :=
6002               Make_Selected_Component
6003                 (Sloc          => Loc,
6004                  Prefix        => Prefix_Node,
6005                  Selector_Name => Selector_Entity);
6006
6007             Set_Restriction_No_Dependence
6008               (Unit    => Node,
6009                Warn    => Treat_Restrictions_As_Warnings,
6010                Profile => Ravenscar);
6011          end if;
6012
6013          --  Set the following restrictions which was added to Ada 2012 (see
6014          --  AI-0171):
6015          --    No_Dependence => System.Multiprocessors.Dispatching_Domains
6016
6017          if Ada_Version >= Ada_2012 then
6018             Name_Buffer (1 .. 6) := "system";
6019             Name_Len := 6;
6020
6021             Prefix_Entity := Make_Identifier (Loc, Name_Find);
6022
6023             Name_Buffer (1 .. 15) := "multiprocessors";
6024             Name_Len := 15;
6025
6026             Selector_Entity := Make_Identifier (Loc, Name_Find);
6027
6028             Prefix_Node :=
6029               Make_Selected_Component
6030                 (Sloc          => Loc,
6031                  Prefix        => Prefix_Entity,
6032                  Selector_Name => Selector_Entity);
6033
6034             Name_Buffer (1 .. 19) := "dispatching_domains";
6035             Name_Len := 19;
6036
6037             Selector_Entity := Make_Identifier (Loc, Name_Find);
6038
6039             Node :=
6040               Make_Selected_Component
6041                 (Sloc          => Loc,
6042                  Prefix        => Prefix_Node,
6043                  Selector_Name => Selector_Entity);
6044
6045             Set_Restriction_No_Dependence
6046               (Unit    => Node,
6047                Warn    => Treat_Restrictions_As_Warnings,
6048                Profile => Ravenscar);
6049          end if;
6050       end Set_Ravenscar_Profile;
6051
6052    --  Start of processing for Analyze_Pragma
6053
6054    begin
6055       --  The following code is a defense against recursion. Not clear that
6056       --  this can happen legitimately, but perhaps some error situations
6057       --  can cause it, and we did see this recursion during testing.
6058
6059       if Analyzed (N) then
6060          return;
6061       else
6062          Set_Analyzed (N, True);
6063       end if;
6064
6065       --  Deal with unrecognized pragma
6066
6067       if not Is_Pragma_Name (Pname) then
6068          if Warn_On_Unrecognized_Pragma then
6069             Error_Msg_Name_1 := Pname;
6070             Error_Msg_N ("?unrecognized pragma%!", Pragma_Identifier (N));
6071
6072             for PN in First_Pragma_Name .. Last_Pragma_Name loop
6073                if Is_Bad_Spelling_Of (Pname, PN) then
6074                   Error_Msg_Name_1 := PN;
6075                   Error_Msg_N -- CODEFIX
6076                     ("\?possible misspelling of %!", Pragma_Identifier (N));
6077                   exit;
6078                end if;
6079             end loop;
6080          end if;
6081
6082          return;
6083       end if;
6084
6085       --  Here to start processing for recognized pragma
6086
6087       Prag_Id := Get_Pragma_Id (Pname);
6088
6089       --  Preset arguments
6090
6091       Arg_Count := 0;
6092       Arg1      := Empty;
6093       Arg2      := Empty;
6094       Arg3      := Empty;
6095       Arg4      := Empty;
6096
6097       if Present (Pragma_Argument_Associations (N)) then
6098          Arg_Count := List_Length (Pragma_Argument_Associations (N));
6099          Arg1 := First (Pragma_Argument_Associations (N));
6100
6101          if Present (Arg1) then
6102             Arg2 := Next (Arg1);
6103
6104             if Present (Arg2) then
6105                Arg3 := Next (Arg2);
6106
6107                if Present (Arg3) then
6108                   Arg4 := Next (Arg3);
6109                end if;
6110             end if;
6111          end if;
6112       end if;
6113
6114       --  An enumeration type defines the pragmas that are supported by the
6115       --  implementation. Get_Pragma_Id (in package Prag) transforms a name
6116       --  into the corresponding enumeration value for the following case.
6117
6118       case Prag_Id is
6119
6120          -----------------
6121          -- Abort_Defer --
6122          -----------------
6123
6124          --  pragma Abort_Defer;
6125
6126          when Pragma_Abort_Defer =>
6127             GNAT_Pragma;
6128             Check_Arg_Count (0);
6129
6130             --  The only required semantic processing is to check the
6131             --  placement. This pragma must appear at the start of the
6132             --  statement sequence of a handled sequence of statements.
6133
6134             if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements
6135               or else N /= First (Statements (Parent (N)))
6136             then
6137                Pragma_Misplaced;
6138             end if;
6139
6140          ------------
6141          -- Ada_83 --
6142          ------------
6143
6144          --  pragma Ada_83;
6145
6146          --  Note: this pragma also has some specific processing in Par.Prag
6147          --  because we want to set the Ada version mode during parsing.
6148
6149          when Pragma_Ada_83 =>
6150             GNAT_Pragma;
6151             Check_Arg_Count (0);
6152
6153             --  We really should check unconditionally for proper configuration
6154             --  pragma placement, since we really don't want mixed Ada modes
6155             --  within a single unit, and the GNAT reference manual has always
6156             --  said this was a configuration pragma, but we did not check and
6157             --  are hesitant to add the check now.
6158
6159             --  However, we really cannot tolerate mixing Ada 2005 or Ada 2012
6160             --  with Ada 83 or Ada 95, so we must check if we are in Ada 2005
6161             --  or Ada 2012 mode.
6162
6163             if Ada_Version >= Ada_2005 then
6164                Check_Valid_Configuration_Pragma;
6165             end if;
6166
6167             --  Now set Ada 83 mode
6168
6169             Ada_Version := Ada_83;
6170             Ada_Version_Explicit := Ada_Version;
6171
6172          ------------
6173          -- Ada_95 --
6174          ------------
6175
6176          --  pragma Ada_95;
6177
6178          --  Note: this pragma also has some specific processing in Par.Prag
6179          --  because we want to set the Ada 83 version mode during parsing.
6180
6181          when Pragma_Ada_95 =>
6182             GNAT_Pragma;
6183             Check_Arg_Count (0);
6184
6185             --  We really should check unconditionally for proper configuration
6186             --  pragma placement, since we really don't want mixed Ada modes
6187             --  within a single unit, and the GNAT reference manual has always
6188             --  said this was a configuration pragma, but we did not check and
6189             --  are hesitant to add the check now.
6190
6191             --  However, we really cannot tolerate mixing Ada 2005 with Ada 83
6192             --  or Ada 95, so we must check if we are in Ada 2005 mode.
6193
6194             if Ada_Version >= Ada_2005 then
6195                Check_Valid_Configuration_Pragma;
6196             end if;
6197
6198             --  Now set Ada 95 mode
6199
6200             Ada_Version := Ada_95;
6201             Ada_Version_Explicit := Ada_Version;
6202
6203          ---------------------
6204          -- Ada_05/Ada_2005 --
6205          ---------------------
6206
6207          --  pragma Ada_05;
6208          --  pragma Ada_05 (LOCAL_NAME);
6209
6210          --  pragma Ada_2005;
6211          --  pragma Ada_2005 (LOCAL_NAME):
6212
6213          --  Note: these pragmas also have some specific processing in Par.Prag
6214          --  because we want to set the Ada 2005 version mode during parsing.
6215
6216          when Pragma_Ada_05 | Pragma_Ada_2005 => declare
6217             E_Id : Node_Id;
6218
6219          begin
6220             GNAT_Pragma;
6221
6222             if Arg_Count = 1 then
6223                Check_Arg_Is_Local_Name (Arg1);
6224                E_Id := Get_Pragma_Arg (Arg1);
6225
6226                if Etype (E_Id) = Any_Type then
6227                   return;
6228                end if;
6229
6230                Set_Is_Ada_2005_Only (Entity (E_Id));
6231
6232             else
6233                Check_Arg_Count (0);
6234
6235                --  For Ada_2005 we unconditionally enforce the documented
6236                --  configuration pragma placement, since we do not want to
6237                --  tolerate mixed modes in a unit involving Ada 2005. That
6238                --  would cause real difficulties for those cases where there
6239                --  are incompatibilities between Ada 95 and Ada 2005.
6240
6241                Check_Valid_Configuration_Pragma;
6242
6243                --  Now set appropriate Ada mode
6244
6245                Ada_Version          := Ada_2005;
6246                Ada_Version_Explicit := Ada_2005;
6247             end if;
6248          end;
6249
6250          ---------------------
6251          -- Ada_12/Ada_2012 --
6252          ---------------------
6253
6254          --  pragma Ada_12;
6255          --  pragma Ada_12 (LOCAL_NAME);
6256
6257          --  pragma Ada_2012;
6258          --  pragma Ada_2012 (LOCAL_NAME):
6259
6260          --  Note: these pragmas also have some specific processing in Par.Prag
6261          --  because we want to set the Ada 2012 version mode during parsing.
6262
6263          when Pragma_Ada_12 | Pragma_Ada_2012 => declare
6264             E_Id : Node_Id;
6265
6266          begin
6267             GNAT_Pragma;
6268
6269             if Arg_Count = 1 then
6270                Check_Arg_Is_Local_Name (Arg1);
6271                E_Id := Get_Pragma_Arg (Arg1);
6272
6273                if Etype (E_Id) = Any_Type then
6274                   return;
6275                end if;
6276
6277                Set_Is_Ada_2012_Only (Entity (E_Id));
6278
6279             else
6280                Check_Arg_Count (0);
6281
6282                --  For Ada_2012 we unconditionally enforce the documented
6283                --  configuration pragma placement, since we do not want to
6284                --  tolerate mixed modes in a unit involving Ada 2012. That
6285                --  would cause real difficulties for those cases where there
6286                --  are incompatibilities between Ada 95 and Ada 2012. We could
6287                --  allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
6288
6289                Check_Valid_Configuration_Pragma;
6290
6291                --  Now set appropriate Ada mode
6292
6293                Ada_Version          := Ada_2012;
6294                Ada_Version_Explicit := Ada_2012;
6295             end if;
6296          end;
6297
6298          ----------------------
6299          -- All_Calls_Remote --
6300          ----------------------
6301
6302          --  pragma All_Calls_Remote [(library_package_NAME)];
6303
6304          when Pragma_All_Calls_Remote => All_Calls_Remote : declare
6305             Lib_Entity : Entity_Id;
6306
6307          begin
6308             Check_Ada_83_Warning;
6309             Check_Valid_Library_Unit_Pragma;
6310
6311             if Nkind (N) = N_Null_Statement then
6312                return;
6313             end if;
6314
6315             Lib_Entity := Find_Lib_Unit_Name;
6316
6317             --  This pragma should only apply to a RCI unit (RM E.2.3(23))
6318
6319             if Present (Lib_Entity)
6320               and then not Debug_Flag_U
6321             then
6322                if not Is_Remote_Call_Interface (Lib_Entity) then
6323                   Error_Pragma ("pragma% only apply to rci unit");
6324
6325                --  Set flag for entity of the library unit
6326
6327                else
6328                   Set_Has_All_Calls_Remote (Lib_Entity);
6329                end if;
6330
6331             end if;
6332          end All_Calls_Remote;
6333
6334          --------------
6335          -- Annotate --
6336          --------------
6337
6338          --  pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}]);
6339          --  ARG ::= NAME | EXPRESSION
6340
6341          --  The first two arguments are by convention intended to refer to an
6342          --  external tool and a tool-specific function. These arguments are
6343          --  not analyzed.
6344
6345          when Pragma_Annotate => Annotate : declare
6346             Arg : Node_Id;
6347             Exp : Node_Id;
6348
6349          begin
6350             GNAT_Pragma;
6351             Check_At_Least_N_Arguments (1);
6352             Check_Arg_Is_Identifier (Arg1);
6353             Check_No_Identifiers;
6354             Store_Note (N);
6355
6356             --  Second parameter is optional, it is never analyzed
6357
6358             if No (Arg2) then
6359                null;
6360
6361             --  Here if we have a second parameter
6362
6363             else
6364                --  Second parameter must be identifier
6365
6366                Check_Arg_Is_Identifier (Arg2);
6367
6368                --  Process remaining parameters if any
6369
6370                Arg := Next (Arg2);
6371                while Present (Arg) loop
6372                   Exp := Get_Pragma_Arg (Arg);
6373                   Analyze (Exp);
6374
6375                   if Is_Entity_Name (Exp) then
6376                      null;
6377
6378                   --  For string literals, we assume Standard_String as the
6379                   --  type, unless the string contains wide or wide_wide
6380                   --  characters.
6381
6382                   elsif Nkind (Exp) = N_String_Literal then
6383                      if Has_Wide_Wide_Character (Exp) then
6384                         Resolve (Exp, Standard_Wide_Wide_String);
6385                      elsif Has_Wide_Character (Exp) then
6386                         Resolve (Exp, Standard_Wide_String);
6387                      else
6388                         Resolve (Exp, Standard_String);
6389                      end if;
6390
6391                   elsif Is_Overloaded (Exp) then
6392                         Error_Pragma_Arg
6393                           ("ambiguous argument for pragma%", Exp);
6394
6395                   else
6396                      Resolve (Exp);
6397                   end if;
6398
6399                   Next (Arg);
6400                end loop;
6401             end if;
6402          end Annotate;
6403
6404          ------------
6405          -- Assert --
6406          ------------
6407
6408          --  pragma Assert ([Check =>] Boolean_EXPRESSION
6409          --                 [, [Message =>] Static_String_EXPRESSION]);
6410
6411          when Pragma_Assert => Assert : declare
6412             Expr : Node_Id;
6413             Newa : List_Id;
6414
6415          begin
6416             Ada_2005_Pragma;
6417             Check_At_Least_N_Arguments (1);
6418             Check_At_Most_N_Arguments (2);
6419             Check_Arg_Order ((Name_Check, Name_Message));
6420             Check_Optional_Identifier (Arg1, Name_Check);
6421
6422             --  We treat pragma Assert as equivalent to:
6423
6424             --    pragma Check (Assertion, condition [, msg]);
6425
6426             --  So rewrite pragma in this manner, and analyze the result
6427
6428             Expr := Get_Pragma_Arg (Arg1);
6429             Newa := New_List (
6430               Make_Pragma_Argument_Association (Loc,
6431                 Expression => Make_Identifier (Loc, Name_Assertion)),
6432
6433               Make_Pragma_Argument_Association (Sloc (Expr),
6434                 Expression => Expr));
6435
6436             if Arg_Count > 1 then
6437                Check_Optional_Identifier (Arg2, Name_Message);
6438                Analyze_And_Resolve (Get_Pragma_Arg (Arg2), Standard_String);
6439                Append_To (Newa, Relocate_Node (Arg2));
6440             end if;
6441
6442             Rewrite (N,
6443               Make_Pragma (Loc,
6444                 Chars                        => Name_Check,
6445                 Pragma_Argument_Associations => Newa));
6446             Analyze (N);
6447          end Assert;
6448
6449          ----------------------
6450          -- Assertion_Policy --
6451          ----------------------
6452
6453          --  pragma Assertion_Policy (Check | Disable |Ignore)
6454
6455          when Pragma_Assertion_Policy => Assertion_Policy : declare
6456             Policy : Node_Id;
6457
6458          begin
6459             Ada_2005_Pragma;
6460             Check_Valid_Configuration_Pragma;
6461             Check_Arg_Count (1);
6462             Check_No_Identifiers;
6463             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
6464
6465             --  We treat pragma Assertion_Policy as equivalent to:
6466
6467             --    pragma Check_Policy (Assertion, policy)
6468
6469             --  So rewrite the pragma in that manner and link on to the chain
6470             --  of Check_Policy pragmas, marking the pragma as analyzed.
6471
6472             Policy := Get_Pragma_Arg (Arg1);
6473
6474             Rewrite (N,
6475               Make_Pragma (Loc,
6476                 Chars => Name_Check_Policy,
6477
6478                 Pragma_Argument_Associations => New_List (
6479                   Make_Pragma_Argument_Association (Loc,
6480                     Expression => Make_Identifier (Loc, Name_Assertion)),
6481
6482                   Make_Pragma_Argument_Association (Loc,
6483                     Expression =>
6484                       Make_Identifier (Sloc (Policy), Chars (Policy))))));
6485
6486             Set_Analyzed (N);
6487             Set_Next_Pragma (N, Opt.Check_Policy_List);
6488             Opt.Check_Policy_List := N;
6489          end Assertion_Policy;
6490
6491          ------------------------------
6492          -- Assume_No_Invalid_Values --
6493          ------------------------------
6494
6495          --  pragma Assume_No_Invalid_Values (On | Off);
6496
6497          when Pragma_Assume_No_Invalid_Values =>
6498             GNAT_Pragma;
6499             Check_Valid_Configuration_Pragma;
6500             Check_Arg_Count (1);
6501             Check_No_Identifiers;
6502             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
6503
6504             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
6505                Assume_No_Invalid_Values := True;
6506             else
6507                Assume_No_Invalid_Values := False;
6508             end if;
6509
6510          ---------------
6511          -- AST_Entry --
6512          ---------------
6513
6514          --  pragma AST_Entry (entry_IDENTIFIER);
6515
6516          when Pragma_AST_Entry => AST_Entry : declare
6517             Ent : Node_Id;
6518
6519          begin
6520             GNAT_Pragma;
6521             Check_VMS (N);
6522             Check_Arg_Count (1);
6523             Check_No_Identifiers;
6524             Check_Arg_Is_Local_Name (Arg1);
6525             Ent := Entity (Get_Pragma_Arg (Arg1));
6526
6527             --  Note: the implementation of the AST_Entry pragma could handle
6528             --  the entry family case fine, but for now we are consistent with
6529             --  the DEC rules, and do not allow the pragma, which of course
6530             --  has the effect of also forbidding the attribute.
6531
6532             if Ekind (Ent) /= E_Entry then
6533                Error_Pragma_Arg
6534                  ("pragma% argument must be simple entry name", Arg1);
6535
6536             elsif Is_AST_Entry (Ent) then
6537                Error_Pragma_Arg
6538                  ("duplicate % pragma for entry", Arg1);
6539
6540             elsif Has_Homonym (Ent) then
6541                Error_Pragma_Arg
6542                  ("pragma% argument cannot specify overloaded entry", Arg1);
6543
6544             else
6545                declare
6546                   FF : constant Entity_Id := First_Formal (Ent);
6547
6548                begin
6549                   if Present (FF) then
6550                      if Present (Next_Formal (FF)) then
6551                         Error_Pragma_Arg
6552                           ("entry for pragma% can have only one argument",
6553                            Arg1);
6554
6555                      elsif Parameter_Mode (FF) /= E_In_Parameter then
6556                         Error_Pragma_Arg
6557                           ("entry parameter for pragma% must have mode IN",
6558                            Arg1);
6559                      end if;
6560                   end if;
6561                end;
6562
6563                Set_Is_AST_Entry (Ent);
6564             end if;
6565          end AST_Entry;
6566
6567          ------------------
6568          -- Asynchronous --
6569          ------------------
6570
6571          --  pragma Asynchronous (LOCAL_NAME);
6572
6573          when Pragma_Asynchronous => Asynchronous : declare
6574             Nm     : Entity_Id;
6575             C_Ent  : Entity_Id;
6576             L      : List_Id;
6577             S      : Node_Id;
6578             N      : Node_Id;
6579             Formal : Entity_Id;
6580
6581             procedure Process_Async_Pragma;
6582             --  Common processing for procedure and access-to-procedure case
6583
6584             --------------------------
6585             -- Process_Async_Pragma --
6586             --------------------------
6587
6588             procedure Process_Async_Pragma is
6589             begin
6590                if No (L) then
6591                   Set_Is_Asynchronous (Nm);
6592                   return;
6593                end if;
6594
6595                --  The formals should be of mode IN (RM E.4.1(6))
6596
6597                S := First (L);
6598                while Present (S) loop
6599                   Formal := Defining_Identifier (S);
6600
6601                   if Nkind (Formal) = N_Defining_Identifier
6602                     and then Ekind (Formal) /= E_In_Parameter
6603                   then
6604                      Error_Pragma_Arg
6605                        ("pragma% procedure can only have IN parameter",
6606                         Arg1);
6607                   end if;
6608
6609                   Next (S);
6610                end loop;
6611
6612                Set_Is_Asynchronous (Nm);
6613             end Process_Async_Pragma;
6614
6615          --  Start of processing for pragma Asynchronous
6616
6617          begin
6618             Check_Ada_83_Warning;
6619             Check_No_Identifiers;
6620             Check_Arg_Count (1);
6621             Check_Arg_Is_Local_Name (Arg1);
6622
6623             if Debug_Flag_U then
6624                return;
6625             end if;
6626
6627             C_Ent := Cunit_Entity (Current_Sem_Unit);
6628             Analyze (Get_Pragma_Arg (Arg1));
6629             Nm := Entity (Get_Pragma_Arg (Arg1));
6630
6631             if not Is_Remote_Call_Interface (C_Ent)
6632               and then not Is_Remote_Types (C_Ent)
6633             then
6634                --  This pragma should only appear in an RCI or Remote Types
6635                --  unit (RM E.4.1(4)).
6636
6637                Error_Pragma
6638                  ("pragma% not in Remote_Call_Interface or " &
6639                   "Remote_Types unit");
6640             end if;
6641
6642             if Ekind (Nm) = E_Procedure
6643               and then Nkind (Parent (Nm)) = N_Procedure_Specification
6644             then
6645                if not Is_Remote_Call_Interface (Nm) then
6646                   Error_Pragma_Arg
6647                     ("pragma% cannot be applied on non-remote procedure",
6648                      Arg1);
6649                end if;
6650
6651                L := Parameter_Specifications (Parent (Nm));
6652                Process_Async_Pragma;
6653                return;
6654
6655             elsif Ekind (Nm) = E_Function then
6656                Error_Pragma_Arg
6657                  ("pragma% cannot be applied to function", Arg1);
6658
6659             elsif Is_Remote_Access_To_Subprogram_Type (Nm) then
6660                   if Is_Record_Type (Nm) then
6661
6662                   --  A record type that is the Equivalent_Type for a remote
6663                   --  access-to-subprogram type.
6664
6665                      N := Declaration_Node (Corresponding_Remote_Type (Nm));
6666
6667                   else
6668                      --  A non-expanded RAS type (distribution is not enabled)
6669
6670                      N := Declaration_Node (Nm);
6671                   end if;
6672
6673                if Nkind (N) = N_Full_Type_Declaration
6674                  and then Nkind (Type_Definition (N)) =
6675                                      N_Access_Procedure_Definition
6676                then
6677                   L := Parameter_Specifications (Type_Definition (N));
6678                   Process_Async_Pragma;
6679
6680                   if Is_Asynchronous (Nm)
6681                     and then Expander_Active
6682                     and then Get_PCS_Name /= Name_No_DSA
6683                   then
6684                      RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm));
6685                   end if;
6686
6687                else
6688                   Error_Pragma_Arg
6689                     ("pragma% cannot reference access-to-function type",
6690                     Arg1);
6691                end if;
6692
6693             --  Only other possibility is Access-to-class-wide type
6694
6695             elsif Is_Access_Type (Nm)
6696               and then Is_Class_Wide_Type (Designated_Type (Nm))
6697             then
6698                Check_First_Subtype (Arg1);
6699                Set_Is_Asynchronous (Nm);
6700                if Expander_Active then
6701                   RACW_Type_Is_Asynchronous (Nm);
6702                end if;
6703
6704             else
6705                Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1);
6706             end if;
6707          end Asynchronous;
6708
6709          ------------
6710          -- Atomic --
6711          ------------
6712
6713          --  pragma Atomic (LOCAL_NAME);
6714
6715          when Pragma_Atomic =>
6716             Process_Atomic_Shared_Volatile;
6717
6718          -----------------------
6719          -- Atomic_Components --
6720          -----------------------
6721
6722          --  pragma Atomic_Components (array_LOCAL_NAME);
6723
6724          --  This processing is shared by Volatile_Components
6725
6726          when Pragma_Atomic_Components   |
6727               Pragma_Volatile_Components =>
6728
6729          Atomic_Components : declare
6730             E_Id : Node_Id;
6731             E    : Entity_Id;
6732             D    : Node_Id;
6733             K    : Node_Kind;
6734
6735          begin
6736             Check_Ada_83_Warning;
6737             Check_No_Identifiers;
6738             Check_Arg_Count (1);
6739             Check_Arg_Is_Local_Name (Arg1);
6740             E_Id := Get_Pragma_Arg (Arg1);
6741
6742             if Etype (E_Id) = Any_Type then
6743                return;
6744             end if;
6745
6746             E := Entity (E_Id);
6747
6748             Check_Duplicate_Pragma (E);
6749
6750             if Rep_Item_Too_Early (E, N)
6751                  or else
6752                Rep_Item_Too_Late (E, N)
6753             then
6754                return;
6755             end if;
6756
6757             D := Declaration_Node (E);
6758             K := Nkind (D);
6759
6760             if (K = N_Full_Type_Declaration and then Is_Array_Type (E))
6761               or else
6762                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
6763                    and then Nkind (D) = N_Object_Declaration
6764                    and then Nkind (Object_Definition (D)) =
6765                                        N_Constrained_Array_Definition)
6766             then
6767                --  The flag is set on the object, or on the base type
6768
6769                if Nkind (D) /= N_Object_Declaration then
6770                   E := Base_Type (E);
6771                end if;
6772
6773                Set_Has_Volatile_Components (E);
6774
6775                if Prag_Id = Pragma_Atomic_Components then
6776                   Set_Has_Atomic_Components (E);
6777                end if;
6778
6779             else
6780                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
6781             end if;
6782          end Atomic_Components;
6783
6784          --------------------
6785          -- Attach_Handler --
6786          --------------------
6787
6788          --  pragma Attach_Handler (handler_NAME, EXPRESSION);
6789
6790          when Pragma_Attach_Handler =>
6791             Check_Ada_83_Warning;
6792             Check_No_Identifiers;
6793             Check_Arg_Count (2);
6794
6795             if No_Run_Time_Mode then
6796                Error_Msg_CRT ("Attach_Handler pragma", N);
6797             else
6798                Check_Interrupt_Or_Attach_Handler;
6799
6800                --  The expression that designates the attribute may depend on a
6801                --  discriminant, and is therefore a per- object expression, to
6802                --  be expanded in the init proc. If expansion is enabled, then
6803                --  perform semantic checks on a copy only.
6804
6805                if Expander_Active then
6806                   declare
6807                      Temp : constant Node_Id :=
6808                               New_Copy_Tree (Get_Pragma_Arg (Arg2));
6809                   begin
6810                      Set_Parent (Temp, N);
6811                      Preanalyze_And_Resolve (Temp, RTE (RE_Interrupt_ID));
6812                   end;
6813
6814                else
6815                   Analyze (Get_Pragma_Arg (Arg2));
6816                   Resolve (Get_Pragma_Arg (Arg2), RTE (RE_Interrupt_ID));
6817                end if;
6818
6819                Process_Interrupt_Or_Attach_Handler;
6820             end if;
6821
6822          --------------------
6823          -- C_Pass_By_Copy --
6824          --------------------
6825
6826          --  pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
6827
6828          when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare
6829             Arg : Node_Id;
6830             Val : Uint;
6831
6832          begin
6833             GNAT_Pragma;
6834             Check_Valid_Configuration_Pragma;
6835             Check_Arg_Count (1);
6836             Check_Optional_Identifier (Arg1, "max_size");
6837
6838             Arg := Get_Pragma_Arg (Arg1);
6839             Check_Arg_Is_Static_Expression (Arg, Any_Integer);
6840
6841             Val := Expr_Value (Arg);
6842
6843             if Val <= 0 then
6844                Error_Pragma_Arg
6845                  ("maximum size for pragma% must be positive", Arg1);
6846
6847             elsif UI_Is_In_Int_Range (Val) then
6848                Default_C_Record_Mechanism := UI_To_Int (Val);
6849
6850             --  If a giant value is given, Int'Last will do well enough.
6851             --  If sometime someone complains that a record larger than
6852             --  two gigabytes is not copied, we will worry about it then!
6853
6854             else
6855                Default_C_Record_Mechanism := Mechanism_Type'Last;
6856             end if;
6857          end C_Pass_By_Copy;
6858
6859          -----------
6860          -- Check --
6861          -----------
6862
6863          --  pragma Check ([Name    =>] IDENTIFIER,
6864          --                [Check   =>] Boolean_EXPRESSION
6865          --              [,[Message =>] String_EXPRESSION]);
6866
6867          when Pragma_Check => Check : declare
6868             Expr : Node_Id;
6869             Eloc : Source_Ptr;
6870
6871             Check_On : Boolean;
6872             --  Set True if category of assertions referenced by Name enabled
6873
6874          begin
6875             GNAT_Pragma;
6876             Check_At_Least_N_Arguments (2);
6877             Check_At_Most_N_Arguments (3);
6878             Check_Optional_Identifier (Arg1, Name_Name);
6879             Check_Optional_Identifier (Arg2, Name_Check);
6880
6881             if Arg_Count = 3 then
6882                Check_Optional_Identifier (Arg3, Name_Message);
6883                Analyze_And_Resolve (Get_Pragma_Arg (Arg3), Standard_String);
6884             end if;
6885
6886             Check_Arg_Is_Identifier (Arg1);
6887
6888             --  Completely ignore if disabled
6889
6890             if Check_Disabled (Chars (Get_Pragma_Arg (Arg1))) then
6891                Rewrite (N, Make_Null_Statement (Loc));
6892                Analyze (N);
6893                return;
6894             end if;
6895
6896             --  Indicate if pragma is enabled. The Original_Node reference here
6897             --  is to deal with pragma Assert rewritten as a Check pragma.
6898
6899             Check_On := Check_Enabled (Chars (Get_Pragma_Arg (Arg1)));
6900
6901             if Check_On then
6902                Set_SCO_Pragma_Enabled (Loc);
6903             end if;
6904
6905             --  If expansion is active and the check is not enabled then we
6906             --  rewrite the Check as:
6907
6908             --    if False and then condition then
6909             --       null;
6910             --    end if;
6911
6912             --  The reason we do this rewriting during semantic analysis rather
6913             --  than as part of normal expansion is that we cannot analyze and
6914             --  expand the code for the boolean expression directly, or it may
6915             --  cause insertion of actions that would escape the attempt to
6916             --  suppress the check code.
6917
6918             --  Note that the Sloc for the if statement corresponds to the
6919             --  argument condition, not the pragma itself. The reason for this
6920             --  is that we may generate a warning if the condition is False at
6921             --  compile time, and we do not want to delete this warning when we
6922             --  delete the if statement.
6923
6924             Expr := Get_Pragma_Arg (Arg2);
6925
6926             if Expander_Active and then not Check_On then
6927                Eloc := Sloc (Expr);
6928
6929                Rewrite (N,
6930                  Make_If_Statement (Eloc,
6931                    Condition =>
6932                      Make_And_Then (Eloc,
6933                        Left_Opnd  => New_Occurrence_Of (Standard_False, Eloc),
6934                        Right_Opnd => Expr),
6935                    Then_Statements => New_List (
6936                      Make_Null_Statement (Eloc))));
6937
6938                Analyze (N);
6939
6940             --  Check is active
6941
6942             else
6943                Analyze_And_Resolve (Expr, Any_Boolean);
6944             end if;
6945          end Check;
6946
6947          ----------------
6948          -- Check_Name --
6949          ----------------
6950
6951          --  pragma Check_Name (check_IDENTIFIER);
6952
6953          when Pragma_Check_Name =>
6954             Check_No_Identifiers;
6955             GNAT_Pragma;
6956             Check_Valid_Configuration_Pragma;
6957             Check_Arg_Count (1);
6958             Check_Arg_Is_Identifier (Arg1);
6959
6960             declare
6961                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
6962
6963             begin
6964                for J in Check_Names.First .. Check_Names.Last loop
6965                   if Check_Names.Table (J) = Nam then
6966                      return;
6967                   end if;
6968                end loop;
6969
6970                Check_Names.Append (Nam);
6971             end;
6972
6973          ------------------
6974          -- Check_Policy --
6975          ------------------
6976
6977          --  pragma Check_Policy (
6978          --    [Name   =>] IDENTIFIER,
6979          --    [Policy =>] POLICY_IDENTIFIER);
6980
6981          --  POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE
6982
6983          --  Note: this is a configuration pragma, but it is allowed to appear
6984          --  anywhere else.
6985
6986          when Pragma_Check_Policy =>
6987             GNAT_Pragma;
6988             Check_Arg_Count (2);
6989             Check_Optional_Identifier (Arg1, Name_Name);
6990             Check_Optional_Identifier (Arg2, Name_Policy);
6991             Check_Arg_Is_One_Of
6992               (Arg2, Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore);
6993
6994             --  A Check_Policy pragma can appear either as a configuration
6995             --  pragma, or in a declarative part or a package spec (see RM
6996             --  11.5(5) for rules for Suppress/Unsuppress which are also
6997             --  followed for Check_Policy).
6998
6999             if not Is_Configuration_Pragma then
7000                Check_Is_In_Decl_Part_Or_Package_Spec;
7001             end if;
7002
7003             Set_Next_Pragma (N, Opt.Check_Policy_List);
7004             Opt.Check_Policy_List := N;
7005
7006          ---------------------
7007          -- CIL_Constructor --
7008          ---------------------
7009
7010          --  pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
7011
7012          --  Processing for this pragma is shared with Java_Constructor
7013
7014          -------------
7015          -- Comment --
7016          -------------
7017
7018          --  pragma Comment (static_string_EXPRESSION)
7019
7020          --  Processing for pragma Comment shares the circuitry for pragma
7021          --  Ident. The only differences are that Ident enforces a limit of 31
7022          --  characters on its argument, and also enforces limitations on
7023          --  placement for DEC compatibility. Pragma Comment shares neither of
7024          --  these restrictions.
7025
7026          -------------------
7027          -- Common_Object --
7028          -------------------
7029
7030          --  pragma Common_Object (
7031          --        [Internal =>] LOCAL_NAME
7032          --     [, [External =>] EXTERNAL_SYMBOL]
7033          --     [, [Size     =>] EXTERNAL_SYMBOL]);
7034
7035          --  Processing for this pragma is shared with Psect_Object
7036
7037          ------------------------
7038          -- Compile_Time_Error --
7039          ------------------------
7040
7041          --  pragma Compile_Time_Error
7042          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7043
7044          when Pragma_Compile_Time_Error =>
7045             GNAT_Pragma;
7046             Process_Compile_Time_Warning_Or_Error;
7047
7048          --------------------------
7049          -- Compile_Time_Warning --
7050          --------------------------
7051
7052          --  pragma Compile_Time_Warning
7053          --    (boolean_EXPRESSION, static_string_EXPRESSION);
7054
7055          when Pragma_Compile_Time_Warning =>
7056             GNAT_Pragma;
7057             Process_Compile_Time_Warning_Or_Error;
7058
7059          -------------------
7060          -- Compiler_Unit --
7061          -------------------
7062
7063          when Pragma_Compiler_Unit =>
7064             GNAT_Pragma;
7065             Check_Arg_Count (0);
7066             Set_Is_Compiler_Unit (Get_Source_Unit (N));
7067
7068          -----------------------------
7069          -- Complete_Representation --
7070          -----------------------------
7071
7072          --  pragma Complete_Representation;
7073
7074          when Pragma_Complete_Representation =>
7075             GNAT_Pragma;
7076             Check_Arg_Count (0);
7077
7078             if Nkind (Parent (N)) /= N_Record_Representation_Clause then
7079                Error_Pragma
7080                  ("pragma & must appear within record representation clause");
7081             end if;
7082
7083          ----------------------------
7084          -- Complex_Representation --
7085          ----------------------------
7086
7087          --  pragma Complex_Representation ([Entity =>] LOCAL_NAME);
7088
7089          when Pragma_Complex_Representation => Complex_Representation : declare
7090             E_Id : Entity_Id;
7091             E    : Entity_Id;
7092             Ent  : Entity_Id;
7093
7094          begin
7095             GNAT_Pragma;
7096             Check_Arg_Count (1);
7097             Check_Optional_Identifier (Arg1, Name_Entity);
7098             Check_Arg_Is_Local_Name (Arg1);
7099             E_Id := Get_Pragma_Arg (Arg1);
7100
7101             if Etype (E_Id) = Any_Type then
7102                return;
7103             end if;
7104
7105             E := Entity (E_Id);
7106
7107             if not Is_Record_Type (E) then
7108                Error_Pragma_Arg
7109                  ("argument for pragma% must be record type", Arg1);
7110             end if;
7111
7112             Ent := First_Entity (E);
7113
7114             if No (Ent)
7115               or else No (Next_Entity (Ent))
7116               or else Present (Next_Entity (Next_Entity (Ent)))
7117               or else not Is_Floating_Point_Type (Etype (Ent))
7118               or else Etype (Ent) /= Etype (Next_Entity (Ent))
7119             then
7120                Error_Pragma_Arg
7121                  ("record for pragma% must have two fields of the same "
7122                   & "floating-point type", Arg1);
7123
7124             else
7125                Set_Has_Complex_Representation (Base_Type (E));
7126
7127                --  We need to treat the type has having a non-standard
7128                --  representation, for back-end purposes, even though in
7129                --  general a complex will have the default representation
7130                --  of a record with two real components.
7131
7132                Set_Has_Non_Standard_Rep (Base_Type (E));
7133             end if;
7134          end Complex_Representation;
7135
7136          -------------------------
7137          -- Component_Alignment --
7138          -------------------------
7139
7140          --  pragma Component_Alignment (
7141          --        [Form =>] ALIGNMENT_CHOICE
7142          --     [, [Name =>] type_LOCAL_NAME]);
7143          --
7144          --   ALIGNMENT_CHOICE ::=
7145          --     Component_Size
7146          --   | Component_Size_4
7147          --   | Storage_Unit
7148          --   | Default
7149
7150          when Pragma_Component_Alignment => Component_AlignmentP : declare
7151             Args  : Args_List (1 .. 2);
7152             Names : constant Name_List (1 .. 2) := (
7153                       Name_Form,
7154                       Name_Name);
7155
7156             Form  : Node_Id renames Args (1);
7157             Name  : Node_Id renames Args (2);
7158
7159             Atype : Component_Alignment_Kind;
7160             Typ   : Entity_Id;
7161
7162          begin
7163             GNAT_Pragma;
7164             Gather_Associations (Names, Args);
7165
7166             if No (Form) then
7167                Error_Pragma ("missing Form argument for pragma%");
7168             end if;
7169
7170             Check_Arg_Is_Identifier (Form);
7171
7172             --  Get proper alignment, note that Default = Component_Size on all
7173             --  machines we have so far, and we want to set this value rather
7174             --  than the default value to indicate that it has been explicitly
7175             --  set (and thus will not get overridden by the default component
7176             --  alignment for the current scope)
7177
7178             if Chars (Form) = Name_Component_Size then
7179                Atype := Calign_Component_Size;
7180
7181             elsif Chars (Form) = Name_Component_Size_4 then
7182                Atype := Calign_Component_Size_4;
7183
7184             elsif Chars (Form) = Name_Default then
7185                Atype := Calign_Component_Size;
7186
7187             elsif Chars (Form) = Name_Storage_Unit then
7188                Atype := Calign_Storage_Unit;
7189
7190             else
7191                Error_Pragma_Arg
7192                  ("invalid Form parameter for pragma%", Form);
7193             end if;
7194
7195             --  Case with no name, supplied, affects scope table entry
7196
7197             if No (Name) then
7198                Scope_Stack.Table
7199                  (Scope_Stack.Last).Component_Alignment_Default := Atype;
7200
7201             --  Case of name supplied
7202
7203             else
7204                Check_Arg_Is_Local_Name (Name);
7205                Find_Type (Name);
7206                Typ := Entity (Name);
7207
7208                if Typ = Any_Type
7209                  or else Rep_Item_Too_Early (Typ, N)
7210                then
7211                   return;
7212                else
7213                   Typ := Underlying_Type (Typ);
7214                end if;
7215
7216                if not Is_Record_Type (Typ)
7217                  and then not Is_Array_Type (Typ)
7218                then
7219                   Error_Pragma_Arg
7220                     ("Name parameter of pragma% must identify record or " &
7221                      "array type", Name);
7222                end if;
7223
7224                --  An explicit Component_Alignment pragma overrides an
7225                --  implicit pragma Pack, but not an explicit one.
7226
7227                if not Has_Pragma_Pack (Base_Type (Typ)) then
7228                   Set_Is_Packed (Base_Type (Typ), False);
7229                   Set_Component_Alignment (Base_Type (Typ), Atype);
7230                end if;
7231             end if;
7232          end Component_AlignmentP;
7233
7234          ----------------
7235          -- Controlled --
7236          ----------------
7237
7238          --  pragma Controlled (first_subtype_LOCAL_NAME);
7239
7240          when Pragma_Controlled => Controlled : declare
7241             Arg : Node_Id;
7242
7243          begin
7244             Check_No_Identifiers;
7245             Check_Arg_Count (1);
7246             Check_Arg_Is_Local_Name (Arg1);
7247             Arg := Get_Pragma_Arg (Arg1);
7248
7249             if not Is_Entity_Name (Arg)
7250               or else not Is_Access_Type (Entity (Arg))
7251             then
7252                Error_Pragma_Arg ("pragma% requires access type", Arg1);
7253             else
7254                Set_Has_Pragma_Controlled (Base_Type (Entity (Arg)));
7255             end if;
7256          end Controlled;
7257
7258          ----------------
7259          -- Convention --
7260          ----------------
7261
7262          --  pragma Convention ([Convention =>] convention_IDENTIFIER,
7263          --    [Entity =>] LOCAL_NAME);
7264
7265          when Pragma_Convention => Convention : declare
7266             C : Convention_Id;
7267             E : Entity_Id;
7268             pragma Warnings (Off, C);
7269             pragma Warnings (Off, E);
7270          begin
7271             Check_Arg_Order ((Name_Convention, Name_Entity));
7272             Check_Ada_83_Warning;
7273             Check_Arg_Count (2);
7274             Process_Convention (C, E);
7275          end Convention;
7276
7277          ---------------------------
7278          -- Convention_Identifier --
7279          ---------------------------
7280
7281          --  pragma Convention_Identifier ([Name =>] IDENTIFIER,
7282          --    [Convention =>] convention_IDENTIFIER);
7283
7284          when Pragma_Convention_Identifier => Convention_Identifier : declare
7285             Idnam : Name_Id;
7286             Cname : Name_Id;
7287
7288          begin
7289             GNAT_Pragma;
7290             Check_Arg_Order ((Name_Name, Name_Convention));
7291             Check_Arg_Count (2);
7292             Check_Optional_Identifier (Arg1, Name_Name);
7293             Check_Optional_Identifier (Arg2, Name_Convention);
7294             Check_Arg_Is_Identifier (Arg1);
7295             Check_Arg_Is_Identifier (Arg2);
7296             Idnam := Chars (Get_Pragma_Arg (Arg1));
7297             Cname := Chars (Get_Pragma_Arg (Arg2));
7298
7299             if Is_Convention_Name (Cname) then
7300                Record_Convention_Identifier
7301                  (Idnam, Get_Convention_Id (Cname));
7302             else
7303                Error_Pragma_Arg
7304                  ("second arg for % pragma must be convention", Arg2);
7305             end if;
7306          end Convention_Identifier;
7307
7308          ---------------
7309          -- CPP_Class --
7310          ---------------
7311
7312          --  pragma CPP_Class ([Entity =>] local_NAME)
7313
7314          when Pragma_CPP_Class => CPP_Class : declare
7315             Arg : Node_Id;
7316             Typ : Entity_Id;
7317
7318          begin
7319             if Warn_On_Obsolescent_Feature then
7320                Error_Msg_N
7321                  ("'G'N'A'T pragma cpp'_class is now obsolete; replace it" &
7322                   " by pragma import?", N);
7323             end if;
7324
7325             GNAT_Pragma;
7326             Check_Arg_Count (1);
7327             Check_Optional_Identifier (Arg1, Name_Entity);
7328             Check_Arg_Is_Local_Name (Arg1);
7329
7330             Arg := Get_Pragma_Arg (Arg1);
7331             Analyze (Arg);
7332
7333             if Etype (Arg) = Any_Type then
7334                return;
7335             end if;
7336
7337             if not Is_Entity_Name (Arg)
7338               or else not Is_Type (Entity (Arg))
7339             then
7340                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
7341             end if;
7342
7343             Typ := Entity (Arg);
7344
7345             if not Is_Tagged_Type (Typ) then
7346                Error_Pragma_Arg ("pragma% applicable to tagged types ", Arg1);
7347             end if;
7348
7349             --  Types treated as CPP classes must be declared limited (note:
7350             --  this used to be a warning but there is no real benefit to it
7351             --  since we did effectively intend to treat the type as limited
7352             --  anyway).
7353
7354             if not Is_Limited_Type (Typ) then
7355                Error_Msg_N
7356                  ("imported 'C'P'P type must be limited",
7357                   Get_Pragma_Arg (Arg1));
7358             end if;
7359
7360             Set_Is_CPP_Class      (Typ);
7361             Set_Convention        (Typ, Convention_CPP);
7362
7363             --  Imported CPP types must not have discriminants (because C++
7364             --  classes do not have discriminants).
7365
7366             if Has_Discriminants (Typ) then
7367                Error_Msg_N
7368                  ("imported 'C'P'P type cannot have discriminants",
7369                   First (Discriminant_Specifications
7370                           (Declaration_Node (Typ))));
7371             end if;
7372
7373             --  Components of imported CPP types must not have default
7374             --  expressions because the constructor (if any) is in the
7375             --  C++ side.
7376
7377             if Is_Incomplete_Or_Private_Type (Typ)
7378               and then No (Underlying_Type (Typ))
7379             then
7380                --  It should be an error to apply pragma CPP to a private
7381                --  type if the underlying type is not visible (as it is
7382                --  for any representation item). For now, for backward
7383                --  compatibility we do nothing but we cannot check components
7384                --  because they are not available at this stage. All this code
7385                --  will be removed when we cleanup this obsolete GNAT pragma???
7386
7387                null;
7388
7389             else
7390                declare
7391                   Tdef  : constant Node_Id :=
7392                             Type_Definition (Declaration_Node (Typ));
7393                   Clist : Node_Id;
7394                   Comp  : Node_Id;
7395
7396                begin
7397                   if Nkind (Tdef) = N_Record_Definition then
7398                      Clist := Component_List (Tdef);
7399                   else
7400                      pragma Assert (Nkind (Tdef) = N_Derived_Type_Definition);
7401                      Clist := Component_List (Record_Extension_Part (Tdef));
7402                   end if;
7403
7404                   if Present (Clist) then
7405                      Comp := First (Component_Items (Clist));
7406                      while Present (Comp) loop
7407                         if Present (Expression (Comp)) then
7408                            Error_Msg_N
7409                              ("component of imported 'C'P'P type cannot have" &
7410                               " default expression", Expression (Comp));
7411                         end if;
7412
7413                         Next (Comp);
7414                      end loop;
7415                   end if;
7416                end;
7417             end if;
7418          end CPP_Class;
7419
7420          ---------------------
7421          -- CPP_Constructor --
7422          ---------------------
7423
7424          --  pragma CPP_Constructor ([Entity =>] LOCAL_NAME
7425          --    [, [External_Name =>] static_string_EXPRESSION ]
7426          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
7427
7428          when Pragma_CPP_Constructor => CPP_Constructor : declare
7429             Elmt    : Elmt_Id;
7430             Id      : Entity_Id;
7431             Def_Id  : Entity_Id;
7432             Tag_Typ : Entity_Id;
7433
7434          begin
7435             GNAT_Pragma;
7436             Check_At_Least_N_Arguments (1);
7437             Check_At_Most_N_Arguments (3);
7438             Check_Optional_Identifier (Arg1, Name_Entity);
7439             Check_Arg_Is_Local_Name (Arg1);
7440
7441             Id := Get_Pragma_Arg (Arg1);
7442             Find_Program_Unit_Name (Id);
7443
7444             --  If we did not find the name, we are done
7445
7446             if Etype (Id) = Any_Type then
7447                return;
7448             end if;
7449
7450             Def_Id := Entity (Id);
7451
7452             --  Check if already defined as constructor
7453
7454             if Is_Constructor (Def_Id) then
7455                Error_Msg_N
7456                  ("?duplicate argument for pragma 'C'P'P_Constructor", Arg1);
7457                return;
7458             end if;
7459
7460             if Ekind (Def_Id) = E_Function
7461               and then (Is_CPP_Class (Etype (Def_Id))
7462                          or else (Is_Class_Wide_Type (Etype (Def_Id))
7463                                    and then
7464                                   Is_CPP_Class (Root_Type (Etype (Def_Id)))))
7465             then
7466                if Arg_Count >= 2 then
7467                   Set_Imported (Def_Id);
7468                   Set_Is_Public (Def_Id);
7469                   Process_Interface_Name (Def_Id, Arg2, Arg3);
7470                end if;
7471
7472                Set_Has_Completion (Def_Id);
7473                Set_Is_Constructor (Def_Id);
7474
7475                --  Imported C++ constructors are not dispatching primitives
7476                --  because in C++ they don't have a dispatch table slot.
7477                --  However, in Ada the constructor has the profile of a
7478                --  function that returns a tagged type and therefore it has
7479                --  been treated as a primitive operation during semantic
7480                --  analysis. We now remove it from the list of primitive
7481                --  operations of the type.
7482
7483                if Is_Tagged_Type (Etype (Def_Id))
7484                  and then not Is_Class_Wide_Type (Etype (Def_Id))
7485                then
7486                   pragma Assert (Is_Dispatching_Operation (Def_Id));
7487                   Tag_Typ := Etype (Def_Id);
7488
7489                   Elmt := First_Elmt (Primitive_Operations (Tag_Typ));
7490                   while Present (Elmt) and then Node (Elmt) /= Def_Id loop
7491                      Next_Elmt (Elmt);
7492                   end loop;
7493
7494                   Remove_Elmt (Primitive_Operations (Tag_Typ), Elmt);
7495                   Set_Is_Dispatching_Operation (Def_Id, False);
7496                end if;
7497
7498                --  For backward compatibility, if the constructor returns a
7499                --  class wide type, and we internally change the return type to
7500                --  the corresponding root type.
7501
7502                if Is_Class_Wide_Type (Etype (Def_Id)) then
7503                   Set_Etype (Def_Id, Root_Type (Etype (Def_Id)));
7504                end if;
7505             else
7506                Error_Pragma_Arg
7507                  ("pragma% requires function returning a 'C'P'P_Class type",
7508                    Arg1);
7509             end if;
7510          end CPP_Constructor;
7511
7512          -----------------
7513          -- CPP_Virtual --
7514          -----------------
7515
7516          when Pragma_CPP_Virtual => CPP_Virtual : declare
7517          begin
7518             GNAT_Pragma;
7519
7520             if Warn_On_Obsolescent_Feature then
7521                Error_Msg_N
7522                  ("'G'N'A'T pragma cpp'_virtual is now obsolete and has " &
7523                   "no effect?", N);
7524             end if;
7525          end CPP_Virtual;
7526
7527          ----------------
7528          -- CPP_Vtable --
7529          ----------------
7530
7531          when Pragma_CPP_Vtable => CPP_Vtable : declare
7532          begin
7533             GNAT_Pragma;
7534
7535             if Warn_On_Obsolescent_Feature then
7536                Error_Msg_N
7537                  ("'G'N'A'T pragma cpp'_vtable is now obsolete and has " &
7538                   "no effect?", N);
7539             end if;
7540          end CPP_Vtable;
7541
7542          ---------
7543          -- CPU --
7544          ---------
7545
7546          --  pragma CPU (EXPRESSION);
7547
7548          when Pragma_CPU => CPU : declare
7549             P   : constant Node_Id := Parent (N);
7550             Arg : Node_Id;
7551
7552          begin
7553             Ada_2012_Pragma;
7554             Check_No_Identifiers;
7555             Check_Arg_Count (1);
7556
7557             --  Subprogram case
7558
7559             if Nkind (P) = N_Subprogram_Body then
7560                Check_In_Main_Program;
7561
7562                Arg := Get_Pragma_Arg (Arg1);
7563                Analyze_And_Resolve (Arg, Any_Integer);
7564
7565                --  Must be static
7566
7567                if not Is_Static_Expression (Arg) then
7568                   Flag_Non_Static_Expr
7569                     ("main subprogram affinity is not static!", Arg);
7570                   raise Pragma_Exit;
7571
7572                --  If constraint error, then we already signalled an error
7573
7574                elsif Raises_Constraint_Error (Arg) then
7575                   null;
7576
7577                --  Otherwise check in range
7578
7579                else
7580                   declare
7581                      CPU_Id : constant Entity_Id := RTE (RE_CPU_Range);
7582                      --  This is the entity System.Multiprocessors.CPU_Range;
7583
7584                      Val : constant Uint := Expr_Value (Arg);
7585
7586                   begin
7587                      if Val < Expr_Value (Type_Low_Bound (CPU_Id))
7588                           or else
7589                         Val > Expr_Value (Type_High_Bound (CPU_Id))
7590                      then
7591                         Error_Pragma_Arg
7592                           ("main subprogram CPU is out of range", Arg1);
7593                      end if;
7594                   end;
7595                end if;
7596
7597                Set_Main_CPU
7598                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
7599
7600             --  Task case
7601
7602             elsif Nkind (P) = N_Task_Definition then
7603                Arg := Get_Pragma_Arg (Arg1);
7604
7605                --  The expression must be analyzed in the special manner
7606                --  described in "Handling of Default and Per-Object
7607                --  Expressions" in sem.ads.
7608
7609                Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range));
7610
7611             --  Anything else is incorrect
7612
7613             else
7614                Pragma_Misplaced;
7615             end if;
7616
7617             if Has_Pragma_CPU (P) then
7618                Error_Pragma ("duplicate pragma% not allowed");
7619             else
7620                Set_Has_Pragma_CPU (P, True);
7621
7622                if Nkind (P) = N_Task_Definition then
7623                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
7624                end if;
7625             end if;
7626          end CPU;
7627
7628          -----------
7629          -- Debug --
7630          -----------
7631
7632          --  pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
7633
7634          when Pragma_Debug => Debug : declare
7635             Cond : Node_Id;
7636             Call : Node_Id;
7637
7638          begin
7639             GNAT_Pragma;
7640
7641             --  Skip analysis if disabled
7642
7643             if Debug_Pragmas_Disabled then
7644                Rewrite (N, Make_Null_Statement (Loc));
7645                Analyze (N);
7646                return;
7647             end if;
7648
7649             Cond :=
7650               New_Occurrence_Of
7651                 (Boolean_Literals (Debug_Pragmas_Enabled and Expander_Active),
7652                  Loc);
7653
7654             if Debug_Pragmas_Enabled then
7655                Set_SCO_Pragma_Enabled (Loc);
7656             end if;
7657
7658             if Arg_Count = 2 then
7659                Cond :=
7660                  Make_And_Then (Loc,
7661                    Left_Opnd  => Relocate_Node (Cond),
7662                    Right_Opnd => Get_Pragma_Arg (Arg1));
7663                Call := Get_Pragma_Arg (Arg2);
7664             else
7665                Call := Get_Pragma_Arg (Arg1);
7666             end if;
7667
7668             if Nkind_In (Call,
7669                  N_Indexed_Component,
7670                  N_Function_Call,
7671                  N_Identifier,
7672                  N_Selected_Component)
7673             then
7674                --  If this pragma Debug comes from source, its argument was
7675                --  parsed as a name form (which is syntactically identical).
7676                --  Change it to a procedure call statement now.
7677
7678                Change_Name_To_Procedure_Call_Statement (Call);
7679
7680             elsif Nkind (Call) = N_Procedure_Call_Statement then
7681
7682                --  Already in the form of a procedure call statement: nothing
7683                --  to do (could happen in case of an internally generated
7684                --  pragma Debug).
7685
7686                null;
7687
7688             else
7689                --  All other cases: diagnose error
7690
7691                Error_Msg
7692                  ("argument of pragma% is not procedure call", Sloc (Call));
7693                return;
7694             end if;
7695
7696             --  Rewrite into a conditional with an appropriate condition. We
7697             --  wrap the procedure call in a block so that overhead from e.g.
7698             --  use of the secondary stack does not generate execution overhead
7699             --  for suppressed conditions.
7700
7701             Rewrite (N, Make_Implicit_If_Statement (N,
7702               Condition => Cond,
7703                  Then_Statements => New_List (
7704                    Make_Block_Statement (Loc,
7705                      Handled_Statement_Sequence =>
7706                        Make_Handled_Sequence_Of_Statements (Loc,
7707                          Statements => New_List (Relocate_Node (Call)))))));
7708             Analyze (N);
7709          end Debug;
7710
7711          ------------------
7712          -- Debug_Policy --
7713          ------------------
7714
7715          --  pragma Debug_Policy (Check | Ignore)
7716
7717          when Pragma_Debug_Policy =>
7718             GNAT_Pragma;
7719             Check_Arg_Count (1);
7720             Check_Arg_Is_One_Of (Arg1, Name_Check, Name_Disable, Name_Ignore);
7721             Debug_Pragmas_Enabled :=
7722               Chars (Get_Pragma_Arg (Arg1)) = Name_Check;
7723             Debug_Pragmas_Disabled :=
7724               Chars (Get_Pragma_Arg (Arg1)) = Name_Disable;
7725
7726          ---------------------
7727          -- Detect_Blocking --
7728          ---------------------
7729
7730          --  pragma Detect_Blocking;
7731
7732          when Pragma_Detect_Blocking =>
7733             Ada_2005_Pragma;
7734             Check_Arg_Count (0);
7735             Check_Valid_Configuration_Pragma;
7736             Detect_Blocking := True;
7737
7738          --------------------------
7739          -- Default_Storage_Pool --
7740          --------------------------
7741
7742          --  pragma Default_Storage_Pool (storage_pool_NAME | null);
7743
7744          when Pragma_Default_Storage_Pool =>
7745             Ada_2012_Pragma;
7746             Check_Arg_Count (1);
7747
7748             --  Default_Storage_Pool can appear as a configuration pragma, or
7749             --  in a declarative part or a package spec.
7750
7751             if not Is_Configuration_Pragma then
7752                Check_Is_In_Decl_Part_Or_Package_Spec;
7753             end if;
7754
7755             --  Case of Default_Storage_Pool (null);
7756
7757             if Nkind (Expression (Arg1)) = N_Null then
7758                Analyze (Expression (Arg1));
7759
7760                --  This is an odd case, this is not really an expression, so
7761                --  we don't have a type for it. So just set the type to Empty.
7762
7763                Set_Etype (Expression (Arg1), Empty);
7764
7765             --  Case of Default_Storage_Pool (storage_pool_NAME);
7766
7767             else
7768                --  If it's a configuration pragma, then the only allowed
7769                --  argument is "null".
7770
7771                if Is_Configuration_Pragma then
7772                   Error_Pragma_Arg ("NULL expected", Arg1);
7773                end if;
7774
7775                --  The expected type for a non-"null" argument is
7776                --  Root_Storage_Pool'Class.
7777
7778                Analyze_And_Resolve
7779                  (Get_Pragma_Arg (Arg1),
7780                   Typ => Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
7781             end if;
7782
7783             --  Finally, record the pool name (or null). Freeze.Freeze_Entity
7784             --  for an access type will use this information to set the
7785             --  appropriate attributes of the access type.
7786
7787             Default_Pool := Expression (Arg1);
7788
7789          ---------------
7790          -- Dimension --
7791          ---------------
7792
7793          when Pragma_Dimension =>
7794             GNAT_Pragma;
7795             Check_Arg_Count (4);
7796             Check_No_Identifiers;
7797             Check_Arg_Is_Local_Name (Arg1);
7798
7799             if not Is_Type (Arg1) then
7800                Error_Pragma ("first argument for pragma% must be subtype");
7801             end if;
7802
7803             Check_Arg_Is_Static_Expression (Arg2, Standard_Integer);
7804             Check_Arg_Is_Static_Expression (Arg3, Standard_Integer);
7805             Check_Arg_Is_Static_Expression (Arg4, Standard_Integer);
7806
7807          -------------------
7808          -- Discard_Names --
7809          -------------------
7810
7811          --  pragma Discard_Names [([On =>] LOCAL_NAME)];
7812
7813          when Pragma_Discard_Names => Discard_Names : declare
7814             E    : Entity_Id;
7815             E_Id : Entity_Id;
7816
7817          begin
7818             Check_Ada_83_Warning;
7819
7820             --  Deal with configuration pragma case
7821
7822             if Arg_Count = 0 and then Is_Configuration_Pragma then
7823                Global_Discard_Names := True;
7824                return;
7825
7826             --  Otherwise, check correct appropriate context
7827
7828             else
7829                Check_Is_In_Decl_Part_Or_Package_Spec;
7830
7831                if Arg_Count = 0 then
7832
7833                   --  If there is no parameter, then from now on this pragma
7834                   --  applies to any enumeration, exception or tagged type
7835                   --  defined in the current declarative part, and recursively
7836                   --  to any nested scope.
7837
7838                   Set_Discard_Names (Current_Scope);
7839                   return;
7840
7841                else
7842                   Check_Arg_Count (1);
7843                   Check_Optional_Identifier (Arg1, Name_On);
7844                   Check_Arg_Is_Local_Name (Arg1);
7845
7846                   E_Id := Get_Pragma_Arg (Arg1);
7847
7848                   if Etype (E_Id) = Any_Type then
7849                      return;
7850                   else
7851                      E := Entity (E_Id);
7852                   end if;
7853
7854                   if (Is_First_Subtype (E)
7855                       and then
7856                         (Is_Enumeration_Type (E) or else Is_Tagged_Type (E)))
7857                     or else Ekind (E) = E_Exception
7858                   then
7859                      Set_Discard_Names (E);
7860                   else
7861                      Error_Pragma_Arg
7862                        ("inappropriate entity for pragma%", Arg1);
7863                   end if;
7864
7865                end if;
7866             end if;
7867          end Discard_Names;
7868
7869          ---------------
7870          -- Elaborate --
7871          ---------------
7872
7873          --  pragma Elaborate (library_unit_NAME {, library_unit_NAME});
7874
7875          when Pragma_Elaborate => Elaborate : declare
7876             Arg   : Node_Id;
7877             Citem : Node_Id;
7878
7879          begin
7880             --  Pragma must be in context items list of a compilation unit
7881
7882             if not Is_In_Context_Clause then
7883                Pragma_Misplaced;
7884             end if;
7885
7886             --  Must be at least one argument
7887
7888             if Arg_Count = 0 then
7889                Error_Pragma ("pragma% requires at least one argument");
7890             end if;
7891
7892             --  In Ada 83 mode, there can be no items following it in the
7893             --  context list except other pragmas and implicit with clauses
7894             --  (e.g. those added by use of Rtsfind). In Ada 95 mode, this
7895             --  placement rule does not apply.
7896
7897             if Ada_Version = Ada_83 and then Comes_From_Source (N) then
7898                Citem := Next (N);
7899                while Present (Citem) loop
7900                   if Nkind (Citem) = N_Pragma
7901                     or else (Nkind (Citem) = N_With_Clause
7902                               and then Implicit_With (Citem))
7903                   then
7904                      null;
7905                   else
7906                      Error_Pragma
7907                        ("(Ada 83) pragma% must be at end of context clause");
7908                   end if;
7909
7910                   Next (Citem);
7911                end loop;
7912             end if;
7913
7914             --  Finally, the arguments must all be units mentioned in a with
7915             --  clause in the same context clause. Note we already checked (in
7916             --  Par.Prag) that the arguments are all identifiers or selected
7917             --  components.
7918
7919             Arg := Arg1;
7920             Outer : while Present (Arg) loop
7921                Citem := First (List_Containing (N));
7922                Inner : while Citem /= N loop
7923                   if Nkind (Citem) = N_With_Clause
7924                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
7925                   then
7926                      Set_Elaborate_Present (Citem, True);
7927                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
7928                      Generate_Reference (Entity (Name (Citem)), Citem);
7929
7930                      --  With the pragma present, elaboration calls on
7931                      --  subprograms from the named unit need no further
7932                      --  checks, as long as the pragma appears in the current
7933                      --  compilation unit. If the pragma appears in some unit
7934                      --  in the context, there might still be a need for an
7935                      --  Elaborate_All_Desirable from the current compilation
7936                      --  to the named unit, so we keep the check enabled.
7937
7938                      if In_Extended_Main_Source_Unit (N) then
7939                         Set_Suppress_Elaboration_Warnings
7940                           (Entity (Name (Citem)));
7941                      end if;
7942
7943                      exit Inner;
7944                   end if;
7945
7946                   Next (Citem);
7947                end loop Inner;
7948
7949                if Citem = N then
7950                   Error_Pragma_Arg
7951                     ("argument of pragma% is not with'ed unit", Arg);
7952                end if;
7953
7954                Next (Arg);
7955             end loop Outer;
7956
7957             --  Give a warning if operating in static mode with -gnatwl
7958             --  (elaboration warnings enabled) switch set.
7959
7960             if Elab_Warnings and not Dynamic_Elaboration_Checks then
7961                Error_Msg_N
7962                  ("?use of pragma Elaborate may not be safe", N);
7963                Error_Msg_N
7964                  ("?use pragma Elaborate_All instead if possible", N);
7965             end if;
7966          end Elaborate;
7967
7968          -------------------
7969          -- Elaborate_All --
7970          -------------------
7971
7972          --  pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
7973
7974          when Pragma_Elaborate_All => Elaborate_All : declare
7975             Arg   : Node_Id;
7976             Citem : Node_Id;
7977
7978          begin
7979             Check_Ada_83_Warning;
7980
7981             --  Pragma must be in context items list of a compilation unit
7982
7983             if not Is_In_Context_Clause then
7984                Pragma_Misplaced;
7985             end if;
7986
7987             --  Must be at least one argument
7988
7989             if Arg_Count = 0 then
7990                Error_Pragma ("pragma% requires at least one argument");
7991             end if;
7992
7993             --  Note: unlike pragma Elaborate, pragma Elaborate_All does not
7994             --  have to appear at the end of the context clause, but may
7995             --  appear mixed in with other items, even in Ada 83 mode.
7996
7997             --  Final check: the arguments must all be units mentioned in
7998             --  a with clause in the same context clause. Note that we
7999             --  already checked (in Par.Prag) that all the arguments are
8000             --  either identifiers or selected components.
8001
8002             Arg := Arg1;
8003             Outr : while Present (Arg) loop
8004                Citem := First (List_Containing (N));
8005                Innr : while Citem /= N loop
8006                   if Nkind (Citem) = N_With_Clause
8007                     and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg))
8008                   then
8009                      Set_Elaborate_All_Present (Citem, True);
8010                      Set_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem));
8011
8012                      --  Suppress warnings and elaboration checks on the named
8013                      --  unit if the pragma is in the current compilation, as
8014                      --  for pragma Elaborate.
8015
8016                      if In_Extended_Main_Source_Unit (N) then
8017                         Set_Suppress_Elaboration_Warnings
8018                           (Entity (Name (Citem)));
8019                      end if;
8020                      exit Innr;
8021                   end if;
8022
8023                   Next (Citem);
8024                end loop Innr;
8025
8026                if Citem = N then
8027                   Set_Error_Posted (N);
8028                   Error_Pragma_Arg
8029                     ("argument of pragma% is not with'ed unit", Arg);
8030                end if;
8031
8032                Next (Arg);
8033             end loop Outr;
8034          end Elaborate_All;
8035
8036          --------------------
8037          -- Elaborate_Body --
8038          --------------------
8039
8040          --  pragma Elaborate_Body [( library_unit_NAME )];
8041
8042          when Pragma_Elaborate_Body => Elaborate_Body : declare
8043             Cunit_Node : Node_Id;
8044             Cunit_Ent  : Entity_Id;
8045
8046          begin
8047             Check_Ada_83_Warning;
8048             Check_Valid_Library_Unit_Pragma;
8049
8050             if Nkind (N) = N_Null_Statement then
8051                return;
8052             end if;
8053
8054             Cunit_Node := Cunit (Current_Sem_Unit);
8055             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
8056
8057             if Nkind_In (Unit (Cunit_Node), N_Package_Body,
8058                                             N_Subprogram_Body)
8059             then
8060                Error_Pragma ("pragma% must refer to a spec, not a body");
8061             else
8062                Set_Body_Required (Cunit_Node, True);
8063                Set_Has_Pragma_Elaborate_Body (Cunit_Ent);
8064
8065                --  If we are in dynamic elaboration mode, then we suppress
8066                --  elaboration warnings for the unit, since it is definitely
8067                --  fine NOT to do dynamic checks at the first level (and such
8068                --  checks will be suppressed because no elaboration boolean
8069                --  is created for Elaborate_Body packages).
8070
8071                --  But in the static model of elaboration, Elaborate_Body is
8072                --  definitely NOT good enough to ensure elaboration safety on
8073                --  its own, since the body may WITH other units that are not
8074                --  safe from an elaboration point of view, so a client must
8075                --  still do an Elaborate_All on such units.
8076
8077                --  Debug flag -gnatdD restores the old behavior of 3.13, where
8078                --  Elaborate_Body always suppressed elab warnings.
8079
8080                if Dynamic_Elaboration_Checks or Debug_Flag_DD then
8081                   Set_Suppress_Elaboration_Warnings (Cunit_Ent);
8082                end if;
8083             end if;
8084          end Elaborate_Body;
8085
8086          ------------------------
8087          -- Elaboration_Checks --
8088          ------------------------
8089
8090          --  pragma Elaboration_Checks (Static | Dynamic);
8091
8092          when Pragma_Elaboration_Checks =>
8093             GNAT_Pragma;
8094             Check_Arg_Count (1);
8095             Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic);
8096             Dynamic_Elaboration_Checks :=
8097               (Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic);
8098
8099          ---------------
8100          -- Eliminate --
8101          ---------------
8102
8103          --  pragma Eliminate (
8104          --      [Unit_Name  =>] IDENTIFIER | SELECTED_COMPONENT,
8105          --    [,[Entity     =>] IDENTIFIER |
8106          --                      SELECTED_COMPONENT |
8107          --                      STRING_LITERAL]
8108          --    [,                OVERLOADING_RESOLUTION]);
8109
8110          --  OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
8111          --                             SOURCE_LOCATION
8112
8113          --  PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
8114          --                                        FUNCTION_PROFILE
8115
8116          --  PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
8117
8118          --  FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
8119          --                       Result_Type => result_SUBTYPE_NAME]
8120
8121          --  PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
8122          --  SUBTYPE_NAME    ::= STRING_LITERAL
8123
8124          --  SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
8125          --  SOURCE_TRACE    ::= STRING_LITERAL
8126
8127          when Pragma_Eliminate => Eliminate : declare
8128             Args  : Args_List (1 .. 5);
8129             Names : constant Name_List (1 .. 5) := (
8130                       Name_Unit_Name,
8131                       Name_Entity,
8132                       Name_Parameter_Types,
8133                       Name_Result_Type,
8134                       Name_Source_Location);
8135
8136             Unit_Name       : Node_Id renames Args (1);
8137             Entity          : Node_Id renames Args (2);
8138             Parameter_Types : Node_Id renames Args (3);
8139             Result_Type     : Node_Id renames Args (4);
8140             Source_Location : Node_Id renames Args (5);
8141
8142          begin
8143             GNAT_Pragma;
8144             Check_Valid_Configuration_Pragma;
8145             Gather_Associations (Names, Args);
8146
8147             if No (Unit_Name) then
8148                Error_Pragma ("missing Unit_Name argument for pragma%");
8149             end if;
8150
8151             if No (Entity)
8152               and then (Present (Parameter_Types)
8153                           or else
8154                         Present (Result_Type)
8155                           or else
8156                         Present (Source_Location))
8157             then
8158                Error_Pragma ("missing Entity argument for pragma%");
8159             end if;
8160
8161             if (Present (Parameter_Types)
8162                   or else
8163                 Present (Result_Type))
8164               and then
8165                 Present (Source_Location)
8166             then
8167                Error_Pragma
8168                  ("parameter profile and source location cannot " &
8169                   "be used together in pragma%");
8170             end if;
8171
8172             Process_Eliminate_Pragma
8173               (N,
8174                Unit_Name,
8175                Entity,
8176                Parameter_Types,
8177                Result_Type,
8178                Source_Location);
8179          end Eliminate;
8180
8181          ------------
8182          -- Export --
8183          ------------
8184
8185          --  pragma Export (
8186          --    [   Convention    =>] convention_IDENTIFIER,
8187          --    [   Entity        =>] local_NAME
8188          --    [, [External_Name =>] static_string_EXPRESSION ]
8189          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8190
8191          when Pragma_Export => Export : declare
8192             C      : Convention_Id;
8193             Def_Id : Entity_Id;
8194
8195             pragma Warnings (Off, C);
8196
8197          begin
8198             Check_Ada_83_Warning;
8199             Check_Arg_Order
8200               ((Name_Convention,
8201                 Name_Entity,
8202                 Name_External_Name,
8203                 Name_Link_Name));
8204             Check_At_Least_N_Arguments (2);
8205             Check_At_Most_N_Arguments  (4);
8206             Process_Convention (C, Def_Id);
8207
8208             if Ekind (Def_Id) /= E_Constant then
8209                Note_Possible_Modification
8210                  (Get_Pragma_Arg (Arg2), Sure => False);
8211             end if;
8212
8213             Process_Interface_Name (Def_Id, Arg3, Arg4);
8214             Set_Exported (Def_Id, Arg2);
8215
8216             --  If the entity is a deferred constant, propagate the information
8217             --  to the full view, because gigi elaborates the full view only.
8218
8219             if Ekind (Def_Id) = E_Constant
8220               and then Present (Full_View (Def_Id))
8221             then
8222                declare
8223                   Id2 : constant Entity_Id := Full_View (Def_Id);
8224                begin
8225                   Set_Is_Exported    (Id2, Is_Exported          (Def_Id));
8226                   Set_First_Rep_Item (Id2, First_Rep_Item       (Def_Id));
8227                   Set_Interface_Name (Id2, Einfo.Interface_Name (Def_Id));
8228                end;
8229             end if;
8230          end Export;
8231
8232          ----------------------
8233          -- Export_Exception --
8234          ----------------------
8235
8236          --  pragma Export_Exception (
8237          --        [Internal         =>] LOCAL_NAME
8238          --     [, [External         =>] EXTERNAL_SYMBOL]
8239          --     [, [Form     =>] Ada | VMS]
8240          --     [, [Code     =>] static_integer_EXPRESSION]);
8241
8242          when Pragma_Export_Exception => Export_Exception : declare
8243             Args  : Args_List (1 .. 4);
8244             Names : constant Name_List (1 .. 4) := (
8245                       Name_Internal,
8246                       Name_External,
8247                       Name_Form,
8248                       Name_Code);
8249
8250             Internal : Node_Id renames Args (1);
8251             External : Node_Id renames Args (2);
8252             Form     : Node_Id renames Args (3);
8253             Code     : Node_Id renames Args (4);
8254
8255          begin
8256             GNAT_Pragma;
8257
8258             if Inside_A_Generic then
8259                Error_Pragma ("pragma% cannot be used for generic entities");
8260             end if;
8261
8262             Gather_Associations (Names, Args);
8263             Process_Extended_Import_Export_Exception_Pragma (
8264               Arg_Internal => Internal,
8265               Arg_External => External,
8266               Arg_Form     => Form,
8267               Arg_Code     => Code);
8268
8269             if not Is_VMS_Exception (Entity (Internal)) then
8270                Set_Exported (Entity (Internal), Internal);
8271             end if;
8272          end Export_Exception;
8273
8274          ---------------------
8275          -- Export_Function --
8276          ---------------------
8277
8278          --  pragma Export_Function (
8279          --        [Internal         =>] LOCAL_NAME
8280          --     [, [External         =>] EXTERNAL_SYMBOL]
8281          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8282          --     [, [Result_Type      =>] TYPE_DESIGNATOR]
8283          --     [, [Mechanism        =>] MECHANISM]
8284          --     [, [Result_Mechanism =>] MECHANISM_NAME]);
8285
8286          --  EXTERNAL_SYMBOL ::=
8287          --    IDENTIFIER
8288          --  | static_string_EXPRESSION
8289
8290          --  PARAMETER_TYPES ::=
8291          --    null
8292          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8293
8294          --  TYPE_DESIGNATOR ::=
8295          --    subtype_NAME
8296          --  | subtype_Name ' Access
8297
8298          --  MECHANISM ::=
8299          --    MECHANISM_NAME
8300          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8301
8302          --  MECHANISM_ASSOCIATION ::=
8303          --    [formal_parameter_NAME =>] MECHANISM_NAME
8304
8305          --  MECHANISM_NAME ::=
8306          --    Value
8307          --  | Reference
8308          --  | Descriptor [([Class =>] CLASS_NAME)]
8309
8310          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8311
8312          when Pragma_Export_Function => Export_Function : declare
8313             Args  : Args_List (1 .. 6);
8314             Names : constant Name_List (1 .. 6) := (
8315                       Name_Internal,
8316                       Name_External,
8317                       Name_Parameter_Types,
8318                       Name_Result_Type,
8319                       Name_Mechanism,
8320                       Name_Result_Mechanism);
8321
8322             Internal         : Node_Id renames Args (1);
8323             External         : Node_Id renames Args (2);
8324             Parameter_Types  : Node_Id renames Args (3);
8325             Result_Type      : Node_Id renames Args (4);
8326             Mechanism        : Node_Id renames Args (5);
8327             Result_Mechanism : Node_Id renames Args (6);
8328
8329          begin
8330             GNAT_Pragma;
8331             Gather_Associations (Names, Args);
8332             Process_Extended_Import_Export_Subprogram_Pragma (
8333               Arg_Internal         => Internal,
8334               Arg_External         => External,
8335               Arg_Parameter_Types  => Parameter_Types,
8336               Arg_Result_Type      => Result_Type,
8337               Arg_Mechanism        => Mechanism,
8338               Arg_Result_Mechanism => Result_Mechanism);
8339          end Export_Function;
8340
8341          -------------------
8342          -- Export_Object --
8343          -------------------
8344
8345          --  pragma Export_Object (
8346          --        [Internal =>] LOCAL_NAME
8347          --     [, [External =>] EXTERNAL_SYMBOL]
8348          --     [, [Size     =>] EXTERNAL_SYMBOL]);
8349
8350          --  EXTERNAL_SYMBOL ::=
8351          --    IDENTIFIER
8352          --  | static_string_EXPRESSION
8353
8354          --  PARAMETER_TYPES ::=
8355          --    null
8356          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8357
8358          --  TYPE_DESIGNATOR ::=
8359          --    subtype_NAME
8360          --  | subtype_Name ' Access
8361
8362          --  MECHANISM ::=
8363          --    MECHANISM_NAME
8364          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8365
8366          --  MECHANISM_ASSOCIATION ::=
8367          --    [formal_parameter_NAME =>] MECHANISM_NAME
8368
8369          --  MECHANISM_NAME ::=
8370          --    Value
8371          --  | Reference
8372          --  | Descriptor [([Class =>] CLASS_NAME)]
8373
8374          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8375
8376          when Pragma_Export_Object => Export_Object : declare
8377             Args  : Args_List (1 .. 3);
8378             Names : constant Name_List (1 .. 3) := (
8379                       Name_Internal,
8380                       Name_External,
8381                       Name_Size);
8382
8383             Internal : Node_Id renames Args (1);
8384             External : Node_Id renames Args (2);
8385             Size     : Node_Id renames Args (3);
8386
8387          begin
8388             GNAT_Pragma;
8389             Gather_Associations (Names, Args);
8390             Process_Extended_Import_Export_Object_Pragma (
8391               Arg_Internal => Internal,
8392               Arg_External => External,
8393               Arg_Size     => Size);
8394          end Export_Object;
8395
8396          ----------------------
8397          -- Export_Procedure --
8398          ----------------------
8399
8400          --  pragma Export_Procedure (
8401          --        [Internal         =>] LOCAL_NAME
8402          --     [, [External         =>] EXTERNAL_SYMBOL]
8403          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8404          --     [, [Mechanism        =>] MECHANISM]);
8405
8406          --  EXTERNAL_SYMBOL ::=
8407          --    IDENTIFIER
8408          --  | static_string_EXPRESSION
8409
8410          --  PARAMETER_TYPES ::=
8411          --    null
8412          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8413
8414          --  TYPE_DESIGNATOR ::=
8415          --    subtype_NAME
8416          --  | subtype_Name ' Access
8417
8418          --  MECHANISM ::=
8419          --    MECHANISM_NAME
8420          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8421
8422          --  MECHANISM_ASSOCIATION ::=
8423          --    [formal_parameter_NAME =>] MECHANISM_NAME
8424
8425          --  MECHANISM_NAME ::=
8426          --    Value
8427          --  | Reference
8428          --  | Descriptor [([Class =>] CLASS_NAME)]
8429
8430          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8431
8432          when Pragma_Export_Procedure => Export_Procedure : declare
8433             Args  : Args_List (1 .. 4);
8434             Names : constant Name_List (1 .. 4) := (
8435                       Name_Internal,
8436                       Name_External,
8437                       Name_Parameter_Types,
8438                       Name_Mechanism);
8439
8440             Internal        : Node_Id renames Args (1);
8441             External        : Node_Id renames Args (2);
8442             Parameter_Types : Node_Id renames Args (3);
8443             Mechanism       : Node_Id renames Args (4);
8444
8445          begin
8446             GNAT_Pragma;
8447             Gather_Associations (Names, Args);
8448             Process_Extended_Import_Export_Subprogram_Pragma (
8449               Arg_Internal        => Internal,
8450               Arg_External        => External,
8451               Arg_Parameter_Types => Parameter_Types,
8452               Arg_Mechanism       => Mechanism);
8453          end Export_Procedure;
8454
8455          ------------------
8456          -- Export_Value --
8457          ------------------
8458
8459          --  pragma Export_Value (
8460          --     [Value     =>] static_integer_EXPRESSION,
8461          --     [Link_Name =>] static_string_EXPRESSION);
8462
8463          when Pragma_Export_Value =>
8464             GNAT_Pragma;
8465             Check_Arg_Order ((Name_Value, Name_Link_Name));
8466             Check_Arg_Count (2);
8467
8468             Check_Optional_Identifier (Arg1, Name_Value);
8469             Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
8470
8471             Check_Optional_Identifier (Arg2, Name_Link_Name);
8472             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
8473
8474          -----------------------------
8475          -- Export_Valued_Procedure --
8476          -----------------------------
8477
8478          --  pragma Export_Valued_Procedure (
8479          --        [Internal         =>] LOCAL_NAME
8480          --     [, [External         =>] EXTERNAL_SYMBOL,]
8481          --     [, [Parameter_Types  =>] (PARAMETER_TYPES)]
8482          --     [, [Mechanism        =>] MECHANISM]);
8483
8484          --  EXTERNAL_SYMBOL ::=
8485          --    IDENTIFIER
8486          --  | static_string_EXPRESSION
8487
8488          --  PARAMETER_TYPES ::=
8489          --    null
8490          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
8491
8492          --  TYPE_DESIGNATOR ::=
8493          --    subtype_NAME
8494          --  | subtype_Name ' Access
8495
8496          --  MECHANISM ::=
8497          --    MECHANISM_NAME
8498          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
8499
8500          --  MECHANISM_ASSOCIATION ::=
8501          --    [formal_parameter_NAME =>] MECHANISM_NAME
8502
8503          --  MECHANISM_NAME ::=
8504          --    Value
8505          --  | Reference
8506          --  | Descriptor [([Class =>] CLASS_NAME)]
8507
8508          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
8509
8510          when Pragma_Export_Valued_Procedure =>
8511          Export_Valued_Procedure : declare
8512             Args  : Args_List (1 .. 4);
8513             Names : constant Name_List (1 .. 4) := (
8514                       Name_Internal,
8515                       Name_External,
8516                       Name_Parameter_Types,
8517                       Name_Mechanism);
8518
8519             Internal        : Node_Id renames Args (1);
8520             External        : Node_Id renames Args (2);
8521             Parameter_Types : Node_Id renames Args (3);
8522             Mechanism       : Node_Id renames Args (4);
8523
8524          begin
8525             GNAT_Pragma;
8526             Gather_Associations (Names, Args);
8527             Process_Extended_Import_Export_Subprogram_Pragma (
8528               Arg_Internal        => Internal,
8529               Arg_External        => External,
8530               Arg_Parameter_Types => Parameter_Types,
8531               Arg_Mechanism       => Mechanism);
8532          end Export_Valued_Procedure;
8533
8534          -------------------
8535          -- Extend_System --
8536          -------------------
8537
8538          --  pragma Extend_System ([Name =>] Identifier);
8539
8540          when Pragma_Extend_System => Extend_System : declare
8541          begin
8542             GNAT_Pragma;
8543             Check_Valid_Configuration_Pragma;
8544             Check_Arg_Count (1);
8545             Check_Optional_Identifier (Arg1, Name_Name);
8546             Check_Arg_Is_Identifier (Arg1);
8547
8548             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
8549
8550             if Name_Len > 4
8551               and then Name_Buffer (1 .. 4) = "aux_"
8552             then
8553                if Present (System_Extend_Pragma_Arg) then
8554                   if Chars (Get_Pragma_Arg (Arg1)) =
8555                      Chars (Expression (System_Extend_Pragma_Arg))
8556                   then
8557                      null;
8558                   else
8559                      Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg);
8560                      Error_Pragma ("pragma% conflicts with that #");
8561                   end if;
8562
8563                else
8564                   System_Extend_Pragma_Arg := Arg1;
8565
8566                   if not GNAT_Mode then
8567                      System_Extend_Unit := Arg1;
8568                   end if;
8569                end if;
8570             else
8571                Error_Pragma ("incorrect name for pragma%, must be Aux_xxx");
8572             end if;
8573          end Extend_System;
8574
8575          ------------------------
8576          -- Extensions_Allowed --
8577          ------------------------
8578
8579          --  pragma Extensions_Allowed (ON | OFF);
8580
8581          when Pragma_Extensions_Allowed =>
8582             GNAT_Pragma;
8583             Check_Arg_Count (1);
8584             Check_No_Identifiers;
8585             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
8586
8587             if Chars (Get_Pragma_Arg (Arg1)) = Name_On then
8588                Extensions_Allowed := True;
8589                Ada_Version := Ada_Version_Type'Last;
8590
8591             else
8592                Extensions_Allowed := False;
8593                Ada_Version := Ada_Version_Explicit;
8594             end if;
8595
8596          --------------
8597          -- External --
8598          --------------
8599
8600          --  pragma External (
8601          --    [   Convention    =>] convention_IDENTIFIER,
8602          --    [   Entity        =>] local_NAME
8603          --    [, [External_Name =>] static_string_EXPRESSION ]
8604          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
8605
8606          when Pragma_External => External : declare
8607                Def_Id : Entity_Id;
8608
8609                C : Convention_Id;
8610                pragma Warnings (Off, C);
8611
8612          begin
8613             GNAT_Pragma;
8614             Check_Arg_Order
8615               ((Name_Convention,
8616                 Name_Entity,
8617                 Name_External_Name,
8618                 Name_Link_Name));
8619             Check_At_Least_N_Arguments (2);
8620             Check_At_Most_N_Arguments  (4);
8621             Process_Convention (C, Def_Id);
8622             Note_Possible_Modification
8623               (Get_Pragma_Arg (Arg2), Sure => False);
8624             Process_Interface_Name (Def_Id, Arg3, Arg4);
8625             Set_Exported (Def_Id, Arg2);
8626          end External;
8627
8628          --------------------------
8629          -- External_Name_Casing --
8630          --------------------------
8631
8632          --  pragma External_Name_Casing (
8633          --    UPPERCASE | LOWERCASE
8634          --    [, AS_IS | UPPERCASE | LOWERCASE]);
8635
8636          when Pragma_External_Name_Casing => External_Name_Casing : declare
8637          begin
8638             GNAT_Pragma;
8639             Check_No_Identifiers;
8640
8641             if Arg_Count = 2 then
8642                Check_Arg_Is_One_Of
8643                  (Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase);
8644
8645                case Chars (Get_Pragma_Arg (Arg2)) is
8646                   when Name_As_Is     =>
8647                      Opt.External_Name_Exp_Casing := As_Is;
8648
8649                   when Name_Uppercase =>
8650                      Opt.External_Name_Exp_Casing := Uppercase;
8651
8652                   when Name_Lowercase =>
8653                      Opt.External_Name_Exp_Casing := Lowercase;
8654
8655                   when others =>
8656                      null;
8657                end case;
8658
8659             else
8660                Check_Arg_Count (1);
8661             end if;
8662
8663             Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase);
8664
8665             case Chars (Get_Pragma_Arg (Arg1)) is
8666                when Name_Uppercase =>
8667                   Opt.External_Name_Imp_Casing := Uppercase;
8668
8669                when Name_Lowercase =>
8670                   Opt.External_Name_Imp_Casing := Lowercase;
8671
8672                when others =>
8673                   null;
8674             end case;
8675          end External_Name_Casing;
8676
8677          --------------------------
8678          -- Favor_Top_Level --
8679          --------------------------
8680
8681          --  pragma Favor_Top_Level (type_NAME);
8682
8683          when Pragma_Favor_Top_Level => Favor_Top_Level : declare
8684                Named_Entity : Entity_Id;
8685
8686          begin
8687             GNAT_Pragma;
8688             Check_No_Identifiers;
8689             Check_Arg_Count (1);
8690             Check_Arg_Is_Local_Name (Arg1);
8691             Named_Entity := Entity (Get_Pragma_Arg (Arg1));
8692
8693             --  If it's an access-to-subprogram type (in particular, not a
8694             --  subtype), set the flag on that type.
8695
8696             if Is_Access_Subprogram_Type (Named_Entity) then
8697                Set_Can_Use_Internal_Rep (Named_Entity, False);
8698
8699             --  Otherwise it's an error (name denotes the wrong sort of entity)
8700
8701             else
8702                Error_Pragma_Arg
8703                  ("access-to-subprogram type expected",
8704                   Get_Pragma_Arg (Arg1));
8705             end if;
8706          end Favor_Top_Level;
8707
8708          ---------------
8709          -- Fast_Math --
8710          ---------------
8711
8712          --  pragma Fast_Math;
8713
8714          when Pragma_Fast_Math =>
8715             GNAT_Pragma;
8716             Check_No_Identifiers;
8717             Check_Valid_Configuration_Pragma;
8718             Fast_Math := True;
8719
8720          ---------------------------
8721          -- Finalize_Storage_Only --
8722          ---------------------------
8723
8724          --  pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
8725
8726          when Pragma_Finalize_Storage_Only => Finalize_Storage : declare
8727             Assoc   : constant Node_Id := Arg1;
8728             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
8729             Typ     : Entity_Id;
8730
8731          begin
8732             GNAT_Pragma;
8733             Check_No_Identifiers;
8734             Check_Arg_Count (1);
8735             Check_Arg_Is_Local_Name (Arg1);
8736
8737             Find_Type (Type_Id);
8738             Typ := Entity (Type_Id);
8739
8740             if Typ = Any_Type
8741               or else Rep_Item_Too_Early (Typ, N)
8742             then
8743                return;
8744             else
8745                Typ := Underlying_Type (Typ);
8746             end if;
8747
8748             if not Is_Controlled (Typ) then
8749                Error_Pragma ("pragma% must specify controlled type");
8750             end if;
8751
8752             Check_First_Subtype (Arg1);
8753
8754             if Finalize_Storage_Only (Typ) then
8755                Error_Pragma ("duplicate pragma%, only one allowed");
8756
8757             elsif not Rep_Item_Too_Late (Typ, N) then
8758                Set_Finalize_Storage_Only (Base_Type (Typ), True);
8759             end if;
8760          end Finalize_Storage;
8761
8762          --------------------------
8763          -- Float_Representation --
8764          --------------------------
8765
8766          --  pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]);
8767
8768          --  FLOAT_REP ::= VAX_Float | IEEE_Float
8769
8770          when Pragma_Float_Representation => Float_Representation : declare
8771             Argx : Node_Id;
8772             Digs : Nat;
8773             Ent  : Entity_Id;
8774
8775          begin
8776             GNAT_Pragma;
8777
8778             if Arg_Count = 1 then
8779                Check_Valid_Configuration_Pragma;
8780             else
8781                Check_Arg_Count (2);
8782                Check_Optional_Identifier (Arg2, Name_Entity);
8783                Check_Arg_Is_Local_Name (Arg2);
8784             end if;
8785
8786             Check_No_Identifier (Arg1);
8787             Check_Arg_Is_One_Of (Arg1, Name_VAX_Float, Name_IEEE_Float);
8788
8789             if not OpenVMS_On_Target then
8790                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8791                   Error_Pragma
8792                     ("?pragma% ignored (applies only to Open'V'M'S)");
8793                end if;
8794
8795                return;
8796             end if;
8797
8798             --  One argument case
8799
8800             if Arg_Count = 1 then
8801                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8802                   if Opt.Float_Format = 'I' then
8803                      Error_Pragma ("'I'E'E'E format previously specified");
8804                   end if;
8805
8806                   Opt.Float_Format := 'V';
8807
8808                else
8809                   if Opt.Float_Format = 'V' then
8810                      Error_Pragma ("'V'A'X format previously specified");
8811                   end if;
8812
8813                   Opt.Float_Format := 'I';
8814                end if;
8815
8816                Set_Standard_Fpt_Formats;
8817
8818             --  Two argument case
8819
8820             else
8821                Argx := Get_Pragma_Arg (Arg2);
8822
8823                if not Is_Entity_Name (Argx)
8824                  or else not Is_Floating_Point_Type (Entity (Argx))
8825                then
8826                   Error_Pragma_Arg
8827                     ("second argument of% pragma must be floating-point type",
8828                      Arg2);
8829                end if;
8830
8831                Ent  := Entity (Argx);
8832                Digs := UI_To_Int (Digits_Value (Ent));
8833
8834                --  Two arguments, VAX_Float case
8835
8836                if Chars (Get_Pragma_Arg (Arg1)) = Name_VAX_Float then
8837                   case Digs is
8838                      when  6 => Set_F_Float (Ent);
8839                      when  9 => Set_D_Float (Ent);
8840                      when 15 => Set_G_Float (Ent);
8841
8842                      when others =>
8843                         Error_Pragma_Arg
8844                           ("wrong digits value, must be 6,9 or 15", Arg2);
8845                   end case;
8846
8847                --  Two arguments, IEEE_Float case
8848
8849                else
8850                   case Digs is
8851                      when  6 => Set_IEEE_Short (Ent);
8852                      when 15 => Set_IEEE_Long  (Ent);
8853
8854                      when others =>
8855                         Error_Pragma_Arg
8856                           ("wrong digits value, must be 6 or 15", Arg2);
8857                   end case;
8858                end if;
8859             end if;
8860          end Float_Representation;
8861
8862          -----------
8863          -- Ident --
8864          -----------
8865
8866          --  pragma Ident (static_string_EXPRESSION)
8867
8868          --  Note: pragma Comment shares this processing. Pragma Comment is
8869          --  identical to Ident, except that the restriction of the argument to
8870          --  31 characters and the placement restrictions are not enforced for
8871          --  pragma Comment.
8872
8873          when Pragma_Ident | Pragma_Comment => Ident : declare
8874             Str : Node_Id;
8875
8876          begin
8877             GNAT_Pragma;
8878             Check_Arg_Count (1);
8879             Check_No_Identifiers;
8880             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
8881             Store_Note (N);
8882
8883             --  For pragma Ident, preserve DEC compatibility by requiring the
8884             --  pragma to appear in a declarative part or package spec.
8885
8886             if Prag_Id = Pragma_Ident then
8887                Check_Is_In_Decl_Part_Or_Package_Spec;
8888             end if;
8889
8890             Str := Expr_Value_S (Get_Pragma_Arg (Arg1));
8891
8892             declare
8893                CS : Node_Id;
8894                GP : Node_Id;
8895
8896             begin
8897                GP := Parent (Parent (N));
8898
8899                if Nkind_In (GP, N_Package_Declaration,
8900                                 N_Generic_Package_Declaration)
8901                then
8902                   GP := Parent (GP);
8903                end if;
8904
8905                --  If we have a compilation unit, then record the ident value,
8906                --  checking for improper duplication.
8907
8908                if Nkind (GP) = N_Compilation_Unit then
8909                   CS := Ident_String (Current_Sem_Unit);
8910
8911                   if Present (CS) then
8912
8913                      --  For Ident, we do not permit multiple instances
8914
8915                      if Prag_Id = Pragma_Ident then
8916                         Error_Pragma ("duplicate% pragma not permitted");
8917
8918                      --  For Comment, we concatenate the string, unless we want
8919                      --  to preserve the tree structure for ASIS.
8920
8921                      elsif not ASIS_Mode then
8922                         Start_String (Strval (CS));
8923                         Store_String_Char (' ');
8924                         Store_String_Chars (Strval (Str));
8925                         Set_Strval (CS, End_String);
8926                      end if;
8927
8928                   else
8929                      --  In VMS, the effect of IDENT is achieved by passing
8930                      --  --identification=name as a --for-linker switch.
8931
8932                      if OpenVMS_On_Target then
8933                         Start_String;
8934                         Store_String_Chars
8935                           ("--for-linker=--identification=");
8936                         String_To_Name_Buffer (Strval (Str));
8937                         Store_String_Chars (Name_Buffer (1 .. Name_Len));
8938
8939                         --  Only the last processed IDENT is saved. The main
8940                         --  purpose is so an IDENT associated with a main
8941                         --  procedure will be used in preference to an IDENT
8942                         --  associated with a with'd package.
8943
8944                         Replace_Linker_Option_String
8945                           (End_String, "--for-linker=--identification=");
8946                      end if;
8947
8948                      Set_Ident_String (Current_Sem_Unit, Str);
8949                   end if;
8950
8951                --  For subunits, we just ignore the Ident, since in GNAT these
8952                --  are not separate object files, and hence not separate units
8953                --  in the unit table.
8954
8955                elsif Nkind (GP) = N_Subunit then
8956                   null;
8957
8958                --  Otherwise we have a misplaced pragma Ident, but we ignore
8959                --  this if we are in an instantiation, since it comes from
8960                --  a generic, and has no relevance to the instantiation.
8961
8962                elsif Prag_Id = Pragma_Ident then
8963                   if Instantiation_Location (Loc) = No_Location then
8964                      Error_Pragma ("pragma% only allowed at outer level");
8965                   end if;
8966                end if;
8967             end;
8968          end Ident;
8969
8970          -----------------
8971          -- Implemented --
8972          -----------------
8973
8974          --  pragma Implemented (procedure_LOCAL_NAME, implementation_kind);
8975          --  implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any
8976
8977          when Pragma_Implemented => Implemented : declare
8978             Proc_Id : Entity_Id;
8979             Typ     : Entity_Id;
8980
8981          begin
8982             Ada_2012_Pragma;
8983             Check_Arg_Count (2);
8984             Check_No_Identifiers;
8985             Check_Arg_Is_Identifier (Arg1);
8986             Check_Arg_Is_Local_Name (Arg1);
8987             Check_Arg_Is_One_Of
8988               (Arg2, Name_By_Any, Name_By_Entry, Name_By_Protected_Procedure);
8989
8990             --  Extract the name of the local procedure
8991
8992             Proc_Id := Entity (Get_Pragma_Arg (Arg1));
8993
8994             --  Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
8995             --  primitive procedure of a synchronized tagged type.
8996
8997             if Ekind (Proc_Id) = E_Procedure
8998               and then Is_Primitive (Proc_Id)
8999               and then Present (First_Formal (Proc_Id))
9000             then
9001                Typ := Etype (First_Formal (Proc_Id));
9002
9003                if Is_Tagged_Type (Typ)
9004                  and then
9005
9006                   --  Check for a protected, a synchronized or a task interface
9007
9008                    ((Is_Interface (Typ)
9009                        and then Is_Synchronized_Interface (Typ))
9010
9011                   --  Check for a protected type or a task type that implements
9012                   --  an interface.
9013
9014                    or else
9015                     (Is_Concurrent_Record_Type (Typ)
9016                        and then Present (Interfaces (Typ)))
9017
9018                   --  Check for a private record extension with keyword
9019                   --  "synchronized".
9020
9021                    or else
9022                     (Ekind_In (Typ, E_Record_Type_With_Private,
9023                                     E_Record_Subtype_With_Private)
9024                        and then Synchronized_Present (Parent (Typ))))
9025                then
9026                   null;
9027                else
9028                   Error_Pragma_Arg
9029                     ("controlling formal must be of synchronized " &
9030                      "tagged type", Arg1);
9031                   return;
9032                end if;
9033
9034             --  Procedures declared inside a protected type must be accepted
9035
9036             elsif Ekind (Proc_Id) = E_Procedure
9037               and then Is_Protected_Type (Scope (Proc_Id))
9038             then
9039                null;
9040
9041             --  The first argument is not a primitive procedure
9042
9043             else
9044                Error_Pragma_Arg
9045                  ("pragma % must be applied to a primitive procedure", Arg1);
9046                return;
9047             end if;
9048
9049             --  Ada 2012 (AI05-0030): Cannot apply the implementation_kind
9050             --  By_Protected_Procedure to the primitive procedure of a task
9051             --  interface.
9052
9053             if Chars (Arg2) = Name_By_Protected_Procedure
9054               and then Is_Interface (Typ)
9055               and then Is_Task_Interface (Typ)
9056             then
9057                Error_Pragma_Arg
9058                  ("implementation kind By_Protected_Procedure cannot be " &
9059                   "applied to a task interface primitive", Arg2);
9060                return;
9061             end if;
9062
9063             Record_Rep_Item (Proc_Id, N);
9064          end Implemented;
9065
9066          ----------------------
9067          -- Implicit_Packing --
9068          ----------------------
9069
9070          --  pragma Implicit_Packing;
9071
9072          when Pragma_Implicit_Packing =>
9073             GNAT_Pragma;
9074             Check_Arg_Count (0);
9075             Implicit_Packing := True;
9076
9077          ------------
9078          -- Import --
9079          ------------
9080
9081          --  pragma Import (
9082          --       [Convention    =>] convention_IDENTIFIER,
9083          --       [Entity        =>] local_NAME
9084          --    [, [External_Name =>] static_string_EXPRESSION ]
9085          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9086
9087          when Pragma_Import =>
9088             Check_Ada_83_Warning;
9089             Check_Arg_Order
9090               ((Name_Convention,
9091                 Name_Entity,
9092                 Name_External_Name,
9093                 Name_Link_Name));
9094             Check_At_Least_N_Arguments (2);
9095             Check_At_Most_N_Arguments  (4);
9096             Process_Import_Or_Interface;
9097
9098          ----------------------
9099          -- Import_Exception --
9100          ----------------------
9101
9102          --  pragma Import_Exception (
9103          --        [Internal         =>] LOCAL_NAME
9104          --     [, [External         =>] EXTERNAL_SYMBOL]
9105          --     [, [Form     =>] Ada | VMS]
9106          --     [, [Code     =>] static_integer_EXPRESSION]);
9107
9108          when Pragma_Import_Exception => Import_Exception : declare
9109             Args  : Args_List (1 .. 4);
9110             Names : constant Name_List (1 .. 4) := (
9111                       Name_Internal,
9112                       Name_External,
9113                       Name_Form,
9114                       Name_Code);
9115
9116             Internal : Node_Id renames Args (1);
9117             External : Node_Id renames Args (2);
9118             Form     : Node_Id renames Args (3);
9119             Code     : Node_Id renames Args (4);
9120
9121          begin
9122             GNAT_Pragma;
9123             Gather_Associations (Names, Args);
9124
9125             if Present (External) and then Present (Code) then
9126                Error_Pragma
9127                  ("cannot give both External and Code options for pragma%");
9128             end if;
9129
9130             Process_Extended_Import_Export_Exception_Pragma (
9131               Arg_Internal => Internal,
9132               Arg_External => External,
9133               Arg_Form     => Form,
9134               Arg_Code     => Code);
9135
9136             if not Is_VMS_Exception (Entity (Internal)) then
9137                Set_Imported (Entity (Internal));
9138             end if;
9139          end Import_Exception;
9140
9141          ---------------------
9142          -- Import_Function --
9143          ---------------------
9144
9145          --  pragma Import_Function (
9146          --        [Internal                 =>] LOCAL_NAME,
9147          --     [, [External                 =>] EXTERNAL_SYMBOL]
9148          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9149          --     [, [Result_Type              =>] SUBTYPE_MARK]
9150          --     [, [Mechanism                =>] MECHANISM]
9151          --     [, [Result_Mechanism         =>] MECHANISM_NAME]
9152          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9153
9154          --  EXTERNAL_SYMBOL ::=
9155          --    IDENTIFIER
9156          --  | static_string_EXPRESSION
9157
9158          --  PARAMETER_TYPES ::=
9159          --    null
9160          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9161
9162          --  TYPE_DESIGNATOR ::=
9163          --    subtype_NAME
9164          --  | subtype_Name ' Access
9165
9166          --  MECHANISM ::=
9167          --    MECHANISM_NAME
9168          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9169
9170          --  MECHANISM_ASSOCIATION ::=
9171          --    [formal_parameter_NAME =>] MECHANISM_NAME
9172
9173          --  MECHANISM_NAME ::=
9174          --    Value
9175          --  | Reference
9176          --  | Descriptor [([Class =>] CLASS_NAME)]
9177
9178          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9179
9180          when Pragma_Import_Function => Import_Function : declare
9181             Args  : Args_List (1 .. 7);
9182             Names : constant Name_List (1 .. 7) := (
9183                       Name_Internal,
9184                       Name_External,
9185                       Name_Parameter_Types,
9186                       Name_Result_Type,
9187                       Name_Mechanism,
9188                       Name_Result_Mechanism,
9189                       Name_First_Optional_Parameter);
9190
9191             Internal                 : Node_Id renames Args (1);
9192             External                 : Node_Id renames Args (2);
9193             Parameter_Types          : Node_Id renames Args (3);
9194             Result_Type              : Node_Id renames Args (4);
9195             Mechanism                : Node_Id renames Args (5);
9196             Result_Mechanism         : Node_Id renames Args (6);
9197             First_Optional_Parameter : Node_Id renames Args (7);
9198
9199          begin
9200             GNAT_Pragma;
9201             Gather_Associations (Names, Args);
9202             Process_Extended_Import_Export_Subprogram_Pragma (
9203               Arg_Internal                 => Internal,
9204               Arg_External                 => External,
9205               Arg_Parameter_Types          => Parameter_Types,
9206               Arg_Result_Type              => Result_Type,
9207               Arg_Mechanism                => Mechanism,
9208               Arg_Result_Mechanism         => Result_Mechanism,
9209               Arg_First_Optional_Parameter => First_Optional_Parameter);
9210          end Import_Function;
9211
9212          -------------------
9213          -- Import_Object --
9214          -------------------
9215
9216          --  pragma Import_Object (
9217          --        [Internal =>] LOCAL_NAME
9218          --     [, [External =>] EXTERNAL_SYMBOL]
9219          --     [, [Size     =>] EXTERNAL_SYMBOL]);
9220
9221          --  EXTERNAL_SYMBOL ::=
9222          --    IDENTIFIER
9223          --  | static_string_EXPRESSION
9224
9225          when Pragma_Import_Object => Import_Object : declare
9226             Args  : Args_List (1 .. 3);
9227             Names : constant Name_List (1 .. 3) := (
9228                       Name_Internal,
9229                       Name_External,
9230                       Name_Size);
9231
9232             Internal : Node_Id renames Args (1);
9233             External : Node_Id renames Args (2);
9234             Size     : Node_Id renames Args (3);
9235
9236          begin
9237             GNAT_Pragma;
9238             Gather_Associations (Names, Args);
9239             Process_Extended_Import_Export_Object_Pragma (
9240               Arg_Internal => Internal,
9241               Arg_External => External,
9242               Arg_Size     => Size);
9243          end Import_Object;
9244
9245          ----------------------
9246          -- Import_Procedure --
9247          ----------------------
9248
9249          --  pragma Import_Procedure (
9250          --        [Internal                 =>] LOCAL_NAME
9251          --     [, [External                 =>] EXTERNAL_SYMBOL]
9252          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9253          --     [, [Mechanism                =>] MECHANISM]
9254          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9255
9256          --  EXTERNAL_SYMBOL ::=
9257          --    IDENTIFIER
9258          --  | static_string_EXPRESSION
9259
9260          --  PARAMETER_TYPES ::=
9261          --    null
9262          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9263
9264          --  TYPE_DESIGNATOR ::=
9265          --    subtype_NAME
9266          --  | subtype_Name ' Access
9267
9268          --  MECHANISM ::=
9269          --    MECHANISM_NAME
9270          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9271
9272          --  MECHANISM_ASSOCIATION ::=
9273          --    [formal_parameter_NAME =>] MECHANISM_NAME
9274
9275          --  MECHANISM_NAME ::=
9276          --    Value
9277          --  | Reference
9278          --  | Descriptor [([Class =>] CLASS_NAME)]
9279
9280          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9281
9282          when Pragma_Import_Procedure => Import_Procedure : declare
9283             Args  : Args_List (1 .. 5);
9284             Names : constant Name_List (1 .. 5) := (
9285                       Name_Internal,
9286                       Name_External,
9287                       Name_Parameter_Types,
9288                       Name_Mechanism,
9289                       Name_First_Optional_Parameter);
9290
9291             Internal                 : Node_Id renames Args (1);
9292             External                 : Node_Id renames Args (2);
9293             Parameter_Types          : Node_Id renames Args (3);
9294             Mechanism                : Node_Id renames Args (4);
9295             First_Optional_Parameter : Node_Id renames Args (5);
9296
9297          begin
9298             GNAT_Pragma;
9299             Gather_Associations (Names, Args);
9300             Process_Extended_Import_Export_Subprogram_Pragma (
9301               Arg_Internal                 => Internal,
9302               Arg_External                 => External,
9303               Arg_Parameter_Types          => Parameter_Types,
9304               Arg_Mechanism                => Mechanism,
9305               Arg_First_Optional_Parameter => First_Optional_Parameter);
9306          end Import_Procedure;
9307
9308          -----------------------------
9309          -- Import_Valued_Procedure --
9310          -----------------------------
9311
9312          --  pragma Import_Valued_Procedure (
9313          --        [Internal                 =>] LOCAL_NAME
9314          --     [, [External                 =>] EXTERNAL_SYMBOL]
9315          --     [, [Parameter_Types          =>] (PARAMETER_TYPES)]
9316          --     [, [Mechanism                =>] MECHANISM]
9317          --     [, [First_Optional_Parameter =>] IDENTIFIER]);
9318
9319          --  EXTERNAL_SYMBOL ::=
9320          --    IDENTIFIER
9321          --  | static_string_EXPRESSION
9322
9323          --  PARAMETER_TYPES ::=
9324          --    null
9325          --  | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
9326
9327          --  TYPE_DESIGNATOR ::=
9328          --    subtype_NAME
9329          --  | subtype_Name ' Access
9330
9331          --  MECHANISM ::=
9332          --    MECHANISM_NAME
9333          --  | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
9334
9335          --  MECHANISM_ASSOCIATION ::=
9336          --    [formal_parameter_NAME =>] MECHANISM_NAME
9337
9338          --  MECHANISM_NAME ::=
9339          --    Value
9340          --  | Reference
9341          --  | Descriptor [([Class =>] CLASS_NAME)]
9342
9343          --  CLASS_NAME ::= ubs | ubsb | uba | s | sb | a | nca
9344
9345          when Pragma_Import_Valued_Procedure =>
9346          Import_Valued_Procedure : declare
9347             Args  : Args_List (1 .. 5);
9348             Names : constant Name_List (1 .. 5) := (
9349                       Name_Internal,
9350                       Name_External,
9351                       Name_Parameter_Types,
9352                       Name_Mechanism,
9353                       Name_First_Optional_Parameter);
9354
9355             Internal                 : Node_Id renames Args (1);
9356             External                 : Node_Id renames Args (2);
9357             Parameter_Types          : Node_Id renames Args (3);
9358             Mechanism                : Node_Id renames Args (4);
9359             First_Optional_Parameter : Node_Id renames Args (5);
9360
9361          begin
9362             GNAT_Pragma;
9363             Gather_Associations (Names, Args);
9364             Process_Extended_Import_Export_Subprogram_Pragma (
9365               Arg_Internal                 => Internal,
9366               Arg_External                 => External,
9367               Arg_Parameter_Types          => Parameter_Types,
9368               Arg_Mechanism                => Mechanism,
9369               Arg_First_Optional_Parameter => First_Optional_Parameter);
9370          end Import_Valued_Procedure;
9371
9372          -----------------
9373          -- Independent --
9374          -----------------
9375
9376          --  pragma Independent (LOCAL_NAME);
9377
9378          when Pragma_Independent => Independent : declare
9379             E_Id : Node_Id;
9380             E    : Entity_Id;
9381             D    : Node_Id;
9382             K    : Node_Kind;
9383
9384          begin
9385             Check_Ada_83_Warning;
9386             Ada_2012_Pragma;
9387             Check_No_Identifiers;
9388             Check_Arg_Count (1);
9389             Check_Arg_Is_Local_Name (Arg1);
9390             E_Id := Get_Pragma_Arg (Arg1);
9391
9392             if Etype (E_Id) = Any_Type then
9393                return;
9394             end if;
9395
9396             E := Entity (E_Id);
9397             D := Declaration_Node (E);
9398             K := Nkind (D);
9399
9400             --  Check duplicate before we chain ourselves!
9401
9402             Check_Duplicate_Pragma (E);
9403
9404             --  Check appropriate entity
9405
9406             if Is_Type (E) then
9407                if Rep_Item_Too_Early (E, N)
9408                     or else
9409                   Rep_Item_Too_Late (E, N)
9410                then
9411                   return;
9412                else
9413                   Check_First_Subtype (Arg1);
9414                end if;
9415
9416             elsif K = N_Object_Declaration
9417               or else (K = N_Component_Declaration
9418                        and then Original_Record_Component (E) = E)
9419             then
9420                if Rep_Item_Too_Late (E, N) then
9421                   return;
9422                end if;
9423
9424             else
9425                Error_Pragma_Arg
9426                  ("inappropriate entity for pragma%", Arg1);
9427             end if;
9428
9429             Independence_Checks.Append ((N, E));
9430          end Independent;
9431
9432          ----------------------------
9433          -- Independent_Components --
9434          ----------------------------
9435
9436          --  pragma Atomic_Components (array_LOCAL_NAME);
9437
9438          --  This processing is shared by Volatile_Components
9439
9440          when Pragma_Independent_Components => Independent_Components : declare
9441             E_Id : Node_Id;
9442             E    : Entity_Id;
9443             D    : Node_Id;
9444             K    : Node_Kind;
9445
9446          begin
9447             Check_Ada_83_Warning;
9448             Ada_2012_Pragma;
9449             Check_No_Identifiers;
9450             Check_Arg_Count (1);
9451             Check_Arg_Is_Local_Name (Arg1);
9452             E_Id := Get_Pragma_Arg (Arg1);
9453
9454             if Etype (E_Id) = Any_Type then
9455                return;
9456             end if;
9457
9458             E := Entity (E_Id);
9459
9460             --  Check duplicate before we chain ourselves!
9461
9462             Check_Duplicate_Pragma (E);
9463
9464             --  Check appropriate entity
9465
9466             if Rep_Item_Too_Early (E, N)
9467                  or else
9468                Rep_Item_Too_Late (E, N)
9469             then
9470                return;
9471             end if;
9472
9473             D := Declaration_Node (E);
9474             K := Nkind (D);
9475
9476             if (K = N_Full_Type_Declaration
9477                  and then (Is_Array_Type (E) or else Is_Record_Type (E)))
9478               or else
9479                 ((Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
9480                    and then Nkind (D) = N_Object_Declaration
9481                    and then Nkind (Object_Definition (D)) =
9482                                        N_Constrained_Array_Definition)
9483             then
9484                Independence_Checks.Append ((N, E));
9485
9486             else
9487                Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1);
9488             end if;
9489          end Independent_Components;
9490
9491          ------------------------
9492          -- Initialize_Scalars --
9493          ------------------------
9494
9495          --  pragma Initialize_Scalars;
9496
9497          when Pragma_Initialize_Scalars =>
9498             GNAT_Pragma;
9499             Check_Arg_Count (0);
9500             Check_Valid_Configuration_Pragma;
9501             Check_Restriction (No_Initialize_Scalars, N);
9502
9503             --  Initialize_Scalars creates false positives in CodePeer, and
9504             --  incorrect negative results in Alfa mode, so ignore this pragma
9505             --  in these modes.
9506
9507             if not Restriction_Active (No_Initialize_Scalars)
9508               and then not (CodePeer_Mode or Alfa_Mode)
9509             then
9510                Init_Or_Norm_Scalars := True;
9511                Initialize_Scalars := True;
9512             end if;
9513
9514          ------------
9515          -- Inline --
9516          ------------
9517
9518          --  pragma Inline ( NAME {, NAME} );
9519
9520          when Pragma_Inline =>
9521
9522             --  Pragma is active if inlining option is active
9523
9524             Process_Inline (Inline_Active);
9525
9526          -------------------
9527          -- Inline_Always --
9528          -------------------
9529
9530          --  pragma Inline_Always ( NAME {, NAME} );
9531
9532          when Pragma_Inline_Always =>
9533             GNAT_Pragma;
9534
9535             --  Pragma always active unless in CodePeer or Alfa mode, since
9536             --  this causes walk order issues.
9537
9538             if not (CodePeer_Mode or Alfa_Mode) then
9539                Process_Inline (True);
9540             end if;
9541
9542          --------------------
9543          -- Inline_Generic --
9544          --------------------
9545
9546          --  pragma Inline_Generic (NAME {, NAME});
9547
9548          when Pragma_Inline_Generic =>
9549             GNAT_Pragma;
9550             Process_Generic_List;
9551
9552          ----------------------
9553          -- Inspection_Point --
9554          ----------------------
9555
9556          --  pragma Inspection_Point [(object_NAME {, object_NAME})];
9557
9558          when Pragma_Inspection_Point => Inspection_Point : declare
9559             Arg : Node_Id;
9560             Exp : Node_Id;
9561
9562          begin
9563             if Arg_Count > 0 then
9564                Arg := Arg1;
9565                loop
9566                   Exp := Get_Pragma_Arg (Arg);
9567                   Analyze (Exp);
9568
9569                   if not Is_Entity_Name (Exp)
9570                     or else not Is_Object (Entity (Exp))
9571                   then
9572                      Error_Pragma_Arg ("object name required", Arg);
9573                   end if;
9574
9575                   Next (Arg);
9576                   exit when No (Arg);
9577                end loop;
9578             end if;
9579          end Inspection_Point;
9580
9581          ---------------
9582          -- Interface --
9583          ---------------
9584
9585          --  pragma Interface (
9586          --    [   Convention    =>] convention_IDENTIFIER,
9587          --    [   Entity        =>] local_NAME
9588          --    [, [External_Name =>] static_string_EXPRESSION ]
9589          --    [, [Link_Name     =>] static_string_EXPRESSION ]);
9590
9591          when Pragma_Interface =>
9592             GNAT_Pragma;
9593             Check_Arg_Order
9594               ((Name_Convention,
9595                 Name_Entity,
9596                 Name_External_Name,
9597                 Name_Link_Name));
9598             Check_At_Least_N_Arguments (2);
9599             Check_At_Most_N_Arguments  (4);
9600             Process_Import_Or_Interface;
9601
9602             --  In Ada 2005, the permission to use Interface (a reserved word)
9603             --  as a pragma name is considered an obsolescent feature.
9604
9605             if Ada_Version >= Ada_2005 then
9606                Check_Restriction
9607                  (No_Obsolescent_Features, Pragma_Identifier (N));
9608             end if;
9609
9610          --------------------
9611          -- Interface_Name --
9612          --------------------
9613
9614          --  pragma Interface_Name (
9615          --    [  Entity        =>] local_NAME
9616          --    [,[External_Name =>] static_string_EXPRESSION ]
9617          --    [,[Link_Name     =>] static_string_EXPRESSION ]);
9618
9619          when Pragma_Interface_Name => Interface_Name : declare
9620             Id     : Node_Id;
9621             Def_Id : Entity_Id;
9622             Hom_Id : Entity_Id;
9623             Found  : Boolean;
9624
9625          begin
9626             GNAT_Pragma;
9627             Check_Arg_Order
9628               ((Name_Entity, Name_External_Name, Name_Link_Name));
9629             Check_At_Least_N_Arguments (2);
9630             Check_At_Most_N_Arguments  (3);
9631             Id := Get_Pragma_Arg (Arg1);
9632             Analyze (Id);
9633
9634             if not Is_Entity_Name (Id) then
9635                Error_Pragma_Arg
9636                  ("first argument for pragma% must be entity name", Arg1);
9637             elsif Etype (Id) = Any_Type then
9638                return;
9639             else
9640                Def_Id := Entity (Id);
9641             end if;
9642
9643             --  Special DEC-compatible processing for the object case, forces
9644             --  object to be imported.
9645
9646             if Ekind (Def_Id) = E_Variable then
9647                Kill_Size_Check_Code (Def_Id);
9648                Note_Possible_Modification (Id, Sure => False);
9649
9650                --  Initialization is not allowed for imported variable
9651
9652                if Present (Expression (Parent (Def_Id)))
9653                  and then Comes_From_Source (Expression (Parent (Def_Id)))
9654                then
9655                   Error_Msg_Sloc := Sloc (Def_Id);
9656                   Error_Pragma_Arg
9657                     ("no initialization allowed for declaration of& #",
9658                      Arg2);
9659
9660                else
9661                   --  For compatibility, support VADS usage of providing both
9662                   --  pragmas Interface and Interface_Name to obtain the effect
9663                   --  of a single Import pragma.
9664
9665                   if Is_Imported (Def_Id)
9666                     and then Present (First_Rep_Item (Def_Id))
9667                     and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma
9668                     and then
9669                       Pragma_Name (First_Rep_Item (Def_Id)) = Name_Interface
9670                   then
9671                      null;
9672                   else
9673                      Set_Imported (Def_Id);
9674                   end if;
9675
9676                   Set_Is_Public (Def_Id);
9677                   Process_Interface_Name (Def_Id, Arg2, Arg3);
9678                end if;
9679
9680             --  Otherwise must be subprogram
9681
9682             elsif not Is_Subprogram (Def_Id) then
9683                Error_Pragma_Arg
9684                  ("argument of pragma% is not subprogram", Arg1);
9685
9686             else
9687                Check_At_Most_N_Arguments (3);
9688                Hom_Id := Def_Id;
9689                Found := False;
9690
9691                --  Loop through homonyms
9692
9693                loop
9694                   Def_Id := Get_Base_Subprogram (Hom_Id);
9695
9696                   if Is_Imported (Def_Id) then
9697                      Process_Interface_Name (Def_Id, Arg2, Arg3);
9698                      Found := True;
9699                   end if;
9700
9701                   exit when From_Aspect_Specification (N);
9702                   Hom_Id := Homonym (Hom_Id);
9703
9704                   exit when No (Hom_Id)
9705                     or else Scope (Hom_Id) /= Current_Scope;
9706                end loop;
9707
9708                if not Found then
9709                   Error_Pragma_Arg
9710                     ("argument of pragma% is not imported subprogram",
9711                      Arg1);
9712                end if;
9713             end if;
9714          end Interface_Name;
9715
9716          -----------------------
9717          -- Interrupt_Handler --
9718          -----------------------
9719
9720          --  pragma Interrupt_Handler (handler_NAME);
9721
9722          when Pragma_Interrupt_Handler =>
9723             Check_Ada_83_Warning;
9724             Check_Arg_Count (1);
9725             Check_No_Identifiers;
9726
9727             if No_Run_Time_Mode then
9728                Error_Msg_CRT ("Interrupt_Handler pragma", N);
9729             else
9730                Check_Interrupt_Or_Attach_Handler;
9731                Process_Interrupt_Or_Attach_Handler;
9732             end if;
9733
9734          ------------------------
9735          -- Interrupt_Priority --
9736          ------------------------
9737
9738          --  pragma Interrupt_Priority [(EXPRESSION)];
9739
9740          when Pragma_Interrupt_Priority => Interrupt_Priority : declare
9741             P   : constant Node_Id := Parent (N);
9742             Arg : Node_Id;
9743
9744          begin
9745             Check_Ada_83_Warning;
9746
9747             if Arg_Count /= 0 then
9748                Arg := Get_Pragma_Arg (Arg1);
9749                Check_Arg_Count (1);
9750                Check_No_Identifiers;
9751
9752                --  The expression must be analyzed in the special manner
9753                --  described in "Handling of Default and Per-Object
9754                --  Expressions" in sem.ads.
9755
9756                Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority));
9757             end if;
9758
9759             if not Nkind_In (P, N_Task_Definition, N_Protected_Definition) then
9760                Pragma_Misplaced;
9761                return;
9762
9763             elsif Has_Pragma_Priority (P) then
9764                Error_Pragma ("duplicate pragma% not allowed");
9765
9766             else
9767                Set_Has_Pragma_Priority (P, True);
9768                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
9769             end if;
9770          end Interrupt_Priority;
9771
9772          ---------------------
9773          -- Interrupt_State --
9774          ---------------------
9775
9776          --  pragma Interrupt_State (
9777          --    [Name  =>] INTERRUPT_ID,
9778          --    [State =>] INTERRUPT_STATE);
9779
9780          --  INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
9781          --  INTERRUPT_STATE => System | Runtime | User
9782
9783          --  Note: if the interrupt id is given as an identifier, then it must
9784          --  be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
9785          --  given as a static integer expression which must be in the range of
9786          --  Ada.Interrupts.Interrupt_ID.
9787
9788          when Pragma_Interrupt_State => Interrupt_State : declare
9789
9790             Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID);
9791             --  This is the entity Ada.Interrupts.Interrupt_ID;
9792
9793             State_Type : Character;
9794             --  Set to 's'/'r'/'u' for System/Runtime/User
9795
9796             IST_Num : Pos;
9797             --  Index to entry in Interrupt_States table
9798
9799             Int_Val : Uint;
9800             --  Value of interrupt
9801
9802             Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1);
9803             --  The first argument to the pragma
9804
9805             Int_Ent : Entity_Id;
9806             --  Interrupt entity in Ada.Interrupts.Names
9807
9808          begin
9809             GNAT_Pragma;
9810             Check_Arg_Order ((Name_Name, Name_State));
9811             Check_Arg_Count (2);
9812
9813             Check_Optional_Identifier (Arg1, Name_Name);
9814             Check_Optional_Identifier (Arg2, Name_State);
9815             Check_Arg_Is_Identifier (Arg2);
9816
9817             --  First argument is identifier
9818
9819             if Nkind (Arg1X) = N_Identifier then
9820
9821                --  Search list of names in Ada.Interrupts.Names
9822
9823                Int_Ent := First_Entity (RTE (RE_Names));
9824                loop
9825                   if No (Int_Ent) then
9826                      Error_Pragma_Arg ("invalid interrupt name", Arg1);
9827
9828                   elsif Chars (Int_Ent) = Chars (Arg1X) then
9829                      Int_Val := Expr_Value (Constant_Value (Int_Ent));
9830                      exit;
9831                   end if;
9832
9833                   Next_Entity (Int_Ent);
9834                end loop;
9835
9836             --  First argument is not an identifier, so it must be a static
9837             --  expression of type Ada.Interrupts.Interrupt_ID.
9838
9839             else
9840                Check_Arg_Is_Static_Expression (Arg1, Any_Integer);
9841                Int_Val := Expr_Value (Arg1X);
9842
9843                if Int_Val < Expr_Value (Type_Low_Bound (Int_Id))
9844                     or else
9845                   Int_Val > Expr_Value (Type_High_Bound (Int_Id))
9846                then
9847                   Error_Pragma_Arg
9848                     ("value not in range of type " &
9849                      """Ada.Interrupts.Interrupt_'I'D""", Arg1);
9850                end if;
9851             end if;
9852
9853             --  Check OK state
9854
9855             case Chars (Get_Pragma_Arg (Arg2)) is
9856                when Name_Runtime => State_Type := 'r';
9857                when Name_System  => State_Type := 's';
9858                when Name_User    => State_Type := 'u';
9859
9860                when others =>
9861                   Error_Pragma_Arg ("invalid interrupt state", Arg2);
9862             end case;
9863
9864             --  Check if entry is already stored
9865
9866             IST_Num := Interrupt_States.First;
9867             loop
9868                --  If entry not found, add it
9869
9870                if IST_Num > Interrupt_States.Last then
9871                   Interrupt_States.Append
9872                     ((Interrupt_Number => UI_To_Int (Int_Val),
9873                       Interrupt_State  => State_Type,
9874                       Pragma_Loc       => Loc));
9875                   exit;
9876
9877                --  Case of entry for the same entry
9878
9879                elsif Int_Val = Interrupt_States.Table (IST_Num).
9880                                                            Interrupt_Number
9881                then
9882                   --  If state matches, done, no need to make redundant entry
9883
9884                   exit when
9885                     State_Type = Interrupt_States.Table (IST_Num).
9886                                                            Interrupt_State;
9887
9888                   --  Otherwise if state does not match, error
9889
9890                   Error_Msg_Sloc :=
9891                     Interrupt_States.Table (IST_Num).Pragma_Loc;
9892                   Error_Pragma_Arg
9893                     ("state conflicts with that given #", Arg2);
9894                   exit;
9895                end if;
9896
9897                IST_Num := IST_Num + 1;
9898             end loop;
9899          end Interrupt_State;
9900
9901          ---------------
9902          -- Invariant --
9903          ---------------
9904
9905          --  pragma Invariant
9906          --    ([Entity =>]    type_LOCAL_NAME,
9907          --     [Check  =>]    EXPRESSION
9908          --     [,[Message =>] String_Expression]);
9909
9910          when Pragma_Invariant => Invariant : declare
9911             Type_Id : Node_Id;
9912             Typ     : Entity_Id;
9913
9914             Discard : Boolean;
9915             pragma Unreferenced (Discard);
9916
9917          begin
9918             GNAT_Pragma;
9919             Check_At_Least_N_Arguments (2);
9920             Check_At_Most_N_Arguments (3);
9921             Check_Optional_Identifier (Arg1, Name_Entity);
9922             Check_Optional_Identifier (Arg2, Name_Check);
9923
9924             if Arg_Count = 3 then
9925                Check_Optional_Identifier (Arg3, Name_Message);
9926                Check_Arg_Is_Static_Expression (Arg3, Standard_String);
9927             end if;
9928
9929             Check_Arg_Is_Local_Name (Arg1);
9930
9931             Type_Id := Get_Pragma_Arg (Arg1);
9932             Find_Type (Type_Id);
9933             Typ := Entity (Type_Id);
9934
9935             if Typ = Any_Type then
9936                return;
9937
9938             elsif not Ekind_In (Typ, E_Private_Type,
9939                                      E_Record_Type_With_Private,
9940                                      E_Limited_Private_Type)
9941             then
9942                Error_Pragma_Arg
9943                  ("pragma% only allowed for private type", Arg1);
9944             end if;
9945
9946             --  Note that the type has at least one invariant, and also that
9947             --  it has inheritable invariants if we have Invariant'Class.
9948
9949             Set_Has_Invariants (Typ);
9950
9951             if Class_Present (N) then
9952                Set_Has_Inheritable_Invariants (Typ);
9953             end if;
9954
9955             --  The remaining processing is simply to link the pragma on to
9956             --  the rep item chain, for processing when the type is frozen.
9957             --  This is accomplished by a call to Rep_Item_Too_Late.
9958
9959             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
9960          end Invariant;
9961
9962          ----------------------
9963          -- Java_Constructor --
9964          ----------------------
9965
9966          --  pragma Java_Constructor ([Entity =>] LOCAL_NAME);
9967
9968          --  Also handles pragma CIL_Constructor
9969
9970          when Pragma_CIL_Constructor | Pragma_Java_Constructor =>
9971          Java_Constructor : declare
9972             Convention  : Convention_Id;
9973             Def_Id      : Entity_Id;
9974             Hom_Id      : Entity_Id;
9975             Id          : Entity_Id;
9976             This_Formal : Entity_Id;
9977
9978          begin
9979             GNAT_Pragma;
9980             Check_Arg_Count (1);
9981             Check_Optional_Identifier (Arg1, Name_Entity);
9982             Check_Arg_Is_Local_Name (Arg1);
9983
9984             Id := Get_Pragma_Arg (Arg1);
9985             Find_Program_Unit_Name (Id);
9986
9987             --  If we did not find the name, we are done
9988
9989             if Etype (Id) = Any_Type then
9990                return;
9991             end if;
9992
9993             --  Check wrong use of pragma in wrong VM target
9994
9995             if VM_Target = No_VM then
9996                return;
9997
9998             elsif VM_Target = CLI_Target
9999               and then Prag_Id = Pragma_Java_Constructor
10000             then
10001                Error_Pragma ("must use pragma 'C'I'L_'Constructor");
10002
10003             elsif VM_Target = JVM_Target
10004               and then Prag_Id = Pragma_CIL_Constructor
10005             then
10006                Error_Pragma ("must use pragma 'Java_'Constructor");
10007             end if;
10008
10009             case Prag_Id is
10010                when Pragma_CIL_Constructor  => Convention := Convention_CIL;
10011                when Pragma_Java_Constructor => Convention := Convention_Java;
10012                when others                  => null;
10013             end case;
10014
10015             Hom_Id := Entity (Id);
10016
10017             --  Loop through homonyms
10018
10019             loop
10020                Def_Id := Get_Base_Subprogram (Hom_Id);
10021
10022                --  The constructor is required to be a function
10023
10024                if Ekind (Def_Id) /= E_Function then
10025                   if VM_Target = JVM_Target then
10026                      Error_Pragma_Arg
10027                        ("pragma% requires function returning a " &
10028                         "'Java access type", Def_Id);
10029                   else
10030                      Error_Pragma_Arg
10031                        ("pragma% requires function returning a " &
10032                         "'C'I'L access type", Def_Id);
10033                   end if;
10034                end if;
10035
10036                --  Check arguments: For tagged type the first formal must be
10037                --  named "this" and its type must be a named access type
10038                --  designating a class-wide tagged type that has convention
10039                --  CIL/Java. The first formal must also have a null default
10040                --  value. For example:
10041
10042                --      type Typ is tagged ...
10043                --      type Ref is access all Typ;
10044                --      pragma Convention (CIL, Typ);
10045
10046                --      function New_Typ (This : Ref) return Ref;
10047                --      function New_Typ (This : Ref; I : Integer) return Ref;
10048                --      pragma Cil_Constructor (New_Typ);
10049
10050                --  Reason: The first formal must NOT be a primitive of the
10051                --  tagged type.
10052
10053                --  This rule also applies to constructors of delegates used
10054                --  to interface with standard target libraries. For example:
10055
10056                --      type Delegate is access procedure ...
10057                --      pragma Import (CIL, Delegate, ...);
10058
10059                --      function new_Delegate
10060                --        (This : Delegate := null; ... ) return Delegate;
10061
10062                --  For value-types this rule does not apply.
10063
10064                if not Is_Value_Type (Etype (Def_Id)) then
10065                   if No (First_Formal (Def_Id)) then
10066                      Error_Msg_Name_1 := Pname;
10067                      Error_Msg_N ("% function must have parameters", Def_Id);
10068                      return;
10069                   end if;
10070
10071                   --  In the JRE library we have several occurrences in which
10072                   --  the "this" parameter is not the first formal.
10073
10074                   This_Formal := First_Formal (Def_Id);
10075
10076                   --  In the JRE library we have several occurrences in which
10077                   --  the "this" parameter is not the first formal. Search for
10078                   --  it.
10079
10080                   if VM_Target = JVM_Target then
10081                      while Present (This_Formal)
10082                        and then Get_Name_String (Chars (This_Formal)) /= "this"
10083                      loop
10084                         Next_Formal (This_Formal);
10085                      end loop;
10086
10087                      if No (This_Formal) then
10088                         This_Formal := First_Formal (Def_Id);
10089                      end if;
10090                   end if;
10091
10092                   --  Warning: The first parameter should be named "this".
10093                   --  We temporarily allow it because we have the following
10094                   --  case in the Java runtime (file s-osinte.ads) ???
10095
10096                   --    function new_Thread
10097                   --      (Self_Id : System.Address) return Thread_Id;
10098                   --    pragma Java_Constructor (new_Thread);
10099
10100                   if VM_Target = JVM_Target
10101                     and then Get_Name_String (Chars (First_Formal (Def_Id)))
10102                                = "self_id"
10103                     and then Etype (First_Formal (Def_Id)) = RTE (RE_Address)
10104                   then
10105                      null;
10106
10107                   elsif Get_Name_String (Chars (This_Formal)) /= "this" then
10108                      Error_Msg_Name_1 := Pname;
10109                      Error_Msg_N
10110                        ("first formal of % function must be named `this`",
10111                         Parent (This_Formal));
10112
10113                   elsif not Is_Access_Type (Etype (This_Formal)) then
10114                      Error_Msg_Name_1 := Pname;
10115                      Error_Msg_N
10116                        ("first formal of % function must be an access type",
10117                         Parameter_Type (Parent (This_Formal)));
10118
10119                   --  For delegates the type of the first formal must be a
10120                   --  named access-to-subprogram type (see previous example)
10121
10122                   elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type
10123                     and then Ekind (Etype (This_Formal))
10124                                /= E_Access_Subprogram_Type
10125                   then
10126                      Error_Msg_Name_1 := Pname;
10127                      Error_Msg_N
10128                        ("first formal of % function must be a named access" &
10129                         " to subprogram type",
10130                         Parameter_Type (Parent (This_Formal)));
10131
10132                   --  Warning: We should reject anonymous access types because
10133                   --  the constructor must not be handled as a primitive of the
10134                   --  tagged type. We temporarily allow it because this profile
10135                   --  is currently generated by cil2ada???
10136
10137                   elsif Ekind (Etype (Def_Id)) /= E_Access_Subprogram_Type
10138                     and then not Ekind_In (Etype (This_Formal),
10139                                              E_Access_Type,
10140                                              E_General_Access_Type,
10141                                              E_Anonymous_Access_Type)
10142                   then
10143                      Error_Msg_Name_1 := Pname;
10144                      Error_Msg_N
10145                        ("first formal of % function must be a named access" &
10146                         " type",
10147                         Parameter_Type (Parent (This_Formal)));
10148
10149                   elsif Atree.Convention
10150                          (Designated_Type (Etype (This_Formal))) /= Convention
10151                   then
10152                      Error_Msg_Name_1 := Pname;
10153
10154                      if Convention = Convention_Java then
10155                         Error_Msg_N
10156                           ("pragma% requires convention 'Cil in designated" &
10157                            " type",
10158                            Parameter_Type (Parent (This_Formal)));
10159                      else
10160                         Error_Msg_N
10161                           ("pragma% requires convention 'Java in designated" &
10162                            " type",
10163                            Parameter_Type (Parent (This_Formal)));
10164                      end if;
10165
10166                   elsif No (Expression (Parent (This_Formal)))
10167                     or else Nkind (Expression (Parent (This_Formal))) /= N_Null
10168                   then
10169                      Error_Msg_Name_1 := Pname;
10170                      Error_Msg_N
10171                        ("pragma% requires first formal with default `null`",
10172                         Parameter_Type (Parent (This_Formal)));
10173                   end if;
10174                end if;
10175
10176                --  Check result type: the constructor must be a function
10177                --  returning:
10178                --   * a value type (only allowed in the CIL compiler)
10179                --   * an access-to-subprogram type with convention Java/CIL
10180                --   * an access-type designating a type that has convention
10181                --     Java/CIL.
10182
10183                if Is_Value_Type (Etype (Def_Id)) then
10184                   null;
10185
10186                --  Access-to-subprogram type with convention Java/CIL
10187
10188                elsif Ekind (Etype (Def_Id)) = E_Access_Subprogram_Type then
10189                   if Atree.Convention (Etype (Def_Id)) /= Convention then
10190                      if Convention = Convention_Java then
10191                         Error_Pragma_Arg
10192                           ("pragma% requires function returning a " &
10193                            "'Java access type", Arg1);
10194                      else
10195                         pragma Assert (Convention = Convention_CIL);
10196                         Error_Pragma_Arg
10197                           ("pragma% requires function returning a " &
10198                            "'C'I'L access type", Arg1);
10199                      end if;
10200                   end if;
10201
10202                elsif Ekind (Etype (Def_Id)) in Access_Kind then
10203                   if not Ekind_In (Etype (Def_Id), E_Access_Type,
10204                                                    E_General_Access_Type)
10205                     or else
10206                       Atree.Convention
10207                         (Designated_Type (Etype (Def_Id))) /= Convention
10208                   then
10209                      Error_Msg_Name_1 := Pname;
10210
10211                      if Convention = Convention_Java then
10212                         Error_Pragma_Arg
10213                           ("pragma% requires function returning a named" &
10214                            "'Java access type", Arg1);
10215                      else
10216                         Error_Pragma_Arg
10217                           ("pragma% requires function returning a named" &
10218                            "'C'I'L access type", Arg1);
10219                      end if;
10220                   end if;
10221                end if;
10222
10223                Set_Is_Constructor (Def_Id);
10224                Set_Convention     (Def_Id, Convention);
10225                Set_Is_Imported    (Def_Id);
10226
10227                exit when From_Aspect_Specification (N);
10228                Hom_Id := Homonym (Hom_Id);
10229
10230                exit when No (Hom_Id) or else Scope (Hom_Id) /= Current_Scope;
10231             end loop;
10232          end Java_Constructor;
10233
10234          ----------------------
10235          -- Java_Interface --
10236          ----------------------
10237
10238          --  pragma Java_Interface ([Entity =>] LOCAL_NAME);
10239
10240          when Pragma_Java_Interface => Java_Interface : declare
10241             Arg : Node_Id;
10242             Typ : Entity_Id;
10243
10244          begin
10245             GNAT_Pragma;
10246             Check_Arg_Count (1);
10247             Check_Optional_Identifier (Arg1, Name_Entity);
10248             Check_Arg_Is_Local_Name (Arg1);
10249
10250             Arg := Get_Pragma_Arg (Arg1);
10251             Analyze (Arg);
10252
10253             if Etype (Arg) = Any_Type then
10254                return;
10255             end if;
10256
10257             if not Is_Entity_Name (Arg)
10258               or else not Is_Type (Entity (Arg))
10259             then
10260                Error_Pragma_Arg ("pragma% requires a type mark", Arg1);
10261             end if;
10262
10263             Typ := Underlying_Type (Entity (Arg));
10264
10265             --  For now simply check some of the semantic constraints on the
10266             --  type. This currently leaves out some restrictions on interface
10267             --  types, namely that the parent type must be java.lang.Object.Typ
10268             --  and that all primitives of the type should be declared
10269             --  abstract. ???
10270
10271             if not Is_Tagged_Type (Typ) or else not Is_Abstract_Type (Typ) then
10272                Error_Pragma_Arg ("pragma% requires an abstract "
10273                  & "tagged type", Arg1);
10274
10275             elsif not Has_Discriminants (Typ)
10276               or else Ekind (Etype (First_Discriminant (Typ)))
10277                         /= E_Anonymous_Access_Type
10278               or else
10279                 not Is_Class_Wide_Type
10280                       (Designated_Type (Etype (First_Discriminant (Typ))))
10281             then
10282                Error_Pragma_Arg
10283                  ("type must have a class-wide access discriminant", Arg1);
10284             end if;
10285          end Java_Interface;
10286
10287          ----------------
10288          -- Keep_Names --
10289          ----------------
10290
10291          --  pragma Keep_Names ([On => ] local_NAME);
10292
10293          when Pragma_Keep_Names => Keep_Names : declare
10294             Arg : Node_Id;
10295
10296          begin
10297             GNAT_Pragma;
10298             Check_Arg_Count (1);
10299             Check_Optional_Identifier (Arg1, Name_On);
10300             Check_Arg_Is_Local_Name (Arg1);
10301
10302             Arg := Get_Pragma_Arg (Arg1);
10303             Analyze (Arg);
10304
10305             if Etype (Arg) = Any_Type then
10306                return;
10307             end if;
10308
10309             if not Is_Entity_Name (Arg)
10310               or else Ekind (Entity (Arg)) /= E_Enumeration_Type
10311             then
10312                Error_Pragma_Arg
10313                  ("pragma% requires a local enumeration type", Arg1);
10314             end if;
10315
10316             Set_Discard_Names (Entity (Arg), False);
10317          end Keep_Names;
10318
10319          -------------
10320          -- License --
10321          -------------
10322
10323          --  pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
10324
10325          when Pragma_License =>
10326             GNAT_Pragma;
10327             Check_Arg_Count (1);
10328             Check_No_Identifiers;
10329             Check_Valid_Configuration_Pragma;
10330             Check_Arg_Is_Identifier (Arg1);
10331
10332             declare
10333                Sind : constant Source_File_Index :=
10334                         Source_Index (Current_Sem_Unit);
10335
10336             begin
10337                case Chars (Get_Pragma_Arg (Arg1)) is
10338                   when Name_GPL =>
10339                      Set_License (Sind, GPL);
10340
10341                   when Name_Modified_GPL =>
10342                      Set_License (Sind, Modified_GPL);
10343
10344                   when Name_Restricted =>
10345                      Set_License (Sind, Restricted);
10346
10347                   when Name_Unrestricted =>
10348                      Set_License (Sind, Unrestricted);
10349
10350                   when others =>
10351                      Error_Pragma_Arg ("invalid license name", Arg1);
10352                end case;
10353             end;
10354
10355          ---------------
10356          -- Link_With --
10357          ---------------
10358
10359          --  pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
10360
10361          when Pragma_Link_With => Link_With : declare
10362             Arg : Node_Id;
10363
10364          begin
10365             GNAT_Pragma;
10366
10367             if Operating_Mode = Generate_Code
10368               and then In_Extended_Main_Source_Unit (N)
10369             then
10370                Check_At_Least_N_Arguments (1);
10371                Check_No_Identifiers;
10372                Check_Is_In_Decl_Part_Or_Package_Spec;
10373                Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10374                Start_String;
10375
10376                Arg := Arg1;
10377                while Present (Arg) loop
10378                   Check_Arg_Is_Static_Expression (Arg, Standard_String);
10379
10380                   --  Store argument, converting sequences of spaces to a
10381                   --  single null character (this is one of the differences
10382                   --  in processing between Link_With and Linker_Options).
10383
10384                   Arg_Store : declare
10385                      C : constant Char_Code := Get_Char_Code (' ');
10386                      S : constant String_Id :=
10387                            Strval (Expr_Value_S (Get_Pragma_Arg (Arg)));
10388                      L : constant Nat := String_Length (S);
10389                      F : Nat := 1;
10390
10391                      procedure Skip_Spaces;
10392                      --  Advance F past any spaces
10393
10394                      -----------------
10395                      -- Skip_Spaces --
10396                      -----------------
10397
10398                      procedure Skip_Spaces is
10399                      begin
10400                         while F <= L and then Get_String_Char (S, F) = C loop
10401                            F := F + 1;
10402                         end loop;
10403                      end Skip_Spaces;
10404
10405                   --  Start of processing for Arg_Store
10406
10407                   begin
10408                      Skip_Spaces; -- skip leading spaces
10409
10410                      --  Loop through characters, changing any embedded
10411                      --  sequence of spaces to a single null character (this
10412                      --  is how Link_With/Linker_Options differ)
10413
10414                      while F <= L loop
10415                         if Get_String_Char (S, F) = C then
10416                            Skip_Spaces;
10417                            exit when F > L;
10418                            Store_String_Char (ASCII.NUL);
10419
10420                         else
10421                            Store_String_Char (Get_String_Char (S, F));
10422                            F := F + 1;
10423                         end if;
10424                      end loop;
10425                   end Arg_Store;
10426
10427                   Arg := Next (Arg);
10428
10429                   if Present (Arg) then
10430                      Store_String_Char (ASCII.NUL);
10431                   end if;
10432                end loop;
10433
10434                Store_Linker_Option_String (End_String);
10435             end if;
10436          end Link_With;
10437
10438          ------------------
10439          -- Linker_Alias --
10440          ------------------
10441
10442          --  pragma Linker_Alias (
10443          --      [Entity =>]  LOCAL_NAME
10444          --      [Target =>]  static_string_EXPRESSION);
10445
10446          when Pragma_Linker_Alias =>
10447             GNAT_Pragma;
10448             Check_Arg_Order ((Name_Entity, Name_Target));
10449             Check_Arg_Count (2);
10450             Check_Optional_Identifier (Arg1, Name_Entity);
10451             Check_Optional_Identifier (Arg2, Name_Target);
10452             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10453             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10454
10455             --  The only processing required is to link this item on to the
10456             --  list of rep items for the given entity. This is accomplished
10457             --  by the call to Rep_Item_Too_Late (when no error is detected
10458             --  and False is returned).
10459
10460             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10461                return;
10462             else
10463                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10464             end if;
10465
10466          ------------------------
10467          -- Linker_Constructor --
10468          ------------------------
10469
10470          --  pragma Linker_Constructor (procedure_LOCAL_NAME);
10471
10472          --  Code is shared with Linker_Destructor
10473
10474          -----------------------
10475          -- Linker_Destructor --
10476          -----------------------
10477
10478          --  pragma Linker_Destructor (procedure_LOCAL_NAME);
10479
10480          when Pragma_Linker_Constructor |
10481               Pragma_Linker_Destructor =>
10482          Linker_Constructor : declare
10483             Arg1_X : Node_Id;
10484             Proc   : Entity_Id;
10485
10486          begin
10487             GNAT_Pragma;
10488             Check_Arg_Count (1);
10489             Check_No_Identifiers;
10490             Check_Arg_Is_Local_Name (Arg1);
10491             Arg1_X := Get_Pragma_Arg (Arg1);
10492             Analyze (Arg1_X);
10493             Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1);
10494
10495             if not Is_Library_Level_Entity (Proc) then
10496                Error_Pragma_Arg
10497                 ("argument for pragma% must be library level entity", Arg1);
10498             end if;
10499
10500             --  The only processing required is to link this item on to the
10501             --  list of rep items for the given entity. This is accomplished
10502             --  by the call to Rep_Item_Too_Late (when no error is detected
10503             --  and False is returned).
10504
10505             if Rep_Item_Too_Late (Proc, N) then
10506                return;
10507             else
10508                Set_Has_Gigi_Rep_Item (Proc);
10509             end if;
10510          end Linker_Constructor;
10511
10512          --------------------
10513          -- Linker_Options --
10514          --------------------
10515
10516          --  pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
10517
10518          when Pragma_Linker_Options => Linker_Options : declare
10519             Arg : Node_Id;
10520
10521          begin
10522             Check_Ada_83_Warning;
10523             Check_No_Identifiers;
10524             Check_Arg_Count (1);
10525             Check_Is_In_Decl_Part_Or_Package_Spec;
10526             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
10527             Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1))));
10528
10529             Arg := Arg2;
10530             while Present (Arg) loop
10531                Check_Arg_Is_Static_Expression (Arg, Standard_String);
10532                Store_String_Char (ASCII.NUL);
10533                Store_String_Chars
10534                  (Strval (Expr_Value_S (Get_Pragma_Arg (Arg))));
10535                Arg := Next (Arg);
10536             end loop;
10537
10538             if Operating_Mode = Generate_Code
10539               and then In_Extended_Main_Source_Unit (N)
10540             then
10541                Store_Linker_Option_String (End_String);
10542             end if;
10543          end Linker_Options;
10544
10545          --------------------
10546          -- Linker_Section --
10547          --------------------
10548
10549          --  pragma Linker_Section (
10550          --      [Entity  =>]  LOCAL_NAME
10551          --      [Section =>]  static_string_EXPRESSION);
10552
10553          when Pragma_Linker_Section =>
10554             GNAT_Pragma;
10555             Check_Arg_Order ((Name_Entity, Name_Section));
10556             Check_Arg_Count (2);
10557             Check_Optional_Identifier (Arg1, Name_Entity);
10558             Check_Optional_Identifier (Arg2, Name_Section);
10559             Check_Arg_Is_Library_Level_Local_Name (Arg1);
10560             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10561
10562             --  This pragma applies only to objects
10563
10564             if not Is_Object (Entity (Get_Pragma_Arg (Arg1))) then
10565                Error_Pragma_Arg ("pragma% applies only to objects", Arg1);
10566             end if;
10567
10568             --  The only processing required is to link this item on to the
10569             --  list of rep items for the given entity. This is accomplished
10570             --  by the call to Rep_Item_Too_Late (when no error is detected
10571             --  and False is returned).
10572
10573             if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then
10574                return;
10575             else
10576                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10577             end if;
10578
10579          ----------
10580          -- List --
10581          ----------
10582
10583          --  pragma List (On | Off)
10584
10585          --  There is nothing to do here, since we did all the processing for
10586          --  this pragma in Par.Prag (so that it works properly even in syntax
10587          --  only mode).
10588
10589          when Pragma_List =>
10590             null;
10591
10592          --------------------
10593          -- Locking_Policy --
10594          --------------------
10595
10596          --  pragma Locking_Policy (policy_IDENTIFIER);
10597
10598          when Pragma_Locking_Policy => declare
10599             LP : Character;
10600
10601          begin
10602             Check_Ada_83_Warning;
10603             Check_Arg_Count (1);
10604             Check_No_Identifiers;
10605             Check_Arg_Is_Locking_Policy (Arg1);
10606             Check_Valid_Configuration_Pragma;
10607             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
10608             LP := Fold_Upper (Name_Buffer (1));
10609
10610             if Locking_Policy /= ' '
10611               and then Locking_Policy /= LP
10612             then
10613                Error_Msg_Sloc := Locking_Policy_Sloc;
10614                Error_Pragma ("locking policy incompatible with policy#");
10615
10616             --  Set new policy, but always preserve System_Location since we
10617             --  like the error message with the run time name.
10618
10619             else
10620                Locking_Policy := LP;
10621
10622                if Locking_Policy_Sloc /= System_Location then
10623                   Locking_Policy_Sloc := Loc;
10624                end if;
10625             end if;
10626          end;
10627
10628          ----------------
10629          -- Long_Float --
10630          ----------------
10631
10632          --  pragma Long_Float (D_Float | G_Float);
10633
10634          when Pragma_Long_Float =>
10635             GNAT_Pragma;
10636             Check_Valid_Configuration_Pragma;
10637             Check_Arg_Count (1);
10638             Check_No_Identifier (Arg1);
10639             Check_Arg_Is_One_Of (Arg1, Name_D_Float, Name_G_Float);
10640
10641             if not OpenVMS_On_Target then
10642                Error_Pragma ("?pragma% ignored (applies only to Open'V'M'S)");
10643             end if;
10644
10645             --  D_Float case
10646
10647             if Chars (Get_Pragma_Arg (Arg1)) = Name_D_Float then
10648                if Opt.Float_Format_Long = 'G' then
10649                   Error_Pragma ("G_Float previously specified");
10650                end if;
10651
10652                Opt.Float_Format_Long := 'D';
10653
10654             --  G_Float case (this is the default, does not need overriding)
10655
10656             else
10657                if Opt.Float_Format_Long = 'D' then
10658                   Error_Pragma ("D_Float previously specified");
10659                end if;
10660
10661                Opt.Float_Format_Long := 'G';
10662             end if;
10663
10664             Set_Standard_Fpt_Formats;
10665
10666          -----------------------
10667          -- Machine_Attribute --
10668          -----------------------
10669
10670          --  pragma Machine_Attribute (
10671          --       [Entity         =>] LOCAL_NAME,
10672          --       [Attribute_Name =>] static_string_EXPRESSION
10673          --    [, [Info           =>] static_EXPRESSION] );
10674
10675          when Pragma_Machine_Attribute => Machine_Attribute : declare
10676             Def_Id : Entity_Id;
10677
10678          begin
10679             GNAT_Pragma;
10680             Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info));
10681
10682             if Arg_Count = 3 then
10683                Check_Optional_Identifier (Arg3, Name_Info);
10684                Check_Arg_Is_Static_Expression (Arg3);
10685             else
10686                Check_Arg_Count (2);
10687             end if;
10688
10689             Check_Optional_Identifier (Arg1, Name_Entity);
10690             Check_Optional_Identifier (Arg2, Name_Attribute_Name);
10691             Check_Arg_Is_Local_Name (Arg1);
10692             Check_Arg_Is_Static_Expression (Arg2, Standard_String);
10693             Def_Id := Entity (Get_Pragma_Arg (Arg1));
10694
10695             if Is_Access_Type (Def_Id) then
10696                Def_Id := Designated_Type (Def_Id);
10697             end if;
10698
10699             if Rep_Item_Too_Early (Def_Id, N) then
10700                return;
10701             end if;
10702
10703             Def_Id := Underlying_Type (Def_Id);
10704
10705             --  The only processing required is to link this item on to the
10706             --  list of rep items for the given entity. This is accomplished
10707             --  by the call to Rep_Item_Too_Late (when no error is detected
10708             --  and False is returned).
10709
10710             if Rep_Item_Too_Late (Def_Id, N) then
10711                return;
10712             else
10713                Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1)));
10714             end if;
10715          end Machine_Attribute;
10716
10717          ----------
10718          -- Main --
10719          ----------
10720
10721          --  pragma Main
10722          --   (MAIN_OPTION [, MAIN_OPTION]);
10723
10724          --  MAIN_OPTION ::=
10725          --    [STACK_SIZE              =>] static_integer_EXPRESSION
10726          --  | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
10727          --  | [TIME_SLICING_ENABLED    =>] static_boolean_EXPRESSION
10728
10729          when Pragma_Main => Main : declare
10730             Args  : Args_List (1 .. 3);
10731             Names : constant Name_List (1 .. 3) := (
10732                       Name_Stack_Size,
10733                       Name_Task_Stack_Size_Default,
10734                       Name_Time_Slicing_Enabled);
10735
10736             Nod : Node_Id;
10737
10738          begin
10739             GNAT_Pragma;
10740             Gather_Associations (Names, Args);
10741
10742             for J in 1 .. 2 loop
10743                if Present (Args (J)) then
10744                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10745                end if;
10746             end loop;
10747
10748             if Present (Args (3)) then
10749                Check_Arg_Is_Static_Expression (Args (3), Standard_Boolean);
10750             end if;
10751
10752             Nod := Next (N);
10753             while Present (Nod) loop
10754                if Nkind (Nod) = N_Pragma
10755                  and then Pragma_Name (Nod) = Name_Main
10756                then
10757                   Error_Msg_Name_1 := Pname;
10758                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10759                end if;
10760
10761                Next (Nod);
10762             end loop;
10763          end Main;
10764
10765          ------------------
10766          -- Main_Storage --
10767          ------------------
10768
10769          --  pragma Main_Storage
10770          --   (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
10771
10772          --  MAIN_STORAGE_OPTION ::=
10773          --    [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
10774          --  | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
10775
10776          when Pragma_Main_Storage => Main_Storage : declare
10777             Args  : Args_List (1 .. 2);
10778             Names : constant Name_List (1 .. 2) := (
10779                       Name_Working_Storage,
10780                       Name_Top_Guard);
10781
10782             Nod : Node_Id;
10783
10784          begin
10785             GNAT_Pragma;
10786             Gather_Associations (Names, Args);
10787
10788             for J in 1 .. 2 loop
10789                if Present (Args (J)) then
10790                   Check_Arg_Is_Static_Expression (Args (J), Any_Integer);
10791                end if;
10792             end loop;
10793
10794             Check_In_Main_Program;
10795
10796             Nod := Next (N);
10797             while Present (Nod) loop
10798                if Nkind (Nod) = N_Pragma
10799                  and then Pragma_Name (Nod) = Name_Main_Storage
10800                then
10801                   Error_Msg_Name_1 := Pname;
10802                   Error_Msg_N ("duplicate pragma% not permitted", Nod);
10803                end if;
10804
10805                Next (Nod);
10806             end loop;
10807          end Main_Storage;
10808
10809          -----------------
10810          -- Memory_Size --
10811          -----------------
10812
10813          --  pragma Memory_Size (NUMERIC_LITERAL)
10814
10815          when Pragma_Memory_Size =>
10816             GNAT_Pragma;
10817
10818             --  Memory size is simply ignored
10819
10820             Check_No_Identifiers;
10821             Check_Arg_Count (1);
10822             Check_Arg_Is_Integer_Literal (Arg1);
10823
10824          -------------
10825          -- No_Body --
10826          -------------
10827
10828          --  pragma No_Body;
10829
10830          --  The only correct use of this pragma is on its own in a file, in
10831          --  which case it is specially processed (see Gnat1drv.Check_Bad_Body
10832          --  and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
10833          --  check for a file containing nothing but a No_Body pragma). If we
10834          --  attempt to process it during normal semantics processing, it means
10835          --  it was misplaced.
10836
10837          when Pragma_No_Body =>
10838             GNAT_Pragma;
10839             Pragma_Misplaced;
10840
10841          ---------------
10842          -- No_Return --
10843          ---------------
10844
10845          --  pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
10846
10847          when Pragma_No_Return => No_Return : declare
10848             Id    : Node_Id;
10849             E     : Entity_Id;
10850             Found : Boolean;
10851             Arg   : Node_Id;
10852
10853          begin
10854             Ada_2005_Pragma;
10855             Check_At_Least_N_Arguments (1);
10856
10857             --  Loop through arguments of pragma
10858
10859             Arg := Arg1;
10860             while Present (Arg) loop
10861                Check_Arg_Is_Local_Name (Arg);
10862                Id := Get_Pragma_Arg (Arg);
10863                Analyze (Id);
10864
10865                if not Is_Entity_Name (Id) then
10866                   Error_Pragma_Arg ("entity name required", Arg);
10867                end if;
10868
10869                if Etype (Id) = Any_Type then
10870                   raise Pragma_Exit;
10871                end if;
10872
10873                --  Loop to find matching procedures
10874
10875                E := Entity (Id);
10876                Found := False;
10877                while Present (E)
10878                  and then Scope (E) = Current_Scope
10879                loop
10880                   if Ekind_In (E, E_Procedure, E_Generic_Procedure) then
10881                      Set_No_Return (E);
10882
10883                      --  Set flag on any alias as well
10884
10885                      if Is_Overloadable (E) and then Present (Alias (E)) then
10886                         Set_No_Return (Alias (E));
10887                      end if;
10888
10889                      Found := True;
10890                   end if;
10891
10892                   exit when From_Aspect_Specification (N);
10893                   E := Homonym (E);
10894                end loop;
10895
10896                if not Found then
10897                   Error_Pragma_Arg ("no procedure & found for pragma%", Arg);
10898                end if;
10899
10900                Next (Arg);
10901             end loop;
10902          end No_Return;
10903
10904          -----------------
10905          -- No_Run_Time --
10906          -----------------
10907
10908          --  pragma No_Run_Time;
10909
10910          --  Note: this pragma is retained for backwards compatibility. See
10911          --  body of Rtsfind for full details on its handling.
10912
10913          when Pragma_No_Run_Time =>
10914             GNAT_Pragma;
10915             Check_Valid_Configuration_Pragma;
10916             Check_Arg_Count (0);
10917
10918             No_Run_Time_Mode           := True;
10919             Configurable_Run_Time_Mode := True;
10920
10921             --  Set Duration to 32 bits if word size is 32
10922
10923             if Ttypes.System_Word_Size = 32 then
10924                Duration_32_Bits_On_Target := True;
10925             end if;
10926
10927             --  Set appropriate restrictions
10928
10929             Set_Restriction (No_Finalization, N);
10930             Set_Restriction (No_Exception_Handlers, N);
10931             Set_Restriction (Max_Tasks, N, 0);
10932             Set_Restriction (No_Tasking, N);
10933
10934          ------------------------
10935          -- No_Strict_Aliasing --
10936          ------------------------
10937
10938          --  pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
10939
10940          when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare
10941             E_Id : Entity_Id;
10942
10943          begin
10944             GNAT_Pragma;
10945             Check_At_Most_N_Arguments (1);
10946
10947             if Arg_Count = 0 then
10948                Check_Valid_Configuration_Pragma;
10949                Opt.No_Strict_Aliasing := True;
10950
10951             else
10952                Check_Optional_Identifier (Arg2, Name_Entity);
10953                Check_Arg_Is_Local_Name (Arg1);
10954                E_Id := Entity (Get_Pragma_Arg (Arg1));
10955
10956                if E_Id = Any_Type then
10957                   return;
10958                elsif No (E_Id) or else not Is_Access_Type (E_Id) then
10959                   Error_Pragma_Arg ("pragma% requires access type", Arg1);
10960                end if;
10961
10962                Set_No_Strict_Aliasing (Implementation_Base_Type (E_Id));
10963             end if;
10964          end No_Strict_Aliasing;
10965
10966          -----------------------
10967          -- Normalize_Scalars --
10968          -----------------------
10969
10970          --  pragma Normalize_Scalars;
10971
10972          when Pragma_Normalize_Scalars =>
10973             Check_Ada_83_Warning;
10974             Check_Arg_Count (0);
10975             Check_Valid_Configuration_Pragma;
10976
10977             --  Normalize_Scalars creates false positives in CodePeer, and
10978             --  incorrect negative results in Alfa mode, so ignore this pragma
10979             --  in these modes.
10980
10981             if not (CodePeer_Mode or Alfa_Mode) then
10982                Normalize_Scalars := True;
10983                Init_Or_Norm_Scalars := True;
10984             end if;
10985
10986          -----------------
10987          -- Obsolescent --
10988          -----------------
10989
10990          --  pragma Obsolescent;
10991
10992          --  pragma Obsolescent (
10993          --    [Message =>] static_string_EXPRESSION
10994          --  [,[Version =>] Ada_05]]);
10995
10996          --  pragma Obsolescent (
10997          --    [Entity  =>] NAME
10998          --  [,[Message =>] static_string_EXPRESSION
10999          --  [,[Version =>] Ada_05]] );
11000
11001          when Pragma_Obsolescent => Obsolescent : declare
11002             Ename : Node_Id;
11003             Decl  : Node_Id;
11004
11005             procedure Set_Obsolescent (E : Entity_Id);
11006             --  Given an entity Ent, mark it as obsolescent if appropriate
11007
11008             ---------------------
11009             -- Set_Obsolescent --
11010             ---------------------
11011
11012             procedure Set_Obsolescent (E : Entity_Id) is
11013                Active : Boolean;
11014                Ent    : Entity_Id;
11015                S      : String_Id;
11016
11017             begin
11018                Active := True;
11019                Ent    := E;
11020
11021                --  Entity name was given
11022
11023                if Present (Ename) then
11024
11025                   --  If entity name matches, we are fine. Save entity in
11026                   --  pragma argument, for ASIS use.
11027
11028                   if Chars (Ename) = Chars (Ent) then
11029                      Set_Entity (Ename, Ent);
11030                      Generate_Reference (Ent, Ename);
11031
11032                   --  If entity name does not match, only possibility is an
11033                   --  enumeration literal from an enumeration type declaration.
11034
11035                   elsif Ekind (Ent) /= E_Enumeration_Type then
11036                      Error_Pragma
11037                        ("pragma % entity name does not match declaration");
11038
11039                   else
11040                      Ent := First_Literal (E);
11041                      loop
11042                         if No (Ent) then
11043                            Error_Pragma
11044                              ("pragma % entity name does not match any " &
11045                               "enumeration literal");
11046
11047                         elsif Chars (Ent) = Chars (Ename) then
11048                            Set_Entity (Ename, Ent);
11049                            Generate_Reference (Ent, Ename);
11050                            exit;
11051
11052                         else
11053                            Ent := Next_Literal (Ent);
11054                         end if;
11055                      end loop;
11056                   end if;
11057                end if;
11058
11059                --  Ent points to entity to be marked
11060
11061                if Arg_Count >= 1 then
11062
11063                   --  Deal with static string argument
11064
11065                   Check_Arg_Is_Static_Expression (Arg1, Standard_String);
11066                   S := Strval (Get_Pragma_Arg (Arg1));
11067
11068                   for J in 1 .. String_Length (S) loop
11069                      if not In_Character_Range (Get_String_Char (S, J)) then
11070                         Error_Pragma_Arg
11071                           ("pragma% argument does not allow wide characters",
11072                            Arg1);
11073                      end if;
11074                   end loop;
11075
11076                   Obsolescent_Warnings.Append
11077                     ((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1))));
11078
11079                   --  Check for Ada_05 parameter
11080
11081                   if Arg_Count /= 1 then
11082                      Check_Arg_Count (2);
11083
11084                      declare
11085                         Argx : constant Node_Id := Get_Pragma_Arg (Arg2);
11086
11087                      begin
11088                         Check_Arg_Is_Identifier (Argx);
11089
11090                         if Chars (Argx) /= Name_Ada_05 then
11091                            Error_Msg_Name_2 := Name_Ada_05;
11092                            Error_Pragma_Arg
11093                              ("only allowed argument for pragma% is %", Argx);
11094                         end if;
11095
11096                         if Ada_Version_Explicit < Ada_2005
11097                           or else not Warn_On_Ada_2005_Compatibility
11098                         then
11099                            Active := False;
11100                         end if;
11101                      end;
11102                   end if;
11103                end if;
11104
11105                --  Set flag if pragma active
11106
11107                if Active then
11108                   Set_Is_Obsolescent (Ent);
11109                end if;
11110
11111                return;
11112             end Set_Obsolescent;
11113
11114          --  Start of processing for pragma Obsolescent
11115
11116          begin
11117             GNAT_Pragma;
11118
11119             Check_At_Most_N_Arguments (3);
11120
11121             --  See if first argument specifies an entity name
11122
11123             if Arg_Count >= 1
11124               and then
11125                 (Chars (Arg1) = Name_Entity
11126                    or else
11127                      Nkind_In (Get_Pragma_Arg (Arg1), N_Character_Literal,
11128                                                       N_Identifier,
11129                                                       N_Operator_Symbol))
11130             then
11131                Ename := Get_Pragma_Arg (Arg1);
11132
11133                --  Eliminate first argument, so we can share processing
11134
11135                Arg1 := Arg2;
11136                Arg2 := Arg3;
11137                Arg_Count := Arg_Count - 1;
11138
11139             --  No Entity name argument given
11140
11141             else
11142                Ename := Empty;
11143             end if;
11144
11145             if Arg_Count >= 1 then
11146                Check_Optional_Identifier (Arg1, Name_Message);
11147
11148                if Arg_Count = 2 then
11149                   Check_Optional_Identifier (Arg2, Name_Version);
11150                end if;
11151             end if;
11152
11153             --  Get immediately preceding declaration
11154
11155             Decl := Prev (N);
11156             while Present (Decl) and then Nkind (Decl) = N_Pragma loop
11157                Prev (Decl);
11158             end loop;
11159
11160             --  Cases where we do not follow anything other than another pragma
11161
11162             if No (Decl) then
11163
11164                --  First case: library level compilation unit declaration with
11165                --  the pragma immediately following the declaration.
11166
11167                if Nkind (Parent (N)) = N_Compilation_Unit_Aux then
11168                   Set_Obsolescent
11169                     (Defining_Entity (Unit (Parent (Parent (N)))));
11170                   return;
11171
11172                --  Case 2: library unit placement for package
11173
11174                else
11175                   declare
11176                      Ent : constant Entity_Id := Find_Lib_Unit_Name;
11177                   begin
11178                      if Is_Package_Or_Generic_Package (Ent) then
11179                         Set_Obsolescent (Ent);
11180                         return;
11181                      end if;
11182                   end;
11183                end if;
11184
11185             --  Cases where we must follow a declaration
11186
11187             else
11188                if         Nkind (Decl) not in N_Declaration
11189                  and then Nkind (Decl) not in N_Later_Decl_Item
11190                  and then Nkind (Decl) not in N_Generic_Declaration
11191                  and then Nkind (Decl) not in N_Renaming_Declaration
11192                then
11193                   Error_Pragma
11194                     ("pragma% misplaced, "
11195                      & "must immediately follow a declaration");
11196
11197                else
11198                   Set_Obsolescent (Defining_Entity (Decl));
11199                   return;
11200                end if;
11201             end if;
11202          end Obsolescent;
11203
11204          --------------
11205          -- Optimize --
11206          --------------
11207
11208          --  pragma Optimize (Time | Space | Off);
11209
11210          --  The actual check for optimize is done in Gigi. Note that this
11211          --  pragma does not actually change the optimization setting, it
11212          --  simply checks that it is consistent with the pragma.
11213
11214          when Pragma_Optimize =>
11215             Check_No_Identifiers;
11216             Check_Arg_Count (1);
11217             Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off);
11218
11219          ------------------------
11220          -- Optimize_Alignment --
11221          ------------------------
11222
11223          --  pragma Optimize_Alignment (Time | Space | Off);
11224
11225          when Pragma_Optimize_Alignment => Optimize_Alignment : begin
11226             GNAT_Pragma;
11227             Check_No_Identifiers;
11228             Check_Arg_Count (1);
11229             Check_Valid_Configuration_Pragma;
11230
11231             declare
11232                Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1));
11233             begin
11234                case Nam is
11235                   when Name_Time =>
11236                      Opt.Optimize_Alignment := 'T';
11237                   when Name_Space =>
11238                      Opt.Optimize_Alignment := 'S';
11239                   when Name_Off =>
11240                      Opt.Optimize_Alignment := 'O';
11241                   when others =>
11242                      Error_Pragma_Arg ("invalid argument for pragma%", Arg1);
11243                end case;
11244             end;
11245
11246             --  Set indication that mode is set locally. If we are in fact in a
11247             --  configuration pragma file, this setting is harmless since the
11248             --  switch will get reset anyway at the start of each unit.
11249
11250             Optimize_Alignment_Local := True;
11251          end Optimize_Alignment;
11252
11253          -------------
11254          -- Ordered --
11255          -------------
11256
11257          --  pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
11258
11259          when Pragma_Ordered => Ordered : declare
11260             Assoc   : constant Node_Id := Arg1;
11261             Type_Id : Node_Id;
11262             Typ     : Entity_Id;
11263
11264          begin
11265             GNAT_Pragma;
11266             Check_No_Identifiers;
11267             Check_Arg_Count (1);
11268             Check_Arg_Is_Local_Name (Arg1);
11269
11270             Type_Id := Get_Pragma_Arg (Assoc);
11271             Find_Type (Type_Id);
11272             Typ := Entity (Type_Id);
11273
11274             if Typ = Any_Type then
11275                return;
11276             else
11277                Typ := Underlying_Type (Typ);
11278             end if;
11279
11280             if not Is_Enumeration_Type (Typ) then
11281                Error_Pragma ("pragma% must specify enumeration type");
11282             end if;
11283
11284             Check_First_Subtype (Arg1);
11285             Set_Has_Pragma_Ordered (Base_Type (Typ));
11286          end Ordered;
11287
11288          ----------
11289          -- Pack --
11290          ----------
11291
11292          --  pragma Pack (first_subtype_LOCAL_NAME);
11293
11294          when Pragma_Pack => Pack : declare
11295             Assoc   : constant Node_Id := Arg1;
11296             Type_Id : Node_Id;
11297             Typ     : Entity_Id;
11298             Ctyp    : Entity_Id;
11299             Ignore  : Boolean := False;
11300
11301          begin
11302             Check_No_Identifiers;
11303             Check_Arg_Count (1);
11304             Check_Arg_Is_Local_Name (Arg1);
11305
11306             Type_Id := Get_Pragma_Arg (Assoc);
11307             Find_Type (Type_Id);
11308             Typ := Entity (Type_Id);
11309
11310             if Typ = Any_Type
11311               or else Rep_Item_Too_Early (Typ, N)
11312             then
11313                return;
11314             else
11315                Typ := Underlying_Type (Typ);
11316             end if;
11317
11318             if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then
11319                Error_Pragma ("pragma% must specify array or record type");
11320             end if;
11321
11322             Check_First_Subtype (Arg1);
11323             Check_Duplicate_Pragma (Typ);
11324
11325             --  Array type
11326
11327             if Is_Array_Type (Typ) then
11328                Ctyp := Component_Type (Typ);
11329
11330                --  Ignore pack that does nothing
11331
11332                if Known_Static_Esize (Ctyp)
11333                  and then Known_Static_RM_Size (Ctyp)
11334                  and then Esize (Ctyp) = RM_Size (Ctyp)
11335                  and then Addressable (Esize (Ctyp))
11336                then
11337                   Ignore := True;
11338                end if;
11339
11340                --  Process OK pragma Pack. Note that if there is a separate
11341                --  component clause present, the Pack will be cancelled. This
11342                --  processing is in Freeze.
11343
11344                if not Rep_Item_Too_Late (Typ, N) then
11345
11346                   --  In the context of static code analysis, we do not need
11347                   --  complex front-end expansions related to pragma Pack,
11348                   --  so disable handling of pragma Pack in these cases.
11349
11350                   if CodePeer_Mode or Alfa_Mode then
11351                      null;
11352
11353                   --  Don't attempt any packing for VM targets. We possibly
11354                   --  could deal with some cases of array bit-packing, but we
11355                   --  don't bother, since this is not a typical kind of
11356                   --  representation in the VM context anyway (and would not
11357                   --  for example work nicely with the debugger).
11358
11359                   elsif VM_Target /= No_VM then
11360                      if not GNAT_Mode then
11361                         Error_Pragma
11362                           ("?pragma% ignored in this configuration");
11363                      end if;
11364
11365                   --  Normal case where we do the pack action
11366
11367                   else
11368                      if not Ignore then
11369                         Set_Is_Packed            (Base_Type (Typ));
11370                         Set_Has_Non_Standard_Rep (Base_Type (Typ));
11371                      end if;
11372
11373                      Set_Has_Pragma_Pack (Base_Type (Typ));
11374                   end if;
11375                end if;
11376
11377             --  For record types, the pack is always effective
11378
11379             else pragma Assert (Is_Record_Type (Typ));
11380                if not Rep_Item_Too_Late (Typ, N) then
11381
11382                   --  Ignore pack request with warning in VM mode (skip warning
11383                   --  if we are compiling GNAT run time library).
11384
11385                   if VM_Target /= No_VM then
11386                      if not GNAT_Mode then
11387                         Error_Pragma
11388                           ("?pragma% ignored in this configuration");
11389                      end if;
11390
11391                   --  Normal case of pack request active
11392
11393                   else
11394                      Set_Is_Packed            (Base_Type (Typ));
11395                      Set_Has_Pragma_Pack      (Base_Type (Typ));
11396                      Set_Has_Non_Standard_Rep (Base_Type (Typ));
11397                   end if;
11398                end if;
11399             end if;
11400          end Pack;
11401
11402          ----------
11403          -- Page --
11404          ----------
11405
11406          --  pragma Page;
11407
11408          --  There is nothing to do here, since we did all the processing for
11409          --  this pragma in Par.Prag (so that it works properly even in syntax
11410          --  only mode).
11411
11412          when Pragma_Page =>
11413             null;
11414
11415          -------------
11416          -- Passive --
11417          -------------
11418
11419          --  pragma Passive [(PASSIVE_FORM)];
11420
11421          --  PASSIVE_FORM ::= Semaphore | No
11422
11423          when Pragma_Passive =>
11424             GNAT_Pragma;
11425
11426             if Nkind (Parent (N)) /= N_Task_Definition then
11427                Error_Pragma ("pragma% must be within task definition");
11428             end if;
11429
11430             if Arg_Count /= 0 then
11431                Check_Arg_Count (1);
11432                Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No);
11433             end if;
11434
11435          ----------------------------------
11436          -- Preelaborable_Initialization --
11437          ----------------------------------
11438
11439          --  pragma Preelaborable_Initialization (DIRECT_NAME);
11440
11441          when Pragma_Preelaborable_Initialization => Preelab_Init : declare
11442             Ent : Entity_Id;
11443
11444          begin
11445             Ada_2005_Pragma;
11446             Check_Arg_Count (1);
11447             Check_No_Identifiers;
11448             Check_Arg_Is_Identifier (Arg1);
11449             Check_Arg_Is_Local_Name (Arg1);
11450             Check_First_Subtype (Arg1);
11451             Ent := Entity (Get_Pragma_Arg (Arg1));
11452
11453             if not (Is_Private_Type (Ent)
11454                       or else
11455                     Is_Protected_Type (Ent)
11456                       or else
11457                     (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)))
11458             then
11459                Error_Pragma_Arg
11460                  ("pragma % can only be applied to private, formal derived or "
11461                   & "protected type",
11462                   Arg1);
11463             end if;
11464
11465             --  Give an error if the pragma is applied to a protected type that
11466             --  does not qualify (due to having entries, or due to components
11467             --  that do not qualify).
11468
11469             if Is_Protected_Type (Ent)
11470               and then not Has_Preelaborable_Initialization (Ent)
11471             then
11472                Error_Msg_N
11473                  ("protected type & does not have preelaborable " &
11474                   "initialization", Ent);
11475
11476             --  Otherwise mark the type as definitely having preelaborable
11477             --  initialization.
11478
11479             else
11480                Set_Known_To_Have_Preelab_Init (Ent);
11481             end if;
11482
11483             if Has_Pragma_Preelab_Init (Ent)
11484               and then Warn_On_Redundant_Constructs
11485             then
11486                Error_Pragma ("?duplicate pragma%!");
11487             else
11488                Set_Has_Pragma_Preelab_Init (Ent);
11489             end if;
11490          end Preelab_Init;
11491
11492          --------------------
11493          -- Persistent_BSS --
11494          --------------------
11495
11496          --  pragma Persistent_BSS [(object_NAME)];
11497
11498          when Pragma_Persistent_BSS => Persistent_BSS :  declare
11499             Decl : Node_Id;
11500             Ent  : Entity_Id;
11501             Prag : Node_Id;
11502
11503          begin
11504             GNAT_Pragma;
11505             Check_At_Most_N_Arguments (1);
11506
11507             --  Case of application to specific object (one argument)
11508
11509             if Arg_Count = 1 then
11510                Check_Arg_Is_Library_Level_Local_Name (Arg1);
11511
11512                if not Is_Entity_Name (Get_Pragma_Arg (Arg1))
11513                  or else not
11514                   Ekind_In (Entity (Get_Pragma_Arg (Arg1)), E_Variable,
11515                                                             E_Constant)
11516                then
11517                   Error_Pragma_Arg ("pragma% only applies to objects", Arg1);
11518                end if;
11519
11520                Ent := Entity (Get_Pragma_Arg (Arg1));
11521                Decl := Parent (Ent);
11522
11523                if Rep_Item_Too_Late (Ent, N) then
11524                   return;
11525                end if;
11526
11527                if Present (Expression (Decl)) then
11528                   Error_Pragma_Arg
11529                     ("object for pragma% cannot have initialization", Arg1);
11530                end if;
11531
11532                if not Is_Potentially_Persistent_Type (Etype (Ent)) then
11533                   Error_Pragma_Arg
11534                     ("object type for pragma% is not potentially persistent",
11535                      Arg1);
11536                end if;
11537
11538                Check_Duplicate_Pragma (Ent);
11539
11540                Prag :=
11541                  Make_Linker_Section_Pragma
11542                    (Ent, Sloc (N), ".persistent.bss");
11543                Insert_After (N, Prag);
11544                Analyze (Prag);
11545
11546             --  Case of use as configuration pragma with no arguments
11547
11548             else
11549                Check_Valid_Configuration_Pragma;
11550                Persistent_BSS_Mode := True;
11551             end if;
11552          end Persistent_BSS;
11553
11554          -------------
11555          -- Polling --
11556          -------------
11557
11558          --  pragma Polling (ON | OFF);
11559
11560          when Pragma_Polling =>
11561             GNAT_Pragma;
11562             Check_Arg_Count (1);
11563             Check_No_Identifiers;
11564             Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
11565             Polling_Required := (Chars (Get_Pragma_Arg (Arg1)) = Name_On);
11566
11567          -------------------
11568          -- Postcondition --
11569          -------------------
11570
11571          --  pragma Postcondition ([Check   =>] Boolean_EXPRESSION
11572          --                      [,[Message =>] String_EXPRESSION]);
11573
11574          when Pragma_Postcondition => Postcondition : declare
11575             In_Body : Boolean;
11576             pragma Warnings (Off, In_Body);
11577
11578          begin
11579             GNAT_Pragma;
11580             Check_At_Least_N_Arguments (1);
11581             Check_At_Most_N_Arguments (2);
11582             Check_Optional_Identifier (Arg1, Name_Check);
11583
11584             --  All we need to do here is call the common check procedure,
11585             --  the remainder of the processing is found in Sem_Ch6/Sem_Ch7.
11586
11587             Check_Precondition_Postcondition (In_Body);
11588          end Postcondition;
11589
11590          ------------------
11591          -- Precondition --
11592          ------------------
11593
11594          --  pragma Precondition ([Check   =>] Boolean_EXPRESSION
11595          --                     [,[Message =>] String_EXPRESSION]);
11596
11597          when Pragma_Precondition => Precondition : declare
11598             In_Body : Boolean;
11599
11600          begin
11601             GNAT_Pragma;
11602             Check_At_Least_N_Arguments (1);
11603             Check_At_Most_N_Arguments (2);
11604             Check_Optional_Identifier (Arg1, Name_Check);
11605             Check_Precondition_Postcondition (In_Body);
11606
11607             --  If in spec, nothing more to do. If in body, then we convert the
11608             --  pragma to pragma Check (Precondition, cond [, msg]). Note we do
11609             --  this whether or not precondition checks are enabled. That works
11610             --  fine since pragma Check will do this check, and will also
11611             --  analyze the condition itself in the proper context.
11612
11613             if In_Body then
11614                Rewrite (N,
11615                  Make_Pragma (Loc,
11616                    Chars => Name_Check,
11617                    Pragma_Argument_Associations => New_List (
11618                      Make_Pragma_Argument_Association (Loc,
11619                        Expression => Make_Identifier (Loc, Name_Precondition)),
11620
11621                      Make_Pragma_Argument_Association (Sloc (Arg1),
11622                        Expression => Relocate_Node (Get_Pragma_Arg (Arg1))))));
11623
11624                if Arg_Count = 2 then
11625                   Append_To (Pragma_Argument_Associations (N),
11626                     Make_Pragma_Argument_Association (Sloc (Arg2),
11627                       Expression => Relocate_Node (Get_Pragma_Arg (Arg2))));
11628                end if;
11629
11630                Analyze (N);
11631             end if;
11632          end Precondition;
11633
11634          ---------------
11635          -- Predicate --
11636          ---------------
11637
11638          --  pragma Predicate
11639          --    ([Entity =>] type_LOCAL_NAME,
11640          --     [Check  =>] EXPRESSION);
11641
11642          when Pragma_Predicate => Predicate : declare
11643             Type_Id : Node_Id;
11644             Typ     : Entity_Id;
11645
11646             Discard : Boolean;
11647             pragma Unreferenced (Discard);
11648
11649          begin
11650             GNAT_Pragma;
11651             Check_Arg_Count (2);
11652             Check_Optional_Identifier (Arg1, Name_Entity);
11653             Check_Optional_Identifier (Arg2, Name_Check);
11654
11655             Check_Arg_Is_Local_Name (Arg1);
11656
11657             Type_Id := Get_Pragma_Arg (Arg1);
11658             Find_Type (Type_Id);
11659             Typ := Entity (Type_Id);
11660
11661             if Typ = Any_Type then
11662                return;
11663             end if;
11664
11665             --  The remaining processing is simply to link the pragma on to
11666             --  the rep item chain, for processing when the type is frozen.
11667             --  This is accomplished by a call to Rep_Item_Too_Late. We also
11668             --  mark the type as having predicates.
11669
11670             Set_Has_Predicates (Typ);
11671             Discard := Rep_Item_Too_Late (Typ, N, FOnly => True);
11672          end Predicate;
11673
11674          ------------------
11675          -- Preelaborate --
11676          ------------------
11677
11678          --  pragma Preelaborate [(library_unit_NAME)];
11679
11680          --  Set the flag Is_Preelaborated of program unit name entity
11681
11682          when Pragma_Preelaborate => Preelaborate : declare
11683             Pa  : constant Node_Id   := Parent (N);
11684             Pk  : constant Node_Kind := Nkind (Pa);
11685             Ent : Entity_Id;
11686
11687          begin
11688             Check_Ada_83_Warning;
11689             Check_Valid_Library_Unit_Pragma;
11690
11691             if Nkind (N) = N_Null_Statement then
11692                return;
11693             end if;
11694
11695             Ent := Find_Lib_Unit_Name;
11696             Check_Duplicate_Pragma (Ent);
11697
11698             --  This filters out pragmas inside generic parent then
11699             --  show up inside instantiation
11700
11701             if Present (Ent)
11702               and then not (Pk = N_Package_Specification
11703                              and then Present (Generic_Parent (Pa)))
11704             then
11705                if not Debug_Flag_U then
11706                   Set_Is_Preelaborated (Ent);
11707                   Set_Suppress_Elaboration_Warnings (Ent);
11708                end if;
11709             end if;
11710          end Preelaborate;
11711
11712          ---------------------
11713          -- Preelaborate_05 --
11714          ---------------------
11715
11716          --  pragma Preelaborate_05 [(library_unit_NAME)];
11717
11718          --  This pragma is useable only in GNAT_Mode, where it is used like
11719          --  pragma Preelaborate but it is only effective in Ada 2005 mode
11720          --  (otherwise it is ignored). This is used to implement AI-362 which
11721          --  recategorizes some run-time packages in Ada 2005 mode.
11722
11723          when Pragma_Preelaborate_05 => Preelaborate_05 : declare
11724             Ent : Entity_Id;
11725
11726          begin
11727             GNAT_Pragma;
11728             Check_Valid_Library_Unit_Pragma;
11729
11730             if not GNAT_Mode then
11731                Error_Pragma ("pragma% only available in GNAT mode");
11732             end if;
11733
11734             if Nkind (N) = N_Null_Statement then
11735                return;
11736             end if;
11737
11738             --  This is one of the few cases where we need to test the value of
11739             --  Ada_Version_Explicit rather than Ada_Version (which is always
11740             --  set to Ada_2012 in a predefined unit), we need to know the
11741             --  explicit version set to know if this pragma is active.
11742
11743             if Ada_Version_Explicit >= Ada_2005 then
11744                Ent := Find_Lib_Unit_Name;
11745                Set_Is_Preelaborated (Ent);
11746                Set_Suppress_Elaboration_Warnings (Ent);
11747             end if;
11748          end Preelaborate_05;
11749
11750          --------------
11751          -- Priority --
11752          --------------
11753
11754          --  pragma Priority (EXPRESSION);
11755
11756          when Pragma_Priority => Priority : declare
11757             P   : constant Node_Id := Parent (N);
11758             Arg : Node_Id;
11759
11760          begin
11761             Check_No_Identifiers;
11762             Check_Arg_Count (1);
11763
11764             --  Subprogram case
11765
11766             if Nkind (P) = N_Subprogram_Body then
11767                Check_In_Main_Program;
11768
11769                Arg := Get_Pragma_Arg (Arg1);
11770                Analyze_And_Resolve (Arg, Standard_Integer);
11771
11772                --  Must be static
11773
11774                if not Is_Static_Expression (Arg) then
11775                   Flag_Non_Static_Expr
11776                     ("main subprogram priority is not static!", Arg);
11777                   raise Pragma_Exit;
11778
11779                --  If constraint error, then we already signalled an error
11780
11781                elsif Raises_Constraint_Error (Arg) then
11782                   null;
11783
11784                --  Otherwise check in range
11785
11786                else
11787                   declare
11788                      Val : constant Uint := Expr_Value (Arg);
11789
11790                   begin
11791                      if Val < 0
11792                        or else Val > Expr_Value (Expression
11793                                        (Parent (RTE (RE_Max_Priority))))
11794                      then
11795                         Error_Pragma_Arg
11796                           ("main subprogram priority is out of range", Arg1);
11797                      end if;
11798                   end;
11799                end if;
11800
11801                Set_Main_Priority
11802                     (Current_Sem_Unit, UI_To_Int (Expr_Value (Arg)));
11803
11804                --  Load an arbitrary entity from System.Tasking to make sure
11805                --  this package is implicitly with'ed, since we need to have
11806                --  the tasking run-time active for the pragma Priority to have
11807                --  any effect.
11808
11809                declare
11810                   Discard : Entity_Id;
11811                   pragma Warnings (Off, Discard);
11812                begin
11813                   Discard := RTE (RE_Task_List);
11814                end;
11815
11816             --  Task or Protected, must be of type Integer
11817
11818             elsif Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11819                Arg := Get_Pragma_Arg (Arg1);
11820
11821                --  The expression must be analyzed in the special manner
11822                --  described in "Handling of Default and Per-Object
11823                --  Expressions" in sem.ads.
11824
11825                Preanalyze_Spec_Expression (Arg, Standard_Integer);
11826
11827                if not Is_Static_Expression (Arg) then
11828                   Check_Restriction (Static_Priorities, Arg);
11829                end if;
11830
11831             --  Anything else is incorrect
11832
11833             else
11834                Pragma_Misplaced;
11835             end if;
11836
11837             if Has_Pragma_Priority (P) then
11838                Error_Pragma ("duplicate pragma% not allowed");
11839             else
11840                Set_Has_Pragma_Priority (P, True);
11841
11842                if Nkind_In (P, N_Protected_Definition, N_Task_Definition) then
11843                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
11844                   --  exp_ch9 should use this ???
11845                end if;
11846             end if;
11847          end Priority;
11848
11849          -----------------------------------
11850          -- Priority_Specific_Dispatching --
11851          -----------------------------------
11852
11853          --  pragma Priority_Specific_Dispatching (
11854          --    policy_IDENTIFIER,
11855          --    first_priority_EXPRESSION,
11856          --    last_priority_EXPRESSION);
11857
11858          when Pragma_Priority_Specific_Dispatching =>
11859          Priority_Specific_Dispatching : declare
11860             Prio_Id : constant Entity_Id := RTE (RE_Any_Priority);
11861             --  This is the entity System.Any_Priority;
11862
11863             DP          : Character;
11864             Lower_Bound : Node_Id;
11865             Upper_Bound : Node_Id;
11866             Lower_Val   : Uint;
11867             Upper_Val   : Uint;
11868
11869          begin
11870             Ada_2005_Pragma;
11871             Check_Arg_Count (3);
11872             Check_No_Identifiers;
11873             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
11874             Check_Valid_Configuration_Pragma;
11875             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
11876             DP := Fold_Upper (Name_Buffer (1));
11877
11878             Lower_Bound := Get_Pragma_Arg (Arg2);
11879             Check_Arg_Is_Static_Expression (Lower_Bound, Standard_Integer);
11880             Lower_Val := Expr_Value (Lower_Bound);
11881
11882             Upper_Bound := Get_Pragma_Arg (Arg3);
11883             Check_Arg_Is_Static_Expression (Upper_Bound, Standard_Integer);
11884             Upper_Val := Expr_Value (Upper_Bound);
11885
11886             --  It is not allowed to use Task_Dispatching_Policy and
11887             --  Priority_Specific_Dispatching in the same partition.
11888
11889             if Task_Dispatching_Policy /= ' ' then
11890                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11891                Error_Pragma
11892                  ("pragma% incompatible with Task_Dispatching_Policy#");
11893
11894             --  Check lower bound in range
11895
11896             elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11897                     or else
11898                   Lower_Val > Expr_Value (Type_High_Bound (Prio_Id))
11899             then
11900                Error_Pragma_Arg
11901                  ("first_priority is out of range", Arg2);
11902
11903             --  Check upper bound in range
11904
11905             elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id))
11906                     or else
11907                   Upper_Val > Expr_Value (Type_High_Bound (Prio_Id))
11908             then
11909                Error_Pragma_Arg
11910                  ("last_priority is out of range", Arg3);
11911
11912             --  Check that the priority range is valid
11913
11914             elsif Lower_Val > Upper_Val then
11915                Error_Pragma
11916                  ("last_priority_expression must be greater than" &
11917                   " or equal to first_priority_expression");
11918
11919             --  Store the new policy, but always preserve System_Location since
11920             --  we like the error message with the run-time name.
11921
11922             else
11923                --  Check overlapping in the priority ranges specified in other
11924                --  Priority_Specific_Dispatching pragmas within the same
11925                --  partition. We can only check those we know about!
11926
11927                for J in
11928                   Specific_Dispatching.First .. Specific_Dispatching.Last
11929                loop
11930                   if Specific_Dispatching.Table (J).First_Priority in
11931                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11932                   or else Specific_Dispatching.Table (J).Last_Priority in
11933                     UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val)
11934                   then
11935                      Error_Msg_Sloc :=
11936                        Specific_Dispatching.Table (J).Pragma_Loc;
11937                         Error_Pragma
11938                           ("priority range overlaps with "
11939                            & "Priority_Specific_Dispatching#");
11940                   end if;
11941                end loop;
11942
11943                --  The use of Priority_Specific_Dispatching is incompatible
11944                --  with Task_Dispatching_Policy.
11945
11946                if Task_Dispatching_Policy /= ' ' then
11947                   Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
11948                      Error_Pragma
11949                        ("Priority_Specific_Dispatching incompatible "
11950                         & "with Task_Dispatching_Policy#");
11951                end if;
11952
11953                --  The use of Priority_Specific_Dispatching forces ceiling
11954                --  locking policy.
11955
11956                if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then
11957                   Error_Msg_Sloc := Locking_Policy_Sloc;
11958                      Error_Pragma
11959                        ("Priority_Specific_Dispatching incompatible "
11960                         & "with Locking_Policy#");
11961
11962                --  Set the Ceiling_Locking policy, but preserve System_Location
11963                --  since we like the error message with the run time name.
11964
11965                else
11966                   Locking_Policy := 'C';
11967
11968                   if Locking_Policy_Sloc /= System_Location then
11969                      Locking_Policy_Sloc := Loc;
11970                   end if;
11971                end if;
11972
11973                --  Add entry in the table
11974
11975                Specific_Dispatching.Append
11976                     ((Dispatching_Policy => DP,
11977                       First_Priority     => UI_To_Int (Lower_Val),
11978                       Last_Priority      => UI_To_Int (Upper_Val),
11979                       Pragma_Loc         => Loc));
11980             end if;
11981          end Priority_Specific_Dispatching;
11982
11983          -------------
11984          -- Profile --
11985          -------------
11986
11987          --  pragma Profile (profile_IDENTIFIER);
11988
11989          --  profile_IDENTIFIER => Restricted | Ravenscar
11990
11991          when Pragma_Profile =>
11992             Ada_2005_Pragma;
11993             Check_Arg_Count (1);
11994             Check_Valid_Configuration_Pragma;
11995             Check_No_Identifiers;
11996
11997             declare
11998                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
11999             begin
12000                if Chars (Argx) = Name_Ravenscar then
12001                   Set_Ravenscar_Profile (N);
12002                elsif Chars (Argx) = Name_Restricted then
12003                   Set_Profile_Restrictions
12004                     (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12005                else
12006                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12007                end if;
12008             end;
12009
12010          ----------------------
12011          -- Profile_Warnings --
12012          ----------------------
12013
12014          --  pragma Profile_Warnings (profile_IDENTIFIER);
12015
12016          --  profile_IDENTIFIER => Restricted | Ravenscar
12017
12018          when Pragma_Profile_Warnings =>
12019             GNAT_Pragma;
12020             Check_Arg_Count (1);
12021             Check_Valid_Configuration_Pragma;
12022             Check_No_Identifiers;
12023
12024             declare
12025                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
12026             begin
12027                if Chars (Argx) = Name_Ravenscar then
12028                   Set_Profile_Restrictions (Ravenscar, N, Warn => True);
12029                elsif Chars (Argx) = Name_Restricted then
12030                   Set_Profile_Restrictions (Restricted, N, Warn => True);
12031                else
12032                   Error_Pragma_Arg ("& is not a valid profile", Argx);
12033                end if;
12034             end;
12035
12036          --------------------------
12037          -- Propagate_Exceptions --
12038          --------------------------
12039
12040          --  pragma Propagate_Exceptions;
12041
12042          --  Note: this pragma is obsolete and has no effect
12043
12044          when Pragma_Propagate_Exceptions =>
12045             GNAT_Pragma;
12046             Check_Arg_Count (0);
12047
12048             if In_Extended_Main_Source_Unit (N) then
12049                Propagate_Exceptions := True;
12050             end if;
12051
12052          ------------------
12053          -- Psect_Object --
12054          ------------------
12055
12056          --  pragma Psect_Object (
12057          --        [Internal =>] LOCAL_NAME,
12058          --     [, [External =>] EXTERNAL_SYMBOL]
12059          --     [, [Size     =>] EXTERNAL_SYMBOL]);
12060
12061          when Pragma_Psect_Object | Pragma_Common_Object =>
12062          Psect_Object : declare
12063             Args  : Args_List (1 .. 3);
12064             Names : constant Name_List (1 .. 3) := (
12065                       Name_Internal,
12066                       Name_External,
12067                       Name_Size);
12068
12069             Internal : Node_Id renames Args (1);
12070             External : Node_Id renames Args (2);
12071             Size     : Node_Id renames Args (3);
12072
12073             Def_Id : Entity_Id;
12074
12075             procedure Check_Too_Long (Arg : Node_Id);
12076             --  Posts message if the argument is an identifier with more
12077             --  than 31 characters, or a string literal with more than
12078             --  31 characters, and we are operating under VMS
12079
12080             --------------------
12081             -- Check_Too_Long --
12082             --------------------
12083
12084             procedure Check_Too_Long (Arg : Node_Id) is
12085                X : constant Node_Id := Original_Node (Arg);
12086
12087             begin
12088                if not Nkind_In (X, N_String_Literal, N_Identifier) then
12089                   Error_Pragma_Arg
12090                     ("inappropriate argument for pragma %", Arg);
12091                end if;
12092
12093                if OpenVMS_On_Target then
12094                   if (Nkind (X) = N_String_Literal
12095                        and then String_Length (Strval (X)) > 31)
12096                     or else
12097                      (Nkind (X) = N_Identifier
12098                        and then Length_Of_Name (Chars (X)) > 31)
12099                   then
12100                      Error_Pragma_Arg
12101                        ("argument for pragma % is longer than 31 characters",
12102                         Arg);
12103                   end if;
12104                end if;
12105             end Check_Too_Long;
12106
12107          --  Start of processing for Common_Object/Psect_Object
12108
12109          begin
12110             GNAT_Pragma;
12111             Gather_Associations (Names, Args);
12112             Process_Extended_Import_Export_Internal_Arg (Internal);
12113
12114             Def_Id := Entity (Internal);
12115
12116             if not Ekind_In (Def_Id, E_Constant, E_Variable) then
12117                Error_Pragma_Arg
12118                  ("pragma% must designate an object", Internal);
12119             end if;
12120
12121             Check_Too_Long (Internal);
12122
12123             if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then
12124                Error_Pragma_Arg
12125                  ("cannot use pragma% for imported/exported object",
12126                   Internal);
12127             end if;
12128
12129             if Is_Concurrent_Type (Etype (Internal)) then
12130                Error_Pragma_Arg
12131                  ("cannot specify pragma % for task/protected object",
12132                   Internal);
12133             end if;
12134
12135             if Has_Rep_Pragma (Def_Id, Name_Common_Object)
12136                  or else
12137                Has_Rep_Pragma (Def_Id, Name_Psect_Object)
12138             then
12139                Error_Msg_N ("?duplicate Common/Psect_Object pragma", N);
12140             end if;
12141
12142             if Ekind (Def_Id) = E_Constant then
12143                Error_Pragma_Arg
12144                  ("cannot specify pragma % for a constant", Internal);
12145             end if;
12146
12147             if Is_Record_Type (Etype (Internal)) then
12148                declare
12149                   Ent  : Entity_Id;
12150                   Decl : Entity_Id;
12151
12152                begin
12153                   Ent := First_Entity (Etype (Internal));
12154                   while Present (Ent) loop
12155                      Decl := Declaration_Node (Ent);
12156
12157                      if Ekind (Ent) = E_Component
12158                        and then Nkind (Decl) = N_Component_Declaration
12159                        and then Present (Expression (Decl))
12160                        and then Warn_On_Export_Import
12161                      then
12162                         Error_Msg_N
12163                           ("?object for pragma % has defaults", Internal);
12164                         exit;
12165
12166                      else
12167                         Next_Entity (Ent);
12168                      end if;
12169                   end loop;
12170                end;
12171             end if;
12172
12173             if Present (Size) then
12174                Check_Too_Long (Size);
12175             end if;
12176
12177             if Present (External) then
12178                Check_Arg_Is_External_Name (External);
12179                Check_Too_Long (External);
12180             end if;
12181
12182             --  If all error tests pass, link pragma on to the rep item chain
12183
12184             Record_Rep_Item (Def_Id, N);
12185          end Psect_Object;
12186
12187          ----------
12188          -- Pure --
12189          ----------
12190
12191          --  pragma Pure [(library_unit_NAME)];
12192
12193          when Pragma_Pure => Pure : declare
12194             Ent : Entity_Id;
12195
12196          begin
12197             Check_Ada_83_Warning;
12198             Check_Valid_Library_Unit_Pragma;
12199
12200             if Nkind (N) = N_Null_Statement then
12201                return;
12202             end if;
12203
12204             Ent := Find_Lib_Unit_Name;
12205             Set_Is_Pure (Ent);
12206             Set_Has_Pragma_Pure (Ent);
12207             Set_Suppress_Elaboration_Warnings (Ent);
12208          end Pure;
12209
12210          -------------
12211          -- Pure_05 --
12212          -------------
12213
12214          --  pragma Pure_05 [(library_unit_NAME)];
12215
12216          --  This pragma is useable only in GNAT_Mode, where it is used like
12217          --  pragma Pure but it is only effective in Ada 2005 mode (otherwise
12218          --  it is ignored). It may be used after a pragma Preelaborate, in
12219          --  which case it overrides the effect of the pragma Preelaborate.
12220          --  This is used to implement AI-362 which recategorizes some run-time
12221          --  packages in Ada 2005 mode.
12222
12223          when Pragma_Pure_05 => Pure_05 : declare
12224             Ent : Entity_Id;
12225
12226          begin
12227             GNAT_Pragma;
12228             Check_Valid_Library_Unit_Pragma;
12229
12230             if not GNAT_Mode then
12231                Error_Pragma ("pragma% only available in GNAT mode");
12232             end if;
12233
12234             if Nkind (N) = N_Null_Statement then
12235                return;
12236             end if;
12237
12238             --  This is one of the few cases where we need to test the value of
12239             --  Ada_Version_Explicit rather than Ada_Version (which is always
12240             --  set to Ada_2012 in a predefined unit), we need to know the
12241             --  explicit version set to know if this pragma is active.
12242
12243             if Ada_Version_Explicit >= Ada_2005 then
12244                Ent := Find_Lib_Unit_Name;
12245                Set_Is_Preelaborated (Ent, False);
12246                Set_Is_Pure (Ent);
12247                Set_Suppress_Elaboration_Warnings (Ent);
12248             end if;
12249          end Pure_05;
12250
12251          -------------------
12252          -- Pure_Function --
12253          -------------------
12254
12255          --  pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
12256
12257          when Pragma_Pure_Function => Pure_Function : declare
12258             E_Id      : Node_Id;
12259             E         : Entity_Id;
12260             Def_Id    : Entity_Id;
12261             Effective : Boolean := False;
12262
12263          begin
12264             GNAT_Pragma;
12265             Check_Arg_Count (1);
12266             Check_Optional_Identifier (Arg1, Name_Entity);
12267             Check_Arg_Is_Local_Name (Arg1);
12268             E_Id := Get_Pragma_Arg (Arg1);
12269
12270             if Error_Posted (E_Id) then
12271                return;
12272             end if;
12273
12274             --  Loop through homonyms (overloadings) of referenced entity
12275
12276             E := Entity (E_Id);
12277
12278             if Present (E) then
12279                loop
12280                   Def_Id := Get_Base_Subprogram (E);
12281
12282                   if not Ekind_In (Def_Id, E_Function,
12283                                            E_Generic_Function,
12284                                            E_Operator)
12285                   then
12286                      Error_Pragma_Arg
12287                        ("pragma% requires a function name", Arg1);
12288                   end if;
12289
12290                   Set_Is_Pure (Def_Id);
12291
12292                   if not Has_Pragma_Pure_Function (Def_Id) then
12293                      Set_Has_Pragma_Pure_Function (Def_Id);
12294                      Effective := True;
12295                   end if;
12296
12297                   exit when From_Aspect_Specification (N);
12298                   E := Homonym (E);
12299                   exit when No (E) or else Scope (E) /= Current_Scope;
12300                end loop;
12301
12302                if not Effective
12303                  and then Warn_On_Redundant_Constructs
12304                then
12305                   Error_Msg_NE
12306                     ("pragma Pure_Function on& is redundant?",
12307                      N, Entity (E_Id));
12308                end if;
12309             end if;
12310          end Pure_Function;
12311
12312          --------------------
12313          -- Queuing_Policy --
12314          --------------------
12315
12316          --  pragma Queuing_Policy (policy_IDENTIFIER);
12317
12318          when Pragma_Queuing_Policy => declare
12319             QP : Character;
12320
12321          begin
12322             Check_Ada_83_Warning;
12323             Check_Arg_Count (1);
12324             Check_No_Identifiers;
12325             Check_Arg_Is_Queuing_Policy (Arg1);
12326             Check_Valid_Configuration_Pragma;
12327             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
12328             QP := Fold_Upper (Name_Buffer (1));
12329
12330             if Queuing_Policy /= ' '
12331               and then Queuing_Policy /= QP
12332             then
12333                Error_Msg_Sloc := Queuing_Policy_Sloc;
12334                Error_Pragma ("queuing policy incompatible with policy#");
12335
12336             --  Set new policy, but always preserve System_Location since we
12337             --  like the error message with the run time name.
12338
12339             else
12340                Queuing_Policy := QP;
12341
12342                if Queuing_Policy_Sloc /= System_Location then
12343                   Queuing_Policy_Sloc := Loc;
12344                end if;
12345             end if;
12346          end;
12347
12348          -----------------------
12349          -- Relative_Deadline --
12350          -----------------------
12351
12352          --  pragma Relative_Deadline (time_span_EXPRESSION);
12353
12354          when Pragma_Relative_Deadline => Relative_Deadline : declare
12355             P   : constant Node_Id := Parent (N);
12356             Arg : Node_Id;
12357
12358          begin
12359             Ada_2005_Pragma;
12360             Check_No_Identifiers;
12361             Check_Arg_Count (1);
12362
12363             Arg := Get_Pragma_Arg (Arg1);
12364
12365             --  The expression must be analyzed in the special manner described
12366             --  in "Handling of Default and Per-Object Expressions" in sem.ads.
12367
12368             Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span));
12369
12370             --  Subprogram case
12371
12372             if Nkind (P) = N_Subprogram_Body then
12373                Check_In_Main_Program;
12374
12375             --  Tasks
12376
12377             elsif Nkind (P) = N_Task_Definition then
12378                null;
12379
12380             --  Anything else is incorrect
12381
12382             else
12383                Pragma_Misplaced;
12384             end if;
12385
12386             if Has_Relative_Deadline_Pragma (P) then
12387                Error_Pragma ("duplicate pragma% not allowed");
12388             else
12389                Set_Has_Relative_Deadline_Pragma (P, True);
12390
12391                if Nkind (P) = N_Task_Definition then
12392                   Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12393                end if;
12394             end if;
12395          end Relative_Deadline;
12396
12397          ---------------------------
12398          -- Remote_Call_Interface --
12399          ---------------------------
12400
12401          --  pragma Remote_Call_Interface [(library_unit_NAME)];
12402
12403          when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare
12404             Cunit_Node : Node_Id;
12405             Cunit_Ent  : Entity_Id;
12406             K          : Node_Kind;
12407
12408          begin
12409             Check_Ada_83_Warning;
12410             Check_Valid_Library_Unit_Pragma;
12411
12412             if Nkind (N) = N_Null_Statement then
12413                return;
12414             end if;
12415
12416             Cunit_Node := Cunit (Current_Sem_Unit);
12417             K          := Nkind (Unit (Cunit_Node));
12418             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12419
12420             if K = N_Package_Declaration
12421               or else K = N_Generic_Package_Declaration
12422               or else K = N_Subprogram_Declaration
12423               or else K = N_Generic_Subprogram_Declaration
12424               or else (K = N_Subprogram_Body
12425                          and then Acts_As_Spec (Unit (Cunit_Node)))
12426             then
12427                null;
12428             else
12429                Error_Pragma (
12430                  "pragma% must apply to package or subprogram declaration");
12431             end if;
12432
12433             Set_Is_Remote_Call_Interface (Cunit_Ent);
12434          end Remote_Call_Interface;
12435
12436          ------------------
12437          -- Remote_Types --
12438          ------------------
12439
12440          --  pragma Remote_Types [(library_unit_NAME)];
12441
12442          when Pragma_Remote_Types => Remote_Types : declare
12443             Cunit_Node : Node_Id;
12444             Cunit_Ent  : Entity_Id;
12445
12446          begin
12447             Check_Ada_83_Warning;
12448             Check_Valid_Library_Unit_Pragma;
12449
12450             if Nkind (N) = N_Null_Statement then
12451                return;
12452             end if;
12453
12454             Cunit_Node := Cunit (Current_Sem_Unit);
12455             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12456
12457             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12458                                                 N_Generic_Package_Declaration)
12459             then
12460                Error_Pragma
12461                  ("pragma% can only apply to a package declaration");
12462             end if;
12463
12464             Set_Is_Remote_Types (Cunit_Ent);
12465          end Remote_Types;
12466
12467          ---------------
12468          -- Ravenscar --
12469          ---------------
12470
12471          --  pragma Ravenscar;
12472
12473          when Pragma_Ravenscar =>
12474             GNAT_Pragma;
12475             Check_Arg_Count (0);
12476             Check_Valid_Configuration_Pragma;
12477             Set_Ravenscar_Profile (N);
12478
12479             if Warn_On_Obsolescent_Feature then
12480                Error_Msg_N ("pragma Ravenscar is an obsolescent feature?", N);
12481                Error_Msg_N ("|use pragma Profile (Ravenscar) instead", N);
12482             end if;
12483
12484          -------------------------
12485          -- Restricted_Run_Time --
12486          -------------------------
12487
12488          --  pragma Restricted_Run_Time;
12489
12490          when Pragma_Restricted_Run_Time =>
12491             GNAT_Pragma;
12492             Check_Arg_Count (0);
12493             Check_Valid_Configuration_Pragma;
12494             Set_Profile_Restrictions
12495               (Restricted, N, Warn => Treat_Restrictions_As_Warnings);
12496
12497             if Warn_On_Obsolescent_Feature then
12498                Error_Msg_N
12499                  ("pragma Restricted_Run_Time is an obsolescent feature?", N);
12500                Error_Msg_N ("|use pragma Profile (Restricted) instead", N);
12501             end if;
12502
12503          ------------------
12504          -- Restrictions --
12505          ------------------
12506
12507          --  pragma Restrictions (RESTRICTION {, RESTRICTION});
12508
12509          --  RESTRICTION ::=
12510          --    restriction_IDENTIFIER
12511          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12512
12513          when Pragma_Restrictions =>
12514             Process_Restrictions_Or_Restriction_Warnings
12515               (Warn => Treat_Restrictions_As_Warnings);
12516
12517          --------------------------
12518          -- Restriction_Warnings --
12519          --------------------------
12520
12521          --  pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
12522
12523          --  RESTRICTION ::=
12524          --    restriction_IDENTIFIER
12525          --  | restriction_parameter_IDENTIFIER => EXPRESSION
12526
12527          when Pragma_Restriction_Warnings =>
12528             GNAT_Pragma;
12529             Process_Restrictions_Or_Restriction_Warnings (Warn => True);
12530
12531          ----------------
12532          -- Reviewable --
12533          ----------------
12534
12535          --  pragma Reviewable;
12536
12537          when Pragma_Reviewable =>
12538             Check_Ada_83_Warning;
12539             Check_Arg_Count (0);
12540
12541             --  Call dummy debugging function rv. This is done to assist front
12542             --  end debugging. By placing a Reviewable pragma in the source
12543             --  program, a breakpoint on rv catches this place in the source,
12544             --  allowing convenient stepping to the point of interest.
12545
12546             rv;
12547
12548          --------------------------
12549          -- Short_Circuit_And_Or --
12550          --------------------------
12551
12552          when Pragma_Short_Circuit_And_Or =>
12553             GNAT_Pragma;
12554             Check_Arg_Count (0);
12555             Check_Valid_Configuration_Pragma;
12556             Short_Circuit_And_Or := True;
12557
12558          -------------------
12559          -- Share_Generic --
12560          -------------------
12561
12562          --  pragma Share_Generic (NAME {, NAME});
12563
12564          when Pragma_Share_Generic =>
12565             GNAT_Pragma;
12566             Process_Generic_List;
12567
12568          ------------
12569          -- Shared --
12570          ------------
12571
12572          --  pragma Shared (LOCAL_NAME);
12573
12574          when Pragma_Shared =>
12575             GNAT_Pragma;
12576             Process_Atomic_Shared_Volatile;
12577
12578          --------------------
12579          -- Shared_Passive --
12580          --------------------
12581
12582          --  pragma Shared_Passive [(library_unit_NAME)];
12583
12584          --  Set the flag Is_Shared_Passive of program unit name entity
12585
12586          when Pragma_Shared_Passive => Shared_Passive : declare
12587             Cunit_Node : Node_Id;
12588             Cunit_Ent  : Entity_Id;
12589
12590          begin
12591             Check_Ada_83_Warning;
12592             Check_Valid_Library_Unit_Pragma;
12593
12594             if Nkind (N) = N_Null_Statement then
12595                return;
12596             end if;
12597
12598             Cunit_Node := Cunit (Current_Sem_Unit);
12599             Cunit_Ent  := Cunit_Entity (Current_Sem_Unit);
12600
12601             if not Nkind_In (Unit (Cunit_Node), N_Package_Declaration,
12602                                                 N_Generic_Package_Declaration)
12603             then
12604                Error_Pragma
12605                  ("pragma% can only apply to a package declaration");
12606             end if;
12607
12608             Set_Is_Shared_Passive (Cunit_Ent);
12609          end Shared_Passive;
12610
12611          -----------------------
12612          -- Short_Descriptors --
12613          -----------------------
12614
12615          --  pragma Short_Descriptors;
12616
12617          when Pragma_Short_Descriptors =>
12618             GNAT_Pragma;
12619             Check_Arg_Count (0);
12620             Check_Valid_Configuration_Pragma;
12621             Short_Descriptors := True;
12622
12623          ----------------------
12624          -- Source_File_Name --
12625          ----------------------
12626
12627          --  There are five forms for this pragma:
12628
12629          --  pragma Source_File_Name (
12630          --    [UNIT_NAME      =>] unit_NAME,
12631          --     BODY_FILE_NAME =>  STRING_LITERAL
12632          --    [, [INDEX =>] INTEGER_LITERAL]);
12633
12634          --  pragma Source_File_Name (
12635          --    [UNIT_NAME      =>] unit_NAME,
12636          --     SPEC_FILE_NAME =>  STRING_LITERAL
12637          --    [, [INDEX =>] INTEGER_LITERAL]);
12638
12639          --  pragma Source_File_Name (
12640          --     BODY_FILE_NAME  => STRING_LITERAL
12641          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12642          --  [, CASING          => CASING_SPEC]);
12643
12644          --  pragma Source_File_Name (
12645          --     SPEC_FILE_NAME  => STRING_LITERAL
12646          --  [, DOT_REPLACEMENT => STRING_LITERAL]
12647          --  [, CASING          => CASING_SPEC]);
12648
12649          --  pragma Source_File_Name (
12650          --     SUBUNIT_FILE_NAME  => STRING_LITERAL
12651          --  [, DOT_REPLACEMENT    => STRING_LITERAL]
12652          --  [, CASING             => CASING_SPEC]);
12653
12654          --  CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
12655
12656          --  Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
12657          --  Source_File_Name (SFN), however their usage is exclusive: SFN can
12658          --  only be used when no project file is used, while SFNP can only be
12659          --  used when a project file is used.
12660
12661          --  No processing here. Processing was completed during parsing, since
12662          --  we need to have file names set as early as possible. Units are
12663          --  loaded well before semantic processing starts.
12664
12665          --  The only processing we defer to this point is the check for
12666          --  correct placement.
12667
12668          when Pragma_Source_File_Name =>
12669             GNAT_Pragma;
12670             Check_Valid_Configuration_Pragma;
12671
12672          ------------------------------
12673          -- Source_File_Name_Project --
12674          ------------------------------
12675
12676          --  See Source_File_Name for syntax
12677
12678          --  No processing here. Processing was completed during parsing, since
12679          --  we need to have file names set as early as possible. Units are
12680          --  loaded well before semantic processing starts.
12681
12682          --  The only processing we defer to this point is the check for
12683          --  correct placement.
12684
12685          when Pragma_Source_File_Name_Project =>
12686             GNAT_Pragma;
12687             Check_Valid_Configuration_Pragma;
12688
12689             --  Check that a pragma Source_File_Name_Project is used only in a
12690             --  configuration pragmas file.
12691
12692             --  Pragmas Source_File_Name_Project should only be generated by
12693             --  the Project Manager in configuration pragmas files.
12694
12695             --  This is really an ugly test. It seems to depend on some
12696             --  accidental and undocumented property. At the very least it
12697             --  needs to be documented, but it would be better to have a
12698             --  clean way of testing if we are in a configuration file???
12699
12700             if Present (Parent (N)) then
12701                Error_Pragma
12702                  ("pragma% can only appear in a configuration pragmas file");
12703             end if;
12704
12705          ----------------------
12706          -- Source_Reference --
12707          ----------------------
12708
12709          --  pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
12710
12711          --  Nothing to do, all processing completed in Par.Prag, since we need
12712          --  the information for possible parser messages that are output.
12713
12714          when Pragma_Source_Reference =>
12715             GNAT_Pragma;
12716
12717          --------------------------------
12718          -- Static_Elaboration_Desired --
12719          --------------------------------
12720
12721          --  pragma Static_Elaboration_Desired (DIRECT_NAME);
12722
12723          when Pragma_Static_Elaboration_Desired =>
12724             GNAT_Pragma;
12725             Check_At_Most_N_Arguments (1);
12726
12727             if Is_Compilation_Unit (Current_Scope)
12728               and then Ekind (Current_Scope) = E_Package
12729             then
12730                Set_Static_Elaboration_Desired (Current_Scope, True);
12731             else
12732                Error_Pragma ("pragma% must apply to a library-level package");
12733             end if;
12734
12735          ------------------
12736          -- Storage_Size --
12737          ------------------
12738
12739          --  pragma Storage_Size (EXPRESSION);
12740
12741          when Pragma_Storage_Size => Storage_Size : declare
12742             P   : constant Node_Id := Parent (N);
12743             Arg : Node_Id;
12744
12745          begin
12746             Check_No_Identifiers;
12747             Check_Arg_Count (1);
12748
12749             --  The expression must be analyzed in the special manner described
12750             --  in "Handling of Default Expressions" in sem.ads.
12751
12752             Arg := Get_Pragma_Arg (Arg1);
12753             Preanalyze_Spec_Expression (Arg, Any_Integer);
12754
12755             if not Is_Static_Expression (Arg) then
12756                Check_Restriction (Static_Storage_Size, Arg);
12757             end if;
12758
12759             if Nkind (P) /= N_Task_Definition then
12760                Pragma_Misplaced;
12761                return;
12762
12763             else
12764                if Has_Storage_Size_Pragma (P) then
12765                   Error_Pragma ("duplicate pragma% not allowed");
12766                else
12767                   Set_Has_Storage_Size_Pragma (P, True);
12768                end if;
12769
12770                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
12771                --  ???  exp_ch9 should use this!
12772             end if;
12773          end Storage_Size;
12774
12775          ------------------
12776          -- Storage_Unit --
12777          ------------------
12778
12779          --  pragma Storage_Unit (NUMERIC_LITERAL);
12780
12781          --  Only permitted argument is System'Storage_Unit value
12782
12783          when Pragma_Storage_Unit =>
12784             Check_No_Identifiers;
12785             Check_Arg_Count (1);
12786             Check_Arg_Is_Integer_Literal (Arg1);
12787
12788             if Intval (Get_Pragma_Arg (Arg1)) /=
12789               UI_From_Int (Ttypes.System_Storage_Unit)
12790             then
12791                Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit);
12792                Error_Pragma_Arg
12793                  ("the only allowed argument for pragma% is ^", Arg1);
12794             end if;
12795
12796          --------------------
12797          -- Stream_Convert --
12798          --------------------
12799
12800          --  pragma Stream_Convert (
12801          --    [Entity =>] type_LOCAL_NAME,
12802          --    [Read   =>] function_NAME,
12803          --    [Write  =>] function NAME);
12804
12805          when Pragma_Stream_Convert => Stream_Convert : declare
12806
12807             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id);
12808             --  Check that the given argument is the name of a local function
12809             --  of one argument that is not overloaded earlier in the current
12810             --  local scope. A check is also made that the argument is a
12811             --  function with one parameter.
12812
12813             --------------------------------------
12814             -- Check_OK_Stream_Convert_Function --
12815             --------------------------------------
12816
12817             procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is
12818                Ent : Entity_Id;
12819
12820             begin
12821                Check_Arg_Is_Local_Name (Arg);
12822                Ent := Entity (Get_Pragma_Arg (Arg));
12823
12824                if Has_Homonym (Ent) then
12825                   Error_Pragma_Arg
12826                     ("argument for pragma% may not be overloaded", Arg);
12827                end if;
12828
12829                if Ekind (Ent) /= E_Function
12830                  or else No (First_Formal (Ent))
12831                  or else Present (Next_Formal (First_Formal (Ent)))
12832                then
12833                   Error_Pragma_Arg
12834                     ("argument for pragma% must be" &
12835                      " function of one argument", Arg);
12836                end if;
12837             end Check_OK_Stream_Convert_Function;
12838
12839          --  Start of processing for Stream_Convert
12840
12841          begin
12842             GNAT_Pragma;
12843             Check_Arg_Order ((Name_Entity, Name_Read, Name_Write));
12844             Check_Arg_Count (3);
12845             Check_Optional_Identifier (Arg1, Name_Entity);
12846             Check_Optional_Identifier (Arg2, Name_Read);
12847             Check_Optional_Identifier (Arg3, Name_Write);
12848             Check_Arg_Is_Local_Name (Arg1);
12849             Check_OK_Stream_Convert_Function (Arg2);
12850             Check_OK_Stream_Convert_Function (Arg3);
12851
12852             declare
12853                Typ   : constant Entity_Id :=
12854                          Underlying_Type (Entity (Get_Pragma_Arg (Arg1)));
12855                Read  : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2));
12856                Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3));
12857
12858             begin
12859                Check_First_Subtype (Arg1);
12860
12861                --  Check for too early or too late. Note that we don't enforce
12862                --  the rule about primitive operations in this case, since, as
12863                --  is the case for explicit stream attributes themselves, these
12864                --  restrictions are not appropriate. Note that the chaining of
12865                --  the pragma by Rep_Item_Too_Late is actually the critical
12866                --  processing done for this pragma.
12867
12868                if Rep_Item_Too_Early (Typ, N)
12869                     or else
12870                   Rep_Item_Too_Late (Typ, N, FOnly => True)
12871                then
12872                   return;
12873                end if;
12874
12875                --  Return if previous error
12876
12877                if Etype (Typ) = Any_Type
12878                     or else
12879                   Etype (Read) = Any_Type
12880                     or else
12881                   Etype (Write) = Any_Type
12882                then
12883                   return;
12884                end if;
12885
12886                --  Error checks
12887
12888                if Underlying_Type (Etype (Read)) /= Typ then
12889                   Error_Pragma_Arg
12890                     ("incorrect return type for function&", Arg2);
12891                end if;
12892
12893                if Underlying_Type (Etype (First_Formal (Write))) /= Typ then
12894                   Error_Pragma_Arg
12895                     ("incorrect parameter type for function&", Arg3);
12896                end if;
12897
12898                if Underlying_Type (Etype (First_Formal (Read))) /=
12899                   Underlying_Type (Etype (Write))
12900                then
12901                   Error_Pragma_Arg
12902                     ("result type of & does not match Read parameter type",
12903                      Arg3);
12904                end if;
12905             end;
12906          end Stream_Convert;
12907
12908          -------------------------
12909          -- Style_Checks (GNAT) --
12910          -------------------------
12911
12912          --  pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
12913
12914          --  This is processed by the parser since some of the style checks
12915          --  take place during source scanning and parsing. This means that
12916          --  we don't need to issue error messages here.
12917
12918          when Pragma_Style_Checks => Style_Checks : declare
12919             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
12920             S  : String_Id;
12921             C  : Char_Code;
12922
12923          begin
12924             GNAT_Pragma;
12925             Check_No_Identifiers;
12926
12927             --  Two argument form
12928
12929             if Arg_Count = 2 then
12930                Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
12931
12932                declare
12933                   E_Id : Node_Id;
12934                   E    : Entity_Id;
12935
12936                begin
12937                   E_Id := Get_Pragma_Arg (Arg2);
12938                   Analyze (E_Id);
12939
12940                   if not Is_Entity_Name (E_Id) then
12941                      Error_Pragma_Arg
12942                        ("second argument of pragma% must be entity name",
12943                         Arg2);
12944                   end if;
12945
12946                   E := Entity (E_Id);
12947
12948                   if E = Any_Id then
12949                      return;
12950                   else
12951                      loop
12952                         Set_Suppress_Style_Checks (E,
12953                           (Chars (Get_Pragma_Arg (Arg1)) = Name_Off));
12954                         exit when No (Homonym (E));
12955                         E := Homonym (E);
12956                      end loop;
12957                   end if;
12958                end;
12959
12960             --  One argument form
12961
12962             else
12963                Check_Arg_Count (1);
12964
12965                if Nkind (A) = N_String_Literal then
12966                   S   := Strval (A);
12967
12968                   declare
12969                      Slen    : constant Natural := Natural (String_Length (S));
12970                      Options : String (1 .. Slen);
12971                      J       : Natural;
12972
12973                   begin
12974                      J := 1;
12975                      loop
12976                         C := Get_String_Char (S, Int (J));
12977                         exit when not In_Character_Range (C);
12978                         Options (J) := Get_Character (C);
12979
12980                         --  If at end of string, set options. As per discussion
12981                         --  above, no need to check for errors, since we issued
12982                         --  them in the parser.
12983
12984                         if J = Slen then
12985                            Set_Style_Check_Options (Options);
12986                            exit;
12987                         end if;
12988
12989                         J := J + 1;
12990                      end loop;
12991                   end;
12992
12993                elsif Nkind (A) = N_Identifier then
12994                   if Chars (A) = Name_All_Checks then
12995                      if GNAT_Mode then
12996                         Set_GNAT_Style_Check_Options;
12997                      else
12998                         Set_Default_Style_Check_Options;
12999                      end if;
13000
13001                   elsif Chars (A) = Name_On then
13002                      Style_Check := True;
13003
13004                   elsif Chars (A) = Name_Off then
13005                      Style_Check := False;
13006                   end if;
13007                end if;
13008             end if;
13009          end Style_Checks;
13010
13011          --------------
13012          -- Subtitle --
13013          --------------
13014
13015          --  pragma Subtitle ([Subtitle =>] STRING_LITERAL);
13016
13017          when Pragma_Subtitle =>
13018             GNAT_Pragma;
13019             Check_Arg_Count (1);
13020             Check_Optional_Identifier (Arg1, Name_Subtitle);
13021             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13022             Store_Note (N);
13023
13024          --------------
13025          -- Suppress --
13026          --------------
13027
13028          --  pragma Suppress (IDENTIFIER [, [On =>] NAME]);
13029
13030          when Pragma_Suppress =>
13031             Process_Suppress_Unsuppress (True);
13032
13033          ------------------
13034          -- Suppress_All --
13035          ------------------
13036
13037          --  pragma Suppress_All;
13038
13039          --  The only check made here is that the pragma has no arguments.
13040          --  There are no placement rules, and the processing required (setting
13041          --  the Has_Pragma_Suppress_All flag in the compilation unit node was
13042          --  taken care of by the parser). Process_Compilation_Unit_Pragmas
13043          --  then creates and inserts a pragma Suppress (All_Checks).
13044
13045          when Pragma_Suppress_All =>
13046             GNAT_Pragma;
13047             Check_Arg_Count (0);
13048
13049          -------------------------
13050          -- Suppress_Debug_Info --
13051          -------------------------
13052
13053          --  pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
13054
13055          when Pragma_Suppress_Debug_Info =>
13056             GNAT_Pragma;
13057             Check_Arg_Count (1);
13058             Check_Optional_Identifier (Arg1, Name_Entity);
13059             Check_Arg_Is_Local_Name (Arg1);
13060             Set_Debug_Info_Off (Entity (Get_Pragma_Arg (Arg1)));
13061
13062          ----------------------------------
13063          -- Suppress_Exception_Locations --
13064          ----------------------------------
13065
13066          --  pragma Suppress_Exception_Locations;
13067
13068          when Pragma_Suppress_Exception_Locations =>
13069             GNAT_Pragma;
13070             Check_Arg_Count (0);
13071             Check_Valid_Configuration_Pragma;
13072             Exception_Locations_Suppressed := True;
13073
13074          -----------------------------
13075          -- Suppress_Initialization --
13076          -----------------------------
13077
13078          --  pragma Suppress_Initialization ([Entity =>] type_Name);
13079
13080          when Pragma_Suppress_Initialization => Suppress_Init : declare
13081             E_Id : Node_Id;
13082             E    : Entity_Id;
13083
13084          begin
13085             GNAT_Pragma;
13086             Check_Arg_Count (1);
13087             Check_Optional_Identifier (Arg1, Name_Entity);
13088             Check_Arg_Is_Local_Name (Arg1);
13089
13090             E_Id := Get_Pragma_Arg (Arg1);
13091
13092             if Etype (E_Id) = Any_Type then
13093                return;
13094             end if;
13095
13096             E := Entity (E_Id);
13097
13098             if not Is_Type (E) then
13099                Error_Pragma_Arg ("pragma% requires type or subtype", Arg1);
13100             end if;
13101
13102             if Rep_Item_Too_Early (E, N)
13103                  or else
13104                Rep_Item_Too_Late (E, N, FOnly => True)
13105             then
13106                return;
13107             end if;
13108
13109             --  For incomplete/private type, set flag on full view
13110
13111             if Is_Incomplete_Or_Private_Type (E) then
13112                if No (Full_View (Base_Type (E))) then
13113                   Error_Pragma_Arg
13114                     ("argument of pragma% cannot be an incomplete type", Arg1);
13115                else
13116                   Set_Suppress_Initialization (Full_View (Base_Type (E)));
13117                end if;
13118
13119             --  For first subtype, set flag on base type
13120
13121             elsif Is_First_Subtype (E) then
13122                Set_Suppress_Initialization (Base_Type (E));
13123
13124             --  For other than first subtype, set flag on subtype itself
13125
13126             else
13127                Set_Suppress_Initialization (E);
13128             end if;
13129          end Suppress_Init;
13130
13131          -----------------
13132          -- System_Name --
13133          -----------------
13134
13135          --  pragma System_Name (DIRECT_NAME);
13136
13137          --  Syntax check: one argument, which must be the identifier GNAT or
13138          --  the identifier GCC, no other identifiers are acceptable.
13139
13140          when Pragma_System_Name =>
13141             GNAT_Pragma;
13142             Check_No_Identifiers;
13143             Check_Arg_Count (1);
13144             Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat);
13145
13146          -----------------------------
13147          -- Task_Dispatching_Policy --
13148          -----------------------------
13149
13150          --  pragma Task_Dispatching_Policy (policy_IDENTIFIER);
13151
13152          when Pragma_Task_Dispatching_Policy => declare
13153             DP : Character;
13154
13155          begin
13156             Check_Ada_83_Warning;
13157             Check_Arg_Count (1);
13158             Check_No_Identifiers;
13159             Check_Arg_Is_Task_Dispatching_Policy (Arg1);
13160             Check_Valid_Configuration_Pragma;
13161             Get_Name_String (Chars (Get_Pragma_Arg (Arg1)));
13162             DP := Fold_Upper (Name_Buffer (1));
13163
13164             if Task_Dispatching_Policy /= ' '
13165               and then Task_Dispatching_Policy /= DP
13166             then
13167                Error_Msg_Sloc := Task_Dispatching_Policy_Sloc;
13168                Error_Pragma
13169                  ("task dispatching policy incompatible with policy#");
13170
13171             --  Set new policy, but always preserve System_Location since we
13172             --  like the error message with the run time name.
13173
13174             else
13175                Task_Dispatching_Policy := DP;
13176
13177                if Task_Dispatching_Policy_Sloc /= System_Location then
13178                   Task_Dispatching_Policy_Sloc := Loc;
13179                end if;
13180             end if;
13181          end;
13182
13183          ---------------
13184          -- Task_Info --
13185          ---------------
13186
13187          --  pragma Task_Info (EXPRESSION);
13188
13189          when Pragma_Task_Info => Task_Info : declare
13190             P : constant Node_Id := Parent (N);
13191
13192          begin
13193             GNAT_Pragma;
13194
13195             if Nkind (P) /= N_Task_Definition then
13196                Error_Pragma ("pragma% must appear in task definition");
13197             end if;
13198
13199             Check_No_Identifiers;
13200             Check_Arg_Count (1);
13201
13202             Analyze_And_Resolve
13203               (Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type));
13204
13205             if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then
13206                return;
13207             end if;
13208
13209             if Has_Task_Info_Pragma (P) then
13210                Error_Pragma ("duplicate pragma% not allowed");
13211             else
13212                Set_Has_Task_Info_Pragma (P, True);
13213             end if;
13214          end Task_Info;
13215
13216          ---------------
13217          -- Task_Name --
13218          ---------------
13219
13220          --  pragma Task_Name (string_EXPRESSION);
13221
13222          when Pragma_Task_Name => Task_Name : declare
13223             P   : constant Node_Id := Parent (N);
13224             Arg : Node_Id;
13225
13226          begin
13227             Check_No_Identifiers;
13228             Check_Arg_Count (1);
13229
13230             Arg := Get_Pragma_Arg (Arg1);
13231
13232             --  The expression is used in the call to Create_Task, and must be
13233             --  expanded there, not in the context of the current spec. It must
13234             --  however be analyzed to capture global references, in case it
13235             --  appears in a generic context.
13236
13237             Preanalyze_And_Resolve (Arg, Standard_String);
13238
13239             if Nkind (P) /= N_Task_Definition then
13240                Pragma_Misplaced;
13241             end if;
13242
13243             if Has_Task_Name_Pragma (P) then
13244                Error_Pragma ("duplicate pragma% not allowed");
13245             else
13246                Set_Has_Task_Name_Pragma (P, True);
13247                Record_Rep_Item (Defining_Identifier (Parent (P)), N);
13248             end if;
13249          end Task_Name;
13250
13251          ------------------
13252          -- Task_Storage --
13253          ------------------
13254
13255          --  pragma Task_Storage (
13256          --     [Task_Type =>] LOCAL_NAME,
13257          --     [Top_Guard =>] static_integer_EXPRESSION);
13258
13259          when Pragma_Task_Storage => Task_Storage : declare
13260             Args  : Args_List (1 .. 2);
13261             Names : constant Name_List (1 .. 2) := (
13262                       Name_Task_Type,
13263                       Name_Top_Guard);
13264
13265             Task_Type : Node_Id renames Args (1);
13266             Top_Guard : Node_Id renames Args (2);
13267
13268             Ent : Entity_Id;
13269
13270          begin
13271             GNAT_Pragma;
13272             Gather_Associations (Names, Args);
13273
13274             if No (Task_Type) then
13275                Error_Pragma
13276                  ("missing task_type argument for pragma%");
13277             end if;
13278
13279             Check_Arg_Is_Local_Name (Task_Type);
13280
13281             Ent := Entity (Task_Type);
13282
13283             if not Is_Task_Type (Ent) then
13284                Error_Pragma_Arg
13285                  ("argument for pragma% must be task type", Task_Type);
13286             end if;
13287
13288             if No (Top_Guard) then
13289                Error_Pragma_Arg
13290                  ("pragma% takes two arguments", Task_Type);
13291             else
13292                Check_Arg_Is_Static_Expression (Top_Guard, Any_Integer);
13293             end if;
13294
13295             Check_First_Subtype (Task_Type);
13296
13297             if Rep_Item_Too_Late (Ent, N) then
13298                raise Pragma_Exit;
13299             end if;
13300          end Task_Storage;
13301
13302          ---------------
13303          -- Test_Case --
13304          ---------------
13305
13306          --  pragma Test_Case ([Name     =>] Static_String_EXPRESSION
13307          --                   ,[Mode     =>] MODE_TYPE
13308          --                  [, Requires =>  Boolean_EXPRESSION]
13309          --                  [, Ensures  =>  Boolean_EXPRESSION]);
13310
13311          --  MODE_TYPE ::= Nominal | Robustness
13312
13313          when Pragma_Test_Case => Test_Case : declare
13314          begin
13315             GNAT_Pragma;
13316             Check_At_Least_N_Arguments (2);
13317             Check_At_Most_N_Arguments (4);
13318             Check_Arg_Order
13319                  ((Name_Name, Name_Mode, Name_Requires, Name_Ensures));
13320
13321             Check_Optional_Identifier (Arg1, Name_Name);
13322             Check_Arg_Is_Static_Expression (Arg1, Standard_String);
13323             Check_Optional_Identifier (Arg2, Name_Mode);
13324             Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness);
13325
13326             if Arg_Count = 4 then
13327                Check_Identifier (Arg3, Name_Requires);
13328                Check_Identifier (Arg4, Name_Ensures);
13329
13330             elsif Arg_Count = 3 then
13331                Check_Identifier_Is_One_Of (Arg3, Name_Requires, Name_Ensures);
13332             end if;
13333
13334             Check_Test_Case;
13335          end Test_Case;
13336
13337          --------------------------
13338          -- Thread_Local_Storage --
13339          --------------------------
13340
13341          --  pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
13342
13343          when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare
13344             Id : Node_Id;
13345             E  : Entity_Id;
13346
13347          begin
13348             GNAT_Pragma;
13349             Check_Arg_Count (1);
13350             Check_Optional_Identifier (Arg1, Name_Entity);
13351             Check_Arg_Is_Library_Level_Local_Name (Arg1);
13352
13353             Id := Get_Pragma_Arg (Arg1);
13354             Analyze (Id);
13355
13356             if not Is_Entity_Name (Id)
13357               or else Ekind (Entity (Id)) /= E_Variable
13358             then
13359                Error_Pragma_Arg ("local variable name required", Arg1);
13360             end if;
13361
13362             E := Entity (Id);
13363
13364             if Rep_Item_Too_Early (E, N)
13365               or else Rep_Item_Too_Late (E, N)
13366             then
13367                raise Pragma_Exit;
13368             end if;
13369
13370             Set_Has_Pragma_Thread_Local_Storage (E);
13371             Set_Has_Gigi_Rep_Item (E);
13372          end Thread_Local_Storage;
13373
13374          ----------------
13375          -- Time_Slice --
13376          ----------------
13377
13378          --  pragma Time_Slice (static_duration_EXPRESSION);
13379
13380          when Pragma_Time_Slice => Time_Slice : declare
13381             Val : Ureal;
13382             Nod : Node_Id;
13383
13384          begin
13385             GNAT_Pragma;
13386             Check_Arg_Count (1);
13387             Check_No_Identifiers;
13388             Check_In_Main_Program;
13389             Check_Arg_Is_Static_Expression (Arg1, Standard_Duration);
13390
13391             if not Error_Posted (Arg1) then
13392                Nod := Next (N);
13393                while Present (Nod) loop
13394                   if Nkind (Nod) = N_Pragma
13395                     and then Pragma_Name (Nod) = Name_Time_Slice
13396                   then
13397                      Error_Msg_Name_1 := Pname;
13398                      Error_Msg_N ("duplicate pragma% not permitted", Nod);
13399                   end if;
13400
13401                   Next (Nod);
13402                end loop;
13403             end if;
13404
13405             --  Process only if in main unit
13406
13407             if Get_Source_Unit (Loc) = Main_Unit then
13408                Opt.Time_Slice_Set := True;
13409                Val := Expr_Value_R (Get_Pragma_Arg (Arg1));
13410
13411                if Val <= Ureal_0 then
13412                   Opt.Time_Slice_Value := 0;
13413
13414                elsif Val > UR_From_Uint (UI_From_Int (1000)) then
13415                   Opt.Time_Slice_Value := 1_000_000_000;
13416
13417                else
13418                   Opt.Time_Slice_Value :=
13419                     UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000)));
13420                end if;
13421             end if;
13422          end Time_Slice;
13423
13424          -----------
13425          -- Title --
13426          -----------
13427
13428          --  pragma Title (TITLING_OPTION [, TITLING OPTION]);
13429
13430          --   TITLING_OPTION ::=
13431          --     [Title =>] STRING_LITERAL
13432          --   | [Subtitle =>] STRING_LITERAL
13433
13434          when Pragma_Title => Title : declare
13435             Args  : Args_List (1 .. 2);
13436             Names : constant Name_List (1 .. 2) := (
13437                       Name_Title,
13438                       Name_Subtitle);
13439
13440          begin
13441             GNAT_Pragma;
13442             Gather_Associations (Names, Args);
13443             Store_Note (N);
13444
13445             for J in 1 .. 2 loop
13446                if Present (Args (J)) then
13447                   Check_Arg_Is_Static_Expression (Args (J), Standard_String);
13448                end if;
13449             end loop;
13450          end Title;
13451
13452          ---------------------
13453          -- Unchecked_Union --
13454          ---------------------
13455
13456          --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
13457
13458          when Pragma_Unchecked_Union => Unchecked_Union : declare
13459             Assoc   : constant Node_Id := Arg1;
13460             Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc);
13461             Typ     : Entity_Id;
13462             Discr   : Entity_Id;
13463             Tdef    : Node_Id;
13464             Clist   : Node_Id;
13465             Vpart   : Node_Id;
13466             Comp    : Node_Id;
13467             Variant : Node_Id;
13468
13469          begin
13470             Ada_2005_Pragma;
13471             Check_No_Identifiers;
13472             Check_Arg_Count (1);
13473             Check_Arg_Is_Local_Name (Arg1);
13474
13475             Find_Type (Type_Id);
13476             Typ := Entity (Type_Id);
13477
13478             if Typ = Any_Type
13479               or else Rep_Item_Too_Early (Typ, N)
13480             then
13481                return;
13482             else
13483                Typ := Underlying_Type (Typ);
13484             end if;
13485
13486             if Rep_Item_Too_Late (Typ, N) then
13487                return;
13488             end if;
13489
13490             Check_First_Subtype (Arg1);
13491
13492             --  Note remaining cases are references to a type in the current
13493             --  declarative part. If we find an error, we post the error on
13494             --  the relevant type declaration at an appropriate point.
13495
13496             if not Is_Record_Type (Typ) then
13497                Error_Msg_N ("Unchecked_Union must be record type", Typ);
13498                return;
13499
13500             elsif Is_Tagged_Type (Typ) then
13501                Error_Msg_N ("Unchecked_Union must not be tagged", Typ);
13502                return;
13503
13504             elsif Is_Limited_Type (Typ) then
13505                Error_Msg_N
13506                  ("Unchecked_Union must not be limited record type", Typ);
13507                Explain_Limited_Type (Typ, Typ);
13508                return;
13509
13510             else
13511                if not Has_Discriminants (Typ) then
13512                   Error_Msg_N
13513                     ("Unchecked_Union must have one discriminant", Typ);
13514                   return;
13515                end if;
13516
13517                Discr := First_Discriminant (Typ);
13518                while Present (Discr) loop
13519                   if No (Discriminant_Default_Value (Discr)) then
13520                      Error_Msg_N
13521                        ("Unchecked_Union discriminant must have default value",
13522                         Discr);
13523                   end if;
13524
13525                   Next_Discriminant (Discr);
13526                end loop;
13527
13528                Tdef  := Type_Definition (Declaration_Node (Typ));
13529                Clist := Component_List (Tdef);
13530
13531                Comp := First (Component_Items (Clist));
13532                while Present (Comp) loop
13533                   Check_Component (Comp, Typ);
13534                   Next (Comp);
13535                end loop;
13536
13537                if No (Clist) or else No (Variant_Part (Clist)) then
13538                   Error_Msg_N
13539                     ("Unchecked_Union must have variant part",
13540                      Tdef);
13541                   return;
13542                end if;
13543
13544                Vpart := Variant_Part (Clist);
13545
13546                Variant := First (Variants (Vpart));
13547                while Present (Variant) loop
13548                   Check_Variant (Variant, Typ);
13549                   Next (Variant);
13550                end loop;
13551             end if;
13552
13553             Set_Is_Unchecked_Union  (Typ);
13554             Set_Convention (Typ, Convention_C);
13555             Set_Has_Unchecked_Union (Base_Type (Typ));
13556             Set_Is_Unchecked_Union  (Base_Type (Typ));
13557          end Unchecked_Union;
13558
13559          ------------------------
13560          -- Unimplemented_Unit --
13561          ------------------------
13562
13563          --  pragma Unimplemented_Unit;
13564
13565          --  Note: this only gives an error if we are generating code, or if
13566          --  we are in a generic library unit (where the pragma appears in the
13567          --  body, not in the spec).
13568
13569          when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare
13570             Cunitent : constant Entity_Id :=
13571                          Cunit_Entity (Get_Source_Unit (Loc));
13572             Ent_Kind : constant Entity_Kind :=
13573                          Ekind (Cunitent);
13574
13575          begin
13576             GNAT_Pragma;
13577             Check_Arg_Count (0);
13578
13579             if Operating_Mode = Generate_Code
13580               or else Ent_Kind = E_Generic_Function
13581               or else Ent_Kind = E_Generic_Procedure
13582               or else Ent_Kind = E_Generic_Package
13583             then
13584                Get_Name_String (Chars (Cunitent));
13585                Set_Casing (Mixed_Case);
13586                Write_Str (Name_Buffer (1 .. Name_Len));
13587                Write_Str (" is not supported in this configuration");
13588                Write_Eol;
13589                raise Unrecoverable_Error;
13590             end if;
13591          end Unimplemented_Unit;
13592
13593          ------------------------
13594          -- Universal_Aliasing --
13595          ------------------------
13596
13597          --  pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
13598
13599          when Pragma_Universal_Aliasing => Universal_Alias : declare
13600             E_Id : Entity_Id;
13601
13602          begin
13603             GNAT_Pragma;
13604             Check_Arg_Count (1);
13605             Check_Optional_Identifier (Arg2, Name_Entity);
13606             Check_Arg_Is_Local_Name (Arg1);
13607             E_Id := Entity (Get_Pragma_Arg (Arg1));
13608
13609             if E_Id = Any_Type then
13610                return;
13611             elsif No (E_Id) or else not Is_Type (E_Id) then
13612                Error_Pragma_Arg ("pragma% requires type", Arg1);
13613             end if;
13614
13615             Set_Universal_Aliasing (Implementation_Base_Type (E_Id));
13616          end Universal_Alias;
13617
13618          --------------------
13619          -- Universal_Data --
13620          --------------------
13621
13622          --  pragma Universal_Data [(library_unit_NAME)];
13623
13624          when Pragma_Universal_Data =>
13625             GNAT_Pragma;
13626
13627             --  If this is a configuration pragma, then set the universal
13628             --  addressing option, otherwise confirm that the pragma satisfies
13629             --  the requirements of library unit pragma placement and leave it
13630             --  to the GNAAMP back end to detect the pragma (avoids transitive
13631             --  setting of the option due to withed units).
13632
13633             if Is_Configuration_Pragma then
13634                Universal_Addressing_On_AAMP := True;
13635             else
13636                Check_Valid_Library_Unit_Pragma;
13637             end if;
13638
13639             if not AAMP_On_Target then
13640                Error_Pragma ("?pragma% ignored (applies only to AAMP)");
13641             end if;
13642
13643          ----------------
13644          -- Unmodified --
13645          ----------------
13646
13647          --  pragma Unmodified (local_Name {, local_Name});
13648
13649          when Pragma_Unmodified => Unmodified : declare
13650             Arg_Node : Node_Id;
13651             Arg_Expr : Node_Id;
13652             Arg_Ent  : Entity_Id;
13653
13654          begin
13655             GNAT_Pragma;
13656             Check_At_Least_N_Arguments (1);
13657
13658             --  Loop through arguments
13659
13660             Arg_Node := Arg1;
13661             while Present (Arg_Node) loop
13662                Check_No_Identifier (Arg_Node);
13663
13664                --  Note: the analyze call done by Check_Arg_Is_Local_Name will
13665                --  in fact generate reference, so that the entity will have a
13666                --  reference, which will inhibit any warnings about it not
13667                --  being referenced, and also properly show up in the ali file
13668                --  as a reference. But this reference is recorded before the
13669                --  Has_Pragma_Unreferenced flag is set, so that no warning is
13670                --  generated for this reference.
13671
13672                Check_Arg_Is_Local_Name (Arg_Node);
13673                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13674
13675                if Is_Entity_Name (Arg_Expr) then
13676                   Arg_Ent := Entity (Arg_Expr);
13677
13678                   if not Is_Assignable (Arg_Ent) then
13679                      Error_Pragma_Arg
13680                        ("pragma% can only be applied to a variable",
13681                         Arg_Expr);
13682                   else
13683                      Set_Has_Pragma_Unmodified (Arg_Ent);
13684                   end if;
13685                end if;
13686
13687                Next (Arg_Node);
13688             end loop;
13689          end Unmodified;
13690
13691          ------------------
13692          -- Unreferenced --
13693          ------------------
13694
13695          --  pragma Unreferenced (local_Name {, local_Name});
13696
13697          --    or when used in a context clause:
13698
13699          --  pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
13700
13701          when Pragma_Unreferenced => Unreferenced : declare
13702             Arg_Node : Node_Id;
13703             Arg_Expr : Node_Id;
13704             Arg_Ent  : Entity_Id;
13705             Citem    : Node_Id;
13706
13707          begin
13708             GNAT_Pragma;
13709             Check_At_Least_N_Arguments (1);
13710
13711             --  Check case of appearing within context clause
13712
13713             if Is_In_Context_Clause then
13714
13715                --  The arguments must all be units mentioned in a with clause
13716                --  in the same context clause. Note we already checked (in
13717                --  Par.Prag) that the arguments are either identifiers or
13718                --  selected components.
13719
13720                Arg_Node := Arg1;
13721                while Present (Arg_Node) loop
13722                   Citem := First (List_Containing (N));
13723                   while Citem /= N loop
13724                      if Nkind (Citem) = N_With_Clause
13725                        and then
13726                          Same_Name (Name (Citem), Get_Pragma_Arg (Arg_Node))
13727                      then
13728                         Set_Has_Pragma_Unreferenced
13729                           (Cunit_Entity
13730                              (Get_Source_Unit
13731                                 (Library_Unit (Citem))));
13732                         Set_Unit_Name
13733                           (Get_Pragma_Arg (Arg_Node), Name (Citem));
13734                         exit;
13735                      end if;
13736
13737                      Next (Citem);
13738                   end loop;
13739
13740                   if Citem = N then
13741                      Error_Pragma_Arg
13742                        ("argument of pragma% is not with'ed unit", Arg_Node);
13743                   end if;
13744
13745                   Next (Arg_Node);
13746                end loop;
13747
13748             --  Case of not in list of context items
13749
13750             else
13751                Arg_Node := Arg1;
13752                while Present (Arg_Node) loop
13753                   Check_No_Identifier (Arg_Node);
13754
13755                   --  Note: the analyze call done by Check_Arg_Is_Local_Name
13756                   --  will in fact generate reference, so that the entity will
13757                   --  have a reference, which will inhibit any warnings about
13758                   --  it not being referenced, and also properly show up in the
13759                   --  ali file as a reference. But this reference is recorded
13760                   --  before the Has_Pragma_Unreferenced flag is set, so that
13761                   --  no warning is generated for this reference.
13762
13763                   Check_Arg_Is_Local_Name (Arg_Node);
13764                   Arg_Expr := Get_Pragma_Arg (Arg_Node);
13765
13766                   if Is_Entity_Name (Arg_Expr) then
13767                      Arg_Ent := Entity (Arg_Expr);
13768
13769                      --  If the entity is overloaded, the pragma applies to the
13770                      --  most recent overloading, as documented. In this case,
13771                      --  name resolution does not generate a reference, so it
13772                      --  must be done here explicitly.
13773
13774                      if Is_Overloaded (Arg_Expr) then
13775                         Generate_Reference (Arg_Ent, N);
13776                      end if;
13777
13778                      Set_Has_Pragma_Unreferenced (Arg_Ent);
13779                   end if;
13780
13781                   Next (Arg_Node);
13782                end loop;
13783             end if;
13784          end Unreferenced;
13785
13786          --------------------------
13787          -- Unreferenced_Objects --
13788          --------------------------
13789
13790          --  pragma Unreferenced_Objects (local_Name {, local_Name});
13791
13792          when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare
13793             Arg_Node : Node_Id;
13794             Arg_Expr : Node_Id;
13795
13796          begin
13797             GNAT_Pragma;
13798             Check_At_Least_N_Arguments (1);
13799
13800             Arg_Node := Arg1;
13801             while Present (Arg_Node) loop
13802                Check_No_Identifier (Arg_Node);
13803                Check_Arg_Is_Local_Name (Arg_Node);
13804                Arg_Expr := Get_Pragma_Arg (Arg_Node);
13805
13806                if not Is_Entity_Name (Arg_Expr)
13807                  or else not Is_Type (Entity (Arg_Expr))
13808                then
13809                   Error_Pragma_Arg
13810                     ("argument for pragma% must be type or subtype", Arg_Node);
13811                end if;
13812
13813                Set_Has_Pragma_Unreferenced_Objects (Entity (Arg_Expr));
13814                Next (Arg_Node);
13815             end loop;
13816          end Unreferenced_Objects;
13817
13818          ------------------------------
13819          -- Unreserve_All_Interrupts --
13820          ------------------------------
13821
13822          --  pragma Unreserve_All_Interrupts;
13823
13824          when Pragma_Unreserve_All_Interrupts =>
13825             GNAT_Pragma;
13826             Check_Arg_Count (0);
13827
13828             if In_Extended_Main_Code_Unit (Main_Unit_Entity) then
13829                Unreserve_All_Interrupts := True;
13830             end if;
13831
13832          ----------------
13833          -- Unsuppress --
13834          ----------------
13835
13836          --  pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
13837
13838          when Pragma_Unsuppress =>
13839             Ada_2005_Pragma;
13840             Process_Suppress_Unsuppress (False);
13841
13842          -------------------
13843          -- Use_VADS_Size --
13844          -------------------
13845
13846          --  pragma Use_VADS_Size;
13847
13848          when Pragma_Use_VADS_Size =>
13849             GNAT_Pragma;
13850             Check_Arg_Count (0);
13851             Check_Valid_Configuration_Pragma;
13852             Use_VADS_Size := True;
13853
13854          ---------------------
13855          -- Validity_Checks --
13856          ---------------------
13857
13858          --  pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
13859
13860          when Pragma_Validity_Checks => Validity_Checks : declare
13861             A  : constant Node_Id   := Get_Pragma_Arg (Arg1);
13862             S  : String_Id;
13863             C  : Char_Code;
13864
13865          begin
13866             GNAT_Pragma;
13867             Check_Arg_Count (1);
13868             Check_No_Identifiers;
13869
13870             if Nkind (A) = N_String_Literal then
13871                S   := Strval (A);
13872
13873                declare
13874                   Slen    : constant Natural := Natural (String_Length (S));
13875                   Options : String (1 .. Slen);
13876                   J       : Natural;
13877
13878                begin
13879                   J := 1;
13880                   loop
13881                      C := Get_String_Char (S, Int (J));
13882                      exit when not In_Character_Range (C);
13883                      Options (J) := Get_Character (C);
13884
13885                      if J = Slen then
13886                         Set_Validity_Check_Options (Options);
13887                         exit;
13888                      else
13889                         J := J + 1;
13890                      end if;
13891                   end loop;
13892                end;
13893
13894             elsif Nkind (A) = N_Identifier then
13895
13896                if Chars (A) = Name_All_Checks then
13897                   Set_Validity_Check_Options ("a");
13898
13899                elsif Chars (A) = Name_On then
13900                   Validity_Checks_On := True;
13901
13902                elsif Chars (A) = Name_Off then
13903                   Validity_Checks_On := False;
13904
13905                end if;
13906             end if;
13907          end Validity_Checks;
13908
13909          --------------
13910          -- Volatile --
13911          --------------
13912
13913          --  pragma Volatile (LOCAL_NAME);
13914
13915          when Pragma_Volatile =>
13916             Process_Atomic_Shared_Volatile;
13917
13918          -------------------------
13919          -- Volatile_Components --
13920          -------------------------
13921
13922          --  pragma Volatile_Components (array_LOCAL_NAME);
13923
13924          --  Volatile is handled by the same circuit as Atomic_Components
13925
13926          --------------
13927          -- Warnings --
13928          --------------
13929
13930          --  pragma Warnings (On | Off);
13931          --  pragma Warnings (On | Off, LOCAL_NAME);
13932          --  pragma Warnings (static_string_EXPRESSION);
13933          --  pragma Warnings (On | Off, STRING_LITERAL);
13934
13935          when Pragma_Warnings => Warnings : begin
13936             GNAT_Pragma;
13937             Check_At_Least_N_Arguments (1);
13938             Check_No_Identifiers;
13939
13940             --  If debug flag -gnatd.i is set, pragma is ignored
13941
13942             if Debug_Flag_Dot_I then
13943                return;
13944             end if;
13945
13946             --  Process various forms of the pragma
13947
13948             declare
13949                Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
13950
13951             begin
13952                --  One argument case
13953
13954                if Arg_Count = 1 then
13955
13956                   --  On/Off one argument case was processed by parser
13957
13958                   if Nkind (Argx) = N_Identifier
13959                     and then
13960                       (Chars (Argx) = Name_On
13961                          or else
13962                        Chars (Argx) = Name_Off)
13963                   then
13964                      null;
13965
13966                   --  One argument case must be ON/OFF or static string expr
13967
13968                   elsif not Is_Static_String_Expression (Arg1) then
13969                      Error_Pragma_Arg
13970                        ("argument of pragma% must be On/Off or " &
13971                         "static string expression", Arg1);
13972
13973                   --  One argument string expression case
13974
13975                   else
13976                      declare
13977                         Lit : constant Node_Id   := Expr_Value_S (Argx);
13978                         Str : constant String_Id := Strval (Lit);
13979                         Len : constant Nat       := String_Length (Str);
13980                         C   : Char_Code;
13981                         J   : Nat;
13982                         OK  : Boolean;
13983                         Chr : Character;
13984
13985                      begin
13986                         J := 1;
13987                         while J <= Len loop
13988                            C := Get_String_Char (Str, J);
13989                            OK := In_Character_Range (C);
13990
13991                            if OK then
13992                               Chr := Get_Character (C);
13993
13994                               --  Dot case
13995
13996                               if J < Len and then Chr = '.' then
13997                                  J := J + 1;
13998                                  C := Get_String_Char (Str, J);
13999                                  Chr := Get_Character (C);
14000
14001                                  if not Set_Dot_Warning_Switch (Chr) then
14002                                     Error_Pragma_Arg
14003                                       ("invalid warning switch character " &
14004                                        '.' & Chr, Arg1);
14005                                  end if;
14006
14007                               --  Non-Dot case
14008
14009                               else
14010                                  OK := Set_Warning_Switch (Chr);
14011                               end if;
14012                            end if;
14013
14014                            if not OK then
14015                               Error_Pragma_Arg
14016                                 ("invalid warning switch character " & Chr,
14017                                  Arg1);
14018                            end if;
14019
14020                            J := J + 1;
14021                         end loop;
14022                      end;
14023                   end if;
14024
14025                   --  Two or more arguments (must be two)
14026
14027                else
14028                   Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
14029                   Check_At_Most_N_Arguments (2);
14030
14031                   declare
14032                      E_Id : Node_Id;
14033                      E    : Entity_Id;
14034                      Err  : Boolean;
14035
14036                   begin
14037                      E_Id := Get_Pragma_Arg (Arg2);
14038                      Analyze (E_Id);
14039
14040                      --  In the expansion of an inlined body, a reference to
14041                      --  the formal may be wrapped in a conversion if the
14042                      --  actual is a conversion. Retrieve the real entity name.
14043
14044                      if (In_Instance_Body
14045                          or else In_Inlined_Body)
14046                        and then Nkind (E_Id) = N_Unchecked_Type_Conversion
14047                      then
14048                         E_Id := Expression (E_Id);
14049                      end if;
14050
14051                      --  Entity name case
14052
14053                      if Is_Entity_Name (E_Id) then
14054                         E := Entity (E_Id);
14055
14056                         if E = Any_Id then
14057                            return;
14058                         else
14059                            loop
14060                               Set_Warnings_Off
14061                                 (E, (Chars (Get_Pragma_Arg (Arg1)) =
14062                                                               Name_Off));
14063
14064                               if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
14065                                 and then Warn_On_Warnings_Off
14066                               then
14067                                  Warnings_Off_Pragmas.Append ((N, E));
14068                               end if;
14069
14070                               if Is_Enumeration_Type (E) then
14071                                  declare
14072                                     Lit : Entity_Id;
14073                                  begin
14074                                     Lit := First_Literal (E);
14075                                     while Present (Lit) loop
14076                                        Set_Warnings_Off (Lit);
14077                                        Next_Literal (Lit);
14078                                     end loop;
14079                                  end;
14080                               end if;
14081
14082                               exit when No (Homonym (E));
14083                               E := Homonym (E);
14084                            end loop;
14085                         end if;
14086
14087                      --  Error if not entity or static string literal case
14088
14089                      elsif not Is_Static_String_Expression (Arg2) then
14090                         Error_Pragma_Arg
14091                           ("second argument of pragma% must be entity " &
14092                            "name or static string expression", Arg2);
14093
14094                      --  String literal case
14095
14096                      else
14097                         String_To_Name_Buffer
14098                           (Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))));
14099
14100                         --  Note on configuration pragma case: If this is a
14101                         --  configuration pragma, then for an OFF pragma, we
14102                         --  just set Config True in the call, which is all
14103                         --  that needs to be done. For the case of ON, this
14104                         --  is normally an error, unless it is canceling the
14105                         --  effect of a previous OFF pragma in the same file.
14106                         --  In any other case, an error will be signalled (ON
14107                         --  with no matching OFF).
14108
14109                         if Chars (Argx) = Name_Off then
14110                            Set_Specific_Warning_Off
14111                              (Loc, Name_Buffer (1 .. Name_Len),
14112                               Config => Is_Configuration_Pragma);
14113
14114                         elsif Chars (Argx) = Name_On then
14115                            Set_Specific_Warning_On
14116                              (Loc, Name_Buffer (1 .. Name_Len), Err);
14117
14118                            if Err then
14119                               Error_Msg
14120                                 ("?pragma Warnings On with no " &
14121                                  "matching Warnings Off",
14122                                  Loc);
14123                            end if;
14124                         end if;
14125                      end if;
14126                   end;
14127                end if;
14128             end;
14129          end Warnings;
14130
14131          -------------------
14132          -- Weak_External --
14133          -------------------
14134
14135          --  pragma Weak_External ([Entity =>] LOCAL_NAME);
14136
14137          when Pragma_Weak_External => Weak_External : declare
14138             Ent : Entity_Id;
14139
14140          begin
14141             GNAT_Pragma;
14142             Check_Arg_Count (1);
14143             Check_Optional_Identifier (Arg1, Name_Entity);
14144             Check_Arg_Is_Library_Level_Local_Name (Arg1);
14145             Ent := Entity (Get_Pragma_Arg (Arg1));
14146
14147             if Rep_Item_Too_Early (Ent, N) then
14148                return;
14149             else
14150                Ent := Underlying_Type (Ent);
14151             end if;
14152
14153             --  The only processing required is to link this item on to the
14154             --  list of rep items for the given entity. This is accomplished
14155             --  by the call to Rep_Item_Too_Late (when no error is detected
14156             --  and False is returned).
14157
14158             if Rep_Item_Too_Late (Ent, N) then
14159                return;
14160             else
14161                Set_Has_Gigi_Rep_Item (Ent);
14162             end if;
14163          end Weak_External;
14164
14165          -----------------------------
14166          -- Wide_Character_Encoding --
14167          -----------------------------
14168
14169          --  pragma Wide_Character_Encoding (IDENTIFIER);
14170
14171          when Pragma_Wide_Character_Encoding =>
14172             GNAT_Pragma;
14173
14174             --  Nothing to do, handled in parser. Note that we do not enforce
14175             --  configuration pragma placement, this pragma can appear at any
14176             --  place in the source, allowing mixed encodings within a single
14177             --  source program.
14178
14179             null;
14180
14181          --------------------
14182          -- Unknown_Pragma --
14183          --------------------
14184
14185          --  Should be impossible, since the case of an unknown pragma is
14186          --  separately processed before the case statement is entered.
14187
14188          when Unknown_Pragma =>
14189             raise Program_Error;
14190       end case;
14191
14192       --  AI05-0144: detect dangerous order dependence. Disabled for now,
14193       --  until AI is formally approved.
14194
14195       --  Check_Order_Dependence;
14196
14197    exception
14198       when Pragma_Exit => null;
14199    end Analyze_Pragma;
14200
14201    -----------------------------
14202    -- Analyze_TC_In_Decl_Part --
14203    -----------------------------
14204
14205    procedure Analyze_TC_In_Decl_Part (N : Node_Id; S : Entity_Id) is
14206    begin
14207       --  Install formals and push subprogram spec onto scope stack so that we
14208       --  can see the formals from the pragma.
14209
14210       Install_Formals (S);
14211       Push_Scope (S);
14212
14213       --  Preanalyze the boolean expressions, we treat these as spec
14214       --  expressions (i.e. similar to a default expression).
14215
14216       Preanalyze_TC_Args (Get_Requires_From_Test_Case_Pragma (N),
14217                           Get_Ensures_From_Test_Case_Pragma (N));
14218
14219       --  Remove the subprogram from the scope stack now that the pre-analysis
14220       --  of the expressions in the test-case is done.
14221
14222       End_Scope;
14223    end Analyze_TC_In_Decl_Part;
14224
14225    --------------------
14226    -- Check_Disabled --
14227    --------------------
14228
14229    function Check_Disabled (Nam : Name_Id) return Boolean is
14230       PP : Node_Id;
14231
14232    begin
14233       --  Loop through entries in check policy list
14234
14235       PP := Opt.Check_Policy_List;
14236       loop
14237          --  If there are no specific entries that matched, then nothing is
14238          --  disabled, so return False.
14239
14240          if No (PP) then
14241             return False;
14242
14243          --  Here we have an entry see if it matches
14244
14245          else
14246             declare
14247                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14248             begin
14249                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14250                   return Chars (Get_Pragma_Arg (Last (PPA))) = Name_Disable;
14251                else
14252                   PP := Next_Pragma (PP);
14253                end if;
14254             end;
14255          end if;
14256       end loop;
14257    end Check_Disabled;
14258
14259    -------------------
14260    -- Check_Enabled --
14261    -------------------
14262
14263    function Check_Enabled (Nam : Name_Id) return Boolean is
14264       PP : Node_Id;
14265
14266    begin
14267       --  Loop through entries in check policy list
14268
14269       PP := Opt.Check_Policy_List;
14270       loop
14271          --  If there are no specific entries that matched, then we let the
14272          --  setting of assertions govern. Note that this provides the needed
14273          --  compatibility with the RM for the cases of assertion, invariant,
14274          --  precondition, predicate, and postcondition.
14275
14276          if No (PP) then
14277             return Assertions_Enabled;
14278
14279          --  Here we have an entry see if it matches
14280
14281          else
14282             declare
14283                PPA : constant List_Id := Pragma_Argument_Associations (PP);
14284
14285             begin
14286                if Nam = Chars (Get_Pragma_Arg (First (PPA))) then
14287                   case (Chars (Get_Pragma_Arg (Last (PPA)))) is
14288                      when Name_On | Name_Check =>
14289                         return True;
14290                      when Name_Off | Name_Ignore =>
14291                         return False;
14292                      when others =>
14293                         raise Program_Error;
14294                   end case;
14295
14296                else
14297                   PP := Next_Pragma (PP);
14298                end if;
14299             end;
14300          end if;
14301       end loop;
14302    end Check_Enabled;
14303
14304    ---------------------------------
14305    -- Delay_Config_Pragma_Analyze --
14306    ---------------------------------
14307
14308    function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is
14309    begin
14310       return Pragma_Name (N) = Name_Interrupt_State
14311                or else
14312              Pragma_Name (N) = Name_Priority_Specific_Dispatching;
14313    end Delay_Config_Pragma_Analyze;
14314
14315    -------------------------
14316    -- Get_Base_Subprogram --
14317    -------------------------
14318
14319    function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is
14320       Result : Entity_Id;
14321
14322    begin
14323       --  Follow subprogram renaming chain
14324
14325       Result := Def_Id;
14326       while Is_Subprogram (Result)
14327         and then
14328           Nkind (Parent (Declaration_Node (Result))) =
14329                                          N_Subprogram_Renaming_Declaration
14330         and then Present (Alias (Result))
14331       loop
14332          Result := Alias (Result);
14333       end loop;
14334
14335       return Result;
14336    end Get_Base_Subprogram;
14337
14338    ----------------
14339    -- Initialize --
14340    ----------------
14341
14342    procedure Initialize is
14343    begin
14344       Externals.Init;
14345    end Initialize;
14346
14347    -----------------------------
14348    -- Is_Config_Static_String --
14349    -----------------------------
14350
14351    function Is_Config_Static_String (Arg : Node_Id) return Boolean is
14352
14353       function Add_Config_Static_String (Arg : Node_Id) return Boolean;
14354       --  This is an internal recursive function that is just like the outer
14355       --  function except that it adds the string to the name buffer rather
14356       --  than placing the string in the name buffer.
14357
14358       ------------------------------
14359       -- Add_Config_Static_String --
14360       ------------------------------
14361
14362       function Add_Config_Static_String (Arg : Node_Id) return Boolean is
14363          N : Node_Id;
14364          C : Char_Code;
14365
14366       begin
14367          N := Arg;
14368
14369          if Nkind (N) = N_Op_Concat then
14370             if Add_Config_Static_String (Left_Opnd (N)) then
14371                N := Right_Opnd (N);
14372             else
14373                return False;
14374             end if;
14375          end if;
14376
14377          if Nkind (N) /= N_String_Literal then
14378             Error_Msg_N ("string literal expected for pragma argument", N);
14379             return False;
14380
14381          else
14382             for J in 1 .. String_Length (Strval (N)) loop
14383                C := Get_String_Char (Strval (N), J);
14384
14385                if not In_Character_Range (C) then
14386                   Error_Msg
14387                     ("string literal contains invalid wide character",
14388                      Sloc (N) + 1 + Source_Ptr (J));
14389                   return False;
14390                end if;
14391
14392                Add_Char_To_Name_Buffer (Get_Character (C));
14393             end loop;
14394          end if;
14395
14396          return True;
14397       end Add_Config_Static_String;
14398
14399    --  Start of processing for Is_Config_Static_String
14400
14401    begin
14402
14403       Name_Len := 0;
14404       return Add_Config_Static_String (Arg);
14405    end Is_Config_Static_String;
14406
14407    -----------------------------------------
14408    -- Is_Non_Significant_Pragma_Reference --
14409    -----------------------------------------
14410
14411    --  This function makes use of the following static table which indicates
14412    --  whether a given pragma is significant.
14413
14414    --  -1  indicates that references in any argument position are significant
14415    --  0   indicates that appearance in any argument is not significant
14416    --  +n  indicates that appearance as argument n is significant, but all
14417    --      other arguments are not significant
14418    --  99  special processing required (e.g. for pragma Check)
14419
14420    Sig_Flags : constant array (Pragma_Id) of Int :=
14421      (Pragma_AST_Entry                     => -1,
14422       Pragma_Abort_Defer                   => -1,
14423       Pragma_Ada_83                        => -1,
14424       Pragma_Ada_95                        => -1,
14425       Pragma_Ada_05                        => -1,
14426       Pragma_Ada_2005                      => -1,
14427       Pragma_Ada_12                        => -1,
14428       Pragma_Ada_2012                      => -1,
14429       Pragma_All_Calls_Remote              => -1,
14430       Pragma_Annotate                      => -1,
14431       Pragma_Assert                        => -1,
14432       Pragma_Assertion_Policy              =>  0,
14433       Pragma_Assume_No_Invalid_Values      =>  0,
14434       Pragma_Asynchronous                  => -1,
14435       Pragma_Atomic                        =>  0,
14436       Pragma_Atomic_Components             =>  0,
14437       Pragma_Attach_Handler                => -1,
14438       Pragma_Check                         => 99,
14439       Pragma_Check_Name                    =>  0,
14440       Pragma_Check_Policy                  =>  0,
14441       Pragma_CIL_Constructor               => -1,
14442       Pragma_CPP_Class                     =>  0,
14443       Pragma_CPP_Constructor               =>  0,
14444       Pragma_CPP_Virtual                   =>  0,
14445       Pragma_CPP_Vtable                    =>  0,
14446       Pragma_CPU                           => -1,
14447       Pragma_C_Pass_By_Copy                =>  0,
14448       Pragma_Comment                       =>  0,
14449       Pragma_Common_Object                 => -1,
14450       Pragma_Compile_Time_Error            => -1,
14451       Pragma_Compile_Time_Warning          => -1,
14452       Pragma_Compiler_Unit                 =>  0,
14453       Pragma_Complete_Representation       =>  0,
14454       Pragma_Complex_Representation        =>  0,
14455       Pragma_Component_Alignment           => -1,
14456       Pragma_Controlled                    =>  0,
14457       Pragma_Convention                    =>  0,
14458       Pragma_Convention_Identifier         =>  0,
14459       Pragma_Debug                         => -1,
14460       Pragma_Debug_Policy                  =>  0,
14461       Pragma_Detect_Blocking               => -1,
14462       Pragma_Default_Storage_Pool          => -1,
14463       Pragma_Dimension                     => -1,
14464       Pragma_Discard_Names                 =>  0,
14465       Pragma_Elaborate                     => -1,
14466       Pragma_Elaborate_All                 => -1,
14467       Pragma_Elaborate_Body                => -1,
14468       Pragma_Elaboration_Checks            => -1,
14469       Pragma_Eliminate                     => -1,
14470       Pragma_Export                        => -1,
14471       Pragma_Export_Exception              => -1,
14472       Pragma_Export_Function               => -1,
14473       Pragma_Export_Object                 => -1,
14474       Pragma_Export_Procedure              => -1,
14475       Pragma_Export_Value                  => -1,
14476       Pragma_Export_Valued_Procedure       => -1,
14477       Pragma_Extend_System                 => -1,
14478       Pragma_Extensions_Allowed            => -1,
14479       Pragma_External                      => -1,
14480       Pragma_Favor_Top_Level               => -1,
14481       Pragma_External_Name_Casing          => -1,
14482       Pragma_Fast_Math                     => -1,
14483       Pragma_Finalize_Storage_Only         =>  0,
14484       Pragma_Float_Representation          =>  0,
14485       Pragma_Ident                         => -1,
14486       Pragma_Implemented                   => -1,
14487       Pragma_Implicit_Packing              =>  0,
14488       Pragma_Import                        => +2,
14489       Pragma_Import_Exception              =>  0,
14490       Pragma_Import_Function               =>  0,
14491       Pragma_Import_Object                 =>  0,
14492       Pragma_Import_Procedure              =>  0,
14493       Pragma_Import_Valued_Procedure       =>  0,
14494       Pragma_Independent                   =>  0,
14495       Pragma_Independent_Components        =>  0,
14496       Pragma_Initialize_Scalars            => -1,
14497       Pragma_Inline                        =>  0,
14498       Pragma_Inline_Always                 =>  0,
14499       Pragma_Inline_Generic                =>  0,
14500       Pragma_Inspection_Point              => -1,
14501       Pragma_Interface                     => +2,
14502       Pragma_Interface_Name                => +2,
14503       Pragma_Interrupt_Handler             => -1,
14504       Pragma_Interrupt_Priority            => -1,
14505       Pragma_Interrupt_State               => -1,
14506       Pragma_Invariant                     => -1,
14507       Pragma_Java_Constructor              => -1,
14508       Pragma_Java_Interface                => -1,
14509       Pragma_Keep_Names                    =>  0,
14510       Pragma_License                       => -1,
14511       Pragma_Link_With                     => -1,
14512       Pragma_Linker_Alias                  => -1,
14513       Pragma_Linker_Constructor            => -1,
14514       Pragma_Linker_Destructor             => -1,
14515       Pragma_Linker_Options                => -1,
14516       Pragma_Linker_Section                => -1,
14517       Pragma_List                          => -1,
14518       Pragma_Locking_Policy                => -1,
14519       Pragma_Long_Float                    => -1,
14520       Pragma_Machine_Attribute             => -1,
14521       Pragma_Main                          => -1,
14522       Pragma_Main_Storage                  => -1,
14523       Pragma_Memory_Size                   => -1,
14524       Pragma_No_Return                     =>  0,
14525       Pragma_No_Body                       =>  0,
14526       Pragma_No_Run_Time                   => -1,
14527       Pragma_No_Strict_Aliasing            => -1,
14528       Pragma_Normalize_Scalars             => -1,
14529       Pragma_Obsolescent                   =>  0,
14530       Pragma_Optimize                      => -1,
14531       Pragma_Optimize_Alignment            => -1,
14532       Pragma_Ordered                       =>  0,
14533       Pragma_Pack                          =>  0,
14534       Pragma_Page                          => -1,
14535       Pragma_Passive                       => -1,
14536       Pragma_Preelaborable_Initialization  => -1,
14537       Pragma_Polling                       => -1,
14538       Pragma_Persistent_BSS                =>  0,
14539       Pragma_Postcondition                 => -1,
14540       Pragma_Precondition                  => -1,
14541       Pragma_Predicate                     => -1,
14542       Pragma_Preelaborate                  => -1,
14543       Pragma_Preelaborate_05               => -1,
14544       Pragma_Priority                      => -1,
14545       Pragma_Priority_Specific_Dispatching => -1,
14546       Pragma_Profile                       =>  0,
14547       Pragma_Profile_Warnings              =>  0,
14548       Pragma_Propagate_Exceptions          => -1,
14549       Pragma_Psect_Object                  => -1,
14550       Pragma_Pure                          => -1,
14551       Pragma_Pure_05                       => -1,
14552       Pragma_Pure_Function                 => -1,
14553       Pragma_Queuing_Policy                => -1,
14554       Pragma_Ravenscar                     => -1,
14555       Pragma_Relative_Deadline             => -1,
14556       Pragma_Remote_Call_Interface         => -1,
14557       Pragma_Remote_Types                  => -1,
14558       Pragma_Restricted_Run_Time           => -1,
14559       Pragma_Restriction_Warnings          => -1,
14560       Pragma_Restrictions                  => -1,
14561       Pragma_Reviewable                    => -1,
14562       Pragma_Short_Circuit_And_Or          => -1,
14563       Pragma_Share_Generic                 => -1,
14564       Pragma_Shared                        => -1,
14565       Pragma_Shared_Passive                => -1,
14566       Pragma_Short_Descriptors             =>  0,
14567       Pragma_Source_File_Name              => -1,
14568       Pragma_Source_File_Name_Project      => -1,
14569       Pragma_Source_Reference              => -1,
14570       Pragma_Storage_Size                  => -1,
14571       Pragma_Storage_Unit                  => -1,
14572       Pragma_Static_Elaboration_Desired    => -1,
14573       Pragma_Stream_Convert                => -1,
14574       Pragma_Style_Checks                  => -1,
14575       Pragma_Subtitle                      => -1,
14576       Pragma_Suppress                      =>  0,
14577       Pragma_Suppress_Exception_Locations  =>  0,
14578       Pragma_Suppress_All                  => -1,
14579       Pragma_Suppress_Debug_Info           =>  0,
14580       Pragma_Suppress_Initialization       =>  0,
14581       Pragma_System_Name                   => -1,
14582       Pragma_Task_Dispatching_Policy       => -1,
14583       Pragma_Task_Info                     => -1,
14584       Pragma_Task_Name                     => -1,
14585       Pragma_Task_Storage                  =>  0,
14586       Pragma_Test_Case                     => -1,
14587       Pragma_Thread_Local_Storage          =>  0,
14588       Pragma_Time_Slice                    => -1,
14589       Pragma_Title                         => -1,
14590       Pragma_Unchecked_Union               =>  0,
14591       Pragma_Unimplemented_Unit            => -1,
14592       Pragma_Universal_Aliasing            => -1,
14593       Pragma_Universal_Data                => -1,
14594       Pragma_Unmodified                    => -1,
14595       Pragma_Unreferenced                  => -1,
14596       Pragma_Unreferenced_Objects          => -1,
14597       Pragma_Unreserve_All_Interrupts      => -1,
14598       Pragma_Unsuppress                    =>  0,
14599       Pragma_Use_VADS_Size                 => -1,
14600       Pragma_Validity_Checks               => -1,
14601       Pragma_Volatile                      =>  0,
14602       Pragma_Volatile_Components           =>  0,
14603       Pragma_Warnings                      => -1,
14604       Pragma_Weak_External                 => -1,
14605       Pragma_Wide_Character_Encoding       =>  0,
14606       Unknown_Pragma                       =>  0);
14607
14608    function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is
14609       Id : Pragma_Id;
14610       P  : Node_Id;
14611       C  : Int;
14612       A  : Node_Id;
14613
14614    begin
14615       P := Parent (N);
14616
14617       if Nkind (P) /= N_Pragma_Argument_Association then
14618          return False;
14619
14620       else
14621          Id := Get_Pragma_Id (Parent (P));
14622          C := Sig_Flags (Id);
14623
14624          case C is
14625             when -1 =>
14626                return False;
14627
14628             when 0 =>
14629                return True;
14630
14631             when 99 =>
14632                case Id is
14633
14634                   --  For pragma Check, the first argument is not significant,
14635                   --  the second and the third (if present) arguments are
14636                   --  significant.
14637
14638                   when Pragma_Check =>
14639                      return
14640                        P = First (Pragma_Argument_Associations (Parent (P)));
14641
14642                   when others =>
14643                      raise Program_Error;
14644                end case;
14645
14646             when others =>
14647                A := First (Pragma_Argument_Associations (Parent (P)));
14648                for J in 1 .. C - 1 loop
14649                   if No (A) then
14650                      return False;
14651                   end if;
14652
14653                   Next (A);
14654                end loop;
14655
14656                return A = P; -- is this wrong way round ???
14657          end case;
14658       end if;
14659    end Is_Non_Significant_Pragma_Reference;
14660
14661    ------------------------------
14662    -- Is_Pragma_String_Literal --
14663    ------------------------------
14664
14665    --  This function returns true if the corresponding pragma argument is a
14666    --  static string expression. These are the only cases in which string
14667    --  literals can appear as pragma arguments. We also allow a string literal
14668    --  as the first argument to pragma Assert (although it will of course
14669    --  always generate a type error).
14670
14671    function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is
14672       Pragn : constant Node_Id := Parent (Par);
14673       Assoc : constant List_Id := Pragma_Argument_Associations (Pragn);
14674       Pname : constant Name_Id := Pragma_Name (Pragn);
14675       Argn  : Natural;
14676       N     : Node_Id;
14677
14678    begin
14679       Argn := 1;
14680       N := First (Assoc);
14681       loop
14682          exit when N = Par;
14683          Argn := Argn + 1;
14684          Next (N);
14685       end loop;
14686
14687       if Pname = Name_Assert then
14688          return True;
14689
14690       elsif Pname = Name_Export then
14691          return Argn > 2;
14692
14693       elsif Pname = Name_Ident then
14694          return Argn = 1;
14695
14696       elsif Pname = Name_Import then
14697          return Argn > 2;
14698
14699       elsif Pname = Name_Interface_Name then
14700          return Argn > 1;
14701
14702       elsif Pname = Name_Linker_Alias then
14703          return Argn = 2;
14704
14705       elsif Pname = Name_Linker_Section then
14706          return Argn = 2;
14707
14708       elsif Pname = Name_Machine_Attribute then
14709          return Argn = 2;
14710
14711       elsif Pname = Name_Source_File_Name then
14712          return True;
14713
14714       elsif Pname = Name_Source_Reference then
14715          return Argn = 2;
14716
14717       elsif Pname = Name_Title then
14718          return True;
14719
14720       elsif Pname = Name_Subtitle then
14721          return True;
14722
14723       else
14724          return False;
14725       end if;
14726    end Is_Pragma_String_Literal;
14727
14728    ------------------------
14729    -- Preanalyze_TC_Args --
14730    ------------------------
14731
14732    procedure Preanalyze_TC_Args (Arg_Req, Arg_Ens : Node_Id) is
14733    begin
14734       --  Preanalyze the boolean expressions, we treat these as spec
14735       --  expressions (i.e. similar to a default expression).
14736
14737       if Present (Arg_Req) then
14738          Preanalyze_Spec_Expression
14739            (Get_Pragma_Arg (Arg_Req), Standard_Boolean);
14740       end if;
14741
14742       if Present (Arg_Ens) then
14743          Preanalyze_Spec_Expression
14744            (Get_Pragma_Arg (Arg_Ens), Standard_Boolean);
14745       end if;
14746    end Preanalyze_TC_Args;
14747
14748    --------------------------------------
14749    -- Process_Compilation_Unit_Pragmas --
14750    --------------------------------------
14751
14752    procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is
14753    begin
14754       --  A special check for pragma Suppress_All, a very strange DEC pragma,
14755       --  strange because it comes at the end of the unit. Rational has the
14756       --  same name for a pragma, but treats it as a program unit pragma, In
14757       --  GNAT we just decide to allow it anywhere at all. If it appeared then
14758       --  the flag Has_Pragma_Suppress_All was set on the compilation unit
14759       --  node, and we insert a pragma Suppress (All_Checks) at the start of
14760       --  the context clause to ensure the correct processing.
14761
14762       if Has_Pragma_Suppress_All (N) then
14763          Prepend_To (Context_Items (N),
14764            Make_Pragma (Sloc (N),
14765              Chars                        => Name_Suppress,
14766              Pragma_Argument_Associations => New_List (
14767                Make_Pragma_Argument_Association (Sloc (N),
14768                  Expression => Make_Identifier (Sloc (N), Name_All_Checks)))));
14769       end if;
14770
14771       --  Nothing else to do at the current time!
14772
14773    end Process_Compilation_Unit_Pragmas;
14774
14775    --------
14776    -- rv --
14777    --------
14778
14779    procedure rv is
14780    begin
14781       null;
14782    end rv;
14783
14784    --------------------------------
14785    -- Set_Encoded_Interface_Name --
14786    --------------------------------
14787
14788    procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is
14789       Str : constant String_Id := Strval (S);
14790       Len : constant Int       := String_Length (Str);
14791       CC  : Char_Code;
14792       C   : Character;
14793       J   : Int;
14794
14795       Hex : constant array (0 .. 15) of Character := "0123456789abcdef";
14796
14797       procedure Encode;
14798       --  Stores encoded value of character code CC. The encoding we use an
14799       --  underscore followed by four lower case hex digits.
14800
14801       ------------
14802       -- Encode --
14803       ------------
14804
14805       procedure Encode is
14806       begin
14807          Store_String_Char (Get_Char_Code ('_'));
14808          Store_String_Char
14809            (Get_Char_Code (Hex (Integer (CC / 2 ** 12))));
14810          Store_String_Char
14811            (Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#))));
14812          Store_String_Char
14813            (Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#))));
14814          Store_String_Char
14815            (Get_Char_Code (Hex (Integer (CC and 16#0F#))));
14816       end Encode;
14817
14818    --  Start of processing for Set_Encoded_Interface_Name
14819
14820    begin
14821       --  If first character is asterisk, this is a link name, and we leave it
14822       --  completely unmodified. We also ignore null strings (the latter case
14823       --  happens only in error cases) and no encoding should occur for Java or
14824       --  AAMP interface names.
14825
14826       if Len = 0
14827         or else Get_String_Char (Str, 1) = Get_Char_Code ('*')
14828         or else VM_Target /= No_VM
14829         or else AAMP_On_Target
14830       then
14831          Set_Interface_Name (E, S);
14832
14833       else
14834          J := 1;
14835          loop
14836             CC := Get_String_Char (Str, J);
14837
14838             exit when not In_Character_Range (CC);
14839
14840             C := Get_Character (CC);
14841
14842             exit when C /= '_' and then C /= '$'
14843               and then C not in '0' .. '9'
14844               and then C not in 'a' .. 'z'
14845               and then C not in 'A' .. 'Z';
14846
14847             if J = Len then
14848                Set_Interface_Name (E, S);
14849                return;
14850
14851             else
14852                J := J + 1;
14853             end if;
14854          end loop;
14855
14856          --  Here we need to encode. The encoding we use as follows:
14857          --     three underscores  + four hex digits (lower case)
14858
14859          Start_String;
14860
14861          for J in 1 .. String_Length (Str) loop
14862             CC := Get_String_Char (Str, J);
14863
14864             if not In_Character_Range (CC) then
14865                Encode;
14866             else
14867                C := Get_Character (CC);
14868
14869                if C = '_' or else C = '$'
14870                  or else C in '0' .. '9'
14871                  or else C in 'a' .. 'z'
14872                  or else C in 'A' .. 'Z'
14873                then
14874                   Store_String_Char (CC);
14875                else
14876                   Encode;
14877                end if;
14878             end if;
14879          end loop;
14880
14881          Set_Interface_Name (E,
14882            Make_String_Literal (Sloc (S),
14883              Strval => End_String));
14884       end if;
14885    end Set_Encoded_Interface_Name;
14886
14887    -------------------
14888    -- Set_Unit_Name --
14889    -------------------
14890
14891    procedure Set_Unit_Name (N : Node_Id; With_Item : Node_Id) is
14892       Pref : Node_Id;
14893       Scop : Entity_Id;
14894
14895    begin
14896       if Nkind (N) = N_Identifier
14897         and then Nkind (With_Item) = N_Identifier
14898       then
14899          Set_Entity (N, Entity (With_Item));
14900
14901       elsif Nkind (N) = N_Selected_Component then
14902          Change_Selected_Component_To_Expanded_Name (N);
14903          Set_Entity (N, Entity (With_Item));
14904          Set_Entity (Selector_Name (N), Entity (N));
14905
14906          Pref := Prefix (N);
14907          Scop := Scope (Entity (N));
14908          while Nkind (Pref) = N_Selected_Component loop
14909             Change_Selected_Component_To_Expanded_Name (Pref);
14910             Set_Entity (Selector_Name (Pref), Scop);
14911             Set_Entity (Pref, Scop);
14912             Pref := Prefix (Pref);
14913             Scop := Scope (Scop);
14914          end loop;
14915
14916          Set_Entity (Pref, Scop);
14917       end if;
14918    end Set_Unit_Name;
14919
14920 end Sem_Prag;