OSDN Git Service

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