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