OSDN Git Service

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